/* ============================================================================
   CloudCart Design Tokens  —  HIG-inspired, license-safe
   ----------------------------------------------------------------------------
   Borrows Apple's SYSTEM DISCIPLINE (spacing rhythm, type scale, restraint,
   materials, motion) — NOT Apple's assets. No SF Pro, no SF Symbols. See
   fonts-icons.md for why and what we use instead.

   Usage:  <link rel="stylesheet" href="tokens.css">  then style with var(--*).
   Dark mode is automatic via prefers-color-scheme, and forceable with
   <html data-theme="dark"> / data-theme="light".

   Swap ONE thing per project: --brand-accent (and optionally the font).
   Everything else stays constant so all our tools feel like one family.
   Every text/background pair below is WCAG-AA verified (see SKILL.md).
   ========================================================================== */

:root {
  /* --- Brand accent (THE per-project override) -------------------------- */
  /* Default is Apple's system blue. Set --brand-accent to the client's color
     and links/buttons/focus follow automatically. Keep it dark enough that
     white text on it clears AA (>= ~3:1 for the large button label).        */
  --brand-accent:        #0071E3;  /* filled buttons / primary actions        */
  --brand-accent-hover:  #0077ED;
  --brand-accent-text:   #0066CC;  /* links & accent text on white (AA 5.5:1) */
  --on-accent:           #FFFFFF;  /* text/icon sitting ON the accent fill     */

  /* --- Type: license-safe SF-alike stack -------------------------------- */
  /* -apple-system renders as SF on Apple devices (referencing the installed
     OS font is allowed — we never ship the file). Inter is the cross-device
     fallback and closest open analog. Load Inter via fonts-icons.md.         */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, Helvetica, Arial, system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo,
               Consolas, monospace;

  /* Type scale — Apple text-style rhythm, tuned for web. rem @ 16px root.    */
  --text-display:      clamp(2.5rem, 1.2rem + 4vw, 4rem);   /* hero headline  */
  --text-large-title:  2.125rem;   /* 34 */
  --text-title-1:      1.75rem;    /* 28 */
  --text-title-2:      1.375rem;   /* 22 */
  --text-title-3:      1.25rem;    /* 20 */
  --text-headline:     1.0625rem;  /* 17, use with --weight-semibold        */
  --text-body:         1.0625rem;  /* 17 — Apple's comfortable body size     */
  --text-callout:      1rem;       /* 16 */
  --text-subhead:      0.9375rem;  /* 15 */
  --text-footnote:     0.8125rem;  /* 13 */
  --text-caption:      0.75rem;    /* 12 */

  --weight-regular:   400;
  --weight-medium:    500;
  --weight-semibold:  600;
  --weight-bold:      700;

  --leading-tight:    1.1;    /* display / large titles                     */
  --leading-snug:     1.25;   /* titles                                     */
  --leading-normal:   1.47;   /* body copy (Apple ~1.47 for 17px)           */

  /* Apple tracks large text tighter, small text looser.                     */
  --tracking-display: -0.022em;
  --tracking-title:   -0.01em;
  --tracking-normal:  0;
  --tracking-caption: 0.01em;

  /* --- Spacing: 8-pt grid (4-pt half-steps), t-shirt sized --------------- */
  --space-3xs: 2px;
  --space-2xs: 4px;
  --space-xs:  8px;
  --space-sm:  12px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;
  --space-2xl: 48px;
  --space-3xl: 64px;
  --space-4xl: 96px;
  --space-5xl: 128px;

  /* --- Radius: soft, continuous-corner feel ----------------------------- */
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;
  --radius-xl:   20px;
  --radius-2xl:  28px;
  --radius-full: 980px;

  /* --- Layout ----------------------------------------------------------- */
  --content-width:      980px;   /* apple.com-style comfortable column       */
  --content-width-wide: 1280px;
  --gutter:             clamp(16px, 5vw, 32px);
  --nav-height:         48px;

  /* --- Motion: restrained, ease-out dominant ---------------------------- */
  --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);     /* enters / reveals      */
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);    /* moves / reorders      */
  --dur-fast:    150ms;
  --dur-base:    250ms;
  --dur-slow:    400ms;

  /* --- Focus ring (accessibility — never remove, only restyle) ---------- */
  --focus-ring:  0 0 0 3px color-mix(in srgb, var(--brand-accent) 45%, transparent);

  /* ====================== LIGHT THEME (default) ======================== */
  --bg:            #FFFFFF;   /* page                                        */
  --bg-secondary:  #F5F5F7;   /* grouped background / page sections          */
  --bg-tertiary:   #FAFAFC;   /* subtle wells                                */
  --surface:       #FFFFFF;   /* cards / sheets                              */
  --surface-hover: #F5F5F7;

  --text:            #1D1D1F; /* primary label (16.8:1)                      */
  --text-secondary:  #6E6E73; /* secondary label (5.1:1)                     */
  --text-tertiary:   #86868B; /* hints / disabled (3.6:1, large only)        */
  --on-surface-muted:#515154;

  --separator:       rgba(0, 0, 0, 0.10);  /* hairline dividers              */
  --border:          rgba(0, 0, 0, 0.14);  /* input / card outlines          */

  --success: #248A3D;
  --warning: #8A4B00;
  --danger:  #D70015;
  --success-bg: #E7F6EC;
  --warning-bg: #FCF1E2;
  --danger-bg:  #FDE7E9;

  /* Materials — Apple "vibrancy". Pair with backdrop-filter: blur(20px).    */
  --material-thin:    rgba(255, 255, 255, 0.72);
  --material-regular: rgba(255, 255, 255, 0.82);

  /* Elevation — subtle by default; Apple leans on separation, not big shadows */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 1px rgba(0, 0, 0, 0.04);
  --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-3: 0 12px 40px rgba(0, 0, 0, 0.14), 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* ======================== DARK THEME ================================= */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-accent:       #0A84FF;
    --brand-accent-hover: #3395FF;
    --brand-accent-text:  #2997FF;

    --bg:            #000000;
    --bg-secondary:  #1C1C1E;
    --bg-tertiary:   #161618;
    --surface:       #1C1C1E;
    --surface-hover: #2C2C2E;

    --text:            #F5F5F7;
    --text-secondary:  #A1A1A6;
    --text-tertiary:   #8E8E93;
    --on-surface-muted:#C7C7CC;

    --separator:  rgba(255, 255, 255, 0.12);
    --border:     rgba(255, 255, 255, 0.18);

    --success: #30D158;
    --warning: #FFD60A;
    --danger:  #FF453A;
    --success-bg: #12331D;
    --warning-bg: #3A2E05;
    --danger-bg:  #3A1416;

    --material-thin:    rgba(30, 30, 32, 0.72);
    --material-regular: rgba(30, 30, 32, 0.82);

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-3: 0 12px 40px rgba(0, 0, 0, 0.6);
  }
}

