:root {
  color-scheme: light;

  /* Surfaces */
  --bg: #ffffff;
  --panel: #f7f8fa;
  --panel-hover: #f1f3f6;
  --line: #d8dce2;
  --line-hard: #b6bcc6;

  /* Text */
  --text: #0f1720;
  --text-mid: #4a5563;
  --text-mute: #7a8494;

  /* Blue — the ULFG brand blue. There is exactly one blue: it passes contrast
     as a UI color, so brand and interaction share a token.
     Header bar, buttons, links, active nav. */
  --accent: #3d63a7;
  --accent-hover: #325288;
  --accent-soft: #edf1f8;
  --accent-ring: rgba(61, 99, 167, 0.3);

  /* Gold — the ULFG brand gold. Fill and rules only. Never text on white. */
  --gold-bar: #e2b105;
  --gold-bg: #fcf2ce;
  --gold-text: #8a6a04;

  /* Grade signals — one job each */
  --pass: #17803d;
  --warn: #8a6a04;
  --fail: #b91c1c;

  /* Typography (§3) */
  --font-ui: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, monospace;

  /* Type scale — exactly four sizes. There is no fifth. */
  --fs-display: 28px;
  --fs-lg: 18px;
  --fs-base: 14px;
  --fs-sm: 12px;

  /* Geometry (§4) — exactly two radii. */
  --r: 6px;
  --r-pill: 999px;
}

body {
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  background: var(--bg);
  color: var(--text);
}

/* ---------- Inline code ---------- */

code {
  font-family: var(--font-num);
  font-size: 0.9em;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 1px 5px;
}

/* ---------- Layout primitives ---------- */

.card {
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 1.5rem;
}

.card-tight {
  padding: 1.15rem;
}

.card-title {
  font-size: var(--fs-lg);
  font-weight: 600;
  line-height: 1.3;
}

.card-subtitle {
  margin-top: 0.35rem;
  font-size: var(--fs-base);
  color: var(--text-mute);
}

.meta {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-mute);
}

.section-stack > * + * {
  margin-top: 1.25rem;
}

/* ---------- Stats ---------- */

.stat {
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 1.15rem 1.25rem;
}

.stat-label {
  font-size: var(--fs-sm);
  color: var(--text-mute);
}

.stat-value {
  margin-top: 0.4rem;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-lg);
  font-weight: 600;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.stat-value-sm {
  font-size: var(--fs-base);
}

/* The two partial stats - average and rank - are the only --fs-display numbers
   in the app. They are a matched pair and must stay the same size (§3, §6). */
.stat-display {
  font-size: var(--fs-display);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 0.6rem 1.05rem;
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
  text-align: center;
  white-space: nowrap;
}

.btn:hover {
  background: var(--panel-hover);
  border-color: var(--line-hard);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.btn-primary {
  border-color: transparent;
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: transparent;
}

/* For use on the accent bar, where .btn-primary would be blue on blue. */
.btn-on-accent {
  border-color: transparent;
  background: #ffffff;
  color: var(--accent);
}

.btn-on-accent:hover {
  background: var(--accent-soft);
  border-color: transparent;
}

.btn-on-accent:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
  box-shadow: none;
}

.btn-warn {
  border-color: var(--line);
  background: var(--gold-bg);
  color: var(--gold-text);
}

.btn-warn:hover {
  background: var(--gold-bar);
  color: var(--text);
}

.btn-danger {
  border-color: var(--fail);
  background: var(--bg);
  color: var(--fail);
}

.btn-danger:hover {
  background: var(--panel-hover);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: var(--fs-sm);
  border-radius: var(--r);
}

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

.field-label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: var(--fs-sm);
  color: var(--text-mid);
}

.input,
.select,
.textarea {
  width: 100%;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 0.7rem 0.95rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.textarea {
  min-height: 7rem;
  resize: vertical;
}

.checkbox {
  height: 1rem;
  width: 1rem;
  flex: none;
  accent-color: var(--accent);
  cursor: pointer;
}

.checkbox:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: var(--fs-base);
  color: var(--text-mid);
  cursor: pointer;
}

/* ---------- Toggle pill (sharing) ---------- */

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 0.65rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.toggle:hover {
  border-color: var(--line-hard);
}

