/* OnProxy design tokens — shared brand system (seeded from the OnProxy design system).
   Theming: light is the default (:root); dark overrides live in [data-theme="dark"].
   The "System" option resolves to light/dark at boot (see inline script in index.html
   and js/core/theme.js) so only these two attribute states ever exist at runtime.

   Architecture: components consume semantic functions only (surface, border, text,
   icon, brand, status). Never hardcode hex/rgba in component CSS — add or reuse a
   token here so both themes stay in sync. */
:root {
  color-scheme: light;

  /* Surfaces — soft light / cool neutral: the app canvas is visibly cooler than
     the white operational surfaces (cards, tables, panels) that sit on it. */
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f2f5f8;
  --surface-elevated: #ffffff;
  --hover: #f3f6fa;
  --selected: #eef4ff;
  --sidebar-surface: var(--surface-3);
  --sidebar-hover: var(--surface);

  --border: #dde3ea;
  --border-soft: #e8ecf1;
  --border-strong: #cbd3dd;
  --divider: var(--border-soft);

  /* Brand — one blue, several functions. Do not reuse --blue for tints/borders.
     --blue: textual/accent blue (links, active states, dots, rings).
     --primary: solid action fill (primary buttons, filled controls).
     Light and dark keep one blue family; dark recalibrates hue for contrast. */
  --blue: #3157e8;
  --blue-hover: #2848cc;
  --blue-active: #2340b3;
  --primary: var(--blue);
  --primary-hover: var(--blue-hover);
  --primary-active: var(--blue-active);
  --blue-soft: rgba(49, 87, 232, 0.07);
  --blue-soft-2: rgba(49, 87, 232, 0.13);
  --blue-border: rgba(49, 87, 232, 0.3);
  --blue-border-soft: rgba(49, 87, 232, 0.2);

  /* Charts — series ramp (light keeps the brand-blue family) */
  --chart-1: #3157e8;
  --chart-2: #2848cc;
  --chart-3: #6b8df2;
  --chart-4: #9db4f7;
  --chart-5: #c9d6fb;

  /* Text — no pure black; disabled is a real color, not opacity. */
  --text: #172033;
  --text-secondary: #526071;
  --text-muted: #6b7788;
  --text-disabled: #98a2b3;
  --text-on-blue: #ffffff;
  --text-on-danger: #ffffff;

  /* Icons — parallel hierarchy to text (icons read slightly lighter than text
     of the same rank, so they never compete with labels). */
  --icon: #344054;
  --icon-secondary: #667085;
  --icon-muted: #98a2b3;

  /* Status — foreground/subtle/border triads. Subtle backgrounds stay faint;
     borders are the only place semantic alpha is allowed. */
  --ok: #16a34a;
  --ok-soft: rgba(22, 163, 74, 0.09);
  --ok-text: #15803d;
  --ok-border: rgba(22, 163, 74, 0.3);
  --warn: #d97706;
  --warn-soft: rgba(217, 119, 6, 0.09);
  --warn-text: #a16207;
  --warn-border: rgba(217, 119, 6, 0.3);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.07);
  --danger-soft-2: rgba(220, 38, 38, 0.13);
  --danger-text: #b42318;
  --danger-border: rgba(220, 38, 38, 0.3);
  --neutral: #94a3b8;
  --neutral-soft: rgba(148, 163, 184, 0.14);
  --neutral-text: #64748b;
  --neutral-border: rgba(148, 163, 184, 0.35);
  --neutral-block: #cbd5e1;
  --info: #3157e8;
  --info-soft: var(--blue-soft);
  --info-text: #1e3a8a;
  --info-border: var(--blue-border-soft);
  --suspended: #7c6bb5;
  --suspended-text: #5b4d8a;
  /* Aliases — keep component CSS on one semantic vocabulary */
  --success: var(--ok);
  --success-soft: var(--ok-soft);
  --success-text: var(--ok-text);
  --success-border: var(--ok-border);
  --input-bg: var(--surface);
  --input-placeholder: #8a96a8;

  /* Inverse surfaces (toasts, tooltips, log viewer — dark in both themes).
     Text on inverse is off-white, never pure white. */
  --inverse-surface: #182131;
  --inverse-surface-2: #202b3d;
  --inverse-border: #2a3547;
  --inverse-border-strong: #3d4a60;
  --inverse-text: #f1f5f9;
  --inverse-text-soft: #cbd5e1;
  --inverse-text-muted: #8a97a8;
  --inverse-link: #93b3fd;
  --inverse-ok: #4ade80;
  --inverse-warn: #fbbf24;
  --inverse-danger: #f87171;

  /* Misc chrome */
  --backdrop: rgba(15, 23, 42, 0.4);
  --backdrop-soft: rgba(15, 23, 42, 0.22);
  --danger-hover: #b91c1c;
  --scrollbar-thumb: #cfd7e0;
  --scrollbar-thumb-hover: #bac4d1;
  --skeleton-base: #eceff4;
  --skeleton-sheen: #f6f8fb;
  --knob: #ffffff; /* switch handle — white on colored/neutral tracks in both themes */

  /* Shape */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-pill: 999px;

  /* Elevation (overlays only) */
  --shadow-menu: 0 8px 24px rgba(15, 23, 42, 0.12);
  --shadow-drawer: -12px 0 32px rgba(15, 23, 42, 0.1);
  --shadow-modal: 0 16px 48px rgba(15, 23, 42, 0.18);
  --shadow-nav-panel: 6px 0 24px rgba(15, 23, 42, 0.06);

  /* Breakpoints (use with matching media queries) */
  --bp-mobile: 767px;
  --bp-tablet: 1279px;
  --mobile-top-bar-h: 48px;

  /* Layout — single Sidebar (compact rail + expanded overlay) */
  --sidebar-width-compact: 68px;
  --sidebar-width-expanded: 240px;
  --sidebar-compact-width: var(--sidebar-width-compact);
  --sidebar-content-gutter: 14px;
  /* Layout offset — always compact; expanded sidebar overlays, never reserves width */
  --sidebar-current-width: var(--sidebar-width-compact);
  --app-rail-width: var(--sidebar-width-compact);
  --navigation-panel-width: var(--sidebar-width-expanded);
  --navigation-total-expanded-width: var(--sidebar-width-expanded);
  /* Legacy aliases */
  --sidebar-rail-width: var(--sidebar-width-compact);
  --sidebar-expanded-width: var(--sidebar-width-expanded);
  --sidebar-w: var(--sidebar-width-compact);
  --sidebar-w-collapsed: var(--sidebar-width-compact);
  --drawer-w: 420px;

  /* Stacking — sidebar overlay below drawers/modals; tooltips on top */
  --z-sidebar-backdrop: 40;
  --z-sidebar: 50;
  --z-rail: var(--z-sidebar-backdrop);
  --z-navigation-backdrop: var(--z-sidebar-backdrop);
  --z-navigation-panel: var(--z-sidebar);
  --z-dropdown: 70;
  --z-drawer: 80;
  /* Popovers spawned from inside a drawer (Custom range, port settings, …) */
  --z-drawer-popover: 85;
  --z-modal: 90;
  --z-toast: 95;
  --z-tooltip: 100;

  /* Type — Inter from shadcn preset b1tMf3Xjc (fontHeading: inherit).
     Mono is a system stack only: used selectively for IPs / IDs / ports / logs. */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Code", "Roboto Mono", "Segoe UI Mono", Menlo, Consolas, monospace;
  --fs-11: 11px;
  --fs-12: 12px;
  --fs-13: 13px;
  --fs-14: 14px;
  --fs-16: 16px;
  --fs-18: 18px;
  --fs-20: 20px;

  /* Density (Standard default; overridden by [data-density]) */
  --row-h: 88px;
  --cell-py: 17px;

  /* Focus */
  --focus-ring: 0 0 0 2px var(--surface), 0 0 0 4px var(--blue);
}

