/* ============================================================
   Contract Intelligence — dashboard design system
   Light, warm-neutral interface · deep navy-slate ink · teal accent
   8px spacing grid · system fonts · no external assets
   NOTE: the CSP is `style-src 'self'`; templates must never use
   inline style attributes — express all presentation here.
   ============================================================ */

:root {
  color-scheme: light;

  /* palette */
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f2f4f4;
  --ink: #1b2a38;
  --ink-2: #3d4f60;
  --muted: #5c6f81;
  --line: #e4e6e3;
  --line-2: #cfd6d5;

  --accent: #0c6b74;
  --accent-deep: #08525a;
  --accent-soft: #e1efef;
  --accent-wash: #f3f8f8;

  --ok: #17714a;
  --ok-soft: #e2f2e9;
  --warn: #7c5300;
  --warn-soft: #f9efd8;
  --danger: #a92e42;
  --danger-deep: #8d2536;
  --danger-soft: #f9ebee;

  /* elevation */
  --shadow-1: 0 1px 2px rgba(27, 42, 56, 0.05);
  --shadow-2: 0 1px 2px rgba(27, 42, 56, 0.04), 0 10px 28px -14px rgba(27, 42, 56, 0.14);

  /* shape */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;

  /* type */
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas,
          "Liberation Mono", monospace;

  --focus-ring: 0 0 0 3px rgba(12, 107, 116, 0.26);
  --sidebar-w: 246px;
}

/* ---------- base ---------- */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 var(--font);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; line-height: 1.25; }
h1 { font-size: 1.45rem; letter-spacing: -0.015em; }
h2 { font-size: 1.05rem; letter-spacing: -0.008em; }
h3 { font-size: 0.95rem; }

p { margin: 0.5rem 0; }
small { font-size: 0.8rem; }

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

code { font-family: var(--mono); font-size: 0.86em; word-break: break-all; }

svg { flex-shrink: 0; }

.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;
}

.muted { color: var(--muted); }
.lead { font-size: 1.05rem; color: var(--ink-2); }

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

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

