/*
 * ABH Intake Portal. Tokens come from brand/tokens.css (ABH).
 * Two faces: the public upload form (calm, one column, phone first) and the
 * staff Intake Inbox (denser, wide tables). Status is always a word, never
 * only a colour.
 */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--surface-page);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--line-height-body);
}
body.public { font-size: 1rem; }

a { color: var(--link); }
h1, h2, h3 {
  font-family: var(--font-heading);
  color: var(--text-heading);
  line-height: var(--line-height-heading);
  margin: 0 0 var(--space-2);
  text-wrap: balance;
}
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-base); margin-top: var(--space-4); }
p { margin: 0 0 var(--space-3); }
:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

.muted { color: var(--text-muted); }
.small { font-size: var(--text-sm); }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.optional { font-weight: var(--font-weight-body); color: var(--text-muted); font-size: var(--text-sm); }
.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;
}

/* ---- shell --------------------------------------------------------------- */
.demo-banner {
  background: var(--demo-banner-bg);
  color: var(--demo-banner-text);
  border-bottom: 2px solid var(--demo-banner-rule);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  text-align: center;
}
.demo-banner a { color: var(--demo-banner-text); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-2) var(--space-5);
  background: var(--surface-header);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex; align-items: center; gap: var(--space-2);
  color: var(--text-header);
  font-family: var(--font-heading); font-weight: var(--font-weight-heading); font-size: var(--text-lg);
  text-decoration: none;
}
.topnav { display: flex; gap: var(--space-1); margin-right: auto; }
.topnav a {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-control);
  color: var(--text); text-decoration: none; font-weight: var(--font-weight-body-strong);
}
.topnav a:hover { background: var(--surface-tint); }
.topnav a[aria-current="page"] { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }

.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.avatar {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: var(--text-on-accent); font-weight: var(--font-weight-heading);
}
.menu-panel {
  position: absolute; right: 0; top: calc(100% + var(--space-2)); min-width: 15rem;
  padding: var(--space-2);
  background: var(--surface-card); border: 1px solid var(--border);
  border-radius: var(--radius-card); box-shadow: var(--shadow-card);
}
.menu-panel a { display: block; padding: var(--space-3); border-radius: var(--radius-control); text-decoration: none; }
.menu-panel a:hover { background: var(--surface-tint); }
.menu-who { margin: 0; padding: var(--space-2) var(--space-3); font-size: var(--text-sm); overflow-wrap: anywhere; }

.page { max-width: 44rem; margin: 0 auto; padding: var(--space-6) var(--space-4) var(--space-8); }
.page-wide { max-width: 76rem; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); }
.page-head p { margin: 0; }
.crumbs { margin: 0 0 var(--space-2); font-size: var(--text-sm); }

.card {
  background: var(--surface-card); border: 1px solid var(--border);
  border-radius: var(--radius-card); box-shadow: var(--shadow-card);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}
.card.narrow { max-width: 34rem; margin: var(--space-8) auto; }
.card > h2:first-child { margin-bottom: var(--space-3); }
.empty { text-align: center; padding: var(--space-8) var(--space-5); }

.flash { padding: var(--space-3) var(--space-4); border-radius: var(--radius-control); margin-bottom: var(--space-4); }
.flash-success { background: var(--status-good-bg); color: var(--status-good); }
.flash-error { background: var(--status-critical-bg); color: var(--status-critical); }

.actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }
.actions.center { justify-content: center; }

/* ---- buttons & fields ------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 40px; padding: var(--space-2) var(--space-4);
  border: 1px solid transparent; border-radius: var(--radius-control);
  font: inherit; font-weight: var(--font-weight-body-strong); text-decoration: none; cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.btn-primary { background: var(--accent); color: var(--text-on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-card); color: var(--accent); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-tint); }
.btn-ghost { background: transparent; color: var(--link); }
.btn-ghost:hover { background: var(--surface-tint); }
.btn-danger { background: var(--status-critical); color: #fff; }
.btn-danger:hover { background: #8f1c13; }
.btn-sm { min-height: 32px; padding: var(--space-1) var(--space-3); font-size: var(--text-sm); }
.btn-lg { min-height: 52px; padding: var(--space-3) var(--space-6); font-size: var(--text-lg); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.65; cursor: progress; }

.field { margin-bottom: var(--space-4); min-width: 0; }
.field label, .field .label, .stack label {
  display: block; margin-bottom: var(--space-1);
  font-weight: var(--font-weight-body-strong);
}
input:not([type="checkbox"]):not([type="file"]), select, textarea {
  width: 100%; min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-control);
  background: var(--surface-card); color: var(--text);
  font: inherit;
}
textarea { resize: vertical; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: var(--status-critical); box-shadow: 0 0 0 1px var(--status-critical);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.field-row .field { margin-bottom: var(--space-2); }
.field-narrow { max-width: 14rem; }
.hint { color: var(--text-muted); font-size: var(--text-sm); margin: var(--space-1) 0 0; }
.field-error { color: var(--status-critical); font-size: var(--text-sm); font-weight: var(--font-weight-body-strong); margin: var(--space-1) 0 0; }
.stack { display: grid; gap: var(--space-2); margin-top: var(--space-3); }
.stack label { margin: 0; }
.inline-form { display: flex; gap: var(--space-2); }
.check { display: flex; gap: var(--space-3); align-items: flex-start; }
.check input { width: 22px; height: 22px; margin-top: 2px; flex: none; accent-color: var(--accent); }
.check label { font-weight: var(--font-weight-body); margin: 0; }
.check-inline { display: inline-flex; align-items: center; gap: var(--space-2); min-height: 44px; }
.check-inline input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---- public upload form --------------------------------------------------- */
.public-header {
  display: flex; justify-content: center;
  padding: var(--space-4);
  background: var(--surface-header); border-bottom: 1px solid var(--border);
}
.public-logo img { display: block; height: 44px; width: auto; }
.public-page { max-width: 40rem; margin: 0 auto; padding: var(--space-6) var(--space-4) var(--space-8); }
.public-intro h1 { font-size: clamp(1.75rem, 1.2rem + 2.2vw, 2.25rem); }
.public-intro p { font-size: 1.0625rem; }