/* Explicit forced dark (same values, so data-theme="dark" works anywhere). */
:root[data-theme="dark"] {
  --brand-accent: #0A84FF;  --brand-accent-hover: #3395FF; --brand-accent-text: #2997FF;
  --bg: #000000; --bg-secondary: #1C1C1E; --bg-tertiary: #161618;
  --surface: #1C1C1E; --surface-hover: #2C2C2E;
  --text: #F5F5F7; --text-secondary: #A1A1A6; --text-tertiary: #8E8E93; --on-surface-muted: #C7C7CC;
  --separator: rgba(255,255,255,0.12); --border: rgba(255,255,255,0.18);
  --success: #30D158; --warning: #FFD60A; --danger: #FF453A;
  --success-bg: #12331D; --warning-bg: #3A2E05; --danger-bg: #3A1416;
  --material-thin: rgba(30,30,32,0.72); --material-regular: rgba(30,30,32,0.82);
  --shadow-1: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-2: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-3: 0 12px 40px rgba(0,0,0,0.6);
}

/* ============================================================================
   BASELINE  —  the minimum "it already feels Apple-clean" reset. Optional,
   but recommended: import tokens.css then let these defaults do the work.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: var(--leading-normal);
  letter-spacing: var(--tracking-normal);
  font-weight: var(--weight-regular);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  margin: 0 0 var(--space-md);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-title);
  color: var(--text);
}
h1 { font-size: var(--text-large-title); line-height: var(--leading-tight); letter-spacing: var(--tracking-display); }
h2 { font-size: var(--text-title-1); }
h3 { font-size: var(--text-title-2); }
h4 { font-size: var(--text-title-3); }

p { margin: 0 0 var(--space-md); }

a {
  color: var(--brand-accent-text);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease-out);
}
a:hover { text-decoration: none; }

small, .text-caption { font-size: var(--text-caption); letter-spacing: var(--tracking-caption); }

/* One focus style everywhere. Visible, on-brand, keyboard-only. */
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* Respect reduced-motion — Apple does, so do we. */
@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;
  }
}
