/* Аудитория — тяжелобольные и пожилые люди, часто с планшета в палате.
   Приоритеты неизменны: крупный шрифт, высокий контраст, большие цели
   нажатия. Оформление работает на спокойствие, а не на выразительность:
   человек приходит сюда встревоженным, и интерфейс не должен добавлять шума.

   Фон тёплый, бумажный: страница продолжает печатную брошюру, с которой
   пациент сюда и пришёл по QR-коду. */

:root {
  --paper: #f6f4ef;
  --surface: #ffffff;
  --ink: #16191c;
  --ink-soft: #55606e;
  --line: #e4e0d7;
  --accent: #0d5c63;
  --accent-ink: #ffffff;
  --accent-soft: #e7f0f0;
  --alarm: #a32a1f;
  --alarm-bg: #fbedea;
  --alarm-line: #eccec7;

  --radius: 18px;
  --radius-tight: 6px;
  --tap: 48px;

  --shadow-soft: 0 1px 2px rgb(22 25 28 / 0.04), 0 8px 24px rgb(22 25 28 / 0.06);
  --shadow-dock: 0 -8px 24px rgb(22 25 28 / 0.05);

  --step: 240ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'Golos Text', ui-sans-serif, system-ui, sans-serif;
  font-size: 19px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* Еле различимое тепло сверху: даёт глубину, но не отвлекает от текста. */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: 22rem;
  background: radial-gradient(
    80% 100% at 50% 0%,
    rgb(13 92 99 / 0.06),
    transparent 70%
  );
  pointer-events: none;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 44rem;
  margin: 0 auto;
  padding: 0 1.15rem;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Шапка */

.header {
  padding: 1.5rem 0 1rem;
}

.header__center {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.header__title {
  margin: 0.4rem 0 0;
  font-family: 'PT Serif', Georgia, serif;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.header__lead {
  margin: 0.3rem 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

/* Лента диалога */

.chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding-bottom: 1rem;
}

.loading {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  padding: 3rem 0;
}

.loading__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.35;
  animation: pulse 1.25s ease-in-out infinite;
}

.loading__dot:nth-child(2) { animation-delay: 0.18s; }
.loading__dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes pulse {
  0%, 100% { opacity: 0.25; transform: scale(0.85); }
  45%      { opacity: 1;    transform: scale(1); }
}

.msg {
  max-width: 88%;
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: rise var(--step) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.msg--bot {
  align-self: flex-start;
  border-bottom-left-radius: var(--radius-tight);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.msg--user {
  align-self: flex-end;
  border-bottom-right-radius: var(--radius-tight);
  background: var(--accent);
  color: var(--accent-ink);
}

/* Эскалация должна читаться как тревога, а не как обычный ответ */
.msg--alarm {
  align-self: stretch;
  max-width: 100%;
  border: 1px solid var(--alarm-line);
  border-left: 4px solid var(--alarm);
  border-radius: var(--radius-tight) var(--radius) var(--radius) var(--radius-tight);
  background: var(--alarm-bg);
  box-shadow: none;
  font-weight: 500;
}

.msg__sources {
  display: block;
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.msg--typing { color: var(--ink-soft); }

/* Оценка ответа */

.feedback {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.85rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--line);
}

.feedback__label {
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.feedback__button {
  min-height: 38px;
  padding: 0.25rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--step), border-color var(--step);
}

.feedback__button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.feedback__button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Нижняя полка: подсказки, ввод, дисклеймер */

.dock {
  position: sticky;
  bottom: 0;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--paper) 1.25rem);
}

.suggestions {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1.15rem 0.85rem;
  margin: 0 -1.15rem;
  overflow-x: auto;
  scrollbar-width: none;
  /* Горизонтальная лента, а не перенос: на узком экране шесть кнопок в
     столбик съедали половину высоты и выталкивали диалог. */
  scroll-snap-type: x proximity;
}

.suggestions::-webkit-scrollbar { display: none; }

.suggestion {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0.55rem 1.05rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  scroll-snap-align: start;
  box-shadow: var(--shadow-soft);
  transition: background var(--step), border-color var(--step), transform var(--step);
  animation: rise var(--step) both;
}

.suggestion:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.suggestion:active { transform: scale(0.97); }
.suggestion:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.composer {
  display: flex;
  gap: 0.55rem;
  align-items: flex-end;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  background: var(--surface);
  box-shadow: var(--shadow-dock);
  transition: border-color var(--step);
}

.composer:focus-within { border-color: var(--accent); }

.composer__input {
  flex: 1;
  min-height: calc(var(--tap) - 0.6rem);
  max-height: 9rem;
  padding: 0.5rem 0.6rem;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  resize: none;
}

.composer__input::placeholder { color: var(--ink-soft); }
.composer__input:focus-visible { outline: none; }

.composer__send {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: var(--tap);
  padding: 0 1.3rem;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--step), transform var(--step);
}

.composer__send:hover:not(:disabled) { background: #0a4b51; }
.composer__send:active:not(:disabled) { transform: scale(0.98); }
.composer__send:disabled { background: #9aa7ab; cursor: default; }
.composer__send:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

.composer__send-icon { width: 20px; height: 20px; }

.disclaimer {
  margin: 0.7rem 0 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
  text-align: center;
  text-wrap: balance;
}

@media (max-width: 30rem) {
  body { font-size: 18px; }
  .app { padding: 0 0.9rem; }
  .header { padding: 1.1rem 0 0.8rem; }
  .header__title { font-size: 1.5rem; }

  /* Подзаголовок повторяет дисклеймер в подвале, а две строки на первом
     экране стоят дороже: из-за них приветствие не помещалось целиком. */
  .header__lead { display: none; }

  .msg { max-width: 94%; }
  .suggestions { margin: 0 -0.9rem; padding-inline: 0.9rem; }

  /* На телефоне подпись съедает ширину, нужную самому вопросу. */
  .composer__send { padding: 0 1rem; }
  .composer__send-text { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
