:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #182326;
  --muted: #5e6b70;
  --line: #d8dfdc;
  --accent: #1d4f5f;
  --accent-strong: #123c49;
  --accent-soft: #dcecee;
  --warn: #8a4b18;
  --warn-soft: #f7eadc;
  --shadow: 0 12px 28px rgba(24, 35, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
select {
  font: inherit;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-inner {
  max-width: 1180px;
  min-height: 64px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-text {
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 760;
}

.brand-subtitle {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.select-field {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.select-field select {
  min-width: 94px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 30px 0 10px;
}

.button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 7px 12px;
  cursor: pointer;
}

.button:hover {
  border-color: var(--accent);
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.button.primary:hover {
  background: var(--accent-strong);
}

.start-checkin {
  width: min(100%, 280px);
  min-height: 48px;
  font-weight: 760;
}

.layout {
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 18px 36px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  gap: 18px;
  align-items: start;
}

.main {
  min-width: 0;
}

.debug-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: sticky;
  top: 82px;
}

.debug-panel[hidden] {
  display: none;
}

.debug-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.debug-header h2 {
  margin: 0;
  font-size: 0.95rem;
}

.debug-body {
  padding: 12px 14px 14px;
}

.debug-list {
  display: grid;
  gap: 9px;
  margin: 0;
}

.debug-row {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 10px;
  font-size: 0.82rem;
}

.debug-row dt {
  color: var(--muted);
}

.debug-row dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.screen {
  display: grid;
  gap: 18px;
}

.section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 14px;
  margin-bottom: 14px;
}

.section-title {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.15;
}

.section-kicker {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.section-copy {
  margin: 8px 0 0;
  color: var(--muted);
  max-width: 68ch;
}

.flow-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.jump-flows {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.jump-flows summary {
  color: var(--accent);
  cursor: pointer;
  font-weight: 760;
}

.jump-flows .flow-grid {
  margin-top: 12px;
}

.flow-card {
  min-height: 146px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 14px;
  text-align: left;
  cursor: pointer;
  display: grid;
  align-content: space-between;
  gap: 14px;
}

.flow-card:hover,
.flow-card:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.flow-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.flow-card h3 {
  margin: 0;
  font-size: 1.02rem;
}

.flow-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.flow-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--muted);
  background: #fff;
  font-size: 0.76rem;
}

.route-panel {
  display: grid;
  gap: 14px;
}

.route-status {
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  padding: 12px;
  border-radius: 6px;
}

.route-status.warning {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}

.route-status h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.route-status p {
  margin: 0;
  color: var(--muted);
}

.stub-list {
  display: grid;
  gap: 10px;
}

.stub-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.stub-item h3 {
  margin: 0;
  font-size: 1rem;
}

.stub-item p {
  margin: 8px 0 10px;
  color: var(--muted);
}

.compact-list {
  display: grid;
  gap: 6px;
  margin: 0;
}

.question-panel {
  display: grid;
  gap: 16px;
}

.question-progress {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.progress-bar {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #e7ece9;
}

.progress-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.section-stepper {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.section-stepper li {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.section-stepper li span {
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 0.76rem;
  font-weight: 800;
}

.section-stepper li strong {
  font-size: 0.82rem;
}

.section-stepper li.current {
  border-color: var(--accent);
  color: var(--ink);
  background: var(--accent-soft);
}

.section-stepper li.complete span,
.section-stepper li.current span {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.question-copy h2 {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.25;
}

.question-copy p {
  margin: 8px 0 0;
  color: var(--muted);
}

.answer-list {
  display: grid;
  gap: 10px;
}

.answer-option {
  width: 100%;
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 12px;
  text-align: left;
  cursor: pointer;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.answer-option:hover,
.answer-option:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.answer-option.selected {
  border-color: var(--accent);
  background: #f0f8f7;
}

.answer-check {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #fff;
  background: #fff;
  font-weight: 800;
}

.answer-option.selected .answer-check {
  border-color: var(--accent);
  background: var(--accent);
}

.answer-body {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.answer-text {
  font-weight: 700;
}

.answer-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.answer-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 2px 7px;
}

.routing-notice {
  border-left: 4px solid var(--warn);
  border-radius: 6px;
  background: var(--warn-soft);
  padding: 12px;
}

.routing-notice h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
}

.routing-notice ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.question-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.result-hero {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 280px);
  gap: 18px;
  align-items: stretch;
  box-shadow: var(--shadow);
}

.result-hero h1 {
  margin: 0;
  font-size: 1.6rem;
  line-height: 1.12;
}

.result-hero p {
  margin: 10px 0 0;
  max-width: 62ch;
}

.result-kicker {
  margin: 0 0 6px;
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.result-cta {
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  padding: 14px;
  display: grid;
  align-content: center;
  gap: 6px;
}

.result-cta span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.result-cta strong {
  font-size: 1.05rem;
}

.result-looks-organized {
  background: #e7f3ec;
  border-color: #94bea4;
}

.result-worth-reviewing {
  background: #edf1fb;
  border-color: #a4b5d9;
}

.result-talk-with-me-before-deciding {
  background: #fff2d7;
  border-color: #d7a94f;
}

.result-high-priority-review {
  background: #fbe7dc;
  border-color: #cf7e51;
}

.result-urgent-route {
  background: #f9dddd;
  border-color: #c84d4d;
}

.result-details {
  display: grid;
  gap: 18px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  display: grid;
  gap: 5px;
}

.metric span {
  color: var(--muted);
  font-size: 0.78rem;
}

.metric strong {
  overflow-wrap: anywhere;
}

.result-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.result-columns h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.flag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.flag-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 5px 8px;
  font-size: 0.78rem;
}

.score-list {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
}

.score-list li {
  padding-left: 2px;
}

.score-list span {
  color: var(--muted);
}

.score-list strong {
  float: right;
  margin-left: 12px;
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

.advisor-summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.advisor-summary summary {
  cursor: pointer;
  font-weight: 760;
}

.advisor-summary p {
  margin: 10px 0 0;
  color: var(--muted);
}

.ask-me-panel {
  display: grid;
  gap: 18px;
}

.ask-me-form {
  display: grid;
  gap: 14px;
}

.field-label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.field-label select,
.field-label textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  font: inherit;
  font-weight: 400;
}

.field-label textarea {
  resize: vertical;
  min-height: 120px;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-weight: 700;
}

.triage-result {
  border: 1px solid var(--line);
  border-left-width: 5px;
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  display: grid;
  gap: 12px;
}

.triage-result h2 {
  margin: 0;
  font-size: 1.15rem;
}

.triage-result p {
  margin: 6px 0 0;
  color: var(--muted);
}

.triage-auto-answer,
.triage-referral {
  border-left-color: #3d7b57;
}

.triage-escalate {
  border-left-color: #7f6a23;
}

.triage-escalate-urgent,
.triage-refusal {
  border-left-color: #b45f33;
}

.surface-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  min-height: 100vh;
  padding: 24px;
  display: grid;
  place-items: center;
  background: #f7f8f6;
}

.crisis-surface {
  background: #f9efef;
}

.safety-surface {
  background: #f4f3ed;
}

.surface-card {
  width: min(100%, 760px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 24px;
  display: grid;
  gap: 16px;
  box-shadow: var(--shadow);
}

.surface-review {
  margin: 0;
  border: 1px solid #d9b56a;
  border-radius: 6px;
  background: #fff8df;
  padding: 9px 10px;
  color: #6b4a00;
  font-size: 0.82rem;
  font-weight: 700;
}

.surface-urgent {
  border-left: 5px solid #b43232;
  border-radius: 6px;
  background: #fae2e2;
  padding: 12px;
  font-size: 1.05rem;
}

.surface-kicker {
  margin: 0;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.surface-card h1 {
  margin: 0;
  font-size: clamp(1.75rem, 3vw, 2.35rem);
  line-height: 1.08;
}

.surface-copy {
  margin: 0;
  color: var(--muted);
  font-size: 1.04rem;
  max-width: 62ch;
}

.surface-actions,
.surface-secondary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.surface-details {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin: 0;
  display: grid;
  gap: 8px;
}

.surface-secondary {
  justify-content: flex-end;
}

.debug-json {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.debug-json summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
}

.debug-json pre {
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f9f8;
  padding: 10px;
  font-size: 0.75rem;
  white-space: pre-wrap;
}

@media (max-width: 880px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .debug-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  .topbar-inner {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .flow-grid {
    grid-template-columns: 1fr;
  }

  .section-header {
    display: grid;
  }

  .question-progress,
  .result-hero,
  .result-columns {
    grid-template-columns: 1fr;
  }

  .question-progress {
    display: grid;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }
}
