/* ==========================================================================
   Themes. The default (:root) is the generic "Slate" palette; every other
   palette overrides the same variables via [data-theme=...] on <html>.
   All components style themselves ONLY from these variables.
   ========================================================================== */
:root {
  /* Slate (generic default): graphite neutrals with a steel-blue accent */
  --bg: #1f242b;           /* page background, header/sidebar, dark sections */
  --panel: #2c343f;        /* primary surface (cards) */
  --panel-2: #242b34;      /* secondary depth (input wells, chips, hovers) */
  --line: #3b4552;         /* subtle border on both bg and cards */
  --text: #e8ecf1;         /* primary text */
  --muted: #9fb0c0;        /* secondary text */
  --accent: #5aa7e8;       /* headings, buttons, borders, tags */
  --accent-2: #82c0f4;     /* hover/highlight state */
  --accent-ink: #0e1420;   /* ink on accent surfaces */
  --info: #82c0f4;
  --ok: #22c55e;
  --bad: #ef4444;
  --warn: #f5a524;
  --radius: 10px;
  --stage-bg: #14181d;     /* empty media wells (snapshot boxes etc.) */
  --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
}

/* Night Owl: cream/gold on sage greens (the NightOwl house palette) */
:root[data-theme="nightowl"] {
  --bg: #3a4a3c;
  --panel: #6b7f6e;
  --panel-2: #4a5c4d;
  --line: #5a6b5c;
  --text: #f5efe3;
  --muted: #ddd6c4;
  --accent: #d4b484;
  --accent-2: #e8cea0;
  --accent-ink: #3a4a3c;
  --info: #e8cea0;
  --stage-bg: #2b382d;
}

/* Fremantle: Dockers purple with white/silver chevron accents */
:root[data-theme="fremantle"] {
  --bg: #1e1140;
  --panel: #35225e;
  --panel-2: #29184e;
  --line: #473370;
  --text: #f4f1fb;
  --muted: #c3b8dc;
  --accent: #efecf8;
  --accent-2: #ffffff;
  --accent-ink: #2a165c;
  --info: #c3b8dc;
  --stage-bg: #150b30;
}

/* Light: warm paper for daylight control rooms */
:root[data-theme="light"] {
  --bg: #eeeeea;
  --panel: #ffffff;
  --panel-2: #e4e4de;
  --line: #d0d0c7;
  --text: #23282e;
  --muted: #626a72;
  --accent: #38678c;
  --accent-2: #4a7ea8;
  --accent-ink: #ffffff;
  --info: #38678c;
  --ok: #15803d;
  --bad: #dc2626;
  --warn: #b45309;
  --stage-bg: #d8d8d1;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
}
h1, h2 { font-weight: 600; letter-spacing: -.01em; }
h3 { letter-spacing: -.01em; }
button { font-family: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--bg);          /* header/dark section = Sage Deep */
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 20px 20px 16px; display: flex; align-items: center; gap: 11px; }
.brand-icon { width: 42px; height: auto; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-size: 19px; font-weight: 600; color: var(--text); line-height: 1.15; letter-spacing: 0; }
.brand-gold { color: var(--accent); }
.brand-sub { font-size: 10.5px; font-weight: 300; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-top: 3px; }
.sidebar nav { display: flex; flex-direction: column; padding: 4px 10px; gap: 2px; }
.sidebar nav a {
  color: var(--muted); padding: 10px 14px; border-radius: 8px;
  font-weight: 500; display: flex; align-items: center; gap: 10px;
}
.sidebar nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: var(--accent); color: var(--accent-ink); }
.sidebar nav .ico { width: 16px; text-align: center; opacity: .9; }
.sidebar-foot { margin-top: auto; padding: 16px 20px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }

/* Content */
.content { flex: 1; padding: 28px 32px; max-width: 1200px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 10px; }
.page-head h1 { margin: 0; font-size: 24px; }
.page-actions { display: flex; align-items: center; gap: 12px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }

/* Stat row */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 22px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.stat-num { font-size: 30px; font-weight: 700; }
.stat-of { font-size: 18px; color: var(--muted); font-weight: 500; }
.stat-label { color: var(--muted); margin-top: 2px; }
.stat.danger { border-color: var(--bad); }
.stat.danger .stat-num { color: var(--bad); }

.alert-banner {
  background: rgba(239,68,68,.12); border: 1px solid var(--bad); color: #fca5a5;
  padding: 12px 16px; border-radius: var(--radius); margin-bottom: 18px; font-weight: 600;
}

