:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1f232c; --line: #2a2f3a; --text: #e8eaf0; --muted: #9aa3b2;
  --accent: #6aa8ff; --accent2: #3d7be0; --mine: #2b5fb8; --ok: #3ecf8e; --warn: #f2b84b; --err: #ff6b6b;
  --r: 18px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; }
body { overscroll-behavior: none; }
#app { height: 100%; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; }
.hidden { display: none !important; }
.splash { margin: auto; font-size: 48px; opacity: .6; }
h1 { font-size: 22px; margin: 0; }
p { margin: .4em 0; }
.muted { color: var(--muted); font-size: 14px; }
.err { color: var(--err); min-height: 1.2em; font-size: 14px; }
.warn { color: var(--warn); font-size: 14px; }

/* карточки: вход, установка */
.card { margin: auto; width: min(92vw, 400px); background: var(--panel); border: 1px solid var(--line); border-radius: 22px;
  padding: 26px 22px; display: flex; flex-direction: column; gap: 12px; margin-top: calc(var(--safe-t) + 8vh); }
.logo { font-size: 40px; text-align: center; }
.card h1 { text-align: center; }
input, textarea { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 14px; padding: 13px 14px; outline: none; width: 100%; font-size: 16px; }
input:focus, textarea:focus { border-color: var(--accent2); }
.btn { font: inherit; font-weight: 600; border: 0; border-radius: 14px; padding: 13px 16px; background: var(--accent2);
  color: #fff; cursor: pointer; }
.btn:disabled { opacity: .5; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--err); border: 1px solid var(--line); }
.btn.small { padding: 9px 12px; font-size: 15px; border-radius: 12px; }
.steps { padding-left: 1.2em; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.ios-share { display: inline-block; border: 1px solid var(--muted); border-radius: 6px; padding: 0 5px; }

/* шапка */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-t) + 10px) 14px 10px; background: rgba(15, 17, 21, .92); backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.top h1 { flex: 1; }
.top-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.top-title small { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: transparent; border: 0; color: var(--accent); font-size: 24px; padding: 4px 8px; cursor: pointer; line-height: 1; }
.icon-btn.back { font-size: 34px; padding: 0 8px 4px 0; }

/* список чатов */
.threads { display: flex; flex-direction: column; padding: 6px 0; }
.thread { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: transparent; border: 0;
  border-bottom: 1px solid var(--line); color: inherit; text-align: left; font: inherit; cursor: pointer; width: 100%; }
