:root {
  --ink: #17211f;
  --muted: #60706c;
  --line: #d5dedb;
  --surface: #ffffff;
  --surface-soft: #f2f6f4;
  --teal: #087f6b;
  --teal-dark: #056252;
  --teal-soft: #dff2ec;
  --yellow: #e7b943;
  --yellow-soft: #fff4cf;
  --red: #b93832;
  --red-soft: #fbe9e7;
  --focus: #1269d3;
  --shadow: 0 8px 24px rgba(23, 33, 31, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--surface-soft);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  margin: 0;
  min-width: 320px;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  background: var(--ink);
  color: white;
  left: 16px;
  padding: 10px 14px;
  position: fixed;
  top: -60px;
  z-index: 20;
}

.skip-link:focus {
  top: 12px;
}

.app-header {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 72px;
  padding: 12px 28px;
}

.brand-block {
  align-items: center;
  display: flex;
  gap: 12px;
}

.brand-mark {
  align-items: center;
  background: var(--ink);
  border-radius: 6px;
  color: white;
  display: flex;
  font-size: 21px;
  font-weight: 800;
  height: 42px;
  justify-content: center;
  width: 42px;
}

.brand-block strong,
.brand-block span {
  display: block;
  letter-spacing: 0;
}

.brand-block strong {
  font-size: 19px;
}

.brand-block span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.header-status {
  align-items: center;
  display: flex;
  gap: 10px;
}

.profile-button {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  max-width: 240px;
  min-height: 32px;
  overflow: hidden;
  padding: 6px 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-button:hover {
  background: var(--surface-soft);
}

.mode-badge,
.voice-status,
.risk-badge,
.source-badge,
.trace-count,
.memory-badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
  padding: 7px 9px;
}

.mode-badge {
  background: var(--yellow-soft);
  color: #6b5012;
}

.voice-status {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  color: var(--muted);
}

.voice-status[data-status="authorized"],
.voice-status[data-status="used"] {
  background: var(--teal-soft);
  border-color: #a3d8ca;
  color: var(--teal-dark);
}

.simulation-notice {
  background: var(--yellow-soft);
  border-bottom: 1px solid #ead489;
  color: #604c19;
  font-size: 13px;
  font-weight: 650;
  padding: 8px 28px;
  text-align: center;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 410px);
  margin: 0 auto;
  max-width: 1440px;
  min-height: calc(100vh - 105px);
}

.patient-workspace {
  background: var(--surface);
  min-width: 0;
  padding: 32px clamp(22px, 5vw, 72px) 44px;
}

.trace-panel {
  border-left: 1px solid var(--line);
  min-width: 0;
  padding: 32px 26px;
}

.progress-row {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 13px;
  font-weight: 700;
  gap: 14px;
  margin-bottom: 36px;
}

.progress-track {
  background: #e5ece9;
  height: 5px;
  max-width: 340px;
  overflow: hidden;
  width: 45%;
}

.progress-track span {
  background: var(--teal);
  display: block;
  height: 100%;
  transition: width 180ms ease;
  width: 6%;
}

.decision-surface {
  margin: 0 auto;
  max-width: 820px;
  min-height: 470px;
}

.eyebrow {
  color: var(--teal-dark);
  display: block;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 7px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  letter-spacing: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.2;
  margin: 0 0 12px;
}

h2 {
  font-size: 20px;
  line-height: 1.3;
  margin: 0;
}

h3 {
  font-size: 16px;
  margin: 0;
}

.lead {
  color: var(--muted);
  font-size: 17px;
  line-height: 1.55;
  margin: 0 0 28px;
  max-width: 650px;
}

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

.button {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: inline-flex;
  font-weight: 750;
  justify-content: center;
  min-height: 54px;
  padding: 13px 18px;
}

.button-primary {
  background: var(--teal);
  border-color: var(--teal);
  color: white;
}

.button-primary:hover {
  background: var(--teal-dark);
}

.button-secondary {
  background: white;
  color: var(--ink);
}

.button-secondary:hover {
  background: var(--surface-soft);
}

.button-danger {
  background: white;
  border-color: #e2aaa6;
  color: var(--red);
}

