/* ==========================================================================
   PingByte design tokens: the ONE source of truth for the public website, the
   store, the Customer Panel and the Admin Panel.

   Source file: frontend/src/design/tokens.css. The public website is static
   (not built by Vite), so it uses a copy at site/assets/tokens.css; keep them
   identical with `deploy/sync-design-tokens.sh` (CI/deploy check: `--check`).

   Naming: --pb-<group>-<name>. Brand yellow is a FILL colour (primary buttons,
   active markers, key numbers); text that needs the accent uses
   --pb-accent-text, which is darker in the light theme so it stays readable.
   Status colours (ok / warn / danger / info) are reserved for real states and
   mean the same thing on every surface. Themes are selected by
   :root[data-theme='dark'|'light'], set before first paint by /theme.js from
   localStorage "pb-theme" (or the device setting): no flash.

   Older names (--bg, --surface, --border, --cp-*, ...) are kept as aliases at
   the bottom so existing styles keep working; new code should use --pb-*.
   ========================================================================== */

/* ───────── typography, spacing, shape, motion (theme-independent) ───────── */
:root {
  /* families (Inter + Space Grotesk are loaded by the pages; system fallbacks follow) */
  --pb-font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --pb-font-display: 'Space Grotesk', 'Inter', system-ui, sans-serif;
  --pb-font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', 'JetBrains Mono', Consolas, monospace;

  /* type scale */
  --pb-text-xs: 0.75rem;     /* 12px captions, table headers */
  --pb-text-sm: 0.8125rem;   /* 13px secondary text, dense admin */
  --pb-text-base: 0.875rem;  /* 14px panel body */
  --pb-text-md: 0.9375rem;   /* 15px inputs, marketing body-small */
  --pb-text-lg: 1.0625rem;   /* 17px card titles */
  --pb-text-xl: 1.25rem;     /* 20px section headings */
  --pb-text-2xl: 1.5rem;     /* 24px page titles */
  --pb-text-3xl: 1.875rem;   /* 30px */
  --pb-text-4xl: 2.5rem;     /* 40px marketing display */
  --pb-weight-regular: 400;
  --pb-weight-medium: 500;
  --pb-weight-semibold: 600;
  --pb-weight-bold: 700;
  --pb-weight-extrabold: 800;
  --pb-leading-tight: 1.15;
  --pb-leading-snug: 1.3;
  --pb-leading-normal: 1.5;
  --pb-leading-relaxed: 1.65;
  --pb-tracking-tight: -0.02em;
  --pb-tracking-normal: 0;
  --pb-tracking-wide: 0.06em;

  /* spacing: a 4px scale */
  --pb-space-1: 0.25rem;  /* 4  */
  --pb-space-2: 0.5rem;   /* 8  */
  --pb-space-3: 0.75rem;  /* 12 */
  --pb-space-4: 1rem;     /* 16 */
  --pb-space-5: 1.25rem;  /* 20 */
  --pb-space-6: 1.5rem;   /* 24 */
  --pb-space-8: 2rem;     /* 32 */
  --pb-space-10: 2.5rem;  /* 40 */
  --pb-space-12: 3rem;    /* 48 */
  --pb-space-16: 4rem;    /* 64 */

  /* radii */
  --pb-radius-xs: 4px;    /* chips, tiny marks */
  --pb-radius-sm: 6px;    /* small controls, menu items */
  --pb-radius-md: 10px;   /* buttons, inputs, tiles */
  --pb-radius-lg: 14px;   /* cards, panels */
  --pb-radius-xl: 18px;   /* dialogs */
  --pb-radius-pill: 999px;

  /* component heights */
  --pb-control-h-sm: 32px;
  --pb-control-h-dense: 34px;   /* admin */
  --pb-control-h: 40px;
  --pb-control-h-touch: 44px;   /* used on phones (minimum comfortable touch target) */
  --pb-topbar-h: 58px;
  --pb-topbar-h-dense: 52px;    /* admin */
  --pb-sidebar-w: 256px;
  --pb-sidebar-w-dense: 236px;  /* admin */
  --pb-sidebar-w-rail: 68px;

  /* breakpoints (documentation: CSS media queries cannot read custom properties;
     the same numbers are exported to scripts from src/design/breakpoints.ts) */
  --pb-bp-sm: 480px;
  --pb-bp-md: 768px;    /* below: phone layout */
  --pb-bp-lg: 1100px;   /* below: tablet rail; at/above: desktop sidebar */
  --pb-bp-xl: 1440px;

  /* motion */
  --pb-dur-fast: 120ms;
  --pb-dur-base: 180ms;
  --pb-dur-slow: 280ms;
  --pb-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --pb-ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

  /* layering */
  --pb-z-sticky: 30;
  --pb-z-drawer: 40;
  --pb-z-dropdown: 60;
  --pb-z-modal: 1000;
  --pb-z-toast: 1100;

  /* focus */
  --pb-focus-width: 2px;
  --pb-focus-offset: 2px;
}

