/* CS KPI Reports — interface styles. No framework, no build step.
 *
 * Light is the default and does NOT follow the OS preference: the light palette
 * sits on bare :root and the dark one only under [data-theme="dark"], which the
 * header toggle stamps on <html> and persists in localStorage. */

/* ─── Tokens ─────────────────────────────────────────────────────────────── */

:root {
  color-scheme: light;

  /* Neutrals carry a slight blue cast; pure grey reads cheap on screens. */
  --bg: #f7f8fa;
  --bg-alt: #eef0f4;
  --surface: #ffffff;
  --surface-2: #f4f6f9;
  --surface-3: #eaedf2;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;

  --text: #101828;
  --text-dim: #667085;
  --text-faint: #98a2b3;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-border: #c7d2fe;
  --accent-text: #3730a3;

  /* More contacts is worse for a support team, so a rise reads as the warning
     colour and a fall as the positive one. */
  --up: #be123c;
  --up-soft: #fff1f2;
  --down: #047857;
  --down-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --warn-border: #fde68a;
  --danger: #be123c;
  --danger-soft: #fff1f2;
  --danger-border: #fecdd3;

  --radius-xl: 16px;
  --radius-lg: 12px;
  --radius: 9px;
  --radius-sm: 6px;

  --shadow-xs: 0 1px 2px rgb(16 24 40 / 0.04);
  --shadow-sm: 0 1px 3px rgb(16 24 40 / 0.06), 0 1px 2px rgb(16 24 40 / 0.04);
  --shadow: 0 4px 8px -2px rgb(16 24 40 / 0.06), 0 2px 4px -2px rgb(16 24 40 / 0.04);
  --shadow-lg: 0 12px 24px -6px rgb(16 24 40 / 0.10), 0 4px 8px -4px rgb(16 24 40 / 0.06);
  --ring: 0 0 0 3px rgb(79 70 229 / 0.16);

  --sans: system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Mono", "Roboto Mono", Menlo, monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0c0f14;
  --bg-alt: #12161d;
  --surface: #151a21;
  --surface-2: #1c222b;
  --surface-3: #242b36;
  --border: #262e3a;
  --border-strong: #364150;

  --text: #e9edf3;
  --text-dim: #98a2b3;
  --text-faint: #6b7787;

  --accent: #8b93f8;
  --accent-hover: #a5abfa;
  --accent-soft: #1e2036;
  --accent-border: #383c66;
  --accent-text: #b4b9fb;

  --up: #fb7185;
  --up-soft: #2a161c;
  --down: #34d399;
  --down-soft: #10251e;
  --warn: #fbbf24;
  --warn-soft: #241d10;
  --warn-border: #4a3a15;
  --danger: #fb7185;
  --danger-soft: #2a161c;
  --danger-border: #4d2029;

  --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.3);
  --shadow-sm: 0 1px 3px rgb(0 0 0 / 0.4);
  --shadow: 0 4px 10px -2px rgb(0 0 0 / 0.45);
  --shadow-lg: 0 16px 32px -8px rgb(0 0 0 / 0.55);
  --ring: 0 0 0 3px rgb(139 147 248 / 0.24);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv05" 1, "ss01" 1;
}

[hidden] { display: none !important; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ─── App shell: fixed sidebar, scrolling content ────────────────────────── */

#app-shell {
  display: grid;
  grid-template-columns: 246px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 14px;
  font-weight: 640;
  font-size: 15px;
  letter-spacing: -0.015em;
  white-space: nowrap;
}
.brand img { border-radius: 7px; flex: none; display: block; }
.brand .brand-text span { color: var(--text-faint); font-weight: 450; }
.brand-lg { font-size: 16px; padding: 0 0 20px; }

/* ─── Sidebar navigation ─────────────────────────────────────────────────── */

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.nav button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 11px;
  width: 100%;
  background: none;
  border: 0;
  padding: 9px 11px;
  border-radius: var(--radius);
  color: var(--text-dim);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  box-shadow: none;
  transition: background 0.14s, color 0.14s;
}
.nav button:hover {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: none;
  transform: none;
}
.nav button[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 570;
}

/* Icons are stroked, so they inherit the row's colour on hover and when active. */
.nav button svg {
  width: 19px;
  height: 19px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.85;
}
.nav button[aria-current="page"] svg { opacity: 1; }

