/* Kiosk Fleet — one operator, dense and legible, light and dark. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --border: #d9dee4;
  --text: #1b2733;
  --muted: #66707b;
  --accent: #2563eb;
  --accent-ink: #ffffff;

  --online: #15803d;   --online-bg: #dcfce7;
  --sleeping: #475569; --sleeping-bg: #e2e8f0;
  --late: #b45309;     --late-bg: #fef3c7;
  --never: #6b7280;    --never-bg: #e5e7eb;
  --danger: #b91c1c;   --danger-bg: #fee2e2;

  /* charts: one series hue, a hairline grid, and a wash for the night */
  --series-1: #2a78d6;
  --chart-grid: #e8ebef;
  --chart-night: rgba(102, 112, 123, 0.09);

  --radius: 10px;
  --mono: ui-monospace, "Cascadia Code", "Consolas", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141a;
    --surface: #171d25;
    --surface-2: #1e2631;
    --border: #2c3743;
    --text: #e6ebf1;
    --muted: #94a1b0;
    --accent: #3b82f6;

    --online: #4ade80;   --online-bg: #14311f;
    --sleeping: #94a3b8; --sleeping-bg: #1e293b;
    --late: #fbbf24;     --late-bg: #3a2c08;
    --never: #9ca3af;    --never-bg: #22272e;
    --danger: #f87171;   --danger-bg: #3a1414;

    --series-1: #3987e5;
    --chart-grid: #232c37;
    --chart-night: rgba(148, 161, 176, 0.08);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 15px; line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: .2rem 0 .6rem; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: .86em; }

