/* PickSight Edge Console - design system */
:root {
  --bg: #f3f5f9; --surface: #ffffff; --surface-2: #f8fafc; --text: #0f172a; --text-2: #334155; --muted: #64748b;
  --border: #e2e8f0; --border-strong: #cbd5e1;
  --nav: #0b1426; --nav-2: #111c33; --nav-text: #a9b6cc; --nav-text-strong: #f1f5f9; --nav-accent: #3b82f6;
  --primary: #2563eb; --primary-strong: #1d4ed8; --primary-soft: #eff6ff;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2;
  --info: #0369a1; --info-soft: #e0f2fe; --idle: #475569; --idle-soft: #f1f5f9;
  --c1: #2563eb; --c2: #16a34a; --c3: #f59e0b; --c4: #7c3aed; --c5: #dc2626; --c6: #0891b2;
  --radius: 12px; --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 6px 16px -8px rgba(15, 23, 42, .12);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a101c; --surface: #111a2b; --surface-2: #0e1625; --text: #e5eaf3; --text-2: #c3cddd; --muted: #8b98ad;
    --border: #1f2a3d; --border-strong: #2c3a52; --nav: #070c16; --nav-2: #0d1526;
    --primary: #3b82f6; --primary-strong: #60a5fa; --primary-soft: rgba(59, 130, 246, .14);
    --ok: #4ade80; --ok-soft: rgba(74, 222, 128, .13); --warn: #fbbf24; --warn-soft: rgba(251, 191, 36, .14);
    --bad: #f87171; --bad-soft: rgba(248, 113, 113, .14); --info: #38bdf8; --info-soft: rgba(56, 189, 248, .14);
    --idle: #94a3b8; --idle-soft: rgba(148, 163, 184, .12);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; font-size: 13px; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 13px; font-weight: 650; margin: 0 0 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 8px; }
a { color: var(--primary); text-decoration: none; } a:hover { text-decoration: underline; }
code, pre { font-family: var(--mono); font-size: 12px; }
pre { background: var(--surface-2); border: 1px solid var(--border); padding: 12px; border-radius: var(--radius-sm); overflow: auto; max-height: 440px; margin: 0; }

/* ---------- controls */
button { font: inherit; font-weight: 550; padding: 7px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); cursor: pointer; transition: background .15s, border-color .15s, box-shadow .15s; }
button:hover { border-color: var(--primary); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); background: transparent; }
button.danger:hover { background: var(--bad-soft); }
button.link { border: none; background: none; color: var(--nav-text); padding: 0; font-weight: 500; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); width: 100%; }
textarea { font-family: var(--mono); font-size: 12px; }
label { display: block; margin: 10px 0; font-size: 13px; font-weight: 550; color: var(--text-2); }

/* ---------- tables */
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { position: sticky; top: 0; background: var(--surface); font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; z-index: 1; }
tbody tr:last-child td, table tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--primary-soft); }
.table-wrap { max-height: 520px; overflow: auto; margin: 0 -4px; padding: 0 4px; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 20% -10%, color-mix(in srgb, var(--primary) 22%, transparent), transparent), var(--bg); }
.login-card { width: 380px; padding: 32px; }
.login-card .logo { margin-bottom: 18px; }
.login-card h1 { font-size: 24px; margin-bottom: 4px; }

/* ---------- shell */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.nav { background: linear-gradient(180deg, var(--nav) 0%, var(--nav-2) 100%); color: var(--nav-text); display: flex; flex-direction: column;
  padding: 18px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.logo .mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3b82f6, #06b6d4); color: #fff; box-shadow: 0 6px 16px -6px rgba(59, 130, 246, .7); }
.logo .name { font-weight: 700; font-size: 17px; color: var(--nav-text-strong); letter-spacing: -.01em; }
.logo .sub { font-size: 11px; color: var(--nav-text); letter-spacing: .08em; text-transform: uppercase; }
.nav-group { margin-top: 14px; }
.nav-group .label { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: #64748b; padding: 0 10px 6px; font-weight: 650; }
.nav nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--nav-text);
  text-decoration: none; cursor: pointer; font-weight: 500; position: relative; }
.nav nav a svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.nav nav a:hover { background: rgba(255, 255, 255, .05); color: var(--nav-text-strong); text-decoration: none; }
.nav nav a.active { background: rgba(59, 130, 246, .16); color: #fff; }
.nav nav a.active::before { content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--nav-accent); }
.nav-foot { margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid rgba(255, 255, 255, .07); font-size: 12px; display: grid; gap: 6px; }
.nav-foot .who { color: var(--nav-text-strong); font-weight: 600; }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 12px 28px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar .crumb { font-weight: 600; color: var(--text-2); }
.topbar .space { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: 12px; font-weight: 550; color: var(--text-2); white-space: nowrap; }
main { padding: 22px 28px 40px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; max-width: 760px; }

