/* ============================================================
   Agentic OS — Design Tokens
   Extracted from the reference UI kit (Inter, indigo/violet accent,
   8px spacing grid, deep-navy neutral scale).
   Light + dark themes via [data-theme] on <html>.

   ── Ink / fill / soft ───────────────────────────────────────
   One colour cannot do two jobs. #22c55e reads fine as a status
   dot on white and is invisible as text on white — 2.28:1, where
   AA asks 4.5. So every semantic splits three ways:

     --x         FILL.  Dots, meters, bars, solid buttons. Bright.
                        Do not darken these: styles.css hardcodes
                        dark ink on --warning and --success fills.
     --x-ink     TEXT.  >= 4.5:1 on every surface it can land on,
                        which for the dark theme is --surface-3 and
                        for the light theme is also --surface-3.
                        Also used for borders that carry meaning.
     --x-soft    TINT.  Background wash behind ink of the same hue.

   Ratios were measured against all four grounds (bg, surface,
   surface-2, surface-3), not just one, and test/design-tokens.test.js
   fails the build if any pair drops below its floor. Change a value
   there and here together, never here alone.
   ============================================================ */

:root {
  /* --- Brand / primary (violet) --- */
  --violet-50:  #f5f3ff;
  --violet-100: #ede9fe;
  --violet-200: #ddd6fe;
  --violet-300: #c4b5fd;
  --violet-400: #a78bfa;
  --violet-500: #8b5cf6;
  --violet-600: #7c3aed;
  --violet-700: #6d28d9;
  --violet-800: #5b21b6;
  --violet-900: #4c1d95;

  /* --- Semantic fills (theme-independent; see the ink/fill note above) --- */
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.12);
  --success-soft: rgba(34, 197, 94, 0.12);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --warning-soft: rgba(245, 158, 11, 0.12);
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.12);
  --error-soft: rgba(239, 68, 68, 0.12);
  --info: #3b82f6;
  --info-bg: rgba(59, 130, 246, 0.12);
  --info-soft: rgba(59, 130, 246, 0.12);
  --cyan: #06b6d4;
  /* Scout teal — CVD-validated so the fleet palette never hinges on
     violet-vs-blue, which is indistinguishable under deuteranopia. */
  --teal: #0d9488;
  --teal-soft: rgba(13, 148, 136, 0.12);

  /* --- Typography --- */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", ui-monospace,
    Menlo, Consolas, monospace;

  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 16px;
  --text-lg: 18px;
  --text-xl: 22px;
  --text-2xl: 28px;
  --text-3xl: 40px;
  --text-4xl: 56px;

  /* --- Spacing (8px grid) --- */
  --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;
  --space-14: 56px;

  /* --- Radius --- */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-2xl: 24px;
  --radius-full: 999px;

  /* --- Layout --- */
  /* Rail + section column. The rail is fixed; the sidebar total varies with
     the breakpoint, which is why both are named. */
  --rail-w: 68px;
  --sidebar-w: 252px;
  --topbar-h: 64px;
  /* What the bar actually occupies once it has cleared the notch. Every layout
     that fills "the rest of the screen" subtracts this, not --topbar-h, or it
     ends up taller than the space it was given by exactly the inset. */
  --topbar-total: calc(var(--topbar-h) + var(--safe-t));
  --tabbar-h: 60px;
  --maxw: 1600px;

  /* --- Breakpoints ---
     Four, and only four. Media queries cannot read a custom property, so these
     are documentation the stylesheet is expected to honour — there had been
     seventeen ad-hoc widths (560 620 640 700 720 760 800 820 900 1050 1060 1100
     1120 1150 1180 1200 1280) and no way to tell which was deliberate.

       640   phone      — one column, drawer navigation, wrapped rows
       900   tablet     — sidebar leaves the flow
       1280  desktop    — the full multi-column layouts
       1680  wide       — room for a third column
  */

  /* --- Telegram Mini App ---
     Telegram's container is not the browser viewport: it has a header of its
     own, it can be collapsed, and it resizes as the keyboard opens.
     viewportStableHeight is the one measurement that does not flicker while
     that happens, and the bridge writes it here. Outside Telegram nothing sets
     it and the fallback is the ordinary dynamic viewport. */
  --tg-viewport: 100dvh;

  /* --- Safe areas ---
     Named rather than used inline so a layout can be tested: a probe can set
     --safe-b and see the shell respond, which env() alone does not allow.
     Non-zero only with viewport-fit=cover, which index.html sets. */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);

  /* --- Motion --- */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur: 160ms;
}

