/* ————————————————————————————————————————————————
   Аптека AI — чат в стиле Telegram (dark)
   ———————————————————————————————————————————————— */

:root {
  --bg: #0e1621;
  --header-bg: #17212b;
  --composer-bg: #17212b;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --panel: #17212b;
  --panel-2: #212936;
  --border: #242f3d;
  --text: #ffffff;
  --muted: #7f91a4;
  --accent: #62a8e5;
  --accent-strong: #4fa6ea;
  --green: #4dcd5e;
  --red: #e05b5b;
}

* { box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(79, 166, 234, .07), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(77, 205, 94, .05), transparent 60%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }

/* ——— Каркас ——— */

.chat-shell {
  display: flex;
  flex-direction: column;
  max-width: 1024px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  background: rgba(14, 22, 33, .72);
  border-left: 1px solid rgba(36, 47, 61, .6);
  border-right: 1px solid rgba(36, 47, 61, .6);
  box-shadow: 0 0 60px rgba(0, 0, 0, .45);
}

/* ——— Шапка ——— */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.chat-header__peer {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.chat-avatar svg { width: 22px; height: 22px; }

.chat-peer__name {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}

.chat-peer__status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex: none;
}
.chat-peer__status.is-busy .status-dot {
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .4; transform: scale(.8); }
}

.chat-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 7px 12px;
  font-size: 13px;
  outline: none;
  max-width: 240px;
}
.header-select:focus { border-color: var(--accent); }

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 7px 14px;
  font-size: 13px;
  transition: background .15s ease, border-color .15s ease;
}
.header-btn:hover { background: #2a3646; border-color: var(--accent); }
.header-btn svg { width: 15px; height: 15px; color: var(--accent-strong); }

/* ——— Лента ——— */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
}

.msg {
  display: flex;
  max-width: 100%;
}
.msg--bot { justify-content: flex-start; }
.msg--user { justify-content: flex-end; }

.msg__bubble {
  position: relative;
  max-width: min(560px, 82%);
  padding: 8px 12px 9px;
  border-radius: 14px;
  background: var(--bubble-in);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .35);
  font-size: 14.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.msg--bot .msg__bubble {
  border-bottom-left-radius: 5px;
}
.msg--user .msg__bubble {
  background: var(--bubble-out);
  border-bottom-right-radius: 5px;
}

.msg__label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--accent-strong);
  margin-bottom: 6px;
}
.msg--user .msg__label { color: #a8d4ff; }

.msg__meta {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
}

.msg__text { white-space: pre-wrap; }

.msg__time {
  display: block;
  text-align: right;
  font-size: 10.5px;
  color: rgba(255, 255, 255, .45);
  margin-top: 3px;
  user-select: none;
}

.msg--error .msg__bubble {
  background: rgba(224, 91, 91, .14);
  border: 1px solid rgba(224, 91, 91, .45);
  color: #ffb4b4;
}

/* Печатающий ответ */
.msg__text.is-streaming::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--accent-strong);
  animation: blink .9s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

