/* ==========================================================================
   Smart Warehouse Command Center — design tokens & components
   Works on its own; Tailwind utilities (tailwind.css / CDN) are additive.
   ========================================================================== */
:root {
  --bg: #060b16;
  --bg-2: #0a1222;
  --panel: #0f1828;
  --panel-2: #131f33;
  --panel-3: #1a2840;
  --glass: rgba(17, 27, 45, 0.72);
  --border: rgba(148, 163, 184, 0.13);
  --border-strong: rgba(148, 163, 184, 0.26);
  --text: #e6edf7;
  --text-2: #b8c4d6;
  --muted: #7d8ca3;
  --cyan: #22d3ee;
  --blue: #3b82f6;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --violet: #a78bfa;
  --sky: #38bdf8;
  --glow-cyan: 0 0 0 1px rgba(34, 211, 238, .25), 0 0 24px -6px rgba(34, 211, 238, .45);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "IBM Plex Sans Thai", "Kanit", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sidebar-w: 248px;
  --topbar-h: 60px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(59, 130, 246, .08), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(34, 211, 238, .06), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
/* element rules use `body` prefix so Tailwind preflight (loaded later in CDN mode) cannot override them */
body a { color: var(--cyan); text-decoration: none; }
button { font-family: inherit; }
body :is(h1, h2, h3, h4) { margin: 0; font-weight: 600; letter-spacing: .1px; }
body :is(h1) { font-size: 22px; } body :is(h2) { font-size: 18px; } body :is(h3) { font-size: 14px; }
body ol { list-style: decimal; } body ul.bullets { list-style: disc; padding-left: 18px; }
body pre { white-space: pre-wrap; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.hidden { display: none !important; }
.glass { background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--border); }
:is([data-lucide], svg.lucide) { width: 18px; height: 18px; stroke-width: 1.8; flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ---------- shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; position: sticky; top: 0; height: 100vh;
  background: linear-gradient(180deg, #0b1323, #08101d); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 40;
}
.sidebar-brand { display: flex; gap: 10px; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); height: var(--topbar-h); }
.brand-mark { color: var(--cyan); display: grid; place-items: center; filter: drop-shadow(0 0 8px rgba(34, 211, 238, .35)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 14px; }
.brand-text span { font-size: 11px; color: var(--muted); letter-spacing: 1.2px; text-transform: uppercase; }
.nav { padding: 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; color: var(--text-2);
  font-size: 13.5px; position: relative; transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(148, 163, 184, .07); color: var(--text); }
.nav-item.active { background: linear-gradient(90deg, rgba(34, 211, 238, .14), rgba(34, 211, 238, .03)); color: #fff; }
.nav-item.active::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--cyan); box-shadow: 0 0 10px var(--cyan); }
.nav-item.active :is([data-lucide], svg.lucide) { color: var(--cyan); }
.nav-num { font-family: var(--mono); font-size: 10px; color: var(--muted); width: 14px; text-align: right; }
.sidebar-foot { padding: 12px 18px; border-top: 1px solid var(--border); color: var(--muted); font-size: 11px; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 14px; padding: 0 20px; position: sticky; top: 0; z-index: 30;
  background: rgba(8, 14, 26, .82); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
}
.topbar-wh { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.wh-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wh-code { font-size: 11px; color: var(--muted); }
.topbar-spacer { flex: 1; }
.topbar-stat { display: flex; align-items: center; gap: 6px; color: var(--text-2); padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); }
.alert-pill.has-critical { border-color: rgba(239, 68, 68, .5); color: #fecaca; background: rgba(239, 68, 68, .12); animation: pulse-red 1.6s infinite; }
.alert-pill.has-open { border-color: rgba(245, 158, 11, .45); color: #fde68a; }
@keyframes pulse-red { 0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .0); } 50% { box-shadow: 0 0 0 4px rgba(239, 68, 68, .18); } }
.topbar-clock { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.topbar-clock #hdrClock { font-size: 15px; color: #fff; }
.clock-date { font-size: 11px; color: var(--muted); }
.demo-badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; letter-spacing: .3px;
  color: #fde68a; background: rgba(245, 158, 11, .1); border: 1px dashed rgba(245, 158, 11, .5); padding: 4px 10px; border-radius: 999px;
}
.demo-badge :is([data-lucide], svg.lucide) { width: 14px; height: 14px; }
.conn { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-2); }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.conn[data-state="live"] .conn-dot { background: var(--green); box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); animation: blink 2s infinite; }
.conn[data-state="degraded"] .conn-dot { background: var(--amber); }
.conn[data-state="lost"] .conn-dot { background: var(--red); box-shadow: 0 0 0 3px rgba(239, 68, 68, .25); }
.conn[data-state="lost"] { color: #fecaca; }
@keyframes blink { 50% { opacity: .55; } }
.conn-banner {
  display: flex; gap: 10px; align-items: center; padding: 9px 20px; background: rgba(239, 68, 68, .14);
  border-bottom: 1px solid rgba(239, 68, 68, .35); color: #fecaca; font-size: 13px;
}
.user-menu { position: relative; }
.user-menu summary { list-style: none; display: flex; gap: 8px; align-items: center; cursor: pointer; }
.user-menu summary::-webkit-details-marker { display: none; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, #1d4ed8, #0891b2); font-weight: 600; }
.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-meta small { color: var(--muted); font-size: 11px; }
.user-pop { position: absolute; right: 0; top: 44px; min-width: 210px; padding: 12px; border-radius: 10px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.icon-btn { background: transparent; border: 1px solid var(--border); color: var(--text-2); border-radius: 8px; height: 34px; min-width: 34px; display: inline-grid; place-items: center; cursor: pointer; }
.icon-btn:hover { color: #fff; border-color: var(--border-strong); }
.icon-btn[aria-pressed="true"] { color: var(--cyan); border-color: rgba(34, 211, 238, .45); }
.md-hide { display: none; }

.view { padding: 20px; flex: 1; min-width: 0; outline: none; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--muted); font-size: 13px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.data-stamp { font-size: 11.5px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.data-stamp .mono { color: var(--text-2); }

/* ---------- cards ---------- */
.card { background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid var(--border); border-radius: var(--radius); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.card-h h3 { font-size: 14px; }
.card-h .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.card-b { padding: 14px 16px; }
.card-b.flush { padding: 0; }
.grid { display: grid; gap: 14px; }
.kpi-grid { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi {
  position: relative; padding: 14px 14px 12px; border-radius: var(--radius); cursor: pointer; overflow: hidden;
  background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid var(--border); transition: border-color .15s, transform .15s;
  text-align: left; color: inherit; font: inherit;
}
.kpi:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.kpi::after { content: ""; position: absolute; inset: auto 0 0 0; height: 2px; background: var(--accent, var(--cyan)); opacity: .8; }
.kpi .k-label { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.kpi .k-label :is([data-lucide], svg.lucide) { width: 15px; height: 15px; color: var(--accent, var(--cyan)); }
.kpi .k-value { font-family: var(--mono); font-size: 30px; font-weight: 600; margin-top: 4px; line-height: 1.1; }
.kpi .k-foot { font-size: 11px; color: var(--muted); margin-top: 2px; }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 14px; }
.chart-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.chart-box { position: relative; height: 220px; }
.chart-note { font-size: 11px; color: var(--muted); padding: 0 16px 12px; }

/* ---------- status ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; letter-spacing: .2px; border: 1px solid transparent; white-space: nowrap; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-MOVING, .st-RUNNING { color: #4ade80; background: rgba(34, 197, 94, .12); border-color: rgba(34, 197, 94, .3); }
.st-ONLINE { color: #86efac; background: rgba(34, 197, 94, .08); border-color: rgba(34, 197, 94, .2); }
.st-IDLE { color: #cbd5e1; background: rgba(148, 163, 184, .1); border-color: rgba(148, 163, 184, .25); }
.st-CHARGING { color: #7dd3fc; background: rgba(56, 189, 248, .12); border-color: rgba(56, 189, 248, .3); }
.st-PAUSED { color: #fde68a; background: rgba(250, 204, 21, .1); border-color: rgba(250, 204, 21, .3); }
.st-BLOCKED { color: #fbbf24; background: rgba(245, 158, 11, .14); border-color: rgba(245, 158, 11, .35); }
.st-ERROR, .st-EMERGENCY_STOP { color: #fca5a5; background: rgba(239, 68, 68, .14); border-color: rgba(239, 68, 68, .4); }
.st-OFFLINE, .st-STALE { color: #94a3b8; background: rgba(71, 85, 105, .25); border-color: rgba(100, 116, 139, .35); }
.st-CREATED, .st-QUEUED { color: #c4b5fd; background: rgba(167, 139, 250, .1); border-color: rgba(167, 139, 250, .3); }
.st-ASSIGNED { color: #67e8f9; background: rgba(34, 211, 238, .1); border-color: rgba(34, 211, 238, .3); }
.st-COMPLETED { color: #86efac; background: rgba(34, 197, 94, .08); border-color: rgba(34, 197, 94, .25); }
.st-FAILED { color: #fca5a5; background: rgba(239, 68, 68, .1); border-color: rgba(239, 68, 68, .3); }
.st-CANCELLED { color: #94a3b8; background: rgba(100, 116, 139, .15); border-color: rgba(100, 116, 139, .3); }
.sev-CRITICAL { color: #fca5a5; background: rgba(239, 68, 68, .16); border-color: rgba(239, 68, 68, .45); }
.sev-WARNING { color: #fcd34d; background: rgba(245, 158, 11, .14); border-color: rgba(245, 158, 11, .4); }
.sev-INFO { color: #93c5fd; background: rgba(59, 130, 246, .12); border-color: rgba(59, 130, 246, .35); }
.al-OPEN { color: #fecaca; } .al-ACKNOWLEDGED { color: #fde68a; } .al-RESOLVED { color: #94a3b8; }

.battery { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 12px; }
.battery .bar { width: 34px; height: 12px; border: 1.5px solid currentColor; border-radius: 3px; padding: 1px; position: relative; opacity: .9; }
.battery .bar::after { content: ""; position: absolute; right: -4px; top: 3px; width: 2px; height: 5px; background: currentColor; border-radius: 1px; }
.battery .fill { height: 100%; border-radius: 1px; background: currentColor; }
.battery.ok { color: #4ade80; } .battery.mid { color: #fbbf24; } .battery.low { color: #f87171; }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border-strong); background: var(--panel-3); color: var(--text); cursor: pointer; font-size: 13px; font-weight: 500; line-height: 1.2; transition: background .15s, border-color .15s; }
.btn:hover { border-color: rgba(148, 163, 184, .45); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(180deg, #0891b2, #0e7490); border-color: rgba(34, 211, 238, .55); color: #fff; box-shadow: var(--glow-cyan); }
.btn-primary:hover { background: linear-gradient(180deg, #06b6d4, #0891b2); }
.btn-danger { background: rgba(239, 68, 68, .15); border-color: rgba(239, 68, 68, .5); color: #fecaca; }
.btn-warn { background: rgba(245, 158, 11, .12); border-color: rgba(245, 158, 11, .45); color: #fde68a; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn-block { width: 100%; }
.btn :is([data-lucide], svg.lucide) { width: 16px; height: 16px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: var(--panel); }
.seg button { background: transparent; border: 0; color: var(--text-2); padding: 6px 11px; font-size: 12px; cursor: pointer; border-right: 1px solid var(--border); display: inline-flex; gap: 6px; align-items: center; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: rgba(34, 211, 238, .14); color: #fff; }
.seg button :is([data-lucide], svg.lucide) { width: 15px; height: 15px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; font-size: 12.5px; color: var(--text-2); }
.input, .field input, .field select, .field textarea, select.input {
  background: #0a1322; border: 1px solid var(--border-strong); color: var(--text); border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 13.5px; width: 100%;
}
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--cyan); outline: none; box-shadow: 0 0 0 3px rgba(34, 211, 238, .15); }
.field .err { color: #fca5a5; font-size: 12px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .input { width: auto; min-width: 160px; padding: 7px 10px; font-size: 13px; }
.check { display: inline-flex; gap: 7px; align-items: center; cursor: pointer; font-size: 12.5px; color: var(--text-2); user-select: none; }
.check input { accent-color: var(--cyan); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: rgba(10, 18, 34, .55); position: sticky; top: 0; }
.tbl th.sortable { cursor: pointer; }
.tbl th.sortable:hover { color: var(--text); }
.tbl td { padding: 9px 12px; border-bottom: 1px solid rgba(148, 163, 184, .07); vertical-align: middle; }
.tbl tbody tr { cursor: pointer; transition: background .1s; }
.tbl tbody tr:hover { background: rgba(34, 211, 238, .045); }
.tbl tbody tr.sel { background: rgba(34, 211, 238, .08); }
.tbl .num { text-align: right; font-family: var(--mono); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 12px; font-size: 12px; color: var(--muted); }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 16px; border-bottom: 1px solid rgba(148, 163, 184, .07); cursor: pointer; }
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: rgba(148, 163, 184, .05); }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .li-sub { font-size: 12px; color: var(--muted); }
.list-item .li-right { text-align: right; font-size: 11.5px; color: var(--muted); white-space: nowrap; }

/* ---------- states ---------- */
.state-box { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 40px 20px; color: var(--muted); text-align: center; min-height: 160px; }
.state-box :is([data-lucide], svg.lucide) { width: 34px; height: 34px; opacity: .7; }
.state-box.error { color: #fca5a5; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid rgba(34, 211, 238, .18); border-top-color: var(--cyan); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, rgba(148, 163, 184, .06), rgba(148, 163, 184, .14), rgba(148, 163, 184, .06)); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 6px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- map / viewport ---------- */
.viewport-wrap { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: #050a14; }
.viewport-wrap canvas { display: block; width: 100%; height: 100%; }
.viewport-wrap.map-lg { height: calc(100vh - var(--topbar-h) - 120px); min-height: 460px; }
.viewport-wrap.map-sm { height: 340px; }
.viewport-wrap:fullscreen { border-radius: 0; height: 100vh !important; }
.vp-overlay { position: absolute; z-index: 5; display: flex; gap: 8px; flex-wrap: wrap; }
.vp-tl { top: 12px; left: 12px; }
.vp-tr { top: 12px; right: 12px; justify-content: flex-end; }
.vp-bl { bottom: 12px; left: 12px; }
.vp-br { bottom: 12px; right: 12px; }
.vp-panel { background: rgba(8, 14, 26, .82); backdrop-filter: blur(10px); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 12px; }
.vp-panel h4 { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; }
.legend span { display: inline-flex; gap: 5px; align-items: center; color: var(--text-2); font-size: 11.5px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.tooltip { position: absolute; pointer-events: none; z-index: 20; background: rgba(6, 11, 22, .94); border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; font-size: 12px; min-width: 140px; transform: translate(12px, 12px); box-shadow: 0 8px 24px rgba(0, 0, 0, .4); }
.tooltip b { color: #fff; }
.label3d { font-family: var(--mono); font-size: 11px; font-weight: 600; color: #fff; background: rgba(6, 11, 22, .78); border: 1px solid rgba(34, 211, 238, .4); padding: 1px 6px; border-radius: 5px; white-space: nowrap; pointer-events: none; transform: translateY(-14px); }
.label3d.err { border-color: rgba(239, 68, 68, .7); color: #fecaca; }
.label3d.warn { border-color: rgba(245, 158, 11, .7); color: #fde68a; }
.label3d.stale { opacity: .55; border-style: dashed; }
.label3d.zone { font-family: var(--font); font-weight: 500; font-size: 11px; border-color: rgba(148, 163, 184, .35); color: #cbd5e1; }
.twin-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; }
.side-panel { display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - var(--topbar-h) - 120px); overflow-y: auto; }
.tour-steps { display: flex; flex-direction: column; gap: 4px; }
.tour-steps button { text-align: left; background: transparent; border: 1px solid transparent; color: var(--text-2); padding: 7px 9px; border-radius: 8px; cursor: pointer; display: flex; gap: 8px; align-items: center; font-size: 12.5px; }
.tour-steps button:hover { background: rgba(148, 163, 184, .06); }
.tour-steps button.on { border-color: rgba(34, 211, 238, .4); background: rgba(34, 211, 238, .08); color: #fff; }
.tour-steps .n { font-family: var(--mono); font-size: 11px; color: var(--cyan); width: 18px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-family: var(--mono); }
.walk-hint { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 6; }
.crosshair { position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; pointer-events: none; z-index: 6; }
.crosshair::before, .crosshair::after { content: ""; position: absolute; background: rgba(255, 255, 255, .7); }
.crosshair::before { left: 6px; top: 0; width: 2px; height: 14px; }
.crosshair::after { top: 6px; left: 0; height: 2px; width: 14px; }

/* ---------- drawer / modal / toast ---------- */
.drawer-backdrop, .modal-backdrop { position: fixed; inset: 0; background: rgba(2, 6, 14, .55); z-index: 80; animation: fade .15s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); z-index: 81; background: linear-gradient(180deg, #0f1a2d, #0a1322); border-left: 1px solid var(--border-strong); display: flex; flex-direction: column; animation: slide .2s ease-out; box-shadow: -20px 0 50px rgba(0, 0, 0, .45); }
.drawer-h { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: flex-start; }
.drawer-h h2 { font-size: 18px; }
.drawer-b { padding: 16px 18px; overflow-y: auto; flex: 1; }
.drawer-f { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: -4px -18px 14px; padding: 0 12px; }
.tabs button { background: none; border: 0; color: var(--muted); padding: 9px 12px; cursor: pointer; border-bottom: 2px solid transparent; font-size: 13px; }
.tabs button.on { color: #fff; border-bottom-color: var(--cyan); }
.modal { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px); overflow-y: auto; z-index: 81; border-radius: 14px; background: #0f1a2d; border: 1px solid var(--border-strong); box-shadow: 0 30px 80px rgba(0, 0, 0, .55); animation: fade .15s; }
.modal-h { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-h h3 { font-size: 16px; }
.modal-b { padding: 16px 18px; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.toast-root { position: fixed; right: 16px; bottom: 16px; z-index: 90; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 10px; background: #111c30; border: 1px solid var(--border-strong); box-shadow: 0 10px 30px rgba(0, 0, 0, .45); font-size: 13px; display: flex; gap: 10px; align-items: flex-start; animation: slide .2s; }
.toast.ok { border-color: rgba(34, 197, 94, .5); }
.toast.err { border-color: rgba(239, 68, 68, .55); }
.toast.warn { border-color: rgba(245, 158, 11, .55); }
.notice { padding: 10px 12px; border-radius: 9px; font-size: 12.5px; display: flex; gap: 9px; align-items: flex-start; border: 1px solid; }
.notice.info { background: rgba(59, 130, 246, .08); border-color: rgba(59, 130, 246, .3); color: #bfdbfe; }
.notice.warn { background: rgba(245, 158, 11, .08); border-color: rgba(245, 158, 11, .35); color: #fde68a; }
.notice.danger { background: rgba(239, 68, 68, .08); border-color: rgba(239, 68, 68, .35); color: #fecaca; }
.notice :is([data-lucide], svg.lucide) { width: 16px; height: 16px; margin-top: 1px; }
.timeline-canvas { width: 100%; display: block; }
.mini-stat { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 10px; background: rgba(10, 19, 34, .7); border: 1px solid var(--border); }
.mini-stat .v { font-family: var(--mono); font-size: 18px; font-weight: 600; }
.mini-stat .l { font-size: 11.5px; color: var(--muted); }
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.event-log { display: flex; flex-direction: column; gap: 0; border-left: 2px solid var(--border); margin-left: 6px; }
.event-log .ev { position: relative; padding: 4px 0 10px 14px; font-size: 12.5px; }
.event-log .ev::before { content: ""; position: absolute; left: -6px; top: 9px; width: 10px; height: 10px; border-radius: 50%; background: var(--panel-3); border: 2px solid var(--cyan); }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-wrap { width: 100%; max-width: 400px; }
.login-card { border-radius: 16px; padding: 28px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.login-brand h1 { font-size: 20px; }
.login-brand p { margin: 0; color: var(--muted); font-size: 12.5px; letter-spacing: .5px; }
.login-error { background: rgba(239, 68, 68, .12); border: 1px solid rgba(239, 68, 68, .45); color: #fecaca; padding: 9px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.login-foot { color: var(--muted); font-size: 11.5px; text-align: center; margin: 16px 0 0; }

/* ---------- responsive ---------- */
@media (min-width: 1920px) {
  body { font-size: 15px; }
  .kpi .k-value { font-size: 36px; }
  .chart-box { height: 260px; }
  .viewport-wrap.map-sm { height: 420px; }
}
@media (max-width: 1500px) {
  .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 1200px) {
  .dash-grid, .twin-layout { grid-template-columns: minmax(0, 1fr); }
  .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side-panel { max-height: none; }
  .user-meta { display: none; }
}
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 20px 0 50px rgba(0, 0, 0, .5); }
  .sidebar.open { transform: none; }
  .md-hide { display: inline-grid; }
  .topbar { gap: 8px; padding: 0 12px; }
  .topbar-clock .clock-date, .conn-text, .wh-code { display: none; }
  .demo-badge { font-size: 0; padding: 5px; }
  .demo-badge :is([data-lucide], svg.lucide) { width: 15px; height: 15px; }
  .view { padding: 14px; }
}
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-grid { grid-template-columns: minmax(0, 1fr); }
  .topbar-stat:first-of-type { display: none; }
  .kpi .k-value { font-size: 24px; }
  .viewport-wrap.map-lg { height: 62vh; min-height: 360px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- layout safety (found by browser tests) ---------- */
[hidden] { display: none !important; }
.grid > *, .dash-grid > *, .twin-layout > *, .chart-grid > *, .kpi-grid > * { min-width: 0; }
.card-h { flex-wrap: wrap; row-gap: 6px; }
.card-h .right { flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 640px) {
  #miniLegend { display: none; }
  .page-head .actions { margin-left: 0; }
  .toolbar .input { min-width: 0; flex: 1 1 140px; }
}
