/* 4GPAQS VI. One stylesheet, no framework, no build step (DR-007).

   Design target: a MacBook Air at 1440 x 900 (UI-SPEC 3). Below it the layout
   degrades in a fixed order and never collapses: the header wraps, forms
   stack, and only then does the page scroll. Nothing becomes unreachable.

   Colour is never the only signal (UI-SPEC 12): current tab is also
   underlined, errors also say "error", required fields also say so. */

:root {
  --bg: #fbfbf9;
  --fg: #1d1f21;
  --muted: #5f6368;
  --line: #d9d9d4;
  --panel: #ffffff;
  --accent: #1f5f99;
  --accent-fg: #ffffff;
  --error: #a4262c;
  --error-bg: #fdecea;
  --notice-bg: #e8f1fa;
  --focus: #e8a200;
  --err: rgba(31, 95, 153, 0.18);
  --sky: #b07a2a;
  --sed: #c2410c;   /* photometry points and the spectrum-scale slider */
  --tpl: #0e7c86;   /* the template overlay */
  --telluric: rgba(120, 120, 120, 0.12);
  --arm-B: rgba(60, 110, 220, 0.05);
  --arm-G: rgba(40, 160, 90, 0.05);
  --arm-R: rgba(210, 60, 50, 0.05);
  --pressed: #dce9f6;
  --danger: #a4262c;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #16181b;
  --fg: #e6e6e3;
  --muted: #a0a4a8;
  --line: #34383d;
  --panel: #1e2125;
  --accent: #6aa7e0;
  --accent-fg: #0d1014;
  --error: #ff8a80;
  --error-bg: #3a1f1f;
  --notice-bg: #1d2b3a;
  --err: rgba(106, 167, 224, 0.22);
  --sky: #d9a453;
  --sed: #fb923c;
  --tpl: #2dd4bf;
  --telluric: rgba(200, 200, 200, 0.10);
  --arm-B: rgba(90, 140, 255, 0.07);
  --arm-G: rgba(80, 200, 120, 0.06);
  --arm-R: rgba(255, 110, 100, 0.06);
  --pressed: #24415f;
  --danger: #ff8a80;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 15px/1.45 var(--sans); }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--muted); }
h1 { font-size: 1.35rem; margin: 0 0 0.8rem; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 0.6rem; }
h2.first { margin-top: 0; }
.spaced { margin-top: 1rem; }
/* No style="" attributes anywhere: the Content-Security-Policy refuses them,
   as it refuses inline script. Everything visual lives in this file. */

/* --- the header: 44 px at the design size (UI-SPEC 3) ------------------- */

.app-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.9rem;
  min-height: 44px; padding: 0 0.9rem;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; text-decoration: none; color: var(--fg); }
.tabs { display: flex; gap: 0.2rem; }
.tabs a {
  padding: 0.55rem 0.7rem; text-decoration: none; color: var(--muted);
  border-bottom: 3px solid transparent;
}
.tabs a.current { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }
.spacer { flex: 1; }
.who { color: var(--muted); }
.inline { display: inline; margin: 0; }
.icon-button, .link-button {
  font: inherit; background: none; border: 1px solid var(--line); color: var(--fg);
  border-radius: 4px; padding: 0.2rem 0.55rem; cursor: pointer; text-decoration: none;
}
.link-button { border-color: transparent; color: var(--accent); }

.burger { position: relative; }
.burger summary {
  list-style: none; cursor: pointer; font-size: 1.2rem; padding: 0.2rem 0.4rem;
  border: 1px solid var(--line); border-radius: 4px;
}
.burger summary::-webkit-details-marker { display: none; }
.burger-panel {
  position: absolute; top: 2.4rem; left: 0; z-index: 10; width: 22rem; max-height: 70vh;
  overflow: auto; padding: 0.8rem; background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.15);
}

/* --- pages ---------------------------------------------------------------- */

