/* Light theme.
 *
 * Accent colours are NOT the dark-theme values reused. Those were tuned for
 * contrast against #0f1216 and several fail WCAG AA on white -- the amber in
 * particular sat around 3.4:1 as body text. Each is darkened here to clear
 * 4.5:1 against the panel background while staying recognisably the same hue,
 * so status colours mean the same thing they did before.
 *
 * Depth comes from soft shadows rather than borders alone: on a light ground,
 * borders everywhere read as heavy and gridded.
 */

:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --line: #dde2e8;
  --line-strong: #c8d0d9;

  --text: #16202b;
  --muted: #5c6b7a;          /* 5.6:1 on white */

  --accent: #1d4ed8;         /* 7.0:1 */
  --ok: #0f7a4a;             /* 4.9:1 */
  --warn: #9a5b06;           /* 5.4:1 */
  --err: #c0272d;            /* 5.4:1 */

  --ok-soft: #e7f5ee;
  --warn-soft: #fdf3e2;
  --err-soft: #fdeaea;
  --accent-soft: #e8eefc;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .07);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* The header carries a title, group picker, status, six tabs and an account
   block. Everything that must not break mid-word is nowrap; the nav is allowed
   to fall onto its own row rather than squeezing the rest. */
header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
header h1 {
  font-size: 16px; margin: 0; font-weight: 600; letter-spacing: .2px;
  white-space: nowrap;
}
header h1 .v { color: var(--muted); font-weight: 400; }
/* The title is a link home now that each feature is its own page. */
header h1 a { color: inherit; text-decoration: none; }
header h1 a:hover { color: var(--accent); }
header nav { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
header #area-select { max-width: 260px; }
header #live-label { white-space: nowrap; }

@media (max-width: 1100px) {
  /* Nav takes a full row; the account block stays pinned right on row one. */
  header nav { order: 3; flex-basis: 100%; margin-left: 0; }
  header .account { margin-left: auto; }
}

/* Tabs are anchors, not buttons: each feature is a real page with a real URL,
   so they must be middle-clickable, bookmarkable and openable in a new tab.
   inline-block and text-decoration are what an <a> needs that a <button> did
   not. */
.tab {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 6px 14px; border-radius: var(--radius); cursor: pointer; font-size: 13px;
  white-space: nowrap;
  display: inline-block; text-decoration: none; line-height: 1.4;
  font-family: inherit;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.active { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 500; }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px;
           color: var(--muted); margin: 0 0 12px; font-weight: 600; }

.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.stat { text-align: center; }
.stat-value { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11px;
     text-transform: uppercase; letter-spacing: .5px; padding: 6px 10px 6px 0;
     border-bottom: 1px solid var(--line-strong); }
td { padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line);
     font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }

/* Free is deliberately quiet and occupied is loud, so a wall of tiles can be
   scanned for the few in use rather than read one by one. Red for occupied
   follows the convention of every seat-booking and availability board: green
   free, red taken.

   Colour is never the only signal -- red/green is the worst pair for colour
   blindness. Each tile also carries a text badge, a heavier border and a
   different background weight, so it survives greyscale and a mono display. */
.zone {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px;
  border-left: 3px solid var(--line-strong);
}
.zone-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.zone-name { font-weight: 600; }
.zone-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }

.zone.occupied {
  border-left: 5px solid var(--err);
  border-color: var(--err);
  background: var(--err-soft);
}
.zone.occupied .zone-name { color: var(--err); }
.zone.occupied .zone-meta { color: var(--err); opacity: .85; }

.zone-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  padding: 2px 7px; border-radius: 999px; white-space: nowrap;
  background: var(--panel); border: 1px solid var(--line-strong); color: var(--muted);
}
.zone.occupied .zone-badge {
  background: var(--err); border-color: var(--err); color: #fff;
}

/* Applied when the pipeline heartbeat is stale, so nothing on screen reads as
   a current measurement when it is actually the last known state. */
.stale { opacity: .45; }
.stale .stat-value { color: var(--muted); }

#stale-banner { margin-bottom: 16px; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong);
       display: inline-block; }
.dot.live { background: var(--ok); }
.dot.stalled { background: var(--err); }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px;
        background: var(--panel-2); border: 1px solid var(--line-strong); color: var(--muted); }