a, button, .badge, .chip, input, select, textarea, progress, .side-nav a {
  transition: background-color 120ms ease, border-color 120ms ease,
              color 120ms ease, box-shadow 120ms ease;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -3rem;
  z-index: 50;
  padding: 0.5rem 0.85rem;
  background: var(--ink);
  color: #fff;
  border-radius: var(--r-sm);
}
.skip-link:focus { top: 0.75rem; color: #fff; }

/* ---------- app shell ---------- */

body.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  height: 100dvh;
  overflow-y: auto;
  padding: 1.25rem 1rem;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.25rem 0.5rem;
  color: var(--ink);
  font-size: 0.94rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.brand:hover { color: var(--ink); text-decoration: none; }
.brand-mark { width: 27px; height: 27px; }
.brand-mark .bm-bg { fill: var(--accent); }
.brand-mark .bm-shield { fill: none; stroke: #fff; stroke-width: 1.8; stroke-linejoin: round; }
.brand-mark .bm-check { fill: none; stroke: #fff; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.side-nav { display: flex; flex-direction: column; gap: 2px; margin-top: 0.75rem; flex: 1; }

.nav-group-label {
  margin: 1rem 0.55rem 0.3rem;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.side-nav .nav-group-label:first-child { margin-top: 0; }

.side-nav a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 38px;
  padding: 0.35rem 0.55rem;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: 0.9rem;
  font-weight: 550;
}
.side-nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.side-nav a .nav-icon { width: 17px; height: 17px; color: var(--muted); }
.side-nav a:hover .nav-icon { color: var(--ink-2); }
.side-nav a.is-active { background: var(--accent-soft); color: var(--accent-deep); font-weight: 650; position: relative; }
.side-nav a.is-active .nav-icon { color: var(--accent); }
/* A filled pill alone reads as a hover state; the marker makes the current
   section unambiguous, and survives forced-colours mode where the tint drops. */
.side-nav a.is-active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 1.15rem;
  border-radius: 0 2px 2px 0;
  background: var(--accent);
}
@media (forced-colors: active) {
  .side-nav a.is-active::before { background: Highlight; }
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-account {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 38px;
  padding: 0.35rem 0.55rem;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: 0.9rem;
  font-weight: 550;
}
.side-account:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.side-account .nav-icon { width: 17px; height: 17px; color: var(--muted); }
.side-account[aria-current="page"] { background: var(--accent-soft); color: var(--accent-deep); font-weight: 650; }
.side-account[aria-current="page"] .nav-icon { color: var(--accent); }

.side-logout { margin: 0; }
.side-logout button {
  justify-content: flex-start;
  width: 100%;
  min-height: 38px;
  padding: 0.35rem 0.55rem;
  background: transparent;
  border-color: transparent;
  color: var(--ink-2);
  font-size: 0.9rem;
  font-weight: 550;
}
.side-logout button:hover { background: var(--surface-2); border-color: transparent; color: var(--ink); }
.side-logout button .nav-icon { width: 17px; height: 17px; color: var(--muted); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.55rem;
  border-radius: var(--r-sm);
}

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 0.8rem;
  font-weight: 700;
}

.user-meta { display: grid; min-width: 0; }
.user-meta strong {
  font-size: 0.84rem;
  font-weight: 640;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-meta small { color: var(--muted); font-size: 0.72rem; }

/* public (unauthenticated / guest-request) shell */

body.public { display: flex; flex-direction: column; min-height: 100dvh; }

.public-topbar {
  display: flex;
  align-items: center;
  padding: 0.9rem max(1.25rem, calc((100% - 1160px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

main.container {
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: 2rem 2rem 3.5rem;
}
body.public main.container { max-width: 640px; padding-top: 2.5rem; }

/* ---------- messages & callouts ---------- */

.message,
.warning,
.alert {
  display: block;
  margin: 0 0 1rem;
  padding: 0.7rem 1rem;
  background: var(--accent-wash);
  border: 1px solid var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-sm);
  font-size: 0.9rem;
}

.warning,
.alert-warning {
  background: var(--warn-soft);
  border-color: #efdfb5;
  border-left-color: #c98a00;
  color: var(--warn);
}
.alert-danger, .alert-error {
  background: var(--danger-soft);
  border-color: #f0cdd4;
  border-left-color: var(--danger);
  color: var(--danger-deep);
}
.alert-success, .message.success { background: var(--ok-soft); border-color: #cbe7d7; border-left-color: var(--ok); color: var(--ok); }
.message.warning { background: var(--warn-soft); border-color: #efdfb5; border-left-color: #c98a00; color: var(--warn); }
.message.error { background: var(--danger-soft); border-color: #f0cdd4; border-left-color: var(--danger); color: var(--danger-deep); }

.live-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 1rem;
  padding: 0.7rem 1rem;
  background: var(--warn-soft);
  border: 1px solid #efdfb5;
  border-left: 3px solid #c98a00;
  border-radius: var(--r-sm);
  font-size: 0.9rem;
  color: var(--warn);
}
.live-banner[hidden] { display: none; }
.live-banner a { font-weight: 600; }

/* ---------- page heading ---------- */

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}
.page-heading-info { min-width: 0; }
.page-sub { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.92rem; max-width: 60ch; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 1rem;
  font-size: 0.84rem;
}
.breadcrumb .crumb-sep { color: var(--line-2); }
.breadcrumb [aria-current] { color: var(--muted); font-family: var(--mono); font-size: 0.8rem; }

/* segmented period control */

.period-picker { display: grid; gap: 0.3rem; justify-items: end; }
.control-label { color: var(--muted); font-size: 0.72rem; font-weight: 700; }

.segmented {
  display: inline-flex;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-1);
}
.segmented a {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 0.75rem;
  border-radius: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
}
.segmented a:hover { color: var(--ink); text-decoration: none; }
.segmented a.is-active { background: var(--accent-soft); color: var(--accent-deep); }

/* ---------- badges, chips, statuses ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.1rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 0.74rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  max-width: 100%;
  overflow-wrap: anywhere;
  text-align: center;
}

.badge-accent { background: var(--accent-soft); border-color: #c8e0e1; color: var(--accent-deep); }
.badge-ok      { background: var(--ok-soft);     border-color: #c6e5d4; color: var(--ok); }
.badge-warn    { background: var(--warn-soft);   border-color: #eddcae; color: var(--warn); }
.badge-danger  { background: var(--danger-soft); border-color: #efccd3; color: var(--danger-deep); }

/* pipeline / verification states, applied on top of .badge */
.status-ok, .status-successful, .status-published, .status-confirmed,
.status-active, .status-resolved, .status-approved {
  background: var(--ok-soft); border-color: #c6e5d4; color: var(--ok);
}
.status-failed, .status-error, .status-declined, .status-revoked, .status-expired {
  background: var(--danger-soft); border-color: #efccd3; color: var(--danger-deep);
}
.status-unknown, .status-pending, .status-awaiting, .status-awaiting-verification,
.status-awaiting_verification,
.status-unverified, .status-open, .status-warning, .status-partial, .status-degraded {
  background: var(--warn-soft); border-color: #eddcae; color: var(--warn);
}

/* confidence levels */
.conf-high { background: var(--surface-2); border-color: var(--line); color: var(--ink-2); }
.conf-mid  { background: var(--warn-soft); border-color: #eddcae; color: var(--warn); }
.conf-low  { background: var(--danger-soft); border-color: #efccd3; color: var(--danger-deep); }
.conf-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.conf-mid .conf-dot { background: #c98a00; }
.conf-low .conf-dot { background: var(--danger); }

.status-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #c98a00;
}
.status-dot.status-ok, .status-dot.status-successful, .status-dot.status-published { background: var(--ok); }
.status-dot.status-failed, .status-dot.status-error { background: var(--danger); }

.chip {
  display: inline-block;
  padding: 0.06rem 0.45rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-2);
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: normal;
}
a.chip:hover { border-color: var(--accent); color: var(--accent-deep); background: var(--accent-wash); text-decoration: none; }

.missing { color: var(--muted); }

.money { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- buttons & forms ---------- */

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 38px;
  padding: 0.45rem 1rem;
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #fff;
  font: 600 0.88rem/1.2 var(--font);
  cursor: pointer;
}
button:hover, .btn:hover { background: var(--accent-deep); border-color: var(--accent-deep); color: #fff; text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button:focus-visible, .btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

button.secondary, .btn-secondary, .btn-info, .btn-warning {
  background: var(--surface);
  border-color: var(--line-2);
  color: var(--ink-2);
}
button.secondary:hover, .btn-secondary:hover, .btn-info:hover, .btn-warning:hover {
  background: var(--surface-2);
  border-color: var(--muted);
  color: var(--ink);
}

button.danger, .btn-danger {
  background: var(--surface);
  border-color: #e3b6bf;
  color: var(--danger-deep);
}
button.danger:hover, .btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

.btn-link { background: none; border-color: transparent; color: var(--accent); padding: 0.45rem 0.5rem; }
.btn-link:hover { background: var(--accent-wash); color: var(--accent-deep); }
.btn-block { display: flex; width: 100%; }
.btn-sm { min-height: 32px; padding: 0.25rem 0.7rem; font-size: 0.8rem; }
.float-right { float: right; }

label { font-size: 0.8rem; font-weight: 650; color: var(--ink-2); }

input, textarea, select {
  max-width: 100%;
  min-height: 38px;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font: 400 0.9rem/1.4 var(--font);
}
textarea { min-height: 5rem; resize: vertical; }
input::placeholder, textarea::placeholder { color: #9aa8b5; }
input:hover, textarea:hover, select:hover { border-color: var(--muted); }
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%235c6f81' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
}

input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  min-height: 0;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

/* rendered by form.as_p on public/auth pages */
form p { display: grid; gap: 0.3rem; margin: 0 0 0.9rem; }
form p label { margin: 0; }

/* forms rendered with as_table (django-two-factor pages): stack the rows and
   strip the data-table chrome */
form table, form table tbody, form table tr, form table th, form table td { display: block; }
form table th, form table td { padding: 0; border: 0; background: none; }
form table th {
  color: var(--ink-2);
  font-size: 0.8rem;
  letter-spacing: 0;
  text-transform: none;
  padding-bottom: 0.25rem;
}
form table td { padding-bottom: 0.9rem; }
form table td input:not([type="checkbox"]):not([type="radio"]),
form table td select, form table td textarea { width: 100%; }
.errorlist { margin: 0 0 0.75rem; padding: 0; list-style: none; }
.errorlist li {
  padding: 0.5rem 0.75rem;
  background: var(--danger-soft);
  border: 1px solid #efccd3;
  border-radius: var(--r-sm);
  color: var(--danger-deep);
  font-size: 0.84rem;
}
.helptext { color: var(--muted); font-size: 0.78rem; font-weight: 400; }

/* six-digit verification code */
#id_code {
  max-width: 12rem;
  font-family: var(--mono);
  font-size: 1.3rem;
  letter-spacing: 0.35em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---------- cards / panels ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-1);
}

.section-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}
.panel .section-heading { margin-bottom: 1rem; }
.section-heading > a, .section-heading .heading-note { font-size: 0.84rem; white-space: nowrap; }
.section-heading .heading-note { color: var(--muted); }

/* KPI cards */

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin: 1.5rem 0 1rem;
}

.kpi {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.15rem;
  min-height: 118px;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
}
.kpi-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.kpi-label::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--line-2);
}
.kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.kpi-note { color: var(--muted); font-size: 0.78rem; }

.accent-card { border-color: #c8e0e1; background: linear-gradient(180deg, var(--surface), var(--accent-wash)); }
.accent-card .kpi-label::before { background: var(--accent); }
.accent-card .kpi-value { color: var(--accent-deep); }

.risk-card { border-color: #efccd3; background: linear-gradient(180deg, var(--surface), #fdf6f7); }
.risk-card .kpi-label::before { background: var(--danger); }
.risk-card .kpi-value { color: var(--danger-deep); }

/* pipeline run strip */

.run-strip {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  font-size: 0.88rem;
}
.run-strip .muted { font-variant-numeric: tabular-nums; }
/* Liveness of the polling worker, which the run timestamp cannot convey: runs
   are only recorded when a generation changes, so a healthy-but-quiet worker
   and a dead one leave the same trace. */
.live-beat {
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent-deep);
  white-space: nowrap;
}
.live-beat-failing { background: var(--warn-soft); color: var(--warn); }
.live-beat-stale { background: var(--danger-soft); color: var(--danger-deep); }
.run-strip-link { margin-left: auto; display: inline-flex; align-items: center; gap: 0.3rem; font-weight: 600; font-size: 0.84rem; }

/* ---------- overview panels ---------- */

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 1fr);
  gap: 1rem;
  margin: 1rem 0;
}
.dashboard-grid.halves { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.bar-chart { display: grid; gap: 0.5rem; align-content: start; }
.bar-row {
  display: grid;
  grid-template-columns: 52px 1fr 30px;
  gap: 0.7rem;
  align-items: center;
  font-size: 0.78rem;
}
.bar-row time { color: var(--muted); white-space: nowrap; }
.bar-row strong { text-align: right; font-variant-numeric: tabular-nums; }

progress {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  border: 0;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
.bar-line { height: 8px; }
.coverage-bar { height: 8px; }

.coverage-item { margin-bottom: 1.1rem; }
.coverage-item > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.4rem;
  font-size: 0.88rem;
}
.coverage-item strong { font-variant-numeric: tabular-nums; }

.action-list { border-top: 1px solid var(--line); margin-top: 1.1rem; padding-top: 0.35rem; }
.action-list a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 40px;
  padding: 0.35rem 0.25rem;
  border-bottom: 1px solid var(--surface-2);
  border-radius: 4px;
  color: var(--ink-2);
  font-size: 0.88rem;
}
.action-list a:last-child { border-bottom: 0; }
.action-list a:hover { background: var(--accent-wash); color: var(--ink); text-decoration: none; }
.action-list .count {
  margin-left: auto;
  min-width: 1.9rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.action-list .chev { color: var(--line-2); }
.action-list a:hover .chev { color: var(--accent); }

.rankings { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
.rankings li { border-bottom: 1px solid var(--surface-2); }
.rankings li:last-child { border-bottom: 0; }
.rankings li > a, .rankings .rank-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.55rem 0.25rem;
  border-radius: 4px;
  color: inherit;
}
.rankings li > a:hover { background: var(--accent-wash); text-decoration: none; }
.rankings .rank-index {
  width: 1.4rem;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.rankings .rank-label { display: grid; min-width: 0; }
.rankings .rank-label strong {
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rankings .rank-label small { color: var(--muted); }
.rankings b { margin-left: auto; font-size: 0.88rem; white-space: nowrap; font-variant-numeric: tabular-nums; }

.recent-heading { margin: 2rem 0 0.75rem; }

/* ---------- filters toolbar ---------- */

.filters-panel {
  margin: 1.25rem 0 1rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.85rem 1rem;
  margin: 0;
}
.filters .field { display: grid; gap: 0.3rem; }
.filters .field-search { flex: 1 1 240px; }
.search-field { position: relative; display: flex; }
.search-field input { width: 100%; padding-left: 2.1rem; }
.search-field .search-icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--muted);
  pointer-events: none;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 38px;
  padding: 0 0.75rem;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 0.84rem;
  font-weight: 550;
  color: var(--ink-2);
  cursor: pointer;
}
.check-field:hover { border-color: var(--muted); }

.filter-actions { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; }

.export-actions { display: grid; gap: 0.3rem; justify-items: end; }
.export-buttons { display: flex; gap: 0.5rem; }
.reset-link { font-size: 0.84rem; color: var(--muted); }
.reset-link:hover { color: var(--danger-deep); }

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.85rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.filter-chips .chip-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.6rem;
  background: var(--accent-soft);
  border: 1px solid #c8e0e1;
  border-radius: 999px;
  color: var(--accent-deep);
  font-weight: 600;
}
.filter-chips .chip-filter span { font-weight: 450; }

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

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

table { width: 100%; border-collapse: collapse; }
.table-wrap table { min-width: 820px; }

th, td {
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--surface-2);
  text-align: left;
  vertical-align: top;
}
th {
  padding-top: 0.75rem;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--accent-wash); }
