:root {
  color-scheme: light;
  --neutral-1: oklch(98% 0.006 250);
  --neutral-2: oklch(96% 0.008 250);
  --neutral-3: oklch(92% 0.01 250);
  --neutral-4: oklch(85% 0.012 250);
  --neutral-5: oklch(72% 0.014 250);
  --neutral-6: oklch(58% 0.016 250);
  --neutral-7: oklch(45% 0.018 250);
  --neutral-8: oklch(31% 0.02 250);
  --neutral-9: oklch(20% 0.022 250);
  --blue-1: oklch(97% 0.02 252);
  --blue-2: oklch(93% 0.04 252);
  --blue-3: oklch(87% 0.07 252);
  --blue-4: oklch(79% 0.1 252);
  --blue-5: oklch(69% 0.14 252);
  --blue-6: oklch(58% 0.18 252);
  --blue-7: oklch(49% 0.19 252);
  --blue-8: oklch(39% 0.15 252);
  --blue-9: oklch(29% 0.1 252);
  --green-1: oklch(97% 0.02 155);
  --green-5: oklch(67% 0.14 155);
  --green-8: oklch(36% 0.09 155);
  --amber-1: oklch(97% 0.03 82);
  --amber-5: oklch(74% 0.15 82);
  --amber-8: oklch(42% 0.1 82);
  --red-1: oklch(97% 0.02 25);
  --red-5: oklch(65% 0.19 25);
  --red-8: oklch(38% 0.13 25);
  --surface: var(--neutral-1);
  --surface-raised: oklch(100% 0 0);
  --surface-muted: var(--neutral-2);
  --text: var(--neutral-9);
  --text-muted: var(--neutral-7);
  --text-faint: var(--neutral-6);
  --line: var(--neutral-3);
  --primary: var(--blue-7);
  --primary-hover: var(--blue-8);
  --primary-soft: var(--blue-1);
  --focus: var(--blue-6);
  --success: var(--green-8);
  --success-soft: var(--green-1);
  --warning: var(--amber-8);
  --warning-soft: var(--amber-1);
  --danger: var(--red-8);
  --danger-soft: var(--red-1);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;
  --space-16: 64px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-raised: 0 1px 2px oklch(20% 0.02 250 / 0.08), 0 8px 24px oklch(20% 0.02 250 / 0.06);
  --shadow-floating: 0 2px 4px oklch(20% 0.02 250 / 0.1), 0 16px 48px oklch(20% 0.02 250 / 0.14);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

* { box-sizing: border-box; }

html { background: var(--surface); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background: var(--surface);
  font-weight: 400;
}

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

button, a { -webkit-tap-highlight-color: transparent; }

button { user-select: none; }

a { color: var(--primary); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 20;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--neutral-9);
  color: var(--surface-raised);
  transform: translateY(-200%);
}

.skip-link:focus { transform: translateY(0); }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 72px;
  padding: var(--space-3) var(--space-6);
  background: var(--surface-raised);
  box-shadow: 0 1px 0 var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--neutral-9);
  color: var(--surface-raised);
  font-size: 20px;
  font-weight: 600;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; font-weight: 600; }
.brand small { color: var(--text-muted); font-size: 16px; }

.primary-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: var(--space-1);
  padding: 0 var(--space-6);
  overflow-x: auto;
  background: var(--surface-raised);
  box-shadow: 0 1px 0 var(--line);
}

.primary-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 0 var(--space-4);
  color: var(--text-muted);
  text-decoration: none;
  box-shadow: inset 0 -2px transparent;
}

.primary-nav a[aria-current="page"] {
  color: var(--text);
  box-shadow: inset 0 -2px var(--primary);
}

main {
  width: 100%;
  max-width: 1440px;
  min-height: calc(100vh - 120px);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-16);
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(32px, 5vw, 48px); line-height: 1.1; font-weight: 600; letter-spacing: -0.02em; }
h2, h3 { font-size: 20px; line-height: 1.2; font-weight: 600; }
p { max-width: 72ch; }

.page-header { margin-bottom: var(--space-8); }
.page-header h1 { margin-bottom: var(--space-2); }
.page-header p { color: var(--text-muted); }