/* ─── Sidebar footer: account and session actions ────────────────────────── */

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: 0;
  padding: 7px 9px;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  box-shadow: none;
  color: var(--text);
  transition: background 0.14s;
}
.user-chip:hover { background: var(--surface-2); box-shadow: none; transform: none; }

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 12.5px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.user-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.user-meta .who {
  font-size: 13.5px;
  font-weight: 550;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-meta .role {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.sidebar-actions { display: flex; gap: 8px; }
.sidebar-actions .secondary { flex: 1; font-size: 13.5px; padding: 7px 12px; }

main {
  width: 100%;
  /* Centred in the space beside the sidebar. Without `margin: 0 auto` a capped
     column hugs the sidebar and leaves the right half of a wide monitor empty,
     which is exactly how this looked on a 34" display. */
  margin: 0 auto;
  max-width: 1320px;
  min-width: 0;
  /* Gutters grow with the viewport instead of staying at a fixed 34px, so the
     content is not pinned to the edges on a small laptop. */
  padding: 34px clamp(18px, 2.6vw, 44px) 96px;
}

/* Very wide displays get more room for the tables rather than more empty
   margin. Safe for readability because every prose element is capped on its own
   measure (.lede, .summary-list li, .guide-body), not by the container. */
@media (min-width: 1700px) {
  main { max-width: 1480px; }
}
@media (min-width: 2300px) {
  main { max-width: 1680px; }
}

/* ─── Typography ─────────────────────────────────────────────────────────── */

h1 {
  font-size: 26px;
  font-weight: 660;
  letter-spacing: -0.025em;
  margin: 0 0 6px;
  line-height: 1.25;
}

h2 {
  font-size: 18px;
  font-weight: 620;
  letter-spacing: -0.015em;
  margin: 40px 0 14px;
  line-height: 1.3;
}

/* Section label, not a shouty all-caps header. */
h3 {
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  margin: 28px 0 12px;
  color: var(--text);
}

h4 {
  font-size: 13.5px;
  font-weight: 600;
  margin: 22px 0 8px;
  color: var(--text-dim);
}

.lede {
  color: var(--text-dim);
  margin: 0 0 24px;
  max-width: 76ch;
  font-size: 14.5px;
}

.muted { color: var(--text-dim); }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* ─── Surfaces ───────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-xs);
}
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }

.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
}

/* The report's five headline tiles. A lower minimum than .grid so all five sit
   on one row beside the sidebar, instead of wrapping to 4 + 1. */
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); }
.grid-kpi .stat { padding: 14px 16px 16px; }
.grid-kpi .stat .value { font-size: 27px; }

/* ─── KPI tiles ──────────────────────────────────────────────────────────── */

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px 18px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow 0.16s, transform 0.16s;
}
.stat:hover { box-shadow: var(--shadow-sm); }

.stat .label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0;
  text-transform: none;
}
.stat .value {
  font-size: 30px;
  font-weight: 650;
  letter-spacing: -0.03em;
  margin: 6px 0 4px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat .sub {
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* Delta pill inside a tile or a sentence. */
.delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: var(--surface-3);
  color: var(--text-dim);
}
.delta.up { background: var(--up-soft); color: var(--up); }
.delta.down { background: var(--down-soft); color: var(--down); }

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--text-dim); }

/* ─── Tables ─────────────────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  margin-bottom: 18px;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

th, td {
  padding: 11px 16px;
  text-align: left;
  white-space: nowrap;
}

th {
  background: var(--surface-2);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: none;
  letter-spacing: 0;
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--border);
}
th:first-child { border-top-left-radius: var(--radius-lg); }
th:last-child { border-top-right-radius: var(--radius-lg); }

td { border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 0.12s; }
tbody tr:hover td { background: var(--surface-2); }

td.num, th.num { text-align: right; }
td.wrap { white-space: normal; min-width: 230px; }

/* ─── Forms ──────────────────────────────────────────────────────────────── */

label {
  display: block;
  font-size: 13px;
  font-weight: 550;
  margin-bottom: 6px;
  color: var(--text);
}
.hint { font-weight: 400; color: var(--text-faint); font-size: 12.5px; }

