/* web/css/app.css */
:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #1b2430;
  --muted: #667085;
  --line: #d9dee5;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --ok: #1a7f37;
  --ok-bg: #dcf5e3;
  --warn: #9a6700;
  --warn-bg: #fff3c4;
  --bad: #c62828;
  --bad-bg: #fde0de;
  --info-bg: #dbe9ff;
  --grey-bg: #e7eaee;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --panel: #182029;
    --text: #e6eaf0;
    --muted: #94a0b0;
    --line: #2c3743;
    --accent: #4c94ff;
    --accent-text: #0b1220;
    --ok: #57d07a;
    --ok-bg: #153a22;
    --warn: #f0c14b;
    --warn-bg: #40330c;
    --bad: #ff7b72;
    --bad-bg: #4a1b19;
    --info-bg: #17305c;
    --grey-bg: #27313c;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.08rem; margin: 0 0 0.6rem; }
h3 { font-size: 0.98rem; margin: 0.8rem 0 0.4rem; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: 0.85rem; }
.mono { font-family: var(--mono); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 0.5rem 1rem; position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; color: var(--text); text-decoration: none; }
.nav { display: flex; gap: 0.15rem; flex: 1; flex-wrap: wrap; }
.nav a {
  padding: 0.35rem 0.7rem; border-radius: 6px; text-decoration: none; color: var(--text);
}
.nav a:hover { background: var(--grey-bg); }
.nav a.active { background: var(--accent); color: var(--accent-text); }
.nav-toggle { display: none; background: none; border: 1px solid var(--line); border-radius: 6px; color: var(--text); font-size: 1.1rem; padding: 0.15rem 0.55rem; }
.user-box { display: flex; align-items: center; gap: 0.5rem; }
.view { max-width: 1280px; margin: 0 auto; padding: 1rem; outline: none; }

/* building blocks */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 0.9rem 1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid > * { min-width: 0; }   /* let long names/errors wrap instead of widening the page */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.2rem 0.9rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.6rem; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 0.45rem 0.6rem; }
.stat .label { color: var(--muted); font-size: 0.78rem; }
.stat .value { font-size: 1.12rem; font-weight: 600; }

.btn {
  font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 0.4rem 0.8rem; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-block;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.small { padding: 0.2rem 0.55rem; font-size: 0.85rem; }
.btn.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 0.35rem 0.5rem; max-width: 100%;
}
input[type="checkbox"] { width: 1.05rem; height: 1.05rem; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
label.field > span.lbl { font-size: 0.82rem; color: var(--muted); }
label.field.check { flex-direction: row; align-items: center; gap: 0.45rem; }
label.field.check > span.lbl { font-size: inherit; color: var(--text); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0.7rem 1rem; align-items: end; }
.form-grid .wide { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 1rem; padding: 0.7rem 0.9rem 0.9rem; }
legend { font-weight: 600; padding: 0 0.4rem; }
.field-error { color: var(--bad); font-size: 0.82rem; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--bad); }

.banner { border-radius: 8px; padding: 0.6rem 0.9rem; margin-bottom: 0.8rem; border: 1px solid transparent; }
.banner.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.banner.info { background: var(--info-bg); border-color: var(--accent); }
.banner.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }

.badge {
  display: inline-block; padding: 0.05rem 0.5rem; border-radius: 999px; font-size: 0.78rem;
  font-weight: 600; background: var(--grey-bg); color: var(--text); white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--accent); }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 0.38rem 0.55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--grey-bg); }
td.pre { white-space: pre-wrap; font-family: var(--mono); font-size: 0.85rem; }

/* container number */
.cnum { font-family: var(--mono); font-weight: 700; letter-spacing: 0.04em; white-space: nowrap; display: inline-flex; gap: 0.45em; align-items: baseline; }
.cnum.large { font-size: 1.7rem; }
.cnum.huge { font-size: 2.3rem; }
.cnum .grp { display: inline-flex; }
.cnum .ch { display: inline-block; min-width: 0.62em; text-align: center; border-radius: 3px; }
.cnum .ch.unk { color: var(--muted); border-bottom: 2px dashed var(--muted); font-weight: 400; }
.cnum .ch.low { background: var(--bad-bg); color: var(--bad); }
.cnum .ch.mid { background: var(--warn-bg); color: var(--warn); }
.cnum .ch.fix { text-decoration: underline dotted; text-underline-offset: 0.18em; }
.cnum .grp.check { border: 2px solid currentColor; border-radius: 4px; padding: 0 0.12em; }
.cnum.empty { color: var(--muted); font-weight: 400; }

