/*
 * ARC Safety Platform — Shared Design System
 * Version 3.0 — Apple-First (June 2026)
 *
 * Palette : iOS-native light/dark with blue primary
 * Typeface: SF Pro / system stack
 * Philosophy: Clean, accessible, readable — as if Apple designed a safety platform.
 *
 * DARK MODE — apply [data-theme="dark"] to <html> to activate.
 *   theme.js handles auto-detection (prefers-color-scheme) and the manual toggle.
 *
 * SINGLE SOURCE OF TRUTH — all six ARC pages link here.
 *   Field-tool alias tokens (--r, --navy, --em-*, --ok, --warn, etc.)
 *   are included so inspection, audit, portal and ai-photo can migrate
 *   without renaming every var() reference.
 */

/* ══════════════════════════════════════════════════════════════════════
   LIGHT MODE TOKENS (default)
   ══════════════════════════════════════════════════════════════════════ */
:root {

  /* ── Surfaces ── */
  --bg:            #f2f2f7;
  --surface:       #ffffff;
  --surface-2:     #f2f2f7;
  --surface-3:     #e5e5ea;
  --surface-glass: rgba(255,255,255,.92);

  /* ── Chrome — sidebar / topbar, always dark in both modes ── */
  --chrome-bg:     #1c1c1e;
  --chrome-text:   #ebebf5;
  --chrome-muted:  #8e8e9a;
  --chrome-active: #ffffff;
  --chrome-hover:  rgba(255,255,255,.09);
  --chrome-border: rgba(255,255,255,.1);
  --chrome-accent: #007aff;

  /* ── Text ── */
  --text:          #1c1c1e;
  --text-muted:    #6b6b70;
  --text-faint:    #8e8e93;

  /* ── Borders ── */
  --border:        #d1d1d6;
  --border-strong: #aeaeb2;
  --border-focus:  #007aff;
  --border-glow:   #007aff;

  /* ── Brand / Primary — iOS blue ── */
  --primary:       #007aff;
  --primary-hover: #0062cc;
  --primary-light: rgba(0,122,255,.10);
  --primary-text:  #ffffff;

  /* ── Status — iOS system colours ── */
  --success:       #34c759;
  --success-bg:    #d4f7de;
  --success-text:  #1a5e2a;
  --warning:       #ff9500;
  --warning-bg:    #fff3cd;
  --warning-text:  #7a4300;
  --danger:        #ff3b30;
  --danger-bg:     #fde8e7;
  --danger-text:   #7a1914;
  --info:          #007aff;
  --info-bg:       #e8f2ff;
  --info-text:     #003f87;
  --neutral-bg:    #f2f2f7;
  --neutral-text:  #6e6e73;

  /* ── Field-tool status aliases (inspection / audit / portal) ── */
  --ok:       #34c759;
  --ok-l:     rgba(52,199,89,.14);
  --ok-b:     #30b652;
  --warn:     #ff9500;
  --warn-l:   rgba(255,149,0,.14);
  --warn-b:   #cc7700;
  --danger-l: rgba(255,59,48,.14);
  --danger-b: #cc2f25;
  --red:      #ff3b30;
  --amber:    #ff9500;
  --green:    #34c759;
  --gold:     #ff9500;
  --accent:   #007aff;

  /* ── Emerald scale — kept for semantic conformance / success use ── */
  --em-50:  #ecfdf5; --em-100: #d1fae5; --em-200: #a7f3d0;
  --em-300: #6ee7b7; --em-400: #34c759; --em-500: #30b652;
  --em-600: #248a3d; --em-700: #1a6b2e; --em-800: #065f46;
  --em-900: #064e3b; --em-950: #022c1a;

  /* ── Layout / colour aliases (used by field tools) ── */
  --navy:  #1c1c1e;
  --mid:   #3a3a3c;
  --light: #f2f2f7;
  --grey:  #8e8e93;
  --white: #ffffff;

  /* ── Shadow aliases (used by field tools) ── */
  --glow-sm:   0 1px 3px rgba(0,0,0,.06);
  --glow-md:   0 2px 8px rgba(0,0,0,.08);
  --glow-lg:   0 4px 16px rgba(0,0,0,.10);
  --glow-cyan: none;

  /* ── Typography — SF Pro stack ── */
  --font:      -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Consolas", monospace;
  --text-xs:   11px;
  --text-sm:   12px;
  --text-base: 13px;
  --text-md:   14px;
  --text-lg:   16px;
  --text-xl:   18px;
  --text-2xl:  22px;
  --text-3xl:  28px;

  /* ── Radius — 12px everywhere per ARC design standard ── */
  --radius-sm: 6px;
  --radius:    12px;
  --r:         12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* ── Shadows — subtle iOS lift ── */
  --shadow-xs:    0 1px 3px rgba(0,0,0,.06);
  --shadow-sm:    0 2px 8px rgba(0,0,0,.08);
  --shadow:       0 4px 16px rgba(0,0,0,.08);
  --shadow-lg:    0 8px 32px rgba(0,0,0,.12);
  --shadow-modal: 0 20px 60px rgba(0,0,0,.15);

  /* ── Spacing ── */
  --space-1: 4px;
  --space-2: clamp(6px,  0.55vw, 8px);
  --space-3: clamp(8px,  0.75vw, 12px);
  --space-4: clamp(10px, 1vw,    16px);
  --space-5: clamp(12px, 1.25vw, 20px);
  --space-6: clamp(14px, 1.6vw,  24px);
  --space-8: clamp(18px, 2.2vw,  32px);

  /* ── Layout ── */
  --sidebar-w:   clamp(190px, 15vw, 220px);
  --topbar-h:    clamp(46px, 5.5vh, 52px);
  --page-pad:    clamp(12px, 1.7vw, 24px);
  --content-max: 1440px;
  --transition:  150ms ease;
}

