/* SARS Audit dashboard — light/dark, table-first. */
:root {
  --surface: #ffffff;
  --surface-sunken: #f4f6f8;
  --surface-raised: #ffffff;
  --border: #dfe3e8;
  --border-strong: #c4cad2;
  --ink: #16202b;
  --ink-secondary: #4a5763;
  --ink-muted: #78838f;
  --accent: #1f5f8b;
  --accent-soft: #e6eff6;
  --good: #1d7a54;
  --warn: #8a5a00;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 4px 12px rgba(16, 32, 48, .05);
  --radius: 8px;
}
:root[data-theme="dark"] {
  --surface: #12171d;
  --surface-sunken: #0d1116;
  --surface-raised: #1a2028;
  --border: #2a323c;
  --border-strong: #3a444f;
  --ink: #e8edf2;
  --ink-secondary: #aeb9c4;
  --ink-muted: #7d8894;
  --accent: #6fb3dd;
  --accent-soft: #1b2c39;
  --good: #5fc79a;
  --warn: #d6a44a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 12px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  background: var(--surface-sunken);
  color: var(--ink);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand a { display: flex; align-items: baseline; gap: 10px; color: inherit; }
.brand a:hover { text-decoration: none; }
.brand-mark {
  font-weight: 700; letter-spacing: .06em; font-size: 15px;
  color: #fff; background: var(--accent);
  padding: 3px 8px; border-radius: 5px;
}
.brand-text { font-weight: 600; color: var(--ink-secondary); }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

main { padding: 20px; max-width: 1800px; margin: 0 auto; }

/* -------------------------------------------------------------- buttons */
.btn {
  font: inherit; cursor: pointer;
  padding: 7px 12px; border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface-raised); color: var(--ink);
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-secondary); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { color: #fff; filter: brightness(1.08); }
.btn-danger { border-color: transparent; background: transparent; color: var(--ink-muted); }
.btn-danger:hover { color: #b4331f; border-color: #b4331f; }

/* ---------------------------------------------------------- stat tiles */
.stats {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.stat {
  background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px;
}
.stat-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-muted); font-weight: 600;
}
.stat-value {
  font-size: 24px; font-weight: 650; line-height: 1.1;
  font-variant-numeric: tabular-nums; color: var(--ink);
}

/* ------------------------------------------------------------- filters */
.filters {
  background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.filter-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filter-row + .filter-row { margin-top: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 140px; }
.field-grow { flex: 1 1 320px; }
.field-inline { flex-direction: row; align-items: center; gap: 6px; min-width: 0; }
.field > span {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-muted); font-weight: 600; white-space: nowrap;
}
input, select {
  font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 6px; padding: 7px 9px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

/* --------------------------------------------------------------- table */
/* The grid scrolls inside its own box in both directions, so the sticky header
   pins to the top of the table rather than to the page. */
.table-wrap {
  background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: auto; max-height: calc(100vh - 330px); min-height: 260px;
}
.grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.grid th, .grid td {
  padding: 9px 12px; text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.grid thead th {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface); color: var(--ink-secondary);
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  font-weight: 700; cursor: pointer; user-select: none;
  border-bottom: 2px solid var(--border-strong);
}
.grid thead th:hover { color: var(--accent); }
.grid thead th[data-active]::after { content: " ▲"; font-size: 9px; }
.grid thead th[data-active="desc"]::after { content: " ▼"; }
.grid tbody tr:hover { background: var(--accent-soft); }
.grid td.num, .grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.grid td.empty { text-align: center; color: var(--ink-muted); padding: 32px; }

.ref { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.ref.has-doc { font-weight: 600; }
.ref.has-doc::after { content: " ▸"; color: var(--good); }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 650; letter-spacing: .02em;
  border: 1px solid var(--border-strong); color: var(--ink-secondary);
}
.pill-voc { border-color: var(--warn); color: var(--warn); }
.pill-doc { border-color: var(--good); color: var(--good); }
.pill-instruction { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.doc-instruction { border-color: var(--accent); background: var(--accent-soft); }
.doc-instruction .doc-name { flex-basis: 100%; }
.doc-instruction-banner, .doc-entryexit-banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin-top: 12px; padding: 12px 14px;
  border: 1px solid var(--accent); border-radius: 8px; background: var(--accent-soft);
}
.doc-instruction-banner .doc-name, .doc-entryexit-banner .doc-name {
  font-weight: 600; margin-right: auto; word-break: break-all;
}
.doc-entryexit-banner { border-color: var(--good); }
.pill-entryexit { border-color: var(--good); color: var(--good); background: var(--accent-soft); }
.pack-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }

/* --------------------------------------------------------------- pager */
.pager {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 14px; padding-bottom: 8px;
}
.pager-info { color: var(--ink-secondary); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------- entry page */
.card {
  background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-muted); }
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 24px; font-family: ui-monospace, Consolas, monospace; }
.detail-grid { display: grid; gap: 12px 24px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.detail dt { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-muted); font-weight: 600; }
.detail dd { margin: 2px 0 0; word-break: break-word; }
.doc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.doc-list li {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface);
}
.doc-name { font-weight: 600; flex: 1 1 240px; word-break: break-all; }
.doc-meta { color: var(--ink-muted); font-size: 12px; }
.viewer { width: 100%; height: 78vh; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.muted { color: var(--ink-muted); }

/* --------------------------------------------------------------- modal */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 18, 26, .55);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--surface-raised); border-radius: var(--radius);
  width: min(980px, 100%); max-height: 88vh; display: flex; flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 8px 18px 18px; overflow: auto; }

/* --------------------------------------------------------------- admin */
.dropzone {
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  padding: 40px 20px; text-align: center; color: var(--ink-secondary);
  background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.progress { margin-top: 14px; }
.progress[hidden] { display: none; }
.progress-bar {
  height: 8px; border-radius: 999px; overflow: hidden;
  background: var(--surface-sunken); border: 1px solid var(--border);
}
.progress-bar span {
  display: block; height: 100%; width: 0;
  background: var(--accent); transition: width .25s ease;
}
.progress-text {
  margin-top: 6px; font-size: 12px; color: var(--ink-secondary);
  font-variant-numeric: tabular-nums;
}

.audit-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.audit-cards {
  display: grid; gap: 10px; margin-top: 14px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.mini {
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  background: var(--surface); display: flex; flex-direction: column; gap: 4px;
}
.mini-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-muted); font-weight: 600;
}
.mini-value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.mini-value.ok { color: var(--good); }
.mini-value.bad { color: #b4331f; }
.mini-value.warn { color: var(--warn); }
:root[data-theme="dark"] .mini-value.bad { color: #f2a99c; }

.login-wrap { max-width: 380px; margin: 12vh auto; }
.notice { padding: 10px 12px; border-radius: 6px; background: var(--accent-soft); color: var(--ink-secondary); }
.notice-error { background: #fdeceb; color: #a3291a; }
:root[data-theme="dark"] .notice-error { background: #3a1a16; color: #f2a99c; }
.upload-log { list-style: none; margin: 12px 0 0; padding: 0; font-size: 13px; display: grid; gap: 4px; }
.upload-log li::before { content: "• "; }
.upload-log .ok { color: var(--good); }
.upload-log .warn { color: var(--warn); }
.upload-log .bad { color: #b4331f; }

.footer { padding: 20px; text-align: center; color: var(--ink-muted); font-size: 12px; }

@media (max-width: 720px) {
  main { padding: 12px; }
  .table-wrap { max-height: 60vh; }
  .stat-value { font-size: 20px; }
}