/* Индикатор «печатает» */
.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 11px 14px;
}
.typing__label {
  font-size: 13.5px;
  color: var(--muted);
  margin-right: 3px;
}
.typing__dots {
  display: inline-flex;
  gap: 4px;
}
.typing__dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing 1.2s infinite ease-in-out;
}
.typing__dots i:nth-child(2) { animation-delay: .15s; }
.typing__dots i:nth-child(3) { animation-delay: .3s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ——— Найденные позиции ——— */

.match-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.match {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  transition: border-color .15s ease;
}
.match:hover { border-color: rgba(98, 168, 229, .5); }

.match__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.match__name {
  font-size: 14px;
  font-weight: 600;
}
.match__price {
  font-size: 14px;
  font-weight: 700;
  color: var(--green);
  white-space: nowrap;
}
.match__meta {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}
.match__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

/* ——— Чипы и бейджи ——— */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  line-height: 1.3;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .04);
  color: #b9c5d2;
}
.chip--ok {
  border-color: rgba(77, 205, 94, .45);
  background: rgba(77, 205, 94, .12);
  color: #7fe38d;
}
.chip--bad {
  border-color: rgba(224, 91, 91, .45);
  background: rgba(224, 91, 91, .12);
  color: #ff9d9d;
}
.chip--mute { color: var(--muted); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.badge--stock { background: rgba(77, 205, 94, .14); color: #7fe38d; }
.badge--out { background: rgba(224, 91, 91, .14); color: #ff9d9d; }
.badge--symptom { background: rgba(98, 168, 229, .16); color: #9ccdf5; }
.badge--score { background: rgba(255, 255, 255, .06); color: var(--muted); font-weight: 500; }

/* ——— Быстрые подсказки ——— */

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.suggestion-chip {
  border: 1px solid rgba(98, 168, 229, .55);
  background: rgba(98, 168, 229, .1);
  color: #9ccdf5;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  transition: background .15s ease, color .15s ease;
}
.suggestion-chip:hover {
  background: rgba(98, 168, 229, .22);
  color: #fff;
}

.about-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 999px;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.about-btn::before {
  content: '';
  width: 13px;
  height: 13px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  background:
    linear-gradient(currentColor, currentColor) center 2px / 1.5px 1.5px no-repeat,
    linear-gradient(currentColor, currentColor) center 5.5px / 1.5px 4.5px no-repeat;
  opacity: .9;
}
.about-btn:hover {
  color: var(--accent);
  border-color: rgba(98, 168, 229, .55);
  background: rgba(98, 168, 229, .08);
}

/* ——— Пустое состояние ——— */

.empty-state {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 26px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ——— Ввод ——— */

.chat-composer {
  flex: none;
  background: var(--composer-bg);
  border-top: 1px solid var(--border);
  padding: 10px 14px 8px;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 132px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  line-height: 1.4;
  padding: 11px 14px;
  outline: none;
  transition: border-color .15s ease;
}
.composer textarea::placeholder { color: var(--muted); }
.composer textarea:focus { border-color: var(--accent); }

.send-btn {
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  background: var(--accent-strong);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  transition: transform .12s ease, background .15s ease, opacity .15s ease;
}
.send-btn:hover { background: #3f95d9; }
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { opacity: .5; cursor: not-allowed; }
.send-btn svg { width: 21px; height: 21px; margin-left: 2px; }

.composer-hint {
  margin: 6px 2px 0;
  font-size: 11px;
  color: rgba(127, 145, 164, .75);
  text-align: center;
}

/* ——— Модалка каталога ——— */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal[hidden] { display: none; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(2px);
}

.modal__panel {
  position: relative;
  width: min(940px, 100%);
  max-height: min(86vh, 900px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
  overflow: hidden;
  animation: modal-in .18s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to { opacity: 1; transform: none; }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
}

.modal__title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.modal__count {
  font-size: 12px;
  color: var(--muted);
}

.modal__tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal__tools input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 13.5px;
  padding: 8px 14px;
  width: 220px;
  outline: none;
}
.modal__tools input:focus { border-color: var(--accent); }

.modal__close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  transition: background .15s ease, color .15s ease;
}
.modal__close:hover { background: rgba(224, 91, 91, .2); color: #ff9d9d; }

.modal__body {
  padding: 14px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

/* Модалка «О проекте» */
.modal__panel--about {
  width: min(560px, 100%);
}
.modal__body--about {
  display: block;
  padding: 18px 20px 20px;
  font-size: 14px;
  line-height: 1.6;
}
.modal__body--about p { margin: 0 0 12px; }
.modal__body--about ul {
  margin: 0 0 12px;
  padding-left: 20px;
}
.modal__body--about li { margin-bottom: 5px; }
.modal__body--about li::marker { color: var(--accent); }
.about__note {
  margin-top: 16px !important;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  font-size: 12.5px;
  color: var(--muted);
}

/* Карточки каталога */
.drug-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  padding: 12px 14px;
  transition: border-color .15s ease, transform .15s ease;
}
.drug-card:hover {
  border-color: rgba(98, 168, 229, .5);
  transform: translateY(-1px);
}
.drug-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.drug-card__name {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.3;
}
.drug-card__price {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--green);
  white-space: nowrap;
}
.drug-card__meta {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.45;
}
.drug-card__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.drug-card__tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

/* ——— Тост ——— */

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  max-width: 420px;
  border-radius: 12px;
  background: #2b2118;
  border: 1px solid rgba(224, 91, 91, .5);
  color: #ffd7d7;
  font-size: 13.5px;
  line-height: 1.5;
  padding: 12px 16px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .55);
  animation: toast-in .25s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ——— Скроллбар ——— */

.chat-messages::-webkit-scrollbar,
.modal__body::-webkit-scrollbar { width: 8px; height: 8px; }
.chat-messages::-webkit-scrollbar-thumb,
.modal__body::-webkit-scrollbar-thumb {
  background: rgba(127, 145, 164, .35);
  border-radius: 4px;
}
.chat-messages::-webkit-scrollbar-track { background: transparent; }

/* ——— Мобильные ——— */

@media (max-width: 720px) {
  .chat-shell {
    border: none;
    box-shadow: none;
  }
  .header-select { max-width: 132px; font-size: 12px; }
  .header-btn span { display: none; }
  .msg__bubble { max-width: 92%; }
  .modal__tools input { width: 130px; }
  .composer-hint { display: none; }
}
