:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #14171f;
  --muted: #5d6475;
  --line: #dde1e8;
  --accent: #2563eb;
  --danger: #c2410c;
  --ok: #15803d;
  --motion: #2563eb;
  --person: #d97706;
  --vehicle: #7c3aed;
  --pet: #0d9488;
  --sound: #db2777;
  --other: #64748b;
  --chart-person: #d97706;
  --chart-vehicle: #7c3aed;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --text: #e8eaf0;
    --muted: #9aa1b2;
    --line: #2a2f3a;
    --accent: #60a5fa;
    --danger: #fb923c;
    --ok: #4ade80;
    --motion: #60a5fa;
    --person: #fbbf24;
    --vehicle: #a78bfa;
    --pet: #2dd4bf;
    --sound: #f472b6;
    --other: #94a3b8;
    --chart-person: #d97706;
    --chart-vehicle: #8b5cf6;
    color-scheme: dark;
  }
}

* { 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, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: .01em; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent); }

/* ── Sign in ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 340px; display: grid; gap: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px;
}
.login-card .brand { font-size: 18px; margin-bottom: 4px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input {
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-card button[type=submit] {
  padding: 10px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600;
}
.login-card button[disabled] { opacity: .6; }
.err { color: var(--danger); margin: 0; min-height: 1.2em; font-size: 13px; }

/* ── Header ── */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.daynav { display: flex; align-items: center; gap: 6px; margin-inline: auto; }
.icon, .ghost {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; height: 34px;
}
.icon { width: 34px; font-size: 20px; line-height: 1; }
.ghost { padding: 0 12px; font-size: 14px; }
.icon:disabled, .ghost:disabled { opacity: .4; cursor: default; }
.datepick { position: relative; display: inline-flex; align-items: center; padding: 0 12px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; min-width: 150px; justify-content: center; }
.datepick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }

/* ── Status ── */
.status { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 16px 0; font-size: 13px; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--other); }
.pill.ok i { background: var(--ok); }
.pill.bad i { background: var(--danger); }

/* ── Summary + timeline ── */
.panel { margin: 12px 16px 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.summary { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.total strong { font-size: 22px; }
.total span { color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2); font-size: 13px;
}
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.chip[aria-pressed="false"] { opacity: .45; }

.timeline { margin-top: 14px; }
.track { position: relative; height: 34px; border-radius: 8px; background: var(--surface-2); overflow: hidden; }
.track .now { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--danger); opacity: .7; }
.track .hr { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line); }
.mark {
  position: absolute; top: 6px; bottom: 6px; min-width: 3px; border-radius: 2px; background: var(--c); border: 0; padding: 0;
  opacity: .9;
}
.mark:hover, .mark:focus-visible { opacity: 1; outline: 2px solid var(--text); outline-offset: 1px; }
.hours { position: relative; height: 18px; font-size: 11px; color: var(--muted); }
.hours span { position: absolute; transform: translateX(-50%); top: 3px; }

/* ── List ── */
.list { padding: 8px 16px 40px; }
.hour-h { margin: 18px 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.card {
  display: grid; grid-template-rows: auto 1fr; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; scroll-margin-top: 80px;
}
.card.flash { outline: 2px solid var(--accent); }
.thumb {
  aspect-ratio: 16 / 9; background: var(--surface-2); border: 0; padding: 0; display: block; width: 100%;
  position: relative; color: var(--muted); font-size: 12px;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .noimg { position: absolute; inset: 0; display: grid; place-items: center; }
.meta { padding: 10px 12px; display: grid; gap: 4px; }
.meta .row { display: flex; align-items: center; gap: 4px 8px; justify-content: space-between; flex-wrap: wrap; }
.time { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--text); }
.badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.sub { font-size: 12px; color: var(--muted); }
.live { color: var(--danger); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* ── Viewer ── */
.viewer { border: 0; padding: 0; background: transparent; max-width: min(96vw, 1400px); width: 100%; }
.viewer::backdrop { background: rgba(0, 0, 0, .8); }
.viewer img { width: 100%; height: auto; border-radius: 8px; display: block; }
.viewer p { color: #eee; text-align: center; margin: 8px 0 0; }
.viewer .close { position: absolute; right: 8px; top: 8px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 22px; }

/* ── Tiles ── */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 12px 16px 0; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.tile-l { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.tile-l i { width: 10px; height: 10px; border-radius: 3px; }
.tile-v { font-size: 30px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.tile-s { font-size: 12px; color: var(--muted); }

/* ── Visits + history ── */
.duo { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 12px; margin: 12px 16px 0; }
.duo .panel { margin: 0; min-width: 0; }
.ph { font-size: 14px; margin: 0 0 10px; }
.ph-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 13px; margin: 0; }
.hint { color: var(--muted); font-weight: 400; font-size: 11px; }
table.visits { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.visits th, table.visits td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.visits thead th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.visits .num { text-align: right; }
table.visits td, table.visits thead th { white-space: nowrap; }
table.visits a { color: var(--text); }
.who { color: var(--text); }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 5px; }
.lg i { width: 10px; height: 10px; border-radius: 3px; }
.history { position: relative; }
.history svg { display: block; width: 100%; height: auto; }
.history .grid { stroke: var(--line); stroke-width: 1; }
.history .axis { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.history .tick { fill: var(--muted); font-size: 11px; }
.history .tick.sel { fill: var(--text); font-weight: 700; }
.history .val { fill: var(--text); font-size: 11px; font-weight: 600; }
.history .hit { fill: transparent; cursor: pointer; outline: none; }
.history .hit:hover, .history .hit:focus-visible { fill: color-mix(in srgb, var(--text) 6%, transparent); }
.tip {
  position: absolute; top: 0; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15); min-width: 140px;
}
.tip-h { font-weight: 650; margin-bottom: 4px; }
.tip-r { display: flex; align-items: center; gap: 6px; }
.tip-r i { width: 8px; height: 8px; border-radius: 2px; }
.tip-r b { margin-left: auto; font-variant-numeric: tabular-nums; }
.tip-f { color: var(--muted); margin-top: 4px; font-size: 11px; }
.tableview { margin-top: 8px; font-size: 13px; }
.tableview summary { cursor: pointer; color: var(--muted); }

@media (max-width: 860px) {
  .duo { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 560px) {
  .tiles { gap: 8px; }
  .tile { padding: 10px; }
  .tile-v { font-size: 24px; }
  table.visits th, table.visits td { padding: 6px 4px; }
  table.visits .hint { display: block; }
  .bar { gap: 8px; }
  .daynav { order: 3; width: 100%; justify-content: center; }
  .datepick { min-width: 0; flex: 1; }
  .cards { grid-template-columns: 1fr 1fr; }
  .meta { padding: 8px; }
  .hours .minor { display: none; }
}
