/* ==========================================================================
   СнабКонтроль ИИ — слой оформления по макету Google Stitch «Smart Supply AI»
   (экраны 07/08/09 — AI Assistant). Подключается ПОСЛЕ app.css.
   Значения перенесены из макета: hex/px, скругления 2/4/8/12, primary #003EC7,
   моно-шрифт для номеров, иконки Material Symbols из локального шрифта.
   ========================================================================== */

/* ---------- база ---------- */
body {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 20px;
  color: var(--text);
  background: var(--bg);
}

/* Иконки макета */
.msym {
  font-family: "Material Symbols Outlined";
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  display: inline-block;
  white-space: nowrap;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  flex: none;
}

.msym--fill { font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 24; }
.msym--16 { font-size: 16px; }
.msym--18 { font-size: 18px; }
.msym--20 { font-size: 20px; }

/* ---------- боковая панель тредов (по макету: 280px, светлая) ---------- */
.sidebar,
[data-theme="dark"] .sidebar {
  color: var(--sidebar-text);
  background: var(--sidebar-bg) !important;
  border-right: 1px solid var(--sidebar-line);
}

.sidebar .wordmark-name { color: var(--sidebar-text-strong); }
.sidebar .wordmark-suffix { color: var(--sidebar-muted); }

.sidebar-section { border-color: var(--sidebar-line); }

/* Заголовок-капс «Недавние диалоги» */
.sidebar-section > h2,
.sidebar-section > h3,
.conversation-list-title {
  font-size: 11px;
  line-height: 16px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Элемент списка диалогов */
.conversation-item {
  min-height: 40px;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 20px;
  color: var(--sidebar-text);
  border: 1px solid transparent;
  border-radius: var(--radius);
}

.conversation-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); }

.conversation-item.active,
.conversation-item[aria-current="true"] {
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-soft);
  border-color: var(--accent-soft-line);
}

/* ---------- верхняя панель ----------
   !important — перебиваем «синий хром» прошлой версии оформления в app.css */
.topbar,
[data-theme="light"] .topbar,
[data-theme="dark"] .topbar {
  height: 64px;
  min-height: 64px;
  padding: 0 32px;
  gap: 16px;
  color: var(--text) !important;
  background: var(--surface) !important;
  border-bottom: 1px solid var(--line) !important;
}

.topbar .wordmark-name,
.topbar .wordmark-name b { color: var(--text) !important; }
.topbar .wordmark-name b { color: var(--accent) !important; }
.topbar .theme-toggle-label,
.topbar .theme-toggle { color: var(--text-2) !important; }

.topbar .wordmark-name { color: var(--text); }
.topbar .wordmark-suffix { color: var(--muted); }
.topbar .tabs { display: none !important; }
.proj-dd { display: none !important; }

.topbar .icon-button,
.topbar .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px !important;
  min-width: 36px !important;
  height: 36px !important;
  padding: 0 !important;
  color: var(--text-2) !important;
  background: transparent !important;
  border: 0 !important;
  border-radius: var(--radius) !important;
}

.topbar .icon-button:hover,
.topbar .icon-btn:hover { color: var(--text) !important; background: var(--surface-3) !important; }

/* ---------- шапка чата ---------- */
.chat-header {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
}

.chat-kicker {
  font-size: 11px;
  line-height: 16px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-2);
}

.chat-header h1,
.chat-title-wrap h1 {
  margin: 2px 0 0;
  font-size: 20px;
  line-height: 28px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--text);
}

/* ---------- пузыри сообщений (макет 07:267-323) ---------- */
.message {
  max-width: 85%;
  margin: 0 0 16px;
  padding: 16px;
  font-size: 14px;
  line-height: 20px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px 4px 4px 0;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, .05);
}

/* Сообщение пользователя: синий пузырь справа, срезан правый нижний угол */
.message.user,
.message.me,
.message[data-role="user"] {
  max-width: 80%;
  margin-left: auto;
  margin-right: 0;
  padding: 8px 16px;
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
  border-radius: 4px 4px 0 4px;
}