/* ══════════════════════════════════════════════════════════════════════
   DARK MODE TOKENS  —  [data-theme="dark"] on <html>
   Follows Apple iOS / macOS dark mode values exactly.
   ══════════════════════════════════════════════════════════════════════ */
[data-theme="dark"] {

  /* ── Surfaces — OLED true-black base ── */
  --bg:            #000000;
  --surface:       #1c1c1e;
  --surface-2:     #2c2c2e;
  --surface-3:     #3a3a3c;
  --surface-glass: rgba(28,28,30,.92);

  /* ── Chrome — slightly darker than surface so sidebar stays distinct ── */
  --chrome-bg:     #111111;
  --chrome-border: rgba(255,255,255,.08);

  /* ── Text ── */
  --text:       #ffffff;
  --text-muted: #ebebeb;
  --text-faint: #8e8e93;

  /* ── Borders ── */
  --border:        #38383a;
  --border-strong: #545456;
  --border-focus:  #0a84ff;
  --border-glow:   #0a84ff;

  /* ── Primary — brighter blue for dark backgrounds ── */
  --primary:       #0a84ff;
  --primary-hover: #409cff;
  --primary-light: rgba(10,132,255,.15);

  /* ── Status — iOS dark mode variants ── */
  --success:       #30d158;
  --success-bg:    rgba(48,209,88,.15);
  --success-text:  #30d158;
  --warning:       #ff9f0a;
  --warning-bg:    rgba(255,159,10,.15);
  --warning-text:  #ff9f0a;
  --danger:        #ff453a;
  --danger-bg:     rgba(255,69,58,.15);
  --danger-text:   #ff453a;
  --info:          #0a84ff;
  --info-bg:       rgba(10,132,255,.15);
  --info-text:     #0a84ff;
  --neutral-bg:    #2c2c2e;
  --neutral-text:  #8e8e93;

  /* ── Field-tool status aliases — dark ── */
  --ok:       #30d158;
  --ok-l:     rgba(48,209,88,.15);
  --ok-b:     #28a745;
  --warn:     #ff9f0a;
  --warn-l:   rgba(255,159,10,.15);
  --warn-b:   #cc7a00;
  --danger-l: rgba(255,69,58,.15);
  --danger-b: #cc2f25;
  --red:      #ff453a;
  --amber:    #ff9f0a;
  --green:    #30d158;
  --gold:     #ff9f0a;
  --accent:   #0a84ff;

  /* ── Emerald scale — dark adjusted ── */
  --em-300: #34d399;
  --em-400: #30d158;
  --em-600: #059669;

  /* ── Layout aliases ── */
  --navy:  #000000;
  --mid:   #3a3a3c;
  --light: #1c1c1e;
  --grey:  #636366;

  /* ── Shadows — more visible on dark ── */
  --shadow-xs:    0 1px 3px rgba(0,0,0,.30);
  --shadow-sm:    0 2px 8px rgba(0,0,0,.40);
  --shadow:       0 4px 16px rgba(0,0,0,.40);
  --shadow-lg:    0 8px 32px rgba(0,0,0,.50);
  --shadow-modal: 0 20px 60px rgba(0,0,0,.60);

  --glow-sm: 0 1px 3px rgba(0,0,0,.30);
  --glow-md: 0 2px 8px rgba(0,0,0,.40);
  --glow-lg: 0 4px 16px rgba(0,0,0,.40);
}