/* Venue tiles + donut wheel */
.venue-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.venue-tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 10px 12px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text); transition: transform .08s ease, border-color .12s; font-family: inherit; }
.venue-tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.venue-name { font-weight: 600; font-size: 13.5px; text-align: center; line-height: 1.2; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.venue-sub { font-size: 11.5px; color: var(--muted); }
.donut { width: 82px; height: 82px; }
.donut-bg { stroke: var(--panel-2); }
.donut-fg { stroke: var(--ok); transition: stroke-dasharray .4s ease; }
.donut-num { fill: var(--text); font-size: 7px; font-weight: 700; text-anchor: middle; font-family: inherit; }
.venue-tile.alert { border-color: rgba(239,68,68,.5); }
.venue-tile.alert .donut-fg { stroke: var(--bad); }
.venue-tile.alert .venue-sub { color: #fca5a5; font-weight: 600; }
.venue-tile.hdd { border-color: rgba(239,68,68,.65); }
.venue-tile.hdd .donut-fg { stroke: var(--bad); }
.venue-tile.hdd .venue-sub { color: #fca5a5; font-weight: 600; }
.venue-tile.unreachable { border-color: rgba(148,163,184,.4); }
.venue-tile.unreachable .donut-fg { stroke: var(--muted); }
.venue-tile.unreachable .donut-num { fill: var(--muted); }
.venue-tile.unreachable .venue-sub { color: var(--warn); font-weight: 600; }
.venue-tile.works { border-color: rgba(245,158,11,.55); }
.venue-tile.works .donut-fg { stroke: var(--warn); }
.venue-tile.works .venue-sub { color: var(--warn); font-weight: 600; }
.venue-tile.changed { border-color: rgba(212,180,132,.5); }
.venue-tile.changed .donut-fg { stroke: var(--info); }
.venue-tile.changed .venue-sub { color: var(--info); font-weight: 600; }

.info-banner { background: rgba(212,180,132,.12); border: 1px solid var(--info); color: var(--info); padding: 12px 16px; border-radius: var(--radius); margin-bottom: 18px; }
.changed-note { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: rgba(212,180,132,.1); border: 1px solid rgba(212,180,132,.4); color: var(--info); padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 50; }
.modal-overlay.show { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: 100%; max-width: 540px; max-height: 80vh; overflow-y: auto; padding: 18px 20px; }
.modal.modal-wide { max-width: 680px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.modal-sub { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 8px; }
.modal-loading { padding: 30px; text-align: center; color: var(--muted); }
.modal-allgood { padding: 6px 0; }

/* Live view */
.live-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: 100%; max-width: 880px; overflow: hidden; }
.live-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.live-stage { background: #000; display: flex; align-items: center; justify-content: center; min-height: 320px; }
.live-stage img { max-width: 100%; max-height: 72vh; display: block; }
.live-foot { padding: 8px 16px; font-size: 12px; }
.snap-img img { cursor: pointer; }

/* Cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.card-alert { border-color: var(--bad); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.card-head h2, .card-head h3 { margin: 0; font-size: 17px; }
.card-head h3 { font-size: 15px; }
.site-heading { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 0 10px; }

.empty { background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); }

/* Pills & badges */
.pill { font-size: 12px; padding: 4px 12px; border-radius: 999px; font-weight: 600; }
.pill-ok { background: rgba(34,197,94,.15); color: #86efac; }
.pill-bad { background: rgba(239,68,68,.15); color: #fca5a5; }
.badge { font-size: 11.5px; padding: 3px 9px; border-radius: 6px; font-weight: 600; }
.badge-ok { background: rgba(34,197,94,.15); color: #86efac; }
.badge-bad { background: rgba(239,68,68,.15); color: #fca5a5; }
.badge-warn { background: rgba(245,158,11,.15); color: #fcd34d; }

/* Tables */
/* Wide tables live inside .table-scroll so narrow screens scroll the table,
   not the page. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll > table { min-width: 560px; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.data-table tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }

.offline-list { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.offline-row { color: #fca5a5; background: rgba(239,68,68,.08); padding: 7px 12px; border-radius: 6px; border-left: 3px solid var(--bad); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ignored-block { margin-top: 12px; }
.ignored-block summary { cursor: pointer; color: var(--muted); font-size: 12.5px; padding: 4px 0; }
.ignored-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); padding: 6px 12px; background: var(--panel-2); border-radius: 6px; margin-top: 6px; }
.ack-area { display: inline-flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.btn-ghost { opacity: .7; }
.btn-ghost:hover { opacity: 1; }

/* Works List */
.wl-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.wl-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.wl-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.wl-table tr:last-child td { border-bottom: none; }
/* NB: must stay a real table-cell (no flex) or its border-bottom detaches from the row */
.wl-actions { text-align: right; white-space: nowrap; }
.wl-actions .btn + .btn { margin-left: 6px; }

/* Fault reports */
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.chip:hover { border-color: var(--accent); text-decoration: none; color: var(--text); }
.chip-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip-on:hover { color: var(--accent-ink); }
.fault-table td { vertical-align: top; }
.fault-table .nowrap { white-space: nowrap; }
.fault-details { max-width: 420px; }
.fault-details .small { font-size: 11.5px; }
.nvr-form label.full { display: block; margin-top: 12px; }
.nvr-form label.full textarea { width: 100%; margin-top: 4px; resize: vertical; }

.edit-note { font-size: 12.5px; margin: 0 0 12px; line-height: 1.5; }

/* Fault ticket detail */
.ticket-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.ticket-desc { margin: 4px 0; white-space: pre-wrap; }
.timeline { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.tl-entry { border-left: 2px solid var(--line); padding: 2px 0 2px 14px; }
.tl-when { font-weight: 600; font-size: 13px; }
.tl-note { white-space: pre-wrap; margin: 4px 0; font-size: 14px; }
.fault-thumb { max-width: 260px; max-height: 200px; border-radius: 8px; border: 1px solid var(--line); margin-top: 6px; cursor: pointer; display: block; }

.add-update { border-top: 1px solid var(--line); padding-top: 14px; }
.add-update textarea { width: 100%; min-height: 96px; resize: vertical; box-sizing: border-box; }
.au-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; align-items: end; }
.au-row input { min-width: 200px; }
.au-status { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }
.paste-zone { margin-top: 10px; border: 1.5px dashed var(--line); border-radius: 8px; padding: 14px 18px; display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.paste-zone.drag { border-color: var(--accent); color: var(--text); background: var(--panel-2); }
.paste-zone.has-img { border-style: solid; }
.paste-browse { color: var(--accent); cursor: pointer; text-decoration: underline; }
.img-preview { margin-top: 10px; display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.img-preview img { max-width: 260px; max-height: 200px; border-radius: 8px; border: 1px solid var(--line); }

/* Snapshots */
.snap-hint { margin: -6px 0 14px; }
.site-fold { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 14px; background: var(--panel); }
.site-fold > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; }
.site-fold > summary::-webkit-details-marker { display: none; }
.site-fold > summary:hover { background: var(--panel-2); border-radius: 10px; }
.site-fold-name { font-size: 16px; font-weight: 700; }
.site-fold-meta { display: inline-flex; align-items: center; gap: 9px; white-space: nowrap; }
.fold-arrow { display: inline-block; font-size: 16px; line-height: 1; color: var(--accent); transition: transform .15s ease; }
details[open] > summary .fold-arrow { transform: rotate(180deg); }
.site-fold-body { padding: 12px 14px 14px; }
.site-fold-body .card { background: var(--panel-2); }
.snap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.snap-tile { margin: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.snap-img { position: relative; aspect-ratio: 16/9; background: var(--stage-bg); display: flex; align-items: center; justify-content: center; }
.snap-img img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.snap-placeholder { color: var(--muted); font-size: 12px; padding: 8px; text-align: center; }
.snap-refresh { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.55); color: #fff; border: none; width: 28px; height: 28px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.snap-refresh:hover { background: var(--accent); color: var(--accent-ink); }
.snap-flag { position: absolute; bottom: 6px; left: 6px; background: var(--bad); color: #fff; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; }
.snap-tile figcaption { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; gap: 8px; }
.snap-title { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.snap-time { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* Storage */
.kv-row { display: flex; gap: 28px; margin-bottom: 14px; }
.kv-num { font-size: 26px; font-weight: 700; }
.kv-num.small { font-size: 15px; font-weight: 600; }
.kv-label { color: var(--muted); font-size: 12px; }
.disk { margin-top: 10px; }
.disk-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.bar { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.bar-fill.bar-hot { background: var(--bad); }

/* Health */
.health-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 28px; }
.health-grid > div { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 5px 0; gap: 12px; }
.h-label { color: var(--muted); }
.h-val { text-align: right; }
.disk-chip { display: inline-block; position: relative; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: 12px; margin: 1px 0 1px 6px; white-space: nowrap; cursor: default; }
.disk-chip.bad { border-color: rgba(239,68,68,.6); color: #fca5a5; background: rgba(239,68,68,.08); }
.disk-chip:hover { border-color: var(--accent); }
/* SMART hover card */
.disk-tip { display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 250px; max-width: 340px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; box-shadow: 0 10px 28px rgba(0,0,0,.45); text-align: left; white-space: normal; color: var(--text); font-size: 12px; line-height: 1.45; }
.disk-chip:hover .disk-tip { display: block; }
.disk-tip .tip-title { display: block; font-weight: 600; margin-bottom: 6px; border-bottom: 1px solid var(--line); padding-bottom: 5px; }
.disk-tip table { width: 100%; border-collapse: collapse; }
.disk-tip td { padding: 2px 0; vertical-align: top; }
.disk-tip td:first-child { color: var(--muted); padding-right: 12px; white-space: nowrap; }
.disk-tip td:last-child { text-align: right; word-break: break-all; }
.disk-tip .tip-note { color: var(--muted); }
.err-note { margin-top: 12px; color: #fca5a5; background: rgba(239,68,68,.08); padding: 8px 12px; border-radius: 6px; }
.err-note a { color: inherit; }

/* Buttons */
.btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-size: 13px; font-weight: 500; display: inline-block; }
a.btn, a.btn:hover { text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn-small { padding: 5px 10px; font-size: 12px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-danger { color: #fca5a5; border-color: rgba(239,68,68,.4); }
.btn-danger:hover { border-color: var(--bad); background: rgba(239,68,68,.1); }

/* Forms */
label { display: flex; flex-direction: column; font-size: 12.5px; color: var(--muted); gap: 4px; min-width: 0; }
/* form controls never get wider than their column (long <option> text etc.) */
label > input, label > select, label > textarea { width: 100%; min-width: 0; }
input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 8px 10px; font-size: 13px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; }

/* Collapsed NVR list */
.nvr-item { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--panel-2); }
.nvr-item > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; }
.nvr-item > summary::-webkit-details-marker { display: none; }
.nvr-item[open] > summary { border-bottom: 1px solid var(--line); }
.nvr-name { font-weight: 600; }
.nvr-status { display: flex; align-items: center; gap: 10px; }
.edit-hint { color: var(--muted); font-size: 12px; }
.add-summary { cursor: pointer; list-style: none; }
.add-summary::-webkit-details-marker { display: none; }
.add-summary h2 { margin: 0; }

.nvr-form { padding: 16px 14px 14px; }
.nvr-item .nvr-form { border-top: none; }
.nvr-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.nvr-row > label { flex: 1; min-width: 130px; }
.nvr-row > label.w-port { flex: 0 0 90px; }
.nvr-row > label.w-scheme { flex: 0 0 130px; }
.nvr-row > label.check { flex: 0 0 auto; align-self: flex-end; padding-bottom: 8px; }
.nvr-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.test-result, #test-email-result { font-size: 12.5px; }
.test-result.ok, #test-email-result.ok { color: #86efac; }
.test-result.bad, #test-email-result.bad { color: #fca5a5; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid2 .full { grid-column: 1 / -1; }
.inline-test { display: flex; gap: 10px; align-items: center; margin-top: 14px; }
.inline-test input { flex: 0 0 280px; }
.save-bar { position: sticky; bottom: 0; padding: 14px 0; display: flex; justify-content: flex-end;
  background: linear-gradient(to top, var(--bg) 60%, transparent); }
.jobs { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.job-pill { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 9px; font-size: 11.5px; }

/* Toast */
.toast { position: fixed; bottom: 22px; right: 22px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px 18px; opacity: 0; transform: translateY(10px); transition: all .2s; pointer-events: none; max-width: 360px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok { border-color: var(--ok); }
.toast.bad { border-color: var(--bad); }

@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; padding: 4px 10px 10px; }
  .sidebar-foot { display: none; }
  .brand { padding: 14px 16px 8px; font-size: 20px; }
  .stat-row, .grid2, .health-grid { grid-template-columns: 1fr; }
  .content { padding: 16px 14px; }
  .card { padding: 14px; }
  /* keep everything inside the touchable area */
  .page-actions { flex-wrap: wrap; }
  .inline-test { flex-wrap: wrap; }
  .inline-test input { flex: 1 1 200px; min-width: 0; }
  .health-grid > div { flex-wrap: wrap; }         /* disk chips wrap under the label */
  .disk-tip { max-width: min(340px, 88vw); }
  .modal-overlay { padding: 16px 10px; }
  .modal { max-height: 90vh; }
  .toast { left: 14px; right: 14px; max-width: none; }
  .fault-details { max-width: none; }
  .kv-row { flex-wrap: wrap; gap: 16px; }
  input, select, textarea { font-size: 16px; }    /* stops iOS zoom-on-focus */
}

/* ==========================================================================
   NVR Manager additions (auth pages, live grid player, mobile tab bar)
   ========================================================================== */

/* Auth (login / setup) */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px 26px; width: 100%; max-width: 380px; }
.auth-brand { padding: 0 0 18px; }
.auth-title { margin: 0 0 6px; font-size: 18px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.auth-form .btn { margin-top: 4px; padding: 10px; font-size: 14px; }

/* Generic brand mark (inline SVG inherits the accent colour of any theme) */
.generic-logo { width: 38px; height: 38px; color: var(--accent); flex-shrink: 0; }

/* Sidebar user chip */
.logout-form { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.user-chip { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Live grid play affordance */
.snap-img { cursor: pointer; }
.snap-play { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 30px; color: #fff; background: rgba(0,0,0,0); opacity: 0; transition: opacity .12s, background .12s; text-shadow: 0 2px 8px rgba(0,0,0,.7); }
.snap-img:hover .snap-play { opacity: 1; background: rgba(0,0,0,.25); }

/* Full-viewport player overlay (live + fullscreen playback) */
.player-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.82); display: none; align-items: center; justify-content: center; padding: 18px; z-index: 60; }
.player-overlay.show { display: flex; }
.player-box { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; width: 100%; max-width: 1100px; overflow: hidden; display: flex; flex-direction: column; max-height: 96vh; }
.player-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600; gap: 10px; }
.player-head-actions { display: inline-flex; align-items: center; gap: 8px; }
/* Fixed 16:9 stage: the poster and the (later-arriving) video render at the
   same size, so there's no small-poster-then-jump when the stream decodes. */
.player-stage { position: relative; background: #000; aspect-ratio: 16/9; max-height: 82vh; display: flex; align-items: center; justify-content: center; }
.player-stage video-stream { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.player-stage video { width: 100%; height: 100%; object-fit: contain; display: block; }
.player-status { position: absolute; bottom: 10px; left: 0; right: 0; text-align: center; color: #fff; font-size: 13px; text-shadow: 0 1px 3px rgba(0,0,0,.9); pointer-events: none; }

/* Mobile: bottom tab bar navigation */
@media (max-width: 820px) {
  .layout { flex-direction: column; padding-bottom: 62px; }   /* room for the tab bar */
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; justify-content: space-between; border-right: none; border-bottom: 1px solid var(--line); }
  .sidebar nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 55;
    flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--bg); border-top: 1px solid var(--line);
    justify-content: space-around;
  }
  .sidebar nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 14px; flex: 1; text-align: center; align-items: center; }
  .sidebar nav .ico { font-size: 18px; width: auto; }
  .sidebar-foot { display: none; }
  .player-overlay { padding: 0; }
  .player-box { max-width: none; height: 100%; max-height: none; border-radius: 0; border: none; }
  .player-stage { flex: 1; aspect-ratio: auto; max-height: none; }
  .player-stage video { max-height: none; height: 100%; }
  .snap-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* Landscape phone: let the video own the screen */
@media (max-width: 950px) and (orientation: landscape) and (pointer: coarse) {
  .player-head { padding: 6px 12px; }
}

/* Live overlay: hide the player's built-in MSE/RTC mode badge (errors in
   .status stay visible) and label the prev/next camera buttons. */
.player-stage video-stream .mode { display: none; }
.live-hd { font-weight: 700; letter-spacing: .03em; }
.live-hd.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.live-nav { display: inline-flex; align-items: center; gap: 6px; max-width: 170px; }
.live-nav-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }

@media (max-width: 820px) {
  .live-nav { max-width: 110px; }   /* swipe is the primary gesture on touch */
}