/* ───────── dark theme (default) ───────── */
:root,
:root[data-theme='dark'] {
  color-scheme: dark;

  /* surfaces */
  --pb-bg: #0a0a0d;
  --pb-bg-side: #0d0d11;
  --pb-surface: #121217;
  --pb-surface-raised: #18181f;
  --pb-surface-sunken: #0c0c10;
  --pb-surface-hover: #20202a;
  --pb-line: rgba(255, 255, 255, 0.075);
  --pb-line-strong: rgba(255, 255, 255, 0.15);
  --pb-overlay: rgba(5, 5, 8, 0.62);

  /* text */
  --pb-text: #ececf0;
  --pb-text-muted: #a0a0ac;
  --pb-text-faint: #8c8c98;
  --pb-text-disabled: #5d5d68;

  /* brand */
  --pb-accent: #f5d400;
  --pb-accent-hover: #ffdf33;
  --pb-accent-dim: #b89e00;
  --pb-accent-ink: #15130a;       /* text on an accent fill */
  --pb-accent-text: #f5d400;      /* accent used as text */
  --pb-accent-soft: rgba(245, 212, 0, 0.12);
  --pb-focus: #f5d400;

  /* status */
  --pb-ok: #3ecf8e;      --pb-ok-soft: rgba(62, 207, 142, 0.13);
  --pb-warn: #f2b230;    --pb-warn-soft: rgba(242, 178, 48, 0.14);
  --pb-danger: #f27066;  --pb-danger-soft: rgba(242, 112, 102, 0.14);
  --pb-danger-solid: #c23a30;     /* destructive button fill */
  --pb-on-danger: #ffffff;
  --pb-info: #74aaff;    --pb-info-soft: rgba(116, 170, 255, 0.14);

  /* data visualisation */
  --pb-series-cpu: #e0a024;
  --pb-series-ram: #5a9cf2;
  --pb-series-disk: #b98cf0;
  --pb-meter-neutral: #cfcfc8;

  /* terminal (stays dark in both themes: ANSI colours are made for it) */
  --pb-term-bg: #07070a;
  --pb-term-bar: #101015;
  --pb-term-input: #0c0c11;
  --pb-term-text: #d9d7c4;
  --pb-term-dim: #7d7b6c;
  --pb-ansi-black: #6b6b73;  --pb-ansi-red: #f27066;  --pb-ansi-green: #3ecf8e;  --pb-ansi-yellow: #f2b230;
  --pb-ansi-blue: #74aaff;   --pb-ansi-magenta: #c490f0;  --pb-ansi-cyan: #54d0d6;  --pb-ansi-white: #d9d7c4;
  --pb-ansi-bright-black: #9a9aa6;  --pb-ansi-bright-red: #ff8b82;  --pb-ansi-bright-green: #6fe3a9;  --pb-ansi-bright-yellow: #ffd166;
  --pb-ansi-bright-blue: #9cc1ff;   --pb-ansi-bright-magenta: #d9b0ff;  --pb-ansi-bright-cyan: #7fe3e8;  --pb-ansi-bright-white: #ffffff;

  /* surfaces that stay dark on purpose (brand panel on the sign-in page) */
  --pb-fixed-dark-bg: #0b0b0e;
  --pb-fixed-dark-text: #ececf0;
  --pb-fixed-dark-muted: #c8c8d2;

  /* elevation */
  --pb-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --pb-shadow-card: 0 0 0 1px rgba(255, 255, 255, 0.02), 0 8px 28px rgba(0, 0, 0, 0.35);
  --pb-shadow-pop: 0 12px 40px rgba(0, 0, 0, 0.55);
}

/* ───────── light theme (designed separately, not an inversion) ───────── */
:root[data-theme='light'] {
  color-scheme: light;

  --pb-bg: #f3f3ef;
  --pb-bg-side: #fafaf7;
  --pb-surface: #ffffff;
  --pb-surface-raised: #f7f7f3;
  --pb-surface-sunken: #eeeee8;
  --pb-surface-hover: #e9e9e3;
  --pb-line: rgba(22, 22, 30, 0.09);
  --pb-line-strong: rgba(22, 22, 30, 0.18);
  --pb-overlay: rgba(22, 22, 30, 0.42);

  --pb-text: #16161c;
  --pb-text-muted: #565662;
  --pb-text-faint: #686873;
  --pb-text-disabled: #9a9aa4;

  --pb-accent: #f5d400;
  --pb-accent-hover: #ffdb12;
  --pb-accent-dim: #a38b00;
  --pb-accent-ink: #15130a;
  --pb-accent-text: #695500;
  --pb-accent-soft: rgba(245, 212, 0, 0.2);
  --pb-focus: #8a6e00;

  --pb-ok: #0e6b3c;      --pb-ok-soft: rgba(14, 107, 60, 0.1);
  --pb-warn: #8f5a00;    --pb-warn-soft: rgba(143, 90, 0, 0.11);
  --pb-danger: #b8322a;  --pb-danger-soft: rgba(184, 50, 42, 0.09);
  --pb-danger-solid: #c4392f;
  --pb-on-danger: #ffffff;
  --pb-info: #1f56b5;    --pb-info-soft: rgba(31, 86, 181, 0.09);

  --pb-series-cpu: #a56a00;
  --pb-series-ram: #2461c4;
  --pb-series-disk: #7b45c2;
  --pb-meter-neutral: #4a4a44;

  --pb-shadow-sm: 0 1px 2px rgba(22, 22, 30, 0.08);
  --pb-shadow-card: 0 1px 2px rgba(22, 22, 30, 0.05), 0 6px 20px rgba(22, 22, 30, 0.05);
  --pb-shadow-pop: 0 10px 36px rgba(22, 22, 30, 0.18);
}