[data-theme="dark"] .message.user,
[data-theme="dark"] .message.me,
[data-theme="dark"] .message[data-role="user"] {
  color: var(--text);
  background: var(--surface-4);
  border-color: var(--line);
}

/* Ответ ассистента: аватар-плашка с иконкой слева */
.message.assistant { position: relative; margin-left: 40px; }

.message.assistant::before {
  content: "\f06c"; /* smart_toy */
  position: absolute;
  left: -40px;
  top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-family: "Material Symbols Outlined";
  font-size: 16px;
  font-variation-settings: "FILL" 0, "wght" 400;
  color: var(--accent-fixed);
  background: var(--accent-hover);
  border-radius: var(--radius);
}

[data-theme="dark"] .message.assistant::before {
  color: var(--accent-fixed);
  background: var(--secondary-container);
}

.message-content { font-size: 14px; line-height: 20px; overflow-wrap: anywhere; }
.message-content p { margin: 0 0 16px; }
.message-content p:last-child { margin-bottom: 0; }

.message-content h1,
.message-content h2,
.message-content h3 {
  margin: 16px 0 8px;
  font-size: 16px;
  line-height: 24px;
  font-weight: 600;
  color: var(--text);
}

.message-content a { color: var(--accent); }
.message-content code,
.message-content pre {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* Таблица в ответе — как в макете */
.message-content table {
  width: 100%;
  margin: 8px 0 16px;
  border-collapse: collapse;
  font-size: 12px;
  line-height: 16px;
}

.message-content thead {
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.message-content th {
  padding: 8px 12px;
  font-size: 11px;
  line-height: 16px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-2);
  text-align: left;
}

.message-content td {
  padding: 8px 12px;
  color: var(--text-2);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 50%, transparent);
}

.message-content td:first-child { font-family: var(--font-mono); font-size: 13px; color: var(--accent); }

/* ---------- поле ввода (макет 07:327-339) ---------- */
.composer {
  padding: 8px 16px 16px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.composer-box {
  max-width: 768px;
  gap: 8px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, .05);
}

.composer-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.composer-box textarea {
  min-height: 40px;
  padding: 10px 4px;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 20px;
  color: var(--text);
  background: transparent;
  border: 0;
  box-shadow: none;
}

.composer-box textarea:focus { outline: none; box-shadow: none; }

.composer-hint {
  max-width: 768px;
  margin: 8px auto 0;
  font-size: 12px;
  line-height: 16px;
  text-align: center;
  color: var(--muted);
}

/* Кнопка отправки — синий квадрат, как в макете */
.composer-box button[type="submit"],
.composer-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--accent-ink);
  background: var(--accent);
  border: 0;
  border-radius: var(--radius);
}

.composer-box button[type="submit"]:hover,
.composer-send:hover { background: var(--accent-hover); }

.composer-plus,
.composer-box .ghost {
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
}

.composer-plus:hover,
.composer-box .ghost:hover { color: var(--text); background: var(--surface-3); }

/* ---------- кнопки и поля ---------- */
button.primary,
.btn-primary,
.danger-button {
  min-height: 40px;
  padding: 10px 16px;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
  border-radius: var(--radius);
}

button.primary,
.btn-primary {
  color: var(--accent-ink);
  background: var(--accent);
  border: 1px solid var(--accent);
}

button.primary:hover,
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.danger-button {
  color: var(--accent-ink);
  background: var(--danger);
  border: 1px solid var(--danger);
}

button.ghost,
.ghost {
  min-height: 40px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

button.ghost:hover,
.ghost:hover { background: var(--surface-3); }

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]),
select,
textarea {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 20px;
  color: var(--text);
  background: var(--surface-lowest);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]),
select { min-height: 40px; padding: 10px 12px; }

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus);
}

/* ---------- прочее ---------- */
.task-list,
.template-panel,
.settings-view,
.user-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: none;
}

.muted { color: var(--text-2); }

/* ---------- экран входа по макету ---------- */
.login-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
  background: var(--bg);
}