.page { max-width: 72rem; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.narrow { max-width: 26rem; margin: 8vh auto; padding: 0 1rem; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 1rem 1.2rem;
}
.notice { background: var(--notice-bg); padding: 0.6rem 0.9rem; border-radius: 4px; }
.error {
  background: var(--error-bg); color: var(--error); padding: 0.6rem 0.9rem;
  border-radius: 4px; border-left: 4px solid var(--error);
}
.field-error { color: var(--error); font-size: 0.9em; }
.stats { display: flex; flex-wrap: wrap; gap: 1rem; }
.stat { min-width: 10rem; }
.stat .n { font-size: 1.8rem; font-weight: 600; }

/* --- forms: labels above fields, one column, stacking on narrow windows -- */

form.stacked label { display: block; margin: 0.8rem 0 0.25rem; font-weight: 500; }
form.stacked input[type=text], form.stacked input[type=password],
form.stacked input[type=email], form.stacked input[type=number] {
  width: 100%; padding: 0.45rem 0.55rem; font: inherit; color: var(--fg);
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px;
}
.checks { display: flex; flex-wrap: wrap; gap: 0.4rem 1.2rem; margin: 0.6rem 0; }
.checks label { display: flex; align-items: center; gap: 0.35rem; font-weight: normal; margin: 0; }
.button {
  display: inline-block; font: inherit; font-weight: 600; cursor: pointer;
  padding: 0.5rem 1rem; margin-top: 1rem; border-radius: 4px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-fg); text-decoration: none;
}
.button.secondary { background: none; color: var(--accent); }
.hint { color: var(--muted); font-size: 0.9em; margin: 0.2rem 0 0; }

/* --- tables --------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; background: var(--panel); }
table.data th, table.data td {
  text-align: left; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data th { font-weight: 600; color: var(--muted); font-size: 0.9em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tag {
  display: inline-block; font-size: 0.8em; padding: 0 0.4rem; border-radius: 3px;
  border: 1px solid var(--line); margin-right: 0.2rem;
}

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

.admin { display: grid; grid-template-columns: 11rem 1fr; gap: 1.5rem; }
.admin-nav a { display: block; padding: 0.35rem 0.5rem; text-decoration: none; border-radius: 4px; }
.admin-nav a.current { background: var(--notice-bg); font-weight: 600; }
.reset-link { font-family: var(--mono); word-break: break-all; padding: 0.7rem;
  background: var(--bg); border: 1px dashed var(--line); user-select: all; }
pre.report { font-family: var(--mono); font-size: 0.85em; white-space: pre-wrap;
  background: var(--panel); border: 1px solid var(--line); padding: 1rem; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

kbd {
  font-family: var(--mono); font-size: 0.85em; padding: 0.05rem 0.35rem;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px;
}

/* Below the design width: the admin menu goes above the content. */
@media (max-width: 900px) {
  .admin { grid-template-columns: 1fr; }
  .admin-nav { display: flex; flex-wrap: wrap; gap: 0.3rem; }
}

/* --- home: the batch ------------------------------------------------------ */

.batch-request { display: flex; flex-wrap: wrap; align-items: end; gap: 0.6rem; }
.batch-request label { display: block; font-weight: 500; }
.batch-request input { width: 6rem; padding: 0.45rem; font: inherit; color: var(--fg);
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px; }
.batch-request .button { margin-top: 0; }
.button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.batch-list { margin: 0; padding-left: 1.4rem; }
.batch-list li { padding: 0.1rem 0; }
.batch-list li.current a { font-weight: 700; }
.batch-list li.state-graded a { text-decoration: line-through; color: var(--muted); }

/* --- S3: the inspection screen (UI-SPEC 3) --------------------------------
   Two columns at the design size. Below it, in this order: the right column
   narrows, the flag grid drops to three columns, and only then does the page
   scroll. The plot is what gives way vertically, never a control. */

main.inspect { max-width: none; padding: 0.5rem 0.8rem; }
#inspect { display: grid; grid-template-columns: minmax(0, 1fr) 21rem; gap: 0.9rem;
  height: calc(100vh - 44px - 1rem); min-height: 640px; }
#inspect .left { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.obj-header { display: flex; justify-content: space-between; align-items: center;
  gap: 0.6rem; min-height: 40px; }
.obj-actions { display: flex; gap: 0.5rem; align-items: center; }
.plot-wrap { position: relative; flex: 1 1 auto; min-height: 260px;
  border: 1px solid var(--line); border-radius: 4px; background: var(--panel); }
#plot { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
/* Vertical scale sliders right of the plot area (inside the canvas margin). */
.sliders { position: absolute; right: 2px; width: 52px; display: flex; gap: 2px; justify-content: center; }
.sliders label { display: flex; flex-direction: column; align-items: center; height: 100%; font-size: 0.7em;
  color: var(--muted); }
