:root {
  --bg: #f3f2ee;
  --surface: #ffffff;
  --text: #1f1f1d;
  --muted: #9a978f;
  --border: #e6e4de;
  --chip-bg: #f1efe9;
  --accent: #1f1f1d;
  --radius: 24px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

/* ── IDLE MODE (по умолчанию) ── */
.page {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 48px 16px 32px;
  overflow-y: auto;
}

.header { display: none; }
.chat   { display: none; }

/* ── CHAT MODE ── */
.page--chat {
  justify-content: flex-start;
  gap: 0;
  padding: 0;
  overflow: hidden;
  height: 100%;
  height: 100dvh;
}

.page--chat .header {
  display: flex;
  align-items: center;
  width: 100%;
  flex-shrink: 0;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.header__logo {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.03em;
  cursor: pointer;
  user-select: none;
  flex: 1;
}

.model-settings-btn { color: var(--muted); }
.model-settings-btn:hover { color: var(--text); }

/* Модальное окно модели */
.model-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.model-modal:not([hidden]) {
  display: flex;
}
.model-modal__box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  width: min(480px, calc(100vw - 32px));
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}
.model-modal__title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 14px;
}
.model-modal__input {
  width: 100%;
  font-size: 14px;
  font-family: "SF Mono", "Fira Code", monospace;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  box-sizing: border-box;
  transition: border-color 0.15s;
}
.model-modal__input:focus { border-color: var(--accent); }
.model-modal__hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}
.model-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}
.model-modal__cancel {
  height: 38px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.model-modal__save {
  height: 38px;
  padding: 0 18px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 500;
}
.model-modal__label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 12px 0 4px;
}
.model-modal__label:first-of-type { margin-top: 0; }
.model-modal__textarea {
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
}
.demo-card__edit {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(4px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 2;
}
.demo-card:hover .demo-card__edit { opacity: 1; }

.page--chat .hero   { display: none; }
.page--chat .rates  { display: none; }
.page--chat .presets { display: none; }

.page--chat .chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  width: 100%;
  padding: 28px 16px 16px;
  gap: 24px;
}

.page--chat .search-wrap {
  flex-shrink: 0;
  width: 100%;
  padding: 12px 16px 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
}

/* ── Сообщения ── */
.msg {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

/* Пользователь — справа */
.msg--user {
  flex-direction: column;
  align-items: flex-end;
}

.msg__attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-bottom: 6px;
}

