/* SoraData design tokens. The one place that defines colour, type, space,
   radius, elevation, control size and motion for every product surface
   (account portal, home, webmail, legal pages; later calendar, contacts,
   cameras, files). Read docs/design-system.md before changing anything here.

   Rules:
   - Everything else consumes var(--sd-*). Raw hex, rgba and px radii live in
     this file only (internal/portal/design_test.go enforces it).
   - Themes: light is the default, dark follows prefers-color-scheme, and an
     explicit data-theme="light"|"dark" on <html> (or any element, for
     previews) wins over the system setting.
   - The dark values appear twice (the media query and [data-theme="dark"]);
     a Go test keeps the two copies identical.
   - The old variable names (--canvas, --surface, --fg, ...) are aliases at
     the bottom, so existing CSS keeps working while it migrates.

   This file has no dependency on the portal: the webmail imports it as is. */

/* ---- 1. colour roles: light (the default) ---- */
:root, [data-theme="light"] {
  color-scheme: light;
  --sd-bg:#f5f5f7;               /* the page behind everything */
  --sd-surface:#fff;             /* cards, panels, inputs, tables */
  --sd-surface-raised:#fff;      /* menus, dialogs, popovers: above the surface */
  --sd-surface-sunken:#fbfbfd;   /* sidebar, table heads: just off the surface */
  --sd-fill:#e8e8ed;             /* secondary buttons, selected rows, pills */
  --sd-fill-subtle:#f2f2f5;      /* hover on a surface, wells, code */
  --sd-line:#d2d2d7;             /* control borders */
  --sd-hairline:rgba(0,0,0,.08); /* dividers, card outlines */
  --sd-fg:#1d1d1f;               /* text */
  --sd-muted:#6e6e73;            /* secondary text (AA on surface, bg and fill-subtle) */
  --sd-faint:#6e6e73;            /* tertiary text and placeholders: AA, so equal to muted in light */
  --sd-accent:#0066cc;           /* links, active nav, focus: text-safe blue */
  --sd-accent-hover:#0057b0;
  --sd-accent-bg:#0071e3;        /* primary button fill: white text is AA on it */
  --sd-accent-bg-hover:#0067c9;
  --sd-accent-ring:rgba(0,113,227,.28);
  --sd-on-accent:#fff;
  --sd-ok:#17722f;   --sd-ok-bg:#e5f6ea;
  --sd-warn:#9a6200; --sd-warn-bg:#fff4dc;
  --sd-bad:#c9001a;  --sd-bad-bg:#ffe9eb;
  --sd-info:#0066cc; --sd-info-bg:#e6f0fc;
  --sd-shadow-1:0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);       /* card */
  --sd-shadow-2:0 8px 40px rgba(0,0,0,.14), 0 0 0 1px var(--sd-hairline);    /* menu, popover */
  --sd-shadow-3:0 16px 48px rgba(0,0,0,.25), 0 0 0 1px var(--sd-hairline);   /* dialog, lightbox */
  /* the home screen's translucent tiles over a calm gradient */
  --sd-tile-bg:rgba(255,255,255,.74); --sd-tile-line:rgba(255,255,255,.75); --sd-tile-hair:rgba(20,30,60,.08);
  --sd-tile-well:rgba(20,30,70,.045);
  --sd-tile-shadow:0 1px 2px rgba(20,32,72,.05), 0 12px 32px -8px rgba(20,32,72,.14);
  --sd-home-bg:
    radial-gradient(1100px 620px at 8% -12%, #d9e6ff 0%, rgba(217,230,255,0) 62%),
    radial-gradient(900px 620px at 100% 0%, #ece3ff 0%, rgba(236,227,255,0) 58%),
    radial-gradient(800px 600px at 50% 110%, #ddf3ef 0%, rgba(221,243,239,0) 60%),
    linear-gradient(180deg, #f3f5fb 0%, #edf0f7 100%);
}

/* ---- 2. colour roles: dark (system setting) ---- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --sd-bg:#000; --sd-surface:#1c1c1e; --sd-surface-raised:#1c1c1e; --sd-surface-sunken:#161618;
    --sd-fill:#2c2c2e; --sd-fill-subtle:#232325; --sd-line:#38383a; --sd-hairline:rgba(255,255,255,.1);
    --sd-fg:#f5f5f7; --sd-muted:#a1a1a6; --sd-faint:#98989d;
    --sd-accent:#2997ff; --sd-accent-hover:#47a6ff; --sd-accent-bg:#0071e3; --sd-accent-bg-hover:#0067c9;
    --sd-accent-ring:rgba(41,151,255,.35); --sd-on-accent:#fff;
    --sd-ok:#32d74b; --sd-ok-bg:#0f2a17; --sd-warn:#ffd60a; --sd-warn-bg:#2a2408;
    --sd-bad:#ff6961; --sd-bad-bg:#2e1210; --sd-info:#2997ff; --sd-info-bg:#0d2238;
    --sd-shadow-1:0 0 0 1px rgba(255,255,255,.04);
    --sd-shadow-2:0 8px 40px rgba(0,0,0,.14), 0 0 0 1px var(--sd-hairline);
    --sd-shadow-3:0 16px 48px rgba(0,0,0,.25), 0 0 0 1px var(--sd-hairline);
    --sd-tile-bg:rgba(20,28,52,.62); --sd-tile-line:rgba(255,255,255,.07); --sd-tile-hair:rgba(255,255,255,.08);
    --sd-tile-well:rgba(255,255,255,.06);
    --sd-tile-shadow:0 1px 0 rgba(255,255,255,.04) inset, 0 16px 40px -12px rgba(0,0,0,.55);
    --sd-home-bg:
      radial-gradient(1200px 700px at 0% -15%, #1d3f86 0%, rgba(29,63,134,0) 60%),
      radial-gradient(900px 700px at 100% 5%, #2b2170 0%, rgba(43,33,112,0) 56%),
      radial-gradient(900px 600px at 60% 115%, #0d3b4a 0%, rgba(13,59,74,0) 60%),
      linear-gradient(180deg, #0a1533 0%, #060c22 100%);
  }
}
[data-theme="dark"] {
  color-scheme: dark;
  --sd-bg:#000; --sd-surface:#1c1c1e; --sd-surface-raised:#1c1c1e; --sd-surface-sunken:#161618;
  --sd-fill:#2c2c2e; --sd-fill-subtle:#232325; --sd-line:#38383a; --sd-hairline:rgba(255,255,255,.1);
  --sd-fg:#f5f5f7; --sd-muted:#a1a1a6; --sd-faint:#98989d;
  --sd-accent:#2997ff; --sd-accent-hover:#47a6ff; --sd-accent-bg:#0071e3; --sd-accent-bg-hover:#0067c9;
  --sd-accent-ring:rgba(41,151,255,.35); --sd-on-accent:#fff;
  --sd-ok:#32d74b; --sd-ok-bg:#0f2a17; --sd-warn:#ffd60a; --sd-warn-bg:#2a2408;
  --sd-bad:#ff6961; --sd-bad-bg:#2e1210; --sd-info:#2997ff; --sd-info-bg:#0d2238;
  --sd-shadow-1:0 0 0 1px rgba(255,255,255,.04);
  --sd-shadow-2:0 8px 40px rgba(0,0,0,.14), 0 0 0 1px var(--sd-hairline);
  --sd-shadow-3:0 16px 48px rgba(0,0,0,.25), 0 0 0 1px var(--sd-hairline);
  --sd-tile-bg:rgba(20,28,52,.62); --sd-tile-line:rgba(255,255,255,.07); --sd-tile-hair:rgba(255,255,255,.08);
  --sd-tile-well:rgba(255,255,255,.06);
  --sd-tile-shadow:0 1px 0 rgba(255,255,255,.04) inset, 0 16px 40px -12px rgba(0,0,0,.55);
  --sd-home-bg:
    radial-gradient(1200px 700px at 0% -15%, #1d3f86 0%, rgba(29,63,134,0) 60%),
    radial-gradient(900px 700px at 100% 5%, #2b2170 0%, rgba(43,33,112,0) 56%),
    radial-gradient(900px 600px at 60% 115%, #0d3b4a 0%, rgba(13,59,74,0) 60%),
    linear-gradient(180deg, #0a1533 0%, #060c22 100%);
}

/* ---- 3. everything that does not change with the theme ---- */
:root {
  /* type: system font, a 7-step scale (px), line-heights and weights */
  --sd-font:-apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, "Segoe UI", Roboto, sans-serif;
  --sd-font-mono:ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  --sd-fs-xs:12px;  --sd-lh-xs:1.35;   /* captions, badges, table heads */
  --sd-fs-sm:13px;  --sd-lh-sm:1.4;    /* secondary text, hints, compact controls */
  --sd-fs-md:15px;  --sd-lh-md:1.45;   /* dense body: lists, forms, webmail */
  --sd-fs-lg:17px;  --sd-lh-lg:1.47;   /* body of the portal and legal pages; card titles */
  --sd-fs-xl:20px;  --sd-lh-xl:1.3;    /* section titles */
  --sd-fs-2xl:24px; --sd-lh-2xl:1.25;  /* page sub-titles, dialog titles */
  --sd-fs-3xl:32px; --sd-lh-3xl:1.18;  /* page titles */
  --sd-fs-input:16px;                  /* form fields: 16 stops iOS Safari zooming in */
  --sd-fw-regular:400; --sd-fw-medium:500; --sd-fw-semibold:600; --sd-fw-bold:700;
  --sd-tracking-tight:-.03em; --sd-tracking-snug:-.02em; --sd-tracking-body:-.01em; --sd-tracking-caps:.04em;

  /* spacing: 4 / 8 / 12 / 16 / 24 / 32 / 48 */
  --sd-s-1:4px; --sd-s-2:8px; --sd-s-3:12px; --sd-s-4:16px; --sd-s-5:24px; --sd-s-6:32px; --sd-s-7:48px;

  /* radii: control, card, panel/tile, pill, plus two small ones */
  --sd-r-xs:6px;      /* code, kbd, tiny marks */
  --sd-r-sm:8px;      /* nav items, small controls, list-row hover */
  --sd-r-md:12px;     /* control: inputs, buttons that are not pills, option cards */
  --sd-r-lg:18px;     /* card */
  --sd-r-xl:24px;     /* panel, dialog, home tile */
  --sd-r-pill:980px;  /* pill buttons, badges, chips */

  /* control heights: compact 28, default 36, large 44 (touch) */
  --sd-h-sm:28px; --sd-h-md:36px; --sd-h-lg:44px;
  /* portal buttons and fields: 36px with a mouse; 44px on touch (block below) */
  --sd-h-ctl:var(--sd-h-md);

  /* focus: one ring everywhere */
  --sd-focus-ring:0 0 0 4px var(--sd-accent-ring);

  /* motion */
  --sd-dur-fast:100ms; --sd-dur-base:150ms; --sd-dur-slow:250ms;
  --sd-ease:ease; --sd-ease-out:cubic-bezier(.2,.7,.2,1);

  /* layers */
  --sd-z-sticky:5; --sd-z-menu:10; --sd-z-dialog:40; --sd-z-toast:50;

  /* breakpoints (media queries cannot read variables: these document the
     values to write in @media): phone < 40rem, tablet < 52rem,
     home grid 700px (two columns) and 1100px (twelve) */
  --sd-bp-phone:40rem; --sd-bp-tablet:52rem; --sd-bp-grid-2:700px; --sd-bp-grid-12:1100px;

  /* brand art: not themed. App icon gradients, system hues, avatars. */
  --sd-art-home:linear-gradient(150deg,#5b8cff 0%,#3b5bdb 55%,#6a45e0 100%);
  --sd-art-mail:linear-gradient(150deg,#55a2ff 0%,#2f6df0 60%,#2348c9 100%);
  --sd-art-calendar:linear-gradient(150deg,#ff8c6b 0%,#f2555a 60%,#d93a64 100%);
  --sd-art-contacts:linear-gradient(150deg,#d08cff 0%,#a259f0 60%,#7c3fd6 100%);
  --sd-art-files:linear-gradient(150deg,#69d3f2 0%,#33a8dc 60%,#2581c0 100%);
  --sd-art-camera:linear-gradient(150deg,#4fe0b4 0%,#1fb78d 60%,#0f8f76 100%);
  --sd-art-admin:linear-gradient(150deg,#7d8bff 0%,#5361e6 60%,#3c3fb8 100%);
  --sd-art-key:linear-gradient(150deg,#ffcc5c 0%,#f59f2a 60%,#de7a12 100%);
  --sd-art-billing:linear-gradient(150deg,#ffcf6b 0%,#f5a431 60%,#e07b17 100%);
  --sd-art-security:linear-gradient(150deg,#8b9bb8 0%,#5d6d8c 60%,#3d4a66 100%);
  --sd-art-spark:linear-gradient(150deg,#ff9bd2 0%,#c86bf0 50%,#6f7cff 100%);
  --sd-art-devices:linear-gradient(150deg,#ffb35c 0%,#ff8a1f 60%,#e86a0c 100%);
  --sd-art-mark:linear-gradient(145deg,#3a8dff 0%,#0058d0 55%,#5b3cff 100%);
  --sd-art-avatar:linear-gradient(145deg,#8e8e93,#636366);
  --sd-art-avatar-me:linear-gradient(145deg,#4a7dff,#7a52f0);
  --sd-art-avatar-xl:linear-gradient(145deg,#5b8cff 0%,#6a5cf0 50%,#b45cf0 100%);
  --sd-art-progress:linear-gradient(90deg,#34c759,#30d158);
  --sd-art-broken:linear-gradient(150deg,#2a3550,#161d31);
  --sd-hue-blue:#0a84ff; --sd-hue-teal:#30b0c7; --sd-hue-mail:#007aff; --sd-hue-green:#34c759; --sd-hue-grey:#8e8e93;
  --sd-hue-orange:#ff9f0a; --sd-hue-indigo:#5e5ce6; --sd-hue-sky:#5ac8fa; --sd-hue-pink:#ff6482; --sd-hue-brown:#a2845e;
  --sd-hue-steel:#64a0d8; --sd-hue-red:#ff2d55; --sd-hue-purple:#bf5af2;
  --sd-hue-camera:#1fb78d; --sd-hue-mailblue:#2f6df0;
  --sd-white:#fff;           /* a glyph on brand art, whatever the theme */
  --sd-scrim:rgba(0,0,0,.62);
  --sd-overlay:rgba(0,0,0,.4);
}

/* Compact density: the webmail (and any dense tool) sets
   <html data-density="compact">. Smaller radii and the 36px default. */
[data-density="compact"] {
  --sd-r-md:8px; --sd-r-lg:10px; --sd-r-xl:14px;
  --sd-h-ctl:var(--sd-h-md);
  --sd-focus-ring:0 0 0 3px var(--sd-accent-ring);
}

@media (prefers-reduced-motion: reduce) {
  :root { --sd-dur-fast:.01ms; --sd-dur-base:.01ms; --sd-dur-slow:.01ms; }
}

/* ---- 4. legacy names: aliases so nothing breaks while pages migrate.
        New code uses the --sd-* names. Declared on every element that can
        carry a theme so a [data-theme] preview re-resolves them. ---- */
:root, [data-theme] {
  --canvas:var(--sd-bg); --surface:var(--sd-surface); --surface2:var(--sd-surface-sunken);
  --fg:var(--sd-fg); --muted:var(--sd-muted); --faint:var(--sd-faint);
  --line:var(--sd-line); --hair:var(--sd-hairline); --fill:var(--sd-fill); --fill2:var(--sd-fill-subtle);
  --accent:var(--sd-accent); --accent-hover:var(--sd-accent-bg-hover); --accent-ring:var(--sd-accent-ring); --onaccent:var(--sd-on-accent);
  --ok:var(--sd-ok); --okbg:var(--sd-ok-bg); --warn:var(--sd-warn); --warnbg:var(--sd-warn-bg);
  --bad:var(--sd-bad); --badbg:var(--sd-bad-bg); --runbg:var(--sd-info-bg);
  --shadow:var(--sd-shadow-1);
  --r-card:var(--sd-r-lg); --r-ctl:var(--sd-r-md);
}

/* a finger needs 44px; a pointer does not */
@media (pointer: coarse) { :root, [data-density="compact"] { --sd-h-ctl:var(--sd-h-lg); } }