tbody tr.row-empty:hover td { background: transparent; }

th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.cell-date { color: var(--muted); font-size: 0.82rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.cell-date time { display: block; color: var(--ink-2); }
td.cell-subject { max-width: 420px; }
td.cell-winner { max-width: 300px; color: var(--ink-2); font-size: 0.88rem; }
.cell-ada a { font-family: var(--mono); font-size: 0.8rem; white-space: nowrap; }

.table-empty {
  display: grid;
  justify-items: center;
  gap: 0.35rem;
  padding: 2.5rem 1rem;
  text-align: center;
}
.table-empty svg { width: 30px; height: 30px; color: var(--line-2); }
.table-empty strong { font-size: 0.95rem; }
.table-empty span { color: var(--muted); font-size: 0.85rem; }

/* ---------- pagination ---------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
}
.page-status { color: var(--muted); font-size: 0.84rem; font-variant-numeric: tabular-nums; }
.page-controls { display: flex; gap: 0.5rem; }
.page-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 36px;
  padding: 0.3rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: 0.84rem;
  font-weight: 600;
}
a.page-btn:hover { border-color: var(--accent); color: var(--accent-deep); text-decoration: none; background: var(--accent-wash); }
span.page-btn { opacity: 0.45; }

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

.detail-header { margin-bottom: 1.25rem; }
.detail-header h1 { max-width: 56ch; overflow-wrap: anywhere; }
.detail-meta-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}
.detail-badges { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.75rem; }

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, 1fr);
  gap: 1rem;
  align-items: start;
}
.detail-main { display: grid; gap: 1rem; min-width: 0; }
.detail-aside { min-width: 0; display: grid; gap: 1rem; }
.facts dt code { font-size: 0.78rem; }

.fin-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  margin: 0;
}
.fin-item { display: grid; gap: 0.1rem; padding: 1rem 1.25rem; border-left: 1px solid var(--surface-2); }
.fin-item:first-child { border-left: 0; }
.fin-item dt { color: var(--muted); font-size: 0.74rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.fin-item dd { margin: 0; font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.fin-item.fin-total { background: var(--accent-wash); }
.fin-item.fin-total dd { color: var(--accent-deep); }

.facts { margin: 0; }
.facts > div {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--surface-2);
}
.facts > div:last-child { border-bottom: 0; }
.facts dt { color: var(--muted); font-size: 0.8rem; font-weight: 650; padding-top: 0.1rem; }
.facts dd { margin: 0; font-size: 0.88rem; min-width: 0; overflow-wrap: anywhere; }
.facts dd .badge { margin: 0 0.2rem 0.2rem 0; }

.doc-link { display: inline-flex; align-items: center; gap: 0.45rem; margin-top: 1rem; width: 100%; }

/* winners / ownership entity cards */

.entity-list { display: grid; gap: 0.75rem; }
.entity-card {
  display: flex;
  gap: 0.9rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
}
.entity-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 0.95rem;
  font-weight: 700;
}
.entity-body { display: grid; gap: 0.4rem; min-width: 0; flex: 1; }
.entity-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
}
.entity-title strong { overflow-wrap: anywhere; }
.entity-title .entity-amount { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.entity-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.entity-row .sep { color: var(--line-2); }

.path-chain { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.path-chain .path-arrow { color: var(--line-2); font-size: 0.8rem; }

.note-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 0.5rem; }
.note-list li {
  padding: 0.6rem 0.9rem;
  background: var(--warn-soft);
  border: 1px solid #eddcae;
  border-radius: var(--r-sm);
  color: var(--warn);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

.detail-section { margin-top: 1.75rem; }
.detail-section > h2 { margin-bottom: 0.75rem; }
.detail-section .section-count { color: var(--muted); font-weight: 500; }

/* ---------- reviews & access queues ---------- */

.queue-section + .queue-section { margin-top: 2rem; }
.queue { display: grid; gap: 1rem; margin-top: 1rem; }

.case-card { padding: 1.25rem; }
.case-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.case-head h2, .case-head h3 { font-size: 1rem; overflow-wrap: anywhere; }
.case-subject { margin: 0.25rem 0 0.75rem; color: var(--ink-2); font-size: 0.92rem; max-width: 75ch; overflow-wrap: anywhere; }

.reason-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 1rem; padding: 0; list-style: none; }
.reason-tags li {
  padding: 0.15rem 0.6rem;
  background: var(--warn-soft);
  border: 1px solid #eddcae;
  border-radius: 999px;
  color: var(--warn);
  font-size: 0.78rem;
  font-weight: 600;
}

.correction-form {
  display: grid;
  gap: 0.85rem;
  padding: 1rem 0;
  border-top: 1px solid var(--surface-2);
}
.correction-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}
.correction-grid .field { display: grid; gap: 0.3rem; }
.correction-grid .field-wide { grid-column: span 2; }
.correction-grid .field-full { grid-column: 1 / -1; }
/* A grid item's automatic minimum size is its content's min-content width, and
   an <input> contributes its intrinsic `size` width (~180px) regardless of
   `max-width: 100%`. In the narrow right-hand review pane the four tracks are
   thinner than that, so without this the fields overflowed their own tracks and
   painted on top of each other. */
