/*
 * styles.css — вёрстка чат-виджета Whieda AI Assistant.
 *
 * Аудитория — партнёры MLM 50+, преимущественно не технические пользователи.
 * Отсюда набор жёстких требований ниже: крупный шрифт по умолчанию, высокий
 * контраст, отсутствие hover-only взаимодействий, крупные зоны нажатия,
 * видимый фокус, поддержка prefers-reduced-motion.
 */

*, *::before, *::after { box-sizing: border-box; }

/* ── Цветовые токены ───────────────────────────────────────────────────── */
/* Определяем один раз (светлая тема) на голом :root, тёмную тему переопре-
   деляем внутри @media (prefers-color-scheme: dark) — так, как просили:
   "default to light", т.к. виджет встраивается в контекст страницы Wix,
   где тёмная тема может выглядеть чужеродно, но поддержка обеих реализована
   корректно и переключается автоматически по системной настройке. */
:root {
  --wh-font-scale: 1; /* переключается кнопками A / A+ / A++ в app.js */
  --wh-base-font-size: 18px;

  --wh-color-bg: #ffffff;
  --wh-color-bg-elevated: #f3f4f6;
  --wh-color-text: #1a1a1a;
  --wh-color-text-muted: #46484c;
  --wh-color-border: #d3d6db;

  --wh-color-primary: #0b5d3f;
  --wh-color-primary-hover: #084b32;
  --wh-color-primary-text: #ffffff;

  --wh-color-user-bubble-bg: #e3edff;
  --wh-color-user-bubble-text: #0c1f3d;
  --wh-color-assistant-bubble-bg: #f3f4f6;
  --wh-color-assistant-bubble-text: #1a1a1a;

  --wh-color-danger: #8c1d15;
  --wh-color-danger-bg: #fbe9e7;
  --wh-color-warning-bg: #fff2da;
  --wh-color-warning-text: #5c3d00;
  --wh-color-disclaimer-bg: #fff6d9;
  --wh-color-disclaimer-text: #4a3900;

  --wh-color-link: #0a4faa;
  --wh-color-focus-ring: #0b5d3f;

  --wh-radius: 10px;
  --wh-tap-min: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --wh-color-bg: #17191d;
    --wh-color-bg-elevated: #21242a;
    --wh-color-text: #f2f2f2;
    --wh-color-text-muted: #cfd1d5;
    --wh-color-border: #3c4048;

    --wh-color-primary: #3fd192;
    --wh-color-primary-hover: #35b57e;
    --wh-color-primary-text: #06251a;

    --wh-color-user-bubble-bg: #223a5e;
    --wh-color-user-bubble-text: #eaf1ff;
    --wh-color-assistant-bubble-bg: #24272e;
    --wh-color-assistant-bubble-text: #f2f2f2;

    --wh-color-danger: #ff9a90;
    --wh-color-danger-bg: #3a1e1b;
    --wh-color-warning-bg: #3a2f13;
    --wh-color-warning-text: #ffd98a;
    --wh-color-disclaimer-bg: #332a08;
    --wh-color-disclaimer-text: #ffe58a;

    --wh-color-link: #8ec1ff;
    --wh-color-focus-ring: #3fd192;
  }
}

/* ── Базовая типографика ──────────────────────────────────────────────── */
html, body {
  height: 100%;
  margin: 0;
}