/* Attribute-agnostic: an <input> with no type attribute is still a text box,
   and selecting on [type="text"] silently skipped it. */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  box-shadow: var(--shadow-xs);
  transition: border-color 0.14s, box-shadow 0.14s;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 17px) center, calc(100% - 12px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
select[multiple] {
  min-height: 132px;
  background-image: none;
  padding-right: 12px;
}
select[multiple] option { padding: 4px 6px; border-radius: 4px; }

/* Styled file input — the native control is the single most dated element on
   any page that uses it. */
.file-field {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s;
}
.file-field:hover { border-color: var(--accent); background: var(--accent-soft); }
.file-field input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.file-field .file-cta {
  font-weight: 550;
  font-size: 13px;
  padding: 5px 11px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-xs);
  white-space: nowrap;
}
.file-field .file-name {
  font-size: 13.5px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-field.has-file { border-style: solid; border-color: var(--accent-border); background: var(--accent-soft); }
.file-field.has-file .file-name { color: var(--text); font-weight: 500; }

.field { margin-bottom: 16px; }
.field-row {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */

button, .btn {
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-decoration: none;
  /* A wrapped label makes a button taller than its row, which is what inflated
     the collapsed sidebar strip to 77px. */
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: background 0.14s, box-shadow 0.14s, transform 0.08s, border-color 0.14s;
}
button:hover, .btn:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}
button:active, .btn:active { transform: translateY(1px); }
button:focus-visible, .btn:focus-visible { outline: none; box-shadow: var(--ring); }
button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

button.secondary, .btn.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
button.secondary:hover, .btn.secondary:hover { background: var(--surface-2); }

button.danger {
  background: var(--danger);
  border-color: transparent;
  color: #fff;
}
button.danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); }

button.link {
  background: none;
  border: 0;
  color: var(--accent);
  padding: 0;
  font-weight: 550;
  font-size: 13.5px;
  box-shadow: none;
  text-decoration: none;
}
button.link:hover { background: none; box-shadow: none; text-decoration: underline; }

.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  padding: 0;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  font-size: 15px;
  flex: none;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 18px; }

/* ─── Badges and notices ─────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-dim);
  white-space: nowrap;
}
.badge.ready { background: var(--down-soft); color: var(--down); }
.badge.failed { background: var(--danger-soft); color: var(--danger); }
.badge.processing, .badge.pending, .badge.queued, .badge.building {
  background: var(--warn-soft);
  color: var(--warn);
}
.badge.high { background: var(--danger-soft); color: var(--danger); }
.badge.medium { background: var(--warn-soft); color: var(--warn); }
.badge.low { background: var(--surface-3); color: var(--text-dim); }

.notice {
  padding: 13px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 16px;
  box-shadow: var(--shadow-xs);
  font-size: 14px;
}
.notice.error {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}
.notice.warn {
  background: var(--warn-soft);
  border-color: var(--warn-border);
  color: var(--warn);
}
.notice ul { margin: 8px 0 0; padding-left: 20px; }
.notice li + li { margin-top: 5px; }
.notice strong { font-weight: 620; }

/* ─── Progress ───────────────────────────────────────────────────────────── */

.progress {
  height: 6px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
  min-width: 96px;
}
.progress > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 65%, #22d3ee));
  border-radius: 999px;
  transition: width 0.35s ease;
}

/* ─── Sign-in ────────────────────────────────────────────────────────────── */

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1000px 520px at 15% -10%, var(--accent-soft), transparent 65%),
    radial-gradient(760px 420px at 92% 108%, color-mix(in srgb, var(--accent-soft) 70%, transparent), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 396px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}