/* ---------------- Dark theme (default) ---------------- */
:root,
:root[data-theme="dark"] {

  /* Native controls the page does not paint: <select> popups, scrollbars,
     date pickers. Without this the browser draws them light under a dark
     page, and the language dropdown put near-white text on a white popup. */
  color-scheme: dark;

  --bg: #080b14;
  --bg-1: #0b0f19;
  --surface: #10151f;
  --surface-2: #161c28;
  --surface-3: #1c2431;
  --elevated: #141a26;
  --border: #222c3c;
  --border-strong: #2c3849;
  /* A boundary that carries meaning — input outline, checkbox edge, focus —
     needs 3:1. --border-strong is 1.54:1 and is for decorative rules only. */
  --border-interactive: #5c729e;
  --ring: #a78bfa;

  --text: #e6eaf2;
  --text-2: #a9b2c3;
  --text-3: #8b96a8;
  --text-inv: #ffffff;

  --primary: var(--violet-600);
  --primary-hover: var(--violet-500);
  --primary-ink: var(--violet-400);
  --primary-soft: rgba(124, 58, 237, 0.16);
  --primary-text: #ffffff;
  --accent-grad: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);

  /* Ink. The bright fills already clear 4.5:1 on this ground; blue and red
     do not, so they lighten. */
  --success-ink: #22c55e;
  --warning-ink: #f59e0b;
  --error-ink: #f87171;
  --info-ink: #60a5fa;
  --teal-ink: #2dd4bf;
  /* .btn-danger puts white on this. White on --error is 3.76:1. */
  --danger-fill: #dc2626;

  --teal: #2dd4bf;
  --teal-soft: rgba(45, 212, 191, 0.14);

  --chart-grid: rgba(255, 255, 255, 0.06);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 45px rgba(0, 0, 0, 0.55);
  --shadow-xl: 0 30px 70px rgba(0, 0, 0, 0.6);
  --scrim: rgba(3, 6, 12, 0.66);

  --card-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 10px 30px -14px rgba(0, 0, 0, 0.6);
  --card-hover-shadow: 0 1px 0 rgba(255, 255, 255, 0.07) inset, 0 20px 46px -16px rgba(0, 0, 0, 0.75);
  --glow-primary: 0 10px 26px -8px rgba(124, 58, 237, 0.55);
  --grad-text: linear-gradient(120deg, #c4b5fd, #8b5cf6 45%, #6d28d9);
  --hero-glow: radial-gradient(55% 75% at 72% 28%, rgba(124, 58, 237, 0.28), transparent 70%);
}

/* ---------------- Command theme (the operator's dark) ----------------
   The Command Center's language — warm near-black and one ember accent —
   promoted from the stage to the whole operator surface (Ф5). Stored
   preference stays "dark"; app.js maps it to this theme for operators, so
   Member and Design keep the original dark untouched.

   The fill/ink split matters doubly here: bright ember (#ff6a00) is 2.6:1
   under white text, so the button fill is the deep burnt --primary below
   (white clears 5.1:1) and the bright ember lives in ink, ring and glow. */
