/* Mini Doctor Consultation — design tokens, layout and components. Light + dark, mobile-first. */
:root {
  --brand: #0f766e;
  --brand-ink: #0b5952;
  --brand-soft: #e6f4f2;
  --accent: #f59e0b;
  --ink: #1d2a33;
  --muted: #5b6b75;
  --bg: #f4f7f7;
  --card: #ffffff;
  --card-2: #f8fbfb;
  --line: #dfe6e8;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --ok: #1b7f3b;
  --ok-soft: #e7f6ec;
  --info: #1d5fae;
  --info-soft: #e8f0fb;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  /* avatar */
  --av-bg: #d9f0ec; --av-skin: #f1c7a3; --av-skin-line: #d9a47c; --av-hair: #3b2a20; --av-coat: #ffffff;
  --av-coat-line: #cfdde0; --av-scrub: #0f766e; --av-eye: #ffffff; --av-pupil: #1f2a33; --av-mouth: #7a3b2e;
  --av-cheek: #f29b8f; --av-steth: #334155;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #2bb3a5; --brand-ink: #5fd0c3; --brand-soft: #123b38; --ink: #e5eef0; --muted: #9fb2b9;
    --bg: #0e1719; --card: #152225; --card-2: #1a2a2e; --line: #26383c; --danger: #ff6b6b; --danger-soft: #3a1c1c;
    --warn: #ffb74d; --warn-soft: #3a2b12; --ok: #5bd17f; --ok-soft: #13301d; --info: #78aef0; --info-soft: #152a45;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .35);
    --av-bg: #1b3a37; --av-coat-line: #9fb2b9;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #2bb3a5; --brand-ink: #5fd0c3; --brand-soft: #123b38; --ink: #e5eef0; --muted: #9fb2b9;
  --bg: #0e1719; --card: #152225; --card-2: #1a2a2e; --line: #26383c; --danger: #ff6b6b; --danger-soft: #3a1c1c;
  --warn: #ffb74d; --warn-soft: #3a2b12; --ok: #5bd17f; --ok-soft: #13301d; --info: #78aef0; --info-soft: #152a45;
  --av-bg: #1b3a37; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100dvh; font: 16px/1.5 var(--font); color: var(--ink); background: var(--bg);
  display: flex; flex-direction: column; overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-ink); }
img, svg { max-width: 100%; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--card); padding: 8px 12px; z-index: 50; }
.skip-link:focus { left: 8px; }
.muted { color: var(--muted); }
code { font-size: .9em; background: var(--card-2); padding: 1px 5px; border-radius: 6px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4em; min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid transparent; background: var(--card); cursor: pointer; text-decoration: none;
  font-weight: 600; white-space: nowrap; color: var(--ink); }