.attention-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: var(--space-8);
  padding: var(--space-8);
  border-radius: var(--radius-lg);
  background: var(--neutral-9);
  color: var(--surface-raised);
  box-shadow: var(--shadow-raised);
}

.attention-strip h1 { margin: var(--space-4) 0 var(--space-3); }
.attention-strip p { color: var(--neutral-4); }

.hero-metric {
  min-width: 192px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.hero-metric strong { display: block; font-size: 48px; line-height: 1; font-weight: 600; }
.hero-metric span { color: var(--neutral-4); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.metric-card, .stockpile-card, .panel, .action-card, .evidence-card, .output-card {
  background: var(--surface-raised);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-raised);
}

.metric-card { padding: var(--space-6); }
.metric-card .metric-value { display: block; margin: var(--space-2) 0; font-size: 32px; line-height: 1.1; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric-card p, .metric-label, .metric-basis { color: var(--text-muted); }
.metric-basis { display: flex; justify-content: space-between; gap: var(--space-3); align-items: end; }
.sparkline { width: 96px; height: 32px; color: var(--primary); }
.sparkline polyline { fill: none; stroke: currentColor; stroke-width: 2; vector-effect: non-scaling-stroke; }

.section { margin-top: var(--space-8); }
.section-header { display: flex; align-items: end; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-3); }
.section-header p { color: var(--text-muted); }

.stockpile-grid, .action-list, .evidence-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.stockpile-card, .action-card, .evidence-card, .output-card { padding: var(--space-6); }
.card-heading { display: flex; justify-content: space-between; align-items: start; gap: var(--space-4); margin-bottom: var(--space-6); }
.card-heading p { color: var(--text-muted); }

.status-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-2); }
.status-cell { padding: var(--space-3); border-radius: var(--radius-sm); background: var(--surface-muted); }
.status-cell span { display: block; color: var(--text-muted); }
.status-cell strong { display: block; margin-top: var(--space-1); font-weight: 600; text-transform: capitalize; }
.status-cell[data-state="confirmed"], .status-cell[data-state="sent"] { background: var(--success-soft); color: var(--success); }
.status-cell[data-state="needed"], .status-cell[data-state="due"] { background: var(--warning-soft); color: var(--warning); }
.status-cell[data-state="blocked"] { background: var(--danger-soft); color: var(--danger); }

