/* ================================================================
   CTG COMMAND CENTER — DARK OPERATIONAL THEME
   PCLB / PCCC · Cát Tường Group · Bắc Ninh
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;600&display=swap');

/* ================================================================
   DARK THEME (default)
   ================================================================ */
:root, [data-theme="dark"] {
  /* Brand — same in both themes */
  --teal: #10B981;
  --teal-glow: #34D399;
  --teal-dark: #047857;
  --teal-deep: #022C22;
  --orange: #F39200;
  --orange-glow: #FFB547;
  --amber: #F5B301;

  /* Surface palette */
  --bg-0: #05070C;       /* deepest bg */
  --bg-1: #0A0F17;       /* app bg */
  --bg-2: #111827;       /* card bg */
  --bg-3: #182234;       /* elevated */
  --bg-4: #1F2C42;       /* input bg */
  --sidebar-bg-a: #0A121F;
  --sidebar-bg-b: #05070C;
  --topbar-bg: rgba(10,15,23,.85);
  --line: #223349;
  --line-2: #2E4363;
  --line-3: #3B5578;

  /* Ink */
  --ink: #E7EEF7;
  --ink-2: #A6B5CC;
  --ink-3: #6F819C;
  --ink-4: #4C5D77;
  --ink-heading: #FFFFFF;      /* pure white for h1-h4 in dark */

  /* Status */
  --lv0: #22C55E;
  --lv0-bg: rgba(34,197,94,.14);
  --lv0-line: rgba(34,197,94,.45);
  --lv1: #FACC15;
  --lv1-bg: rgba(250,204,21,.12);
  --lv1-line: rgba(250,204,21,.45);
  --lv2: #F59E0B;
  --lv2-bg: rgba(245,158,11,.14);
  --lv2-line: rgba(245,158,11,.5);
  --lv3: #EF4444;
  --lv3-bg: rgba(239,68,68,.16);
  --lv3-line: rgba(239,68,68,.55);
  --lv4: #A855F7;
  --lv4-bg: rgba(168,85,247,.16);
  --lv4-line: rgba(168,85,247,.55);

  --good: #22C55E;
  --warn: #F59E0B;
  --crit: #EF4444;
  --info: #38BDF8;

  /* Backdrop textures */
  --backdrop-a: rgba(16,185,129,.06);
  --backdrop-b: rgba(243,146,0,.05);
  --grid-line: rgba(255,255,255,.015);
  --modal-scrim: rgba(0,0,0,.7);

  /* Effects */
  --r: 10px;
  --r-sm: 6px;
  --r-lg: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 2px 8px rgba(0,0,0,.25);
  --shadow-lg: 0 20px 48px rgba(0,0,0,.55), 0 4px 12px rgba(0,0,0,.4);
  --shadow-glow: 0 0 0 1px rgba(52,211,153,.4), 0 0 24px rgba(52,211,153,.25);

  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;

  --sidebar-w: 232px;
  --sidebar-w-collapsed: 60px;
  --topbar-h: 62px;
  --bottom-nav-h: 60px;

  color-scheme: dark;
}

/* ================================================================
   LIGHT THEME
   ================================================================ */
[data-theme="light"] {
  --teal: #059669;
  --teal-glow: #047857;
  --teal-dark: #065F46;
  --teal-deep: #ECFDF5;
  --orange: #D97706;
  --orange-glow: #B45309;
  --amber: #B45309;

  --bg-0: #F1F4F8;         /* body backdrop */
  --bg-1: #F7F9FC;         /* app / sidebar bg */
  --bg-2: #FFFFFF;         /* card */
  --bg-3: #F1F4F8;         /* elevated / task rows */
  --bg-4: #E7EDF4;         /* input */
  --sidebar-bg-a: #0E2135; /* keep sidebar dark for command-center feel */
  --sidebar-bg-b: #061423;
  --topbar-bg: rgba(255,255,255,.9);
  --line: #E2E7EE;
  --line-2: #CFD7E1;
  --line-3: #A9B5C4;

  --ink: #0F172A;
  --ink-2: #475569;
  --ink-3: #64748B;
  --ink-4: #94A3B8;
  --ink-heading: #0F172A;

  --lv0: #16A34A;
  --lv0-bg: rgba(22,163,74,.10);
  --lv0-line: rgba(22,163,74,.40);
  --lv1: #CA8A04;
  --lv1-bg: rgba(202,138,4,.12);
  --lv1-line: rgba(202,138,4,.40);
  --lv2: #EA580C;
  --lv2-bg: rgba(234,88,12,.10);
  --lv2-line: rgba(234,88,12,.40);
  --lv3: #DC2626;
  --lv3-bg: rgba(220,38,38,.10);
  --lv3-line: rgba(220,38,38,.45);
  --lv4: #7C3AED;
  --lv4-bg: rgba(124,58,237,.10);
  --lv4-line: rgba(124,58,237,.45);

  --good: #16A34A;
  --warn: #EA580C;
  --crit: #DC2626;
  --info: #0284C7;

  --backdrop-a: rgba(5,150,105,.05);
  --backdrop-b: rgba(217,119,6,.04);
  --grid-line: rgba(15,23,42,.04);
  --modal-scrim: rgba(15,23,42,.5);

  --shadow: 0 1px 2px rgba(15,23,42,.05), 0 2px 8px rgba(15,23,42,.06);
  --shadow-lg: 0 20px 48px rgba(15,23,42,.15), 0 4px 12px rgba(15,23,42,.08);
  --shadow-glow: 0 0 0 1px rgba(5,150,105,.35), 0 0 24px rgba(5,150,105,.20);

  color-scheme: light;
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg-0);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  min-height: 100vh;
}
body::before {
  /* subtle grid backdrop */
  content: "";
  position: fixed; inset: 0;
  background:
    radial-gradient(1200px 800px at 12% -10%, var(--backdrop-a), transparent 60%),
    radial-gradient(900px 700px at 100% 100%, var(--backdrop-b), transparent 60%),
    linear-gradient(var(--grid-line) 1px, transparent 1px) 0 0/40px 40px,
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px) 0 0/40px 40px,
    var(--bg-0);
  z-index: -1;
  pointer-events: none;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea {
  font-family: inherit; font-size: 13.5px; color: var(--ink);
  background: var(--bg-4); border: 1px solid var(--line-2);
  border-radius: var(--r-sm); padding: 8px 11px; outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--teal-glow);
  box-shadow: 0 0 0 3px rgba(52,211,153,.18);
}
::placeholder { color: var(--ink-4); }
h1,h2,h3,h4 { line-height: 1.25; font-weight: 700; color: var(--ink-heading); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--ink-3); font-weight: 600; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; background: var(--bg-3); }
tr:last-child td { border-bottom: none; }
a { color: var(--teal-glow); text-decoration: none; }
code, .mono { font-family: var(--mono); font-size: .92em; }
hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; border: 2px solid var(--bg-1); }
::-webkit-scrollbar-thumb:hover { background: var(--line-3); }

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns .28s cubic-bezier(.2,.8,.2,1);
}