.msg__img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.msg__bubble {
  background: var(--accent);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  padding: 12px 16px;
  max-width: 80%;
  font-size: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ИИ — слева */
.msg--ai {
  align-items: flex-start;
}

.msg__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg__body {
  flex: 1;
  min-width: 0;
}

.msg__text {
  font-size: 16px;
  line-height: 1.7;
  word-break: break-word;
  color: var(--text);
}

.msg__text p { margin: 0 0 10px; }
.msg__text p:last-child { margin-bottom: 0; }
.msg__text strong { font-weight: 600; }
.msg__text em { font-style: italic; }
.msg__text ul, .msg__text ol { margin: 6px 0 10px 20px; padding: 0; }
.msg__text li { margin-bottom: 4px; }
.msg__text h1, .msg__text h2, .msg__text h3 {
  font-weight: 600;
  margin: 14px 0 6px;
  letter-spacing: -0.01em;
}
.msg__text h1 { font-size: 20px; }
.msg__text h2 { font-size: 17px; }
.msg__text h3 { font-size: 15px; }
.msg__text code {
  background: var(--chip-bg);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 14px;
  font-family: "SF Mono", "Fira Code", monospace;
}
.msg__text pre {
  background: var(--chip-bg);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 8px 0;
}
.msg__text pre code { background: none; padding: 0; }
.msg__text hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

.msg__error {
  color: #c0392b;
  font-size: 15px;
}

/* Блок рассуждений */
.msg__thinking {
  display: none;
}

.msg__thinking summary {
  font-size: 13px;
  color: var(--muted);
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.msg__thinking summary::before {
  content: "▶";
  font-size: 9px;
  transition: transform 0.15s;
}

.msg__thinking[open] summary::before {
  transform: rotate(90deg);
}

.msg__think-text {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  padding: 0 12px 10px;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}

/* Индикатор «печатает» — точки + статус времени */
.typing {
  display: flex;
  align-items: center;
  gap: 10px;
}

.typing-status {
  font-size: 13px;
  color: var(--muted);
}

.typing-status:empty { display: none; }

.typing-dots {
  display: flex;
  gap: 5px;
  padding: 8px 0;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: dot-pulse 1.6s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.28s; }
.typing-dots span:nth-child(3) { animation-delay: 0.56s; }

@keyframes dot-pulse {
  0%, 60%, 100% { opacity: 0.2; transform: translateY(0); }
  30%            { opacity: 1;   transform: translateY(-4px); }
}

/* Кнопка отправки в состоянии загрузки */
.submit-btn.is-loading {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Логотип */
.logo {
  font-size: clamp(40px, 7vw, 64px);
  font-weight: 600;
  letter-spacing: -0.03em;
  margin: 0;
}

/* Обёртка строки поиска: в idle-режиме .page имеет align-items: center,
   поэтому без явной ширины блок сжимается по max-width детей (720px) и
   вылезает за вьюпорт на узких экранах. width: 100% привязывает к вьюпорту. */
.search-wrap {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

/* Поисковая строка */
.search {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search.is-dragover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 31, 29, 0.08);
}

.search__input {
  min-height: 56px;
  font-size: 19px;
  line-height: 1.4;
  outline: none;
  padding: 4px 6px;
  word-break: break-word;
}

.search__input:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}

.search__input::after {
  content: attr(data-suggestion);
  color: var(--muted);
  pointer-events: none;
}

/* Превью прикреплённых файлов */
.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 4px 6px 12px;
}

.attachment {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  max-width: 220px;
}

.attachment img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

.attachment__doc {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border-radius: 8px;
  color: var(--muted);
}

.attachment__name {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attachment__remove {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

/* Нижняя панель */
.search__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.search__left,
.search__right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s;
}

.icon-btn:hover { background: var(--chip-bg); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.chip:hover { background: var(--chip-bg); }
.chip[data-active="true"] { background: var(--chip-bg); }
.chip__chevron { color: var(--muted); }

.model-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
}

.model-btn:hover { color: var(--text); }

.submit-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: opacity 0.15s;
}

.submit-btn:hover { opacity: 0.85; }

/* Быстрые варианты ответа */
.quick-replies {
  width: 100%;
  max-width: 720px;
  margin: 0 auto 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0;
}

.quick-reply {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 16px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.quick-reply:hover {
  background: var(--chip-bg);
  border-color: var(--accent);
}

/* Пресеты */
.presets {
  width: 100%;
  max-width: 720px;
  display: flex;
  align-items: center;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

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

.preset {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.preset:hover { background: var(--chip-bg); }
.preset svg { color: var(--muted); }

.preset--icon {
  width: 48px;
  padding: 0;
  justify-content: center;
  border-color: transparent;
}

/* Таблица тарифов */
.rates {
  width: 100%;
  max-width: 720px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.rates__head {
  margin-bottom: 14px;
}

.rates__title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}

.rates__note {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}

.rates__scroll {
  overflow-x: auto;
  scrollbar-width: thin;
}

.rates__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  white-space: nowrap;
}

.rates__table th,
.rates__table td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.rates__table th {
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.rates__table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rates__table tbody tr:last-child td {
  border-bottom: none;
}

.rates__table tbody tr:hover {
  background: var(--chip-bg);
}

/* ── Demo-карточки ── */
.demos-panel {
  width: 100%;
  max-width: 720px;
  margin: 10px auto 12px;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 8px 28px 28px;
  scrollbar-width: none;
}
.demos-panel::-webkit-scrollbar { display: none; }
.page--chat .demos-panel { display: none; }

.demo-card {
  flex-shrink: 0;
  width: 110px;
  border-radius: 16px;
  border: 1px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  background: var(--surface);
  padding: 0;
  font-family: inherit;
  transition: box-shadow 0.15s;
}
.demo-card:hover {
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.demo-card__thumb {
  height: 80px;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 38px;
}
.demo-card__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.demo-card__info {
  padding: 8px 10px 10px;
  border-top: 1px solid var(--border);
  text-align: left;
}
.demo-card__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.demo-card__sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 600px) {
  .search__right .model-btn span { display: none; }
  /* Задача 2: font-size 16px предотвращает зум iOS при фокусе */
  .search__input { font-size: 16px; }
  .rates { padding: 16px; }
  /* Задача 2: тач-зоны ≥44px */
  .icon-btn { width: 44px; height: 44px; }
  .submit-btn { width: 44px; height: 44px; }
  /* Задача 3: chips — горизонтальный скролл без переноса */
  .quick-replies {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .quick-replies::-webkit-scrollbar { display: none; }
  /* Задача 3: пресеты компактнее */
  .preset { height: 42px; font-size: 14px; }
  /* Задача 5: пузыри шире на мобильном */
  .msg__bubble { max-width: 88%; }
  /* Задача 5: шапка чата компактнее */
  .page--chat .header { padding: 10px 16px; }
  /* Задача 5: отступы чата на мобильном */
  .page--chat .chat { padding: 16px 12px 8px; gap: 16px; }
}

@media (max-width: 480px) {
  /* Задача 4: скрыть колонку «№» в таблице тарифов */
  .rates__table th:first-child,
  .rates__table td:first-child { display: none; }
  .rates__table th,
  .rates__table td { padding: 8px 10px; }
  .rates__table { font-size: 13px; }
}