/* ══════════════════════════════════════════════════════════════════════
   RESET & BASE
   ══════════════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* ══════════════════════════════════════════════════════════════════════
   THEME TOGGLE BUTTON
   Place <button class="arc-theme-btn" onclick="arcToggleTheme()"></button>
   anywhere on a page. theme.js sets the icon and title automatically.
   For pages with a topbar add it inside .topbar-actions.
   For all other pages it floats fixed top-right.
   ══════════════════════════════════════════════════════════════════════ */
.arc-theme-btn {
  position: fixed;
  top: 10px;
  right: 14px;
  z-index: 9000;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), box-shadow var(--transition);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.arc-theme-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: var(--shadow);
}
/* When inside a topbar or portal header, remove fixed positioning */
.topbar-actions .arc-theme-btn,
.topbar .arc-theme-btn,
.header .arc-theme-btn {
  position: static;
  box-shadow: none;
  background: none;
  border-color: transparent;
  color: var(--chrome-muted);
}
.topbar-actions .arc-theme-btn:hover,
.topbar .arc-theme-btn:hover,
.header .arc-theme-btn:hover {
  background: var(--chrome-hover);
  color: var(--chrome-active);
  border-color: transparent;
  box-shadow: none;
}

/* ══════════════════════════════════════════════════════════════════════
   LAYOUT SHELL
   ══════════════════════════════════════════════════════════════════════ */
.app-shell { display: flex; min-height: 100vh; }
.app-shell, .sidebar, .topbar, .content { position: relative; z-index: 1; }

/* ══════════════════════════════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--chrome-bg);
  border-right: 1px solid var(--chrome-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform var(--transition);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4);
  height: var(--topbar-h);
  border-bottom: 1px solid var(--chrome-border);
  flex-shrink: 0;
}

.sidebar-brand-mark {
  width: 28px; height: 28px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 900; color: white;
  flex-shrink: 0;
}

.sidebar-brand-name {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--chrome-active);
  letter-spacing: -0.2px;
  white-space: nowrap;
}

.sidebar-section {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--chrome-border);
}
.sidebar-section:last-of-type { border-bottom: none; }

.sidebar-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--chrome-muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  padding: var(--space-2) var(--space-4) var(--space-1);
}

.sb-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 7px var(--space-4);
  font-size: var(--text-base);
  color: var(--chrome-text);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
  border-left: 2px solid transparent;
  user-select: none;
}
.sb-item:hover {
  background: var(--chrome-hover);
  color: var(--chrome-active);
}
.sb-item.active {
  background: var(--chrome-hover);
  color: var(--chrome-active);
  border-left-color: var(--primary);
  font-weight: 600;
}
.sb-item-icon {
  width: 16px;
  text-align: center;
  font-size: 14px;
  flex-shrink: 0;
  opacity: 0.8;
}

/* ══════════════════════════════════════════════════════════════════════
   TOPBAR
   ══════════════════════════════════════════════════════════════════════ */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: var(--topbar-h);
  background: var(--chrome-bg);
  border-bottom: 1px solid var(--chrome-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  z-index: 100;
}

.topbar-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--chrome-active);
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  font-size: var(--text-sm);
  color: var(--chrome-muted);
}
.topbar-user:hover { background: var(--chrome-hover); color: var(--chrome-text); }