body {
  /* Виджет всегда живёт в iframe с фиксированной высотой (см. README) —
     задаём разумную высоту и скролл ленты внутри, не полагаясь на то, что
     родительская страница пришлёт resize. */
  height: 100vh;
  background: var(--wh-color-bg);
  color: var(--wh-color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: calc(var(--wh-base-font-size) * var(--wh-font-scale));
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

/* Видимый фокус — НЕ убираем, только заменяем стандартный на более заметный */
:focus-visible {
  outline: 3px solid var(--wh-color-focus-ring);
  outline-offset: 2px;
}

/* ── Общий layout ─────────────────────────────────────────────────────── */
.wh-app {
  position: relative;
  display: flex;
  height: 100%;
  overflow: hidden;
}

.wh-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
}

/* ── Хамбургер ────────────────────────────────────────────────────────── */
.wh-hamburger {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 20;
  min-width: var(--wh-tap-min);
  min-height: var(--wh-tap-min);
  border: 1px solid var(--wh-color-border);
  border-radius: var(--wh-radius);
  background: var(--wh-color-bg-elevated);
  font-size: 1.3em;
  line-height: 1;
  cursor: pointer;
}

/* ── Сайдбар / drawer со списком чатов ────────────────────────────────── */
.wh-sidebar {
  position: absolute;
  inset: 0 auto 0 0;
  width: min(85vw, 320px);
  background: var(--wh-color-bg-elevated);
  border-right: 1px solid var(--wh-color-border);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  z-index: 30;
  height: 100%;
}

.wh-sidebar.wh-sidebar-open {
  transform: translateX(0);
}

/* На широких экранах (>=640px) сайдбар не наезжает поверх контента, а
   сдвигает его — раздвигаем layout вместо position:absolute-оверлея. */
@media (min-width: 640px) {
  .wh-sidebar {
    position: relative;
    width: 0;
    min-width: 0;
    border-right: none;
    overflow: hidden;
    transform: none;
    transition: width 0.2s ease;
  }
  .wh-sidebar.wh-sidebar-open {
    width: 300px;
    min-width: 300px;
    border-right: 1px solid var(--wh-color-border);
  }
}

.wh-sidebar-overlay {
  display: none;
}

@media (max-width: 639px) {
  .wh-sidebar-overlay:not([hidden]) {
    display: block;
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 25;
  }
}

.wh-sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  padding-left: calc(var(--wh-tap-min) + 16px); /* место под хамбургер */
  border-bottom: 1px solid var(--wh-color-border);
}

.wh-btn-block { flex: 1 1 auto; }

.wh-icon-btn {
  min-width: var(--wh-tap-min);
  min-height: var(--wh-tap-min);
  border: 1px solid var(--wh-color-border);
  border-radius: var(--wh-radius);
  background: var(--wh-color-bg);
  font-size: 1.2em;
  cursor: pointer;
}

.wh-session-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.wh-session-item {
  display: flex;
  align-items: stretch;
  gap: 4px;
  margin-bottom: 6px;
}

.wh-session-btn {
  flex: 1 1 auto;
  text-align: left;
  min-height: var(--wh-tap-min);
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: var(--wh-radius);
  background: transparent;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wh-session-btn[aria-current="true"] {
  background: var(--wh-color-bg);
  border-color: var(--wh-color-border);
  font-weight: 600;
}

.wh-session-delete {
  min-width: var(--wh-tap-min);
  min-height: var(--wh-tap-min);
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--wh-radius);
  cursor: pointer;
  color: var(--wh-color-text-muted);
}

/* ── Шапка и управление размером шрифта ───────────────────────────────── */
.wh-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 10px calc(var(--wh-tap-min) + 16px);
  border-bottom: 1px solid var(--wh-color-border);
}

.wh-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wh-font-controls {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
}

.wh-font-btn {
  min-width: var(--wh-tap-min);
  min-height: var(--wh-tap-min);
  border: 1px solid var(--wh-color-border);
  background: var(--wh-color-bg);
  border-radius: var(--wh-radius);
  cursor: pointer;
  font-weight: 600;
}

.wh-font-btn[aria-pressed="true"] {
  background: var(--wh-color-primary);
  color: var(--wh-color-primary-text);
  border-color: var(--wh-color-primary);
}

/* ── Баннер состояния (paywall / rate-limited / auth-error / offline) ───── */
.wh-state-banner {
  margin: 10px 12px 0;
  padding: 12px 14px;
  border-radius: var(--wh-radius);
  background: var(--wh-color-warning-bg);
  color: var(--wh-color-warning-text);
  font-weight: 500;
}

.wh-state-banner-auth-error,
.wh-state-banner-offline {
  background: var(--wh-color-danger-bg);
  color: var(--wh-color-danger);
}

/* ── Лента сообщений ──────────────────────────────────────────────────── */
.wh-message-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.wh-message {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(70ch, 92%);
}

.wh-message-user {
  align-self: flex-end;
  align-items: flex-end;
}