/* ───────── global behaviour shared by every interface ───────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
/* a visible focus ring everywhere unless a component draws its own (zero specificity, so it never overrides one) */
:where(a, button, summary, [tabindex]):focus-visible {
  outline: var(--pb-focus-width) solid var(--pb-focus);
  outline-offset: var(--pb-focus-offset);
}
::selection { background: var(--pb-accent-soft); }

/* ───────── compatibility aliases (older names -> the tokens above) ───────── */
:root {
  /* public website, store, legacy chrome */
  --bg: var(--pb-bg);
  --surface: var(--pb-surface);
  --surface-2: var(--pb-surface-raised);
  --surface-3: var(--pb-surface-hover);
  --border: var(--pb-line);
  --border-bright: var(--pb-line-strong);
  --text: var(--pb-text);
  --text-dim: var(--pb-text-muted);
  --accent: var(--pb-accent);
  --accent-bright: var(--pb-accent-hover);
  --accent-dim: var(--pb-accent-dim);
  --accent-text: var(--pb-accent-text);
  --on-accent: var(--pb-accent-ink);
  --focus: var(--pb-focus);
  --danger: var(--pb-danger);
  --danger-dim: var(--pb-danger-soft);
  --ok: var(--pb-ok);
  --ok-dim: var(--pb-ok-soft);
  --status-warning: var(--pb-warn);
  --status-warning-dim: var(--pb-warn-soft);
  --status-critical: var(--pb-danger-solid);
  --console-bg: var(--pb-term-bg);
  --console-text: var(--pb-term-text);
  --overlay: var(--pb-overlay);
  --shadow-sm: var(--pb-shadow-sm);
  --shadow-md: var(--pb-shadow-pop);
  --meter-normal: var(--pb-meter-neutral);
  --chart-series-cpu: var(--pb-series-cpu);
  --chart-series-ram: var(--pb-series-ram);
  --radius: var(--pb-radius-md);
  --mono: var(--pb-font-mono);
  --display: var(--pb-font-display);

  /* Customer + Admin panels */
  --cp-bg: var(--pb-bg);
  --cp-side: var(--pb-bg-side);
  --cp-surface: var(--pb-surface);
  --cp-raised: var(--pb-surface-raised);
  --cp-sunken: var(--pb-surface-sunken);
  --cp-line: var(--pb-line);
  --cp-line-strong: var(--pb-line-strong);
  --cp-text: var(--pb-text);
  --cp-muted: var(--pb-text-muted);
  --cp-faint: var(--pb-text-faint);
  --cp-accent: var(--pb-accent);
  --cp-accent-ink: var(--pb-accent-ink);
  --cp-accent-text: var(--pb-accent-text);
  --cp-accent-soft: var(--pb-accent-soft);
  --cp-ok: var(--pb-ok);            --cp-ok-soft: var(--pb-ok-soft);
  --cp-warn: var(--pb-warn);        --cp-warn-soft: var(--pb-warn-soft);
  --cp-danger: var(--pb-danger);    --cp-danger-soft: var(--pb-danger-soft);
  --cp-danger-solid: var(--pb-danger-solid);
  --cp-info: var(--pb-info);        --cp-info-soft: var(--pb-info-soft);
  --cp-series-cpu: var(--pb-series-cpu);
  --cp-series-ram: var(--pb-series-ram);
  --cp-series-disk: var(--pb-series-disk);
  --cp-shadow: var(--pb-shadow-card);
  --cp-pop: var(--pb-shadow-pop);
  --cp-term-bg: var(--pb-term-bg);
  --cp-term-text: var(--pb-term-text);
  --cp-term-dim: var(--pb-term-dim);
  --cp-r: var(--pb-radius-md);
  --cp-r-lg: var(--pb-radius-lg);
  --cp-side-w: var(--pb-sidebar-w);
  --cp-side-w-c: var(--pb-sidebar-w-rail);
  --cp-top-h: var(--pb-topbar-h);
  --cp-mono: var(--pb-font-mono);
  --cp-display: var(--pb-font-display);
}
