/* Meyar — клинический справочный ассистент.
   Палитра и типографика интерфейса: тёмно-синий с красным акцентом, серифные
   заголовки. Знак и имя — из фирменного стиля Meyar (design/meyar). Метрики — «свободная» плотность, единственная. */

:root {
  --bg-app: #f6f7f9;
  --bg-panel: #ffffff;
  --brand: #12284b;
  --brand-hover: #1e3a63;
  --brand-soft: #eef1f6;
  --brand-tint: #fbfcfd;
  --brand-tab: #f1f3f6;
  --mark-tile: linear-gradient(135deg, #16304f, #091424);
  --accent: #c0392b;
  --accent-hover: #9c2e22;
  --accent-soft: #fbf1ef;
  --accent-line: #eedfdc;
  --ink: #12284b;
  --ink-muted: #47536b;
  --ink-faint: #7a8598;
  --line: #e3e6ec;
  --line-soft: #edeff3;
  --line-field: #d8dce4;
  --side-ink: #c9d5e8;
  --side-faint: #8fa3c4;
  --user-bubble: #f1f3f6;
  --danger: #c0392b;
  --ok: #2e7d62;

  /* Тревожная поверхность: ошибки, признаки тревоги, несходящиеся сведения.
     Тёплая производная от красного акцента — заметнее обычной карточки,
     но не кричит. */
  --flag-bg: #fdf5f3;
  --flag-line: var(--accent-line);
  --flag-title: var(--accent-hover);
  --flag-icon: var(--accent);
  --flag-ink: #5b4a47;
  --flag-note: #7a655f;

  --thread-pad: 26px 26px;
  --composer-pad: 14px 26px 18px;
  --col-max: 660px;
  --msg-gap: 24px;
  --bubble-pad: 13px 17px;
  --fs-msg: 14.5px;
}

* { box-sizing: border-box; }

/* Явные display-правила ниже перебивают браузерное [hidden]{display:none} — возвращаем его. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-app);
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; border-bottom: 1px solid rgba(14, 92, 85, 0.28); }
a:hover { color: var(--accent-hover); }
a.plain { border-bottom: none; }

h1, h2, h3 {
  font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.005em;
}

button, input, textarea { font-family: inherit; }
button:focus-visible, a:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.icon { width: 1em; height: 1em; flex: none; display: inline-block; vertical-align: -0.125em; }

.sc::-webkit-scrollbar { width: 9px; }
.sc::-webkit-scrollbar-thumb { background: #cbdcd6; border-radius: 5px; border: 3px solid #fff; }

@keyframes blink { 50% { opacity: 0; } }
.caret {
  display: inline-block;
  width: 6px; height: 14px;
  background: var(--brand);
  vertical-align: -2px;
  margin-left: 3px;
  animation: blink 1s steps(1) infinite;
}

.app { height: 100vh; display: flex; background: var(--bg-app); }

/* ── боковая панель ───────────────────────────────────── */

.side {
  width: 266px; flex: none;
  display: flex; flex-direction: column; gap: 18px;
  padding: 20px 18px;
  background: var(--brand);
  color: var(--side-ink);
}
.side-org { display: flex; align-items: center; gap: 11px; }
.side-org img {
  height: 40px; width: auto; flex: none;
  object-fit: contain; background: #fff;
  border-radius: 8px; padding: 4px;
}
.side-org-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.side-org-name { font-family: "Source Serif 4", Georgia, "Times New Roman", serif; font-size: 13px; font-weight: 700; color: #fff; }
.side-org-sub { font-size: 10.5px; opacity: 0.8; line-height: 1.35; }

.side-new {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 14px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff; font-size: 13px; font-weight: 600; cursor: pointer;
}
.side-new:hover { background: rgba(255, 255, 255, 0.16); }

.side-history { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; }
.side-label { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.72; margin-bottom: 6px; }
.side-item {
  padding: 8px 10px; border: none; border-radius: 8px;
  background: transparent; color: inherit;
  cursor: pointer; text-align: left; display: block; width: 100%;
}
.side-item:hover { background: rgba(255, 255, 255, 0.08); }
.side-item[aria-current="true"] { background: rgba(255, 255, 255, 0.14); }
.side-item-title { font-size: 12.5px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-item-meta { font-size: 10.5px; opacity: 0.72; }
.side-empty { font-size: 11px; line-height: 1.5; opacity: 0.7; padding: 2px 2px 6px; }
.side-hint { font-size: 10.5px; line-height: 1.5; opacity: 0.72; padding-top: 8px; }

.side-foot { display: flex; flex-direction: column; gap: 10px; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, 0.16); }
.side-note { display: flex; gap: 9px; align-items: flex-start; }
.side-note .icon { font-size: 14px; margin-top: 2px; opacity: 0.8; }
.side-note span { font-size: 11px; line-height: 1.5; }
.side-note.strong span { font-weight: 600; }

/* ── основная колонка ─────────────────────────────────── */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg-panel); }

