/*
 * styles.css — оформление демо: тема (светлая/тёмная), макет страницы, зубная схема.
 *
 * Схема (teeth.js) не содержит цветов: всё задаётся CSS-переменными здесь.
 * Стиль схемы «Фарфор»: объёмные зубы цвета эмали, рельеф, десна — как 3D-рендер.
 * Тёмная тема включается классом .dark на <html> (ставит скрипт по выбору пользователя или системы).
 */

/* ---------- Палитра страницы и цвета состояний (общие для обоих стилей) ---------- */
:root {
  --bg: #f3f6f8;
  --bg-glow: rgba(20, 150, 160, .10);
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --text: #0e1b2b;
  --muted: #64748b;
  --line: #e2e8ee;
  --accent: #0d7f86;
  --accent-soft: rgba(13, 127, 134, .10);
  --shadow-card: 0 1px 2px rgba(15, 30, 50, .04), 0 8px 30px rgba(15, 30, 50, .07);

  --c-caries: #e5484d;
  --c-pulpitis: #f76b15;
  --c-periodontitis: #8e4ec6;
  --c-filling: #3e63dd;
  --c-crown: #e0a32e;
  --c-endo_treated: #d6409f;
  --c-implant: #12a594;
  --c-missing: #94a3b8;
  --c-extraction_planned: #b4232c;
  --c-fracture: #5f9b1c;

  color-scheme: light;
}

html.dark {
  --bg: #0a111b;
  --bg-glow: rgba(45, 212, 191, .08);
  --surface: #111a26;
  --surface-2: #162130;
  --text: #e8eef5;
  --muted: #8b9bb0;
  --line: #223042;
  --accent: #2dd4bf;
  --accent-soft: rgba(45, 212, 191, .12);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 40px rgba(0, 0, 0, .35);

  --c-caries: #ff6369;
  --c-pulpitis: #ff8b3e;
  --c-periodontitis: #b07ef0;
  --c-filling: #6e8bff;
  --c-crown: #f2bf4b;
  --c-endo_treated: #f06ac0;
  --c-implant: #2ccbb2;
  --c-missing: #6b7c93;
  --c-fracture: #9be15d;
  --c-extraction_planned: #ff4d57;

  color-scheme: dark;
}

/* ---------- Базовая страница ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 500px at 50% -120px, var(--bg-glow), transparent 70%), var(--bg);
  transition: background-color .3s, color .3s;
}
.page { max-width: 1080px; margin: 0 auto; padding: 20px 16px 96px; }   /* снизу запас под кнопку чата */

/* Шапка */
.top { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.brand { display: flex; gap: 12px; align-items: center; flex: 1 1 260px; min-width: 0; }   /* на узком экране переключатель темы переносится ниже, а не выезжает за край */
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #14b8a6, #0d7f86); color: #fff;
  box-shadow: 0 6px 18px rgba(13, 127, 134, .35);
}
.brand h1 { font-size: 18px; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

/* Карточки-блоки */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-card);
  padding: 16px;
}
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }

/* Сегментированный переключатель (стиль, тема) */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600;
  padding: 7px 12px; border-radius: 9px; cursor: pointer; transition: background .2s, color .2s;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }
.seg.big button { padding: 10px 16px; font-size: 14px; }

/* Чипы демо-сценариев */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: 13px;
  padding: 7px 12px; border-radius: 999px; cursor: pointer; transition: border-color .2s, background .2s;
}
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 0; cursor: pointer; font: inherit; font-weight: 600; font-size: 14px;
  background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 12px;
}
html.dark .btn { color: #04201d; }

/* Макет: на телефоне блоки друг под другом (микрофон первым), на ноутбуке схема слева, микрофон и карта справа */
.layout {
  display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "mic" "chart" "card" "legend";
}
.area-mic { grid-area: mic; } .area-chart { grid-area: chart; } .area-card { grid-area: card; } .area-legend { grid-area: legend; }
@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); align-items: start;
    grid-template-areas: "chart mic" "chart card" "legend card";
  }
}
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; text-align: center; }

/* Легенда состояний */
.legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 12px; margin: 0; padding: 0; list-style: none; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend i { width: 14px; height: 14px; border-radius: 5px; background: var(--c); flex: none; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08); }
.legend i.dashed { background: transparent; border: 1.5px dashed var(--c); }

.footer { margin-top: 24px; text-align: center; color: var(--muted); font-size: 12px; }