.topbar-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: var(--text-xs);
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.topbar-org-badge {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--chrome-muted);
  background: rgba(255,255,255,.08);
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--chrome-border);
}

/* ══════════════════════════════════════════════════════════════════════
   MAIN CONTENT
   ══════════════════════════════════════════════════════════════════════ */
.main-wrap {
  margin-left: var(--sidebar-w);
  padding-top: var(--topbar-h);
  min-height: 100vh;
  flex: 1;
}

.page {
  display: none;
  padding: var(--page-pad);
  width: 100%;
  max-width: var(--content-max);
}
.page.active { display: block; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
  line-height: 1.2;
}

.page-subtitle {
  font-size: var(--text-base);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

/* ══════════════════════════════════════════════════════════════════════
   SUPPORT BANNER
   ══════════════════════════════════════════════════════════════════════ */
.support-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 999;
  background: #b45309;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: 8px var(--space-6);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* ══════════════════════════════════════════════════════════════════════
   CARDS
   ══════════════════════════════════════════════════════════════════════ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  margin-bottom: var(--space-4);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.card-sub {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: 2px;
}

.card-body { padding: var(--space-5); }

.card-footer {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

/* Stat card */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-xs);
}

.stat-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-2);
}

.stat-value {
  font-size: var(--text-3xl);
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.5px;
}

.stat-delta {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

/* ══════════════════════════════════════════════════════════════════════
   FILTER TOOLBAR
   ══════════════════════════════════════════════════════════════════════ */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.filter-bar .f-inp,
.filter-bar .f-sel { height: 34px; font-size: var(--text-sm); }

/* ══════════════════════════════════════════════════════════════════════
   TABLES
   ══════════════════════════════════════════════════════════════════════ */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

table.arc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.arc-table thead th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.arc-table tbody td {
  padding: 11px var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.arc-table tbody tr:last-child td { border-bottom: none; }
.arc-table tbody tr:hover td { background: var(--surface-2); }
.arc-table tbody tr.selected td { background: var(--primary-light); }

.td-mono { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-muted); }
.td-actions { white-space: nowrap; text-align: right; }

/* Global table rules */
table { background: transparent; color: var(--text); }
thead th {
  background: var(--surface-2);
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: var(--text-xs);
}
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:hover { background: var(--surface-2); }

/* ══════════════════════════════════════════════════════════════════════
   TABS
   ══════════════════════════════════════════════════════════════════════ */
.tabs {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  background: rgba(0,0,0,.06);
  border: none;
  border-radius: 10px;
  margin-bottom: var(--space-5);
}

.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 14px;
  height: 30px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  border-radius: 7px;
  background: transparent;
  white-space: nowrap;
  user-select: none;
  transition: color 150ms, background 150ms, box-shadow 150ms;
}
.tab:hover { color: var(--text); }
.tab.active,
.tab[aria-selected="true"] {
  background: #fff;
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.14), 0 0 0 0.5px rgba(0,0,0,.06);
}

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 20px;
  background: rgba(0,0,0,.08);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-left: 6px;
}
.tab.active .tab-count {
  background: rgba(0,0,0,.07);
  color: var(--text);
}

/* CPanel tabs — Apple segmented pill style */
.cpanel-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 14px;
  height: 30px;
  background: transparent;
  border: none;
  border-radius: 7px;
  color: var(--text-muted);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: color 150ms, background 150ms, box-shadow 150ms;
}
.cpanel-tab:hover { color: var(--text); }
.cpanel-tab.active {
  background: #fff;
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.14), 0 0 0 0.5px rgba(0,0,0,.06);
}

/* ══════════════════════════════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-family: var(--font);
  font-size: var(--text-sm);
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* Primary */
.btn.primary,
.btn-primary,
.btn-submit {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  font-weight: 600;
}
.btn.primary:hover,
.btn-primary:hover,
.btn-submit:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 2px 8px rgba(0,122,255,.25);
}
[data-theme="dark"] .btn.primary:hover,
[data-theme="dark"] .btn-primary:hover,
[data-theme="dark"] .btn-submit:hover {
  box-shadow: 0 2px 8px rgba(10,132,255,.30);
}

