/* Application Copilot — mobile-first, single stylesheet, no framework.
   Restraint is deliberate: one accent, one surface ramp, no gradients or
   glass. Density comes from tight type scale and honest spacing, not from
   shrinking hit targets. */

:root {
  color-scheme: dark;

  --ink: #eef1f6;
  --ink-2: #b9c1cf;
  --ink-3: #8b94a5;

  --bg: #0d1015;
  --surface: #141920;
  --surface-2: #1b212a;
  --surface-3: #232b36;
  --line: #2b3441;
  --line-strong: #3a4553;

  --accent: #6ea8ff;
  --accent-ink: #0d1015;
  --accent-soft: #16243c;

  --ok: #6ddba0;
  --ok-soft: #122b1f;
  --warn: #f0c26b;
  --warn-soft: #2e2413;
  --danger: #ff8f8f;
  --danger-soft: #331a1c;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  --tap: 44px;
  --pane-gap: 1px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --ink: #131820; --ink-2: #4a5666; --ink-3: #6b7788;
    --bg: #f5f7fa; --surface: #ffffff; --surface-2: #f0f3f8; --surface-3: #e6ebf2;
    --line: #dde3ec; --line-strong: #c3ccd9;
    --accent: #1f5fd0; --accent-ink: #ffffff; --accent-soft: #e6efff;
    --ok: #1c7d51; --ok-soft: #e3f5ec; --warn: #8a6212; --warn-soft: #fbf1da;
    --danger: #b5322f; --danger-soft: #fbe6e6;
  }
}

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

/* Several components below set an explicit `display`, which would otherwise
   defeat the `hidden` attribute the controller uses to toggle them. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  overflow-wrap: anywhere;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 640; letter-spacing: -0.01em; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.9rem; }
p { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }

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

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  padding: 10px 14px; background: var(--accent); color: var(--accent-ink);
  border-radius: var(--r-md); text-decoration: none; font-weight: 600;
  transition: top 120ms ease;
}
.skip-link:focus { top: 8px; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 14px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-mark {
  width: 26px; height: 26px; flex: none; border-radius: 7px;
  background: var(--accent);
  box-shadow: inset 0 0 0 4px var(--surface);
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }
/* `overflow-wrap: anywhere` on <body> would otherwise break the product name
   mid-word when the top bar gets tight. */
.brand-text strong {
  font-size: 0.95rem; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; overflow-wrap: normal;
}
.brand-text small { color: var(--ink-3); font-size: 0.72rem; white-space: nowrap; }

@media (max-width: 560px) { .brand-text small { display: none; } }

/* Below this the top bar cannot hold three full-width items. Shorten the
   button rather than truncating the product name. */
@media (max-width: 440px) { .btn-word { display: none; } }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.storage-banner {
  margin: 0; padding: 8px 14px;
  background: var(--warn-soft); color: var(--ink);
  border-top: 1px solid var(--line); font-size: 0.8rem;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface-2); color: var(--ink);
  font-size: 0.85rem; font-weight: 560; cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--ink-3); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); border-color: var(--accent); }

.btn-ghost { background: transparent; }
.btn-sm { min-height: 34px; padding: 0 10px; font-size: 0.78rem; }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }

/* ---------- menu ---------- */

.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }

.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  min-width: 232px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-md); box-shadow: 0 12px 28px rgb(0 0 0 / 0.35);
}
.menu-panel button {
  display: block; width: 100%; text-align: left;
  min-height: 40px; padding: 0 10px;
  background: none; border: 0; border-radius: var(--r-sm);
  font-size: 0.85rem; cursor: pointer;
}
.menu-panel button:hover { background: var(--surface-2); }
.menu-panel button.is-danger { color: var(--danger); }
.menu-panel hr { margin: 6px 4px; border: 0; border-top: 1px solid var(--line); }

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 1fr;
  min-height: calc(100dvh - 58px);
}

.pane { min-width: 0; }

/* Mobile: one pane at a time, driven by data-view on <main>. */
@media (max-width: 899px) {
  .layout[data-view="list"] .pane-detail { display: none; }
  .layout[data-view="detail"] .pane-list { display: none; }
}

@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(320px, 380px) 1fr; gap: var(--pane-gap); background: var(--line); }
  .pane { background: var(--bg); }
  .pane-list { position: sticky; top: 58px; align-self: start; max-height: calc(100dvh - 58px); overflow-y: auto; }
}

.pane-head { padding: 16px 14px 10px; }
.pane-sub { color: var(--ink-3); font-size: 0.8rem; margin-top: 2px; }

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

.filters { padding: 0 14px 12px; display: grid; gap: 8px; }

.field-search input {
  width: 100%; min-height: var(--tap); padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
}