.notice {
  border-left: 4px solid var(--abh-slate);
  background: var(--surface-card);
  padding: var(--space-3) var(--space-4);
  border-radius: 0 var(--radius-control) var(--radius-control) 0;
  margin: var(--space-4) 0 var(--space-6);
}

.error-summary {
  border: 2px solid var(--status-critical); background: var(--status-critical-bg);
  border-radius: var(--radius-card); padding: var(--space-4) var(--space-5); margin-bottom: var(--space-5);
}
.error-summary h2 { color: var(--status-critical); }
.error-summary ul { margin: 0; padding-left: var(--space-5); }
.error-summary a { color: var(--status-critical); font-weight: var(--font-weight-body-strong); }
.error-summary p { margin: var(--space-2) 0 0; }

.upload-form .section {
  border: 1px solid var(--border); border-radius: var(--radius-card);
  background: var(--surface-card); box-shadow: var(--shadow-card);
  padding: var(--space-5); margin: 0 0 var(--space-4);
  min-width: 0;
}
.upload-form legend {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 0 var(--space-2); margin-left: calc(-1 * var(--space-2));
  font-family: var(--font-heading); font-weight: var(--font-weight-heading);
  font-size: var(--text-lg); color: var(--text-heading);
}
.step {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-tint); color: var(--accent); font-size: var(--text-sm);
}
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
  padding: var(--space-6) var(--space-4);
  border: 2px dashed var(--border-strong); border-radius: var(--radius-card);
  background: var(--abh-mist); text-align: center;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.dropzone.is-over { background: var(--surface-tint); border-color: var(--accent); }
.dropzone.is-invalid { border-color: var(--status-critical); }
.dropzone-text { margin: 0; color: var(--text-muted); font-size: var(--text-sm); }
/* Visually hidden but still focusable and operable; the label is the button. */
.js .file-input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.js .file-input:focus-visible + label { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.dropzone label.btn { margin: 0; }

.file-list { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: grid; gap: var(--space-2); }
.file-list li {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--surface-card);
}
.file-list .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.file-list .size { color: var(--text-muted); font-size: var(--text-sm); font-variant-numeric: tabular-nums; white-space: nowrap; }
.file-list .problem { color: var(--status-critical); font-size: var(--text-sm); display: block; }
.file-list li.is-bad { border-color: var(--status-critical); background: var(--status-critical-bg); }
.file-list button {
  border: 0; background: none; color: var(--link); cursor: pointer; font: inherit; font-size: var(--text-sm);
  min-height: 32px; padding: 0 var(--space-2); border-radius: var(--radius-sm);
}
.file-list button:hover { background: var(--surface-tint); }

.submit-row { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); margin-top: var(--space-5); }
.secure-note { margin: 0; }
.public-footer { margin-top: var(--space-6); }

.thanks { text-align: center; padding: var(--space-8) var(--space-6); }
.thanks-mark {
  display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 50%;
  background: var(--status-good-bg); color: var(--status-good);
  font-size: 1.75rem; font-weight: var(--font-weight-heading); margin-bottom: var(--space-3);
}
.ref-box {
  display: inline-flex; flex-direction: column; gap: var(--space-1);
  margin: var(--space-3) 0; padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-card); background: var(--surface-tint);
}
.ref { font-family: var(--font-heading); font-size: var(--text-2xl); letter-spacing: 0.06em; color: var(--text-heading); font-variant-numeric: tabular-nums; }

