/* =========================
   301.st – THEME TOKENS
   - Цвета
   - Типографика
   - Базовые переменные
   ========================= */

/*!
 * UI System 1.0 — Unified control recipe
 * This file defines the single source of truth for control sizing.
 * All interactive components MUST consume these tokens. Do not override
 * padding/height in variants (primary/ghost/danger/social/chips).
 */

:root {
  color-scheme: dark;

  /* Blues (primary brand) */
  --blue-900: #003682;
  --blue-700: #0055DC;
  --blue-500: #3475C0;
  --blue-300: #408BC9;
  --blue-neon: #4DA3FF;

  /* Oranges (Cloudflare-ish family) */
  --orange-500: #F48120;
  --orange-700: #F38020;
  --orange-900: #C65000;

  /*
    Cloudflare CTA accent.

    Chosen to keep CF vibe but pass WCAG AA with WHITE text:
    - #C24F00 on #FFFFFF ≈ 4.76:1
    - #C24F00 on #000000 ≈ 4.41:1
  */
  --accent-cf: #C24F00;
  --accent-cf-hover: #E05A00;
  --accent-cf-soft: rgba(244, 129, 32, 0.16);

  /* Neutrals */
  --gray-950: #000000;
  --gray-900: #111111;
  --gray-800: #222222;
  --gray-700: #333333;
  --gray-600: #404242;
  --gray-500: #424242;
  --gray-400: #808080;

  --gray-50:  #F8FBFB;
  --gray-100: #F7F7F8;
  --gray-200: #F4F8FC;
  --gray-250: #EAEBEB;
  --gray-300: #E5E5E4;
  --gray-350: #CAC8C8;

  /* Semantic */
  --danger: #FF4F6E;
  /* Solid red for FILLS under white text, in both themes: white on #D9264A is
     4.86:1. --danger (#FF4F6E here) is for red text and icons on dark; white on
     it is 3.18:1 — the dark-theme .btn--danger failed AA (301-ui#276). */
  --danger-solid: #D9264A;
  --success: #18C27A;
  --warning: #FFB347;
  --info: #3B82F6;

  /* Typography */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", sans-serif;
  /* Was used by name with differing fallbacks and never defined (301-ui#276). */
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  /* Text line height. `normal` is the font's own: ~1.31 with Segoe UI, ~1.2
     with SF and Roboto, so the same page was denser on a Mac or a phone. 1.35
     keeps the Windows look and gives it to every platform (owner, 2026-11-09). */
  --lh-body: 1.35;

  /* Unified control system — font-driven sizing */
  --fs-control: clamp(0.94rem, 0.92rem + 0.2vw, 0.98rem);
  --lh-control: 1.25;

  /* Control spacing (relative, no px) */
  --control-pad-y: 0.35em;
  --control-pad-x: 0.90em;
  --border-1: 1px;
  --indicator-thickness: 1px; /* For loading bar & global notice border */
  --control-min-height: calc(
    1em * var(--lh-control) +
    2 * var(--control-pad-y) +
    2 * var(--border-1)
  );

  /* Radius & layout spacing */
  --r-pill: 999px;
  --r-field: 0.75rem;
  --control-radius: var(--r-pill);
  --inline-gap: 0.5rem;
  --stack-gap: 0.75rem;

  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;

  --fw-normal: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* Spacing & radii */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  /* Control sizing */
  --control-scale-sm: 0.9;
  --control-scale-lg: 1.1;

  --radius-xs: 0.25rem;
  --radius: 0.5rem;
  --radius-lg: 0.75rem;

  --border-width-thin: 1px;
  --border-width-strong: 1px;

  --shadow-sm-light: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md-light: 0 6px 18px rgba(0, 0, 0, 0.12);
  --shadow-lg-light: 0 18px 45px rgba(0, 0, 0, 0.25);

  --shadow-sm-dark: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-md-dark: 0 6px 18px rgba(0, 0, 0, 0.45);
  --shadow-lg-dark: 0 18px 45px rgba(0, 0, 0, 0.65);

  --shadow-sm: var(--shadow-sm-light);
  --shadow-md: var(--shadow-md-light);
  --shadow-lg: var(--shadow-lg-light);

  --shadow-soft:   0 1px 3px  color-mix(in srgb, var(--gray-900) 18%, transparent),
                   0 1px 2px  color-mix(in srgb, var(--gray-900) 22%, transparent);
  --shadow-subtle: 0 3px 6px  color-mix(in srgb, var(--gray-900) 16%, transparent),
                   0 1px 4px  color-mix(in srgb, var(--gray-900) 20%, transparent);

  --border-width: 1px;
  --border-style: solid;

  --transition-fast: 120ms ease-out;
  --transition-md: 160ms ease-out;

  /* Z-index scale - ascending order */
  --z-base: 1;           /* Base elevated elements (utility-bar) */
  --z-indicator: 2;      /* Visual indicators (loading-bar, logo overlay) */
  --z-elevated: 10;      /* Elevated UI elements */
  --z-dropdown: 20;      /* Dropdowns, popovers */
  --z-sticky: 30;        /* Sticky headers */
  --z-global-notice: 100; /* Global alerts (covers utility-bar content) */
  --z-sidebar: 100;      /* Sidebar navigation */
  --z-sidebar-overlay: 99; /* Sidebar backdrop */
  --z-header: 200;       /* Main header (above sidebar) */
  --z-drawer: 1000;      /* Drawers base (stacked: +10 per level via drawer-manager) */
  --z-modal: 2000;       /* Modals, dialogs (above all drawers) */
  --z-toast: 2100;       /* Toast notifications (above modals) */
  --z-tooltip: 2200;     /* Tooltips (topmost) */

  /* High-contrast text for buttons / chips on dark backgrounds */
  --btn-text-on-dark: #FFFFFF;
  --btn-text-on-bright: #111111;
}

