:root {
  --paper: #f2f7fb;
  --surface: #ffffff;
  --ink: #132a3e;
  --muted: #58697c;
  --line: #d5e1ec;
  --primary: #1668b8;
  --primary-deep: #0d4f8f;
  --primary-soft: #e4f0fb;
  --accent: #178a57;
  --accent-soft: #e3f4eb;
  --danger: #b3261e;
  --radius: 14px;
  font-family: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--paper); font-size: 15px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary-deep); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-areas: "top" "journey" "log" "composer" "fineprint";
  max-width: 720px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Fixed areas, so hiding the journey bar doesn't shift the message log into its row */
.top { grid-area: top; }
.journey { grid-area: journey; }
.log { grid-area: log; }
.composer { grid-area: composer; }
.fineprint { grid-area: fineprint; }

/* Opened directly (not inside the widget iframe): show the chat as a card on wide screens */
@media (min-width: 760px) {
  .standalone body { padding: 24px 16px; }
  .standalone .app {
    border: 1px solid var(--line);
    border-radius: 18px;
    overflow: hidden;
    background: var(--surface);
    box-shadow: 0 18px 50px rgba(19, 42, 62, 0.12);
  }
}

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mark { width: 34px; height: 34px; flex: none; }
.brand h1 { font-size: 16px; margin: 0; line-height: 1.2; }
.sub { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.top-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center;
}
.icon-btn[hidden] { display: none; }
.icon-btn:hover { background: var(--primary-soft); color: var(--primary-deep); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- journey route: the patient's trip as a flight path ---------- */
.journey { background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 12px 8px; }
.route { list-style: none; margin: 0; padding: 0; display: flex; }
.route li {
  flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 11.5px; color: var(--muted); text-align: center; min-width: 0;
}
.route li + li::before {
  content: ''; position: absolute; top: 5px; right: 50%; width: 100%; height: 0;
  border-top: 2px dashed var(--line);
  transition: border-color .4s ease;
}
.route li.done + li::before, .route li.done + li.now::before { border-top-style: solid; border-color: var(--accent); }
.stop {
  position: relative; z-index: 1; width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--line);
  transition: background .3s ease, border-color .3s ease;
}
.route li.done .stop { background: var(--accent); border-color: var(--accent); }
.route li.now .stop { border: 3px solid var(--primary); transform: scale(1.15); }
.route li.now .name { color: var(--ink); font-weight: 700; overflow: visible; text-overflow: clip; }
.route .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; padding: 0 2px; }
@media (max-width: 360px) { .route li:not(.now) .name { visibility: hidden; } }

/* ---------- conversation ---------- */
.log {
  overflow-y: auto; padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 10px;
  overscroll-behavior: contain;
}
.msg { max-width: 88%; animation: arrive .22s ease-out; }
.msg p { margin: 0; }
.msg p + p, .msg ul, .msg ol { margin-top: 6px; }
.msg ul, .msg ol { padding-left: 20px; margin-bottom: 0; }
.msg.bot > .bubble {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  padding: 10px 13px;
}
.msg.user { align-self: flex-end; }
.msg.user > .bubble {
  background: var(--primary); color: #fff;
  border-radius: var(--radius) 4px var(--radius) var(--radius);
  padding: 9px 13px;
}
.msg.alert > .bubble { border-color: var(--danger); border-width: 2px; }
.msg.actions { max-width: 100%; }
@keyframes arrive { from { opacity: 0; transform: translateY(4px); } }

.sources { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.sources > p { font-size: 13px; color: var(--muted); }

/* ---------- Vanya article links ---------- */
.msg .articles { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.articles a {
  display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink);
  padding: 9px 11px; border: 1px solid var(--line); border-left: 3px solid var(--primary); border-radius: 8px;
  background: var(--paper);
}
.articles a:hover { background: var(--primary-soft); border-color: var(--primary); }
.articles .a-text { display: grid; flex: 1; min-width: 0; }
.articles strong { font-size: 14px; line-height: 1.3; }
.articles .a-site { font-size: 12px; color: var(--muted); }
.articles svg { width: 18px; height: 18px; flex: none; color: var(--primary); }

.dots { display: inline-flex; gap: 4px; padding: 4px 2px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .35; animation: blink 1s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 50% { opacity: 1; } }

/* ---------- choice chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--primary); background: var(--surface); color: var(--primary-deep);
  border-radius: 999px; padding: 8px 14px; cursor: pointer; text-align: left; line-height: 1.3;
  min-height: 40px;
}
.chip:hover { background: var(--primary-soft); }
.chip[aria-pressed='true'] { background: var(--primary); color: #fff; }
.chip.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.chip.primary:hover { filter: brightness(.96); }
.chip.quiet { border-color: var(--line); color: var(--muted); }
.chip:disabled { opacity: .5; cursor: default; }

/* ---------- inline cards: forms, date, upload ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; display: grid; gap: 12px; width: min(100%, 420px);
}
.field { display: grid; gap: 4px; }
.field label { font-size: 13.5px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.consent { display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; color: var(--muted); }
.consent input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--primary); flex: none; }
.btn {
  border: 0; border-radius: 999px; padding: 11px 18px; min-height: 44px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 700;
}
.btn.quiet { background: transparent; color: var(--primary-deep); border: 1.5px solid var(--primary); font-weight: 400; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.error { color: var(--danger); font-size: 13.5px; margin: 0; }
.error:empty { display: none; }

.drop {
  border: 2px dashed var(--line); border-radius: 10px; padding: 16px; text-align: center; cursor: pointer; color: var(--muted);
}
.drop:hover, .drop.over { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-deep); }
.drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.files { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13.5px; }
.files li { display: flex; justify-content: space-between; gap: 10px; }
.files .state { color: var(--muted); flex: none; }
.files .state.ok { color: var(--primary-deep); }
.files .state.bad { color: var(--danger); }

/* ---------- partner hospitals ---------- */
.hospitals { list-style: none; margin: 8px 0 0; padding: 0; }
.hospitals li { padding: 10px 0; border-top: 1px solid var(--line); }
.hospitals li:first-child { border-top: 0; padding-top: 4px; }
.hospitals strong { display: block; }
.hospitals .place { color: var(--muted); font-size: 13.5px; }
.hospitals .note { font-size: 13.5px; margin-top: 2px; }

/* ---------- composer ---------- */
.composer {
  display: flex; gap: 8px; padding: 10px 12px; background: var(--surface); border-top: 1px solid var(--line);
}
.composer input {
  flex: 1; min-width: 0; min-height: 44px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--paper);
}
.composer input:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); background: #fff; }
.composer button {
  width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--primary); color: #fff; cursor: pointer;
  display: grid; place-items: center; flex: none;
}
.composer button:disabled { opacity: .5; cursor: progress; }
.composer button svg { width: 22px; height: 22px; }
.fineprint { margin: 0; padding: 0 12px 8px; font-size: 11.5px; color: var(--muted); text-align: center; background: var(--surface); }

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

/* ---------- review step before sending ---------- */
.review { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.review li { display: grid; grid-template-columns: 92px 1fr; gap: 8px; }
.review span:first-child { color: var(--muted); }
.review span:last-child { word-break: break-word; }