/* Ghost */
.btn.ghost,
.btn-ghost,
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn.ghost:hover,
.btn-ghost:hover,
.btn-secondary:hover {
  background: var(--surface-2);
  border-color: var(--primary);
  color: var(--primary);
}

/* Danger */
.btn.danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn.danger:hover { background: #cc2f25; }

/* Danger ghost */
.btn.danger-ghost { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.danger-ghost:hover { background: var(--danger-bg); }

/* Sizes */
.btn.sm  { padding: 5px 10px; font-size: var(--text-xs); border-radius: var(--radius-sm); }
.btn.lg  { padding: 10px 20px; font-size: var(--text-md); }
.btn.icon { padding: 7px; width: 32px; height: 32px; }

/* ══════════════════════════════════════════════════════════════════════
   FORM ELEMENTS
   ══════════════════════════════════════════════════════════════════════ */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
.form-grid .full { grid-column: 1 / -1; }

.form-group { display: flex; flex-direction: column; gap: 5px; }

.f-lbl {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.f-inp,
.f-sel,
.f-txt {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  font-family: var(--font);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

.f-txt {
  height: auto;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.5;
}

.f-inp:focus,
.f-sel:focus,
.f-txt:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(0,122,255,.12);
}
[data-theme="dark"] .f-inp:focus,
[data-theme="dark"] .f-sel:focus,
[data-theme="dark"] .f-txt:focus {
  box-shadow: 0 0 0 3px rgba(10,132,255,.18);
}

.f-inp::placeholder,
.f-txt::placeholder { color: var(--text-faint); }

.f-inp:disabled,
.f-sel:disabled { background: var(--surface-2); color: var(--text-muted); cursor: not-allowed; }

.f-sel {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23667085'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}

.f-hint  { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.f-error { font-size: var(--text-xs); color: var(--danger); margin-top: 2px; }

/* Global input override — ensures all plain inputs follow the token system */
input, select, textarea {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  transition: border-color var(--transition), box-shadow var(--transition);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(0,122,255,.12);
}
[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus {
  box-shadow: 0 0 0 3px rgba(10,132,255,.18);
}

[data-theme="dark"] .tabs {
  background: rgba(255,255,255,.10);
}
[data-theme="dark"] .tab.active,
[data-theme="dark"] .tab[aria-selected="true"] {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.35), 0 0 0 0.5px rgba(255,255,255,.06);
}
[data-theme="dark"] .cpanel-tab.active {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.35), 0 0 0 0.5px rgba(255,255,255,.06);
}

/* ══════════════════════════════════════════════════════════════════════
   BADGES / STATUS CHIPS
   ══════════════════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge-success  { background: var(--success-bg);  color: var(--success-text); }
.badge-warning  { background: var(--warning-bg);  color: var(--warning-text); }
.badge-danger   { background: var(--danger-bg);   color: var(--danger-text);  }
.badge-info     { background: var(--info-bg);     color: var(--info-text);    }
.badge-neutral  { background: var(--neutral-bg);  color: var(--neutral-text); }
.badge-primary  { background: var(--primary-light); color: var(--primary);    }

.badge.success, .chip.success, .status.success { background: var(--success-bg); color: var(--success-text); }
.badge.warning, .chip.warning, .status.warning { background: var(--warning-bg); color: var(--warning-text); }
.badge.danger,  .chip.danger,  .status.danger,
.badge.error,   .chip.error,   .status.error   { background: var(--danger-bg);  color: var(--danger-text);  }
.badge.info,    .chip.info,    .status.info    { background: var(--info-bg);    color: var(--info-text);    }

/* Status-specific chip aliases */
.chip-draft    { background: var(--neutral-bg);   color: var(--neutral-text); }
.chip-active   { background: var(--primary-light); color: var(--primary);     }
.chip-final    { background: var(--success-bg);   color: var(--success-text); }
.chip-open     { background: var(--danger-bg);    color: var(--danger-text);  }
.chip-closed   { background: var(--success-bg);   color: var(--success-text); }
.chip-overdue  { background: var(--warning-bg);   color: var(--warning-text); }
.chip-review   { background: var(--info-bg);      color: var(--info-text);    }
.chip-archived { background: var(--neutral-bg);   color: var(--text-faint);   }

/* Score chip */
.score-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: var(--text-sm);
  font-weight: 800;
  letter-spacing: -0.3px;
}
.score-chip.good { background: var(--success-bg); color: var(--success); }
.score-chip.ok   { background: var(--warning-bg); color: var(--warning); }
.score-chip.bad  { background: var(--danger-bg);  color: var(--danger);  }

/* ══════════════════════════════════════════════════════════════════════
   MODALS
   ══════════════════════════════════════════════════════════════════════ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }

.modal,
.modal-backdrop { background: rgba(0,0,0,.45); backdrop-filter: blur(4px); }

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-modal);
  width: 100%;
  max-width: 640px;
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-in 160ms ease;
}
.modal.sm  { max-width: 420px; }
.modal.lg  { max-width: 880px; }
.modal.xl  { max-width: 1080px; }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title { font-size: var(--text-lg); font-weight: 700; color: var(--text); line-height: 1.3; }
.modal-context { font-size: var(--text-sm); color: var(--text-muted); margin-top: 2px; }

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 2px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
}
.modal-close:hover { color: var(--text); background: var(--surface-2); }

.modal-body { padding: var(--space-6); overflow-y: auto; flex: 1; }

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}

.modal-foot-right { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; }

/* ══════════════════════════════════════════════════════════════════════
   ALERTS / NOTICES
   ══════════════════════════════════════════════════════════════════════ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  border: 1px solid transparent;
}

.alert-success, .alert.success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-bg); border-left: 3px solid var(--success); }
.alert-warning, .alert.warning { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-bg); border-left: 3px solid var(--warning); }
.alert-danger,  .alert.danger,
.alert.error    { background: var(--danger-bg);  color: var(--danger-text);  border-color: var(--danger-bg);  border-left: 3px solid var(--danger); }
.alert-info,    .alert.info    { background: var(--info-bg);    color: var(--info-text);    border-color: var(--info-bg);    border-left: 3px solid var(--info); }
.alert-neutral  { background: var(--neutral-bg); color: var(--neutral-text); border-color: var(--border); }

/* ══════════════════════════════════════════════════════════════════════
   EMPTY STATES
   ══════════════════════════════════════════════════════════════════════ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-6);
  text-align: center;
  color: var(--text-muted);
}
.empty-icon  { font-size: 32px; margin-bottom: var(--space-3); opacity: 0.5; }
.empty-title { font-size: var(--text-md); font-weight: 600; color: var(--text); margin-bottom: var(--space-1); }
.empty-desc  { font-size: var(--text-sm); color: var(--text-muted); max-width: 320px; }

/* ══════════════════════════════════════════════════════════════════════
   LOADING
   ══════════════════════════════════════════════════════════════════════ */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
  flex-shrink: 0;
}
.spinner.lg { width: 28px; height: 28px; border-width: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }

.loading-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-6);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* ══════════════════════════════════════════════════════════════════════
   BREADCRUMB
   ══════════════════════════════════════════════════════════════════════ */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}