.button-danger:hover {
  background: var(--red-soft);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.capture-display {
  align-items: center;
  border-bottom: 1px solid var(--line);
  border-top: 1px solid var(--line);
  display: flex;
  gap: 18px;
  margin: 28px 0;
  padding: 28px 0;
}

.record-dot {
  background: var(--red);
  border-radius: 50%;
  box-shadow: 0 0 0 8px var(--red-soft);
  flex: 0 0 auto;
  height: 16px;
  width: 16px;
}

.capture-time {
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  font-weight: 760;
}

.capture-caption {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-top: 3px;
}

.evidence-band {
  border-bottom: 1px solid var(--line);
  border-top: 1px solid var(--line);
  margin: 26px 0;
  padding: 22px 0;
}

.evidence-group + .evidence-group {
  margin-top: 18px;
}

.evidence-label {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 750;
  margin-bottom: 9px;
  text-transform: uppercase;
}

.token-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.token {
  background: var(--teal-soft);
  border: 1px solid #add9cd;
  border-radius: 4px;
  font-size: 17px;
  font-weight: 720;
  padding: 8px 11px;
}

.token.uncertain {
  background: var(--yellow-soft);
  border-color: #ead489;
  color: #6b5012;
}

.candidate-list {
  border-top: 1px solid var(--line);
  margin-top: 24px;
}

.candidate-item {
  border-bottom: 1px solid var(--line);
  padding: 0;
}

.candidate-select {
  align-items: center;
  background: transparent;
  border: 0;
  color: var(--ink);
  display: grid;
  gap: 14px;
  grid-template-columns: 34px minmax(0, 1fr) 20px;
  padding: 20px 4px;
  text-align: left;
  width: 100%;
}

.candidate-select:hover {
  background: var(--surface-soft);
}

.candidate-index {
  align-items: center;
  background: var(--ink);
  border-radius: 50%;
  color: white;
  display: flex;
  font-size: 13px;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.candidate-copy {
  min-width: 0;
}

.candidate-text {
  display: block;
  font-size: 20px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.candidate-meta {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-top: 7px;
}

.candidate-arrow {
  color: var(--teal);
  font-size: 28px;
  line-height: 1;
}

.candidate-provenance {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 4px 17px 52px;
}

.span-chip {
  background: var(--teal-soft);
  border-radius: 4px;
  color: var(--teal-dark);
  font-size: 12px;
  padding: 5px 7px;
}

.span-chip.ai {
  background: var(--yellow-soft);
  color: #6b5012;
}

.final-expression {
  border-bottom: 1px solid var(--line);
  border-top: 1px solid var(--line);
  font-size: 28px;
  font-weight: 760;
  line-height: 1.35;
  margin: 24px 0 18px;
  overflow-wrap: anywhere;
  padding: 26px 0;
}

.review-meta {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.risk-badge {
  background: var(--surface-soft);
  color: var(--muted);
}

.risk-badge.high_risk {
  background: var(--red-soft);
  color: var(--red);
}

.source-badge {
  background: var(--yellow-soft);
  color: #6b5012;
}

.memory-badge {
  background: var(--teal-soft);
  color: var(--teal-dark);
}

.audio-review {
  background: var(--surface-soft);
  border-left: 4px solid var(--teal);
  margin: 22px 0;
  padding: 18px;
}

.audio-review audio {
  margin-top: 12px;
  width: 100%;
}

.confirmation-check {
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  display: flex;
  font-weight: 690;
  gap: 10px;
  padding: 13px 0;
}

.confirmation-check input {
  height: 21px;
  margin: 0;
  width: 21px;
}

.receipt-table {
  border-top: 1px solid var(--line);
  margin: 24px 0;
}

.receipt-row {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 14px;
  grid-template-columns: 180px minmax(0, 1fr);
  padding: 13px 0;
}

.receipt-row dt {
  color: var(--muted);
  font-size: 13px;
}

.receipt-row dd {
  font-weight: 700;
  margin: 0;
  overflow-wrap: anywhere;
}

.universal-controls {
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin: 24px auto 0;
  max-width: 820px;
  padding-top: 18px;
}

.universal-controls .button {
  min-height: 44px;
  padding: 9px 13px;
}

.status-message {
  color: var(--red);
  font-size: 14px;
  margin: 14px auto 0;
  max-width: 820px;
  min-height: 22px;
}

.trace-heading-row {
  align-items: flex-start;
  display: flex;
  justify-content: space-between;
}

.trace-count {
  background: var(--ink);
  color: white;
}

.trace-list {
  border-top: 1px solid var(--line);
  margin-top: 20px;
}

.trace-item {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: 11px minmax(0, 1fr);
  padding: 15px 0;
}

.trace-marker {
  background: var(--teal);
  border-radius: 50%;
  height: 9px;
  margin-top: 5px;
  width: 9px;
}

.trace-item strong {
  display: block;
  font-size: 13px;
}

.trace-item p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.empty-trace,
.loading-state {
  color: var(--muted);
}

.loading-state {
  align-items: center;
  display: flex;
  gap: 12px;
  min-height: 300px;
}

.activity-indicator {
  animation: pulse 900ms ease-in-out infinite alternate;
  background: var(--teal);
  border-radius: 50%;
  height: 12px;
  width: 12px;
}

.access-dialog {
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 420px;
  padding: 0;
  width: calc(100% - 36px);
}

.access-dialog::backdrop {
  background: rgba(23, 33, 31, 0.62);
}

.access-dialog form {
  padding: 30px;
}

.access-dialog label {
  display: block;
  font-size: 13px;
  font-weight: 750;
  margin: 24px 0 7px;
}

.access-dialog input,
.access-dialog select {
  border: 1px solid var(--line);
  border-radius: 5px;
  min-height: 48px;
  padding: 10px 12px;
  width: 100%;
}

.profile-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: 14px 0 0;
}

.access-dialog .profile-upload {
  margin-top: 14px;
}

.access-dialog .button {
  margin-top: 16px;
  width: 100%;
}

.form-error {
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
}

.visually-hidden {
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
}

.access-dialog input.visually-hidden {
  height: 1px;
  min-height: 0;
  padding: 0;
  position: absolute;
  width: 1px;
}

@keyframes pulse {
  from { opacity: 0.35; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1.1); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .trace-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .decision-surface {
    min-height: 410px;
  }
}

@media (max-width: 620px) {
  .app-header {
    align-items: flex-start;
    padding: 12px 16px;
  }

  .brand-block span {
    display: none;
  }

  .header-status {
    align-items: flex-end;
    flex-direction: column;
    gap: 5px;
  }

  .simulation-notice {
    padding-left: 16px;
    padding-right: 16px;
  }

  .patient-workspace,
  .trace-panel {
    padding: 24px 18px 34px;
  }

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

  h1 {
    font-size: 27px;
  }

  .candidate-text {
    font-size: 18px;
  }

  .receipt-row {
    grid-template-columns: 1fr;
  }
}