.sidebar {
  background: linear-gradient(180deg, var(--sidebar-bg-a) 0%, var(--sidebar-bg-b) 100%);
  border-right: 1px solid var(--line);
  padding: 14px 12px;
  display: flex; flex-direction: column; gap: 3px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  z-index: 60;
  color: #E7EEF7;  /* sidebar keeps dark styling in both themes */
  width: 100%;
  min-width: 0;
  transition: width .28s cubic-bezier(.2,.8,.2,1), padding .28s;
}
.sidebar::after {
  content: ""; position: absolute; inset: 0 -1px 0 auto; width: 1px;
  background: linear-gradient(180deg, transparent, var(--teal-glow) 20%, var(--teal) 60%, transparent);
  opacity: .3;
  pointer-events: none;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 6px 8px 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}
.brand-logo {
  width: 40px; height: 40px; flex: none; border-radius: 10px;
  background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%);
  display: grid; place-items: center;
  box-shadow: 0 0 0 1px rgba(52,211,153,.4), 0 6px 20px rgba(16,185,129,.35);
  position: relative;
}
.brand-logo::after {
  content: ""; position: absolute; inset: -2px; border-radius: 12px;
  background: conic-gradient(from 0deg, transparent 70%, rgba(52,211,153,.5), transparent);
  animation: spin 4s linear infinite;
  z-index: -1;
  opacity: .6;
}
@keyframes spin { to { transform: rotate(360deg); } }
.brand-name {
  font-weight: 800; font-size: 13px; letter-spacing: .04em; color: #fff;
}
.brand-sub {
  font-size: 9.5px; color: var(--teal-glow);
  text-transform: uppercase; letter-spacing: .12em; font-weight: 700;
}
.nav-group {
  font-size: 9.5px; letter-spacing: .13em; text-transform: uppercase;
  color: var(--ink-4); font-weight: 700; padding: 12px 10px 4px;
}
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  color: #C6D4E4;  /* sidebar always dark, so light gray */
  padding: 8px 10px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  transition: background .15s, color .15s;
  position: relative;
}
.nav-btn svg { flex: none; opacity: .8; }
.nav-btn:hover { background: rgba(52,211,153,.10); color: #fff; }
.nav-btn.active {
  background: linear-gradient(90deg, rgba(16,185,129,.25), rgba(16,185,129,0));
  color: #fff; font-weight: 600;
}
.nav-btn.active::before {
  content: ""; position: absolute;
  left: -12px; top: 6px; bottom: 6px; width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--teal-glow);
  box-shadow: 0 0 12px var(--teal-glow);
}
.nav-badge {
  margin-left: auto;
  background: var(--orange); color: #1A0F00;
  font-size: 10px; font-weight: 800;
  border-radius: 99px; padding: 1px 7px;
  min-width: 20px; text-align: center;
}
.sidebar-foot {
  margin-top: auto; padding: 12px 8px 4px;
  border-top: 1px solid var(--line);
  font-size: 10.5px; color: var(--ink-4); line-height: 1.6;
}

/* Sidebar collapse toggle button */
.sb-toggle {
  display: flex; align-items: center; justify-content: center;
  gap: 8px;
  padding: 8px 10px; margin-top: 4px;
  color: var(--ink-3);
  font-size: 11.5px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s, color .15s;
  border: 1px dashed rgba(255,255,255,.08);
  background: transparent;
  width: 100%;
}
.sb-toggle:hover { background: rgba(52,211,153,.08); color: var(--teal-glow); border-color: rgba(52,211,153,.30); }
.sb-toggle .sb-toggle-icon { transition: transform .28s; flex: none; }

/* ================================================================
   COLLAPSED SIDEBAR STATE
   ================================================================ */
.app.sb-collapsed .sidebar {
  padding: 14px 6px;
  width: var(--sidebar-w-collapsed);
  min-width: 0;
  overflow: hidden;
}
.app.sb-collapsed {
  grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr);
}
/* Hide text labels — keep only icons */
.app.sb-collapsed .brand > div:last-child,
.app.sb-collapsed .nav-group,
.app.sb-collapsed .sidebar-foot,
.app.sb-collapsed .nav-btn > *:not(svg):not(.nav-badge) {
  display: none;
}
.app.sb-collapsed .brand {
  justify-content: center;
  padding: 6px 0 14px;
}
.app.sb-collapsed .nav-btn {
  justify-content: center;
  padding: 10px 8px;
  position: relative;
}
.app.sb-collapsed .nav-btn svg { opacity: 1; }
.app.sb-collapsed .nav-btn .nav-badge {
  position: absolute;
  top: 3px; right: 5px;
  margin-left: 0;
  min-width: 16px; height: 16px;
  font-size: 9.5px;
  padding: 0 4px;
  line-height: 16px;
}
.app.sb-collapsed .nav-btn.active::before {
  left: -6px;
}
/* Tooltip on hover for collapsed nav-btn */
.app.sb-collapsed .nav-btn::after {
  content: attr(data-tip);
  position: absolute;
  left: calc(100% + 14px);
  top: 50%; transform: translateY(-50%);
  background: var(--bg-3);
  color: var(--ink);
  border: 1px solid var(--line-2);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s, transform .15s;
  box-shadow: var(--shadow-lg);
  z-index: 100;
}
.app.sb-collapsed .nav-btn:hover::after {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}
/* Rotate arrow when collapsed */
.app.sb-collapsed .sb-toggle .sb-toggle-icon {
  transform: rotate(180deg);
}
.app.sb-collapsed .sb-toggle {
  padding: 8px 6px;
  border-style: solid;
  border-color: rgba(255,255,255,.06);
}

/* Nav group separator when collapsed */
.app.sb-collapsed .nav-group {
  display: block;
  height: 1px;
  padding: 0;
  margin: 8px 8px;
  background: rgba(255,255,255,.08);
  overflow: hidden;
  text-indent: -9999px;
}