.breadcrumb a { color: var(--text-muted); text-decoration: none; transition: color var(--transition); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb-sep     { color: var(--border-strong); }
.breadcrumb-current { color: var(--text); font-weight: 500; }

/* ══════════════════════════════════════════════════════════════════════
   NOTIFICATION BELL
   ══════════════════════════════════════════════════════════════════════ */
.notif-btn {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius);
  color: var(--chrome-muted);
  font-size: 18px;
  transition: background var(--transition), color var(--transition);
}
.notif-btn:hover { background: var(--chrome-hover); color: var(--chrome-active); }

.notif-badge {
  position: absolute;
  top: 2px; right: 2px;
  min-width: 16px; height: 16px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
  pointer-events: none;
}

/* ══════════════════════════════════════════════════════════════════════
   ACTIVITY LOG
   ══════════════════════════════════════════════════════════════════════ */
.activity-row-amber {
  background: rgba(255,149,0,.10);
  border-left: 3px solid var(--warning);
  padding-left: 10px;
}

/* ══════════════════════════════════════════════════════════════════════
   DIVIDERS
   ══════════════════════════════════════════════════════════════════════ */
.divider,
hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: var(--space-4) 0;
}

.section-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: var(--space-3);
}

/* ══════════════════════════════════════════════════════════════════════
   OVERVIEW GRID
   ══════════════════════════════════════════════════════════════════════ */