:root[data-theme="command"] {
  color-scheme: dark;

  --bg: #070706;
  --bg-1: #0b0a09;
  --surface: #12110f;
  --surface-2: #191713;
  --surface-3: #201e1b;
  --elevated: #161412;
  --border: #262420;
  --border-strong: #343029;
  --border-interactive: #8a8478;
  --ring: #ff9440;

  --text: #f2f0ec;
  --text-2: #b5b0a6;
  --text-3: #9a958a;
  --text-inv: #ffffff;

  --primary: #b84d00;
  --primary-hover: #a64500;
  --primary-ink: #ff9440;
  --primary-soft: rgba(255, 106, 0, 0.14);
  --primary-text: #ffffff;
  --accent-grad: linear-gradient(135deg, #ff8a2a 0%, #b84d00 100%);

  --success-ink: #22c55e;
  --warning-ink: #f59e0b;
  --error-ink: #f87171;
  --info-ink: #60a5fa;
  --teal-ink: #2dd4bf;
  --danger-fill: #dc2626;

  --teal: #2dd4bf;
  --teal-soft: rgba(45, 212, 191, 0.14);

  --chart-grid: rgba(255, 250, 240, 0.06);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 18px 45px rgba(0, 0, 0, 0.6);
  --shadow-xl: 0 30px 70px rgba(0, 0, 0, 0.65);
  --scrim: rgba(4, 3, 2, 0.68);

  --card-shadow: 0 1px 0 rgba(255, 235, 200, 0.04) inset, 0 10px 30px -14px rgba(0, 0, 0, 0.65);
  --card-hover-shadow: 0 1px 0 rgba(255, 235, 200, 0.07) inset, 0 20px 46px -16px rgba(0, 0, 0, 0.8);
  --glow-primary: 0 10px 26px -8px rgba(255, 106, 0, 0.45);
  --grad-text: linear-gradient(120deg, #ffc98f, #ff8a2a 45%, #b84d00);
  --hero-glow: radial-gradient(55% 75% at 72% 28%, rgba(255, 106, 0, 0.22), transparent 70%);
}

/* ---------------- Light theme ---------------- */
:root[data-theme="light"] {
  color-scheme: light;

  --bg: #f4f5fa;
  --bg-1: #eef0f7;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --surface-3: #eef0f7;
  --elevated: #ffffff;
  --border: #e4e7f0;
  --border-strong: #d3d8e6;
  --border-interactive: #78849f;
  --ring: var(--violet-700);

  --text: #141a26;
  --text-2: #4b5568;
  --text-3: #5b6575;
  --text-inv: #ffffff;

  --primary: var(--violet-600);
  --primary-hover: var(--violet-700);
  --primary-ink: var(--violet-700);
  --primary-soft: rgba(124, 58, 237, 0.1);
  --primary-text: #ffffff;
  --accent-grad: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);

  /* Ink. This is where the old palette failed hardest: the fills were picked
     against near-black and reused unchanged on white, so "Healthy" rendered
     at 2.28:1 and "Degraded" at 2.15:1. */
  --success-ink: #047857;
  --warning-ink: #92400e;
  --error-ink: #b91c1c;
  --info-ink: #1d4ed8;
  --teal-ink: #0f766e;
  --danger-fill: #dc2626;

  /* The tints are washes behind ink of the same hue; on white the dark-theme
     alphas are too weak to read as a state, so they lift slightly. */
  --success-soft: rgba(4, 120, 87, 0.10);
  --warning-soft: rgba(146, 64, 14, 0.10);
  --error-soft: rgba(185, 28, 28, 0.09);
  --info-soft: rgba(29, 78, 216, 0.09);
  --teal-soft: rgba(15, 118, 110, 0.10);

  --chart-grid: rgba(15, 23, 42, 0.07);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 20px 45px rgba(16, 24, 40, 0.12);
  --shadow-xl: 0 30px 70px rgba(16, 24, 40, 0.16);
  --scrim: rgba(15, 23, 42, 0.35);

  --card-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 10px 24px -16px rgba(16, 24, 40, 0.2);
  --card-hover-shadow: 0 2px 6px rgba(16, 24, 40, 0.07), 0 20px 42px -18px rgba(16, 24, 40, 0.26);
  --glow-primary: 0 10px 22px -8px rgba(124, 58, 237, 0.42);
  --grad-text: linear-gradient(120deg, #7c3aed, #6d28d9);
  --hero-glow: radial-gradient(55% 75% at 72% 28%, rgba(124, 58, 237, 0.16), transparent 70%);
}