.login-card .brand { margin-bottom: 22px; font-size: 16px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card .lede { font-size: 13.5px; margin-bottom: 22px; }
.login-card .actions { margin-top: 22px; }
.login-card .actions button[type="submit"] { flex: 1; }

/* ─── Report ─────────────────────────────────────────────────────────────── */

.report-head {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 24px 26px;
  margin-bottom: 26px;
  box-shadow: var(--shadow-xs);
}
.report-head h1 { margin-bottom: 14px; }

.meta-grid {
  display: grid;
  gap: 14px 32px;
  grid-template-columns: repeat(auto-fit, minmax(175px, max-content));
  margin-bottom: 4px;
}
.meta-item .k {
  font-size: 12px;
  color: var(--text-faint);
  font-weight: 500;
  margin-bottom: 2px;
}
.meta-item .v { font-size: 14px; font-weight: 550; }

.summary-list { margin: 0; padding-left: 22px; }
.summary-list li { margin-bottom: 9px; max-width: 92ch; }
.summary-list li:last-child { margin-bottom: 0; }

.takeaway {
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 15px 18px;
  margin-bottom: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}
.takeaway.p-high { border-left-color: var(--danger); }
.takeaway.p-medium { border-left-color: var(--warn); }
.takeaway.p-low { border-left-color: var(--border-strong); }
.takeaway .head { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.takeaway .area { font-weight: 600; font-size: 14px; }
.takeaway p { margin: 0 0 6px; }
.takeaway p:last-child { margin-bottom: 0; }
.takeaway .action { color: var(--text-dim); }

.spark {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 56px;
  margin-top: 12px;
}
.spark > div {
  flex: 1;
  /* Without a cap, a short period (a daily comparison is two points) stretches
     into a couple of enormous blocks on a wide monitor. Bars stop growing and
     the series stays left-aligned, reading as a time axis. */
  max-width: 54px;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 55%, transparent));
  border-radius: 3px 3px 1px 1px;
  min-height: 2px;
  transition: opacity 0.14s;
}
.spark > div:hover { opacity: 0.7; }

/* ─── Admin ──────────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 3px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin: 0 0 24px;
  width: fit-content;
}
.tabs button {
  background: none;
  border: 0;
  border-radius: var(--radius);
  color: var(--text-dim);
  padding: 7px 15px;
  font-weight: 550;
  box-shadow: none;
}
.tabs button:hover { background: var(--surface); color: var(--text); box-shadow: none; }
.tabs button[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

.role-help { margin: 10px 0 0; padding-left: 18px; color: var(--text-dim); font-size: 13px; }
.role-help li { margin-bottom: 4px; }
.role-help code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 4px;
}

.pw-out {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 11px 13px;
  margin-top: 12px;
  word-break: break-all;
  line-height: 1.7;
  color: var(--text);
}

.inline-form { display: flex; gap: 11px; align-items: flex-end; flex-wrap: wrap; }
.inline-form > div { flex: 1 1 250px; }

/* Compact select used inside a table cell. */
td select { width: auto; min-width: 108px; padding: 5px 30px 5px 10px; font-size: 13px; }

/* ─── Utility ────────────────────────────────────────────────────────────── */

.empty {
  color: var(--text-faint);
  padding: 40px 24px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  margin-bottom: 18px;
  font-size: 14px;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.65s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 11px 20px;
  border-radius: 999px;
  z-index: 100;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  font-weight: 500;
  animation: rise 0.22s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 900px) {
  /* minmax(0, 1fr) rather than 1fr: a grid item's min-width defaults to auto,
     so the row-direction sidebar refused to shrink below its content width and
     pushed the whole page into horizontal scroll on a phone. */
  #app-shell { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: auto;
    /* Same reason — lets the nav's own overflow-x actually take effect. */
    min-width: 0;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(160%) blur(12px);
  }

  .brand { padding: 0; }
  .brand .brand-text { display: none; }

  .nav { flex-direction: row; overflow-x: auto; min-width: 0; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav button { width: auto; white-space: nowrap; }
  .nav button svg { display: none; }

  .sidebar-foot {
    border-top: 0;
    padding-top: 0;
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }
  .user-meta { display: none; }
  .sidebar-actions .secondary { font-size: 13px; }

  main { padding: 22px 16px 64px; }
}

@media (max-width: 700px) {
  h1 { font-size: 22px; }
  .stat .value { font-size: 26px; }
  .report-head { padding: 18px; }
  .sidebar-actions .secondary { display: none; }
}

/* ─── Admin: user rows ───────────────────────────────────────────────────── */

/* Username, real name and email in one cell. Seven columns pushed the action
   buttons past the right edge of the container, where they were clipped. */
.user-cell { white-space: normal; min-width: 190px; }
.user-cell .u-name { font-weight: 600; }
.user-cell .u-sub { font-size: 12.5px; color: var(--text-dim); }

.row-actions { white-space: nowrap; }
.row-actions button + button { margin-left: 14px; }

/* ─── Analyst guide ──────────────────────────────────────────────────────── */

.guide {
  display: grid;
  gap: 40px;
  grid-template-columns: 216px minmax(0, 1fr);
  align-items: start;
  /* Contents column plus a 74ch body. Centred so the guide does not drift to
     the left edge of a wide content area. */
  max-width: 1010px;
  margin: 0 auto;
}