/* DARK THEME – default */
:root[data-theme="dark"] {
  --bg: #111111;
  --bg-elevated: #181A1F;
  --bg-soft: #1F2229;

  /* Decorative mesh (trigons-lite). Its own tokens rather than reusing the
     surfaces, because the two themes need opposite treatment and the library's
     fake lighting only ever darkens: on a near-black palette it has nothing to
     work with, on a near-white one it overshoots into mid grey. So the contrast
     lives here, in the palette, and `depth` stays near zero.
     Measured luminance spread of the rendered mesh: 0.018 (--bg is 0.006). */
  --mesh-1: #111111;
  --mesh-2: #1C1F26;
  --mesh-3: #282D38;

  /* Seamless triangle tile for `.surface-mesh`. Baked, not computed: the tile
     is a deterministic 219-byte SVG — a square with one diagonal — so asking
     the browser to load a library and build it at runtime would buy nothing.
     Regenerate with:
       node -e "global.window={};require('trigons-lite/trigons-lite.min.js');
                console.log(window.TrigonsLite.pattern({size:44,color:'#4DA3FF',opacity:0.07}))" */
  --mesh-tile: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22https%3A%2F%2Fsiteproxy.ruqli.workers.dev%3A443%2Fhttp%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2244%22%20height%3D%2244%22%20viewBox%3D%220%200%2044%2044%22%3E%3Cpath%20d%3D%22M0%200L44%200M0%2044L44%2044M0%200L0%2044M44%200L44%2044M44%200L0%2044%22%20fill%3D%22none%22%20stroke%3D%22%234DA3FF%22%20stroke-width%3D%221%22%20stroke-opacity%3D%220.07%22%2F%3E%3C%2Fsvg%3E");

  /* Status panel fill strength — semantic corner glow over a neutral surface.
     Kept low so the status colour signals state without dominating the fill. */
  --panel-glow: 16%;
  --panel-tint: 7%;

  --panel: var(--bg-elevated);

  --panel-border: color-mix(in srgb, var(--gray-100) 22%, transparent);

  --text-main: #E7E9EE;
  --text-muted: #A0A4AF;
  --text-subtle: #8B8F98; /* Brightened for AA on bg-elev/bg-soft (was #7A7E87 → 3.9:1) */

  --text: var(--text-main);
  --muted: var(--text-muted);

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.14);
  --shadow-sm: var(--shadow-sm-dark);
  --shadow-md: var(--shadow-md-dark);
  --shadow-lg: var(--shadow-lg-dark);
  --shadow-soft:   0 1px 3px  color-mix(in srgb, var(--gray-700) 14%, var(--blue-900) 8%),
                   0 1px 2px  color-mix(in srgb, var(--gray-700) 18%, var(--blue-900) 6%);

  --shadow-subtle: 0 3px 6px  color-mix(in srgb, var(--gray-700) 12%, var(--blue-900) 10%),
                   0 1px 4px  color-mix(in srgb, var(--gray-700) 16%, var(--blue-900) 8%);
  /*
    Primary uses blue-500:
    - #3475C0 with white text ≈ 4.72:1 (AA for normal text).
  */
  --primary: #3475C0;
  --primary-soft: rgba(77, 163, 255, 0.1);
  --primary-hover: #4DA3FF;

  --ok: var(--success);

  --brand: var(--primary);

  /*
    Cloudflare accent = shared accent-cf.
    White text passes AA.
  */
  --accent-cf-bg: var(--accent-cf);
  --accent-cf-bg-hover: var(--accent-cf-hover);

  /* Status backgrounds (solid for predictable contrast) */
  --bg-danger: #3D0915;
  --bg-success: #042C1C;

  --input-bg: rgba(15, 16, 22, 0.9);
  --input-border: var(--border-strong);
  --input-border-focus: rgba(77, 163, 255, 0.8);

  /* Search-hit highlight (<mark>) — warm amber, distinct from blue hover/selection */
  --mark-bg: rgba(240, 180, 70, 0.26);
  --mark-fg: var(--text-main);
}

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

  --bg: #FFFFFF;
  --bg-elevated: #F7F7F8;
  --bg-soft: #F4F8FC;

  /* See the dark block for why the mesh has its own tokens. Here the palette
     steps down from white instead of up from black; rendered spread 0.186. */
  --mesh-1: #FFFFFF;
  --mesh-2: #F7F9FC;
  --mesh-3: #EDF1F7;

  /* Same tile, darker stroke: a light-blue line is invisible on white. See the
     dark block for the regenerating command. */
  --mesh-tile: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22https%3A%2F%2Fsiteproxy.ruqli.workers.dev%3A443%2Fhttp%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2244%22%20height%3D%2244%22%20viewBox%3D%220%200%2044%2044%22%3E%3Cpath%20d%3D%22M0%200L44%200M0%2044L44%2044M0%200L0%2044M44%200L44%2044M44%200L0%2044%22%20fill%3D%22none%22%20stroke%3D%22%230055DC%22%20stroke-width%3D%221%22%20stroke-opacity%3D%220.05%22%2F%3E%3C%2Fsvg%3E");

  /* Status panel fill — softer on light so the surface stays near-neutral
     (not a saturated alert plate). */
  --panel-glow: 10%;
  --panel-tint: 4%;

  --panel: var(--bg-elevated);

  --panel-border: color-mix(in srgb, var(--gray-900) 18%, transparent);

  --text-main: #111111;
  --text-muted: #666A73;
  --text-subtle: #6E7580; /* Darkened for AA on white (was #8A8F99 → 3.25:1) */

  --text: var(--text-main);
  --muted: var(--text-muted);

  --border-subtle: rgba(15, 23, 42, 0.06);
  --border-strong: rgba(15, 23, 42, 0.16);
  --shadow-sm: var(--shadow-sm-light);
  --shadow-md: var(--shadow-md-light);
  --shadow-lg: var(--shadow-lg-light);

  /*
    Primary uses blue-700:
    - #0055DC with white text ≈ 6.30:1 (AA).
  */
  --primary: #0055DC;
  --primary-soft: rgba(0, 85, 220, 0.08);
  --primary-hover: #003682; /* even higher contrast */

  --brand: var(--primary);

  /*
    Light-theme semantic overrides — darker for AA 4.5:1 on white.
    Shared :root values (#FF4F6E, #18C27A, #FFB347, #3B82F6) are tuned for dark bg;
    these replacements keep the hue but pass contrast on light backgrounds.
  */
  --danger:  #D9264A; /* 4.86:1 on #FFF (was #FF4F6E → 3.18:1) */
  --success: #0E7B4C; /* 5.31:1 on #FFF (was #18C27A → 2.32:1) */
  --warning: #9A6200; /* 5.09:1 on #FFF (was #FFB347 → 1.78:1) */
  --info:    #2563EB; /* 5.14:1 on #FFF (was #3B82F6 → 3.68:1) */
  --ok: var(--success);

  /*
    Cloudflare accent = same accent-cf to keep brand consistent.
  */
  --accent-cf-bg: var(--accent-cf);
  --accent-cf-bg-hover: var(--accent-cf-hover);

  --bg-danger: #FDE6EA;
  --bg-success: #E0F7EE;

  --input-bg: #FFFFFF;

  /* Search-hit highlight (<mark>) — classic yellow, AA-legible on light surfaces */
  --mark-bg: rgba(255, 209, 64, 0.55);
  --mark-fg: var(--text-main);
  --input-border: var(--border-strong);
  --input-border-focus: rgba(0, 85, 220, 0.8);
}

/* Глобальные мелочи */

a {
  color: inherit;
}

.border {
  border: var(--border-width) var(--border-style) currentColor;
  opacity: 0.28;
}