/* ---------- cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.card.error-card { border-color: color-mix(in srgb, var(--bad) 45%, transparent); background: var(--bad-soft); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.span-2 { grid-column: span 2; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.space { flex: 1; }
.section-gap { margin-top: 16px; }

/* ---------- KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { position: relative; overflow: hidden; padding: 14px 16px 14px 18px; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--tone, var(--border-strong)); }
.kpi .l { color: var(--muted); font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .07em; }
.kpi .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; line-height: 1.15; }
.kpi .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tone-ok { --tone: var(--ok); } .tone-warn { --tone: var(--warn); } .tone-bad { --tone: var(--bad); }
.tone-info { --tone: var(--info); } .tone-primary { --tone: var(--primary); } .tone-idle { --tone: var(--border-strong); }

/* ---------- status */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--idle); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-soft); } .badge.warn { color: var(--warn); background: var(--warn-soft); }
.badge.bad { color: var(--bad); background: var(--bad-soft); } .badge.idle { color: var(--idle); background: var(--idle-soft); }
.badge.info { color: var(--info); background: var(--info-soft); }

/* ---------- selector hero */
.hero { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 16px; margin-bottom: 16px; }
.selector-card { display: flex; flex-direction: column; gap: 14px; }
.selector-top { display: flex; align-items: center; gap: 16px; }
.selector-id { width: 76px; height: 76px; border-radius: 20px; display: grid; place-items: center; color: #fff; font-size: 30px; font-weight: 750;
  background: var(--sel, var(--primary)); box-shadow: 0 10px 24px -10px var(--sel, var(--primary)); flex: none; }
.selector-id.none { background: var(--idle-soft); color: var(--muted); box-shadow: none; font-size: 22px; }
.selector-meta .title { font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.selector-meta .big { font-size: 20px; font-weight: 700; margin: 2px 0 6px; }
.meter { height: 8px; border-radius: 999px; background: var(--idle-soft); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), #06b6d4); transition: width .4s; }
.track-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.track-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 8px; background: var(--surface-2);
  border: 1px solid var(--border); font-size: 12.5px; font-weight: 550; }
.track-chip b { color: var(--text); } .track-chip .k { color: var(--muted); }
.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 16px; font-size: 13px; }
.facts .k { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; }
.facts .v { font-weight: 600; }
.analytics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.metric { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.metric .l { font-size: 11px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; display: flex; align-items: center; gap: 6px; }
.metric .v { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.metric .s { font-size: 11.5px; color: var(--muted); }
.metric.accent { background: linear-gradient(135deg, var(--primary-soft), transparent); border-color: color-mix(in srgb, var(--primary) 30%, var(--border)); }

/* ---------- cameras */
.live-main { display: grid; grid-template-columns: minmax(340px, 5fr) 7fr; gap: 16px; align-items: start; }
.live-main .floor { position: sticky; top: 72px; }
.cam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; align-content: start; }
.cam { padding: 0; overflow: hidden; }
.cam .cam-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.cam .cam-head strong { font-size: 14px; }
.cam canvas, .cam img.feed { width: 100%; aspect-ratio: 16/10; object-fit: contain; background: #05080f; display: block; }
.cam .cam-foot { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px; font-size: 12px; color: var(--muted); }
.cam .cam-foot .sel { color: var(--text); font-weight: 650; }
.floor canvas { width: 100%; height: 520px; background: var(--surface-2); border-radius: 10px; display: block; border: 1px solid var(--border); }
.feed-list { max-height: 440px; overflow: auto; font-size: 13px; display: grid; gap: 2px; }
.feed-item { display: grid; grid-template-columns: 74px 1fr; gap: 8px; padding: 7px 8px; border-radius: 8px; }
.feed-item:hover { background: var(--surface-2); }
.feed-item .t { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.feed-item.anomaly { background: var(--bad-soft); } .feed-item.pick { background: var(--ok-soft); }

/* ---------- forms */
.tabs { display: flex; gap: 2px; flex-wrap: wrap; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); padding: 8px 12px; }
.tabs button.active { border-bottom-color: var(--primary); color: var(--primary); }
.form-section { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin: 10px 0; background: var(--surface-2); }
.form-section > .title { font-weight: 650; margin-bottom: 6px; text-transform: capitalize; }
.field { display: grid; grid-template-columns: minmax(170px, 270px) 1fr; gap: 12px; align-items: center; padding: 5px 0; }
.field > label { margin: 0; text-transform: capitalize; }
.field .help { grid-column: 2; color: var(--muted); font-size: 12px; margin-top: -4px; }
.field input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); }
.array-item { border-left: 3px solid var(--primary); padding-left: 12px; margin: 10px 0; }

/* ---------- charts, media, misc */
.chart svg { width: 100%; height: 190px; display: block; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
video.clip { width: 100%; max-height: 380px; background: #000; border-radius: 10px; }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; background: var(--info-soft); color: var(--text-2); margin-bottom: 16px; font-size: 13px; }
.notice b { color: var(--info); }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 10px; max-width: 440px; z-index: 50; box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); color: #fff; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

@media (max-width: 1100px) { .hero, .live-main { grid-template-columns: 1fr; } .live-main .floor { position: static; } .span-2 { grid-column: auto; } }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; } .nav { position: static; height: auto; }
  .field { grid-template-columns: 1fr; } .field .help { grid-column: 1; } main, .topbar { padding-left: 16px; padding-right: 16px; }
  .g2 { grid-template-columns: 1fr; }
}
