/* StellaLynx dashboard. Dark on purpose: it is read at night beside a telescope, so no bright panels and
   no pure white. System fonts only (no external assets: the CSP allows 'self' only). */
:root {
  --bg: #0b0d10;
  --panel: #13171c;
  --panel-2: #1a1f26;
  --line: #262d36;
  --text: #c3cad3;
  --muted: #7d8794;
  --accent: #5f8fb4;
  --accent-dim: #2b4256;
  --ok: #6fa28a;
  --warn: #c29a55;
  --radius: 6px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); }
a:hover { color: #86acc9; }
h1, h2, h3 { font-weight: 600; margin: 0 0 8px; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
code, pre, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace; font-size: 13px; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.ok { color: var(--ok); }
.hidden { display: none !important; }

button, .button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 12px;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover, .button:hover { border-color: var(--accent); color: var(--text); }
button.primary { background: var(--accent-dim); border-color: var(--accent); }
button.danger { color: var(--warn); border-color: var(--warn); }
button.danger:hover { color: var(--text); background: rgba(194, 154, 85, 0.15); }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 9px;
  font: inherit;
}

/* top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { color: var(--text); font-weight: 600; text-decoration: none; letter-spacing: 0.02em; }
.topbar nav { flex: 1; }
.topbar nav a { margin-right: 14px; }
.who { display: flex; align-items: center; gap: 10px; color: var(--muted); }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
section { margin-bottom: 28px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.error { color: var(--warn); min-height: 1.4em; margin: 6px 0 0; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: var(--panel); color: var(--muted); font-weight: 500; position: sticky; top: 0; }
tbody tr:hover { background: var(--panel-2); }
tr.link { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.empty { color: var(--muted); text-align: center; padding: 18px; }

/* login */
.auth { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; max-width: 820px; margin: 40px auto; }
.auth form { display: grid; gap: 10px; }
.auth label { display: grid; gap: 4px; color: var(--muted); }
.password-form { display: grid; gap: 10px; max-width: 360px; }
.password-form label { display: grid; gap: 4px; color: var(--muted); }
.password-form p { margin: 0; }
.password-form button { justify-self: start; }

/* dialog */
dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  max-width: 560px;
  width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.pair-code { font-size: 28px; letter-spacing: 0.12em; margin: 8px 0; }
.command { display: flex; gap: 8px; align-items: stretch; margin: 8px 0; }
.command code { flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 7px 9px; overflow-x: auto; white-space: nowrap; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* live session */
.session-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 22px; margin-bottom: 14px; }
.session-head h1 { margin: 0; }
.session-head .fact { color: var(--muted); }
.session-head .fact b { color: var(--text); font-weight: 500; }
.stream-status { margin-left: auto; color: var(--muted); }
.stream-status::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.stream-status.live::before { background: var(--ok); }
.stream-status.reconnecting::before { background: var(--warn); }

.live-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.preview { margin: 0; background: #000; border: 1px solid var(--line); border-radius: var(--radius); position: relative; min-height: 240px; display: flex; align-items: center; justify-content: center; }
.preview img { display: block; width: 100%; height: auto; max-height: 78vh; object-fit: contain; }
.preview-label {
  position: absolute; top: 8px; left: 8px;
  background: rgba(11, 13, 16, 0.8); color: var(--warn);
  border: 1px solid var(--warn); border-radius: 4px; padding: 2px 8px; font-size: 12px; letter-spacing: 0.04em;
}
.preview-note { position: absolute; bottom: 8px; left: 8px; font-size: 12px; color: var(--muted); background: rgba(11, 13, 16, 0.8); padding: 2px 6px; border-radius: 4px; }
.preview .placeholder { color: var(--muted); padding: 40px; }
.preview-links { margin-top: 8px; display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }

.counters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
.counter { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; margin: 0; }
.counter dt { color: var(--muted); font-size: 12px; }
.counter dd { margin: 2px 0 0; font-size: 18px; font-variant-numeric: tabular-nums; }
.counter.wide { grid-column: 1 / -1; }
.reasons { margin: 4px 0 0; padding-left: 18px; font-size: 12px; color: var(--muted); }

.snapshots { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.snapshot { padding: 4px; display: grid; gap: 2px; justify-items: center; flex: 0 0 auto; }
.snapshot img { width: 120px; height: 80px; object-fit: cover; background: #000; border-radius: 3px; }
.snapshot.active { border-color: var(--accent); }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
.compare figure { margin: 0; }
.compare img { width: 100%; height: auto; background: #000; border: 1px solid var(--line); border-radius: var(--radius); }
.compare figcaption { color: var(--muted); font-size: 12px; margin-top: 4px; }

.chart svg { width: 100%; max-width: 760px; height: auto; display: block; }
.chart .axis { stroke: var(--line); }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .series { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .ideal { fill: none; stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .dot { fill: var(--accent); }
.chart .dot.latest { fill: var(--ok); }

.thumb-pop {
  position: fixed; z-index: 20; pointer-events: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px;
}
.thumb-pop img { display: block; width: 280px; height: auto; background: #000; }

/* final stacks (M5-004): labelled FINAL in the "ok" colour, apart from the amber LIVE PREVIEW label */
select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 9px;
  font: inherit;
}
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
select option:disabled { color: var(--muted); }
.finals-group { margin-bottom: 14px; }
.finals-group h3 { color: var(--muted); font-weight: 500; }
.finals-list { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; }
.final-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; width: 320px; max-width: 100%; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
/* min-width 0: a long line in the expanded record must not widen the card's one grid track */
.final-card > *, .final-card details { min-width: 0; max-width: 100%; }
.final-thumb { display: block; position: relative; width: 100%; max-width: 100%; }
.final-thumb img { display: block; width: 100%; max-width: 100%; height: 190px; object-fit: contain; background: #000; border-radius: 3px; }
.final-label {
  position: absolute; top: 6px; left: 6px;
  background: rgba(11, 13, 16, 0.85); color: var(--ok);
  border: 1px solid var(--ok); border-radius: 4px; padding: 2px 8px; font-size: 12px; font-weight: 600; letter-spacing: 0.06em;
}
.final-facts { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; font-size: 13px; }
.final-facts dt { color: var(--muted); }
.final-facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.final-links { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; }
.final-card details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.final-card details pre { box-sizing: border-box; width: 100%; max-width: 100%; max-height: 320px; overflow: auto; white-space: pre; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; font-size: 12px; margin: 6px 0 0; }
.integration-jobs { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.integration-jobs li { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; }
.integration-jobs li.failed { border-color: var(--warn); color: var(--warn); }
.integrate-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 14px; align-items: end; max-width: 1000px; margin-top: 12px; }
.integrate-form h3, .integrate-form .form-wide, .integrate-form .form-actions { grid-column: 1 / -1; }
.integrate-form h3 { margin: 0; }
.integrate-form label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.integrate-form .form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.integrate-form .error { margin: 0; }

/* calibration library (M5-005) */
.topbar nav a[aria-current="page"] { color: var(--text); text-decoration: none; }
.upload-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 14px; align-items: end; max-width: 1000px; }
.upload-form label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.upload-form .form-wide, .upload-form .form-actions { grid-column: 1 / -1; }
.upload-form .form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.upload-form .error { margin: 0; }
.upload-form input[type="file"] { padding: 5px; }
.masters-camera { margin-bottom: 18px; }
.masters-type { margin: 0 0 12px; }
.masters-type h4 { color: var(--muted); font-weight: 500; font-size: 13px; margin: 0 0 6px; }
input.toggle { width: auto; margin: 0; accent-color: var(--accent); }

details.data pre { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; overflow-x: auto; }
details.data summary { cursor: pointer; color: var(--muted); }

@media (max-width: 1000px) {
  .live-grid { grid-template-columns: 1fr; }
  .counters { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 800px) {
  main { padding: 12px; }
  .topbar { flex-wrap: wrap; padding: 10px 12px; }
  .auth { grid-template-columns: 1fr; margin: 16px auto; }
  .counters { grid-template-columns: 1fr 1fr; }
  .compare { grid-template-columns: 1fr; }
  .stream-status { margin-left: 0; }
}