.overview-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(clamp(130px, 13vw, 170px), 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr));
  gap: var(--space-4);
}

/* ══════════════════════════════════════════════════════════════════════
   SCORE PROGRESS BAR
   ══════════════════════════════════════════════════════════════════════ */
.score-bar-wrap { display: flex; align-items: center; gap: var(--space-2); }

.score-bar-track {
  flex: 1;
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}

.score-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 400ms ease;
}
.score-bar-fill.good { background: var(--success); }
.score-bar-fill.ok   { background: var(--warning); }
.score-bar-fill.bad  { background: var(--danger);  }

/* ══════════════════════════════════════════════════════════════════════
   SCROLLBARS
   ══════════════════════════════════════════════════════════════════════ */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ══════════════════════════════════════════════════════════════════════
   SELECTION & FOCUS
   ══════════════════════════════════════════════════════════════════════ */
::selection { background: rgba(0,122,255,.20); color: inherit; }
[data-theme="dark"] ::selection { background: rgba(10,132,255,.30); }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ══════════════════════════════════════════════════════════════════════
   LIVE / PULSE INDICATOR
   ══════════════════════════════════════════════════════════════════════ */
.live-dot, .pulse {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  animation: pulse-ring 1.8s cubic-bezier(.4,0,.2,1) infinite;
}
@keyframes pulse-ring {
  0%   { box-shadow: 0 0 0 0   rgba(52,199,89,.6); }
  70%  { box-shadow: 0 0 0 10px rgba(52,199,89,0);  }
  100% { box-shadow: 0 0 0 0   rgba(52,199,89,0);  }
}

/* ══════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  .sidebar { transform: translateX(-220px); width: 220px; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }

  .topbar { left: 0; }
  .main-wrap { margin-left: 0; }
  .page { padding: var(--space-4); }

  .form-grid { grid-template-columns: 1fr; }
  .overview-grid { grid-template-columns: 1fr; }
  .modal { margin: var(--space-2); border-radius: var(--radius-lg); }
  .modal.lg, .modal.xl { max-width: 100%; }
}

/* Compact density — laptops at 1366×768 */
@media (max-height: 820px) {
  :root {
    --text-base: 12.5px;
    --text-md:   13px;
    --text-lg:   15px;
    --topbar-h:  46px;
    --page-pad:  12px;
  }
  .card-head, .card-body { padding: var(--space-3) var(--space-4); }
  .modal-head, .modal-body, .modal-foot { padding: var(--space-3) var(--space-4); }
  .sb-item { padding-top: 5px; padding-bottom: 5px; }
  .arc-table thead th, .arc-table tbody td, table th, table td { padding-top: 7px; padding-bottom: 7px; }
  .stat-card { padding: var(--space-3) var(--space-4); }
  .stat-value { font-size: 24px; }
  .page-header { margin-bottom: var(--space-4); }
  .page-title { font-size: var(--text-xl); }
  .tabs { margin-bottom: var(--space-3); }
  .tab { padding: 8px var(--space-4); }
  .filter-bar { margin-bottom: var(--space-3); }
}

/* Wide screens */
@media (min-width: 1500px) {
  :root { --page-pad: 32px; --content-max: 1600px; }
}

/* ══════════════════════════════════════════════════════════════════════
   UTILITY
   ══════════════════════════════════════════════════════════════════════ */
