/* Chart-room look: chart paper, ink navy, brass. System fonts only (no external requests). */
:root {
  --paper: #e6ebea;
  --paper-2: #f5f7f6;
  --ink: #0e2233;
  --ink-2: #17364d;
  --ink-3: #21506f;
  --harbour: #1c5b6b;
  --brass: #b98b2e;
  --brass-2: #d9ad4e;
  --red: #b83a25;
  --green: #2a8555;
  --amber: #c78a1b;
  --line: #c3cdcb;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
}
[hidden] { display: none !important; }
a { color: var(--harbour); }
:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; }

/* ---------- top bar ---------- */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 4vw, 32px);
  background: var(--ink); color: var(--paper);
  border-bottom: 3px solid var(--brass);
}
.brand { font: 600 1.35rem/1.2 var(--serif); color: var(--paper); text-decoration: none; letter-spacing: .01em; }
.bar nav { display: flex; align-items: center; gap: 18px; font-size: .95rem; }
.bar nav a { color: var(--brass-2); text-decoration: none; }
.bar nav a:hover { text-decoration: underline; }
.who { color: #b9c7d0; }
.link {
  background: none; border: 0; padding: 4px 0; color: var(--paper); font: inherit; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px; white-space: nowrap;
}
@media (max-width: 560px) { .who { display: none; } .brand { font-size: 1.15rem; } }

main { padding: clamp(16px, 3vw, 28px) clamp(16px, 4vw, 32px) 48px; max-width: 1700px; margin: 0 auto; }

/* ---------- camera grid ---------- */
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
@media (min-width: 760px) { .tile.wide { grid-column: span 2; } }
/* With three or more columns the PTZ tile takes a 2x2 block and small tiles sit beside it. */
@media (min-width: 1000px) {
  .tile.wide { grid-row: span 2; }
  .tile.wide .screen { aspect-ratio: auto; flex: 1 1 auto; min-height: 240px; }
}

.tile {
  display: flex; flex-direction: column; color: inherit; text-decoration: none;
  background: var(--paper-2); border: 1px solid var(--line); border-radius: 4px; overflow: hidden;
}
.tile:hover { border-color: var(--ink-3); }
.screen { position: relative; aspect-ratio: 16 / 9; background: #06121b; }
.screen video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #06121b; }
.veil {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 12px; text-align: center;
  color: #9db3c1; font-size: .95rem; background: rgba(6, 18, 27, .72); pointer-events: none;
}
.veil.bad { color: #f0b3a8; }
.caption { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.caption .name { font: 600 1.05rem/1.2 var(--serif); flex: 1; }
.caption .tag { font-size: .8rem; color: var(--paper-2); background: var(--harbour); padding: 2px 8px; border-radius: 3px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--amber); flex: none; }
.dot.live { background: var(--green); }
.dot.bad { background: var(--red); }

.empty { padding: 48px 0; text-align: center; color: #4a6272; }

/* ---------- camera page ---------- */
.crumbs { display: flex; align-items: baseline; gap: 14px; margin: 0 0 14px; flex-wrap: wrap; }
.crumbs h1 { margin: 0; font: 600 1.6rem/1.2 var(--serif); }
.crumbs a { font-size: .95rem; }
.stage { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 980px) { .stage.has-console { grid-template-columns: minmax(0, 1fr) 340px; } }
/* On a phone the picture stays pinned to the top while you use the controls below it. */
@media (max-width: 979px) {
  .stage.has-console > div:first-child { position: sticky; top: 0; z-index: 5; background: var(--paper); padding-bottom: 10px; }
  .stage.has-console .viewer .screen { max-height: 34vh; }
  .viewer-tools { padding: 6px 8px; }
  .viewer-tools .btn, .seg button { padding: 5px 10px; font-size: .85rem; }
}

.viewer { background: #000; border-radius: 4px; overflow: hidden; }
.viewer .screen { max-height: 78vh; }
.viewer-tools {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; background: var(--paper-2); border: 1px solid var(--line); border-top: 0;
}
.viewer-tools .spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--ink-3); border-radius: 4px; overflow: hidden; }
.seg button { border: 0; background: transparent; color: var(--ink); padding: 6px 12px; font: inherit; font-size: .9rem; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.btn {
  border: 1px solid var(--ink-3); background: var(--paper-2); color: var(--ink);
  padding: 7px 14px; font: inherit; font-size: .92rem; border-radius: 4px; cursor: pointer;
}
.btn:hover { background: #fff; }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.primary:hover { background: var(--ink-2); }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- PTZ console ---------- */
.console { background: var(--ink); color: var(--paper); border-radius: 4px; padding: 18px; border-top: 3px solid var(--brass); }
.console h2 { margin: 0 0 4px; font: 600 1.15rem/1.3 var(--serif); }
.console .status { min-height: 3.1em; margin: 0 0 12px; color: #b9c7d0; font-size: .92rem; }
.console .status strong { color: var(--paper); }
.console .actions { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.console .btn { background: var(--ink-2); color: var(--paper); border-color: var(--ink-3); }
.console .btn:hover { background: var(--ink-3); }
.console .btn.primary { background: var(--brass); border-color: var(--brass); color: var(--ink); font-weight: 600; }
.console .btn.primary:hover { background: var(--brass-2); }

.compass { display: block; width: 100%; max-width: 290px; margin: 0 auto 6px; touch-action: none; user-select: none; -webkit-user-select: none; }
.compass .tick { stroke: var(--brass); stroke-width: 1; opacity: .8; }
.compass .tick.major { stroke-width: 2.2; opacity: 1; }
.compass .wedge { cursor: pointer; touch-action: none; -webkit-touch-callout: none; }
.compass .wedge path { fill: var(--ink-2); transition: fill .08s; }
.compass .wedge polygon { fill: #8fb0c4; pointer-events: none; }
.compass .wedge:hover path { fill: var(--ink-3); }
.compass .wedge.held path { fill: var(--brass); }
.compass .wedge.held polygon { fill: var(--ink); }
.compass .hub { fill: var(--ink); stroke: var(--brass); stroke-width: 2; }
.compass .hub-num { fill: var(--paper); font: 600 26px var(--serif); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.compass .hub-cap { fill: #8fb0c4; font: 500 9.5px var(--sans); text-anchor: middle; pointer-events: none; }
.console.locked .wedge { opacity: .35; cursor: not-allowed; }

.zoomrow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 16px; }
.zoomrow button {
  padding: 12px 8px; font: 600 1rem var(--sans); color: var(--paper); background: var(--ink-2);
  border: 1px solid var(--ink-3); border-radius: 4px; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none;
}
.zoomrow button.held { background: var(--brass); color: var(--ink); border-color: var(--brass); }
.console.locked .zoomrow button { opacity: .35; cursor: not-allowed; }

.speed { margin-bottom: 16px; }
.speed label { display: flex; justify-content: space-between; font-size: .9rem; color: #b9c7d0; margin-bottom: 4px; }
.speed input { width: 100%; accent-color: var(--brass); }
.speed small { display: block; color: #8fa5b4; margin-top: 2px; font-size: .8rem; }

.scan { margin: 14px 0; }
.scan .btn { width: 100%; }
.presets h3 { margin: 0 0 8px; font: 600 .95rem var(--sans); color: #b9c7d0; }
.presets .list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.presets button {
  padding: 10px 8px; font: inherit; font-size: .92rem; color: var(--paper); background: var(--ink-2);
  border: 1px solid var(--ink-3); border-radius: 4px; cursor: pointer; text-align: left;
}
.presets button:hover { background: var(--ink-3); }
.console.locked .presets button { opacity: .35; cursor: not-allowed; }
.console .note { margin: 14px 0 0; font-size: .82rem; color: #8fa5b4; }
.readonly { padding: 16px; background: var(--paper-2); border: 1px solid var(--line); border-radius: 4px; }
.readonly h2 { margin: 0 0 6px; font: 600 1.1rem var(--serif); }
.readonly p { margin: 0; color: #4a6272; }

/* ---------- sign in ---------- */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.card { width: 100%; max-width: 380px; background: var(--paper-2); border: 1px solid var(--line); border-top: 4px solid var(--brass); border-radius: 4px; padding: 28px; }
.card svg { display: block; width: 64px; height: 64px; margin: 0 auto 10px; }
.card h1 { margin: 0 0 4px; text-align: center; font: 600 1.6rem/1.2 var(--serif); }
.card p.sub { margin: 0 0 22px; text-align: center; color: #4a6272; }
.card label { display: block; margin: 0 0 4px; font-size: .92rem; font-weight: 600; }
.card input {
  width: 100%; padding: 11px 12px; margin-bottom: 16px; font: inherit; color: var(--ink);
  background: #fff; border: 1px solid #9fb0ad; border-radius: 4px;
}
.card input:focus-visible { outline: 3px solid var(--brass); outline-offset: 1px; border-color: var(--ink-3); }
.card .btn { width: 100%; padding: 12px; font-size: 1rem; }
.error { min-height: 1.4em; margin: 0 0 10px; color: var(--red); font-size: .93rem; }

/* ---------- admin ---------- */
.panel { background: var(--paper-2); border: 1px solid var(--line); border-radius: 4px; padding: 16px; margin-bottom: 20px; overflow-x: auto; }
.panel h2 { margin: 0 0 10px; font: 600 1.2rem var(--serif); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: #4a6272; }
td.err { color: #6b3a30; max-width: 380px; overflow-wrap: anywhere; }
pre.log { margin: 0; max-height: 320px; overflow: auto; font: .82rem/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; }
.help { color: #4a6272; font-size: .92rem; margin: 0; }
.help code { background: #dbe3e1; padding: 1px 5px; border-radius: 3px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
