/* ==========================================================================
   SKM SCADA — operator design system · tokens
   Source of truth for colour, type, spacing, radii, elevation, materials, motion.
   Brand values traced to the owner's exports:
     #E30613  logo red / login card base   (Вход в систему.svg, fill="#E30613" @ .53)
     #A23A3A  "SKM SCADA SYSTEMS" wordmark  (Вход в систему.svg, fill="#A23A3A")
     #6B6262  input fill on brand card @ .2 (Вход в систему.svg)
   Guidance: apple-design-foundations (semantic colour, 8pt grid, 44pt targets),
   apple-design-materials (Liquid Glass web approximation + fallbacks),
   apple-design-tactics (WCAG 2.2 AA, reduce-motion/transparency/contrast).
   Switches on <html> (set by components.js, persisted, default = OS setting):
     data-theme="light|dark", data-transparency="reduce",
     data-motion="reduce", data-contrast="more".
   The OS media queries below apply even without JS.
   ========================================================================== */

:root {
  color-scheme: light;

  /* ---- Brand palette (raw; use semantic tokens in components) ---------- */
  --skm-red-logo: #E30613;
  --skm-red-700: #A23A3A;   /* wordmark, brand text — 6.6:1 on white */
  --skm-red-600: #A15257;   /* login card = #E30613@.53 + black@.33 over white */
  --skm-red-500: #B0585C;   /* selected tab / group — white text 4.8:1 */
  --skm-red-300: #DDB0B0;   /* user pill */
  --skm-red-200: #EBCFCF;   /* table header chips */
  --skm-red-100: #F7ECEC;   /* subtle brand wash */

  --gray-0: #FFFFFF;
  --gray-50: #F7F7F8;
  --gray-100: #EFEFEF;      /* panel grey from exports */
  --gray-200: #E5E5E5;      /* toggle track (кнопка_выкл.svg) */
  --gray-300: #D6D6D6;      /* control grey */
  --gray-400: #B8B8BC;
  --gray-500: #8E8E93;
  --gray-600: #6E6E73;
  --gray-700: #48484A;
  --gray-900: #1C1C1E;

  /* ---- Semantic colour ------------------------------------------------- */
  --bg: var(--gray-0);
  --bg-grouped: var(--gray-50);
  --bg-elevated: var(--gray-0);
  --bg-sunken: var(--gray-100);
  --scrim: rgba(28, 28, 30, 0.32);

  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.85);   /* 8.9:1 */
  --label-3: #636368;                  /* 5.97:1 on white, 5.19:1 on #EFEFEF — placeholders, captions */
  --label-on-brand: #FFFFFF;
  --label-on-brand-2: rgba(255, 255, 255, 0.86);

  --separator: rgba(0, 0, 0, 0.18);
  --separator-strong: #000000;          /* the exports' 1px black rules */

  --fill-1: rgba(120, 120, 128, 0.20);
  --fill-2: rgba(120, 120, 128, 0.14);
  --fill-3: rgba(120, 120, 128, 0.08);

  --brand: var(--skm-red-500);
  --brand-strong: var(--skm-red-600);
  --brand-text: var(--skm-red-700);
  --brand-soft: var(--skm-red-300);
  --brand-subtle: var(--skm-red-200);
  --brand-wash: var(--skm-red-100);
  --brand-logo: var(--skm-red-logo);

  --focus-ring: #1F5FBF;               /* distinct from brand red so focus ≠ selection/error */

  /* ---- SCADA status (never colour alone: always icon + text) ------------ */
  --status-alarm: #C4000F;     --status-alarm-bg: #FDE7E8;
  --status-warning: #8A4F00;   --status-warning-bg: #FFF1D6;
  --status-ok: #1E7B34;        --status-ok-bg: #E3F4E7;
  --status-offline: #5E5E63;   --status-offline-bg: #EDEDEF;
  --status-ack: #2F5E93;       --status-ack-bg: #E5EEF8;
  --danger: #C4000F;           /* login error text — 5.7:1 on white */

  /* ---- Typography ------------------------------------------------------ */
  --font-sans: -apple-system, BlinkMacSystemFont, system-ui, "SF Pro Text", "Segoe UI Variable", "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, system-ui, "SF Pro Display", "Segoe UI Variable Display", "Segoe UI", Inter, Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;

  --text-caption: 0.75rem;    /* 12 */
  --text-footnote: 0.8125rem; /* 13 */
  --text-subhead: 0.9375rem;  /* 15 */
  --text-body: 1.0625rem;     /* 17 */
  --text-headline: 1.0625rem; /* 17 semibold */
  --text-title3: 1.25rem;     /* 20 */
  --text-title2: 1.375rem;    /* 22 */
  --text-title1: 1.75rem;     /* 28 */
  --text-large: 2.125rem;     /* 34 — wordmark */

  --leading-tight: 1.2;
  --leading-normal: 1.4;
  --tracking-display: -0.01em;
  --tracking-body: 0;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* ---- Spacing (8pt grid, 4pt half steps) ------------------------------ */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 40px;
  --space-8: 48px;
  --space-9: 64px;

  /* ---- Sizing ---------------------------------------------------------- */
  --size-target: 44px;         /* min hit area */
  --size-icon: 24px;
  --size-avatar: 40px;
  --size-control: 44px;
  --size-control-lg: 52px;
  --topbar-h: 80px;            /* exports: rule at y=79.5 */
  --sidebar-w: 286px;          /* exports: sidebar ≈ 286px */

  /* ---- Radii ----------------------------------------------------------- */
  --r-xs: 8px;
  --r-field: 16px;
  --r-card: 40px;              /* scheme cards in exports */
  --r-panel: 32px;             /* alarm panel */
  --r-modal: 48px;             /* settings / account modal */
  --r-window: 60px;            /* app frame (Главное меню.svg: 60) */
  --r-capsule: 999px;          /* tabs, pills, buttons, fields */

  /* ---- Elevation ------------------------------------------------------- */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-2: 0 4px 12px rgba(0, 0, 0, 0.08), 0 12px 32px rgba(0, 0, 0, 0.10);
  --shadow-3: 0 12px 40px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-text: 0 1px 2px rgba(0, 0, 0, 0.18);  /* exports use soft text shadow on card titles */

  /* ---- Materials: Liquid Glass web approximation ------------------------
     Glass is only for chrome (top bar, sidebar, modal, segmented controls).
     Content (cards, tables, forms) stays opaque. Never glass on glass. */
  --glass-thin-fill: rgba(255, 255, 255, 0.55);
  --glass-thin-blur: blur(8px) saturate(140%);
  --glass-regular-fill: rgba(255, 255, 255, 0.62);
  --glass-regular-blur: blur(20px) saturate(170%);
  --glass-thick-fill: rgba(250, 248, 248, 0.74);
  --glass-thick-blur: blur(32px) saturate(180%);
  --glass-brand-fill: rgba(161, 82, 87, 0.94);       /* tinted glass: primary surfaces only; .94 keeps white text ≥4.5:1 over the light backdrop */
  --glass-brand-blur: blur(20px) saturate(160%);
  --glass-border: rgba(255, 255, 255, 0.65);
  --glass-edge: inset 0 1px 0 rgba(255, 255, 255, 0.75);
  --glass-hairline: rgba(0, 0, 0, 0.10);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.05);
  --glass-highlight: radial-gradient(ellipse 80% 50% at 30% 0%, rgba(255, 255, 255, 0.45) 0%, transparent 70%);

  /* Living backdrop: gives glass something to sample (brand-tinted, quiet) */
  --backdrop-mesh:
    radial-gradient(ellipse 60% 50% at 85% 0%, rgba(227, 6, 19, 0.10) 0%, transparent 70%),
    radial-gradient(ellipse 55% 45% at 5% 10%, rgba(176, 88, 92, 0.12) 0%, transparent 65%),
    radial-gradient(ellipse 50% 50% at 50% 100%, rgba(160, 170, 190, 0.16) 0%, transparent 70%),
    var(--bg-grouped);

  /* ---- Motion ---------------------------------------------------------- */
  --dur-instant: 80ms;
  --dur-fast: 120ms;
  --dur-base: 200ms;
  --dur-slow: 320ms;
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.36, 0.64, 1);  /* spring-like overshoot for toggles/thumbs */
  --press-scale: 0.97;

  /* ---- Focus ----------------------------------------------------------- */
  --focus-width: 3px;
  --focus-offset: 2px;

  /* ---- Breakpoints (documentation; use in media queries) ---------------
     xl ≥1440 (design) · lg 1280 · md 1024 (sidebar → overlay) · sm 768 (1 column) */
}