.pill.live { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.pill.stalled { color: var(--err); border-color: var(--err); background: var(--err-soft); }
.pill.owner { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

button, select, input {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 7px 12px; font: inherit;
}
button { cursor: pointer; box-shadow: var(--shadow); }
button:hover { border-color: var(--accent); color: var(--accent); }
button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
button.secondary { color: var(--muted); box-shadow: none; background: var(--panel-2); }
button.secondary:hover { color: var(--accent); }
button.warn { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }
button.danger { border-color: var(--err); color: var(--err); background: var(--err-soft); }
button:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar label { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.sep { width: 1px; height: 22px; background: var(--line-strong); }

.canvas-wrap { position: relative; display: inline-block; max-width: 100%; }
.canvas-wrap img { display: block; max-width: 100%; border-radius: 8px; border: 1px solid var(--line); }
.canvas-wrap canvas { position: absolute; inset: 0; cursor: crosshair; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--err); padding: 12px; border: 1px solid var(--err);
         border-radius: 8px; background: var(--err-soft); }

dialog {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; min-width: 380px; box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(16, 24, 40, .35); }
dialog h2 { margin-top: 0; font-size: 15px; }
dialog label { display: block; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
dialog input, dialog select { width: 100%; margin-top: 4px; }
dialog .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
dialog menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; margin: 16px 0 0; }

.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 100;
  background: var(--panel); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  padding: 12px 16px; border-radius: 8px; max-width: 460px;
  box-shadow: var(--shadow-lg);
}
.toast.err { border-left-color: var(--err); background: var(--err-soft); }
.toast.ok  { border-left-color: var(--ok);  background: var(--ok-soft); }

/* -- auth ---------------------------------------------------------------- */

body.centered, .centered {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card { width: 100%; max-width: 380px; margin: 0; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card h1 .v { color: var(--muted); font-weight: 400; }
.login-card label { display: block; margin: 16px 0 0; font-size: 12px; color: var(--muted); }
.login-card input { width: 100%; margin-top: 4px; }
.login-card button[type="submit"] { width: 100%; margin-top: 20px;
  background: var(--accent); color: #fff; border-color: var(--accent); }
.login-card button[type="submit"]:hover:not(:disabled) { filter: brightness(1.1); color: #fff; }
.login-card .error { margin-top: 16px; }

header .account {
  display: flex; align-items: center; gap: 10px; margin-left: 16px;
  padding-left: 16px; border-left: 1px solid var(--line);
  white-space: nowrap;      /* "Sign out" must never break across two lines */
}
header .account #who { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

/* -- live view ----------------------------------------------------------- */

.live-wrap {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  min-height: 300px; display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.live-wrap img { max-width: 100%; display: block; }

/* The zone overlay sits on the stream. pointer-events:none so it never
   intercepts clicks -- unlike the Zone Editor canvas, this one is read-only. */
.live-stage { position: relative; display: inline-block; line-height: 0; }
.live-stage canvas { position: absolute; inset: 0; pointer-events: none; }
.placeholder { color: var(--muted); font-size: 13px; padding: 60px 20px; }

/* -- admin forms --------------------------------------------------------- */

.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px;
}
.form-grid label { font-size: 12px; color: var(--muted); display: block; }
.form-grid input, .form-grid select { width: 100%; margin-top: 4px; }
.form-grid .wide { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; }

.notice {
  margin-top: 14px; padding: 12px 14px; border-radius: 8px;
  background: var(--accent-soft); border: 1px solid var(--accent);
}
.notice code {
  background: var(--panel); padding: 2px 6px; border-radius: 4px;
  font-size: 13px; user-select: all;   /* one click selects the whole password */
}

/* Legend swatches in the Zone Editor. */
.swatch {
  display: inline-block; width: 10px; height: 10px; border-radius: 2px;
  margin: 0 3px 0 10px; vertical-align: middle;
}
.swatch:first-child { margin-left: 0; }

/* A disabled camera is still listed -- it has to be, or it could never be
   re-enabled -- but it must not read as part of the running pipeline. */
.disabled-row { opacity: .55; }
.disabled-row td:first-child { text-decoration: line-through; }

td.actions { white-space: nowrap; }
td.actions button { margin-left: 4px; }

#edit-dialog input { width: 100%; }