.filter-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.filter-row select {
  min-height: 38px; padding: 0 8px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); font-size: 0.8rem;
}

.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--ink-2); min-height: 38px; }
.toggle input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- attention ---------- */

.attention {
  margin: 0 14px 12px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--warn); border-radius: var(--r-md);
}
.attention h3 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); margin-bottom: 6px; }
.attention ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.attention li { font-size: 0.82rem; }
.attention button {
  background: none; border: 0; padding: 4px 0; text-align: left;
  color: var(--ink); cursor: pointer; font-size: 0.82rem; width: 100%;
}
.attention button:hover { color: var(--accent); }
.attention .due { color: var(--ink-3); }
.attention .due.is-overdue { color: var(--warn); font-weight: 600; }

/* ---------- record list ---------- */

.record-list { list-style: none; margin: 0; padding: 0 8px 24px; display: grid; gap: 6px; }

.record-card {
  width: 100%; text-align: left; cursor: pointer;
  display: grid; gap: 6px; padding: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md);
  transition: border-color 120ms ease, background 120ms ease;
}
.record-card:hover { border-color: var(--line-strong); background: var(--surface-2); }
.record-card[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); }

.record-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.record-title { font-weight: 600; font-size: 0.92rem; }
.record-employer { color: var(--ink-2); font-size: 0.8rem; }
.record-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ---------- pills ---------- */

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.01em;
  background: var(--surface-3); color: var(--ink-2);
  border: 1px solid transparent; white-space: nowrap;
}
.pill-neutral { background: var(--surface-3); color: var(--ink-2); }
.pill-active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-synthetic { background: var(--surface-3); color: var(--ink-3); border-color: var(--line-strong); }

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

.empty { padding: 32px 20px; text-align: center; color: var(--ink-2); display: grid; gap: 10px; justify-items: center; }
.empty h2 { color: var(--ink); }
.empty p { max-width: 46ch; font-size: 0.85rem; }
.empty-detail { padding-top: 18vh; }
.empty ol { text-align: left; margin: 4px 0 0; padding-left: 20px; font-size: 0.83rem; color: var(--ink-2); display: grid; gap: 6px; max-width: 46ch; }

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

.detail-head {
  position: sticky; top: 58px; z-index: 10;
  background: var(--bg); border-bottom: 1px solid var(--line);
  padding: 14px 16px 12px; display: grid; gap: 10px;
}
.back-link {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px;
  background: none; border: 0; padding: 0; color: var(--ink-2);
  font-size: 0.82rem; cursor: pointer;
}
.back-link:hover { color: var(--ink); }
@media (min-width: 900px) { .back-link { display: none; } }

.detail-title h2 { font-size: 1.1rem; }
.detail-title .employer { color: var(--ink-2); font-size: 0.88rem; margin-top: 2px; }
.detail-facts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* step rail — makes the current step and next action obvious */
.steps { display: flex; gap: 4px; }
.step {
  flex: 1; min-width: 0; padding: 7px 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); text-align: center;
  font-size: 0.72rem; color: var(--ink-3);
}
.step[data-state="done"] { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.step[data-state="current"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); font-weight: 640; }

.next-action-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: var(--r-md);
}
.next-action-bar .label { font-size: 0.82rem; flex: 1 1 180px; min-width: 0; }
.next-action-bar .label strong { display: block; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); font-weight: 600; }

.detail-body { padding: 14px 16px 40px; display: grid; gap: 12px; }

/* ---------- sections (progressive disclosure) ---------- */

.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.section > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: var(--tap); padding: 10px 14px; cursor: pointer; list-style: none;
  font-weight: 600; font-size: 0.88rem;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary:hover { background: var(--surface-2); }
.section > summary::after {
  content: "›"; color: var(--ink-3); font-size: 1.1rem;
  transform: rotate(90deg); transition: transform 140ms ease; flex: none;
}
.section[open] > summary::after { transform: rotate(-90deg); }
.section-body { padding: 4px 14px 14px; display: grid; gap: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.summary-meta { margin-left: auto; margin-right: 6px; display: flex; gap: 6px; }

/* ---------- fields ---------- */

.field-group { display: grid; gap: 10px; }
.field-group > h3 { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); }

.field { display: grid; gap: 5px; }
.field-label { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 560; }
.field-label .req { color: var(--accent); font-size: 0.68rem; }

.field input[type="text"], .field input[type="date"], .field input[type="url"], .field textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: var(--r-md); resize: vertical;
}
.field textarea { min-height: 92px; line-height: 1.45; }
.field-help { font-size: 0.72rem; color: var(--ink-3); }
.field-foot { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.suggestion {
  display: grid; gap: 6px; padding: 9px 10px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-sm); font-size: 0.8rem;
}
.suggestion-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.suggestion-text { color: var(--ink-2); }
.suggestion-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- evidence ---------- */