[data-density="comfortable"] { --row-h: 104px; --cell-py: 19px; }
[data-density="standard"]    { --row-h: 88px; --cell-py: 17px; }
[data-density="compact"]     { --row-h: 68px; --cell-py: 11px; }

/* ------------------------------------------------------------------ dark theme
   Light (:root) is untouched. Dark is dark + legible (not dim).

   Hierarchy:
     primary → secondary → tertiary(muted) → disabled
   Surfaces:
     bg → surface-2 (recessed) → surface (card) → elevated/hover
   Useful secondary information must NEVER reuse disabled contrast. */
[data-theme="dark"] {
  color-scheme: dark;

  /* Surfaces — cool near-black ladder (not pure #000) */
  --bg: #0d0f12;
  --surface-2: #141619;          /* recessed panels / table canvas */
  --surface: #17191d;            /* cards / primary panels */
  --surface-3: #1b1e23;
  --surface-elevated: #1e2127;   /* popovers, menus, drawers */
  --hover: #1b1e23;
  --selected: rgba(91, 141, 239, 0.12);
  --sidebar-surface: var(--surface-2);
  --sidebar-hover: var(--hover);

  /* Borders — solid steps (clearer than low-alpha white) */
  --border-soft: #262a30;
  --border: #30353d;
  --border-strong: #404751;
  --ring: #5b8def;

  /* Interactive blue — one family for tabs, links, filters, focus */
  --blue: #5b8def;
  --blue-hover: #6a99f5;
  --blue-active: #4f7fe0;
  --primary: #5b8def;
  --primary-hover: #6a99f5;
  --primary-active: #4f7fe0;
  --blue-soft: rgba(91, 141, 239, 0.12);
  --blue-soft-2: rgba(91, 141, 239, 0.18);
  --blue-border: rgba(91, 141, 239, 0.30);
  --blue-border-soft: rgba(91, 141, 239, 0.22);

  /* Charts — cyan ramp, readable on dark surfaces */
  --chart-1: #67e8f9;
  --chart-2: #22d3ee;
  --chart-3: #06b6d4;
  --chart-4: #0891b2;
  --chart-5: #0e7490;

  /* Text — SECONDARY is the major correction (useful gray → off-white) */
  --text: #f2f4f7;
  --text-secondary: #c0c7d0;     /* useful labels / metadata — not disabled */
  --text-muted: #9da6b2;         /* tertiary / units / captions — still readable */
  --text-disabled: #626c78;      /* only truly disabled UI */
  --text-on-blue: #f2f4f7;
  --text-on-danger: #ffffff;
  --divider: #2d3239;            /* internal metric / section dividers */

  /* Icons — parallel ladder; never as dim as disabled text */
  --icon: #e8ebef;
  --icon-secondary: #a8b0ba;
  --icon-muted: #89939f;

  /* Status — restrained, consistent families (aligned with Fleet dark) */
  --ok: #32c675;
  --ok-soft: rgba(50, 198, 117, 0.12);
  --ok-text: #32c675;
  --ok-border: rgba(50, 198, 117, 0.30);
  --warn: #e6a23c;
  --warn-soft: rgba(230, 162, 60, 0.12);
  --warn-text: #e6a23c;
  --warn-border: rgba(230, 162, 60, 0.28);
  --danger: #e15858;
  --danger-soft: rgba(225, 88, 88, 0.10);
  --danger-soft-2: rgba(225, 88, 88, 0.16);
  --danger-text: #e86464;
  --danger-border: rgba(225, 88, 88, 0.32);
  --neutral: #8a94a2;            /* offline / neutral state */
  --neutral-soft: rgba(148, 163, 184, 0.10);
  --neutral-text: #929ba6;
  --neutral-border: rgba(148, 163, 184, 0.22);
  --neutral-block: #2b3037;
  --info: var(--blue);
  --info-soft: var(--blue-soft);
  --info-text: #6a99f5;
  --info-border: var(--blue-border-soft);
  --suspended: #8b5cf6;
  --suspended-text: #a78bfa;
  --success: var(--ok);
  --success-soft: var(--ok-soft);
  --success-text: var(--ok-text);
  --success-border: var(--ok-border);
  --input-bg: #141619;
  --input-placeholder: #7f8996;

  /* Inverse — tooltips / toasts (clear contrast, not gray-on-black) */
  --inverse-surface: #1e2127;
  --inverse-surface-2: #262a30;
  --inverse-border: #343a43;
  --inverse-border-strong: #404751;
  --inverse-text: #f1f3f5;
  --inverse-text-soft: #b6bec8;
  --inverse-text-muted: #949eaa;
  --inverse-link: #93b3fd;
  --inverse-ok: #32c675;
  --inverse-warn: #e6a23c;
  --inverse-danger: #e86464;

  /* Misc chrome */
  --backdrop: rgba(0, 0, 0, 0.72);
  --backdrop-soft: rgba(0, 0, 0, 0.5);
  --danger-hover: #f07171;
  --scrollbar-thumb: #454b54;
  --scrollbar-thumb-hover: #59616c;
  --skeleton-base: #141619;
  --skeleton-sheen: #1b1e23;

  /* Elevation — restrained; surface/border carry hierarchy */
  --shadow-menu: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-drawer: -12px 0 32px rgba(0, 0, 0, 0.4);
  --shadow-modal: 0 16px 48px rgba(0, 0, 0, 0.55);
  --shadow-nav-panel: 8px 0 28px rgba(0, 0, 0, 0.4);

  --focus-ring: 0 0 0 2px var(--surface), 0 0 0 4px var(--blue);
}