.toggle:has(.checkbox:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.toggle-text {
  min-width: 0;
}

.toggle-label {
  font-size: var(--fs-sm);
  color: var(--text-mute);
}

.toggle-value {
  font-size: var(--fs-base);
  font-weight: 600;
  line-height: 1.3;
}

/* ---------- Disclosure (class dropdowns) ---------- */

summary {
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

.details-chevron {
  display: inline-block;
  transition: transform 0.15s ease;
}

details[open] .details-chevron {
  transform: rotate(180deg);
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 0.25rem 0.7rem;
  font-size: var(--fs-sm);
  color: var(--text-mid);
  white-space: nowrap;
}

/* A state chip is neither clickable nor branded, so it stays grey (§2).
   It reads as "on" by being darker than .badge-muted, not by being blue. */
.badge-public {
  border-color: var(--line-hard);
  background: var(--panel);
  color: var(--text);
}

.badge-muted {
  color: var(--text-mute);
}

/* ---------- Header (§5) ---------- */
/* The app's signature: a solid --accent bar with a 3px --gold-bar rule under
   it. The only large area of color anywhere. No blur, no shadow, no radius. */

.site-header {
  background: var(--accent);
  border-bottom: 3px solid var(--gold-bar);
}

.site-header-inner {
  margin: 0 auto;
  max-width: 1600px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
}

.site-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #ffffff;
  text-decoration: none;
}

.site-logo {
  height: 28px;
  width: 28px;
  display: block;
  flex: none;
}

.site-wordmark {
  font-size: var(--fs-lg);
  font-weight: 600;
  color: #ffffff;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

/* Nav only ever sits on the blue bar, so it is styled for that surface. */
.nav-link {
  padding: 8px 12px;
  font-size: var(--fs-base);
  color: rgba(255, 255, 255, 0.82);
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.nav-link:hover {
  color: #ffffff;
}

.nav-link.is-active {
  color: #ffffff;
  border-bottom-color: var(--gold-bar);
}

/* --accent-ring is invisible against the accent bar, so focus is a white ring. */
.nav-link:focus-visible,
.site-brand:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.nav-sep {
  width: 1px;
  align-self: stretch;
  background: rgba(255, 255, 255, 0.28);
  margin: 4px 8px;
}

/* ---------- Tables (§5) ---------- */
/* One table component. The dashboard and the leaderboard both use it; do not
   create a second table style. */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--bg);
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: var(--fs-base);
}

.table thead th {
  background: var(--panel);
  padding: 8px 16px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-mute);
  text-transform: none; /* sentence case */
  letter-spacing: normal;
  white-space: nowrap;
}

.table tbody td {
  border-top: 1px solid var(--line);
  padding: 8px 16px;
  vertical-align: middle;
}

/* No transform, no shadow. Just the surface. */
.table tbody tr:hover {
  background: var(--panel-hover);
}

/* Every number in the app: mono, tabular figures, right-aligned (§3).
   On a th as well, so the header sits over its column. */
.table .num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* A left-aligned column sitting after a right-aligned number column starts hard
   against that column's digits. Extra left padding pulls it clear. Applied to
   the th and its cells together, so the header stays over its column. */
.table .col-spaced {
  padding-left: 32px;
}

/* ---------- Alerts ---------- */

.alert {
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 0.85rem 1.1rem;
  font-size: var(--fs-base);
  color: var(--text);
}

.alert-success {
  border-color: var(--line);
  background: var(--panel);
  color: var(--pass);
}

.alert-error {
  border-color: var(--line);
  background: var(--panel);
  color: var(--fail);
}

.alert-warning {
  border-color: var(--line);
  background: var(--gold-bg);
  color: var(--gold-text);
}

.alert-info {
  border-color: var(--line);
  background: var(--accent-soft);
  color: var(--text);
}

/* ---------- Grade values ---------- */
/* Class names still say green/orange/red because app.py's grade_color() emits
   them. Renaming to pass/warn/fail touches app.py, which is step 5. */

.value-green {
  color: var(--pass);
}

.value-orange {
  color: var(--warn);
}

.value-red {
  color: var(--fail);
}

.value-neutral {
  color: var(--text);
}

/* Cosmetic only. The real value is never rendered for a hidden field, so there
   is nothing here for a reader to recover by removing the blur. */
.is-hidden-grade {
  color: var(--text-mute);
  filter: blur(5px);
  user-select: none;
  pointer-events: none;
  letter-spacing: 0.15em;
}

.empty-state {
  border-radius: var(--r);
  border: 1px dashed var(--line-hard);
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--text-mute);
}

/* ---------- Missing data ---------- */
/* An em-dash in --text-mute. Absent data must never be louder than present
   data, and must never read as the string "Not available" (§5). */

.is-missing {
  color: var(--text-mute);
}

/* ---------- Grade row change flash (§7) ---------- */
/* The only animation in the app: the row flashes --accent-soft and fades back
   over 400ms. Once. Not looping. */

@keyframes row-flash {
  from {
    background-color: var(--accent-soft);
  }
  to {
    background-color: transparent;
  }
}

.grade-row.is-changed {
  animation: row-flash 400ms ease-out 1;
}

.grade-row.is-removed {
  opacity: 0.45;
}

@media (prefers-reduced-motion: reduce) {
  .grade-row.is-changed {
    animation: none;
    background-color: var(--accent-soft);
  }
}

/* ---------- Toasts ---------- */
/* Styling lives here, not in a template literal of utilities inside app.js. */

.toast {
  border-radius: var(--r);
  border: 1px solid var(--line-hard);
  background: var(--bg);
  padding: 12px 16px;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast-title {
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--text);
}

.toast-message {
  margin-top: 4px;
  font-size: var(--fs-base);
  color: var(--text-mid);
}

.toast-success .toast-title {
  color: var(--pass);
}

.toast-error .toast-title {
  color: var(--fail);
}

.toast-warning {
  background: var(--gold-bg);
}

.toast-warning .toast-title {
  color: var(--gold-text);
}

.toast-info {
  background: var(--accent-soft);
}

/* ---------- Connection badge ---------- */
/* Its own state classes. It must not borrow the grade-signal colors: §2 gives
   --pass / --warn / --fail exactly one job each. The label carries the meaning,
   so the states are greyscale. */

.conn-online {
  color: var(--text);
  border-color: var(--line-hard);
}

.conn-idle {
  color: var(--text-mute);
}

.conn-offline {
  color: var(--text);
  border-color: var(--line-hard);
  font-weight: 500;
}