/* ---------- Main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--topbar-bg);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding: 0 20px;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px;
}
.topbar h1 {
  font-size: 15.5px; font-weight: 700; color: var(--ink-heading); letter-spacing: -.005em;
}
.topbar .sub-title {
  font-size: 11px; color: var(--ink-3); font-weight: 500;
}
.top-meta { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* Scenario switcher */
.scenario-sw {
  display: flex; background: var(--bg-2);
  border: 1px solid var(--line-2); border-radius: 999px;
  padding: 3px; gap: 2px;
}
.scenario-sw button {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  color: var(--ink-2);
  transition: all .18s;
}
.scenario-sw button .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3);
}
.scenario-sw button.on {
  background: var(--bg-4); color: var(--ink-heading);
  box-shadow: inset 0 0 0 1px var(--line-3);
}
.scenario-sw button.on[data-s="storm"] .dot { background: var(--orange); box-shadow: 0 0 8px var(--orange); }
.scenario-sw button.on[data-s="fire"] .dot { background: var(--crit); box-shadow: 0 0 8px var(--crit); animation: pulse-glow 1.4s infinite; }
.scenario-sw button.on[data-s="norm"] .dot { background: var(--good); box-shadow: 0 0 8px var(--good); }

.clock {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-weight: 700; color: var(--ink-heading); font-size: 13.5px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 12px;
  display: flex; align-items: center; gap: 8px;
}
.clock .live-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--good);
  box-shadow: 0 0 8px var(--good); animation: pulse-glow 2s infinite;
}
@keyframes pulse-glow { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .45; transform: scale(.85); } }

.content {
  padding: 20px 22px 60px;
  max-width: 1720px;
  width: 100%;
  margin: 0 auto;
}
.section { display: none; animation: fadeIn .3s ease; }
.section.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  position: relative;
}
.card.glow { box-shadow: var(--shadow), 0 0 0 1px rgba(52,211,153,.25), 0 0 32px rgba(16,185,129,.12); }
.card-h {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.card-h h3 { font-size: 13.5px; color: var(--ink-heading); font-weight: 700; letter-spacing: -.005em; }
.card-h .sub { font-size: 11.5px; color: var(--ink-3); width: 100%; margin-top: 2px; font-weight: 400; }
.card-b { padding: 14px 16px; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2,1fr); }
.g3 { grid-template-columns: repeat(3,1fr); }
.g4 { grid-template-columns: repeat(4,1fr); }
.g5 { grid-template-columns: repeat(5,1fr); }
.mt { margin-top: 12px; }
.mt8 { margin-top: 8px; }
.mb { margin-bottom: 12px; }
.muted { color: var(--ink-3); font-size: 12px; }
.small { font-size: 12px; }
.tiny { font-size: 10.5px; }
.b { font-weight: 700; }
.right { margin-left: auto; }
.flex { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.nowrap { white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-weight: 600; font-size: 13px;
  border-radius: 8px; padding: 8px 14px;
  border: 1px solid transparent;
  transition: all .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(180deg, var(--teal), var(--teal-dark));
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,.12) inset, 0 8px 24px rgba(16,185,129,.25);
}
.btn-primary:hover { filter: brightness(1.15); }
.btn-orange {
  background: linear-gradient(180deg, var(--orange), #B46A00);
  color: #1A0F00;
  box-shadow: 0 1px 0 rgba(255,255,255,.2) inset, 0 8px 24px rgba(243,146,0,.28);
}
.btn-danger {
  background: linear-gradient(180deg, var(--crit), #B91C1C);
  color: #fff;
  box-shadow: 0 8px 24px rgba(239,68,68,.28);
}
.btn-ghost {
  background: var(--bg-2); border-color: var(--line-2); color: var(--ink);
}
.btn-ghost:hover { background: var(--bg-3); border-color: var(--line-3); }
.btn-navy { background: var(--bg-4); color: #fff; border: 1px solid var(--line-2); }
.btn-navy:hover { background: var(--bg-3); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-lg { padding: 10px 20px; font-size: 14px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700;
  border-radius: 999px; padding: 2px 9px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge svg { flex: none; }
.bg-lv0 { background: var(--lv0-bg); color: var(--lv0); border-color: var(--lv0-line); }
.bg-lv1 { background: var(--lv1-bg); color: var(--lv1); border-color: var(--lv1-line); }
.bg-lv2 { background: var(--lv2-bg); color: var(--lv2); border-color: var(--lv2-line); }
.bg-lv3 { background: var(--lv3-bg); color: var(--lv3); border-color: var(--lv3-line); }
.bg-lv4 { background: var(--lv4-bg); color: var(--lv4); border-color: var(--lv4-line); }
.bg-navy { background: var(--bg-4); color: var(--ink); border-color: var(--line-2); }
.bg-teal { background: rgba(16,185,129,.16); color: var(--teal-glow); border-color: rgba(52,211,153,.4); }
.bg-good { background: rgba(34,197,94,.14); color: var(--good); border-color: rgba(34,197,94,.4); }
.bg-warn { background: rgba(245,158,11,.14); color: var(--warn); border-color: rgba(245,158,11,.4); }
.bg-crit { background: rgba(239,68,68,.14); color: var(--crit); border-color: rgba(239,68,68,.4); }

/* ---------- Stat cards ---------- */
.stat {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}
.stat::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--teal-glow);
}
.stat.navy::before { background: var(--info); }
.stat.warn::before { background: var(--warn); }
.stat.crit::before { background: var(--crit); }
.stat.good::before { background: var(--good); }
.s-lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 600; }
.s-val {
  font-family: var(--mono); font-size: 28px; font-weight: 700;
  color: var(--ink-heading); line-height: 1.1; margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.s-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 3px; }

/* ---------- Level banner ---------- */
.level-banner {
  padding: 20px 24px;
  border-radius: var(--r-lg);
  border: 1px solid;
  background: var(--bg-2);
  display: flex; align-items: center; gap: 20px;
  position: relative; overflow: hidden;
  margin-bottom: 14px;
}
.level-banner::before {
  content: ""; position: absolute; inset: 0;
  opacity: .12; pointer-events: none;
  background: radial-gradient(500px 300px at 100% 0%, currentColor, transparent 60%);
}
.level-banner.lv0 { border-color: var(--lv0-line); color: var(--lv0); }
.level-banner.lv1 { border-color: var(--lv1-line); color: var(--lv1); }
.level-banner.lv2 { border-color: var(--lv2-line); color: var(--lv2); }
.level-banner.lv3 { border-color: var(--lv3-line); color: var(--lv3); }
.level-banner.lv4 { border-color: var(--lv4-line); color: var(--lv4); }
.level-banner.lv3, .level-banner.lv4 { animation: alert-flash 3s ease-in-out infinite; }
@keyframes alert-flash {
  0%,100% { box-shadow: 0 0 0 rgba(239,68,68,0); }
  50% { box-shadow: 0 0 40px rgba(239,68,68,.25); }
}
.lv-code { font-size: 22px; font-weight: 800; color: var(--ink-heading); letter-spacing: -.01em;
  margin-top: 2px;
}
.lv-desc {
  font-size: 13px; color: var(--ink-2);
  margin-top: 4px; max-width: 640px;
}
.countdown {
  background: rgba(0,0,0,.4);
  border: 1px solid currentColor;
  border-radius: 12px;
  padding: 10px 18px;
  text-align: center;
}
.cd-num {
  font-family: var(--mono); font-size: 24px; font-weight: 700;
  color: var(--ink-heading); font-variant-numeric: tabular-nums; letter-spacing: .04em;
}
.cd-lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3); margin-top: 3px; }