.login-panel {
  width: 100%;
  max-width: 420px;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin: 16px 0 4px;
  font-size: 24px;
  line-height: 32px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.login-panel p {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 20px;
  color: var(--text-2);
}

.login-panel label > span,
.login-panel .field > span {
  font-size: 11px;
  line-height: 16px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-2);
}

/* ---------- телефон ---------- */
@media (max-width: 820px) {
  .topbar {
    height: calc(56px + env(safe-area-inset-top, 0px));
    min-height: calc(56px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 16px 0;
  }

  .message { max-width: 90%; padding: 8px; border-radius: 4px 4px 4px 0; }
  .message.user,
  .message.me { max-width: 90%; padding: 8px; border-radius: 4px 4px 0 4px; }
  .message.assistant { margin-left: 40px; }
  .message.assistant::before { border-radius: var(--radius-pill); font-size: 18px; font-variation-settings: "FILL" 1, "wght" 400; }

  .composer { padding: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .composer-box { padding: 6px; }

  /* Safari на iPhone зумит страницу при шрифте поля меньше 16px */
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="submit"]):not([type="button"]),
  select,
  textarea,
  .composer-box textarea { font-size: 16px; }

  button.primary,
  button.ghost,
  .ghost,
  .btn-primary,
  .danger-button,
  .conversation-item { min-height: 44px; }

  .topbar .icon-button,
  .topbar .icon-btn {
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
  }

  .login-panel { padding: 24px 20px; }
}

/* ==========================================================================
   Остатки прошлого оформления (тёмное меню, «золотые» кнопки) — приводим
   к светлому меню макета: белый текст на светлом фоне был не виден.
   ========================================================================== */

/* Нижние пункты меню: «Настройки», «Инструкция» */
.settings-button,
.settings-button:link,
.settings-button:visited,
.sidebar .settings-button {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 20px;
  color: var(--sidebar-text) !important;
  background: transparent !important;
  border: 0 !important;
  border-radius: var(--radius);
  text-decoration: none;
}

.settings-button:hover,
.sidebar .settings-button:hover {
  color: var(--sidebar-text-strong) !important;
  background: var(--sidebar-hover) !important;
}

.settings-button .nav-tx,
.sidebar .nav-tx { color: inherit !important; }
.settings-button .nav-ic,
.sidebar .nav-ic { color: inherit; opacity: .8; }

/* Кнопка «Новый чат» — основная синяя, как CTA в макете */
.new-chat,
.sidebar .new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  padding: 10px 16px;
  font-family: var(--font-ui);
  font-size: 11px;
  line-height: 16px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--accent-ink) !important;
  background: var(--accent) !important;
  border: 0 !important;
  border-radius: var(--radius);
  box-shadow: none;
}

.new-chat:hover { background: var(--accent-hover) !important; }
.new-chat strong { color: inherit !important; font-weight: inherit; }

/* Кнопка темы в панели: иконка без синей заливки */
.topbar .icon-btn,
[data-theme="light"] .topbar .icon-btn,
[data-theme="dark"] .topbar .icon-btn {
  width: auto !important;
  min-width: 36px !important;
  height: 36px !important;
  padding: 0 10px !important;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2) !important;
  background: transparent !important;
  border: 1px solid var(--line) !important;
  border-radius: var(--radius) !important;
}

.topbar .icon-btn:hover,
[data-theme="light"] .topbar .icon-btn:hover { color: var(--text) !important; background: var(--surface-3) !important; }
.topbar .icon-btn .theme-toggle-label { color: inherit !important; }

/* Пустое состояние чата — как в макете: плашка с иконкой, заголовок, подсказка */
.chat-empty,
.empty-state,
.chat-placeholder { text-align: center; }

.chat-empty h2,
.empty-state h2,
.chat-placeholder h2 {
  font-size: 24px;
  line-height: 32px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.chat-empty p,
.empty-state p,
.chat-placeholder p {
  max-width: 560px;
  margin: 4px auto 0;
  font-size: 14px;
  line-height: 20px;
  color: var(--text-2);
}