.correction-grid .field { min-width: 0; }
.correction-grid input,
.correction-grid textarea { width: 100%; min-width: 0; }
/* The winners row lives in that same narrow pane, so give it tracks that fit
   the control rather than a fixed four-column split: name takes a full row,
   then AFM and the amount share one and stack when the pane gets tight. */
.winner-fieldset .correction-grid {
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
}
.winner-fieldset .correction-grid .field-wide { grid-column: 1 / -1; }
.field-hint { overflow-wrap: anywhere; }
.correction-form textarea { min-height: 4.25rem; }
.form-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.6rem;
}

.decision-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--surface-2);
}
.decision-form .field { display: grid; gap: 0.3rem; flex: 1 1 260px; }
.decision-form input[name="note"] { width: 100%; }

/* ---------- single-case review detail ---------- */

.review-nav { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.case-meta { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin: 0 0 1.25rem; }
.case-meta .reason-tags { margin: 0; }

.review-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}
.review-pdf-pane, .review-form-pane { min-width: 0; }
.review-pdf-pane h2, .review-form-pane h2 { margin: 0 0 0.75rem; font-size: 1rem; }
.review-form-pane h3 { margin: 1.1rem 0 0.5rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.review-form-pane h3:first-of-type { margin-top: 0; }
.review-pdf-frame {
  width: 100%;
  height: 78vh;
  border: 1px solid var(--surface-2);
  border-radius: var(--r-sm);
  background: var(--surface);
}
.winner-fieldset {
  border: 1px solid var(--surface-2);
  border-radius: var(--r-sm);
  padding: 0.75rem 0.85rem 0.4rem;
  margin: 0 0 0.75rem;
}
.winner-fieldset legend { padding: 0 0.4rem; font-size: 0.8rem; color: var(--muted); }
.winner-fieldset-new { border-style: dashed; }
.field-hint { color: var(--muted); font-size: 0.75rem; }
.required-mark { color: var(--danger); }

@media (max-width: 960px) {
  .review-split { grid-template-columns: 1fr; }
  .review-pdf-frame { height: 60vh; }
}

/* ---------- 24h listed-winners widget ---------- */

.recent-listed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  margin: 1rem 0 2rem;
}
.recent-listed-card { padding: 1.1rem; display: grid; gap: 0.6rem; align-content: start; }
.recent-listed-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }

.expandable-field summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}
.expandable-field summary::-webkit-details-marker { color: var(--muted); }
.expandable-field p, .expandable-field ul { margin: 0.4rem 0 0; color: var(--muted); font-size: 0.88rem; overflow-wrap: anywhere; }
.expandable-field ul { padding-left: 1.1rem; }
.expandable-field + .expandable-field { margin-top: 0.1rem; }

.grant-actions { display: flex; justify-content: flex-end; padding-top: 1rem; border-top: 1px solid var(--surface-2); }

.request-meta { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin: 0.5rem 0 0.9rem; color: var(--muted); font-size: 0.8rem; }
.request-note {
  margin: 0.75rem 0;
  padding: 0.6rem 0.9rem;
  background: var(--surface-2);
  border-left: 3px solid var(--line-2);
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

/* ---------- empty states ---------- */

.empty-state {
  display: grid;
  justify-items: center;
  gap: 0.4rem;
  padding: 2.25rem 1rem;
  text-align: center;
  color: var(--muted);
}
.empty-state svg { width: 30px; height: 30px; color: var(--line-2); }
.empty-state strong { color: var(--ink-2); font-size: 0.95rem; }
.empty-state span { font-size: 0.85rem; }
li.empty-state { padding: 1.5rem 0; }

/* ---------- narrow public / auth pages ---------- */

.narrow {
  max-width: 460px;
  margin: 1.5rem auto;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
}
.narrow h1 { font-size: 1.25rem; margin-bottom: 0.25rem; }
.narrow > p { color: var(--ink-2); font-size: 0.92rem; }
.narrow form { margin-top: 1.25rem; }
.narrow button[type="submit"], .narrow form > button { width: 100%; margin-top: 0.5rem; }
.narrow .cf-turnstile { margin: 0.75rem 0; }

.auth-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  margin-bottom: 0.9rem;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-deep);
}
.auth-icon svg { width: 22px; height: 22px; }
.auth-icon.ok { background: var(--ok-soft); color: var(--ok); }

