:root {
  --nav: #07182e;
  --nav-2: #10284a;
  --nav-text: #dbe7f5;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f5f7fa;
  --paper: #ffffff;
  --ink: #0f172a;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --ok: #157a4b;
  --warn: #9a6700;
  --bad: #b42318;
  font-family: "Segoe UI", Aptos, sans-serif;
  color: var(--ink);
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body, #app { margin: 0; min-height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.shell { display: grid; grid-template-columns: 244px minmax(0, 1fr); height: 100vh; overflow: hidden; }
.nav { background: var(--nav); color: var(--nav-text); display: flex; flex-direction: column; min-height: 0; height: 100%; padding: 10px 10px 8px; overflow: auto; }
.brand { padding: 4px 10px 10px; }
.brand img, .gate-brand img { display: block; width: 188px; max-width: 100%; height: auto; }
.brand-lockup { display: none; width: 180px; max-width: 100%; height: auto; margin: 0 auto 8px; }
.nav-scroll { overflow: auto; min-height: 0; }
.nav .group { color: #8ea0b8; font-size: 10px; letter-spacing: .12em; margin: 8px 10px 2px; }
.nav button.item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; background: transparent; color: var(--nav-text); border: 0; border-radius: 8px; padding: 4px 8px; margin: 0; font-size: 13px; }
.nav button.item.active, .nav button.item:hover { background: var(--nav-2); }
.nav button.item svg, .menu svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-foot { margin-top: auto; display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; padding-top: 10px; border-top: 1px solid #1d3358; font-size: 12px; }
.nav-foot b, .nav-foot span { display: block; }
.nav-foot span { color: #8ea0b8; }
.nav-foot .item { grid-column: 1 / -1; }

.workspace { min-width: 0; overflow: auto; background: var(--bg); }
.top { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 18px; background: var(--paper); border-bottom: 1px solid var(--line); }
.top time { margin-left: auto; color: var(--muted); font-size: 12px; }
.who b { display: block; font-size: 13px; }
.who span { color: var(--muted); font-size: 12px; }
.menu, .nav-mask { display: none; }
.page { padding: 14px 18px 28px; }
.page-head h1 { margin: 0 0 8px; font-size: 22px; font-weight: 650; letter-spacing: -.02em; }
.lead, .page-lead, .muted, .eyebrow { color: var(--muted); }
.lead, .page-lead { margin: 0 0 10px; font-size: 13px; }
.eyebrow { margin: 0; font-size: 12px; }

.metrics { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.metric, .panel, .kpi { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; }
.metric { padding: 8px 10px; }
.metric span, .kpi span { display: block; color: var(--muted); font-size: 12px; }
.metric b, .kpi b { display: block; margin-top: 2px; font-size: 20px; letter-spacing: -.03em; }
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.kpi { padding: 10px 12px; }

.toolbar, .actions, .panel-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar, .actions { margin-bottom: 10px; }
.panel { padding: 12px; }
.panel h2, .panel h3 { margin: 0 0 8px; font-size: 15px; }
.primary, .ghost { border-radius: 8px; padding: 8px 12px; min-height: 36px; }
.primary { background: var(--accent); color: #fff; border: 1px solid var(--accent); }
.primary:hover { background: var(--accent-2); }
.ghost, .link { background: #fff; border: 1px solid var(--line); }
.link { color: var(--accent-2); }
input, select, textarea { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 36px; }
textarea { min-height: 88px; width: 100%; }

.sheet { overflow: auto; }
.sheet table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sheet th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 8px; border-bottom: 1px solid var(--line); background: #f8fafc; position: sticky; top: 0; }
.sheet td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.sheet tbody tr:hover { background: #f8fafc; }
.sheet tr[data-org], .sheet tr[data-person], .sheet tr[data-vehicle], .sheet tr[data-visit], .sheet tr[data-entrance], .sheet tr[data-camera], .sheet tr[data-barrier], .sheet tr[data-node], .sheet tr[data-event] { cursor: pointer; }
.mob-list { display: none; }

.pill, .badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 650; background: #eef2f7; color: #334155; }
.pill.ok, .badge.Authorized, .badge.Inside, .badge.Online, .badge.Sent, .badge.SYNCED { background: #e8f6ee; color: var(--ok); }
.pill.bad, .badge.Denied, .badge.Offline, .badge.PermanentFailed, .badge.AuthError { background: #fdecec; color: var(--bad); }
.pill.wait, .badge.Pending, .badge.Unknown, .badge.Queued { background: #f8f1de; color: var(--warn); }
.pill.sim { background: #e8eefc; color: #1e3a8a; }

.command, .command-body, .split, .ops3, .board, .report-center, .ops { display: grid; gap: 12px; }
.command-body, .split, .board, .report-center { grid-template-columns: minmax(0, 1.6fr) minmax(260px, .8fr); }
.ops3 { grid-template-columns: minmax(240px, .9fr) minmax(0, 1.2fr) minmax(220px, .7fr); }
.stack, .rail { display: grid; gap: 12px; align-content: start; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chips.slim { margin: 0; }
.chips button, .stream { border: 1px solid var(--line); background: #fff; border-radius: 8px; }
.chips button { min-height: 32px; padding: 4px 10px; }
.chips button.on, .stream.on { background: #eff4ff; border-color: var(--accent); color: var(--accent-2); }
.stream { display: grid; grid-template-columns: 48px minmax(88px, auto) minmax(0, 1fr) auto; gap: 4px 8px; width: 100%; text-align: left; padding: 8px; margin-bottom: 6px; }
.stream small { grid-column: 1 / -1; color: var(--muted); }
.identity { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 10px; }
.identity h2 { margin: 0; font-size: 20px; display: none; }
.page-head:has(h1:empty) { display: none; }
.identity p { margin: 2px 0 0; color: var(--muted); }
.avatar, .avatar.sm { display: inline-grid; place-items: center; background: var(--accent); color: #fff; font-weight: 700; }
.avatar { width: 36px; height: 36px; border-radius: 8px; }
.avatar.sm { width: 28px; height: 28px; border-radius: 8px; font-size: 12px; }
.facts { display: grid; gap: 8px; margin: 0; }
.facts div, .rows > div, .activity, .quad div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 650; }
.quad, .rows { display: grid; }
.quad { grid-template-columns: 1fr 1fr; gap: 8px; }
.plate { margin: 4px 0; font-size: 28px; font-weight: 750; letter-spacing: .04em; }
.timeline { margin: 0; padding-left: 18px; }
.empty, .empty-title, .empty-state { color: var(--muted); }
.empty-state { padding: 28px 8px; }
.error { color: var(--bad); font-size: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 760px; }
.form-grid label, .editor label, .check, .m-form label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.check { grid-template-columns: 16px 1fr; align-items: center; }
.perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; margin-bottom: 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.settings { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 12px; align-items: start; }
.settings-nav { display: grid; gap: 4px; }
.settings-nav button { text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.settings-nav button.on { border-color: var(--accent); background: #eff4ff; }
.editor { border: 0; border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 24px)); }
.editor form, .editor-inline { display: grid; gap: 10px; padding: 16px; }
.editor-inline[hidden], form.drawer[hidden], #guest[hidden] { display: none !important; }
dialog.editor::backdrop { background: rgba(7, 24, 46, .45); }
pre { white-space: pre-wrap; font-size: 12px; }

.gate { min-height: 100vh; display: grid; grid-template-columns: 42% 1fr; background: #f7f9fc; }
.gate-brand { background: #081b3a; color: #fff; display: flex; flex-direction: column; justify-content: flex-end; padding: 56px; }
.gate-brand img { width: min(360px, 80%); }
.gate-card, .login-card { width: min(420px, calc(100% - 32px)); justify-self: center; align-self: center; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px; display: grid; gap: 12px; }
.gate-card h1, .login-card h1 { margin: 0; font-size: 24px; }
.gate-card p, .login-card p { margin: 0; color: var(--muted); }
.gate-card label, .login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.passline { display: flex; gap: 8px; }
.passline input { flex: 1; width: 100%; }
.login-shell { min-height: 100vh; display: grid; grid-template-columns: .9fr 1.1fr; }
.login-brand { background: #081b3a; color: #fff; display: flex; flex-direction: column; justify-content: center; padding: 48px; }
.login-brand strong { letter-spacing: .12em; font-size: 28px; }

.shell.mobile { display: block; height: auto; overflow: visible; background: var(--bg); padding-bottom: 72px; }
.shell.mobile .page { padding: 16px 16px 24px; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--nav); }
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; background: transparent; color: #c5d4e8; border: 0; min-height: 56px; font-size: 11px; }
.tabbar button.active { color: #fff; }
.tabbar svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.7; }
.m-head h2 { margin: 0; font-size: 22px; }
.m-card, .m-move { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 10px 0; }
.m-stats, .m-row { display: flex; justify-content: space-between; gap: 8px; }
.m-stats span, .m-card h3 { color: var(--muted); font-size: 12px; }
.m-form { display: grid; gap: 10px; }
.cta { width: 100%; }

@media (max-width: 1200px) {
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .command-body, .split, .ops3, .board, .report-center { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell:not(.mobile) { grid-template-columns: 1fr; height: auto; overflow: visible; }
  .nav { position: fixed; inset: 0 auto 0 0; width: min(280px, 88vw); z-index: 20; transform: translateX(-105%); transition: transform .18s ease; }
  .shell.nav-open .nav { transform: none; }
  .nav-mask { display: block; position: fixed; inset: 0; border: 0; background: rgba(7, 24, 46, .45); z-index: 19; opacity: 0; pointer-events: none; }
  .shell.nav-open .nav-mask { opacity: 1; pointer-events: auto; }
  .menu { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
  .brand span, .nav button.item, .nav .group, .nav-foot div, .nav-foot .item { position: static; width: auto; height: auto; overflow: visible; clip: auto; color: inherit; }
  .nav button.item { color: var(--nav-text); width: 100%; }
  .nav-foot { grid-template-columns: 28px 1fr auto; justify-items: stretch; }
  .metrics, .kpis, .form-grid, .perm-grid, .settings { grid-template-columns: 1fr; }
  .settings-nav { grid-auto-flow: column; overflow: auto; }
  .sheet table { display: none; }
  .mob-list { display: grid; gap: 8px; }
  .mob-row { display: grid; gap: 4px; width: 100%; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-height: 64px; }
  .mob-row small { color: var(--muted); font-size: 12px; display: grid; }
  .top time { display: none; }
  .page, .top { padding-left: 12px; padding-right: 12px; }
  .identity { align-items: flex-start; flex-direction: column; }
  .ops3, .stream { grid-template-columns: 1fr; }
}
@media (max-width: 430px) {
  .gate, .login-shell { grid-template-columns: 1fr; background: #081b3a; }
  .gate-brand, .login-brand { display: none; }
  .brand-lockup { display: block; }
  .gate-card, .login-card { margin: 18vh auto 24px; }
}