.thread:active { background: var(--panel); }
.avatar { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; font-size: 26px; flex: none; }
.avatar.doctor { background: linear-gradient(135deg, #1f4d7a, #2e7d6b); }
.avatar.assistant { background: linear-gradient(135deg, #5a3d8a, #8a3d6e); }
.avatar.small { width: 36px; height: 36px; font-size: 19px; }
.thread-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.thread-title { display: flex; justify-content: space-between; gap: 8px; }
.thread-title time { color: var(--muted); font-size: 13px; flex: none; }
.thread-preview { color: var(--muted); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-preview.typing { color: var(--accent); }
.badge { background: var(--accent2); color: #fff; border-radius: 12px; min-width: 24px; height: 24px; padding: 0 7px;
  font-size: 14px; font-weight: 700; display: grid; place-items: center; }
.push-card { margin: 12px 14px 0; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
.push-card .row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

/* переписка */
.messages { flex: 1; overflow-y: auto; padding: 12px 10px 16px; display: flex; flex-direction: column; gap: 6px;
  -webkit-overflow-scrolling: touch; }
.msg { display: flex; flex-direction: column; max-width: 88%; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; }
.bubble { background: var(--panel2); border-radius: var(--r); padding: 9px 13px; overflow-wrap: anywhere; min-width: 48px; }
.msg.mine .bubble { background: var(--mine); border-bottom-right-radius: 6px; }
.msg.theirs .bubble { border-bottom-left-radius: 6px; }
.msg.reminder .bubble { background: #2a2414; border: 1px solid #5b4a1e; }
.msg.failed .bubble { border: 1px solid #5a2a2a; color: #f3c2c2; }
.msg-time { color: var(--muted); font-size: 12px; margin: 2px 6px 4px; }
.plain { white-space: pre-wrap; }
.typing-row { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.streaming { opacity: .85; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.acked { margin-top: 8px; color: var(--ok); font-size: 14px; }
.att-img img { display: block; max-width: 100%; max-height: 320px; border-radius: 12px; margin-bottom: 6px; }
.att-file { display: flex; gap: 8px; align-items: center; color: inherit; text-decoration: none; background: rgba(0,0,0,.18);
  padding: 8px 10px; border-radius: 12px; margin-bottom: 6px; }
.att-audio audio { width: 240px; max-width: 100%; height: 40px; }
.transcript { font-size: 14px; margin: 4px 0 2px; opacity: .9; }

/* markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: .45em 0; }
.md-h { margin: .7em 0 .3em; font-size: 17px; }
h3.md-h { font-size: 18px; }
.md-list { margin: .3em 0; padding-left: 1.35em; }
.md-list li { margin: .15em 0; }
.md-code { background: rgba(0,0,0,.3); padding: 1px 5px; border-radius: 6px; font: 14px ui-monospace, Menlo, monospace; }
.md-pre { background: rgba(0,0,0,.35); padding: 10px; border-radius: 10px; overflow-x: auto; font: 13px/1.4 ui-monospace, Menlo, monospace; }
.md-quote { margin: .5em 0; padding: 4px 0 4px 12px; border-left: 3px solid var(--line); color: #cfd5df; }
.md-callout { border-left-color: var(--accent); background: rgba(106,168,255,.08); border-radius: 0 10px 10px 0; padding: 8px 12px; }
.md-callout.md-warning, .md-callout.md-caution { border-left-color: var(--warn); background: rgba(242,184,75,.08); }
.md-link { color: var(--accent); }
.msg.mine .md-link { color: #fff; }
.md-table-wrap { overflow-x: auto; margin: .5em 0; }
.md-table { border-collapse: collapse; font-size: 14px; }
.md-table th, .md-table td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.md-table th { background: rgba(255,255,255,.04); }
hr { border: 0; border-top: 1px solid var(--line); margin: .8em 0; }

/* композер */
.composer { position: sticky; bottom: 0; background: rgba(15, 17, 21, .96); border-top: 1px solid var(--line);
  padding: 8px 10px calc(var(--safe-b) + 8px); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea { resize: none; max-height: 160px; border-radius: 20px; padding: 10px 14px; line-height: 1.35; }
.send { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent2); color: #fff; font-size: 18px; cursor: pointer; }
.send:disabled { opacity: .5; }
.mic.rec { color: var(--err); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips:not(:empty) { margin-bottom: 8px; }
.chip { display: flex; align-items: center; gap: 6px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  padding: 4px 6px 4px 4px; max-width: 220px; }
.chip img { width: 40px; height: 40px; object-fit: cover; border-radius: 8px; }
.chip.uploading { opacity: .55; }
.chip-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-x { background: transparent; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; }
.rec-bar { display: flex; align-items: center; gap: 10px; width: 100%; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--err); animation: blink 1s infinite; }
.rec-time { flex: 1; font-variant-numeric: tabular-nums; }

/* меню и тосты */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; z-index: 20; }
.sheet { width: 100%; max-width: 760px; margin: 0 auto; background: var(--panel); border-radius: 22px 22px 0 0;
  padding: 16px 16px calc(var(--safe-b) + 16px); display: flex; flex-direction: column; gap: 10px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 90px); transform: translate(-50%, 20px); opacity: 0;
  background: #2a2f3a; color: var(--text); padding: 10px 16px; border-radius: 14px; transition: .25s; z-index: 30;
  max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