/* two-factor package pages inherit the shell; keep their headings calm */
body.public main.container h1 { font-size: 1.25rem; }

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid, .dashboard-grid.halves { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-aside { order: -1; }
}

@media (max-width: 960px) {
  body.shell { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-1);
  }
  .brand span { display: none; }
  .side-nav {
    flex-direction: row;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0;
    overflow-x: auto;
    min-width: 0;
    -webkit-overflow-scrolling: touch;
  }
  .side-nav a { min-height: 36px; padding: 0.3rem 0.6rem; white-space: nowrap; }
  .nav-group-label { display: none; }
  .sidebar-foot { margin-top: 0; padding-top: 0; border-top: 0; flex-direction: row; align-items: center; }
  .side-account span { display: none; }
  .side-logout button { width: auto; }
  .side-logout button span { display: none; }
  .user-chip { padding: 0; }
  .user-meta { display: none; }

  main.container { padding: 1.5rem 1rem 3rem; }
  .page-heading { flex-direction: column; align-items: stretch; }
  .period-picker, .export-actions { justify-items: start; }
}

@media (max-width: 640px) {
  .cards { grid-template-columns: 1fr; }
  .kpi { min-height: 0; }
  .fin-grid { grid-template-columns: 1fr; }
  .fin-item { border-left: 0; border-top: 1px solid var(--surface-2); }
  .fin-item:first-child { border-top: 0; }
  .run-strip { flex-wrap: wrap; }
  .run-strip-link { margin-left: 0; width: 100%; }
  .filters .field, .filters .field-search { flex: 1 1 100%; }
  .filter-actions { margin-left: 0; width: 100%; justify-content: space-between; }
  .filter-actions button { flex: 1; }
  .pagination { flex-direction: column; align-items: stretch; text-align: center; }
  .page-controls { justify-content: space-between; }
  .correction-grid { grid-template-columns: 1fr; }
  .correction-grid .field-wide,
  .correction-grid .field-full { grid-column: auto; }
  .form-actions { justify-content: stretch; }
  .form-actions button { width: 100%; }
  .decision-form { align-items: stretch; flex-direction: column; }
  .narrow { padding: 1.5rem 1.25rem; margin-top: 0.5rem; }
  .segmented { width: 100%; }
  .segmented a { flex: 1; justify-content: center; }
  .entity-card { flex-direction: column; }
  .entity-title .entity-amount { margin-left: 0; }
  .facts > div { grid-template-columns: 1fr; gap: 0.15rem; }
}

/* ---------- motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