.progress-row { display: flex; justify-content: space-between; gap: var(--space-4); margin-top: var(--space-4); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.progress-track { display: block; width: 100%; height: 8px; margin-top: var(--space-2); overflow: hidden; border: 0; border-radius: var(--radius-sm); background: var(--neutral-3); color: var(--primary); }
.progress-track::-webkit-progress-bar { background: var(--neutral-3); }
.progress-track::-webkit-progress-value { background: var(--primary); }
.progress-track::-moz-progress-bar { background: var(--primary); }

.panel { overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: var(--space-3) var(--space-4); text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { position: sticky; top: 0; background: var(--surface-muted); color: var(--text-muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
.number { text-align: right; }
.table-action { text-align: right; }

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: var(--space-1) var(--space-3);
  border-radius: 32px;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-weight: 600;
}
.chip::before { content: ""; width: 8px; height: 8px; margin-right: var(--space-2); border-radius: 50%; background: currentColor; }
.chip.success { background: var(--success-soft); color: var(--success); }
.chip.warning { background: var(--warning-soft); color: var(--warning); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.attention-strip .chip { background: var(--warning-soft); color: var(--warning); }

.primary-button, .secondary-button, .text-button {
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  border: 0;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: transform 140ms cubic-bezier(0.23, 1, 0.32, 1), background-color 140ms cubic-bezier(0.23, 1, 0.32, 1);
}
.primary-button { background: var(--primary); color: var(--surface-raised); }
.secondary-button { background: var(--surface-muted); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.text-button { background: transparent; color: var(--primary); }
.primary-button:disabled, .secondary-button:disabled { cursor: not-allowed; opacity: 0.45; }
.primary-button:active:not(:disabled), .secondary-button:active:not(:disabled), .text-button:active { transform: scale(0.97); }
kbd { padding: var(--space-1) var(--space-2); border-radius: var(--space-1); background: var(--neutral-2); color: var(--text-muted); font: inherit; }

.action-card, .evidence-card { display: flex; flex-direction: column; gap: var(--space-3); }
.action-card p, .evidence-card p, .output-card p { color: var(--text-muted); }
.action-meta, .evidence-meta, .output-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-3); margin-top: auto; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.action-card a { align-self: start; min-height: 44px; display: inline-flex; align-items: center; font-weight: 600; }

.search-field { display: block; width: 100%; max-width: 480px; margin-bottom: var(--space-4); }
.search-field span { display: block; margin-bottom: var(--space-2); font-weight: 600; }
.search-field input { width: 100%; min-height: 44px; padding: var(--space-2) var(--space-3); border: 1px solid var(--neutral-4); border-radius: var(--radius-sm); background: var(--surface-raised); color: var(--text); }
.hash { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-variant-numeric: tabular-nums; }

.output-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 2fr); gap: var(--space-4); }
.schedule-section { margin-top: 0; margin-bottom: var(--space-8); }
.schedule-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); padding: var(--space-6); gap: var(--space-4); }
.schedule-grid span, .schedule-grid strong { display: block; }
.schedule-grid span { color: var(--text-muted); }
.schedule-grid strong { margin-top: var(--space-1); font-variant-numeric: tabular-nums; }
.scheduled-download { display: inline-flex; align-items: center; margin-top: var(--space-4); text-decoration: none; }
.draft-readback { margin-top: var(--space-3); color: var(--text-muted); }
.output-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); }
.output-card .primary-button { display: inline-flex; align-items: center; margin-top: var(--space-6); text-decoration: none; }
.report-preview { margin: 0; padding: var(--space-4); overflow: auto; border-radius: var(--radius-sm); background: var(--neutral-9); color: var(--neutral-2); font: 16px/1.5 ui-monospace, "SFMono-Regular", Consolas, monospace; }

.empty-state, .error-state { padding: var(--space-12) var(--space-6); text-align: center; border-radius: var(--radius-md); background: var(--surface-raised); box-shadow: var(--shadow-raised); }
.empty-state p, .error-state p { margin: var(--space-2) auto var(--space-4); color: var(--text-muted); }
.error-state { color: var(--danger); }

dialog { width: min(560px, calc(100% - 32px)); padding: 0; border: 0; border-radius: var(--radius-lg); background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow-floating); }
dialog::backdrop { background: oklch(20% 0.02 250 / 0.48); }
dialog[open] { animation: dialog-in 180ms cubic-bezier(0.23, 1, 0.32, 1); transform-origin: center; }
.command-dialog[open] { animation: none; }
@keyframes dialog-in { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.dialog-header { display: flex; align-items: start; justify-content: space-between; gap: var(--space-4); padding: var(--space-6); box-shadow: 0 1px 0 var(--line); }
.dialog-header p { color: var(--text-muted); }
.command-list { padding: var(--space-2); }
.command-list a { display: flex; align-items: center; justify-content: space-between; min-height: 48px; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); color: var(--text); text-decoration: none; }
.commit-dialog form { padding-bottom: var(--space-6); }
.weight-check { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); margin: var(--space-6); padding: var(--space-4); border-radius: var(--radius-md); background: var(--surface-muted); }
.weight-check span, .weight-check strong { display: block; text-align: right; }
.weight-check span { color: var(--text-muted); }
.weight-check strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.confirmation-check { display: flex; gap: var(--space-3); margin: 0 var(--space-6) var(--space-4); }
.confirmation-check input { flex: 0 0 24px; width: 24px; height: 24px; margin: 0; }
.commit-dialog .primary-button { width: calc(100% - 48px); margin: 0 var(--space-6); }
.inline-error { margin: 0 var(--space-6) var(--space-4); padding: var(--space-3); border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); }
.warning-box { margin: 0 var(--space-6) var(--space-4); padding: var(--space-3); border-radius: var(--radius-sm); background: var(--warning-soft); color: var(--warning); }
.warning-box p { margin-top: var(--space-1); }
.toast { position: fixed; left: 50%; bottom: var(--space-6); z-index: 30; max-width: calc(100% - 32px); padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); background: var(--neutral-9); color: var(--surface-raised); box-shadow: var(--shadow-floating); transform: translateX(-50%); }