/* ------------------------------------------------------------------------
   Dark theme — dimming, not inverting; elevated surfaces get lighter.
   Toggled by the settings switch "Тёмная тема" (data-theme="dark").
   ------------------------------------------------------------------------ */
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0F0F11;
  --bg-grouped: #151517;
  --bg-elevated: #1E1E21;
  --bg-sunken: #0A0A0B;
  --scrim: rgba(0, 0, 0, 0.55);

  --label: #F5F5F7;
  --label-2: rgba(235, 235, 245, 0.80);
  --label-3: rgba(235, 235, 245, 0.62);

  --separator: rgba(255, 255, 255, 0.16);
  --separator-strong: rgba(255, 255, 255, 0.55);

  --fill-1: rgba(120, 120, 128, 0.36);
  --fill-2: rgba(120, 120, 128, 0.28);
  --fill-3: rgba(120, 120, 128, 0.20);

  --brand: #B0585C;
  --brand-strong: #96474C;
  --brand-text: #F09A9D;      /* 7.4:1 on #0F0F11 */
  --brand-soft: #5A3436;
  --brand-subtle: #4A2C2E;
  --brand-wash: #2A1C1D;

  --focus-ring: #7FB0FF;

  --status-alarm: #FF6B70;    --status-alarm-bg: #3A1416;
  --status-warning: #FFB44D;  --status-warning-bg: #36260C;
  --status-ok: #5FD07A;       --status-ok-bg: #12301A;
  --status-offline: #A1A1A6;  --status-offline-bg: #26262A;
  --status-ack: #8DB8F0;      --status-ack-bg: #172739;
  --danger: #FF6B70;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 4px 12px rgba(0, 0, 0, 0.45), 0 12px 32px rgba(0, 0, 0, 0.45);
  --shadow-3: 0 12px 40px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-text: none;

  --glass-thin-fill: rgba(40, 40, 44, 0.55);
  --glass-regular-fill: rgba(32, 32, 36, 0.62);
  --glass-thick-fill: rgba(28, 28, 32, 0.76);
  --glass-brand-fill: rgba(150, 71, 76, 0.86);
  --glass-border: rgba(255, 255, 255, 0.14);
  --glass-edge: inset 0 1px 0 rgba(255, 255, 255, 0.10);
  --glass-hairline: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.3);
  --glass-highlight: radial-gradient(ellipse 80% 50% at 30% 0%, rgba(255, 255, 255, 0.08) 0%, transparent 70%);

  --backdrop-mesh:
    radial-gradient(ellipse 60% 50% at 85% 0%, rgba(227, 6, 19, 0.16) 0%, transparent 70%),
    radial-gradient(ellipse 55% 45% at 5% 10%, rgba(176, 88, 92, 0.18) 0%, transparent 65%),
    radial-gradient(ellipse 50% 50% at 50% 100%, rgba(60, 80, 120, 0.22) 0%, transparent 70%),
    var(--bg-grouped);
}