.sliders input[type="range"] { writing-mode: vertical-lr; direction: rtl; flex: 1 1 auto; width: 18px;
  margin: 0; accent-color: var(--sed); }
#k-tpl { accent-color: var(--tpl); }
.tpl-pick { font-size: 0.85em; color: var(--muted); }
.tpl-pick select { font: inherit; color: var(--fg); background: var(--bg); max-width: 15rem; }
/* Follows the pointer just under the x axis, over the tick labels. */
.readout { position: absolute; transform: translateX(-50%); font-size: 0.78em; color: var(--fg);
  background: var(--panel); border: 1px solid var(--line); border-radius: 3px; padding: 0 0.3rem;
  white-space: nowrap; pointer-events: none; z-index: 2; }
.identify { position: absolute; z-index: 5; width: 220px; max-height: 260px; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 0.4rem; box-shadow: 0 6px 18px rgba(0,0,0,.18); }
.identify ul { list-style: none; margin: 0; padding: 0; }
.identify button { width: 100%; text-align: left; margin: 1px 0; }
.plot-controls { display: flex; flex-wrap: wrap; gap: 0.3rem 0.8rem; align-items: center;
  min-height: 32px; padding: 0.3rem 0; font-size: 0.9em; }
button.small { font: inherit; font-size: 0.85em; padding: 0.1rem 0.45rem; cursor: pointer;
  background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 3px; }
button.small[aria-pressed="true"], button.flag[aria-pressed="true"],
button.grade[aria-pressed="true"] { background: var(--pressed); border-color: var(--accent);
  font-weight: 600; }
button.small:disabled { opacity: 0.5; cursor: default; }
.lists button { margin-right: 0.2rem; }
fieldset.flags { border: none; margin: 0; padding: 0; }
fieldset.flags legend { font-size: 0.85em; color: var(--muted); padding: 0; }
.flag-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.25rem; }
button.flag { font: inherit; font-size: 0.82em; text-align: left; padding: 0.3rem 0.4rem;
  background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 3px;
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
button.flag[aria-pressed="true"]::after { content: " \2713"; }  /* not colour alone */
.comment-label { font-size: 0.85em; color: var(--muted); margin-top: 0.4rem; }
#comment { width: 100%; padding: 0.4rem; font: inherit; color: var(--fg);
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px; }

#inspect .right { display: flex; flex-direction: column; gap: 0.5rem; min-height: 0; overflow: auto; }
.tabs-row { display: flex; gap: 0.2rem; }
.tabs-row button { font: inherit; font-size: 0.9em; padding: 0.3rem 0.6rem; cursor: pointer;
  background: none; color: var(--muted); border: none; border-bottom: 3px solid transparent; }
.tabs-row button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { font-size: 0.9em; }
#cutout-pick { font: inherit; padding: 0.2rem; margin-bottom: 0.3rem; }
/* The pipeline's PNG is 480 px wide and carries its own labels; the column
   is narrower, so the browser scales it down. */
img.cutout { display: block; width: 100%; height: auto; background: #3a3a3a; }
.cutout-figure { max-width: 24rem; margin: 0 0 1rem; }
#cutout-cap, .cutout-info { margin: 0.3rem 0; font-size: 0.85em; }
.tab-panel .kv { font-size: 0.95em; }
button.alt { display: block; width: 100%; text-align: left; margin: 2px 0; }
.answer { border-top: 1px solid var(--line); padding-top: 0.5rem; }
.answer h3 { font-size: 0.9rem; margin: 0 0 0.4rem; text-transform: uppercase; color: var(--muted); }
.z-row { display: flex; gap: 0.4rem; align-items: center; }
.z-nudge { display: inline-flex; flex-direction: column; gap: 1px; }
.z-nudge button { padding: 0 0.35rem; line-height: 1.05; font-size: 0.7em; }
#z { width: 7.5rem; padding: 0.35rem; font-size: 1.05rem; color: var(--fg);
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px; }
#z-slider { width: 100%; margin: 0.5rem 0 0.2rem; }
.steps { font-size: 0.85em; color: var(--muted); }
.grade-row { display: flex; gap: 0.3rem; align-items: center; margin-top: 0.6rem; flex-wrap: wrap; }
button.grade { font: inherit; font-weight: 600; width: 2.2rem; height: 2.2rem; cursor: pointer;
  border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: var(--fg); }