/* layout */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0 clamp(16px, 4vw, 40px); height: 54px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--text); white-space: nowrap; flex-shrink: 0; }
/* On a phone the links scroll inside the bar, so the page itself never does. */
.topbar nav { display: flex; gap: 1rem; margin-right: auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.topbar nav a { color: var(--muted); font-size: .92rem; white-space: nowrap; }
.logout { flex-shrink: 0; }
.topbar nav a:hover { color: var(--text); text-decoration: none; }
.logout { margin: 0; }
.linkish { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; }
.linkish:hover { color: var(--text); }
.wrap { max-width: 1200px; margin: 0 auto; padding: clamp(16px, 3vw, 28px); }

/* login */
.login-card {
  max-width: 360px; margin: 8vh auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem;
}
.login-card h1 { margin: 0; }
.stack { display: flex; flex-direction: column; gap: .9rem; margin-top: 1.2rem; }
.stack label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .5rem .6rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
textarea { font-family: var(--mono); font-size: .85rem; width: 100%; resize: vertical; }
button {
  font: inherit; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); border-radius: 8px; padding: .5rem .9rem;
}
button:hover { border-color: var(--muted); }
button.primary, button.action.danger-normal { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.primary:hover { filter: brightness(1.06); }

.banner { padding: .6rem .8rem; border-radius: 8px; margin-top: 1rem; font-size: .9rem; }
.banner.error { background: var(--danger-bg); color: var(--danger); }

/* summary tiles */
.summary-row, .latest-row { display: flex; gap: .8rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .7rem 1rem; display: flex; flex-direction: column; min-width: 96px;
}
.stat .n { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.stat .l { font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.stat-late.lit { border-color: var(--late); background: var(--late-bg); }
.stat-late.lit .n { color: var(--late); }
.stat-never.lit { border-color: var(--never); }
.stat-online .n { color: var(--online); }
.stat-sleeping .n { color: var(--sleeping); }

/* filters */
.filters { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.filters .count { margin-left: auto; font-size: .85rem; }

/* tables */
table { width: 100%; border-collapse: collapse; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: .55rem .8rem; border-bottom: 1px solid var(--border); }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
table.devices tbody tr { cursor: pointer; }
table.devices tbody tr:hover { background: var(--surface-2); }
tr.behind td { background: var(--late-bg); }
.machine { font-weight: 600; }

/* status pills */
.pill { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .74rem;
  font-weight: 600; text-transform: capitalize; }
.pill-online { background: var(--online-bg); color: var(--online); }
.pill-sleeping { background: var(--sleeping-bg); color: var(--sleeping); }
.pill-late { background: var(--late-bg); color: var(--late); }
.pill-never { background: var(--never-bg); color: var(--never); }

.pill-cmd-completed { background: var(--online-bg); color: var(--online); }
.pill-cmd-failed { background: var(--danger-bg); color: var(--danger); }
.pill-cmd-queued, .pill-cmd-deferred { background: var(--late-bg); color: var(--late); }
.pill-cmd-delivered, .pill-cmd-running { background: var(--sleeping-bg); color: var(--sleeping); }
.pill-cmd-expired { background: var(--never-bg); color: var(--never); }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--online); }
.dot.bad { background: var(--danger); }
.dot.unknown { background: var(--never); }
.dot.warn { background: var(--late); }
.dot.none { background: transparent; box-shadow: inset 0 0 0 1.5px var(--never); }
.dot.stale { background: var(--never); opacity: .45; }
.badge { background: var(--danger-bg); color: var(--danger); border-radius: 999px;
  padding: .05rem .45rem; font-size: .76rem; font-weight: 700; }

.empty { padding: 2rem; text-align: center; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.refresh-note { font-size: .8rem; margin-top: .8rem; }

/* device detail */
.crumb { font-size: .85rem; color: var(--muted); margin-bottom: .4rem; }
.device-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.device-head .sub { display: flex; gap: .6rem; align-items: center; margin-top: .2rem; }
.tag { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  padding: .05rem .5rem; font-size: .78rem; }
.hb { display: grid; grid-template-columns: repeat(2, auto); gap: .3rem 1.4rem; font-size: .85rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem 1rem; }
.hb .k { color: var(--muted); display: inline-block; min-width: 62px; }

.viewtabs { display: flex; gap: .3rem; margin: 1.2rem 0 0; border-bottom: 1px solid var(--border); }
.viewtabs a { padding: .5rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; }
.viewtabs a:hover { color: var(--text); text-decoration: none; }
.viewtabs a.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.logtabs { display: flex; gap: .2rem; flex-wrap: wrap; margin: .9rem 0 .4rem; }
.logtabs a { padding: .3rem .7rem; border-radius: 7px; font-size: .85rem; color: var(--muted); }
.logtabs a:hover { background: var(--surface-2); text-decoration: none; }
.logtabs a.on { background: var(--accent); color: var(--accent-ink); }

.dayfilter { display: flex; gap: .8rem; align-items: center; margin-bottom: .6rem; flex-wrap: wrap; }
.dayfilter label { display: flex; gap: .4rem; align-items: center; font-size: .82rem; }
.dayfilter #logsearch { margin-left: auto; min-width: 220px; }

.logview { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .4rem 0; max-height: 62vh; overflow: auto; font-family: var(--mono); font-size: .82rem; }
.logline { padding: .12rem .9rem; display: flex; gap: .8rem; border-left: 3px solid transparent; white-space: pre-wrap; word-break: break-word; }
.logline:hover { background: var(--surface-2); }
.logline .ts { color: var(--muted); flex-shrink: 0; }
.logline.sev-error { border-left-color: var(--danger); background: var(--danger-bg); }
.logline.sev-warning { border-left-color: var(--late); }
.logline.sev-info .body { color: var(--online); }

/* control */
.inflight { background: var(--late-bg); border: 1px solid var(--late); border-radius: var(--radius);
  padding: .7rem 1rem; margin: 1rem 0; }
.cmd-row { display: flex; gap: .6rem; align-items: center; font-size: .88rem; margin-top: .35rem; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem; margin-top: 1.1rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.action { border-radius: 8px; }
.action.danger-confirm { border-color: var(--late); color: var(--late); }
.action.danger-destructive { border-color: var(--danger); color: var(--danger); }
.action.builtin { background: var(--surface-2); }
.tiny { font-size: .76rem; padding: .2rem .5rem; }
#push-name { width: 100%; margin-bottom: .5rem; }
#push-body { margin-bottom: .6rem; }

.tasks td { font-size: .85rem; }
.history details { border-bottom: 1px solid var(--border); padding: .3rem 0; }
.history summary { cursor: pointer; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; font-size: .88rem; }
.cmd-out { background: var(--surface-2); border-radius: 8px; padding: .6rem .8rem; margin: .5rem 0 .2rem;
  font-size: .8rem; overflow: auto; max-height: 300px; white-space: pre-wrap; }

/* screenshots */
.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; margin-top: 1rem; }
.shots figure { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.shots img { width: 100%; display: block; background: #000; aspect-ratio: 16/10; object-fit: contain; }
.shots figcaption { padding: .4rem .6rem; font-size: .82rem; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px;
  font-size: .88rem; box-shadow: 0 6px 20px rgba(0,0,0,.25); opacity: 0; transition: opacity .2s; z-index: 100; }
.toast.show { opacity: 1; }
.toast.err { background: var(--danger); color: #fff; }

.bundle-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; margin: 1rem 0; }
.bundle-card h2 { text-transform: capitalize; }
.bundle-card > div { display: flex; gap: .5rem; font-size: .9rem; margin: .2rem 0; }
.bundle-card .k { color: var(--muted); min-width: 78px; display: inline-block; }
.bundle-card button { margin-top: .8rem; }
.tiny-note { font-size: .78rem; margin: .5rem 0 0; }
.drift-h { margin-top: 1.5rem; }
.stage-row { display: flex; gap: .5rem; align-items: center; margin: .6rem 0; flex-wrap: wrap; }
.stage-row input[type=file] { font-size: .8rem; max-width: 190px; }
.chk { font-size: .8rem; color: var(--muted); display: flex; gap: .25rem; align-items: center; }
.anydesk-id { display: flex; gap: .6rem; align-items: center; margin: .3rem 0; }
.anydesk-id .big { font-size: 1.1rem; letter-spacing: .5px; }

/* peripherals: a dot and a few words in tables, a panel on the Control tab */
.periph { white-space: nowrap; }
.periph .dot { margin-right: .35rem; vertical-align: 1px; }
.periph.bad { color: var(--danger); font-weight: 600; }
.periph.warn { color: var(--late); font-weight: 600; }
.periph.none, .periph.unknown, .periph.stale { color: var(--muted); }
a.periph.ok { color: var(--text); }
a.periph:hover { text-decoration: underline; }
.periph-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 1.1rem; margin-top: 1.1rem; }
.periph-grid > .panel { margin-top: 0; }
.periph-notes { margin: .5rem 0; padding-left: 1.1rem; font-size: .88rem; }
.periph-notes li { margin: .2rem 0; }
.periph-head { display: flex; align-items: center; gap: .6rem; }
.periph-head h2 { margin: 0; }
.periph-summary { margin: .55rem 0 .3rem; }
.pill-periph-ok { background: var(--online-bg); color: var(--online); text-transform: none; }
.pill-periph-warn { background: var(--late-bg); color: var(--late); text-transform: none; }
.pill-periph-bad { background: var(--danger-bg); color: var(--danger); text-transform: none; }
.pill-periph-none, .pill-periph-unknown, .pill-periph-stale { background: var(--never-bg); color: var(--never); text-transform: none; }
.advice { margin: .5rem 0; padding: .4rem .75rem; font-size: .9rem; background: var(--surface-2);
  border-left: 3px solid var(--border); border-radius: 0 8px 8px 0; }
.advice-warn { border-left-color: var(--late); }
.advice-bad { border-left-color: var(--danger); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1.2rem; margin: .8rem 0 1rem; font-size: .88rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
button[disabled] { opacity: .5; cursor: not-allowed; }

/* battery charts (drawn by app.js) */
.bat-chart { position: relative; margin: .6rem 0 .2rem; min-height: 250px; }
.bat-chart.bat-compact { min-height: 48px; margin: .4rem 0; }
.bat-chart svg { display: block; overflow: visible; }
.bat-chart:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.bat-grid { stroke: var(--chart-grid); stroke-width: 1; }
.bat-axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.bat-halo { paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.bat-night { fill: var(--chart-night); }
.bat-threshold { stroke: var(--danger); stroke-width: 1; stroke-dasharray: 4 3; opacity: .6; }
.bat-area { fill: var(--series-1); fill-opacity: .10; }
.bat-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.bat-lone { fill: var(--series-1); }
.bat-end { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.bat-end-label { fill: var(--text); font-size: 12px; font-weight: 600; }
.bat-row-stream { fill: var(--series-1); fill-opacity: .55; }
.bat-row-silent { fill: var(--danger); }
.bat-cross { stroke: var(--muted); stroke-width: 1; }
.bat-tip { position: absolute; display: none; flex-direction: column; gap: .1rem; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .35rem .6rem;
  font-size: .78rem; color: var(--muted); white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.12); }
.bat-tip.show { display: flex; }
.bat-tip b { color: var(--text); font-size: .95rem; }
.bat-legend { display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; font-size: .78rem; color: var(--muted); margin: .4rem 0 .6rem; }
.bat-key { display: inline-block; width: 14px; height: 8px; border-radius: 2px; margin-right: .35rem; vertical-align: 0; }
.bat-key-night { background: var(--chart-night); box-shadow: inset 0 0 0 1px var(--chart-grid); }
.bat-key-stream { background: var(--series-1); opacity: .55; height: 5px; }
.bat-key-silent { background: var(--danger); height: 5px; }
.bat-key-threshold { height: 0; border-top: 1px dashed var(--danger); border-radius: 0; vertical-align: 3px; }
.bat-table summary { cursor: pointer; font-size: .85rem; color: var(--accent); margin: .3rem 0; }
.bat-table table { margin-top: .4rem; font-size: .84rem; }
.bat-table td, .bat-table th { padding: .3rem .7rem; }
.bat-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.bat-table tr.quiet td { color: var(--muted); }
.bat-spark { display: block; color: var(--muted); margin: .2rem 0 .6rem; }
.bat-spark:hover { text-decoration: none; }
.bat-spark:hover .tiny-note { color: var(--accent); }
.delta { font-size: .85rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.delta.up { color: var(--online); }
.delta.down { color: var(--danger); }
.stat .n .delta { font-size: 1.25rem; }

/* fleet camera page: small multiples on one scale */
.cam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: .9rem; }
.cam-card { margin-top: 0; padding: .9rem 1rem; color: var(--text); display: flex; flex-direction: column; }
.cam-card:hover { text-decoration: none; border-color: var(--accent); }
.cam-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.cam-figures { display: flex; align-items: baseline; gap: .6rem; margin-top: .3rem; }
.cam-now { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.cam-now.cam-quiet { font-size: 1.05rem; color: var(--muted); }
.cam-nodata { min-height: 48px; margin: .4rem 0; display: flex; align-items: center; font-size: .82rem; color: var(--muted); }
.cam-foot { font-size: .8rem; color: var(--muted); }

@media (max-width: 620px) {
  .hb { grid-template-columns: 1fr; }
  table { font-size: .85rem; }
  /* Tables that name their own narrow-screen columns use .narrow-hide; the
     rest keep hiding their 6th and 7th. */
  table:not(.narrow-explicit) th:nth-child(6), table:not(.narrow-explicit) td:nth-child(6),
  table:not(.narrow-explicit) th:nth-child(7), table:not(.narrow-explicit) td:nth-child(7) { display: none; }
  .narrow-hide { display: none; }
}
