/* MyMedChat — plain CSS, system fonts only, no external resources. */
:root {
  --brand: #0f5c8c;
  --brand-dark: #0b4569;
  --brand-tint: #e8f1f8;
  --text: #1c2430;
  --muted: #5b6676;
  --border: #d9dee5;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --danger: #b42318;
  --danger-tint: #fdecea;
  --warn: #8a5a00;
  --warn-tint: #fff6e0;
  --ok-tint: #e9f6ee;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; font: 16px/1.55 var(--font); color: var(--text); background: var(--bg); display: flex; flex-direction: column; }
a { color: var(--brand); }
a:hover { color: var(--brand-dark); }
:focus-visible { outline: 3px solid #5aa9e6; outline-offset: 2px; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 .75rem; }
h2, .h3 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
code { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--muted); font-size: .92rem; }
.lead { font-size: 1.05rem; color: #364152; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 100; }
.skip-link:focus { left: .5rem; top: .5rem; }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .45rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-main { display: flex; align-items: center; gap: .55rem; min-width: 0; flex: 1 1 auto; }
.brand { display: inline-flex; align-items: center; gap: .45rem; text-decoration: none; color: var(--text); font-weight: 650; font-size: 1.02rem; flex-shrink: 0; }
.topbar-sep { color: var(--muted); flex-shrink: 0; }
.thread-title { font-size: .96rem; font-weight: 600; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; color: var(--text); }
.topbar-del { font-size: .85rem; flex-shrink: 0; margin-left: .2rem; }
.topnav { display: flex; align-items: center; gap: .8rem; font-size: .88rem; flex-shrink: 0; }
.inline { display: inline; margin: 0; }

main { flex: 1 0 auto; padding: 2rem 1rem; }
main:focus { outline: none; }

/* Cards & forms */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2rem; margin: 0 auto; }
.narrow { max-width: 30rem; }
.wide { max-width: 50rem; }
.stack { display: flex; flex-direction: column; gap: .6rem; margin: 1.25rem 0; }
label { font-weight: 600; font-size: .95rem; }
input[type=email], input[type=text], select, textarea {
  font: inherit; color: inherit; padding: .55rem .7rem; border: 1px solid #b8c1cc; border-radius: 8px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); outline: 3px solid rgba(15, 92, 140, .2); outline-offset: 0; }
.code-input { font-family: var(--mono); font-size: 1.5rem; letter-spacing: .4em; text-align: center; }
.check { display: flex; gap: .7rem; align-items: flex-start; padding: .9rem 1rem; border: 1px solid var(--border); border-radius: 8px; background: #fbfcfd; }
.check input { width: 1.2rem; height: 1.2rem; margin-top: .2rem; flex: none; accent-color: var(--brand); }
.check label { font-weight: 500; }
.button { display: inline-flex; justify-content: center; align-items: center; gap: .4rem; font: inherit; font-weight: 600; padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--brand); background: var(--brand); color: #fff; cursor: pointer; text-decoration: none; }
.button:hover { background: var(--brand-dark); color: #fff; }
.button:disabled { opacity: .6; cursor: progress; }
.button.secondary { background: #fff; color: var(--brand); }
.button.secondary:hover { background: var(--brand-tint); }
.button.danger { background: var(--danger); border-color: var(--danger); }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); cursor: pointer; text-decoration: underline; }
.icon-button { background: none; border: 1px solid var(--border); border-radius: 8px; padding: .22rem .5rem; font-size: 1.05rem; cursor: pointer; display: none; flex-shrink: 0; }

/* Alerts, badges, notice */
.alert { padding: .75rem 1rem; border-radius: 8px; margin: 1rem 0; border: 1px solid; }
.alert-error { background: var(--danger-tint); border-color: #f3b4ae; color: #7a1a12; }
.alert-info { background: var(--brand-tint); border-color: #b9d4e8; }
.alert-warn { background: var(--warn-tint); border-color: #f0d28a; color: #5c3d00; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .04em; padding: .1rem .4rem; border-radius: 4px; vertical-align: middle; }
.badge-draft { background: #f1f5f9; color: var(--muted); border: 1px solid var(--border); font-weight: 600; }
.notice { background: var(--warn-tint); border: 1px solid #f0d28a; border-radius: 8px; padding: .35rem .7rem; margin: 1rem 0; font-size: .82rem; color: #4a3500; }
.notice summary { cursor: pointer; display: flex; gap: .45rem; align-items: center; font-weight: 500; list-style: none; }
.notice summary::-webkit-details-marker { display: none; }
.notice summary::after { content: "Details ▾"; margin-left: auto; font-size: .75rem; color: var(--muted); white-space: nowrap; }
.notice[open] summary::after { content: "Hide ▴"; }
.notice p { margin: .4rem 0 0; line-height: 1.45; }
.steps { text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; font-weight: 700; color: var(--muted); margin: 0 0 .5rem; }
details.doc { border: 1px solid var(--border); border-radius: 8px; margin: .6rem 0; background: #fbfcfd; }
details.doc summary { cursor: pointer; padding: .75rem 1rem; font-weight: 600; }
details.doc > *:not(summary) { padding: 0 1rem; }
.doc-body { max-height: 22rem; overflow: auto; border-top: 1px solid var(--border); background: #fff; font-size: .92rem; }
.legal h2 { font-size: 1.35rem; }
.archived-text { white-space: pre-wrap; font-family: var(--font); font-size: .92rem; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
.danger-zone { border: 1px solid #f3b4ae; background: #fffafa; border-radius: 8px; padding: 1rem; max-width: 26rem; }

/* Footer */
.footer { padding: .8rem 1rem; border-top: 1px solid var(--border); background: var(--surface); text-align: center; font-size: .84rem; }
.footer p { margin: .2rem 0; }

/* Chat layout */
body.chat-page { height: 100vh; height: 100dvh; overflow: hidden; }
body.chat-page main { padding: 0; display: flex; min-height: 0; flex: 1 1 auto; overflow: hidden; }
body.chat-page .topbar, body.chat-page .footer, .clinical-panel, .composer-wrap { flex-shrink: 0; }
body.chat-page .footer { padding: .2rem .75rem; font-size: .74rem; }
body.chat-page .footer p.muted { display: none; }
.chat-app { display: flex; flex: 1; min-height: 0; width: 100%; }
.sidebar { width: 16rem; flex: none; background: #f1f5f9; border-right: 1px solid var(--border); padding: .75rem; overflow-y: auto; display: flex; flex-direction: column; gap: .6rem; }
.conv-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .2rem; }
.conv-list button { width: 100%; text-align: left; background: none; border: 1px solid transparent; border-radius: 8px; padding: .45rem .65rem; font: inherit; font-size: .9rem; color: var(--text); cursor: pointer; }
.conv-list button:hover { background: #e2e8f0; }
.conv-list button[aria-current="true"] { background: #fff; border-color: var(--border); box-shadow: var(--shadow); }
.conv-list .conv-title { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.clinical-panel { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; padding: .35rem 1rem; border-bottom: 1px solid var(--border); background: #f8fafc; }
.clinical-select { width: auto; max-width: 20rem; padding: .26rem .55rem; font-size: .82rem; border-radius: 6px; background: #fff; color: var(--text); border: 1px solid var(--border); }
.thread { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 1rem; display: flex; flex-direction: column; gap: .75rem; }
.empty-state { max-width: 32rem; margin: auto; text-align: center; }
.msg { max-width: 46rem; width: 100%; }
.msg-user { align-self: flex-end; max-width: 36rem; width: auto; background: var(--brand); color: #fff; padding: .6rem .9rem; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-assistant { align-self: flex-start; background: #f8fafc; border: 1px solid var(--border); border-radius: 14px 14px 14px 4px; padding: .7rem 1rem; }
.msg-body .sec-head { font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--brand-dark); margin: .75rem 0 .25rem; padding-bottom: .15rem; border-bottom: 1px solid #e2e8f0; }
.msg-body .sec-head:first-child { margin-top: 0; }
.msg-body p { margin: .35rem 0; line-height: 1.55; }
.msg-body p:first-child { margin-top: 0; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body ul, .msg-body ol { margin: .35rem 0; padding-left: 1.35rem; }
.msg-body li { margin: .2rem 0; line-height: 1.5; }
.msg-emergency { background: var(--danger-tint); border-color: #f3b4ae; color: #5f150f; }
.msg-emergency .msg-body { font-weight: 600; }
.msg-redirect { background: var(--brand-tint); border-color: #b9d4e8; }
.msg-error { background: var(--warn-tint); border-color: #f0d28a; }
.typing { color: var(--muted); font-style: italic; }

/* Consolidated composer with follow-up question dropdowns + free-text response */
.composer-wrap { border-top: 1px solid var(--border); padding: .35rem 1rem .35rem; background: var(--surface); }
.composer-toggle { display: none; width: 100%; background: none; border: 0; padding: .15rem 0 .3rem; font: inherit; font-size: .78rem; font-weight: 600; color: var(--brand); cursor: pointer; text-align: center; }
.composer-wrap.collapsed .composer, .composer-wrap.collapsed .notice { display: none; }
.composer-wrap.collapsed { padding: .25rem 1rem; }
.composer-wrap.collapsed .composer-toggle { padding: .15rem 0; }
.composer { display: flex; flex-direction: column; gap: .45rem; }
.composer-questions { display: flex; flex-direction: column; gap: .35rem; padding-bottom: .35rem; border-bottom: 1px solid #eef2f6; }
.q-row { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; }
.q-label { font-size: .86rem; font-weight: 500; color: var(--text); flex: 1 1 14rem; margin: 0; }
.q-select { width: auto; min-width: 11rem; max-width: 18rem; flex: 0 1 auto; padding: .35rem .6rem; font-size: .86rem; border-radius: 6px; }
.composer-row { display: flex; gap: .45rem; align-items: flex-end; flex-wrap: nowrap; }
.composer-row textarea { resize: none; max-height: 8rem; min-height: 2.5rem; flex: 1 1 auto; min-width: 0; padding: .45rem .65rem; }
.new-conv-btn { white-space: nowrap; flex-shrink: 0; }
.new-conv-icon { flex-shrink: 0; }
.composer-wrap .notice { background: transparent; border: 0; padding: .2rem 0 0; margin: 0; font-size: .74rem; color: var(--muted); }
.composer-wrap .notice .badge-draft { display: none; }

@media (max-width: 760px) {
  main { padding: 1rem .5rem; }
  .card { padding: 1.25rem; }
  .icon-button { display: inline-block; }
  .sidebar { position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 4px 0 16px rgba(0,0,0,.15); }
  .sidebar.open { transform: none; }
  .sidebar-backdrop { position: fixed; z-index: 40; inset: 0; background: rgba(16, 24, 40, .25); cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .topbar { padding: .4rem .65rem; gap: .45rem; }
  .topbar-main { gap: .4rem; }
  body.chat-page .brand span, .topbar-sep { display: none; }
  .thread-title { font-size: .92rem; }
  .clinical-panel { padding: .3rem .65rem; }
  .clinical-select { max-width: 100%; font-size: .78rem; }
  .thread { padding: .75rem; gap: .6rem; }
  .composer-wrap { padding: .25rem .75rem .3rem; }
  .composer-toggle { display: block; }
  .q-row { flex-direction: column; align-items: stretch; gap: .2rem; }
  .q-label { flex: none; font-size: .83rem; }
  .q-select { width: 100%; max-width: 100%; }
  .composer-row { gap: .35rem; }
  .new-conv-btn { padding: .55rem .65rem; }
  .new-conv-label { display: none; }
  body.chat-page .footer { padding: .15rem .5rem; font-size: .7rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (prefers-color-scheme: dark) { /* intentionally light-only for v0.1; high contrast maintained */ }

/* Server-inserted emergency banner and response disclaimer (owner decision 2026-10-31): always shown, not collapsible. */
.msg-banner { border-left: 4px solid #b42318; background: #fef3f2; padding: 8px 12px; margin-bottom: 10px; border-radius: 6px; }
.msg-disclaimer { border-left: 4px solid #6b7280; background: #f3f4f6; padding: 8px 12px; margin-bottom: 10px; border-radius: 6px; font-size: 0.95em; }
