:root {
  --bg: #f4f5f7; --panel: #ffffff; --text: #1d2330; --muted: #677085; --line: #dfe2e8;
  --accent: #2459d6; --accent-text: #fff; --target: #d42a2a; --target-bg: #fdecec; --ok: #1f9d55; --bad: #d42a2a; --warn-bg: #fff4d6;
  --radius: 8px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --panel: #1b1f27; --text: #e6e8ee; --muted: #9aa3b5; --line: #2c3240;
    --accent: #5b8cff; --accent-text: #0b0e14; --target: #ff6b6b; --target-bg: #3a1d1f; --ok: #3ccf7c; --bad: #ff6b6b; --warn-bg: #3b3218;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
h1 { font-size: 20px; margin: 0 0 12px; } h2 { font-size: 16px; margin: 16px 0 8px; } h3 { font-size: 14px; margin: 16px 0 8px; }

.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.top nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); }
.top nav a.on { background: var(--bg); color: var(--text); font-weight: 600; }
main { padding: 16px; max-width: 1800px; margin: 0 auto; }
.banner.warn { background: var(--warn-bg); padding: 8px 16px; }

button, .button { font: inherit; border: 0; border-radius: 6px; padding: 6px 12px; background: var(--accent); color: var(--accent-text); cursor: pointer; display: inline-block; }
button.secondary, .button.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--bad); color: #fff; }
button.link { background: none; color: var(--accent); padding: 0; }
button.link.danger { color: var(--bad); background: none; }
button:disabled { opacity: .6; cursor: wait; }
.button.small { padding: 2px 8px; font-size: 12px; font-weight: 400; }
input, select { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); }
label { display: inline-flex; gap: 6px; align-items: center; }
form.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.hint { color: var(--muted); }
.error { color: var(--bad); }
.warn { background: var(--warn-bg); padding: 8px; border-radius: 6px; }
.empty { color: var(--muted); padding: 16px; list-style: none; }
.crumbs { color: var(--muted); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 8px 0; }

.summary, .totals { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; min-width: 120px; display: flex; flex-direction: column; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 18px; font-weight: 600; }
.stat .value small { font-size: 12px; font-weight: 400; color: var(--muted); }
.stat.bad { border-color: var(--bad); }
.target-stat { border-color: var(--target); }
.target-stat .value { font-size: 15px; }

.toolbar { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 12px; }
.areas-panel summary { cursor: pointer; padding: 5px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.areas-panel .panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-top: 6px; display: grid; gap: 6px; }

/* Live grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; transition: box-shadow .3s; }
.tile.saved { box-shadow: 0 0 0 2px var(--ok); }
.tile .screen { display: block; position: relative; aspect-ratio: 16 / 9; background: #000; }
.tile img { width: 100%; height: 100%; object-fit: contain; display: block; opacity: 0; }
.tile img.on { opacity: 1; }
.dot { position: absolute; top: 8px; left: 8px; width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(0,0,0,.5); }
.dot.up { background: var(--ok); } .dot.down { background: var(--bad); }
.count { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.65); color: #fff; border-radius: 10px; padding: 0 8px; font-size: 12px; }
.count::after { content: " people"; }
.tile footer { display: flex; align-items: center; gap: 8px; padding: 6px 8px; }
.tile .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile select { max-width: 50%; padding: 3px 6px; }

/* Focus */
.focus { display: grid; grid-template-columns: minmax(0, 3fr) minmax(260px, 1fr); gap: 16px; }
.focus-screen { position: relative; background: #000; border-radius: var(--radius); aspect-ratio: 16 / 9; overflow: hidden; }
.focus-screen img { width: 100%; height: 100%; object-fit: contain; display: block; }
#focus-wait { position: absolute; inset: 0; display: grid; place-items: center; color: #aaa; }
.area-tag { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; }
@media (max-width: 900px) { .focus { grid-template-columns: 1fr; } }

/* Events */
.event-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.event-list.wide { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
.event { display: flex; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; align-items: center; }
.event.is-target { border-color: var(--target); background: var(--target-bg); }
.event.fresh { animation: flash 1.5s; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: none; } }
.event .thumb { width: 64px; height: 64px; flex: none; background: var(--bg); border-radius: 6px; overflow: hidden; }
.event .thumb img { width: 100%; height: 100%; object-fit: cover; }
.event .meta { font-size: 13px; }
.badge { display: inline-block; border-radius: 10px; padding: 0 8px; font-size: 12px; background: var(--bg); border: 1px solid var(--line); }
.badge.target { background: var(--target); color: #fff; border-color: var(--target); }
.badge.muted { color: var(--muted); }

/* Faces */
.faces { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.face { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.face.is-target { border-color: var(--target); box-shadow: 0 0 0 1px var(--target); }
.face img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.face figcaption { padding: 6px 8px; display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.face .score { color: var(--text); font-weight: 600; }
.face .actions { display: flex; gap: 4px; flex-wrap: wrap; }
.face .actions button { font-size: 12px; padding: 3px 8px; }
.face.small { width: 120px; }
.enrolled { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
img.body { max-height: 220px; border-radius: 6px; }

/* Target timeline */
.day-nav { display: flex; gap: 12px; align-items: center; }
.timeline { width: 100%; height: auto; min-height: 40px; background: var(--bg); border-radius: 6px; display: block; }
.timeline .bar { fill: var(--target); }
.timeline .grid-line { stroke: var(--line); stroke-width: .15; }
.timeline-labels { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.timeline-labels .rows { display: flex; gap: 12px; flex-wrap: wrap; }
.timeline-labels .rows span::before { content: counter(row) ". "; counter-increment: row; }
.timeline-labels .rows { counter-reset: row; }
.timeline-labels .hours { display: flex; justify-content: space-between; }
.moves { padding-left: 18px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tr.bad td { color: var(--bad); }
.channel-row { display: grid; grid-template-columns: 1fr 2fr 2fr 1fr auto auto; gap: 6px; align-items: center; }
.channel-row .actions { display: flex; gap: 4px; }
.test-result img { max-width: 320px; margin-top: 6px; border-radius: 6px; }
@media (max-width: 900px) { .channel-row { grid-template-columns: 1fr; } }

.login-page { display: grid; place-items: center; min-height: 100vh; }
.card.login { width: min(360px, calc(100vw - 32px)); display: grid; gap: 12px; }
.card.login label { display: grid; }