/* ---------- Alert box ---------- */
.alert-box {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid;
  font-size: 12.5px;
  line-height: 1.5;
}
.alert-box svg { flex: none; margin-top: 2px; }
.ab-info { background: rgba(56,189,248,.10); border-color: rgba(56,189,248,.40); color: var(--info); }
.ab-info b { color: var(--info); }
.ab-warn { background: var(--lv2-bg); border-color: var(--lv2-line); color: var(--lv2); }
.ab-warn b { color: var(--lv2); }
.ab-crit { background: var(--lv3-bg); border-color: var(--lv3-line); color: var(--lv3); }
.ab-crit b { color: var(--lv3); }
.ab-ok { background: var(--lv0-bg); border-color: var(--lv0-line); color: var(--lv0); }
.ab-ok b { color: var(--lv0); }
/* Body text inside alerts uses regular ink so long paragraphs stay readable in both themes */
.alert-box > div { color: var(--ink); }
.alert-box > div .tiny, .alert-box > div .small.muted, .alert-box > div .muted { color: var(--ink-3); }

/* ---------- Drill banner ---------- */
.drill-banner {
  background: repeating-linear-gradient(45deg, #F59E0B, #F59E0B 12px, #B45309 12px, #B45309 24px);
  color: #1A0F00; text-align: center; padding: 5px; font-size: 11.5px; font-weight: 800;
  letter-spacing: .1em; text-transform: uppercase;
  display: none;
}
body.drill .drill-banner { display: block; }
body.drill .app { padding-top: 0; }

/* ---------- Task cards ---------- */
.task {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex; gap: 12px;
  transition: all .15s;
  position: relative;
}
.task:hover { border-color: var(--line-3); background: var(--bg-4); }
.task.overdue { border-color: var(--lv3-line); background: rgba(239,68,68,.06); }
.task.done { opacity: .65; }
.task .t-body { flex: 1; min-width: 0; }
.task .t-title { font-weight: 600; font-size: 13.5px; color: var(--ink-heading); }
.task .t-meta {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-top: 5px; font-size: 11.5px; color: var(--ink-3);
}
.task .t-desc { font-size: 12.5px; color: var(--ink-2); margin-top: 6px; line-height: 1.55; }
.task .t-actions { display: flex; flex-direction: column; gap: 5px; align-items: flex-end; }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--ink-3);
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 5px; padding: 2px 6px;
}

/* ---------- Phase strip ---------- */
.phase-strip {
  display: flex; gap: 4px; margin: 10px 0 14px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 4px; overflow-x: auto;
}
.phase-strip button {
  flex: 1; padding: 8px 10px; border-radius: 7px;
  font-size: 12px; color: var(--ink-2); font-weight: 500;
  white-space: nowrap;
  min-width: max-content;
}
.phase-strip button:hover { background: var(--bg-3); color: var(--ink); }
.phase-strip button.on {
  background: var(--bg-4); color: var(--ink-heading); font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--line-3);
}
.phase-strip button .cnt {
  display: inline-block; margin-left: 5px;
  padding: 0 6px; border-radius: 99px;
  background: var(--line-2); color: var(--ink-2); font-size: 10.5px;
}