/* =====================================================================
   Зубная схема
   ===================================================================== */
.teeth-wrap { position: relative; }
.teeth-chart { display: block; width: 100%; height: auto; max-height: 78vh; margin: 0 auto; overflow: visible; -webkit-tap-highlight-color: transparent; }

/* ---------- Токены схемы (стиль «Фарфор») ---------- */
.teeth-chart {
  --e1: #fffefb; --e2: #f7f0e3; --e3: #e3d4b8;
  --edge: #cdbb98; --edge-w: .7;
  --fissure: #a48f6b; --fissure-op: .38;
  --cusp-op: .85; --gloss-op: .55;
  --shadow: rgba(90, 62, 25, .38);
  --gum-1: #f7d7d5; --gum-2: #edbcbe;
  --divider: rgba(120, 100, 70, .45); --divider-op: 0;
  --zone-op: .78;
  --c1: #fff8de; --c2: #f3cf7a; --c3: #c8922a;
  --i1: #e9fffb; --i2: #8adccd; --i3: #2e8f81;
  --label: #8a97a8; --caption: #b3bdc9;
}
html.dark .teeth-chart {
  --e1: #fbf6ea; --e2: #ece0c8; --e3: #c6b38f;
  --edge: #8d7a58;
  --shadow: rgba(0, 0, 0, .7);
  --gum-1: #4a2a33; --gum-2: #3a1f27;
  --label: #6f8096; --caption: #3c4b5e;
  --zone-op: .82;
}