.intake-form { display: grid; gap: var(--space-6); max-width: 720px; }
.form-section { padding: var(--space-6); border-radius: var(--radius-md); background: var(--surface-raised); box-shadow: var(--shadow-raised); }
.form-field { display: block; margin-top: var(--space-4); }
.form-field > span { display: block; margin-bottom: var(--space-2); font-weight: 600; }
.form-field input, .form-field select, .form-field textarea {
  width: 100%; min-height: 44px; padding: var(--space-2) var(--space-3); border: 1px solid var(--neutral-4);
  border-radius: var(--radius-sm); background: var(--surface-raised); color: var(--text);
}
.form-field textarea { min-height: 96px; resize: vertical; }
.ticket-preview { display: grid; place-items: center; min-height: 240px; margin-top: var(--space-4); overflow: hidden; border-radius: var(--radius-md); background: var(--surface-muted); }
.ticket-preview img { display: block; width: 100%; max-height: 480px; object-fit: contain; }
.empty-preview { color: var(--text-muted); }
.form-error { margin: 0; }
.intake-form > .primary-button { justify-self: start; }

.timeline { margin: 0; padding: 0; list-style: none; }
.timeline li { display: grid; grid-template-columns: 192px minmax(0, 1fr); gap: var(--space-4); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--text-muted); font-variant-numeric: tabular-nums; }

.skeleton-view { display: grid; gap: var(--space-4); }
.skeleton-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.skeleton { min-height: 144px; border-radius: var(--radius-md); background: var(--neutral-3); animation: pulse 1200ms ease-in-out infinite alternate; }
.skeleton-wide { min-height: 240px; }
@keyframes pulse { to { opacity: 0.45; } }

@media (hover: hover) and (pointer: fine) {
  .primary-button:hover:not(:disabled) { background: var(--primary-hover); }
  .secondary-button:hover:not(:disabled), .command-list a:hover { background: var(--neutral-3); }
  .text-button:hover { background: var(--primary-soft); }
}

@media (max-width: 800px) {
  .app-header { padding: var(--space-3) var(--space-4); }
  .command-trigger kbd { display: none; }
  .primary-nav { padding: 0 var(--space-2); }
  main { padding: var(--space-6) var(--space-4) var(--space-16); }
  .attention-strip { grid-template-columns: 1fr; gap: var(--space-6); padding: var(--space-6); }
  .hero-metric { min-width: 0; text-align: left; }
  .metric-grid, .stockpile-grid, .action-list, .evidence-list, .output-layout, .output-list, .schedule-grid { grid-template-columns: 1fr; }
  .status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-wrap { overflow: visible; }
  table, tbody { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tr { display: block; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); }
  tbody tr:last-child { border-bottom: 0; }
  td { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: var(--space-3); padding: var(--space-1) 0; border: 0; white-space: normal; text-align: left; }
  td::before { content: attr(data-label); color: var(--text-muted); }
  .table-action { padding-top: var(--space-3); }
  .timeline li { grid-template-columns: 1fr; gap: var(--space-1); }
}

@media (max-width: 480px) {
  .brand small { display: none; }
  .command-trigger { padding: var(--space-2) var(--space-3); }
  .metric-grid { grid-template-columns: 1fr; }
  .weight-check { grid-template-columns: 1fr; }
  .weight-check span, .weight-check strong { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  .primary-button:active:not(:disabled), .secondary-button:active:not(:disabled), .text-button:active { transform: none; }
}

.known-details { margin: 0.75rem 0 1rem; display: grid; gap: 0.5rem; }
.known-details dt { font-weight: 700; }
.transition-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-2); align-items: center; margin-bottom: var(--space-3); }
.field-feedback.valid { color: #166534; }
.field-feedback.invalid { color: #b91c1c; }
.seals-unit { border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--space-3); margin-top: var(--space-2); }
.warning-panel { border: 2px solid #b45309; background: #fffbeb; padding: var(--space-4); border-radius: var(--radius-md); margin-bottom: var(--space-4); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