.guide-toc {
  position: sticky;
  top: 34px;
  font-size: 13.5px;
}
.guide-toc-title {
  font-size: 11.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  margin-bottom: 10px;
}
.guide-toc nav { display: flex; flex-direction: column; gap: 1px; }
.guide-toc a {
  color: var(--text-dim);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--border);
  text-decoration: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.guide-toc a:hover {
  background: var(--surface-2);
  color: var(--text);
  border-left-color: var(--accent);
  text-decoration: none;
}

/* Prose measure: long lines are the main thing that makes documentation
   unreadable, so the body is capped regardless of viewport width. */
.guide-body { max-width: 74ch; }

.guide-section {
  padding-top: 8px;
  margin-bottom: 40px;
  /* Small offset so a jumped-to heading is not flush against the top. */
  scroll-margin-top: 22px;
}
.guide-section h2 {
  margin-top: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.guide-section h4 {
  color: var(--text);
  font-size: 14px;
  margin: 24px 0 8px;
}
.guide-section p { margin: 0 0 14px; }
.guide-section code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--surface-3);
  padding: 1.5px 5px;
  border-radius: 4px;
  white-space: nowrap;
}
.guide-section .notice { margin: 18px 0; }
.guide-section .badge { vertical-align: baseline; }

.guide-steps { margin: 0 0 14px; padding-left: 24px; }
.guide-steps li { margin-bottom: 14px; }
.guide-steps li::marker { color: var(--accent); font-weight: 650; }

.guide-code {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.7;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 15px 17px;
  overflow-x: auto;
  margin: 0 0 16px;
}

/* Documentation tables wrap; data tables do not. */
.guide-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin: 0 0 18px;
  font-size: 13.5px;
  background: var(--surface);
}
.guide-table th {
  position: static;
  border-radius: 0;
  font-size: 12.5px;
}
.guide-table th, .guide-table td { white-space: normal; padding: 10px 14px; vertical-align: top; }
.guide-table code { white-space: nowrap; }