/* ---------- Градиенты: стопы берут цвет из токенов ---------- */
.st-e1 { stop-color: var(--e1); } .st-e2 { stop-color: var(--e2); } .st-e3 { stop-color: var(--e3); }
.st-cusp { stop-color: #fff; stop-opacity: var(--cusp-op); } .st-cusp0 { stop-color: #fff; stop-opacity: 0; }
.st-gloss { stop-color: #fff; stop-opacity: var(--gloss-op); } .st-gloss0 { stop-color: #fff; stop-opacity: 0; }
.st-c1 { stop-color: var(--c1); } .st-c2 { stop-color: var(--c2); } .st-c3 { stop-color: var(--c3); }
.st-i1 { stop-color: var(--i1); } .st-i2 { stop-color: var(--i2); } .st-i3 { stop-color: var(--i3); }
.st-core { stop-color: var(--c-pulpitis); stop-opacity: .95; } .st-core0 { stop-color: var(--c-pulpitis); stop-opacity: 0; }

/* ---------- Десна и подписи ---------- */
.gum path { fill: none; stroke-linecap: round; stroke-linejoin: round; transition: stroke .3s; }
.gum-outer { stroke: var(--gum-2); }
.gum-inner { stroke: var(--gum-1); }
.caption { fill: var(--caption); font-size: 9.5px; font-weight: 700; letter-spacing: .14em; text-anchor: middle; dominant-baseline: central; }
.caption.side { letter-spacing: .08em; font-weight: 600; text-transform: uppercase; }

.tlabel text { fill: var(--label); font-size: 10.5px; font-weight: 600; text-anchor: middle; dominant-baseline: central; transition: fill .4s; font-variant-numeric: tabular-nums; }
.tlabel-bg { fill: var(--lc, transparent); opacity: 0; transition: opacity .4s; }
.tlabel.active text { fill: var(--lc); font-weight: 800; }
.tlabel.active .tlabel-bg { opacity: .16; }

/* ---------- Зуб: базовые слои ---------- */
.tooth { cursor: pointer; outline: none; }
.tooth-body { transition: transform .25s cubic-bezier(.3, .7, .4, 1.3); }
.tooth:hover .tooth-body, .tooth:focus-visible .tooth-body, .tooth.selected .tooth-body { transform: scale(1.1); }

.t-natural { transition: opacity .5s; }
.t-shadow { fill: var(--shadow); }
.t-base { stroke: none; }
.t-edge { fill: none; stroke: var(--edge); stroke-width: var(--edge-w); transition: stroke .4s; }
.t-gloss { pointer-events: none; }
.t-fissure { fill: none; stroke: var(--fissure); stroke-opacity: var(--fissure-op); stroke-width: .9; stroke-linecap: round; }
.t-dividers { opacity: var(--divider-op); transition: opacity .3s; }
.t-dividers line, .t-dividers path { fill: none; stroke: var(--divider); stroke-width: .7; }
.teeth-chart .tooth:hover .t-dividers, .teeth-chart .tooth.selected .t-dividers { opacity: .8; }
.tooth.selected .t-edge { stroke: var(--accent); stroke-width: 1.6; }

/* ---------- Зоны (поверхности) ---------- */
.zone { fill: var(--zc, transparent); fill-opacity: 0; transition: fill-opacity .55s ease; }
.zone.z-caries   { --zc: var(--c-caries);   fill-opacity: var(--zone-op); }
.zone.z-pulpitis { --zc: var(--c-pulpitis); fill-opacity: var(--zone-op); }
.zone.z-filling  { --zc: var(--c-filling);  fill-opacity: var(--zone-op); }
.zone.z-fracture { --zc: var(--c-fracture); fill-opacity: var(--zone-op); }

/* ---------- Состояния целого зуба ---------- */
/* Наложения по умолчанию скрыты; появление — плавное */
.t-crown, .t-canals, .t-core, .t-ghost, .t-implant, .t-extract, .t-halo, .t-flash {
  opacity: 0; transition: opacity .5s; pointer-events: none;
}

/* Коронка: «металлокерамика/цирконий» — тёплый глянцевый слой поверх эмали */
.tooth.is-crown .t-crown { opacity: .95; }
.tooth.is-crown .t-edge { stroke: var(--c3); }

/* Эндолечение: видны запломбированные устья каналов */
.t-canals circle { fill: var(--c-endo_treated); stroke: #fff; stroke-width: .6; }
.tooth.is-endo_treated .t-canals { opacity: 1; }

/* Пульпит: пульсирующий очаг в центре */
.tooth.is-pulpitis .t-core { opacity: 1; animation: core-pulse 1.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes core-pulse { 0%, 100% { transform: scale(.75); opacity: .55; } 50% { transform: scale(1.1); opacity: 1; } }

/* Периодонтит: светящийся ореол вокруг зуба (ткани вокруг корня) */
.t-halo { fill: none; stroke: var(--c-periodontitis); stroke-width: 7; }
.tooth.is-periodontitis .t-halo { opacity: .8; animation: halo 2.4s ease-in-out infinite; }
@keyframes halo { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

/* Отсутствует / имплантат: от зуба остаётся пунктирный контур */
.t-ghost { fill: none; stroke: var(--c-missing); stroke-width: 1.1; stroke-dasharray: 2.6 2.2; }
.tooth.is-missing .t-natural, .tooth.is-implant .t-natural { opacity: 0; }
.tooth.is-missing .t-ghost { opacity: .9; }
.tooth.is-implant .t-ghost { opacity: .6; stroke: var(--c-implant); }
.tooth.is-implant .t-implant { opacity: 1; }
.imp-platform { stroke: var(--i3); stroke-width: 1; }
.imp-thread { fill: none; stroke: rgba(255, 255, 255, .75); stroke-width: 1; stroke-dasharray: 1.6 1.2; }
.imp-hex { fill: var(--i3); stroke: rgba(255, 255, 255, .5); stroke-width: .6; }

/* Под удаление: зуб приглушён, пунктир и крестик */
.tooth.is-extraction_planned .t-natural { opacity: .5; }
.tooth.is-extraction_planned .t-extract { opacity: 1; }
.ext-outline { fill: none; stroke: var(--c-extraction_planned); stroke-width: 1.5; stroke-dasharray: 3 2.2; }
.ext-cross { stroke: var(--c-extraction_planned); stroke-width: 2.2; stroke-linecap: round; }

/* «Вспышка» при появлении состояния: зуб подпрыгивает, от него расходится кольцо */
.t-flash { fill: none; stroke: var(--lc, var(--accent)); stroke-width: 2; transform-box: fill-box; transform-origin: center; }
.tooth.pop .tooth-body { animation: tooth-pop .7s cubic-bezier(.2, .9, .3, 1.4); }
.tooth.pop .t-flash { animation: tooth-flash .8s ease-out; }
@keyframes tooth-pop { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes tooth-flash { 0% { opacity: .9; transform: scale(1); } 100% { opacity: 0; transform: scale(1.9); } }

/* Молочные зубы чуть белее и голубоватее — их легко отличить */
.teeth-chart .tooth.primary { --e2: #f8f5ef; --e3: #e4dccd; }

@media (prefers-reduced-motion: reduce) {
  .tooth-body, .t-core, .t-halo { animation: none !important; transition: none !important; }
}

/* ---------- Карточка зуба ---------- */
.tooth-card {
  position: absolute; z-index: 5; width: min(290px, calc(100% - 12px));
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px;
  box-shadow: 0 12px 40px rgba(10, 25, 45, .22);
  animation: card-in .22s ease-out;
}
@keyframes card-in { from { opacity: 0; transform: translateY(6px) scale(.97); } to { opacity: 1; transform: none; } }
.tc-head { display: flex; align-items: center; gap: 10px; }
.tc-num {
  font-size: 20px; font-weight: 800; min-width: 44px; height: 40px; padding: 0 6px; border-radius: 12px;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-variant-numeric: tabular-nums;
}
.tc-title { flex: 1; min-width: 0; display: grid; }
.tc-title b { font-size: 14px; }
.tc-title em { font-style: normal; font-weight: 600; font-size: 11px; color: var(--accent); background: var(--accent-soft); padding: 1px 6px; border-radius: 6px; margin-left: 4px; }
.tc-title span { font-size: 12px; color: var(--muted); }
.tc-close { border: 0; background: var(--surface-2); color: var(--muted); width: 30px; height: 30px; border-radius: 50%; font-size: 18px; line-height: 1; cursor: pointer; flex: none; }
.tc-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.tc-list li { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; }
.tc-list i { width: 10px; height: 10px; border-radius: 4px; background: var(--c); margin-top: 4px; flex: none; }
.tc-list span { display: block; color: var(--muted); font-size: 12px; }
.tc-list p { margin: 2px 0 0; font-size: 12px; }
.tc-empty { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.tc-dx { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; }
.tc-icd { display: inline-block; margin-top: 4px; font-weight: 700; font-size: 12px; background: var(--surface-2); padding: 2px 8px; border-radius: 6px; }
.tc-warn { display: block; margin-top: 3px; font-size: 11px; color: #b7791f; }
html.dark .tc-warn { color: #f2bf4b; }

/* =====================================================================
   Запись голоса и карта приёма
   ===================================================================== */
.say { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.phrase {
  margin: 0 0 10px; padding: 12px 14px; border-left: 3px solid var(--accent); border-radius: 0 12px 12px 0;
  background: var(--accent-soft); font-size: 14px; line-height: 1.5;
}

.mic-zone { display: grid; justify-items: center; gap: 12px; padding: 18px 0 8px; }
.mic {
  position: relative; width: 92px; height: 92px; border: 0; border-radius: 50%; cursor: pointer; color: #fff;
  background: linear-gradient(145deg, #14b8a6, #0d7f86);
  box-shadow: 0 10px 28px rgba(13, 127, 134, .45), inset 0 1px 0 rgba(255, 255, 255, .35);
  display: grid; place-items: center; transition: transform .15s, background .3s;
  -webkit-tap-highlight-color: transparent;
}
html.dark .mic { color: #04201d; }
.mic:active:not(:disabled) { transform: scale(.94); }
.mic:disabled { cursor: default; }
.mic > * { grid-area: 1 / 1; display: none; }
.mic[data-state="idle"] .ic-mic, .mic[data-state="recording"] .ic-stop,
.mic[data-state="transcribing"] .ic-spin, .mic[data-state="analyzing"] .ic-spin, .mic[data-state="done"] .ic-done { display: block; }
/* Запись: красная кнопка с пульсирующим кольцом */
.mic[data-state="recording"] { background: linear-gradient(145deg, #ff6369, #d93a40); box-shadow: 0 10px 28px rgba(229, 72, 77, .5); }
.mic[data-state="recording"]::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%; border: 3px solid #ff6369; animation: mic-pulse 1.4s ease-out infinite;
}
.ic-stop { width: 26px; height: 26px; border-radius: 7px; background: #fff; }
.ic-spin {
  width: 34px; height: 34px; border-radius: 50%; border: 3.5px solid rgba(255, 255, 255, .35); border-top-color: #fff;
  animation: mic-spin .8s linear infinite;
}
html.dark .ic-spin { border-color: rgba(4, 32, 29, .3); border-top-color: #04201d; }
.mic[data-state="done"] { background: linear-gradient(145deg, #34c77b, #1c9d5a); box-shadow: 0 10px 28px rgba(28, 157, 90, .4); }
@keyframes mic-pulse { from { transform: scale(1); opacity: .9; } to { transform: scale(1.55); opacity: 0; } }
@keyframes mic-spin { to { transform: rotate(360deg); } }
.mic-status { font-size: 14px; color: var(--muted); text-align: center; min-height: 20px; }
.mic-error {
  max-width: 100%; padding: 10px 14px; border-radius: 12px; font-size: 14px; text-align: center;
  background: rgba(229, 72, 77, .10); color: var(--c-caries); border: 1px solid rgba(229, 72, 77, .35);
}

/* Текстовый ввод */
.text-input { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.text-input summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.text-input textarea {
  display: block; width: 100%; margin: 10px 0; padding: 10px 12px; font: inherit; font-size: 14px; resize: vertical;
  color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
}
.btn:disabled { opacity: .5; cursor: default; }

/* Карта приёма */
.f { padding: 9px 0; border-bottom: 1px solid var(--line); }
.f:last-child { border-bottom: 0; }
.f-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 3px; }
.f-val { font-size: 15px; overflow-wrap: anywhere; }
.f-val.empty { color: var(--muted); }
.f-list { margin: 0; padding-left: 18px; font-size: 15px; }
.f-note { margin-top: 4px; font-size: 12px; color: var(--muted); }
.f-transcript .f-val { font-size: 13px; color: var(--muted); font-style: italic; }
.missing {
  margin: 4px 0 8px; padding: 10px 14px; border-radius: 12px;
  background: rgba(245, 190, 40, .16); border: 1px solid rgba(220, 160, 20, .55);
}
.missing-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }


/* =====================================================================
   Общее: ссылка «Главная» в шапке
   ===================================================================== */
.top-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.back {
  color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 600; padding: 7px 10px; border-radius: 9px;
  transition: color .2s, background .2s;
}
.back:hover { color: var(--text); background: var(--surface-2); }

/* =====================================================================
   Главная-хаб: две большие карточки
   ===================================================================== */
.hub { min-height: 100dvh; display: flex; flex-direction: column; }
.hub .brand h1 { font-size: 19px; }
.hub-grid {
  flex: 1; display: grid; gap: 18px; align-content: center; grid-template-columns: minmax(0, 1fr);
  padding-block: 12px;
}
@media (min-width: 760px) { .hub-grid { grid-template-columns: 1fr 1fr; } }
.hub-card {
  position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 10px; min-height: 270px;
  padding: 28px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 28px; box-shadow: var(--shadow-card);
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease;
}
/* мягкое свечение в углу карточки */
.hub-card::before {
  content: ""; position: absolute; width: 340px; height: 340px; right: -120px; top: -140px; border-radius: 50%;
  background: radial-gradient(circle, var(--accent-soft), transparent 68%); pointer-events: none; transition: transform .4s ease;
}
.hub-card:hover, .hub-card:focus-visible { transform: translateY(-4px); border-color: var(--accent); box-shadow: 0 18px 50px rgba(13, 127, 134, .22); }
.hub-card:hover::before { transform: scale(1.25); }
.hub-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.hub-icon {
  width: 76px; height: 76px; border-radius: 22px; display: grid; place-items: center; color: #fff; margin-bottom: 8px;
  background: linear-gradient(135deg, #14b8a6, #0d7f86); box-shadow: 0 10px 26px rgba(13, 127, 134, .38);
}
.hub-title { font-size: 25px; font-weight: 700; line-height: 1.2; letter-spacing: -.015em; }
.hub-text { color: var(--muted); font-size: 15px; line-height: 1.45; max-width: 30ch; }
.hub-go { margin-top: auto; padding-top: 14px; font-weight: 600; color: var(--accent); font-size: 15px; }
.hub-go i { display: inline-block; font-style: normal; transition: transform .25s; }
.hub-card:hover .hub-go i { transform: translateX(5px); }

/* =====================================================================
   Чат (страница и виджет)
   ===================================================================== */
.chat { display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.chat-mark {
  width: 38px; height: 38px; border-radius: 12px; flex: none; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #14b8a6, #0d7f86);
}
.chat-titles { min-width: 0; flex: 1; }
.chat-title { font-weight: 700; font-size: 15px; }
.chat-sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.chat-close {
  border: 0; background: transparent; color: var(--muted); font-size: 28px; line-height: 1; cursor: pointer;
  width: 38px; height: 38px; border-radius: 10px; flex: none;
}
.chat-close:hover { background: var(--surface-2); color: var(--text); }

.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 18px; font-size: 15px; line-height: 1.45; overflow-wrap: anywhere; animation: msg-in .25s ease; }
.msg p { margin: 0; } .msg p + p, .msg ul + p, .msg p + ul { margin-top: 6px; }
.msg ul { margin: 0; padding-left: 20px; }
.msg-user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
html.dark .msg-user { color: #04201d; }
.msg-assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg-none .msg-body { color: var(--muted); }
.msg-err { border-color: #e5484d; }
.msg .w { opacity: 0; transition: opacity .28s ease; } .msg .w.on { opacity: 1; }
.msg-src { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 8px; animation: msg-in .3s ease; }
.msg-src a { color: var(--accent); text-decoration: none; font-weight: 600; overflow-wrap: anywhere; }
.msg-src a::after { content: " ↗"; }
.msg-src a:hover { text-decoration: underline; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Три прыгающие точки */
.msg-typing { display: flex; gap: 5px; padding: 14px 16px; }
.msg-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: dot 1.1s infinite ease-in-out; }
.msg-typing span:nth-child(2) { animation-delay: .15s; } .msg-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-5px); opacity: 1; } }

/* Подсказки-вопросы */
.chat-suggest { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; }
.chat-suggest[hidden] { display: none; }
.chat-suggest .chip { text-align: left; line-height: 1.3; }
.chat-suggest .chip:hover { border-color: var(--accent); color: var(--accent); }

/* Поле ввода */
.chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 12px 16px 14px; border-top: 1px solid var(--line); }
.chat-input {
  flex: 1; resize: none; font: inherit; font-size: 16px; /* 16px — чтобы iOS не увеличивал страницу при фокусе */
  color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px; max-height: 110px;
}
.chat-input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.chat-send {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center;
  background: var(--accent); color: #fff; transition: transform .15s, opacity .2s;
}
html.dark .chat-send { color: #04201d; }
.chat-send:hover { transform: scale(1.06); } .chat-send:disabled { opacity: .45; cursor: default; transform: none; }

/* Страница чата: карточка во всю высоту экрана */
.chat-layout { min-height: 100dvh; display: flex; flex-direction: column; max-width: 860px; padding-bottom: 24px; }
.chat-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; flex: 1; min-height: 420px; max-height: calc(100dvh - 190px); }
.chat-card > .chat { flex: 1; }

/* Виджет: кнопка и панель */
.chat-fab {
  position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); z-index: 50;
  width: 58px; height: 58px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #14b8a6, #0d7f86); box-shadow: 0 10px 28px rgba(13, 127, 134, .5);
  transition: transform .2s ease; animation: fab-pulse 2.4s ease-out 1.2s 2;
}
.chat-fab:hover { transform: scale(1.08); } .chat-fab.active { transform: scale(.94); }
@keyframes fab-pulse { 0% { box-shadow: 0 10px 28px rgba(13, 127, 134, .5), 0 0 0 0 rgba(20, 184, 166, .55); } 100% { box-shadow: 0 10px 28px rgba(13, 127, 134, .5), 0 0 0 22px rgba(20, 184, 166, 0); } }
.chat-panel {
  position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: calc(max(20px, env(safe-area-inset-bottom)) + 72px); z-index: 49;
  width: 390px; height: min(600px, calc(100dvh - 120px)); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 24px 70px rgba(10, 20, 35, .32); overflow: hidden;
  opacity: 0; transform: translateY(14px) scale(.97); transform-origin: bottom right; transition: opacity .2s ease, transform .2s ease;
}
.chat-panel[hidden] { display: none; }
.chat-panel.open { opacity: 1; transform: none; }
.chat-panel > .chat { flex: 1; }
/* Телефон: панель на весь экран, прокрутка страницы под ней отключена */
@media (max-width: 520px) {
  .chat-panel { inset: 0; width: auto; height: auto; border-radius: 0; border: 0; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  html.chat-open, html.chat-open body { overflow: hidden; }
  html.chat-open .chat-fab { display: none; }
}
@media (prefers-reduced-motion: reduce) { .chat-fab { animation: none; } .msg, .msg-src { animation: none; } }

@media (max-width: 520px) {
  .top-right { width: 100%; justify-content: space-between; }
  .top > .seg { margin-left: auto; }
  .brand h1 { font-size: 17px; }
}
