/*
 * TradeKit design tokens - the single source of truth for light and dark themes, built from the brand kit
 * (static/brand/README.md): Navy #0F172A, Mint #22C55E, Amber #F59E0B, the Slate scale and Snow #F8FAFC.
 *
 * Components never hard-code a theme. They read these tokens, so a theme is nothing more than a set of
 * token values and a new theme (or a white-label brand) is one more block in this file.
 *
 *   light  → :root                                  (default)
 *   dark   → :root[data-theme="dark"]               (set by /js/theme.js before first paint, or by the server from the tk-theme cookie)
 *   system → @media (prefers-color-scheme: dark) on :root:not([data-theme])   (no-JavaScript fallback only)
 *
 * The dark token block exists twice (attribute + media query) because CSS cannot share one block between a
 * media query and an attribute selector. Keep them identical; ThemeTokensTest enforces that and WCAG AA (4.5:1).
 */

/* Fonts are self-hosted (SIL OFL, see /fonts/*-OFL.txt): nothing is requested from Google, so no visitor data leaves the site. */
@font-face {
  font-family: "Inter";
  src: url("/fonts/inter-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("/fonts/space-grotesk-latin-wght-normal.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light;

  /* Surfaces */
  --bg: #F8FAFC;            /* brand Snow */
  --panel: #FFFFFF;
  --panel2: #F3F6FA;
  --input-bg: #FFFFFF;
  --track: #E5EAF1;
  --overlay: rgba(15, 23, 42, .50);

  /* Lines. Keep these as 6-digit hex: the chart script appends an alpha byte to them. */
  --line: #E2E8F0;          /* brand Slate 200 */
  --line-strong: #CBD5E1;
  --line-soft: #EEF2F7;

  /* Text */
  --text: #0F172A;          /* brand Navy */
  --text-strong: #0F172A;
  --text-soft: #334155;
  --muted: #475569;         /* brand Slate 600 */

  /* Brand fills: exact kit colours, used for buttons, the logo arrow and highlights. */
  --brand: #22C55E;         /* Mint */
  --brand-hover: #16A34A;   /* Mint Dark */
  --on-brand: #0F172A;      /* Navy label on Mint: 8:1 */
  --amber: #F59E0B;

  /* Brand as TEXT on this theme's surfaces. Mint Dark (#16A34A) is only 3.3:1 on white, so links and small
     text use the same hue one step darker to stay AA. */
  --accent: #15803D;
  --accent-strong: #166534;
  --accent-soft: #DCFCE7;
  --accent-line: #86EFAC;

  /* Semantic: each colour has a foreground, a soft background and a border, so chips, alerts and badges
     are built the same way in both themes. */
  --ok-fg: #15803D;      --ok-soft: #DCFCE7;      --ok-line: #86EFAC;
  --danger: #DC2626;     --danger-fg: #B91C1C;    --danger-soft: #FEE2E2;   --danger-line: #FCA5A5;
  --warn: #B45309;       --warn-fg: #92400E;      --warn-soft: #FEF3C7;     --warn-line: #FCD34D;
  --blue: #2563EB;       --info-fg: #1D4ED8;      --info-soft: #DBEAFE;     --info-line: #93C5FD;
  --violet: #7C3AED;     --violet-fg: #6D28D9;    --violet-soft: #EDE9FE;   --violet-line: #C4B5FD;
  --neutral-fg: #334155; --neutral-soft: #F1F5F9; --neutral-line: #CBD5E1;
  --sun: var(--warn);

  /* Depth: cards, glass, glow. Surfaces are layered (canvas, card, raised) instead of one flat slab. */
  --card-bg: linear-gradient(180deg, #FFFFFF 0%, #FCFDFE 100%);
  --card-hover-line: #B8C4D6;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 1px rgba(15, 23, 42, .04);
  --shadow-md: 0 8px 24px -10px rgba(15, 23, 42, .16);
  --shadow-lg: 0 22px 60px rgba(15, 23, 42, .16);
  --shadow-card: 0 1px 2px rgba(15, 23, 42, .04), 0 14px 34px -18px rgba(15, 23, 42, .16);
  --shadow-pop: 0 24px 64px -16px rgba(15, 23, 42, .30);
  --glass: rgba(248, 250, 252, .78);
  --glass-line: rgba(15, 23, 42, .07);
  --ambient: radial-gradient(60% 60% at 10% -10%, rgba(34, 197, 94, .15), transparent 72%), radial-gradient(48% 52% at 92% -8%, rgba(37, 99, 235, .10), transparent 72%);
  --grid-dot: rgba(15, 23, 42, .11);
  --glow-brand: 0 10px 24px -10px rgba(34, 197, 94, .75);
  --btn-sheen: inset 0 1px 0 rgba(255, 255, 255, .38);
  --seg-track: #EDF1F6;
  --seg-thumb: #FFFFFF;

  /* The sign-in brand panel is dark in both themes. */
  --aside-bg: linear-gradient(160deg, #0F172A 0%, #0B2A33 100%);
  --aside-text: #F8FAFC;
  --aside-muted: #A9B8CC;
  --aside-line: rgba(148, 163, 184, .22);

  /* Coin icons */
  --coin-bg: #FFFFFF;
  --coin-ring: rgba(15, 23, 42, .12);

  /* Type: Space Grotesk for headings and figures, Inter for everything else (both self-hosted). */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Space Grotesk", "Inter", ui-sans-serif, system-ui, sans-serif;

  /* Shape and focus */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --focus-ring: 0 0 0 3px color-mix(in srgb, var(--accent) 32%, transparent);
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0F172A;            /* brand Navy */
    --panel: #131C31;         /* cards sit one step above the Navy canvas */
    --panel2: #1A2540;
    --input-bg: #0C1427;
    --track: #263350;
    --overlay: rgba(2, 6, 23, .70);

    --line: #263350;
    --line-strong: #364768;
    --line-soft: #1D2943;

    --text: #F8FAFC;          /* brand Snow */
    --text-strong: #FFFFFF;
    --text-soft: #CBD5E1;
    --muted: #94A3B8;         /* brand Slate 400 */

    --brand: #22C55E;
    --brand-hover: #4ADE80;
    --on-brand: #0F172A;
    --amber: #F59E0B;

    --accent: #22C55E;
    --accent-strong: #4ADE80;
    --accent-soft: rgba(34, 197, 94, .13);
    --accent-line: rgba(34, 197, 94, .40);

    --ok-fg: #4ADE80;      --ok-soft: rgba(34, 197, 94, .13);    --ok-line: rgba(34, 197, 94, .38);
    --danger: #F87171;     --danger-fg: #FCA5A5;  --danger-soft: rgba(248, 113, 113, .13); --danger-line: rgba(248, 113, 113, .38);
    --warn: #F59E0B;       --warn-fg: #FBBF24;    --warn-soft: rgba(245, 158, 11, .14);    --warn-line: rgba(245, 158, 11, .40);
    --blue: #60A5FA;       --info-fg: #93C5FD;    --info-soft: rgba(96, 165, 250, .13);    --info-line: rgba(96, 165, 250, .38);
    --violet: #A78BFA;     --violet-fg: #C4B5FD;  --violet-soft: rgba(167, 139, 250, .14); --violet-line: rgba(167, 139, 250, .40);
    --neutral-fg: #CBD5E1; --neutral-soft: #1A2540; --neutral-line: #364768;

    --card-bg: linear-gradient(180deg, #18233B 0%, #131C31 100%);
    --card-hover-line: #4A5C80;
    --shadow-sm: 0 1px 2px rgba(2, 6, 23, .5);
    --shadow-md: 0 10px 28px -12px rgba(2, 6, 23, .6);
    --shadow-lg: 0 24px 70px rgba(2, 6, 23, .6);
    --shadow-card: inset 0 1px 0 rgba(255, 255, 255, .035), 0 16px 36px -20px rgba(2, 6, 23, .75);
    --shadow-pop: 0 28px 70px -16px rgba(2, 6, 23, .85);
    --glass: rgba(15, 23, 42, .72);
    --glass-line: rgba(148, 163, 184, .13);
    --ambient: radial-gradient(60% 60% at 10% -10%, rgba(34, 197, 94, .17), transparent 72%), radial-gradient(48% 52% at 92% -8%, rgba(96, 165, 250, .13), transparent 72%);
    --grid-dot: rgba(148, 163, 184, .15);
    --glow-brand: 0 10px 26px -10px rgba(34, 197, 94, .60);
    --btn-sheen: inset 0 1px 0 rgba(255, 255, 255, .30);
    --seg-track: #0C1427;
    --seg-thumb: #25335A;

    --aside-bg: linear-gradient(160deg, #0F172A 0%, #0B2A33 100%);
    --aside-text: #F8FAFC;
    --aside-muted: #A9B8CC;
    --aside-line: rgba(148, 163, 184, .22);

    --coin-bg: #1A2540;
    --coin-ring: rgba(255, 255, 255, .12);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
      color-scheme: dark;

      --bg: #0F172A;            /* brand Navy */
      --panel: #131C31;         /* cards sit one step above the Navy canvas */
      --panel2: #1A2540;
      --input-bg: #0C1427;
      --track: #263350;
      --overlay: rgba(2, 6, 23, .70);

      --line: #263350;
      --line-strong: #364768;
      --line-soft: #1D2943;

      --text: #F8FAFC;          /* brand Snow */
      --text-strong: #FFFFFF;
      --text-soft: #CBD5E1;
      --muted: #94A3B8;         /* brand Slate 400 */

      --brand: #22C55E;
      --brand-hover: #4ADE80;
      --on-brand: #0F172A;
      --amber: #F59E0B;

      --accent: #22C55E;
      --accent-strong: #4ADE80;
      --accent-soft: rgba(34, 197, 94, .13);
      --accent-line: rgba(34, 197, 94, .40);

      --ok-fg: #4ADE80;      --ok-soft: rgba(34, 197, 94, .13);    --ok-line: rgba(34, 197, 94, .38);
      --danger: #F87171;     --danger-fg: #FCA5A5;  --danger-soft: rgba(248, 113, 113, .13); --danger-line: rgba(248, 113, 113, .38);
      --warn: #F59E0B;       --warn-fg: #FBBF24;    --warn-soft: rgba(245, 158, 11, .14);    --warn-line: rgba(245, 158, 11, .40);
      --blue: #60A5FA;       --info-fg: #93C5FD;    --info-soft: rgba(96, 165, 250, .13);    --info-line: rgba(96, 165, 250, .38);
      --violet: #A78BFA;     --violet-fg: #C4B5FD;  --violet-soft: rgba(167, 139, 250, .14); --violet-line: rgba(167, 139, 250, .40);
      --neutral-fg: #CBD5E1; --neutral-soft: #1A2540; --neutral-line: #364768;

      --card-bg: linear-gradient(180deg, #18233B 0%, #131C31 100%);
      --card-hover-line: #4A5C80;
      --shadow-sm: 0 1px 2px rgba(2, 6, 23, .5);
      --shadow-md: 0 10px 28px -12px rgba(2, 6, 23, .6);
      --shadow-lg: 0 24px 70px rgba(2, 6, 23, .6);
      --shadow-card: inset 0 1px 0 rgba(255, 255, 255, .035), 0 16px 36px -20px rgba(2, 6, 23, .75);
      --shadow-pop: 0 28px 70px -16px rgba(2, 6, 23, .85);
      --glass: rgba(15, 23, 42, .72);
      --glass-line: rgba(148, 163, 184, .13);
      --ambient: radial-gradient(60% 60% at 10% -10%, rgba(34, 197, 94, .17), transparent 72%), radial-gradient(48% 52% at 92% -8%, rgba(96, 165, 250, .13), transparent 72%);
      --grid-dot: rgba(148, 163, 184, .15);
      --glow-brand: 0 10px 26px -10px rgba(34, 197, 94, .60);
      --btn-sheen: inset 0 1px 0 rgba(255, 255, 255, .30);
      --seg-track: #0C1427;
      --seg-thumb: #25335A;

      --aside-bg: linear-gradient(160deg, #0F172A 0%, #0B2A33 100%);
      --aside-text: #F8FAFC;
      --aside-muted: #A9B8CC;
      --aside-line: rgba(148, 163, 184, .22);

      --coin-bg: #1A2540;
      --coin-ring: rgba(255, 255, 255, .12);
  }
}

/* ── Base ─────────────────────────────────────────────────────────────────────────────────────── */

/* The canvas colour also shows during overscroll and before the body paints. */
html { background: var(--bg); }

::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }

/* One consistent, visible keyboard focus ring everywhere. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Themed, unobtrusive scrollbars (Firefox + WebKit/Blink). */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

/* Native controls follow the theme (date pickers, selects, autofill). */
input, select, textarea { color-scheme: inherit; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 82%, transparent); }

/* Switching theme crossfades the whole page with one snapshot (View Transitions), which stays smooth on
   large tables. Browsers without it switch instantly. */
@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: .22s; animation-timing-function: ease; }
}
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* ── Brand typography ─────────────────────────────────────────────────────────────────────────── */

/* Persian text uses Vazirmatn everywhere; neither brand face has Persian glyphs. */
html[lang="fa"] { --font-sans: "Vazirmatn", Tahoma, "Segoe UI", Arial, sans-serif; --font-display: var(--font-sans); }

body { font-family: var(--font-sans); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
button, input, select, textarea { font-family: inherit; }
h1, h2, h3, h4, .brand, .workspace-metrics strong { font-family: var(--font-display); }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
/* Prices and percentages line up in columns. */
td, th { font-variant-numeric: tabular-nums; }

/* ── Logo ─────────────────────────────────────────────────────────────────────────────────────── */

/* Two files (navy wordmark for light, white wordmark for dark); the theme decides which one shows. The kit's
   minimum for the horizontal logo is 120px wide, hence the 34px height (≈123px). */
.brand-logo { display: block; height: 34px; width: auto; }
.brand-logo-dark { display: none; }
:root[data-theme="dark"] .brand-logo-light { display: none; }
:root[data-theme="dark"] .brand-logo-dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .brand-logo-light { display: none; }
  :root:not([data-theme]) .brand-logo-dark { display: block; }
}
.login-top .brand-logo { height: 40px; }

/* ── Icons ────────────────────────────────────────────────────────────────────────────────────── */

/* Every icon is <svg class="ico"><use href="#i-name"/></svg> from templates/icons.html; it inherits the text colour. */
.ico { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.2em; }

/* ── Theme switch (header and sign-in pages) ──────────────────────────────────────────────────── */

.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel2);
}
.theme-switch button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s ease, background-color .15s ease, box-shadow .15s ease;
}
.theme-switch button:hover { color: var(--text-strong); }
.theme-switch button[aria-checked="true"] {
  background: var(--panel);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--line-strong), var(--shadow-sm);
}
.theme-switch button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.theme-switch svg { width: 15px; height: 15px; display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Sign-in / sign-up pages have no header, so the switch floats in the corner. */
.auth-theme { position: fixed; top: 16px; inset-inline-end: 16px; z-index: 30; }

/* ── Appearance cards (Settings) ──────────────────────────────────────────────────────────────── */

.appearance { margin: 0 0 26px; padding: 0; border: 0; min-width: 0; }
.appearance > legend { padding: 0; margin-bottom: 4px; font-weight: 600; color: var(--text); }
.appearance > p { margin: 0 0 12px; color: var(--muted); font-size: 12px; }
.appearance-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.appearance-card {
  display: grid;
  gap: 10px;
  padding: 10px 10px 12px;
  text-align: start;
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.appearance-card:hover { border-color: var(--line-strong); }
.appearance-card[aria-checked="true"] { border-color: var(--accent); box-shadow: var(--focus-ring); }
.appearance-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.appearance-name { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 13px; }
.appearance-name::after {
  content: "";
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--line-strong);
  box-sizing: border-box;
}
.appearance-card[aria-checked="true"] .appearance-name::after {
  border-color: var(--accent);
  background: radial-gradient(circle, var(--accent) 0 38%, transparent 42%);
}
.appearance-hint { color: var(--muted); font-size: 11px; line-height: 1.4; }

/* A miniature window that always shows the theme it represents, whatever the current theme is.
   "System" stacks a light and a dark layer and clips the dark one to the right half. */
.appearance-preview {
  display: block;
  position: relative;
  height: 74px;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.pv-layer {
  --pv-bg: #f6f8fa; --pv-panel: #ffffff; --pv-line: #dbe2e8; --pv-text: #0f1c24; --pv-muted: #c4cdd6; --pv-accent: #0a7a50;
  position: absolute;
  inset: 0;
  display: block;
  background: var(--pv-bg);
}
.pv-layer.is-dark { --pv-bg: #0c1014; --pv-panel: #11171d; --pv-line: #242d36; --pv-text: #edf2f5; --pv-muted: #33404c; --pv-accent: #80efb7; }
.pv-layer.is-half { clip-path: inset(0 0 0 50%); }
.pv-layer i { position: absolute; display: block; border-radius: 3px; }
.pv-bar { inset: 0 0 auto 0; height: 14px; background: var(--pv-panel); border-bottom: 1px solid var(--pv-line); border-radius: 0 !important; }
.pv-dot { top: 4px; left: 8px; width: 6px; height: 6px; border-radius: 50% !important; background: var(--pv-accent); }
.pv-card { left: 8px; right: 8px; top: 22px; height: 44px; background: var(--pv-panel); border: 1px solid var(--pv-line); border-radius: 5px !important; }
.pv-line { left: 16px; height: 5px; background: var(--pv-muted); }
.pv-l1 { top: 30px; width: 46%; background: var(--pv-text) !important; opacity: .75; }
.pv-l2 { top: 41px; width: 70%; }
.pv-l3 { top: 51px; width: 34%; background: var(--pv-accent) !important; }

@media (max-width: 560px) {
  .appearance-grid { grid-template-columns: 1fr; }
  .appearance-card { grid-template-columns: 96px 1fr; align-items: center; }
  .appearance-preview { height: 56px; }
}