.button.wide { display: block; width: 100%; margin-top: 0.5rem; }
.button:disabled { opacity: 0.45; cursor: default; }
.message { background: var(--error-bg); color: var(--error); padding: 0.45rem 0.6rem;
  border-radius: 4px; border-left: 4px solid var(--error); font-size: 0.9em; }
.undo { margin-top: 0.5rem; font-size: 0.9em; }
.help-overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  background: rgba(0,0,0,.35); }
.help-overlay .card { max-width: 34rem; max-height: 85vh; overflow: auto; }
[hidden] { display: none !important; }

@media (max-width: 1280px) {
  #inspect { grid-template-columns: minmax(0, 1fr) 18rem; }
  .flag-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px), (max-height: 700px) {
  #inspect { grid-template-columns: 1fr; height: auto; }
  .plot-wrap { min-height: 320px; }
}

/* --- review ---------------------------------------------------------------- */

.filters { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: end; margin: 0.8rem 0; }
.filters label { display: flex; flex-direction: column; font-size: 0.85em; color: var(--muted); }
.filters select, .filters input { font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 4px; padding: 0.3rem; }
.filters .button { margin-top: 0; }
.plot-figure { margin: 0 0 1rem; padding: 0.5rem; }
svg.spectrum { width: 100%; height: auto; color: var(--fg); display: block; }
.zoom { font-size: 0.85em; color: var(--muted); display: flex; gap: 0.4rem; align-items: center; }
.zoom input, input.short { width: 6rem; padding: 0.2rem; font: inherit; color: var(--fg);
  background: var(--bg); border: 1px solid var(--line); border-radius: 3px; }
.zoom .button { margin-top: 0; padding: 0.2rem 0.6rem; }
.signoff fieldset { border: 1px solid var(--line); border-radius: 4px; margin: 0.8rem 0; padding: 0.4rem 0.8rem; }
.signoff fieldset label { display: block; font-weight: normal; margin: 0.25rem 0; }
.signoff select { font: inherit; padding: 0.3rem; }
.swatch-0 { color: #0072B2; } .swatch-1 { color: #D55E00; } .swatch-2 { color: #009E73; }
.swatch-3 { color: #CC79A7; } .swatch-4 { color: #E69F00; } .swatch-5 { color: #56B4E9; }

/* --- my grades ------------------------------------------------------------- */

.filters label.check { flex-direction: row; align-items: center; gap: 0.3rem; color: var(--fg); }
svg.spark { color: var(--muted); display: block; }
table.history td { vertical-align: middle; }
.pager { display: flex; gap: 1.5rem; }
.readonly-note { border: 1px dashed var(--line); border-radius: 4px; padding: 0.5rem; margin: 0.5rem 0; }
.readonly-note p { margin: 0 0 0.4rem; font-size: 0.9em; }
.readonly-note .button { margin-top: 0; }
.readonly-actions { margin-top: 1rem; }
.retract { margin-top: 0.8rem; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: end; }
.retract label { flex-basis: 100%; }
.retract input { flex: 1; min-width: 16rem; padding: 0.4rem; font: inherit; color: var(--fg);
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px; }
.retract .button { margin-top: 0; }

.small-hash { font-size: 0.8em; }
form.stacked select[multiple] { width: 100%; font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 4px; }
form.stacked input[type=date] { font: inherit; padding: 0.35rem; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 4px; }
.small-link { font-size: 0.85em; }

/* --- progress -------------------------------------------------------------- */
.band { margin-bottom: 1.2rem; }
.band h3 { font-size: 0.95rem; margin: 1rem 0 0.3rem; }
svg.bars { width: 100%; max-width: 720px; height: auto; color: var(--fg); display: block; }

/* The object browser (/browse) */
.search-row { display: flex; gap: 0.5rem; margin: 0.8rem 0 0.2rem; max-width: 52rem; }
.search-row input[type="search"] { flex: 1; font: inherit; padding: 0.4rem 0.5rem; color: var(--fg);
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.nowrap { white-space: nowrap; }
table.browse td { font-size: 0.9em; }
.tag.warn { background: #fde7d3; color: #7a3300; }
[data-theme="dark"] .tag.warn { background: #5a2e0e; color: #ffd9b8; }