.evidence-item {
  display: grid; gap: 4px; padding: 10px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-sm); font-size: 0.82rem;
}
.evidence-item .requirement { font-weight: 560; }
.evidence-item .text { color: var(--ink-2); }
.evidence-item .provenance { font-size: 0.7rem; color: var(--ink-3); font-family: var(--mono); }
.evidence-list { display: grid; gap: 8px; }

.unknown-note {
  font-size: 0.78rem; color: var(--ink-2);
  padding: 9px 10px; border: 1px dashed var(--line-strong);
  border-radius: var(--r-sm); background: transparent;
}

/* ---------- checklist ---------- */

.checklist { display: grid; gap: 6px; }
.check {
  display: grid; grid-template-columns: 18px 1fr; gap: 8px; align-items: start;
  font-size: 0.82rem; padding: 6px 0;
}
.check .mark { font-weight: 700; line-height: 1.4; }
.check[data-status="ready"] .mark { color: var(--ok); }
.check[data-status="attention"] .mark { color: var(--warn); }
.check[data-status="missing"] .mark { color: var(--ink-3); }
.check .detail { color: var(--ink-3); font-size: 0.75rem; }

/* ---------- receipts / history ---------- */

.receipt {
  display: grid; gap: 6px; padding: 11px 12px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-left: 3px solid var(--ok); border-radius: var(--r-sm); font-size: 0.82rem;
}
.receipt-id { font-family: var(--mono); font-size: 0.7rem; color: var(--ink-3); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 0.78rem; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }

.timeline { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.timeline li {
  display: grid; grid-template-columns: 9px 1fr; gap: 10px;
  padding: 7px 0; font-size: 0.8rem; position: relative;
}
.timeline li::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--line-strong); margin-top: 6px;
}
.timeline li:last-child::before { background: var(--accent); }
.timeline .when { color: var(--ink-3); font-size: 0.72rem; }

/* ---------- status actions ---------- */

.status-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- dialog ---------- */

.dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(86dvh, 720px);
  padding: 0; border: 1px solid var(--line-strong);
  border-radius: var(--r-lg); background: var(--surface); color: var(--ink);
}
.dialog::backdrop { background: rgb(0 0 0 / 0.55); }
.dialog-head { padding: 16px 18px 10px; display: grid; gap: 4px; }
.dialog-head p { color: var(--ink-2); font-size: 0.83rem; }
.dialog-body { padding: 4px 18px 12px; display: grid; gap: 12px; overflow-y: auto; max-height: 52dvh; }
.dialog-foot {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px;
  padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2);
}
.dialog-foot .spacer { flex: 1; }

.confirm-check {
  display: grid; grid-template-columns: 20px 1fr; gap: 10px; align-items: start;
  padding: 11px 12px; background: var(--warn-soft);
  border: 1px solid var(--warn); border-radius: var(--r-md); font-size: 0.83rem;
}
.confirm-check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); }

.error-box {
  padding: 11px 12px; background: var(--danger-soft);
  border: 1px solid var(--danger); border-radius: var(--r-md); font-size: 0.82rem;
}
.error-box code { font-family: var(--mono); font-size: 0.75rem; }

/* ---------- toasts ---------- */

.toast-region {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 60;
  display: grid; gap: 8px; width: min(520px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  padding: 11px 14px; border-radius: var(--r-md); font-size: 0.83rem;
  background: var(--surface-3); border: 1px solid var(--line-strong);
  box-shadow: 0 10px 24px rgb(0 0 0 / 0.35);
  animation: toast-in 160ms ease-out;
}
.toast[data-tone="ok"] { border-color: var(--ok); }
.toast[data-tone="error"] { border-color: var(--danger); }

@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

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

/* Narrow phones (320px) and high zoom: drop to a single column everywhere
   and let the filter row wrap rather than overflow. */
@media (max-width: 380px) {
  body { font-size: 14px; }
  .topbar-inner { padding: 8px 10px; }
  .btn { padding: 0 10px; font-size: 0.8rem; }
  .pane-head, .filters, .detail-body { padding-left: 10px; padding-right: 10px; }
  .detail-head { padding-left: 12px; padding-right: 12px; }
  .record-list { padding-left: 6px; padding-right: 6px; }
  .filter-row { display: grid; grid-template-columns: 1fr 1fr; }
  .filter-row .toggle { grid-column: 1 / -1; }
  .steps { flex-wrap: wrap; }
  .step { flex: 1 1 44%; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: 4px; }
}
