/*
 * Shared foundations: tokens, resets, forms, buttons, tables.
 *
 * Loaded by every surface. The client-facing look lives in viewer.css and the
 * admin's in admin.css — split because they are genuinely different products
 * that happen to share a codebase, and because one long appended file is how
 * three separate rules ended up silently overriding each other on source order.
 */

:root {
  --ink: #1a1a1a;
  --ink-soft: #5c5c5c;
  --rule: #e2e2e2;
  --page: #ffffff;
  --panel: #f7f7f5;

  --client-accent: #1f4e79;
  --client-accent-contrast: #ffffff;

  /* What buttons, links and focus rings use. Each surface points this at its
     own colour rather than every component knowing whose page it is on. */
  --accent: var(--client-accent);
  --accent-contrast: var(--client-accent-contrast);

  /* A brand accent chosen for a header band is often nearly black — St
     Patrick's olive is #2E3105 — and every tint of it comes out grey. This is
     the same hue lifted to something that actually reads as a colour, for the
     small interactive parts. Falls back to the accent itself where relative
     colour syntax isn't available. */
  --accent-bright: var(--accent);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Kepler and Freight Big are licensed Adobe faces we can't always serve. This
     is a system stack in the same spirit — a transitional serif — rather than a
     pretend match. */
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-heading: var(--font-sans);

  /* Anything raised off the page — cards, panels, rows. Distinct from --panel,
     which is an inset tint. Without the two being genuinely different the whole
     page flattens into one colour. */
  --surface: var(--page);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 2px 10px rgba(0, 0, 0, 0.04);

  --radius: 8px;
  --radius-sm: 5px;
}

@supports (color: oklch(from red l c h)) {
  :root {
    --accent-bright: oklch(from var(--accent) clamp(0.52, calc(l + 0.22), 0.7) max(c, 0.13) h);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  color: var(--ink);
  background: var(--page);
  font: 16px/1.6 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

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

form p { margin: 0 0 1rem; }

label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="color"], input[type="search"],
select, textarea {
  width: 100%;
  max-width: 480px;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  font: inherit;
  /* A field has to look like somewhere you type. On the page colour it vanishes
     into the form around it — it takes the raised surface, same as a card. */
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

input[type="color"] { max-width: 5rem; padding: 0.2rem; height: 2.4rem; box-shadow: none; }
select { max-width: 260px; }

/* Checkboxes read as a row, not as a label stacked over a stray box. */
input[type="checkbox"] { margin-right: 0.4rem; accent-color: var(--accent); }
input[type="checkbox"] + label { display: inline; font-weight: 400; }

fieldset {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem 0.5rem;
  margin: 0 0 1.5rem;
  background: var(--panel);
}

legend {
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  padding: 0 0.45rem;
}

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

input[type="submit"], button, .btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-contrast);
  font: inherit;
  font-weight: 600;
  line-height: 1.4;
  text-decoration: none;
  cursor: pointer;
  transition: filter 120ms ease, border-color 120ms ease;
}

input[type="submit"]:hover, button:hover, .btn:hover { filter: brightness(1.12); }

/* button_to renders a whole <form>, which is block-level. Left alone, two of
   them stack or jam against a neighbouring link — the single biggest cause of
   buttons running together in the admin. */
form.button_to { display: inline-block; margin: 0; }

button.secondary, .btn--secondary {
  background: transparent;
  border-color: var(--rule);
  color: var(--ink);
}

button.secondary:hover, .btn--secondary:hover { border-color: var(--accent); filter: none; }

.danger button, button.danger { background: #8b2020; color: #fff; }

button.linkish {
  background: none;
  border: 0;
  color: inherit;
  padding: 0;
  font-weight: 400;
  text-decoration: underline;
}

/* --- Messages ------------------------------------------------------------- */

.hint { display: block; color: var(--ink-soft); font-size: 0.8rem; margin-top: 0.3rem; }
.note, .empty { color: var(--ink-soft); }

/* Tinted with the accent and ruled down one side, so guidance reads as an aside
   rather than as another beige rectangle. */
.note {
  background: color-mix(in srgb, var(--accent-bright) 14%, var(--page));
  border-left: 3px solid var(--accent-bright);
  padding: 0.85rem 1.1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 0 0 1.5rem;
  color: var(--ink);
}

.empty { padding: 2rem 0; }

.errors {
  background: #fdeeee;
  border: 1px solid #f0c0c0;
  color: #7a1f1f;
  padding: 0.75rem 1rem 0.75rem 2rem;
  border-radius: var(--radius-sm);
  margin: 0 0 1.25rem;
}

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

.stats__table { width: 100%; border-collapse: collapse; margin-bottom: 2rem; }

.stats__table th,
.stats__table td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--rule);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.stats__table tbody tr:last-child td { border-bottom: 0; }

.stats__table th:first-child,
.stats__table td:first-child { text-align: left; }

/* The header band is what separates a table from a list of numbers. */
.stats__table thead th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  font-weight: 700;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}

/* Banding, so the eye can follow a row across six columns. */
.stats__table tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--ink) 3%, var(--surface));
}

.stats__table tbody tr:hover td { background: color-mix(in srgb, var(--accent-bright) 14%, var(--surface)); }

/* The first column is the label; give it weight and keep it readable. */
.stats__table tbody td:first-child { color: var(--ink); }

.stats__lesson { font-weight: 600; }
.stats__rate { color: var(--ink-soft); font-size: 0.85rem; }
.stats__zero { color: var(--ink-soft); }
.stats__title { margin: 0 0 0.5rem; }
.stats__scope { color: var(--ink-soft); margin: 0 0 1.5rem; }

tr.is-idle td { color: var(--ink-soft); }
tr.is-idle .stats__lesson { font-weight: 600; }
tr.is-idle .rows__meta { display: block; font-size: 0.75rem; }

/* Wide by nature, so it scrolls rather than squashing the page — and a card in
   its own right, because a table sitting bare on the page with only hairlines
   between rows reads as nothing at all. */
.grid-scroll {
  overflow-x: auto;
  margin-bottom: 2rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.grid-scroll .stats__table { margin-bottom: 0; }
.stats__table--grid { min-width: 640px; }

.stats__table--grid tfoot td {
  border-top: 2px solid var(--rule);
  border-bottom: 0;
  font-weight: 700;
  text-align: right;
  background: var(--panel);
}

.stats__table--grid tfoot td:first-child { text-align: left; }

.bar {
  height: 4px;
  background: var(--rule);
  border-radius: 2px;
  margin-top: 0.3rem;
  overflow: hidden;
}

.bar__fill { height: 100%; background: var(--accent); }