/* Dark-only semantic role corrections.
   Light Mode keeps its approved token assignments. Useful secondary data that
   still points at muted/disabled in shared CSS is remapped here. */
[data-theme="dark"] .ov-m__label,
[data-theme="dark"] .ov-strip__label,
[data-theme="dark"] .ov-card__label,
[data-theme="dark"] .metric-tile__label,
[data-theme="dark"] .data-table thead th,
[data-theme="dark"] .act-table th,
[data-theme="dark"] .ip-history-table th,
[data-theme="dark"] .pod-th,
[data-theme="dark"] .simple-table th,
[data-theme="dark"] .ws-tab:not(.is-active),
[data-theme="dark"] .pp-row__desc,
[data-theme="dark"] .pp-row__desc-text,
[data-theme="dark"] .pp-row__host,
[data-theme="dark"] .device-cell__hardware,
[data-theme="dark"] .device-cell__model,
[data-theme="dark"] .device-cell__android,
[data-theme="dark"] .table-cell-secondary,
[data-theme="dark"] .cell__id {
  color: var(--text-secondary);
}

[data-theme="dark"] .ov-unit,
[data-theme="dark"] .ov-arr {
  color: var(--text-muted);
}

[data-theme="dark"] .pp-sep,
[data-theme="dark"] .ws-sep {
  color: var(--text-muted);
}

[data-theme="dark"] .ov-strip__seg::before {
  background: var(--divider);
}

[data-theme="dark"] .icon-btn {
  color: var(--icon-secondary);
}
[data-theme="dark"] .icon-btn:hover {
  color: var(--text);
}

[data-theme="dark"] .data-table tbody td {
  border-bottom-color: var(--divider);
}
[data-theme="dark"] .data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

/* Policy/feature disabled ≠ dim the whole card — badge carries the state */
[data-theme="dark"] .pp-gp.is-disabled {
  background: var(--surface);
}

/* Disabled filled buttons: keep shape visible without washing out via opacity */
[data-theme="dark"] .btn--primary:disabled,
[data-theme="dark"] .btn--primary:disabled:hover,
[data-theme="dark"] .modal__actions .btn--danger:disabled {
  opacity: 1;
  background: var(--surface-2);
  border-color: var(--border-soft);
  color: var(--text-disabled);
}