/* ------------------------------------------------------------------------
   Reduce transparency — glass becomes opaque. REQUIRED fallback.
   ------------------------------------------------------------------------ */
@media (prefers-reduced-transparency: reduce) {
  /* :not() lifts specificity to (0,2,0) so this also beats [data-theme="dark"] */
  :root:not([data-transparency="allow"]) {
    --glass-thin-blur: none;
    --glass-regular-blur: none;
    --glass-thick-blur: none;
    --glass-brand-blur: none;
    --glass-thin-fill: var(--bg-elevated);
    --glass-regular-fill: var(--bg-elevated);
    --glass-thick-fill: var(--bg-elevated);
    --glass-brand-fill: var(--brand-strong);
    --glass-highlight: none;
    --glass-border: var(--separator);
  }
}
:root[data-transparency="reduce"] {
  --glass-thin-blur: none;
  --glass-regular-blur: none;
  --glass-thick-blur: none;
  --glass-brand-blur: none;
  --glass-thin-fill: var(--bg-elevated);
  --glass-regular-fill: var(--bg-elevated);
  --glass-thick-fill: var(--bg-elevated);
  --glass-brand-fill: var(--brand-strong);
  --glass-highlight: none;
  --glass-border: var(--separator);
}

/* ------------------------------------------------------------------------
   Increase contrast — solid surfaces, strong borders.
   ------------------------------------------------------------------------ */
@media (prefers-contrast: more) {
  :root:not([data-contrast="no-preference"]) {
    --label-2: var(--label);
    --label-3: var(--label);
    --separator: var(--separator-strong);
    --glass-border: var(--separator-strong);
    --glass-thin-fill: var(--bg-elevated);
    --glass-regular-fill: var(--bg-elevated);
    --glass-thick-fill: var(--bg-elevated);
  }
}
:root[data-contrast="more"] {
  --label-2: var(--label);
  --label-3: var(--label);
  --separator: var(--separator-strong);
  --glass-border: var(--separator-strong);
  --glass-thin-fill: var(--bg-elevated);
  --glass-regular-fill: var(--bg-elevated);
  --glass-thick-fill: var(--bg-elevated);
}

/* ------------------------------------------------------------------------
   Reduce motion — no springs, no scale; fades only.
   ------------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-fast: 1ms;
    --dur-base: 1ms;
    --dur-slow: 1ms;
    --ease-spring: linear;
    --press-scale: 1;
  }
}
:root[data-motion="reduce"] {
  --dur-fast: 1ms;
  --dur-base: 1ms;
  --dur-slow: 1ms;
  --ease-spring: linear;
  --press-scale: 1;
}