/* ---- inbox ----------------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-3); margin-bottom: var(--space-5); }
.kpi {
  display: flex; flex-direction: column;
  background: var(--surface-card); border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: var(--space-4); box-shadow: var(--shadow-card);
}
.kpi-label { font-size: var(--text-sm); color: var(--text-muted); font-weight: var(--font-weight-body-strong); }
.kpi-value { font-family: var(--font-heading); font-size: var(--text-kpi); font-weight: var(--font-weight-heading); color: var(--text-heading); line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: var(--text-sm); color: var(--text-muted); }

.tabs { display: flex; flex-wrap: wrap; gap: var(--space-1); border-bottom: 1px solid var(--border); margin-bottom: var(--space-4); }
.tabs a {
  padding: var(--space-2) var(--space-3); color: var(--text); text-decoration: none;
  font-weight: var(--font-weight-body-strong); border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--accent); }
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .count {
  display: inline-block; min-width: 1.5rem; padding: 0 var(--space-1); margin-left: var(--space-1);
  border-radius: 999px; background: var(--surface-tint); color: var(--text-muted);
  font-size: var(--text-xs); text-align: center; font-variant-numeric: tabular-nums;
}

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); margin-bottom: var(--space-4); }
.filters .field { margin: 0; flex: 1 1 14rem; max-width: 24rem; }
.filters .field label { font-size: var(--text-sm); }

.table-wrap { overflow-x: auto; background: var(--surface-card); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow-card); }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th {
  text-align: left; font-weight: var(--font-weight-subheading); color: var(--text-muted);
  padding: var(--space-3); border-bottom: 1px solid var(--border-strong); background: var(--surface-card);
  white-space: nowrap;
}
.table td { padding: var(--space-3); border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { position: relative; }
.table tbody tr:hover { background: var(--abh-mist); }
.table tr.is-new td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.row-link { font-weight: var(--font-weight-body-strong); font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-link::after { content: ""; position: absolute; inset: 0; }
.table-dense td { padding: var(--space-2) var(--space-3); }

.pill {
  display: inline-block; padding: 2px var(--space-2); border-radius: 999px;
  font-size: var(--text-xs); font-weight: var(--font-weight-body-strong); white-space: nowrap;
}
.pill-lg { font-size: var(--text-sm); padding: var(--space-1) var(--space-3); }
.pill-new { background: var(--surface-tint); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.pill-in_review { background: var(--status-warn-bg); color: var(--status-warn); }
.pill-filed { background: var(--status-good-bg); color: var(--status-good); }
.pill-rejected { background: var(--status-neutral-bg); color: var(--status-neutral); }
.pill-neutral { background: var(--status-neutral-bg); color: var(--status-neutral); }

.pager { display: flex; justify-content: center; align-items: center; gap: var(--space-4); margin-top: var(--space-4); }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 20rem; gap: var(--space-4); align-items: start; }
.files { list-style: none; margin: 0 0 var(--space-2); padding: 0; display: grid; gap: var(--space-2); }
.file { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-control); }
.file-icon {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: var(--radius-control);
  background: var(--surface-tint); color: var(--accent); font-size: var(--text-xs); font-weight: var(--font-weight-heading);
}
.file-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-name { font-weight: var(--font-weight-body-strong); overflow-wrap: anywhere; }
.file-actions { display: flex; gap: var(--space-2); flex: none; }
.scan-ok { color: var(--status-good); }
.scan-bad { color: var(--status-critical); font-weight: var(--font-weight-body-strong); }
.scan-wait { color: var(--status-warn); }

.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3) var(--space-5); margin: 0; }
.facts div { min-width: 0; }
.facts dt { font-size: var(--text-sm); color: var(--text-muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.message { margin: 0; padding: var(--space-3) var(--space-4); background: var(--abh-mist); border-left: 3px solid var(--border-strong); white-space: pre-wrap; }

.note { padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
.note-meta { margin: 0 0 var(--space-1); }
.note-body { margin: 0; white-space: pre-wrap; }
.note-form { display: grid; gap: var(--space-2); margin-top: var(--space-3); justify-items: start; }

.detail-side .card { padding: var(--space-4); }
.detail-side form + form { margin-top: var(--space-3); }
.reject { margin-top: var(--space-3); }
.reject summary, .danger-zone summary { cursor: pointer; color: var(--link); font-size: var(--text-sm); }
.danger-zone summary { color: var(--status-critical); font-weight: var(--font-weight-body-strong); }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); max-height: 22rem; overflow-y: auto; }
.timeline li { display: flex; flex-direction: column; padding-left: var(--space-3); border-left: 2px solid var(--border); }

.picker { list-style: none; padding: 0; display: grid; gap: var(--space-2); }
.picker .btn { justify-content: flex-start; }

/* ---- responsive ------------------------------------------------------------ */
@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .field-row { grid-template-columns: 1fr; }
  .field-narrow { max-width: none; }
  .kpis { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; padding: var(--space-2) var(--space-4); }
  .topnav { order: 3; width: 100%; overflow-x: auto; }
  .page-head { flex-direction: column; }
  .upload-form .section { padding: var(--space-4); }
  .btn-lg { width: 100%; }
  .file { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
