/* The Edit — shared base styles.
 * Sprint 1 (design-system foundations: accessibility + brand).
 *
 * Linked on every page AFTER each page's inline <style>, so additive rules here
 * apply app-wide from one place. Page-specific token VALUES still live in each
 * page's :root; this file adds accessibility primitives, a documented
 * semantic-status palette, and reusable accessible component bases that the
 * later sprints (Outfits modes, Calendar/Settings dialogs) build on.
 */

/* ── Keyboard focus ───────────────────────────────────────────────────────────
 * The pages historically set `outline: none` on inputs and gave buttons no focus
 * style at all, so keyboard users had no visible focus. !important guarantees the
 * ring wins over any existing `outline:none` regardless of selector specificity.
 * :focus-visible shows the ring for keyboard/AT users only — not on mouse click.
 */
:focus-visible {
  outline: 2px solid var(--ink, #1A1A1A) !important;
  outline-offset: 2px !important;
  border-radius: 2px;
}

/* ── Screen-reader-only utility ─────────────────────────────────────────────── */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Brand palette — single source of truth ───────────────────────────────────
 * Per Brand & Social Guidelines v2.0. This file loads AFTER each page's inline
 * <style>, so these values WIN over the per-page :root blocks — change a brand
 * colour here and it updates app-wide. (The per-page :root blocks are now
 * redundant for these tokens and can be trimmed over time.)
 *
 * Note: --warm and --white deliberately stay page-defined — landing.html uses a
 * softer warm/white on purpose — so they are NOT centralised here.
 */
:root {
  --cream:     #F5F0E8;  /* primary background / paper */
  --sand:      #EDE5D8;  /* hairlines, soft panels */
  --stone:     #6E5E4D;  /* muted labels */
  --ink:       #1A1A1A;  /* charcoal text */
  --accent:    #1D9E75;  /* signature teal — italics, rules, links */
  --teal:      #1D9E75;
  --teal-deep: #0F6E56;  /* emphasis + CTAs */
  --teal-mist: #E1F5EE;  /* light teal surface */
  --gold:      #C4A882;  /* Warm Gold — sparing secondary accent only (never a CTA) */
}

/* ── Documented semantic-status colours ───────────────────────────────────────
 * Replaces the ad-hoc ambers/blues/reds/teals scattered across pages. Migrate
 * status text/badges onto these in later sprints. (All AA on cream/white.)
 */
:root {
  --status-success: #2E7D32;
  --status-warning: #B86010;
  --status-danger:  #B83030;
  --status-info:    #3A6A9A;

  /* Destructive-action set (delete / remove / discard). --danger aliases the
     documented status red; the bg/border companions give a consistent soft
     surface for danger buttons and confirm dialogs instead of ad-hoc reds. */
  --danger:        var(--status-danger);
  --danger-bg:     #FBEEEE;
  --danger-border: #E6C9C9;
}

/* ── Design-system scales (type · space · radius · shadow) ─────────────────────
 * The published source of truth for sizing. Values are CALIBRATED to the app's
 * existing editorial type/spacing so adopting a token is non-breaking — a page
 * migrating `font-size: 0.86rem` → `var(--text-md)` renders identically.
 *
 * Adoption is incremental and per-page: when touching a page, snap its ad-hoc
 * sizes to the NEAREST token below (that's where the consistency win lands).
 * base.css loads after each page's inline <style>, so these win app-wide.
 */
:root {
  /* Type ladder (rem) — small, editorial. Snap page sizes to the nearest step. */
  --text-2xs: 0.62rem;   /* uppercase eyebrows / tiny labels */
  --text-xs:  0.72rem;   /* hints, captions */
  --text-sm:  0.78rem;   /* secondary / compact buttons */
  --text-md:  0.86rem;   /* body, default button */
  --text-lg:  0.95rem;   /* emphasised body / large button */
  --text-xl:  1.15rem;   /* card / section titles */
  --text-2xl: 1.4rem;    /* page titles */
  --text-3xl: 1.7rem;    /* wordmark / hero */
  --text-4xl: 2.1rem;    /* display */

  /* Spacing scale (px) — 4-based rhythm. */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px; --space-12: 48px;

  /* Radius scale. */
  --radius-xs: 8px; --radius-sm: 10px; --radius-md: 12px; --radius-lg: 16px; --radius-pill: 100px;

  /* Shadow scale (warm base, matches the app's ink/brown palette). */
  --shadow-sm:    0 2px 8px rgba(39,32,24,0.08);
  --shadow-md:    0 6px 20px rgba(39,32,24,0.12);
  --shadow-lg:    0 14px 40px rgba(39,32,24,0.18);
  --shadow-sheet: 0 -8px 36px rgba(39,32,24,0.16);
}

/* ── Reusable accessible component bases (used in Sprints 5–6) ─────────────────
 * Segmented control / radiogroup — real radio semantics with a visible selected
 * state. Apply role="radiogroup" to the container and role="radio"
 * aria-checked="true|false" to each option; arrow-key handling is wired in JS.
 */
.segmented { display: inline-flex; gap: 4px; }
.segmented [role="radio"] { cursor: pointer; }
.segmented [role="radio"][aria-checked="true"] {
  background: var(--ink, #1A1A1A);
  color: var(--white, #FDFCF9);
}

/* Accessible dialog base (role="dialog" aria-modal="true"). JS adds the `.on`
 * class, focus-trapping and Esc-to-close; this just provides overlay + panel. */
.a11y-dialog-overlay {
  position: fixed; inset: 0;
  background: rgba(39, 32, 24, 0.6);
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
  z-index: 800;
}
.a11y-dialog-overlay.on { display: flex; }
.a11y-dialog {
  background: var(--white, #FDFCF9);
  border-radius: 16px;
  width: min(560px, 100%);
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}

/* ── Respect users who prefer reduced motion ─────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Brand wordmark (luxe rebrand) ────────────────────────────────────────────
 * "THE EDIT" in Cormorant Garamond, tracked caps, deep teal — replaces the old
 * SVG <img> lockups so headers render the real brand font responsively.
 * (Pages load Cormorant Garamond 500 alongside Inter/Playfair.)
 */
.brand-wordmark.brand-wordmark {
  display: inline-block;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 500;
  font-size: var(--text-3xl);
  letter-spacing: 0.32em;
  margin-right: -0.32em;       /* cancel trailing tracking after the final T */
  text-transform: uppercase;
  color: var(--teal-deep, #0F6E56);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}
.brand-wordmark--lg.brand-wordmark--lg { font-size: var(--text-4xl); }
a .brand-wordmark, a.brand-wordmark { text-decoration: none; }
@media (max-width: 640px) {
  .brand-wordmark.brand-wordmark { font-size: var(--text-xl); letter-spacing: 0.24em; margin-right: -0.24em; }
  .brand-wordmark--lg.brand-wordmark--lg { font-size: var(--text-2xl); }
  /* Slimmer chrome on phones — the wordmark is a brand anchor, not a toolbar;
     primary nav lives in the bottom tab bar, so content can start higher. */
  body > header { padding-top: 12px; padding-bottom: 10px; }
  .page { padding-top: 26px; }
}

/* ── "Working behind the scenes" indicator ───────────────────────────────────
 * Shown wherever the AI is generating — the user sees a pulsing monogram and
 * rotating playful messages instead of watching raw text stream in.
 */
.ai-working { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 38px 24px; text-align: center; }
.ai-working-mark { font-family: 'Playfair Display', Georgia, serif; font-weight: 600; font-size: 2.3rem; line-height: 1; color: var(--teal-deep, #0F6E56); animation: ai-pulse 1.6s ease-in-out infinite; }
.ai-working-rule { width: 34px; height: 1.5px; background: var(--teal-deep, #0F6E56); animation: ai-pulse 1.6s ease-in-out infinite; }
.ai-working-msg { margin-top: 10px; font-size: 0.82rem; font-style: italic; color: var(--stone, #6E5E4D); transition: opacity 0.25s; min-height: 1.3em; }
@keyframes ai-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ai-working-mark, .ai-working-rule { animation: none; opacity: 1; } }

/* ── iOS Safari input-zoom guard ──────────────────────────────────────────────
 * Any form control rendered below 16px makes iOS zoom (and not zoom back) on
 * focus. Several pages set input font-size inline (e.g. 0.84rem), so this forces
 * ≥16px on small screens with !important to beat those inline styles. Applied
 * only ≤640px so desktop sizing is untouched. Excludes controls where font-size
 * is irrelevant. */
@media (max-width: 640px) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
  select,
  textarea { font-size: 16px !important; }
}

/* ── Shared design-system foundations ─────────────────────────────────────────
 * Canonical versions of primitives that were copy-pasted into many page <style>
 * blocks. These live in the global stylesheet so a page only needs the class;
 * existing per-page definitions still win (their inline <style> comes later in
 * the cascade), so this is purely additive and safe to adopt incrementally.
 */

/* Loading spinner — pages can use `.spinner` (default) or pass a size via the
 * --spinner-size custom property. One keyframes definition for the whole app. */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: var(--spinner-size, 16px);
  height: var(--spinner-size, 16px);
  border: 2px solid var(--sand, #EDE5D8);
  border-top-color: var(--accent, #1D9E75);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 1.6s; } }

/* Icon button — guarantees a ≥44×44px touch target (Apple HIG / WCAG 2.5.5)
 * around small glyph buttons (close ×, eye toggle, chevrons) that were often
 * rendered far smaller and hard to tap on a phone. */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:disabled { opacity: 0.4; cursor: default; }

/* ── Canonical button system ──────────────────────────────────────────────────
 * One base + four variants so buttons read identically across pages. Variants are
 * COMPOUND selectors (`.btn.btn-primary`) so they only ever style elements that
 * opt in with BOTH classes — existing pages that use a bare `btn-primary` /
 * `btn-ghost` / `btn-secondary` (with their own local definitions) are untouched.
 * New buttons: `class="btn btn-primary"`. Migrate existing ones incrementally.
 *   .btn-primary   filled ink (the main action)
 *   .btn-secondary outlined on white (a lighter affirmative)
 *   .btn-ghost     text-only (tertiary / cancel)
 *   .btn-danger    outlined red (destructive)
 * Modifiers: .btn-block (full width), .btn-sm, .btn-lg.
 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 12px 22px; border-radius: var(--radius-sm); border: 1.5px solid transparent;
  font-family: inherit; font-size: var(--text-md); font-weight: 700; letter-spacing: 0.01em;
  line-height: 1; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: default; transform: none; }
.btn.btn-primary { background: var(--ink, #1A1A1A); color: var(--white, #FDFCF9); }
.btn.btn-primary:hover:not(:disabled) { opacity: 0.88; }
.btn.btn-secondary { background: var(--white, #FDFCF9); color: var(--ink, #1A1A1A); border-color: var(--sand, #EDE5D8); }
.btn.btn-secondary:hover:not(:disabled) { border-color: var(--stone, #6E5E4D); }
.btn.btn-ghost { background: transparent; color: var(--stone, #6E5E4D); }
.btn.btn-ghost:hover:not(:disabled) { color: var(--ink, #1A1A1A); background: rgba(43, 43, 43, 0.05); }
.btn.btn-danger { background: transparent; color: var(--danger, #B83030); border-color: var(--danger-border, #E6C9C9); }
.btn.btn-danger:hover:not(:disabled) { background: var(--danger-bg, #FBEEEE); border-color: var(--danger, #B83030); }
.btn.btn-block { width: 100%; }
.btn.btn-sm { padding: 8px 14px; font-size: var(--text-sm); border-radius: var(--radius-xs); }
.btn.btn-lg { padding: 15px 30px; font-size: var(--text-lg); border-radius: var(--radius-md); }

/* ── Foundations (additive; adopt incrementally) ──────────────────────────────
 * base.css loads AFTER each page's inline <style>, so its :root WINS app-wide.
 * The tokens/components below are therefore safe to ADD (nothing references them
 * yet), but consolidating an EXISTING per-page token here would override every
 * page at once — do that only after auditing that all pages share the value.
 */

/* F.1 — the one semantic colour referenced via a hardcoded fallback but never
 * defined centrally (amber "store/keep-for-now" foreground). Value unchanged. */
:root { --amber-fg: #8a5010; }

/* F.3 — z-index scale. Layer overlays against these tokens instead of magic
 * numbers so modals, sheets, toasts, and the tab bar never fight. Values match
 * what is already in use across the app. */
:root {
  --z-base:     1;
  --z-sticky:   90;    /* sticky bars / mobile bottom tab bar */
  --z-nudge:    95;    /* dismissible nudges (verify / notify) */
  --z-header:   200;   /* sticky page header */
  --z-bulkbar:  300;   /* multi-select / bulk-action bar */
  --z-overlay:  600;   /* page overlays & slide-in drawers */
  --z-modal:    800;   /* dialogs & confirm sheets */
  --z-toast:    1000;  /* toasts — above ordinary overlays */
  --z-carousel: 1100;  /* full-screen image carousel */
}

/* F.2 — shared empty-state. One look for every "nothing here yet" surface:
 *   <div class="empty-state">
 *     <div class="empty-state-icon">👗</div>
 *     <div class="empty-state-title">…</div>
 *     <div class="empty-state-sub">…</div>
 *     <a class="btn btn-primary btn-sm" href="…">…</a>
 *   </div>
 */
.empty-state { text-align: center; padding: 36px 24px; max-width: 380px; margin: 0 auto; }
.empty-state-icon { font-size: 1.9rem; line-height: 1; margin-bottom: 12px; opacity: 0.5; }
.empty-state-title { font-family: var(--serif, Georgia), serif; font-size: 1.05rem; font-weight: 700; color: var(--ink, #1A1A1A); margin-bottom: 6px; line-height: 1.3; }
.empty-state-sub { font-size: 0.82rem; color: var(--stone, #6E5E4D); line-height: 1.55; margin-bottom: 16px; }

/* ── Ethos reminder ("fewer, better → more outfits") ──────────────────────────
   A quiet, one-sentence "why this matters" line woven into the surfaces where the
   edit-vs-keep decision is made. Subtle top border so it reads as a gentle aside,
   not a banner. Shared across pages (static/ethos.js). See docs/ethos-messaging.md. */
.ethos-note { display: flex; gap: 8px; align-items: flex-start; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--sand, #E4DCCD); font-size: 0.76rem; line-height: 1.5; color: var(--warm, #6B5C52); font-style: italic; }
.ethos-note-spark { color: var(--teal-deep, #0F6E56); flex-shrink: 0; font-style: normal; }
