/*
 * Dashboard styles.
 *
 * ---------------------------------------------------------------------------------------------
 * CONSTRAINTS IMPOSED BY THE CSP, AND WHY THEY SHOW UP HERE
 * ---------------------------------------------------------------------------------------------
 * The response policy is `default-src 'none'` with `style-src 'nonce-...'`. Three consequences for
 * this file:
 *
 *   1. No `@import` of a remote stylesheet, no remote `url()`. `font-src` and `img-src` are `'self'`
 *      plus `data:` for images, so a typeface or an icon fetched from a CDN would be blocked. The
 *      font stack below is therefore system fonts only, and there are no background images.
 *
 *   2. No inline `style` attribute in the markup. Every visual state is a class, which is why the
 *      JavaScript sets `className` and `hidden` rather than assigning to `element.style`.
 *
 *   3. No CSS that could be used to exfiltrate a value through a selector. The policy refuses
 *      `unsafe-inline` for styles precisely because `input[value^="a"] { background: url(...) }`
 *      leaks attribute contents one character at a time. Nothing here uses an attribute selector on
 *      a value-bearing attribute.
 *
 * ---------------------------------------------------------------------------------------------
 * WHY THERE IS NO FRAMEWORK AND NO BUILD STEP
 * ---------------------------------------------------------------------------------------------
 * The brief requires zero runtime dependencies and no build tooling. That is a supply-chain decision
 * as much as a simplicity one: every dependency is a signed artefact someone else controls, and this
 * file has to be readable by whoever audits the CSP.
 */

:root {
  --bg: #fbfbfd;
  --surface: #ffffff;
  --border: #dcdce4;
  --text: #1b1b22;
  --muted: #5c5c6b;
  --accent: #1f4fd8;
  --accent-soft: #e8eeff;
  --danger: #a4262c;
  --danger-soft: #fdecec;
  --ok: #1a6b3c;
  --ok-soft: #e6f4ec;
  --warn: #8a5a00;
  --warn-soft: #fdf3e0;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151a;
    --surface: #1c1e26;
    --border: #2f3240;
    --text: #e8e8f0;
    --muted: #a0a0b4;
    --accent: #7aa2ff;
    --accent-soft: #202b4a;
    --danger: #ff8a8f;
    --danger-soft: #3a2022;
    --ok: #6fd39b;
    --ok-soft: #1d3328;
    --warn: #f0c274;
    --warn-soft: #332a17;
  }
}

* {
  box-sizing: border-box;
}

/*
 * `hidden` must win over every component's own `display`.
 *
 * The user-agent rule for `[hidden]` is `display: none` at the LOWEST precedence, so any author
 * rule that sets `display` -- `.topbar { display: flex }`, `.row`, `dl.metrics` -- silently
 * un-hides the element. Measured: the signed-out page showed the whole navigation and a Sign out
 * button, because the script's `topbar.hidden = true` was overridden by `.topbar`. Visibility in
 * this dashboard is driven entirely by the `hidden` attribute (see the note at the top of this
 * file), so the attribute is made authoritative here, once.
 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

/* ---------------------------------------------------------------------------------------------
 * Top bar
 * ------------------------------------------------------------------------------------------ */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.identity {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-family: var(--mono);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: auto;
}

.nav-item {
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.nav-item[aria-current="page"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ---------------------------------------------------------------------------------------------
 * Main
 * ------------------------------------------------------------------------------------------ */

.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.panel + .panel {
  margin-top: 16px;
}

h2 {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 650;
}

/* ---------------------------------------------------------------------------------------------
 * Forms
 * ------------------------------------------------------------------------------------------ */

form {
  display: grid;
  /* `minmax(0, 1fr)`, not the implicit `auto`: an auto track grows to its widest child's
     min-content, so a <select> whose options are full rule statements pushed the form out of the
     panel. A zero minimum lets the track, and the control in it, stay inside max-width. */
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  max-width: 380px;
}

label {
  font-size: 13px;
  color: var(--muted);
}

input,
select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  padding: 8px 14px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #ffffff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

button.secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
  font-weight: 500;
}

button:disabled {
  opacity: 0.55;
  cursor: progress;
}

/* ---------------------------------------------------------------------------------------------
 * Tables
 * ------------------------------------------------------------------------------------------ */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td.numeric,
th.numeric {
  text-align: right;
  font-family: var(--mono);
}

.mono {
  font-family: var(--mono);
  font-size: 13px;
}

/* ---------------------------------------------------------------------------------------------
 * Status and badges
 * ------------------------------------------------------------------------------------------ */

.notice,
.error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 14px;
}

.notice {
  background: var(--accent-soft);
  color: var(--text);
}

.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font);
}

/* Grade is a scientific claim, so it is colour-coded and never ambiguous with a status. */
.badge.confirmed {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.provisional {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge.contested {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.refuted,
.badge.blocking {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.warning {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.info {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
}

/* ---------------------------------------------------------------------------------------------
 * Detail lists
 * ------------------------------------------------------------------------------------------ */

dl.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin: 0 0 16px;
}

dl.metrics div {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

dl.metrics dt {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

dl.metrics dd {
  margin: 4px 0 0;
  font-family: var(--mono);
  font-size: 16px;
}

/* ---------------------------------------------------------------------------------------------
 * Section helpers
 * ------------------------------------------------------------------------------------------ */

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.row > * {
  flex: 0 1 auto;
}

.stack > * + * {
  margin-top: 16px;
}

.subhead {
  margin: 24px 0 8px;
  font-size: 14px;
  font-weight: 650;
  color: var(--muted);
}

.empty {
  color: var(--muted);
  font-size: 14px;
  margin: 8px 0 0;
}

pre.json {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
}

/* Screen-reader-only text. `display: none` would remove it from the accessibility tree. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* castomo sign-in: the button first, the password form below it until P1b removes the form. */
.castomo {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.castomo .divider {
  margin: 4px 0 0;
  color: var(--muted);
  text-align: center;
}