/* ---------- Avatar & person ---------- */
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #64748B, #334155);
  color: #fff;
  display: inline-grid; place-items: center;
  font-size: 11px; font-weight: 700;
  flex: none;
  border: 1px solid var(--line-2);
}
.avatar-lg { width: 52px; height: 52px; font-size: 15px; }
.avatar-sm { width: 24px; height: 24px; font-size: 9.5px; }
.avatar.grad-a { background: linear-gradient(135deg, #10B981, #047857); }
.avatar.grad-b { background: linear-gradient(135deg, #F59E0B, #B45309); }
.avatar.grad-c { background: linear-gradient(135deg, #A855F7, #6D28D9); }
.avatar.grad-d { background: linear-gradient(135deg, #EC4899, #BE185D); }
.avatar.grad-e { background: linear-gradient(135deg, #3B82F6, #1D4ED8); }
.avatar.grad-f { background: linear-gradient(135deg, #EF4444, #B91C1C); }
.avatar.grad-g { background: linear-gradient(135deg, #10B981, #065F46); }
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar { margin-left: -8px; box-shadow: 0 0 0 2px var(--bg-2); }
.avatar-stack .avatar:first-child { margin-left: 0; }

.person {
  display: flex; align-items: center; gap: 10px;
}
.person .p-name { font-weight: 600; font-size: 13px; color: var(--ink-heading); }
.person .p-role { font-size: 11.5px; color: var(--ink-3); }

/* ---------- Progress bar ---------- */
.pbar {
  height: 6px; border-radius: 99px;
  background: var(--bg-4); overflow: hidden;
  position: relative;
}
.pbar .p-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--teal-glow));
  border-radius: 99px;
  transition: width .5s ease;
}
.pbar.warn .p-fill { background: linear-gradient(90deg, var(--warn), var(--orange-glow)); }
.pbar.crit .p-fill { background: linear-gradient(90deg, var(--crit), #F87171); }

/* ---------- Radar / animated bits ---------- */
.radar {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 1px solid var(--teal-dark);
  position: relative;
  background: radial-gradient(circle at 50% 50%, rgba(16,185,129,.15), transparent 70%);
  flex: none;
}
.radar::before, .radar::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 1px solid var(--teal-dark);
  opacity: .5;
}
.radar::before { inset: 5px; }
.radar::after { inset: 12px; }
.radar .sweep {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0deg, transparent 300deg, rgba(52,211,153,.6) 355deg, transparent 360deg);
  animation: spin 3s linear infinite;
}
.radar .blip {
  position: absolute; width: 4px; height: 4px; border-radius: 50%;
  background: var(--orange-glow);
  box-shadow: 0 0 6px var(--orange);
  animation: blip 2s infinite;
}
@keyframes blip { 0%,100% { opacity: 0; } 40%,60% { opacity: 1; } }

/* ---------- Map ---------- */
.map-wrap {
  position: relative;
  background: radial-gradient(circle at 50% 50%, #0F1A2C 0%, #05080F 100%);
  border-radius: var(--r);
  border: 1px solid var(--line);
  overflow: hidden;
  aspect-ratio: 16/9;
  min-height: 340px;
}
/* Map always stays dark — it looks best that way. Add subtle glow border in light. */
[data-theme="light"] .map-wrap {
  box-shadow: 0 0 0 1px rgba(15,23,42,.08), 0 4px 12px rgba(15,23,42,.10);
}
.map-wrap svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.map-marker {
  position: absolute; transform: translate(-50%,-50%);
  display: flex; flex-direction: column; align-items: center;
  cursor: pointer;
  z-index: 5;
}
.map-marker .mk-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--teal-glow);
  box-shadow: 0 0 0 3px rgba(52,211,153,.25), 0 0 12px var(--teal-glow);
  border: 2px solid var(--bg-0);
  transition: all .2s;
}
.map-marker[data-risk="warn"] .mk-dot { background: var(--warn); box-shadow: 0 0 0 3px rgba(245,158,11,.25), 0 0 12px var(--warn); }
.map-marker[data-risk="crit"] .mk-dot {
  background: var(--crit); box-shadow: 0 0 0 3px rgba(239,68,68,.3), 0 0 16px var(--crit);
  animation: pulse-ring 1.4s infinite;
}
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 3px rgba(239,68,68,.5), 0 0 16px var(--crit); }
  70% { box-shadow: 0 0 0 12px rgba(239,68,68,0), 0 0 16px var(--crit); }
  100% { box-shadow: 0 0 0 3px rgba(239,68,68,0), 0 0 16px var(--crit); }
}
.map-marker .mk-label {
  margin-top: 4px;
  font-size: 10.5px; font-weight: 600;
  color: #fff;                          /* map is always dark → white label */
  background: rgba(0,0,0,.72);
  border: 1px solid rgba(255,255,255,.15);
  padding: 2px 6px; border-radius: 5px;
  white-space: nowrap;
  backdrop-filter: blur(4px);
}
.map-marker:hover { z-index: 6; }
.map-marker:hover .mk-dot { transform: scale(1.3); }
.map-marker.warehouse .mk-dot {
  background: var(--info);
  box-shadow: 0 0 0 3px rgba(56,189,248,.25), 0 0 12px var(--info);
  border-radius: 3px;
}
.map-legend {
  position: absolute; left: 12px; bottom: 12px;
  background: rgba(5,7,12,.72);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 10.5px; color: #E7EEF7;         /* map always dark → light text */
  display: flex; gap: 12px;
}
.map-legend .lg { display: flex; align-items: center; gap: 5px; }
.map-legend .sw { width: 10px; height: 10px; border-radius: 50%; }

/* ---------- Timeline (horizontal) ---------- */
.tl-wrap {
  position: relative;
  padding: 24px 0 12px;
  overflow-x: auto;
}
.tl-line {
  position: absolute; left: 0; right: 0; top: 50%;
  height: 2px; background: linear-gradient(90deg, var(--teal-dark), var(--line-3), var(--teal-dark));
  transform: translateY(-50%);
}
.tl-track {
  display: flex; gap: 24px;
  min-width: max-content;
  padding: 0 20px;
  position: relative;
}
.tl-node {
  min-width: 180px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
  font-size: 12px; color: var(--ink-2);
  position: relative;
}
.tl-node::before {
  content: ""; position: absolute;
  top: -14px; left: 20px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--teal-glow);
  box-shadow: 0 0 0 3px var(--bg-1), 0 0 8px var(--teal-glow);
}
.tl-node.now::before { background: var(--orange-glow); box-shadow: 0 0 0 3px var(--bg-1), 0 0 10px var(--orange); animation: pulse-glow 1.5s infinite; }
.tl-node.past { opacity: .55; }
.tl-node.past::before { background: var(--ink-3); box-shadow: 0 0 0 3px var(--bg-1); }
.tl-node .tl-t { font-family: var(--mono); font-size: 10.5px; color: var(--teal-glow); font-weight: 600; }
.tl-node .tl-title { color: var(--ink-heading); font-weight: 600; margin: 2px 0; font-size: 12.5px; }
.tl-node .tl-sub { font-size: 11px; color: var(--ink-3); }

/* ---------- Camera grid (simulated live) ---------- */
.cam-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.cam {
  position: relative; aspect-ratio: 4/3;
  border-radius: 8px; overflow: hidden;
  background: #0A0F17;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: all .2s;
}
.cam:hover { border-color: var(--teal-glow); }
.cam .cam-scene {
  position: absolute; inset: 0;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.02), rgba(255,255,255,.02) 4px, rgba(255,255,255,0) 4px, rgba(255,255,255,0) 8px),
    linear-gradient(160deg, #1E3A5F 0%, #0A1928 50%, #050B12 100%);
}
.cam .cam-scene::before {
  /* scan lines */
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(180deg, transparent, transparent 3px, rgba(0,0,0,.15) 3px, rgba(0,0,0,.15) 4px);
  animation: scanline 6s linear infinite;
}
@keyframes scanline { 0% { transform: translateY(-4px); } 100% { transform: translateY(0); } }
.cam .cam-hud {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 8px 10px;
  color: #fff; font-family: var(--mono); font-size: 10px;
  z-index: 2;
}
.cam .cam-hud .live {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(239,68,68,.85); color: #fff;
  padding: 2px 7px; border-radius: 4px; font-weight: 700;
  font-family: var(--font); font-size: 10px;
  align-self: flex-start;
}
.cam .cam-hud .live::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%; background: #fff;
  animation: pulse-glow 1s infinite;
}
.cam .cam-label {
  background: rgba(0,0,0,.6); padding: 3px 7px; border-radius: 4px;
  align-self: flex-start; font-size: 10.5px; font-weight: 600;
  font-family: var(--font);
}
.cam.alert { border-color: var(--crit); animation: alert-flash 2s infinite; }
.cam.alert .cam-scene {
  background:
    radial-gradient(circle at 30% 60%, rgba(239,68,68,.5), transparent 40%),
    radial-gradient(circle at 60% 30%, rgba(245,158,11,.4), transparent 40%),
    linear-gradient(160deg, #4B1717 0%, #1A0808 100%);
}

/* ---------- Heatmap tiles ---------- */
.heat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.heat-tile {
  padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  position: relative;
  transition: all .2s;
  cursor: pointer;
}
.heat-tile:hover { border-color: var(--line-3); }
.heat-tile.h1 { background: linear-gradient(135deg, rgba(34,197,94,.15), var(--bg-3)); border-color: rgba(34,197,94,.3); }
.heat-tile.h2 { background: linear-gradient(135deg, rgba(250,204,21,.15), var(--bg-3)); border-color: rgba(250,204,21,.3); }
.heat-tile.h3 { background: linear-gradient(135deg, rgba(245,158,11,.2), var(--bg-3)); border-color: rgba(245,158,11,.4); }
.heat-tile.h4 { background: linear-gradient(135deg, rgba(239,68,68,.22), var(--bg-3)); border-color: rgba(239,68,68,.45); }
.heat-tile .h-name { font-size: 12px; font-weight: 600; color: var(--ink-heading); }
.heat-tile .h-val { font-family: var(--mono); font-size: 20px; font-weight: 700; margin-top: 2px; }
.heat-tile .h-sub { font-size: 10.5px; color: var(--ink-3); }
.heat-tile.h1 .h-val { color: var(--good); }
.heat-tile.h2 .h-val { color: var(--amber); }
.heat-tile.h3 .h-val { color: var(--warn); }
.heat-tile.h4 .h-val { color: var(--crit); }

/* ---------- Leaderboard ---------- */
.lb-row {
  display: grid; grid-template-columns: 32px 1fr auto auto;
  align-items: center; gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  transition: background .15s;
}
.lb-row:last-child { border-bottom: none; }
.lb-row:hover { background: var(--bg-3); }
.lb-rank {
  font-family: var(--mono); font-size: 15px; font-weight: 700;
  color: var(--ink-3); text-align: center;
}
.lb-row.gold .lb-rank { color: #FFD700; text-shadow: 0 0 8px rgba(255,215,0,.4); }
.lb-row.silver .lb-rank { color: #C0C0C0; }
.lb-row.bronze .lb-rank { color: #CD7F32; }
.lb-name { font-weight: 600; color: var(--ink-heading); font-size: 13px; }
.lb-sub { font-size: 11px; color: var(--ink-3); margin-top: 1px; }
.lb-score { font-family: var(--mono); font-weight: 700; color: var(--teal-glow); font-size: 14px; }

/* ---------- Chat drawer ---------- */
.fab-stack {
  position: fixed; right: 20px; bottom: 20px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 70;
}
.fab {
  width: 52px; height: 52px; border-radius: 50%;
  background: linear-gradient(180deg, var(--teal), var(--teal-dark));
  color: #fff; display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(16,185,129,.4), 0 0 0 1px rgba(52,211,153,.5);
  cursor: pointer; transition: transform .2s;
  position: relative;
}
.fab:hover { transform: translateY(-2px) scale(1.05); }
.fab.orange { background: linear-gradient(180deg, var(--orange), #B46A00); box-shadow: 0 8px 24px rgba(243,146,0,.4), 0 0 0 1px rgba(255,181,71,.5); }
.fab .fab-badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 20px; height: 20px; border-radius: 999px;
  background: var(--crit); color: #fff;
  font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
  padding: 0 5px;
  box-shadow: 0 0 0 2px var(--bg-0);
}

.drawer {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: 380px; max-width: 92vw;
  background: var(--bg-1);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 40px rgba(0,0,0,.5);
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.2,.8,.2,1);
  z-index: 80;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-h {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.drawer-h h3 { font-size: 14px; color: var(--ink-heading); }
.drawer-close {
  width: 28px; height: 28px; border-radius: 6px;
  color: var(--ink-3);
  display: grid; place-items: center;
}
.drawer-close:hover { background: var(--bg-3); color: var(--ink); }
.drawer-body { flex: 1; overflow-y: auto; padding: 14px; }
.drawer-foot { padding: 12px 14px; border-top: 1px solid var(--line); }

/* chat bubbles */
.chat-msg {
  display: flex; gap: 10px;
  margin-bottom: 14px;
}
.chat-msg .cm-body {
  flex: 1; min-width: 0;
}
.chat-msg .cm-head {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 11.5px;
}
.chat-msg .cm-name { color: var(--ink-heading); font-weight: 600; font-size: 12.5px; }
.chat-msg .cm-time { color: var(--ink-4); font-family: var(--mono); font-size: 10.5px; }
.chat-msg .cm-text {
  background: var(--bg-3); border: 1px solid var(--line);
  padding: 8px 11px; border-radius: 4px 10px 10px 10px;
  margin-top: 3px;
  font-size: 13px; color: var(--ink);
  line-height: 1.5;
}
.chat-msg.me .cm-text {
  background: rgba(16,185,129,.15);
  border-color: rgba(52,211,153,.35);
}
.chat-msg.ai .cm-text {
  background: linear-gradient(135deg, rgba(168,85,247,.12), rgba(59,130,246,.08));
  border-color: rgba(168,85,247,.35);
}
.chat-msg.system .cm-text {
  background: rgba(56,189,248,.08); border-color: rgba(56,189,248,.35);
  font-size: 12px; color: #7DD3FC;
}

.chat-composer {
  display: flex; gap: 6px;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 6px;
}
.chat-composer input {
  flex: 1; background: transparent; border: none; padding: 6px 8px;
  color: var(--ink);
}
.chat-composer input:focus { box-shadow: none; }
.chat-composer button { padding: 6px 12px; }

/* AI suggestion pills */
.ai-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.ai-pill {
  background: var(--bg-3); border: 1px solid var(--line-2);
  border-radius: 999px; padding: 5px 11px;
  font-size: 11.5px; color: var(--ink-2);
  cursor: pointer; transition: all .15s;
}
.ai-pill:hover { border-color: var(--teal-glow); color: var(--teal-glow); background: rgba(16,185,129,.08); }

/* Typing indicator */
.typing { display: inline-flex; gap: 3px; padding: 2px 0; }
.typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3);
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: var(--modal-scrim);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: none;
  align-items: flex-start; justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 640px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  animation: modal-in .25s ease;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(20px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-lg { max-width: 900px; }
.modal-h {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
  position: sticky; top: 0; background: var(--bg-2); z-index: 2;
}
.modal-h h3 { font-size: 15px; color: var(--ink-heading); }
.modal-b { padding: 16px 18px; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- Notification panel ---------- */
.bell-wrap { position: relative; }
.bell-btn {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--ink-2); display: grid; place-items: center;
  position: relative;
}
.bell-btn:hover { background: var(--bg-3); color: var(--ink-heading); }
.bell-cnt {
  position: absolute; top: -4px; right: -4px;
  min-width: 18px; height: 18px; border-radius: 999px;
  background: var(--crit); color: #fff;
  font-size: 10.5px; font-weight: 700;
  display: grid; place-items: center;
  padding: 0 4px;
  box-shadow: 0 0 0 2px var(--bg-2);
}
.notif-panel {
  position: absolute; right: 0; top: calc(100% + 8px);
  width: 380px; max-height: 480px; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow-lg);
  z-index: 90; display: none;
}
.notif-panel.open { display: block; }
.notif-head {
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px;
  position: sticky; top: 0; background: var(--bg-2);
}
.notif-item {
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: flex; gap: 10px;
}
.notif-item:hover { background: var(--bg-3); }
.notif-item.unread { background: rgba(16,185,129,.05); }
.notif-item.unread::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--teal-glow); margin-top: 6px; flex: none;
  box-shadow: 0 0 6px var(--teal-glow);
}
.notif-item .n-body { flex: 1; min-width: 0; }
.notif-item .n-t { font-size: 12.5px; color: var(--ink-heading); font-weight: 600; }
.notif-item .n-d { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.notif-item .n-time { font-size: 10.5px; color: var(--ink-4); font-family: var(--mono); margin-top: 3px; }

/* ---------- Level picker cards ---------- */
.lv-card {
  padding: 14px 16px; border-radius: 12px;
  background: var(--bg-3); border: 1px solid var(--line-2);
  cursor: pointer; transition: all .2s;
  text-align: left;
  color: var(--ink);
}
.lv-card:hover { border-color: var(--line-3); background: var(--bg-4); }
.lv-card.selected {
  background: linear-gradient(160deg, var(--bg-4), var(--bg-3));
  box-shadow: 0 0 0 1px currentColor, 0 8px 24px rgba(0,0,0,.4);
}
.lv-card.selected.lv0-c { color: var(--lv0); }
.lv-card.selected.lv1-c { color: var(--lv1); }
.lv-card.selected.lv2-c { color: var(--lv2); }
.lv-card.selected.lv3-c { color: var(--lv3); }
.lv-card.selected.lv4-c { color: var(--lv4); }
.lv-card h4 { color: var(--ink-heading); font-size: 14.5px; }
.lv-card .lv-t { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; }
.lv-card .lv-d { font-size: 11.5px; color: var(--ink-3); margin-top: 4px; line-height: 1.5; }

/* ---------- Org chart ---------- */
.org-tree { display: flex; flex-direction: column; gap: 8px; }
.org-node {
  background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px;
  display: flex; align-items: center; gap: 10px;
  cursor: pointer;
  transition: all .15s;
}
.org-node:hover { border-color: var(--teal-glow); background: var(--bg-4); }
.org-node.open .caret { transform: rotate(90deg); }
.caret {
  width: 16px; color: var(--ink-3);
  transition: transform .15s;
}
.org-children {
  margin-left: 24px;
  padding-left: 14px;
  border-left: 1px dashed var(--line-2);
  display: none;
  flex-direction: column; gap: 6px;
  margin-top: 6px;
}
.org-node.open + .org-children { display: flex; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; bottom: 90px; right: 20px; z-index: 200; display: flex; flex-direction: column-reverse; gap: 8px; }
.toast {
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  border-left: 3px solid var(--teal-glow);
  border-radius: 8px;
  padding: 10px 14px;
  min-width: 240px;
  color: var(--ink);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: toast-in .3s ease;
}
.toast.warn { border-left-color: var(--warn); }
.toast.crit { border-left-color: var(--crit); }
.toast.good { border-left-color: var(--good); }
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Theme toggle button ---------- */
.theme-btn, .device-btn {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--ink-2); display: grid; place-items: center;
  cursor: pointer; transition: all .15s;
}
.theme-btn:hover, .device-btn:hover { background: var(--bg-3); color: var(--ink-heading); }
.theme-btn .icon-sun { display: none; }
[data-theme="light"] .theme-btn .icon-moon { display: none; }
[data-theme="light"] .theme-btn .icon-sun { display: block; }

/* Device preview switcher */
.device-sw {
  display: inline-flex; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 2px; gap: 1px;
}
.device-sw button {
  width: 28px; height: 28px; border-radius: 6px;
  display: grid; place-items: center;
  color: var(--ink-3);
  transition: all .15s;
}
.device-sw button:hover { color: var(--ink); }
.device-sw button.on {
  background: var(--bg-4); color: var(--ink-heading);
  box-shadow: inset 0 0 0 1px var(--line-3);
}

/* Sidebar backdrop for mobile drawer */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
  z-index: 55;
  animation: fadeIn .2s;
}
.sidebar-backdrop.on { display: block; }

/* Mobile menu button */
.menu-btn {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--ink); display: none;
  place-items: center;
}
.menu-btn:hover { background: var(--bg-3); }

/* Mobile bottom tab bar */
.mobile-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0;
  height: var(--bottom-nav-h);
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(env(safe-area-inset-bottom, 0) + 6px);
  z-index: 55;
  box-shadow: 0 -8px 24px rgba(0,0,0,.15);
}
.mobile-nav-inner {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px;
  height: 100%;
}
.mobile-nav button {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  color: var(--ink-3);
  font-size: 10px; font-weight: 500;
  border-radius: 8px;
  padding: 4px 2px;
  min-height: 44px;
  transition: color .15s, background .15s;
}
.mobile-nav button svg { flex: none; }
.mobile-nav button.active {
  color: var(--teal-glow);
  background: rgba(16,185,129,.10);
}
.mobile-nav button.active svg { color: var(--teal-glow); }

/* ---------- Device preview frame ---------- */
body.dev-tablet, body.dev-mobile {
  background: #08090C;
  padding: 24px 0;
  min-height: 100vh;
}
body.dev-tablet::before, body.dev-mobile::before {
  display: none;
}
body.dev-tablet .app, body.dev-mobile .app {
  max-width: 820px;
  margin: 0 auto;
  box-shadow: 0 0 0 12px #1a1d24, 0 30px 80px rgba(0,0,0,.55);
  border-radius: 28px;
  overflow: hidden;
  min-height: 900px;
  position: relative;                   /* anchor sidebar to app frame */
}
body.dev-mobile .app {
  max-width: 400px;
  min-height: 780px;
}
/* Sidebar & backdrop scoped to app frame in device preview */
body.dev-tablet .sidebar,
body.dev-mobile .sidebar {
  position: absolute; left: 0; top: 0; height: 100%;
  z-index: 60;
}
body.dev-tablet .sidebar-backdrop,
body.dev-mobile .sidebar-backdrop {
  position: absolute;
  z-index: 55;
}
/* Notch cue on mobile preview */
body.dev-mobile .app::before {
  content: "";
  position: absolute; top: 8px; left: 50%;
  transform: translateX(-50%);
  width: 100px; height: 4px; border-radius: 4px;
  background: rgba(255,255,255,.15);
  z-index: 200; pointer-events: none;
}

/* ---------- Responsive breakpoints (real) ---------- */
@media (max-width: 1024px) {
  :root { --sidebar-w: 0px; }
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100vh;
    width: 260px; transform: translateX(-100%);
    transition: transform .3s cubic-bezier(.2,.8,.2,1);
    box-shadow: 8px 0 30px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 14px 14px 80px; }
  .g4, .g3 { grid-template-columns: repeat(2, 1fr); }
  .drawer { width: 100%; }
  .notif-panel { width: min(360px, calc(100vw - 30px)); }
  .menu-btn { display: grid; }
  .device-sw { display: none; }
}
@media (max-width: 640px) {
  .g4, .g3, .g2 { grid-template-columns: 1fr; }
  .topbar { padding: 0 10px; gap: 6px; }
  .topbar h1 { font-size: 14px; }
  .topbar .sub-title { display: none; }
  .top-meta { gap: 4px; }
  .scenario-sw { display: none; }        /* moved to bottom sheet */
  .clock { padding: 4px 8px; font-size: 11.5px; }
  .clock .clock-date { display: none; }
  #demoBtn .lbl { display: none; }
  #meBadge span { display: none; }
  .level-banner {
    flex-direction: column; align-items: flex-start;
    padding: 14px; gap: 12px;
  }
  .level-banner .right { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .level-banner .right .radar { display: none; }
  .content { padding: 12px 12px calc(var(--bottom-nav-h) + 20px); }
  .card-b { padding: 12px; }
  .card-h { padding: 10px 12px; }
  .lv-code { font-size: 18px; }
  .s-val { font-size: 22px; }
  .stat { padding: 10px 12px; }

  /* Show mobile bottom nav */
  .mobile-nav { display: block; }

  /* Hide FAB stack — actions moved elsewhere */
  .fab-stack { bottom: calc(var(--bottom-nav-h) + 12px); right: 12px; }
  .fab { width: 46px; height: 46px; }

  /* Tables: horizontal scroll */
  .card-b > table, .card-b table { display: block; overflow-x: auto; }
  .card-b > table thead, .card-b table thead { min-width: max-content; }

  /* Modal full-screen on mobile */
  .modal-overlay { padding: 12px; }
  .modal { max-height: calc(100vh - 24px); }
  .modal-h, .modal-b, .modal-f { padding: 12px 14px; }

  /* Camera grid smaller */
  .cam-grid { grid-template-columns: repeat(2, 1fr); }
  .heat-grid { grid-template-columns: repeat(2, 1fr); }

  /* Timeline nodes narrower */
  .tl-node { min-width: 160px; }
}
@media (min-width: 1600px) {
  body { font-size: 14.5px; }
}
@media (min-width: 1920px) {
  :root { --sidebar-w: 260px; --topbar-h: 68px; }
  body { font-size: 15px; }
  .content { padding: 24px 28px 80px; }
  .s-val { font-size: 32px; }
  .lv-code { font-size: 26px; }
}

/* Forced device preview mode — override query for consistent demo */
body.dev-mobile .g4, body.dev-mobile .g3, body.dev-mobile .g2 { grid-template-columns: 1fr; }
body.dev-mobile .scenario-sw { display: none; }
body.dev-mobile .mobile-nav { display: block; }
body.dev-mobile .menu-btn { display: grid; }
body.dev-mobile .app { grid-template-columns: 1fr; }
body.dev-mobile .sidebar { transform: translateX(-100%); position: fixed; width: 260px; height: 100%; }
body.dev-mobile .sidebar.open { transform: translateX(0); }
body.dev-mobile .device-sw { }        /* keep visible for switching back */
body.dev-mobile .cam-grid, body.dev-mobile .heat-grid { grid-template-columns: repeat(2, 1fr); }
body.dev-mobile .content { padding: 12px 12px calc(var(--bottom-nav-h) + 20px); }
body.dev-mobile .fab-stack { bottom: calc(var(--bottom-nav-h) + 12px); right: 12px; }
body.dev-mobile .topbar .sub-title, body.dev-mobile .top-meta .clock-date { display: none; }

body.dev-tablet .g4 { grid-template-columns: repeat(2, 1fr); }
body.dev-tablet .app { grid-template-columns: 1fr; }
body.dev-tablet .sidebar { transform: translateX(-100%); position: fixed; width: 260px; height: 100%; }
body.dev-tablet .sidebar.open { transform: translateX(0); }
body.dev-tablet .menu-btn { display: grid; }

/* util */
.hidden { display: none !important; }
.center { display: grid; place-items: center; }
.gap-sm { gap: 6px; }
.gap-lg { gap: 20px; }

/* Respect reduced motion for screenshot tools */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ================================================================
   LOGIN PAGE + FORCE-CHANGE-PASSWORD OVERLAY
   Not present in the original design handoff (prototype assumed an
   already-authenticated session) — these classes were added by dev
   for the real login flow (src/routes/pages.tsx, public/static/js/
   bootstrap.js#showForceChangePasswordModal) but never got matching
   CSS, so both rendered unstyled/broken. Built here reusing existing
   design tokens (.card, --bg-*, --teal*, --r-lg, --shadow-lg) so it
   stays visually consistent with the rest of the app.
   ================================================================ */
.login-page {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background:
    radial-gradient(circle at 20% 15%, var(--backdrop-a), transparent 45%),
    radial-gradient(circle at 85% 80%, var(--backdrop-b), transparent 45%),
    var(--bg-0);
  overflow-y: auto;
}
.login-card {
  width: 100%; max-width: 420px;
  padding: 32px 30px 26px;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand .brand-logo { width: 44px; height: 44px; }
.login-brand .brand-name { font-size: 15px; }
.login-title { font-size: 22px; font-weight: 700; color: var(--ink-heading); margin: 4px 0 2px; letter-spacing: -.005em; }
.login-sub { margin-bottom: 22px; }
.login-form { display: flex; flex-direction: column; }
.login-label { display: block; margin: 14px 0 6px; color: var(--ink-2); }
.login-form input {
  width: 100%;
  background: var(--bg-4);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  color: var(--ink);
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--font);
}
.login-form input:focus { outline: none; border-color: var(--teal-glow); box-shadow: 0 0 0 3px rgba(52,211,153,.18); }
/* Password show/hide toggle (public/static/js/password-toggle.js).
   .login-password-wrap replaces the bare <input> as the direct child of
   .login-form so the existing `.login-form input` rules above still apply
   unchanged; the toggle button is absolutely positioned inside it. */
.login-password-wrap { position: relative; }
.login-password-wrap input { padding-right: 40px; }
.login-pw-toggle {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: var(--r-sm);
  color: var(--ink-3); cursor: pointer; padding: 0;
}
.login-pw-toggle:hover { color: var(--ink-2); background: var(--bg-3); }
.login-pw-toggle:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(52,211,153,.18); color: var(--teal-glow); }
.login-error { margin-top: 14px; }
.login-submit { width: 100%; margin-top: 22px; }
.login-foot { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); line-height: 1.6; }
/* Force-change-password modal (bootstrap.js#showForceChangePasswordModal)
   reuses .login-page as its full-screen scrim; it sets z-index:9999 inline
   (higher than the base z-index:50 here) so it sits above the app shell. */