.flex           { display: flex; }
.flex-col       { display: flex; flex-direction: column; }
.items-center   { align-items: center; }
.items-start    { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end    { justify-content: flex-end; }
.gap-1          { gap: var(--space-1); }
.gap-2          { gap: var(--space-2); }
.gap-3          { gap: var(--space-3); }
.gap-4          { gap: var(--space-4); }
.mt-1           { margin-top: var(--space-1); }
.mt-2           { margin-top: var(--space-2); }
.mt-3           { margin-top: var(--space-3); }
.mt-4           { margin-top: var(--space-4); }
.mb-2           { margin-bottom: var(--space-2); }
.mb-4           { margin-bottom: var(--space-4); }
.mb-6           { margin-bottom: var(--space-6); }
.w-full         { width: 100%; }
.text-sm        { font-size: var(--text-sm); }
.text-xs        { font-size: var(--text-xs); }
.text-muted     { color: var(--text-muted); }
.text-danger    { color: var(--danger); }
.text-success   { color: var(--success); }
.font-mono      { font-family: var(--font-mono); }
.font-bold      { font-weight: 700; }
.truncate       { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Site performance: shared by Admin and the token-scoped client portal. */
.perf-panel { margin: 22px 0; padding: 18px 0 0; border-top: 1px solid var(--border); min-width: 0; }
.perf-tools { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 13px; font-weight: 600; }
.perf-tools select { min-width: 180px; max-width: min(340px, 100%); }
.perf-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.perf-head h2 { margin: 0 0 3px; font-size: 18px; line-height: 1.25; }
.perf-sub, .perf-period, .perf-caveat, .perf-latest p { color: var(--text-muted); font-size: 12px; }
.perf-period { white-space: nowrap; }
.perf-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; margin: 17px 0 18px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.perf-metrics > div { min-width: 0; padding: 12px; border-right: 1px solid var(--border); }
.perf-metrics > div:last-child { border-right: 0; }
.perf-metrics span, .perf-metrics small { display: block; color: var(--text-muted); font-size: 11px; line-height: 1.35; overflow-wrap: anywhere; }
.perf-metrics strong { display: block; margin: 4px 0; font-size: 22px; line-height: 1.1; }
.perf-plots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.perf-plots > div { min-width: 0; }
.perf-plots h3, .perf-latest h3 { margin: 0 0 6px; font-size: 13px; line-height: 1.3; }
.perf-chart { display: block; width: 100%; height: auto; max-height: 140px; }
.perf-axis { fill: var(--text-muted); font-size: 11px; }
.perf-value { fill: var(--text); font-size: 10px; font-weight: 600; }
.perf-empty { padding: 20px 0; color: var(--text-muted); font-size: 13px; }
.perf-latest { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.perf-latest p { margin: 0; }
.perf-incidents { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; min-width: min(440px, 100%); }
.perf-incidents > div { display: flex; flex-direction: column; gap: 3px; }
.perf-incidents span { color: var(--text-muted); font-size: 11px; }
.perf-incidents strong { font-size: 16px; }
.perf-history { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.perf-history h3 { margin: 0 0 8px; font-size: 13px; }
.perf-table-scroll { max-width: 100%; overflow-x: auto; }
.perf-history table { width: 100%; border-collapse: collapse; font-size: 12px; }
.perf-history th, .perf-history td { padding: 7px 9px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.perf-history th:first-child { text-align: left; }
.perf-history thead th { color: var(--text-muted); font-weight: 600; }
.perf-caveat { margin: 14px 0 0; line-height: 1.45; }
@media (max-width: 900px) {
  .perf-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .perf-metrics > div:nth-child(2) { border-right: 0; }
  .perf-metrics > div:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .perf-plots { grid-template-columns: 1fr; }
  .perf-chart { max-height: 180px; }
  .perf-latest { flex-direction: column; }
  .perf-incidents { width: 100%; min-width: 0; }
}
@media (max-width: 480px) {
  .perf-incidents { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ══════════════════════════════════════════════════════════════════════
   PRINT — paper-friendly, preserve conformance colours
   ══════════════════════════════════════════════════════════════════════ */
@media print {
  body, .app-shell, .content, .card, .modal {
    background: #fff !important;
    color: #000 !important;
    box-shadow: none !important;
  }
  h1, h2, h3, .card-title, .page-title { color: #000 !important; background: none !important; }
  .sidebar, .topbar, .arc-theme-btn, .no-print { display: none !important; }
  .badge.success, .status.success { color: #15803d !important; }
  .badge.warning, .status.warning { color: #b45309 !important; }
  .badge.danger,  .status.danger  { color: #b91c1c !important; }
  img, .photo { filter: none !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
