/* AIC People Counting — one column: filters, totals, chart, cameras. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.05);
  --series: #2a78d6;
  --accent: #256abf;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --critical: #d03b3b;
  --critical-wash: #fbebeb;
  --focus: #2a78d6;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.06);
    --series: #3987e5;
    --accent: #3987e5;
    --accent-ink: #0d0d0d;
    --critical: #e66767;
    --critical-wash: #3a1f1f;
    --focus: #6da7ec;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; text-wrap: balance; }
h2 { font-size: 16px; font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Brand */
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0.02em; }
.brand-mark { width: 10px; height: 18px; border-radius: 2px 2px 0 0; background: var(--series); }
.brand-sub { font-weight: 400; color: var(--ink-2); letter-spacing: 0; }

/* Controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--wash); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--wash); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn[aria-pressed="true"] { background: var(--wash); }
input, select {
  min-height: 36px; padding: 0 10px; width: 100%;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--ink); font: inherit;
}
label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 4px; }
.form-error { min-height: 20px; margin: 8px 0 0; color: var(--critical); font-size: 14px; }
.form-error:empty { visibility: hidden; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; padding: 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 20px; margin: 10px 0 20px; }
.login-card label { margin-top: 12px; }
.login-card .btn { width: 100%; margin-top: 8px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px max(16px, calc((100vw - 1120px) / 2));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-name { color: var(--ink-2); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.page { max-width: 1152px; margin: 0 auto; padding: 20px 16px 48px; display: flex; flex-direction: column; gap: 16px; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 36px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px; cursor: pointer;
}
.chip:hover { background: var(--wash); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: transparent; font-weight: 600; }
.field input[type="date"] { width: 142px; }
.field select { width: auto; min-width: 120px; max-width: 200px; }
.field #f-camera { max-width: 320px; }

.banner {
  margin: 0; padding: 10px 14px; border-radius: 8px;
  background: var(--critical-wash); color: var(--ink); border: 1px solid var(--border);
}

/* Tiles */
.tiles { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 12px; }
.tile, .card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.tile { padding: 16px 18px; min-width: 0; }
.tile-label { color: var(--ink-2); font-size: 13px; }
.tile-value { font-size: 28px; font-weight: 600; line-height: 1.2; margin-top: 2px; }
.tile.hero .tile-value { font-size: 48px; }
.tile-note { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* Cards */
.card { padding: 16px 18px; min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-sub { color: var(--ink-2); font-size: 13px; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* Chart */
.chart { position: relative; width: 100%; transition: opacity 0.15s; }
.chart.loading { opacity: 0.5; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--series); }
.chart .hit { fill: transparent; outline: none; }
.chart .hit.on { fill: var(--wash); }
.chart .peak { fill: var(--ink-2); font-size: 12px; font-weight: 600; }
.chart-empty { display: grid; place-items: center; min-height: 220px; color: var(--ink-2); text-align: center; padding: 0 16px; }
.tooltip {
  position: absolute; z-index: 5; pointer-events: none;
  min-width: 132px; padding: 8px 10px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(11, 11, 11, 0.12); font-size: 13px;
}
.tooltip .tt-title { color: var(--ink-2); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.tooltip .tt-key { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tooltip .tt-swatch { width: 10px; height: 2px; border-radius: 1px; background: var(--series); }
.tooltip .tt-swatch.none { background: transparent; }
.tooltip .tt-val { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 10px 10px; text-align: left; border-bottom: 1px solid var(--grid); vertical-align: middle; }
table.data thead th { font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tfoot td { font-weight: 600; border-bottom: 0; }
table.data tbody tr.selected { background: var(--wash); }
#chart-table-wrap { max-height: 320px; overflow-y: auto; margin-top: 12px; }
.cam-btn {
  display: block; padding: 0; border: 0; background: none; color: var(--ink);
  font: inherit; font-weight: 600; text-align: left; cursor: pointer;
}
.cam-btn:hover { text-decoration: underline; }
.cam-site { display: none; color: var(--ink-2); font-size: 13px; }
.cam-sn { display: block; color: var(--muted); font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.site-none { color: var(--muted); }
.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }
.status.off .status-dot { background: transparent; box-shadow: inset 0 0 0 2px var(--critical); }
.status-when { display: block; color: var(--muted); font-size: 12px; }
.empty { margin: 8px 0 4px; color: var(--ink-2); }
.footnote { margin: 0; color: var(--muted); font-size: 13px; }
body:not(.is-admin) .admin-only { display: none; }

/* Dialog */
dialog {
  width: min(420px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgba(11, 11, 11, 0.45); }
dialog label { margin-top: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

@media (max-width: 760px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile.hero { grid-column: 1 / -1; }
  .tile.hero .tile-value { font-size: 40px; }
  .brand-sub { display: none; }
  .field { flex: 1 1 132px; }
  .field input[type="date"], .field select { width: 100%; max-width: none; }
  .card-head { flex-wrap: wrap; }

  /* Cameras: each row becomes a small block instead of a wide table. */
  #devices-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #devices-table, #devices-table tbody, #devices-table tfoot { display: block; }
  #devices-table tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto auto; column-gap: 16px; row-gap: 6px;
    padding: 12px 0; border-bottom: 1px solid var(--grid);
  }
  #devices-table tfoot tr { border-bottom: 0; }
  #devices-table td { padding: 0; border: 0; }
  #devices-table .c-site { display: none; }
  #devices-table .cam-site { display: block; }
  #devices-table .c-in::before, #devices-table .c-out::before {
    content: attr(data-label); display: block; color: var(--ink-2); font-size: 12px; font-weight: 400;
  }
  #devices-table .c-status { grid-column: 1 / -1; }
  #devices-table tfoot .c-status, #devices-table tfoot .c-act { display: none; }
  #devices-table tbody tr.selected { margin: 0 -8px; padding: 12px 8px; border-radius: 8px; }
}