.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-ink); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.is-busy { position: relative; color: transparent !important; }
.btn.is-busy::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid #fff; border-right-color: transparent; animation: spin .8s linear infinite; }
.btn--ghost { border-color: var(--line); color: var(--brand-ink); background: var(--card); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger-outline { border-color: var(--danger); color: var(--danger); background: var(--card); }
.btn--icon { padding: 0; width: 44px; }
.btn--small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn--lg { min-height: 52px; padding: 0 22px; font-size: 17px; }
.btn--block { width: 100%; }
.btn svg { width: 22px; height: 22px; fill: currentColor; flex: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.icon-btn { min-width: 44px; min-height: 44px; border: 0; background: transparent; cursor: pointer; font-size: 18px; color: inherit; }
.link-btn { border: 0; background: none; color: var(--brand-ink); cursor: pointer; padding: 4px; text-decoration: underline; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- top bar & nav ---------- */
.topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand__logo { width: 32px; height: 32px; }
.brand__text { display: flex; flex-direction: column; line-height: 1.15; }
.brand__clinic { font-size: 12px; color: var(--muted); letter-spacing: .02em; }
.brand__app { font-weight: 700; font-size: 18px; color: var(--brand-ink); }
.topbar__controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-box { display: flex; align-items: center; gap: 6px; }
.user-box__name { font-weight: 600; text-decoration: none; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bell { position: relative; }
.bell__count, .nav__count { position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.nav__count { position: static; margin-left: 4px; display: inline-block; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; flex-wrap: wrap; }
.segmented button, .segmented a { min-width: 44px; min-height: 44px; padding: 0 12px; border: 0; background: var(--card);
  cursor: pointer; font-weight: 600; color: var(--muted); text-decoration: none; display: inline-flex; align-items: center; }
.segmented [aria-pressed="true"], .segmented [aria-current="page"] { background: var(--brand); color: #fff; }
.segmented--small button, .segmented--small a { min-height: 36px; font-size: 14px; }
.nav { display: flex; gap: 4px; padding: 6px 12px; background: var(--card); border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav__item { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px; border-radius: 10px;
  text-decoration: none; color: var(--muted); font-weight: 600; white-space: nowrap; }
.nav__item:hover { background: var(--card-2); }
.nav__item.is-active { color: var(--brand-ink); background: var(--brand-soft); }
.nav__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .5; }
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--card-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.badge--ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge--warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge--danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge--info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge--muted { color: var(--ink); background: var(--line); }   /* full-opacity text: 4.5:1 contrast */

/* ---------- banners ---------- */
.emergency { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
  padding: 12px 16px; background: var(--danger); color: #fff; position: sticky; top: 0; z-index: 30; }
.emergency__text { display: flex; flex-direction: column; }
.emergency__actions { display: flex; gap: 8px; align-items: center; }
.emergency .btn--danger { background: #fff; color: #b71c1c; }
.emergency .btn--danger-outline { background: transparent; color: #fff; border-color: #fff; }
.offline { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; padding: 8px 16px;
  background: var(--warn-soft); color: var(--warn); font-weight: 600; font-size: 14px; text-align: center; }
.offline__call { font-weight: 800; color: var(--danger); }
.note { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--info-soft); color: var(--ink); margin: 8px 0; }
.note--warn { background: var(--warn-soft); }
.sandbox-banner { border: 2px dashed var(--warn); background: var(--warn-soft); color: var(--warn); border-radius: var(--radius);
  padding: 14px 16px; margin: 12px 0; }
.sandbox-banner p { margin: 4px 0 0; color: var(--ink); }

/* ---------- page layout ---------- */
.view { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 16px 16px 96px; outline: none; }
.view[aria-busy="true"] { opacity: .6; transition: opacity .2s .15s; }
.page { display: flex; flex-direction: column; gap: 16px; }
.page--narrow { max-width: 560px; margin: 0 auto; width: 100%; }
.page__title { margin: 0; font-size: clamp(22px, 3.2vw, 30px); line-height: 1.2; }
.page__head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; }
.page__head p { margin: 4px 0 0; }
.page__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.back { text-decoration: none; font-weight: 600; }
.footer { padding: 12px 16px 80px; text-align: center; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }
.footer p { margin: 0 auto; max-width: 900px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.panel__title { margin: 0 0 12px; font-size: 18px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.hero { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; padding: 20px;
  border-radius: var(--radius); background: linear-gradient(135deg, var(--brand-soft), var(--card)); border: 1px solid var(--line); }
.hero h1 { margin: 0 0 4px; }
.hero p { margin: 0; }
.hero__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.empty { padding: 20px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty p { margin: 0 0 10px; }

/* ---------- cards, lists, tiles ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.card { display: flex; flex-direction: column; gap: 4px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; color: inherit; text-decoration: none; }
.card--link:hover { border-color: var(--brand); box-shadow: var(--shadow); }
.card__title { font-weight: 700; font-size: 16px; }
.card__meta { color: var(--muted); font-size: 14px; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list > li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list--tight { margin: 4px 0; padding-left: 18px; }
.list--tight li { padding: 2px 0; border: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 4px; padding: 16px; border-radius: var(--radius); background: var(--card);
  border: 1px solid var(--line); text-decoration: none; color: inherit; }
.tile--warn { background: var(--warn-soft); }
.tile__value { font-size: 26px; font-weight: 800; color: var(--brand-ink); }
.tile__label { color: var(--muted); font-size: 14px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.timeline__item { position: relative; padding: 0 0 14px 16px; }
.timeline__item::before { content: ""; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.timeline__date { font-size: 13px; color: var(--muted); }
.timeline__body p { margin: 4px 0; }
.stepper { display: flex; list-style: none; margin: 0; padding: 0; gap: 4px; flex-wrap: wrap; }
.stepper li { flex: 1 1 120px; padding: 8px 10px; border-radius: 10px; background: var(--card-2); color: var(--muted);
  font-size: 14px; font-weight: 600; text-align: center; border: 1px solid var(--line); }
.stepper li.is-done { background: var(--brand-soft); color: var(--brand-ink); border-color: transparent; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { background: var(--card-2); font-weight: 700; color: var(--muted); white-space: nowrap; }
.table tr.is-low td { background: var(--warn-soft); }
.notifications { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.notification { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding: 12px 14px;
  border-radius: var(--radius-sm); background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--info); }
.notification p { margin: 2px 0; }
.notification--warning { border-left-color: var(--warn); }
.notification--critical { border-left-color: var(--danger); background: var(--danger-soft); }
.notification.is-read { opacity: .7; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 12px; }
.form--wide { max-width: 860px; }
.form__actions, .dialog__actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }
.form-links { text-align: center; font-size: 14px; }
.form-error { color: var(--danger); font-weight: 600; margin: 0; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field__label { font-weight: 600; font-size: 14px; }
.field__hint, .hint { color: var(--muted); font-size: 13px; margin: 0; }
input, select, textarea { min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); width: 100%; }
textarea { resize: vertical; }
[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--brand); flex: none; }
input[type="file"] { padding: 6px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; margin: 0; }
legend { font-weight: 600; padding: 0 4px; font-size: 14px; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check--small { font-size: 14px; align-items: center; }
.switch { display: inline-flex; gap: 8px; align-items: center; font-weight: 600; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form > input, .inline-form > select { flex: 1 1 160px; width: auto; }
.filters { display: grid; grid-template-columns: 2fr repeat(3, 1fr); gap: 8px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  font-size: 14px; cursor: pointer; background: var(--card-2); }
.qty { width: 72px; min-width: 72px; text-align: center; }
.qty--wide { width: 110px; }
.demo-hint { margin-top: 12px; font-size: 14px; }

/* ---------- auth ---------- */
.auth { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; align-items: start; max-width: 960px; margin: 0 auto; width: 100%; }
.auth__card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.auth__card h1 { margin: 0 0 4px; }
.auth__aside { padding: 24px; border-radius: var(--radius); background: var(--brand-soft); }
.auth__aside h2 { margin-top: 0; }
.ticks { padding-left: 0; list-style: none; }
.ticks li { padding-left: 28px; position: relative; margin: 8px 0; }
.ticks li::before { content: "✓"; position: absolute; left: 0; color: var(--brand); font-weight: 800; }

/* ---------- marketplace ---------- */
.product__head { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.product__form { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.product__price { font-weight: 800; font-size: 18px; color: var(--brand-ink); }
.product-detail { display: flex; gap: 16px; flex-wrap: wrap; }
.offers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.offer { display: flex; justify-content: space-between; gap: 12px; padding: 12px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--card); flex-wrap: wrap; }
.offer.is-out { opacity: .6; }
.offer__side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.cart { list-style: none; margin: 0; padding: 0; }
.cart__item { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.cart__side { display: flex; align-items: center; gap: 12px; }
.total { font-size: 16px; margin: 8px 0; }

/* ---------- prescriptions ---------- */
.rx-lines { display: flex; flex-direction: column; gap: 12px; }
.rx-line { display: flex; flex-direction: column; gap: 8px; }
.rx-check p { margin: 4px 0; }
.issues { list-style: none; padding: 0; margin: 4px 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.issues li { padding: 6px 10px; border-radius: 8px; }
.issue--hard { background: var(--danger-soft); color: var(--danger); }
.issue--soft { background: var(--warn-soft); color: var(--warn); }
.issue--info { background: var(--info-soft); color: var(--info); }

/* ---------- dialogs & toasts ---------- */
.dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.dialog--wide { width: min(860px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(10, 20, 25, .5); }
.dialog__body { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog__head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dialog__head h2 { margin: 0; font-size: 20px; }
.toasts { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px;
  z-index: 60; width: min(480px, calc(100vw - 32px)); pointer-events: none; }
.toast { padding: 12px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow);
  font-weight: 600; transition: opacity .4s, transform .4s; pointer-events: auto; }
.toast--ok { background: var(--ok); color: #fff; }
.toast--error { background: var(--danger); color: #fff; }
.toast--warn { background: var(--warn); color: #fff; }
.toast.is-leaving { opacity: 0; transform: translateY(8px); }

/* ---------- consultation ---------- */
.chat-layout { display: grid; grid-template-columns: minmax(240px, 320px) 1fr; gap: 16px; align-items: start; }
.doctor { display: flex; flex-direction: column; align-items: center; gap: 10px; position: sticky; top: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.doctor__meta { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; width: 100%; }
.doctor__name { font-size: 18px; }
.doctor__role { font-size: 13px; color: var(--muted); }
.doctor__context { width: 100%; font-size: 14px; text-align: left; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }
.doctor__context p { margin: 4px 0; }
.status { margin: 4px 0 0; min-height: 1.5em; font-weight: 600; color: var(--brand-ink); }
.chat { display: flex; flex-direction: column; gap: 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; min-height: 60vh; }
.chat__toolbar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.chat__toolbar select { width: auto; min-height: 36px; }
.messages { list-style: none; margin: 0; padding: 4px; display: flex; flex-direction: column; gap: 10px; flex: 1;
  overflow-y: auto; max-height: 62vh; }
.messages--readonly { max-height: none; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 16px; background: var(--card-2); border: 1px solid var(--line); }
.msg p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg__meta { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.msg--user { align-self: flex-end; background: var(--brand); color: #fff; border-color: transparent; border-bottom-right-radius: 4px; }
.msg--user .msg__meta { color: rgba(255, 255, 255, .8); }
.msg--assistant { align-self: flex-start; border-bottom-left-radius: 4px; }
.msg--streaming p::after { content: "▍"; margin-left: 2px; opacity: .6; animation: md-caret 1s steps(1) infinite; }
@keyframes md-caret { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .msg--streaming p::after { animation: none; } }
.msg--system { align-self: center; background: var(--warn-soft); color: var(--warn); font-size: 14px; }
.msg--urgent { border-color: var(--warn); background: var(--warn-soft); }
.msg--emergency { border: 2px solid var(--danger); background: var(--danger-soft); }
.msg--queued { opacity: .7; border-style: dashed; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 48px; max-height: 140px; border-radius: 14px; }
.mic { flex: none; width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--brand-soft); color: var(--brand-ink);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.mic svg { width: 26px; height: 26px; fill: currentColor; }
.mic.is-recording { background: var(--danger); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
.mic:disabled { opacity: .5; }
.send { min-height: 52px; }
.chat-layout[data-mode="text"] .mic { opacity: .6; }
.disclaimer { font-size: 12px; color: var(--muted); margin: 0; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px rgba(198, 40, 40, .15); } }

/* ---------- Doctor Ruslan: Avatar Engine (owner's artwork only) ---------- */
.avatar { position: relative; width: 100%; max-width: 300px; aspect-ratio: 13 / 10; border-radius: 24px; --level: 0;
  transition: box-shadow .3s; background: var(--brand-soft); overflow: hidden; }
.avatar--md { max-width: 160px; }
.avatar__label { position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%); z-index: 3; font-size: 12px; font-weight: 700;
  padding: 2px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.avatar__stage { position: absolute; inset: 0; transform-origin: 50% 85%; }
.avatar__canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.avatar__frame, .avatar__layer { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
  border-radius: inherit;
  user-select: none; -webkit-user-drag: none; transition: opacity .28s ease; }
.avatar__frame.is-hidden { opacity: 0; }
.avatar__layer--part { position: absolute; inset: auto; object-fit: fill; }
/* Flat frames only (no facial parts): a gentle pose per state. Speech is NOT imitated by bobbing the picture.
   The Rive renderer moves the head, eyes, brows and mouth inside the rig instead. */
.avatar[data-renderer="frames"][data-state="idle"] .avatar__stage { animation: av-breathe 5s ease-in-out infinite; }
.avatar[data-renderer="frames"][data-state="listening"] .avatar__stage { animation: av-tilt 2.4s ease-in-out infinite; }
.avatar[data-renderer="frames"][data-state="thinking"] .avatar__stage { animation: av-ponder 3s ease-in-out infinite; }
.avatar[data-renderer="frames"][data-emotion="greeting"][data-state="idle"] .avatar__stage,
.avatar[data-renderer="frames"][data-emotion="encouraging"][data-state="idle"] .avatar__stage { animation: av-nod 1.6s ease-in-out 2, av-breathe 5s ease-in-out 3.2s infinite; }
.avatar[data-state="listening"] { box-shadow: 0 0 0 calc(4px + var(--level) * 14px) rgba(15, 118, 110, .25); }
.avatar[data-mood="serious"], .avatar[data-mood="empathy"] { box-shadow: 0 0 0 4px var(--warn-soft); }
.avatar[data-mood="warning"] { box-shadow: 0 0 0 5px var(--danger-soft); }
@keyframes av-breathe { 50% { transform: translateY(-2px) scale(1.008); } }
@keyframes av-tilt { 50% { transform: rotate(-3deg) translateX(-2px); } }
@keyframes av-ponder { 50% { transform: rotate(2deg) translateY(-2px); } }
@keyframes av-nod { 30% { transform: rotate(0) translateY(4px); } 60% { transform: translateY(-2px); } }
/* placeholder: neutral, no face, never a substitute character */
.avatar--placeholder { display: grid; place-items: center; }
.avatar__placeholder { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px; text-align: center; }
.avatar__placeholder svg { width: 56px; height: 56px; fill: var(--brand); opacity: .6; }
.avatar__placeholder-text { font-size: 13px; color: var(--muted); }
/* pause control for the avatar's idle animation (WCAG 2.2.2); 32px target (WCAG 2.5.8) */
.avatar__motion { position: absolute; top: 6px; right: 6px; z-index: 4; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 12px; line-height: 1; cursor: pointer;
  opacity: .75; }
.avatar__motion:hover, .avatar__motion:focus-visible { opacity: 1; }
.avatar[data-motion="off"] .avatar__stage { animation: none !important; }
.avatar--placeholder[data-state="speaking"] svg { transform: scale(calc(1 + var(--level) * .2)); }
.msg--demo { border-style: dashed; }
.msg__retry { display: inline-block; margin-top: 4px; font-size: 13px; }
.demo-ai { margin: 0; font-size: 13px; }
.lang-chip { font-weight: 600; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}

/* ---------- history taking, external services ---------- */
.anamnesis { margin-top: 8px; font-size: 13px; }
.anamnesis__title { margin: 0 0 4px; font-weight: 700; color: var(--muted); }
.anamnesis__list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.anamnesis__list li { padding: 2px 8px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); color: var(--muted); }
.anamnesis__list li.is-known { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.external__box { padding: 10px 12px; border: 1px dashed var(--line); border-radius: var(--radius-sm); background: var(--card); }
.external__box .hint { margin-bottom: 6px; }
pre.code { background: var(--card-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; overflow-x: auto; font-size: 13px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .chat-layout { grid-template-columns: 1fr; }
  .doctor { position: static; flex-direction: row; align-items: center; padding: 10px; }
  .doctor .avatar { max-width: 120px; flex: none; }
  .avatar__placeholder-text, .avatar__label { display: none; }
  .doctor__meta { align-items: flex-start; text-align: left; }
  .avatar__label { font-size: 10px; padding: 1px 6px; }
  .messages { max-height: none; }
  .chat { min-height: 50vh; }
  .auth { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters input[type="search"] { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .view { padding: 12px 12px 96px; }
  .brand__clinic { display: none; }
  .user-box__name { display: none; }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; border-top: 1px solid var(--line); border-bottom: 0;
    padding: 6px 6px max(6px, env(safe-area-inset-bottom)); justify-content: space-around; box-shadow: 0 -4px 16px rgba(0, 0, 0, .06); }
  .nav__item { flex-direction: column; gap: 2px; min-height: 48px; padding: 4px 8px; font-size: 12px; justify-content: center; }
  .footer { padding-bottom: 96px; }
  .msg { max-width: 94%; }
  .send__label { display: none; }
  .send { width: 52px; padding: 0; }
  .offer__side { align-items: flex-start; text-align: left; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 8px; }
  .hero { padding: 16px; }
}

/* ---------- voice & animation admin / test bench ---------- */
.stop-speech[hidden] { display: none; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 8px 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.voice-test { display: grid; grid-template-columns: 180px 1fr; gap: 16px; align-items: start; }
.voice-test__form textarea { width: 100%; }
.lab-compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.lab-col { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.lab-col h3 { margin: 0 0 8px; font-size: 15px; }
.lab-col .avatar { max-width: 220px; }
.lab-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.voice-lab meter { width: 140px; }
@media (max-width: 640px) {
  .voice-test, .lab-compare { grid-template-columns: 1fr; }
}

/* ---------- clinic: reception, queue, booking, receipts (pages/clinic.js) */
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin: 0 0 12px; }
.toolbar .field { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.chip { min-height: 40px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); font: inherit; cursor: pointer; }
.chip:hover { border-color: var(--brand); }
.chip.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.ticket { display: inline-block; margin: 0 4px 4px 0; padding: 2px 10px; border-radius: 8px; background: var(--brand);
  color: #fff; font-weight: 700; letter-spacing: .5px; }
.ticket--wait { background: var(--warn-soft); color: var(--warn); }
.queue-card p { margin: 4px 0; }
.receipt h3 { margin: 0; }
.small { font-size: 12px; }
@media print {
  body:has(dialog[open]) > *:not(dialog) { display: none !important; }
  dialog .dialog__actions, dialog .dialog__head button { display: none !important; }
}

/* ---------- WHO growth charts (growth-chart.js) */
.growth__holder { overflow-x: auto; }
.growth__fig { margin: 8px 0; }
.growth__svg { width: 100%; max-width: 720px; height: auto; display: block; }
.growth__band { fill: var(--ok-soft); }
.growth__line { fill: none; stroke: var(--muted); stroke-width: 1; opacity: .55; }
.growth__line--0 { stroke: var(--ok); stroke-width: 2; opacity: 1; }
.growth__line--2 { stroke: var(--warn); stroke-dasharray: 4 3; opacity: .9; }
.growth__line--3 { stroke: var(--danger); stroke-dasharray: 2 3; opacity: .8; }
.growth__grid { stroke: var(--line); stroke-width: 1; }
.growth__tick { stroke: var(--muted); }
.growth__label { fill: var(--muted); font-size: 11px; }
.growth__child-line { fill: none; stroke: var(--brand); stroke-width: 2; }
.growth__point { fill: var(--brand); stroke: var(--card); stroke-width: 2; }
.growth__point--alert { fill: var(--danger); }

/* ---------- SaaS owner dashboard (pages/owner.js) */
.owner__chart { width: 100%; max-width: 720px; height: auto; display: block; }
.owner__bar--rev { fill: var(--brand); }
.owner__bar--exp { fill: var(--warn); opacity: .75; }
.legend { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; }
.legend--rev { background: var(--brand); }
.legend--exp { background: var(--warn); opacity: .75; }

/* walk-in-only clinic (no online or phone booking) */
.walkin h2 { margin-top: 0; }
.walkin__why { margin: 6px 0 0; padding-left: 20px; display: grid; gap: 6px; }

/* Oson Apteka (pharmacy section = Telegram bot) */
.oson__lead { font-size: 16px; margin-top: 0; }
.oson__open { display: inline-flex; margin: 4px 0 12px; }
.oson__how { margin: 0 0 12px; padding-left: 20px; display: grid; gap: 6px; }

/* parent subscription */
.sub__price { margin: 12px 0 4px; }
.sub__sum { font-size: 28px; font-weight: 700; }
.sub__what { margin: 8px 0 14px; padding-left: 20px; display: grid; gap: 6px; }
.sub__buttons { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.sub--expired .sub__state { color: var(--danger, #b42318); }
.msg__cta { margin-top: 8px; display: inline-flex; }

/* lab results */
.labs { display: grid; gap: 12px; }
.labs__head { margin-bottom: 6px; }
.labs__text { margin: 6px 0 10px; }
.labs__row--flag td { background: var(--warn-soft); }
.labs__tg h2 { margin-top: 0; }
#tg-code { font-size: 18px; letter-spacing: 2px; }

/* doctors rate parents: 1-5 stars */
.stars { display: flex; gap: .25rem; }
.star { background: none; border: 0; font-size: 1.75rem; line-height: 1; color: var(--muted); cursor: pointer; padding: .1rem; min-width: 44px; min-height: 44px; }
.star--on { color: #9a6200; }
.star:focus-visible { outline: 2px solid var(--brand); border-radius: 6px; }
.so-text { white-space: pre-wrap; line-height: 1.5; }

/* AI visit assistant */
.scribe-level { height: 6px; background: var(--line, #ddd); border-radius: 3px; overflow: hidden; margin: .5rem 0; }
.scribe-level > span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .1s; }
#scribe-text { font-family: inherit; }
.fieldset { border: 1px solid var(--line, #ddd); border-radius: 12px; padding: .75rem 1rem; }

/* printable exam sheet (A4) */
.print-sheet { background: #fff; color: #000; max-width: 190mm; margin: 0 auto; padding: 10mm; border: 1px solid #ccc; font-size: 11pt; line-height: 1.4; }
.print-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; border-bottom: 2px solid #000; padding-bottom: 4pt; }
.print-head__name { flex: 1; }
.print-logo { max-height: 18mm; max-width: 40mm; object-fit: contain; }
.logo-preview { display: block; max-width: 160px; max-height: 160px; object-fit: contain; margin-bottom: .75rem; border: 1px solid var(--line, #ddd); border-radius: 8px; padding: 6px; background: #fff; }
.logo-preview[hidden] { display: none; }
.print-small { font-size: 9pt; }
.print-title { text-align: center; font-size: 14pt; letter-spacing: .05em; margin: 8pt 0; }
.print-patient { width: 100%; border-collapse: collapse; margin-bottom: 6pt; }
.print-patient th, .print-patient td { border: 1px solid #000; padding: 3pt 5pt; text-align: left; font-size: 10pt; }
.print-patient th { width: 18%; font-weight: 600; }
.print-block h3 { font-size: 11pt; margin: 8pt 0 2pt; text-transform: uppercase; }
.print-text { white-space: pre-wrap; margin: 0; }
.print-line { border-bottom: 1px solid #000; height: 18pt; }
.print-sign { display: flex; justify-content: space-between; gap: 1rem; margin-top: 16pt; }
.print-blank { display: inline-block; min-width: 45mm; border-bottom: 1px solid #000; }
@media print {
  body { background: #fff !important; }
  body > header, body > nav, body > footer, .no-print, .toasts, .skip-link { display: none !important; }
  .page { padding: 0 !important; margin: 0 !important; }
  .print-sheet { border: 0; padding: 0; max-width: none; }
  @page { size: A4; margin: 12mm; }
}

/* doctors' AI plans */
.plan-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin: 1rem 0; }
.plan-card { position: relative; background: var(--card); border: 1px solid var(--line, #ddd); border-radius: 16px; padding: 1.25rem; display: flex; flex-direction: column; gap: .5rem; }
.plan-card--best { border: 2px solid var(--brand); }
.plan-card--current { box-shadow: 0 0 0 3px var(--brand-soft, #d7f2ee); }
.plan-card__tag { position: absolute; top: -.7rem; right: 1rem; background: var(--brand); color: #fff; font-size: .75rem; padding: .15rem .6rem; border-radius: 999px; }
.plan-card__name { margin: 0; font-size: 1.15rem; }
.plan-card__price span { font-size: 1.6rem; font-weight: 700; }
.plan-card__list { margin: 0; padding-left: 1.1rem; flex: 1; }
.usage { margin: .4rem 0; }
.usage__head { display: flex; justify-content: space-between; font-size: .9rem; }
.usage__bar { height: 8px; background: var(--line, #e3e8ea); border-radius: 4px; overflow: hidden; }
.usage__bar > span { display: block; height: 100%; background: var(--brand); }
.usage__bar > span.usage--full { background: var(--danger); }
.plan-line { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: .6rem .9rem; border: 1px solid var(--line, #ddd); border-radius: 12px; margin: .5rem 0 1rem; }
.plan-line .usage { flex: 1; min-width: 180px; margin: 0; }