.head {
  flex: none; display: flex; align-items: center; flex-wrap: wrap;
  gap: 12px 16px; padding: 14px 26px;
  border-bottom: 1px solid var(--line);
}
.head-id { display: flex; flex-direction: column; gap: 3px; margin-right: auto; }
.head-title { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.head-title h1 { font-size: 15.5px; }
.head-badge {
  font-size: 10.5px; padding: 2px 7px; border-radius: 5px;
  background: var(--user-bubble); color: var(--accent-warm); letter-spacing: 0.04em;
}
.head-status { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--ink-faint); }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: #c6d8d3; }
.dot[data-state="ready"] { background: var(--ok); }
.dot[data-state="down"] { background: var(--danger); }

.tabs { display: flex; gap: 3px; padding: 3px; border-radius: 9px; background: var(--brand-tab); }
.tabs button {
  font-size: 12px; padding: 6px 11px;
  border: none; border-radius: 6px; cursor: pointer;
  background: transparent; color: var(--ink-faint); font-weight: 500;
}
.tabs button[aria-pressed="true"] { background: #fff; color: var(--brand); }

/* ── лента ────────────────────────────────────────────── */

.thread { flex: 1; min-height: 0; overflow-y: auto; padding: var(--thread-pad); }
.col { max-width: var(--col-max); margin: 0 auto; display: flex; flex-direction: column; gap: var(--msg-gap); }

.greet { display: flex; flex-direction: column; gap: 22px; padding: 8px 0 4px; }
.greet-text { display: flex; flex-direction: column; gap: 10px; }
.greet h2 { font-size: 26px; line-height: 1.25; text-wrap: pretty; }
.greet p { margin: 0; font-size: 14px; line-height: 1.7; color: var(--ink-muted); max-width: 62ch; text-wrap: pretty; }
.topics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.topic {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 14px 15px;
  border: 1px solid var(--line-soft); border-radius: 11px;
  background: #fbfdfc; cursor: pointer; text-align: left;
}
.topic:hover { border-color: #c6d8d3; }
.topic .icon { font-size: 16px; color: var(--brand); margin-top: 1px; }
.topic span { font-size: 12.5px; line-height: 1.5; color: var(--ink); }

.msg { display: flex; flex-direction: column; gap: 11px; }

.bubble-user {
  align-self: flex-end; max-width: 80%;
  padding: var(--bubble-pad);
  border-radius: 14px 14px 4px 14px;
  background: var(--user-bubble);
  font-size: var(--fs-msg); line-height: 1.6; white-space: pre-wrap;
}

.bot { display: flex; gap: 12px; align-items: flex-start; }
.bot-avatar {
  width: 28px; height: 28px; flex: none;
  border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-size: 14px; margin-top: 2px;
}
.bot-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.bot-text { font-size: var(--fs-msg); line-height: 1.75; white-space: pre-wrap; text-wrap: pretty; }

.local-note, .incomplete {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  padding: 2px 8px; border-radius: 5px;
  font-size: 10.5px; letter-spacing: 0.03em;
}
.local-note { background: var(--brand-tab); color: var(--ink-faint); }
.incomplete { background: var(--flag-bg); color: var(--flag-title); border: 1px solid var(--flag-line); }

.links { display: flex; flex-wrap: wrap; gap: 7px; }
.links a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 8px;
  background: var(--brand-tab); font-size: 12px; font-weight: 500; border-bottom: none;
}
.links .icon { font-size: 12px; opacity: 0.6; }

.card {
  display: flex; flex-direction: column; gap: 9px;
  padding: 15px 16px; border-radius: 13px;
  background: var(--brand-tint); border: 1px solid var(--line-soft);
}
.card-head { display: flex; align-items: center; gap: 8px; }
.card-head .icon { font-size: 14px; color: var(--brand); }
.card-title { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.card-list { display: flex; flex-direction: column; gap: 8px; }
.card-item { display: flex; flex-direction: column; gap: 2px; }
.card-item a { font-size: 12.5px; line-height: 1.45; font-weight: 500; }
.card-item span { font-size: 11px; color: var(--ink-faint); }
.card-note { font-size: 11.5px; line-height: 1.55; color: var(--ink-faint); }
.card-body { font-size: 12.5px; line-height: 1.6; color: var(--ink-muted); }

.card.flags { background: var(--flag-bg); border-color: var(--flag-line); }
.card.flags .card-title { color: var(--flag-title); }
.card.flags .card-note { color: var(--flag-note); }
.flag-row { display: flex; gap: 9px; align-items: flex-start; }
.flag-row .icon { font-size: 13px; color: var(--flag-icon); margin-top: 3px; }
.flag-row span { font-size: 12.5px; line-height: 1.55; color: var(--flag-ink); }

.card.escalate { gap: 11px; }
.consults { display: flex; flex-wrap: wrap; gap: 6px; }
.consults button {
  padding: 7px 11px; border-radius: 8px; font-size: 12px;
  cursor: pointer; text-align: left;
  border: 1px solid var(--line-field); background: #fff;
  color: var(--ink-muted); font-weight: 500;
}
.consults button[aria-pressed="true"] { background: var(--brand-tint); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.escalate-cta { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; padding-top: 2px; }
.escalate-cta .call {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 15px; border-radius: 8px;
  background: var(--brand); color: #fff;
  font-size: 12.5px; font-weight: 600; border-bottom: none;
}
.escalate-cta .call:hover { background: var(--brand-hover); color: #fff; }
.escalate-cta .secondary {
  padding: 9px 15px; border-radius: 8px;
  border: 1px solid #c6d8d3; font-size: 12.5px; font-weight: 600;
  color: var(--ink); border-bottom: 1px solid #c6d8d3;
}

.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.actions button {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 10px; border: none; border-radius: 7px;
  background: var(--brand-tab); color: var(--ink-muted);
  font-size: 11.5px; cursor: pointer;
}
.actions button:hover { color: var(--brand); }

.chips { display: flex; flex-direction: column; gap: 8px; }
.chips-label { font-size: 11.5px; letter-spacing: 0.11em; text-transform: uppercase; color: var(--ink-faint); }
.chips-row { display: flex; flex-wrap: wrap; gap: 7px; }
.chips-row button {
  padding: 8px 13px; border-radius: 999px;
  border: 1px solid var(--line-field); background: #fff;
  color: var(--ink); font-size: 12.5px; cursor: pointer; text-align: left;
}
.chips-row button:hover { border-color: var(--brand); color: var(--brand); }

.error {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 13px 15px; border-radius: 12px;
  background: var(--flag-bg); border: 1px solid var(--flag-line);
}
.error .icon { font-size: 15px; color: var(--flag-icon); margin-top: 2px; }
.error-text { display: flex; flex-direction: column; gap: 5px; align-items: flex-start; }
.error-title { font-size: 12.5px; font-weight: 600; color: var(--flag-title); }
.error-body { font-size: 12px; line-height: 1.55; color: var(--flag-ink); }
.error-code { font-size: 11px; color: var(--flag-note); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.error button {
  margin-top: 3px; display: flex; align-items: center; gap: 5px;
  padding: 5px 10px; border: 1px solid var(--flag-line); border-radius: 7px;
  background: #fff; color: var(--flag-title); font-size: 11.5px; cursor: pointer;
}

/* ── композер ─────────────────────────────────────────── */

.composer { flex: none; padding: var(--composer-pad); border-top: 1px solid var(--line); }
.composer-col { max-width: var(--col-max); margin: 0 auto; display: flex; flex-direction: column; gap: 9px; }
.composer-row { display: flex; gap: 9px; align-items: flex-end; }
.composer textarea {
  flex: 1; min-width: 0; resize: none;
  padding: 12px 14px;
  border: 1px solid var(--line-field); border-radius: 10px;
  font-size: 13.5px; line-height: 1.5; color: var(--ink);
  outline: none; background: #fbfdfc;
}
.composer textarea:focus { border-color: var(--brand); }
.send, .stop {
  width: 46px; height: 46px; flex: none;
  border-radius: 10px; font-size: 16px; cursor: pointer;
  display: grid; place-items: center;
}
.send { border: none; background: var(--brand); color: #fff; }
.send:hover { background: var(--brand-hover); }
.send[disabled] { background: #c6d8d3; cursor: not-allowed; }
.stop { border: 1px solid var(--line-field); background: #fff; color: var(--ink-muted); font-size: 15px; }
.composer-note { font-size: 11.5px; line-height: 1.55; color: var(--ink-faint); }

@media (max-width: 900px) {
  .side { display: none; }
  .topics { grid-template-columns: 1fr; }
}

/* ── источники ответа ─────────────────────────────────────
   Основа даёт цитаты и сноски, подкрепление — только ссылки. */

.card-hint { font-size: 11px; color: var(--ink-faint); }

.footnote {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 10.5px;
  font-weight: 600;
  vertical-align: super;
  padding: 0 1px 0 2px;
  border-bottom: none;
  color: var(--accent);
}
.footnote:hover { color: var(--accent-hover); text-decoration: underline; }

.source { display: flex; gap: 10px; align-items: flex-start; scroll-margin-top: 12px; }
.source:target .source-quote { background: var(--brand-soft); border-radius: 3px; }
.source-num {
  flex: none; width: 15px;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 13px; font-weight: 600; line-height: 1.55;
  color: var(--accent);
}
.source-body { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.source-quote { font-size: 12.5px; line-height: 1.6; color: var(--ink-muted); font-style: italic; }
.source-meta { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.source-meta .icon { font-size: 12px; color: var(--ink-faint); }
.source-doc { font-size: 11.5px; color: var(--ink); font-weight: 500; }
.source-lang {
  font-size: 9.5px; letter-spacing: 0.07em;
  padding: 1px 5px; border: 1px solid var(--line-field); border-radius: 2px;
  color: var(--ink-faint);
}
.source-place { font-size: 11.5px; color: var(--ink-faint); }

.card.support { background: #fbfcfd; border-color: var(--line-field); }
.support-item {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 7px 8px; border-radius: 6px; border-bottom: none;
}
.support-item:hover { background: var(--brand-tab); }
.support-item .icon { font-size: 12px; color: var(--ink-faint); margin-top: 3px; }
.support-title { display: block; font-size: 12.5px; line-height: 1.45; color: var(--ink); font-weight: 500; }
.support-meta { display: block; font-size: 11.5px; color: var(--ink-faint); }

.card.notfound { background: #fafbfb; }
.card.notfound .card-title { color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 13.5px; font-family: "Source Serif 4", Georgia, "Times New Roman", serif; }

/* Уточнения — приглашение дополнить вопрос, поэтому карточка тихая, а сами
   вопросы выглядят нажимаемыми. */
.card.clarify { background: var(--brand-tint); border-color: var(--line); }
.clarify-item {
  display: flex; flex-direction: column; gap: 4px; width: 100%;
  padding: 9px 11px; text-align: left; cursor: pointer;
  background: #fff; border: 1px solid var(--line-field); border-radius: 8px;
  font: inherit; color: inherit;
}
.clarify-item:hover { border-color: var(--brand); background: var(--brand-soft); }
.clarify-q { font-size: 12.5px; line-height: 1.45; color: var(--ink); font-weight: 500; }
.clarify-src { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--ink-faint); }
.clarify-src .icon { font-size: 12px; flex: none; }

/* Противоречие показывает обе стороны: «данные противоречивы» без указания
   на что — бесполезно. */
.card.conflict { background: var(--flag-bg); border-color: var(--flag-line); }
.card.conflict .card-title { color: var(--flag-title); }
.card.conflict .card-head .icon { color: var(--flag-icon); }
.card.conflict .card-note { color: var(--flag-note); }
.conflict-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.conflict-side {
  font-size: 12.5px; line-height: 1.55; color: var(--flag-ink); font-style: italic;
}
.conflict-vs { flex: none; font-size: 13px; color: var(--flag-icon); }

/* Таблицу не цитируем: извлечение из PDF расплющивает её в неразборчивую
   строку. Показываем ссылку на место в документе. */
.source-table {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 7px 10px;
  border: 1px dashed var(--line-field); border-radius: 4px;
  background: #fbfcfc;
  font-size: 12px; color: var(--ink-faint);
}
.source-table .icon { font-size: 13px; }
.source-table a { font-weight: 500; }

/* ── фирменный блок и настройки ───────────────────────── */

.side-mark {
  width: 34px; height: 34px; flex: none;
  border-radius: 9px; background: var(--mark-tile);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  display: grid; place-items: center;
}
.side-org-name {
  font-family: "Unbounded", "IBM Plex Sans", system-ui, sans-serif;
  font-size: 16px; font-weight: 600; color: #fff; letter-spacing: -0.01em;
}
.side-org-sub { font-size: 11px; line-height: 1.3; color: var(--side-ink); }
/* Организация, в которой развёрнута система: отдельной строкой под брендом. */
.side-org-client {
  margin-top: -8px;
  font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--side-faint);
}

.side-settings {
  display: flex; align-items: center; gap: 9px; width: 100%;
  margin-top: 3px; padding: 8px 9px;
  border: none; border-radius: 5px; background: transparent;
  color: var(--side-ink); font-family: inherit; cursor: pointer; text-align: left;
}
.side-settings:hover, .side-settings[aria-expanded="true"] { background: rgba(255, 255, 255, 0.11); }
.side-settings .icon { font-size: 15px; color: var(--side-faint); }
.side-settings-label { font-size: 11.5px; font-weight: 500; color: #e1e8f3; }
.side-settings-value { margin-left: auto; font-size: 11px; color: var(--side-faint); }

.settings-panel {
  position: absolute; left: 18px; bottom: 78px; width: 282px; z-index: 5;
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px; border: 1px solid var(--line); border-radius: 5px;
  background: #fff; box-shadow: 0 12px 32px rgba(18, 40, 75, 0.2);
}
.settings-head {
  display: flex; align-items: center; gap: 9px;
  padding-bottom: 11px; border-bottom: 1px solid var(--line-soft);
  font-family: "Source Serif 4", Georgia, serif; font-size: 14px; font-weight: 600; color: var(--ink);
}
.settings-head .icon { font-size: 15px; color: var(--ink); }
.settings-label {
  font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-faint); font-weight: 600; padding: 0 11px;
}
.settings-langs { display: flex; flex-direction: column; gap: 2px; }
.lang-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 11px; border: none; border-radius: 4px; background: transparent;
  font-family: inherit; cursor: pointer; text-align: left;
}
.lang-row:hover { background: var(--brand-tab); }
.lang-row[aria-pressed="true"] { background: var(--brand-tab); }
.lang-row.soon { opacity: 0.55; cursor: default; }
.lang-label { font-size: 13px; color: var(--ink); }
.lang-row[aria-pressed="true"] .lang-label { font-weight: 500; }
.lang-native { font-size: 11.5px; color: var(--ink-faint); }
.lang-check { margin-left: auto; display: flex; color: var(--accent); font-size: 15px; }
.lang-soon {
  margin-left: auto; font-size: 9.5px; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 2px 6px; border: 1px solid var(--line); border-radius: 2px; color: var(--ink-faint);
}
.settings-note { font-size: 11px; line-height: 1.55; color: var(--ink-faint); padding: 0 11px; }

.app { position: relative; }