.wh-message-assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.wh-message-content {
  padding: 12px 14px;
  border-radius: var(--wh-radius);
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.wh-message-user .wh-message-content {
  background: var(--wh-color-user-bubble-bg);
  color: var(--wh-color-user-bubble-text);
}

.wh-message-assistant .wh-message-content {
  background: var(--wh-color-assistant-bubble-bg);
  color: var(--wh-color-assistant-bubble-text);
}

.wh-message-content p:first-child { margin-top: 0; }
.wh-message-content p:last-child { margin-bottom: 0; }
.wh-message-content a { color: var(--wh-color-link); }
.wh-message-content pre {
  overflow-x: auto;
  background: var(--wh-color-bg);
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--wh-color-border);
}
.wh-message-content code {
  background: var(--wh-color-bg);
  padding: 0.1em 0.3em;
  border-radius: 4px;
}
.wh-message-content pre code {
  background: none;
  padding: 0;
}

.wh-message-error {
  color: var(--wh-color-danger);
  font-weight: 500;
}

.wh-message-system-error {
  align-self: center;
  color: var(--wh-color-danger);
  font-weight: 500;
  text-align: center;
}

/* Источники — чипы-ссылки под ответом ассистента */
.wh-message-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.wh-source-chip {
  display: inline-flex;
  align-items: center;
  min-height: var(--wh-tap-min);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--wh-color-border);
  background: var(--wh-color-bg);
  color: var(--wh-color-link);
  text-decoration: none;
  font-size: 0.9em;
}
.wh-source-chip:empty { display: none; }

/* Кнопки 👍 / 👎 — всегда видимы, НЕ hover-reveal */
.wh-message-actions {
  display: flex;
  gap: 6px;
}

.wh-feedback-btn {
  min-width: var(--wh-tap-min);
  min-height: var(--wh-tap-min);
  border: 1px solid var(--wh-color-border);
  background: var(--wh-color-bg);
  border-radius: var(--wh-radius);
  cursor: pointer;
  font-size: 1.1em;
}

.wh-feedback-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.wh-feedback-sent {
  border-color: var(--wh-color-primary);
}

/* ── Индикатор "печатает" ─────────────────────────────────────────────── */
.wh-typing-indicator {
  min-height: 1.6em;
  padding: 0 12px;
  color: var(--wh-color-text-muted);
  font-style: italic;
}

/* Классический приём "бегущих точек": анимируем width overflow:hidden
   контейнера с текстом "..." — content нельзя надёжно анимировать через
   @keyframes во всех браузерах, а width — можно. */
.wh-typing-indicator:not(:empty)::after {
  content: '...';
  display: inline-block;
  width: 0;
  margin-left: 0.2em;
  overflow: hidden;
  white-space: nowrap;
  vertical-align: bottom;
  animation: wh-typing-dots 1.2s steps(4, end) infinite;
}

@media (prefers-reduced-motion: reduce) {
  .wh-typing-indicator:not(:empty)::after {
    animation: none;
    width: auto;
  }
}

@keyframes wh-typing-dots {
  0%   { width: 0; }
  100% { width: 1.1em; }
}

/* ── Дисклеймер — постоянный, без возможности закрыть ─────────────────── */
.wh-disclaimer {
  margin: 0;
  padding: 10px 12px;
  background: var(--wh-color-disclaimer-bg);
  color: var(--wh-color-disclaimer-text);
  font-size: 0.85em;
  line-height: 1.5;
  border-top: 1px solid var(--wh-color-border);
}

/* ── Композер ─────────────────────────────────────────────────────────── */
.wh-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--wh-color-border);
}

.wh-textarea {
  flex: 1 1 auto;
  min-height: var(--wh-tap-min);
  max-height: 200px;
  padding: 10px 12px;
  border: 1px solid var(--wh-color-border);
  border-radius: var(--wh-radius);
  background: var(--wh-color-bg);
  resize: none;
}

.wh-textarea:disabled {
  opacity: 0.6;
}

.wh-composer-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.wh-btn {
  min-width: var(--wh-tap-min);
  min-height: var(--wh-tap-min);
  padding: 10px 18px;
  border-radius: var(--wh-radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
}

.wh-btn-primary {
  background: var(--wh-color-primary);
  color: var(--wh-color-primary-text);
}
.wh-btn-primary:hover { background: var(--wh-color-primary-hover); }
.wh-btn-primary:disabled {
  opacity: 0.5;
  cursor: default;
}

.wh-btn-stop {
  background: var(--wh-color-danger-bg);
  color: var(--wh-color-danger);
  border-color: var(--wh-color-danger);
}

/* ── Скрытие ──────────────────────────────────────────────────────────── */
[hidden] { display: none !important; }