@media (max-width: 900px) {
  /* minmax(0, 1fr), not 1fr — otherwise the long identifiers and wide
     documentation tables inside push the page into horizontal scroll. */
  .guide { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .guide-toc { position: static; }
  .guide-toc nav { flex-flow: row wrap; gap: 4px; }
  .guide-toc a { border-left: 0; background: var(--surface-2); }

  /* Source column names like ALL_Messaging Sessions_SOURCE are set nowrap so
     they read as one token on a desktop. On a phone that is wider than the
     screen, so they break instead. */
  .guide-section code,
  .guide-table code { white-space: normal; overflow-wrap: anywhere; }

  /* Documentation tables scroll inside their own box rather than the page. */
  .guide-table { display: block; overflow-x: auto; }
}

/* Caption under "At a glance", stating that every tile is current-period only. */
.tile-caption { margin: -6px 0 14px; font-size: 13.5px; max-width: 86ch; }

/* ─── Source-upload picker (New report) ──────────────────────────────────────
   A report reads exactly the uploads ticked here, so the list has to be
   readable at a glance: filename first, coverage and row count beneath it. */
.pick-group {
  margin-top: 18px;
}

.pick-group:first-of-type {
  margin-top: 8px;
}

.pick-group h4 {
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.pick {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.pick + .pick {
  margin-top: 8px;
}

.pick:hover {
  border-color: var(--accent);
}

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

.pick input {
  margin: 2px 0 0;
  flex: none;
  accent-color: var(--accent);
}

/* min-width: 0 so a long filename wraps instead of widening the row. */
.pick-body {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.pick-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.pick-meta {
  font-size: 0.82rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* ─── Print / PDF ────────────────────────────────────────────────────────────
   "Download PDF" hands the report to the browser's print pipeline, so this is
   the PDF's layout. It is a document, not a screenshot of the app: the shell
   and every control come off, the light palette is forced whatever the screen
   theme, and the page is set for A4. */

.print-only {
  display: none;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 15mm 13mm 18mm;
  }

  /* Force the light palette: a dark-theme reader would otherwise print pages
     of solid dark ink, and the accent colours lose their contrast on paper. */
  :root,
  :root[data-theme="dark"] {
    color-scheme: light;
    --bg: #ffffff;
    --bg-alt: #ffffff;
    --surface: #ffffff;
    --surface-2: #f7f8fa;
    --surface-3: #eef0f4;
    --border: #d8dce3;
    --border-strong: #b9c0cc;
    --text: #101828;
    --text-dim: #4b5565;
    --text-faint: #667085;
    --shadow-xs: none;
    --shadow-sm: none;
    --shadow: none;
    --shadow-lg: none;
  }

  /* Chrome drops backgrounds unless the reader ticks "Background graphics".
     The movement pills and severity colours carry meaning, so they are opted
     back in explicitly. */
  *,
  *::before,
  *::after {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    box-shadow: none !important;
    transition: none !important;
    animation: none !important;
  }

  html,
  body {
    background: #ffffff;
    font-size: 10.5pt;
  }

  /* The app shell is interface, not document. */
  .sidebar,
  .report-head .actions,
  .guide-link,
  button,
  .btn,
  .spinner {
    display: none !important;
  }

  .app,
  main {
    display: block !important;
    max-width: none !important;
    min-width: 0 !important;
    width: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    grid-template-columns: none !important;
  }

  .print-only {
    display: block;
  }

  /* Closes the document. A `position: fixed` running footer is the textbook
     approach and Chrome renders it over the top of the next page's content, so
     this is a plain block at the end instead. Page numbers come from the print
     dialog's own header/footer option. */
  .print-footer {
    margin-top: 22px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    color: var(--text-faint);
    font-size: 8pt;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .report-head {
    border: 0;
    border-bottom: 2px solid var(--accent);
    border-radius: 0;
    padding: 0 0 10px;
    margin-bottom: 18px;
  }

  .report-head h1 {
    font-size: 19pt;
  }

  h2 {
    font-size: 13pt;
    /* A heading alone at the foot of a page is the commonest print defect. */
    break-after: avoid;
    page-break-after: avoid;
    margin-top: 20px;
  }

  h3,
  h4 {
    break-after: avoid;
    page-break-after: avoid;
  }

  /* Nothing that reads as a single object may straddle a page break. */
  .card,
  .stat,
  .takeaway,
  .notice,
  .meta-grid,
  tr,
  li {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .card,
  .stat,
  .notice,
  .takeaway {
    border: 1px solid var(--border);
    border-radius: 6px;
  }

  /* The KPI row is the first thing a reader looks at; keep it whole and on one
     line rather than letting auto-fit wrap it across a page break. */
  .grid-kpi {
    display: grid !important;
    grid-template-columns: repeat(5, 1fr) !important;
    gap: 7px;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .grid-kpi .stat {
    padding: 9px 10px 10px;
  }

  .grid-kpi .stat .value {
    font-size: 14pt;
  }

  .grid-kpi .stat .label,
  .grid-kpi .stat .sub {
    font-size: 7.5pt;
  }

  table {
    width: 100%;
    font-size: 9pt;
    border-collapse: collapse;
  }

  /* A table continuing onto the next page repeats its header there. */
  thead {
    display: table-header-group;
  }

  tbody {
    display: table-row-group;
  }

  th,
  td {
    padding: 4px 6px;
  }

  /* On screen these scroll inside their own box; on paper there is nowhere to
     scroll to, so they lay out in full. */
  .table-wrap {
    overflow: visible !important;
    max-height: none !important;
  }

  a {
    color: var(--text);
    text-decoration: none;
  }

  /* The daily series is the report's only chart, and part of why a reader wants
     a PDF rather than the Markdown. It prints. */
  .spark {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}

/* ─── Multi-file upload rows ─────────────────────────────────────────────────
   One row per chosen file: what it is called, its status as it uploads, and
   the source type it will be parsed as. */
.upload-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.upload-row + .upload-row {
  margin-top: 8px;
}

.upload-row select {
  flex: none;
  width: auto;
  max-width: 46%;
}

.upload-row.done {
  border-color: var(--down);
  background: var(--down-soft);
}

.upload-row.failed {
  border-color: var(--danger-border);
  background: var(--danger-soft);
}

.upload-row.failed .pick-meta {
  color: var(--danger);
}

@media (max-width: 700px) {
  .upload-row {
    flex-direction: column;
    align-items: stretch;
  }

  .upload-row select {
    max-width: none;
    width: 100%;
  }
}

/* A row of small secondary actions inside a form field, e.g. the comparison
   period shortcuts. */
.actions.compact {
  margin: 10px 0 4px;
  gap: 8px;
  flex-wrap: wrap;
}

.actions.compact button {
  padding: 6px 11px;
  font-size: 0.85rem;
}

/* The comparison-period rule currently in force. */
.actions.compact button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-text);
}

/* Remove-from-queue control on an upload row. */
.icon-remove {
  flex: none;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.icon-remove:hover {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

/* Drop target feedback while files are dragged over the picker. */
.file-field.dropping {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ─── §9 mover groups ────────────────────────────────────────────────────────
   One block per brand, language or pair: the slice's own total, then its
   category and subcategory movers side by side. */
.mover-group {
  margin: 18px 0 0;
  padding: 14px 16px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.mover-group h4 {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: baseline;
  margin: 0 0 10px;
  font-size: 0.98rem;
}

/* Stacked, not side by side.
   Two five-column tables sharing one column came out too narrow at every
   width: on screen every one of them needed horizontal scrolling for a
   three-row table, and in print — where there is no scrolling — the Change and
   % Change columns were clipped off the page entirely. Full width each, one
   above the other, behaves the same on screen and on paper. */
.mover-tables {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.mover-tables > div {
  min-width: 0;
}

/* Compact cells: these are short reference tables inside a card, not the
   headline breakdowns. */
.mover-tables th,
.mover-tables td {
  padding: 7px 12px;
}

.mover-tables .table-wrap {
  margin-bottom: 0;
  border-radius: var(--radius-sm);
  box-shadow: none;
}

@media print {
  /* A slice and its two tables read as one object; keep them together. */
  .mover-group {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* Already stacked; nothing to override here beyond keeping it that way if
     the screen rule ever changes. */
  .mover-tables {
    grid-template-columns: 1fr;
  }
}

/* ─── Grouped table rows (§6a combined brand × language) ─────────────────────
   A brand row with its languages nested beneath. The brand reads as the
   heading of its block; the languages are indented so the hierarchy is legible
   without a second table. */
td.group-row {
  font-weight: 650;
  background: var(--surface-2);
}

tr:has(td.group-row) td {
  background: var(--surface-2);
  border-top: 1px solid var(--border-strong);
}

td.child-row {
  padding-left: 32px;
  color: var(--text-dim);
}

@media print {
  /* Keep a brand and at least the start of its languages together. */
  tr:has(td.group-row) {
    break-before: auto;
    break-after: avoid;
    page-break-after: avoid;
  }

  td.child-row {
    padding-left: 18px;
  }
}

/* ─── Market snapshot (§6b, inside At a glance) ───────────────────────────────
   Six slice cards in two market blocks. Each card is a small fixed structure —
   heading, total, two ranked lists, the languages that fed it — so the six read
   as one object rather than six differently-shaped ones. */
.market-group { margin: 0 0 18px; }

.market-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 8px;
}

.market-head h4 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.market-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  align-items: start;
}

.market-card { display: flex; flex-direction: column; gap: 10px; }

.market-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 650;
}

.market-total { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.market-total strong { font-size: 22px; line-height: 1; }
.market-total .muted { font-size: 12px; }

.market-list-label {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 4px;
}

/* Key takes the slack; the three figures sit on their own tracks so they line
   up down the list instead of drifting with the category name's length. */
.market-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 13px;
}

.market-row + .market-row { border-top: 1px solid var(--border); }

/* Column labels. Two of the three figures are percentages of different things,
   which is unreadable without saying which is which. */
.market-row-head,
.market-row-head .market-row-alt {
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding-bottom: 0;
}

.market-row-head + .market-row { border-top: none; }
.market-row-key { overflow-wrap: anywhere; }
.market-row-num { font-variant-numeric: tabular-nums; }
.market-row-alt {
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  font-size: 12px;
}

.market-langs { font-size: 11px; color: var(--text-dim); overflow-wrap: anywhere; }

@media print {
  /* Two per row in print: three columns squeezed the mover lines onto two
     lines each and split cards across the page break. */
  .market-grid { grid-template-columns: repeat(2, 1fr); }
  .market-card { break-inside: avoid; }
  .market-group { break-inside: avoid-page; }
}

/* Two-step sign-in: authenticator set-up (the QR code is an inline SVG built in the page). */
.enrol-qr { display: inline-block; background: #fff; padding: 10px; border-radius: 10px; line-height: 0; margin-bottom: 10px; }
.enrol-key { word-break: break-all; font-size: 13px; }
#use-backup { margin-top: -4px; }