/* camera tiles */
.tile a.shot { text-decoration: none; cursor: zoom-in; }
.tile .shot { position: relative; background: #0b0f14; border-radius: 6px; overflow: hidden; aspect-ratio: 16 / 9; margin: 0.5rem 0; display: flex; align-items: center; justify-content: center; }
.tile .shot img { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile .shot .placeholder { color: #8c98a8; font-size: 0.9rem; position: absolute; }
.tile .head { display: flex; align-items: center; gap: 0.5rem; }
.tile .head h2 { margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-row { margin-bottom: 0.75rem; }
.title-row h1 { margin: 0; }
.fps-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.err-text { color: var(--bad); font-size: 0.85rem; overflow-wrap: anywhere; }

/* enlarged camera feeds (Video page) */
.view.view-wide { max-width: none; }
.video-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.video-head h1 { margin: 0; }
.video-bar { flex: 1; margin: 0; padding: 0.45rem 0.7rem; min-width: 0; }
.chips { display: flex; gap: 0.35rem; flex-wrap: wrap; min-width: 0; max-width: 100%; }
.chip {
  font: inherit; display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 999px; padding: 0.2rem 0.7rem; max-width: min(16rem, 100%);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip:hover { border-color: var(--accent); }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip .dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--muted); flex: none; }
.chip.live .dot { background: var(--ok); }
.chip.on .dot { box-shadow: 0 0 0 1.5px var(--accent-text); }
.check-inline { display: inline-flex; align-items: center; gap: 0.3rem; }
.wall { display: grid; gap: 8px; }
.wall:fullscreen { background: #000; padding: 8px; }
.wall.scrolling .pane { aspect-ratio: 16 / 9; }
.pane { position: relative; background: #0b0f14; border-radius: 6px; overflow: hidden; min-width: 0; min-height: 0; color: #e6eaf0; }
.pane canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.pane canvas.clickable { cursor: zoom-in; }
.pane.stale canvas { opacity: 0.45; }
.pane .placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 2.6rem 1rem; color: #b6c0cc; overflow-wrap: anywhere; pointer-events: none; }
.pane .bar { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0.5rem; background: rgba(8, 12, 17, 0.62); font-size: 0.85rem; min-width: 0; }
.pane .bar.top { top: 0; }
.pane .bar.bottom { bottom: 0; flex-wrap: wrap; row-gap: 0.1rem; }
.pane .bar .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pane .bar .btn { background: rgba(255, 255, 255, 0.12); color: #fff; border-color: rgba(255, 255, 255, 0.35); }
.pane .bar .btn:hover { border-color: #fff; }
.pane .rates { color: #c9d2dc; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pane .last-number { display: inline-flex; align-items: center; gap: 0.45rem; color: #fff; text-decoration: none; }
.pane .last-number .when { color: #c9d2dc; }

/* event cards */
.feed { display: flex; flex-direction: column; gap: 0.6rem; }
.event-card {
  display: grid; grid-template-columns: 1fr auto; gap: 0.3rem 0.9rem; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-left: 5px solid var(--line);
  border-radius: 8px; padding: 0.6rem 0.8rem; color: var(--text); text-decoration: none; box-shadow: var(--shadow);
}
.event-card:hover { border-color: var(--accent); }
.event-card.s-validated { border-left-color: var(--ok); }
.event-card.s-probable { border-left-color: var(--accent); }
.event-card.s-needs_review, .event-card.s-partial { border-left-color: var(--warn); }
.event-card.s-rejected { border-left-color: var(--bad); }
.event-card .meta { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; font-size: 0.86rem; }
.event-card .thumb { max-height: 72px; max-width: 220px; border-radius: 4px; border: 1px solid var(--line); grid-row: 1 / span 3; grid-column: 2; }
.ck-ok { color: var(--ok); font-weight: 600; }
.tag-later { color: var(--warn); background: var(--warn-bg); border-radius: 4px; padding: 0 0.35rem; font-size: 0.85em; }
.ck-bad { color: var(--bad); font-weight: 600; }

/* images / ROI */
.evidence { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0.8rem; }
.evidence figure { margin: 0; }
.evidence img { max-width: 100%; border-radius: 6px; border: 1px solid var(--line); cursor: zoom-in; display: block; }
.evidence figcaption { font-size: 0.8rem; color: var(--muted); }
.roi-editor canvas { width: 100%; max-width: 960px; border-radius: 6px; border: 1px solid var(--line); touch-action: none; display: block; background: #0b0f14; cursor: crosshair; }
.roi-editor .legend { font-size: 0.82rem; }
.swatch { display: inline-block; width: 0.8em; height: 0.8em; border-radius: 2px; margin-right: 0.25em; vertical-align: -0.05em; }

/* modal + toasts */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.modal { background: var(--panel); border-radius: 10px; max-width: min(96vw, 1100px); max-height: 94vh; overflow: auto; padding: 1rem; border: 1px solid var(--line); }
.modal img { max-width: 100%; height: auto; display: block; }
.modal .modal-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.6rem; }
.modal .modal-head h2 { flex: 1; margin: 0; }
.toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 60; max-width: min(92vw, 420px); }
.toast { background: var(--text); color: var(--bg); border-radius: 8px; padding: 0.55rem 0.8rem; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25); }
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

.login-box { max-width: 380px; margin: 8vh auto 0; }
.login-box form { display: flex; flex-direction: column; gap: 0.7rem; }
.pager { display: flex; gap: 0.6rem; align-items: center; justify-content: flex-end; margin-top: 0.6rem; flex-wrap: wrap; }
.checks { display: flex; gap: 0.3rem 0.9rem; flex-wrap: wrap; }
.checks label { display: inline-flex; align-items: center; gap: 0.3rem; }
ul.plain { margin: 0; padding-left: 1.1rem; }

@media (max-width: 720px) {
  .view { padding: 0.6rem; }
  .nav-toggle { display: inline-block; margin-left: auto; }
  .nav { display: none; flex-basis: 100%; flex-direction: column; order: 5; }
  .nav.open { display: flex; }
  .user-box { order: 4; }
  .grid, .grid.two { grid-template-columns: minmax(0, 1fr); }
  .video-head { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 0.4rem; }
  .cnum.large { font-size: 1.35rem; }
  .cnum.huge { font-size: 1.6rem; }
  .event-card { grid-template-columns: 1fr; }
  .event-card .thumb { grid-row: auto; grid-column: 1; max-width: 100%; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dd { margin-bottom: 0.35rem; }
}
