/* auth-styles.css */
/* Стили для авторизации и правой панели истории */

/* ========== ИНФОРМАЦИОННЫЕ БАННЕРЫ ========== */

.info-banner {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: white;
  color: #1a1a1a;
  padding: 20px 30px;
  border-radius: 12px;
  border: 1px solid #e0e0e0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  z-index: 9000;
  max-width: 500px;
  animation: slideDown 0.3s ease;
}

.info-banner.warning {
  background: #fff9e6;
  border-color: #ffd700;
  color: #856404;
}

.info-banner.error {
  background: #fff0f0;
  border-color: #ff6b6b;
  color: #721c24;
}

@keyframes slideDown {
  from {
    transform: translate(-50%, -20px);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

.banner-content {
  text-align: center;
}

.banner-content h3 {
  margin: 0 0 10px 0;
  font-size: 18px;
  font-weight: 600;
}

.banner-content p {
  margin: 10px 0;
  font-size: 14px;
  opacity: 0.95;
}

.banner-content ul {
  text-align: left;
  margin: 15px 0;
  padding-left: 20px;
}

.banner-content ul li {
  margin: 8px 0;
  font-size: 14px;
}

.primary-btn {
  background: #1a1a1a;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 15px;
}

.primary-btn:hover {
  background: #333;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.primary-btn:active {
  transform: translateY(0);
}

/* Индикатор синхронизации */
/* .sync-indicator определён в sync-indicator-styles.css (toast снизу-справа).
   Дубль отсюда удалён — из-за конфликта top/bottom/left/right индикатор
   растягивался на пол-экрана. */

/* Кнопка входа в sidebar */
.sidebar-signin-btn {
  margin-top: 20px;
  background: #1a1a1a;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

.sidebar-signin-btn:hover {
  background: #333;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.sidebar-signin-btn:active {
  transform: translateY(0);
}

/* Встроенная кнопка CloudKit Sign-In - минималистичная */
/* Наш контейнер — чёрная кнопка на всю ширину (как Google). Родную Apple-кнопку внутри
   НЕ растягиваем и не трогаем по layout (иначе её SVG-текст уезжает) — оставляем её родной
   размер 218px, прозрачной, по центру контейнера. Apple сама центрирует свой текст. */
#apple-sign-in-button {
  margin-top: 16px;
  width: 100%;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}
#apple-sign-in-button:not(:empty) { background: #000000; }
#apple-sign-in-button:not(:empty):hover { background: #1a1a1a; }

/* Пока CloudKit поднимает родную кнопку — нейтральный скелетон (резерв места, без мелькания
   старой кнопки и без прыжка Google). Контент появится — :empty перестанет матчиться. */
#apple-sign-in-button:empty {
  background: linear-gradient(90deg, #ececec 25%, #f5f5f5 37%, #ececec 63%);
  background-size: 400% 100%;
  animation: appleSkeleton 1.2s ease-in-out infinite;
}
@keyframes appleSkeleton {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* Внутреннюю Apple-кнопку — только прозрачный фон без рамки (виден наш чёрный контейнер),
   layout/позиционирование текста НЕ трогаем. */
#apple-sign-in-button > div {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  cursor: pointer !important;
}

/* Текст/лого Apple — белым на чёрном. */
#apple-sign-in-button,
#apple-sign-in-button *,
#apple-sign-in-button > div,
#apple-sign-in-button > div * {
  color: #ffffff !important;
}
#apple-sign-in-button svg,
#apple-sign-in-button svg * {
  fill: #ffffff !important;
}

/* Скрыть дубликаты кнопок, если CloudKit создаст несколько */
#apple-sign-in-button > div:not(:first-child) {
  display: none !important;
}

/* ========== МОДАЛЬНОЕ ОКНО АВТОРИЗАЦИИ ========== */

.auth-modal {
  display: none;
  position: fixed;
  z-index: 10000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.auth-modal-content {
  background-color: white;
  padding: 40px 35px;
  border-radius: 16px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  position: relative;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.auth-close {
  position: absolute;
  right: 20px;
  top: 20px;
  font-size: 28px;
  font-weight: bold;
  color: #999;
  cursor: pointer;
  transition: color 0.2s;
  line-height: 1;
}

.auth-close:hover {
  color: #333;
}

#auth-title {
  margin: 0 0 25px 0;
  text-align: center;
  font-size: 26px;
  font-weight: 600;
  color: #1a1a1a;
}

.auth-benefits {
  margin-bottom: 25px;
  padding: 20px;
  background: linear-gradient(135deg, #f5f7fa 0%, #e8eef5 100%);
  border-radius: 12px;
  border: 1px solid #e1e8ed;
}

.auth-benefits p {
  margin: 0 0 12px 0;
  font-size: 15px;
  font-weight: 600;
  color: #333;
}

.auth-benefits ul {
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.auth-benefits li {
  margin: 10px 0;
  font-size: 14px;
  color: #555;
  line-height: 1.5;
}

/* ========== КНОПКИ АВТОРИЗАЦИИ ========== */

.auth-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-btn {
  padding: 14px 20px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.auth-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.auth-btn:active {
  transform: translateY(0);
}

.auth-btn.loading {
  opacity: 0.7;
  cursor: not-allowed;
}

/* Apple Button */
.apple-btn {
  background-color: #000;
  color: white;
}

.apple-btn:hover {
  background-color: #1a1a1a;
}

/* Google Button */
.google-btn {
  background-color: #fff;
  color: #333;
  border: 2px solid #e0e0e0;
}

.google-btn:hover {
  border-color: #4285F4;
  background-color: #f8f9fa;
}

/* Email Button */
.email-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.email-btn:hover {
  background: linear-gradient(135deg, #5568d3 0%, #6a4091 100%);
}

.email-btn-secondary {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white;
}

.email-btn-secondary:hover {
  background: linear-gradient(135deg, #e082ea 0%, #e4465b 100%);
}

/* Anonymous Button */
.anonymous-btn {
  background-color: #f5f5f5;
  color: #333;
  border: 2px solid #e0e0e0;
}

.anonymous-btn:hover {
  background-color: #ebebeb;
  border-color: #d0d0d0;
}

.auth-divider {
  text-align: center;
  margin: 10px 0;
  color: #999;
  font-size: 14px;
  position: relative;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 38%;
  height: 1px;
  background-color: #ddd;
}

.auth-divider::before {
  left: 0;
}

.auth-divider::after {
  right: 0;
}

/* ========== EMAIL ФОРМА ========== */

.email-form {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.email-form input {
  padding: 14px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  font-size: 16px;
  transition: all 0.2s;
  font-family: inherit;
}

.email-form input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.auth-btn-text {
  background: none;
  border: none;
  color: #667eea;
  cursor: pointer;
  font-size: 15px;
  padding: 10px;
  transition: color 0.2s;
  font-weight: 500;
}

.auth-btn-text:hover {
  color: #5568d3;
}

/* ========== СТАТУС ========== */

.auth-status {
  margin-top: 15px;
  padding: 12px 16px;
  border-radius: 10px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  display: none;
  animation: slideIn 0.3s ease;
}

.auth-status.success {
  background-color: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
  display: block;
}

.auth-status.error {
  background-color: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
  display: block;
}

.auth-status.warning {
  background-color: #fff3cd;
  color: #856404;
  border: 1px solid #ffeaa7;
  display: block;
}

/* ========== УВЕДОМЛЕНИЕ О МИГРАЦИИ ========== */

.migration-notification {
  position: fixed;
  top: 20px;
  right: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 16px 24px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  font-size: 15px;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  transform: translateX(400px);
  transition: all 0.3s ease;
}

.migration-notification.show {
  opacity: 1;
  transform: translateX(0);
}

/* ========== ЛЕВАЯ ПАНЕЛЬ ИСТОРИИ (SIDEBAR) - МИНИМАЛИЗМ ========== */

.history-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: 320px;
  background-color: #fafafa;
  border-right: 1px solid #e0e0e0;
  box-shadow: none;
  transform: translateX(0); /* Открыт по умолчанию */
  transition: transform 0.3s ease;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

/* Свернутое состояние */
.history-sidebar.collapsed {
  transform: translateX(-320px); /* Прячем влево */
}

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

.sidebar-header {
  /* min-height = top(16) + кнопка(36) + bottom(16) = 68px; align-items center
     → центр заголовка совпадает с центром бургер-кнопки (top:16, h:36). */
  min-height: 68px;
  padding: 0 20px 0 64px; /* слева место под бургер-кнопку */
  background: transparent; /* без фона */
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
  letter-spacing: -0.2px;
}

.sidebar-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #999;
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s;
}

.sidebar-close:hover {
  background-color: #f5f5f5;
  color: #333;
}

.sidebar-user-info {
  padding: 12px 16px;
  background: #f5f5f5;
  color: #1a1a1a;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid #e0e0e0; /* блок прижат к низу колонки */
}

.sidebar-user-main {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #666;
}

.sidebar-user-details {
  flex: 1;
  min-width: 0; /* позволяет блоку сжиматься, чтобы кнопка «Выйти» не выпадала */
  overflow: hidden;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 400;
  color: #1a1a1a;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-email {
  font-size: 13px;
  font-weight: 400;
  color: #888;
  margin: 2px 0 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-signout-btn {
  background: white;
  border: 1px solid #e0e0e0;
  color: #666;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%; /* кнопка во всю ширину под именем аккаунта */
  white-space: nowrap;
}

.sidebar-signout-btn:hover {
  background: #f5f5f5;
  border-color: #ccc;
  color: #333;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* Табличный список (строки с разделителями), НЕ карточки */
.sidebar-text-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: transparent;
  border: none;
  border-bottom: 1px solid #eceae4;
  border-radius: 0;
  padding: 12px 14px;
  margin: 0;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.18s ease;
  animation: sidebarItemIn 0.18s ease;
}
.sidebar-text-item:last-child { border-bottom: none; }

@keyframes sidebarItemIn {
  from { opacity: 0.4; }
  to { opacity: 1; }
}

.sidebar-text-item:hover {
  background-color: rgba(0, 0, 0, 0.035);
}

.sidebar-text-item.selected {
  background-color: rgba(0, 0, 0, 0.05);
}

.sidebar-text-main { flex: 1; min-width: 0; }

.sidebar-text-preview {
  font-size: 14px;
  font-weight: 500;
  color: #1a1a1a;
  margin: 0;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sidebar-text-learned {
  font-size: 12px;
  color: #9aa0a6;
  margin: 2px 0 0;
}

.sidebar-text-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: #999;
}
/* meta-строка показывается только если есть содержимое (бейджи/избранное),
   иначе не занимает место — плашки компактнее. */
.sidebar-text-meta:empty { display: none; }

/* Кнопка удаления текста (корзина). На десктопе появляется при наведении на строку,
   на мобиле (нет hover) — всегда видна приглушённой. */
.sidebar-text-delete {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  background: transparent;
  color: #b0b0b0;
  cursor: pointer;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}
.sidebar-text-delete i, .sidebar-text-delete svg { width: 16px; height: 16px; }
.sidebar-text-item:hover .sidebar-text-delete { opacity: 1; }
.sidebar-text-delete:hover { color: #e5484d; background-color: rgba(229, 72, 77, 0.1); }
@media (max-width: 600px) {
  .sidebar-text-delete { opacity: 0.5; }
}

/* Анимация исчезновения строки при удалении (оптимистичный UI). */
.sidebar-text-item.removing {
  opacity: 0;
  transform: translateX(-10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Диалог подтверждения удаления. */
.sidebar-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  padding: 20px;
}
.sidebar-confirm {
  background: #fff;
  border-radius: 14px;
  padding: 20px;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  font-family: 'Golos UI', system-ui, sans-serif;
}
.sidebar-confirm-title { font-size: 16px; font-weight: 600; margin: 0 0 6px; color: #1a1a1a; }
.sidebar-confirm-msg { font-size: 14px; color: #666; margin: 0 0 18px; line-height: 1.4; }
.sidebar-confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }
.sidebar-confirm-actions button {
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  font-family: inherit;
}
.sidebar-confirm-cancel { background: #f0f0ee; color: #333; }
.sidebar-confirm-cancel:hover { background: #e6e6e3; }
.sidebar-confirm-del { background: #e5484d; color: #fff; }
.sidebar-confirm-del:hover { background: #d33a3f; }

.sidebar-text-date {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sidebar-text-date svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
}

.sidebar-text-favorite {
  color: #fbbf24;
}

.sidebar-text-favorite svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
  stroke: currentColor;
}

.icon-star-filled {
  fill: #fbbf24;
  stroke: #fbbf24;
}

.sidebar-empty {
  text-align: center;
  padding: 40px 20px;
  color: #999;
}

.sidebar-empty-icon {
  margin-bottom: 16px;
  opacity: 0.3;
}

/* Только иконка пустого состояния (file-text) — прямой потомок, НЕ нейрончик.
   Иначе правило сайзило вложенные svg нейрона (части тела) в 48px → ломало рисунок. */
.sidebar-empty-icon > svg:not(.neuron-loader) {
  width: 48px;
  height: 48px;
  stroke: currentColor;
}

.sidebar-empty-icon--loading {
  opacity: 0.7;
}

.sidebar-empty-icon--loading svg {
  animation: sidebar-spinner-rotate 0.9s linear infinite;
}

@keyframes sidebar-spinner-rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Нейрончик-лоадер (из iOS-вкладки «Нейрончики»): полная непрозрачность, цвет тела
   через color, лёгкое «дыхание». Глаза анимируются внутри SVG (SMIL). */
.sidebar-empty-icon--neuron {
  opacity: 1;
  color: #2b2f36; /* цвет тела нейрончика (легко поменять) */
}
.neuron-loader {
  width: 120px;
  height: auto;
  display: block;
  margin: 0 auto;
  shape-rendering: crispEdges; /* пиксель-арт без размытия */
}
.neuron-loader path { stroke: none; }
/* Глаза нейрончика: статичный x (всегда видны, даже без SMIL — он не стартует при
   innerHTML-вставке) + дискретная анимация бега влево-вправо через CSS. Оба глаза
   двигаются одинаково (база 18 и 31, смещения −4 / +3 / 0). */
.neuron-eye { animation: neuron-eye-move 4s step-end infinite; }
@keyframes neuron-eye-move {
  0%    { transform: translateX(0); }
  25%   { transform: translateX(-4px); }
  62.5% { transform: translateX(3px); }
  100%  { transform: translateX(0); }
}

.sidebar-empty-text {
  font-size: 15px;
  line-height: 1.5;
}

/* ========== СКЕЛЕТОН ЗАГРУЗКИ СПИСКА ========== */
/* Каркас (тоггл/табы/«Новый текст») виден сразу; здесь — нейрончик + серые
   плейсхолдер-строки в зоне списка, пока грузятся данные. */
.sidebar-loading {
  padding: 16px 16px 24px;
}
.sidebar-loading .sidebar-empty-icon--neuron {
  opacity: 1;
  margin-bottom: 24px;
}
.sidebar-skel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.sidebar-skel-row {
  height: 14px;
  border-radius: 7px;
  background: linear-gradient(90deg, #ececec 25%, #f5f5f5 37%, #ececec 63%);
  background-size: 400% 100%;
  animation: sidebar-skel-shimmer 1.4s ease infinite;
}
.sidebar-skel-row:nth-child(odd)  { width: 82%; }
.sidebar-skel-row:nth-child(even) { width: 54%; }
@keyframes sidebar-skel-shimmer {
  0%   { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* Boot-скелетон (статический в index.html, до загрузки JS): на мобиле панель скрыта,
   как реальная свёрнутая шторка — виден только тоггл; на десктопе виден как панель. */
@media (max-width: 768px) {
  #sidebar-boot-skeleton { display: none; }
}

/* ========== КНОПКА ПЕРЕКЛЮЧЕНИЯ SIDEBAR ========== */

.sidebar-toggle-btn {
  position: fixed;
  left: 16px;
  top: 12px; /* выровнено по верху сегмента (тот же top, что у .sidebar-segment) */
  background: #fff;
  color: #333;
  border: 1px solid #e5e5e5;
  width: 30px;
  height: 30px; /* квадратная кнопка высотой как переключатель «Мои тексты | Библиотека» */
  padding: 0; /* убираем дефолтные отступы кнопки */
  margin: 0; /* убираем унаследованный margin-top:5px (сдвигал кнопку ниже заголовка) */
  border-radius: 8px;
  font-size: 0; /* Убираем стандартный текст */
  line-height: 0;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); /* лёгкая тень — кнопка читается поверх любого контента */
  transition: background 0.15s ease, box-shadow 0.15s ease;
  z-index: 9990;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor; /* следует за color (корректно в тёмной теме) */
  display: block; /* убирает baseline-смещение inline svg → иконка строго по центру */
}

.sidebar-toggle-btn:hover {
  background: #f7f7f7;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.sidebar-toggle-btn:active {
  transform: scale(0.95);
}

/* ========== АДАПТИВ ========== */

@media (max-width: 768px) {
  .auth-modal-content {
    padding: 30px 25px;
    max-width: 95%;
  }

  /* Drawer-режим: контент НЕ сдвигаем, шторка выезжает поверх с затемнением. */
  body {
    padding-left: 0 !important;
  }

  .history-sidebar {
    width: 84%;
    max-width: 320px;
    box-shadow: 2px 0 18px rgba(0, 0, 0, 0.18);
    z-index: 1100; /* выше затемнения */
  }

  /* На мобилке закрытая шторка полностью уезжает за левый край. */
  .history-sidebar.collapsed {
    transform: translateX(-100%);
  }

  /* Затемнение под шторкой, но над контентом. */
  #overlay {
    z-index: 1050;
  }

  .sidebar-toggle-btn {
    left: 16px;
    top: 12px; /* выровнено по верху сегмента */
  }
}

@media (max-width: 480px) {
  #auth-title {
    font-size: 22px;
  }

  .auth-btn {
    padding: 12px 16px;
    font-size: 15px;
  }

  .auth-benefits {
    padding: 16px;
  }

  .auth-benefits li {
    font-size: 13px;
  }
}

/* Dark mode support */
:root[data-theme-resolved="dark"] {
  .auth-modal-content {
    background-color: #1f2937;
    color: #f9fafb;
  }

  #auth-title {
    color: #f9fafb;
  }

  .auth-benefits {
    background: linear-gradient(135deg, #374151 0%, #1f2937 100%);
    border-color: #374151;
  }

  .auth-benefits p {
    color: #f9fafb;
  }

  .auth-benefits li {
    color: #d1d5db;
  }

  .email-form input {
    background-color: #374151;
    border-color: #4b5563;
    color: #f9fafb;
  }

  .email-form input:focus {
    border-color: #667eea;
  }

  .history-sidebar {
    background-color: #1f2937;
    border-left-color: #374151;
  }

  .sidebar-header {
    background: transparent;
  }

  .sidebar-header h3 {
    color: #f9fafb;
  }

  .sidebar-text-item {
    background-color: #111827;
    border-color: #374151;
  }

  .sidebar-text-preview {
    color: #f9fafb;
  }
}

/* ========== КНОПКА «SIGN IN WITH GOOGLE» В САЙДБАРЕ ========== */

.sidebar-google-signin-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 10px;
  padding: 10px 14px;
  background: #ffffff;
  color: #3c4043;
  border: 1px solid #dadce0;
  border-radius: 8px;
  font-family: 'Golos UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.sidebar-google-signin-btn:hover {
  background: #f7f8f8;
  box-shadow: 0 1px 3px rgba(60, 64, 67, 0.15);
}

.sidebar-google-signin-btn:active {
  background: #f1f3f4;
}

.sidebar-google-signin-btn svg {
  flex-shrink: 0;
}

/* Статическая кнопка «Sign in with Apple» (ленивый CloudKit) */
.sidebar-apple-signin-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 10px;
  padding: 10px 14px;
  background: #000000;
  color: #ffffff;
  border: 1px solid #000000;
  border-radius: 8px;
  font-family: 'Golos UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.sidebar-apple-signin-btn:hover {
  opacity: 0.85;
}

/* Глобальный стиль span делает текст чёрным — на чёрной кнопке он сливался.
   Принудительно белый. */
.sidebar-apple-signin-btn span {
  color: #ffffff;
}

.sidebar-apple-signin-btn svg {
  flex-shrink: 0;
}

:root[data-theme-resolved="dark"] {
  .sidebar-google-signin-btn {
    background: #1f2937;
    color: #f9fafb;
    border-color: #374151;
  }

  .sidebar-google-signin-btn:hover {
    background: #374151;
  }
}

/* ========== ПЕЙВОЛЛ: ЗАБЛОКИРОВАННЫЕ ТЕКСТЫ ========== */

.sidebar-text-item.locked {
  opacity: 0.6;
  cursor: pointer;
}

.sidebar-text-item.locked .sidebar-text-preview {
  opacity: 0.35; /* не блюр, а прозрачная надпись — текст читается слабо */
  user-select: none;
}

.sidebar-text-lock {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  color: #9ca3af;
}

.sidebar-text-lock svg {
  width: 14px;
  height: 14px;
}

/* Черновик нового текста — пунктирная рамка */
.sidebar-text-item.draft {
  border: 1px dashed #c4c4c4;
  background: transparent;
}
.sidebar-draft-text {
  color: #9ca3af;
}
:root[data-theme-resolved="dark"] {
  .sidebar-text-item.draft {
    border-color: #4b5563;
  }
}

/* Футер гостя: кнопки входа (постоянно внизу сайдбара) */
.sidebar-auth-footer {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  order: 1; /* кнопки входа выше строки-аккаунта (она всегда внизу) */
}
.sidebar-auth-hint {
  font-size: 12px;
  color: #888;
  margin: 0 0 2px 0;
  text-align: center;
  line-height: 1.4;
}
.sidebar-auth-footer .sidebar-apple-signin-btn,
.sidebar-auth-footer .sidebar-google-signin-btn {
  margin-top: 0;
}
:root[data-theme-resolved="dark"] {
  .sidebar-auth-footer { border-top-color: #374151; }
  .sidebar-auth-hint { color: #9ca3af; }
}

/* Микрофон-островок (голосовая сверка) — внизу по центру */
.speech-mic-btn {
  position: fixed;
  bottom: 24px;
  /* На десктопе контент сдвинут вправо под сайдбар (body padding-left:320px), а
     fixed-кнопка считает left от вьюпорта → центрируем её по области контента,
     сместив на половину ширины сайдбара (320/2=160). В drawer-режиме (≤768px,
     padding-left:0) возвращаем чистый центр окна — см. медиазапрос ниже. */
  left: calc(50% + 160px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  background: #1a1a1a;
  color: #ffffff;
  border: none;
  border-radius: 999px;
  font-family: 'Golos UI', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.22);
  z-index: 2000;
  transition: background 0.2s ease, transform 0.1s ease;
}
.speech-mic-btn:hover { background: #333; }
.speech-mic-btn:active { transform: translateX(-50%) scale(0.97); }
.speech-mic-btn.listening { background: #ea4335; }
.speech-mic-btn.error { background: #b3261e; }
.speech-mic-btn.listening .speech-mic-icon { animation: speechMicPulse 1.2s ease-in-out infinite; }
/* Перебиваем глобальное `button span { color: black }` из style.css —
   иначе текст и иконка островка чёрные на чёрном фоне. */
.speech-mic-btn span { color: #ffffff; }
.speech-mic-icon { display: inline-flex; }
.speech-mic-icon svg { width: 18px; height: 18px; }
.speech-mic-label { white-space: nowrap; }

/* Браузер без распознавания (Arc/Brave): кнопка приглушена, но кликабельна. */
.speech-mic-btn--unsupported { opacity: 0.5; cursor: not-allowed; }
.speech-mic-btn--unsupported:hover { background: #1a1a1a; } /* не подсвечивать как активную */

/* Красный поповер с причиной — над кнопкой, по клику на приглушённую кнопку. */
.speech-unsupported-tip {
  position: fixed;
  transform: translateX(-50%) translateY(6px);
  max-width: 320px;
  padding: 10px 16px;
  background: #b3261e;
  color: #ffffff;
  font-family: 'Golos UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  text-align: center;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  z-index: 2001;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.speech-unsupported-tip.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.speech-unsupported-tip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #b3261e;
}

/* На мобиле бар режимов (#toggle-buttons) зафиксирован внизу (~72px). Поднимаем плашку
   речи над ним, чтобы она не перекрывала кнопки переключения режимов. */
/* Drawer-режим (≤768px): контент полноширинный (body padding-left:0) — кнопку
   центрируем по всему окну, без сдвига на сайдбар. */
@media (max-width: 768px) {
  .speech-mic-btn { left: 50%; }
}
@media (max-width: 600px) {
  .speech-mic-btn { bottom: 84px; }
}
@keyframes speechMicPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(1.18); }
}

/* Подсветка слов при голосовой сверке */
.word.speech-correct {
  background: rgba(52, 168, 83, 0.18);
  border-radius: 3px;
  transition: background 0.3s ease;
}
.word.speech-wrong {
  background: rgba(234, 67, 53, 0.16);
  border-radius: 3px;
}

/* === Библиотека стихов === */
/* Сегмент-контроллер «Мои тексты | Библиотека» */
.sidebar-segment {
  display: flex;
  gap: 2px;
  /* левый отступ ~56px — освобождаем место под фикс-кнопку toggle (left:16, ширина 36) */
  margin: 12px 12px 8px 58px;
  padding: 2px;
  background: #ececec;
  border-radius: 9px;
}
.sidebar-segment-btn {
  flex: 1;
  margin: 0; /* убираем дефолтный margin кнопки — иначе серая зона сверху/снизу пилюли */
  border: none;
  background: transparent;
  color: #555;
  font-family: 'Golos UI', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 8px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-segment-btn.active {
  background: #ffffff;
  color: #1a1a1a;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* Контейнер библиотеки (вкладка): flex-колонка, сам не скроллит —
   шапка (язык + поиск + вкладки) зафиксирована, скроллит только .lib-list. */
.sidebar-library {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  padding: 0 8px;
}
.lib-langselect-wrap { padding: 4px 4px 6px; flex: none; }
.lib-langselect {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 12px;
  border: 1px solid #e0e0e0;
  border-radius: 9px;
  font-family: 'Golos UI', system-ui, sans-serif;
  font-size: 14px;
  font-weight: 600;
  background: #fff;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23888' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.lib-langselect:focus { border-color: #999; }
.lib-search-wrap { padding: 4px 4px 8px; flex: none; }
.lib-search {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 12px;
  border: 1px solid #e0e0e0;
  border-radius: 9px;
  font-family: 'Golos UI', system-ui, sans-serif;
  font-size: 14px;
  outline: none;
}
.lib-search:focus { border-color: #999; }
/* Вкладки библиотеки [Популярное | Авторы] — переиспользуют .sidebar-segment(-btn)
   (свет+тёмная тема уже описаны), но без левого отступа 58px под toggle: в библиотеке его нет. */
.lib-tabs { margin: 4px 4px 8px; flex: none; }
.lib-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; padding-bottom: 16px; }
.lib-status { padding: 16px 8px; color: #888; font-size: 13px; text-align: center; }

.lib-author, .lib-poem, .lib-back {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 10px 10px;
  cursor: pointer;
  font-family: 'Golos UI', system-ui, sans-serif;
}
.lib-author:hover, .lib-poem:hover, .lib-back:hover { background: #f0f0f0; }
.lib-author { justify-content: space-between; gap: 8px; }
.lib-author-name { color: #1a1a1a; font-size: 14px; font-weight: 500; }
.lib-author-count { color: #999; font-size: 12px; flex-shrink: 0; }
.lib-back { color: #4285f4; font-size: 13px; font-weight: 600; padding: 8px 10px; }
.lib-author-head { padding: 6px 10px 10px; font-size: 15px; font-weight: 700; color: #1a1a1a; }
.lib-poem { flex-direction: column; align-items: flex-start; gap: 2px; }
.lib-poem-title { color: #1a1a1a; font-size: 13px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lib-poem-author { color: #999; font-size: 11px; }

/* Превью-оверлей стиха */
.lib-preview-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.25s ease;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.lib-preview-backdrop.show { opacity: 1; }
.lib-preview {
  background: #ffffff;
  border-radius: 16px;
  max-width: 560px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding: 24px;
  position: relative;
  font-family: 'Golos UI', system-ui, sans-serif;
  transform: translateY(12px);
  transition: transform 0.25s ease;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.25);
}
.lib-preview-backdrop.show .lib-preview { transform: translateY(0); }
.lib-preview-close {
  position: absolute;
  top: 12px;
  right: 14px;
  border: none;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  color: #999;
  cursor: pointer;
}
.lib-preview-author { color: #888; font-size: 13px; margin-bottom: 4px; }
.lib-preview-title { color: #1a1a1a; font-size: 19px; font-weight: 700; margin-bottom: 14px; padding-right: 28px; }
.lib-preview-text {
  flex: 1;
  overflow-y: auto;
  color: #2a2a2a;
  font-size: 15px;
  line-height: 1.6;
  white-space: normal;
  margin-bottom: 18px;
}
.lib-preview-load {
  flex-shrink: 0;
  width: 100%;
  background: #1a1a1a;
  color: #ffffff;
  border: none;
  border-radius: 999px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.lib-preview-load:hover { background: #333; }

/* Празднование при полном прочтении (шторка снизу, порт iOS) */
.celebration-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.25s ease;
  z-index: 3000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.celebration-backdrop.show { opacity: 1; }
.celebration-sheet {
  width: 100%;
  max-width: 480px;
  background: #ffffff;
  border-radius: 20px 20px 0 0;
  padding: 8px 24px 28px;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  text-align: center;
  font-family: 'Golos UI', system-ui, -apple-system, sans-serif;
}
.celebration-backdrop.show .celebration-sheet { transform: translateY(0); }
.celebration-grabber {
  width: 40px;
  height: 5px;
  border-radius: 3px;
  background: #d8d8d8;
  margin: 0 auto 18px;
}
.celebration-emoji { font-size: 56px; line-height: 1; margin-bottom: 12px; }
.celebration-title { font-size: 22px; font-weight: 700; color: #1a1a1a; margin: 0 0 8px; }
.celebration-subtitle { font-size: 15px; color: #6b6b6b; margin: 0 0 18px; line-height: 1.4; }
.celebration-stat {
  display: inline-block;
  background: rgba(52, 168, 83, 0.12);
  color: #1e8e3e;
  font-size: 15px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  margin-bottom: 22px;
}
.celebration-continue {
  width: 100%;
  background: #1a1a1a;
  color: #ffffff;
  border: none;
  border-radius: 999px;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.celebration-continue span { color: #ffffff; } /* перебить глобальное button span{color:black} */
.celebration-continue:hover { background: #333; }
.celebration-confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3001;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 14px;
  opacity: 0.9;
  border-radius: 1px;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  to { transform: translateY(106vh) rotate(720deg); opacity: 0.9; }
}

/* Рекламные баннеры приложений, перенесённые в низ страницы */
.store-banners-bottom {
  margin-top: 32px;
}

/* Кнопка «Новый текст» над списком */
.sidebar-new-text-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: calc(100% - 24px);
  margin: 12px;
  padding: 9px 14px;
  background: transparent;
  color: #3c4043;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-family: 'Golos UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.sidebar-new-text-btn:hover {
  background: #f5f5f5;
  border-color: #d0d0d0;
}
.sidebar-new-text-btn svg {
  width: 16px;
  height: 16px;
  opacity: 0.7;
}

:root[data-theme-resolved="dark"] {
  .sidebar-new-text-btn {
    color: #e5e7eb;
    border-color: #374151;
  }
  .sidebar-new-text-btn:hover {
    background: #374151;
    border-color: #4b5563;
  }
}

/* Ненавязчивый статус синхронизации на карточке текста */
.sidebar-text-sync {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  line-height: 1;
  width: 14px;
  height: 14px;
  justify-content: center;
}
.sidebar-text-sync.saving {
  color: #9ca3af;
}
.sidebar-text-sync.saving::after {
  content: '';
  width: 9px;
  height: 9px;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: sidebarSyncSpin 0.7s linear infinite;
}
.sidebar-text-sync.saved {
  color: #34a853;
}
.sidebar-text-sync.saved::after {
  content: '✓';
  font-weight: 700;
  animation: sidebarSyncFade 0.3s ease;
}
.sidebar-text-sync.error {
  color: #ea4335;
}
.sidebar-text-sync.error::after {
  content: '!';
  font-weight: 700;
}
@keyframes sidebarSyncSpin {
  to { transform: rotate(360deg); }
}
@keyframes sidebarSyncFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===== Paywall ===== */
.paywall-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 1200; }
.paywall-sheet { background: #fff; border-radius: 20px; padding: 24px; width: min(92vw, 420px); position: relative; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.paywall-close { position: absolute; top: 16px; right: 16px; border: none; background: transparent; color: #9aa0a6; width: 32px; height: 32px; border-radius: 50%; font-size: 22px; line-height: 1; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: background .15s ease, color .15s ease; }
.paywall-close:hover { background: #f1f3f4; color: #444; }
.paywall-secondary { width: 100%; padding: 12px; margin-top: 10px; border: none; border-radius: 12px; background: transparent; color: #666; font-size: 15px; cursor: pointer; }
.paywall-secondary:hover { background: #f1f3f4; }
.paywall-title { font-size: 20px; font-weight: 700; margin: 0 0 16px; }
.paywall-plans { display: flex; flex-direction: column; gap: 10px; }
.paywall-plan { display: flex; justify-content: space-between; align-items: center; padding: 16px; border: 2px solid #e6e6e6; border-radius: 14px; background: #fff; cursor: pointer; font-size: 15px; text-align: left; transition: border-color .15s ease, background .15s ease; }
.paywall-plan:hover { border-color: #bbb; }
.paywall-plan.is-selected { border-color: #111; background: #fafafa; }
.paywall-plan-title { font-weight: 700; }
.paywall-features { margin: 16px 0; display: flex; flex-direction: column; gap: 6px; color: #444; font-size: 14px; }
.paywall-currencies { display: flex; gap: 8px; margin-bottom: 12px; }
.paywall-cur { flex: 1; padding: 8px; border: 2px solid #e6e6e6; border-radius: 10px; background: #fff; cursor: pointer; transition: border-color .15s ease; }
.paywall-cur:hover { border-color: #bbb; }
.paywall-cur.is-selected { border-color: #111; color: #111; font-weight: 700; }
.paywall-methods { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.paywall-method { display: flex; align-items: center; gap: 8px; padding: 12px; border: 2px solid #e6e6e6; border-radius: 10px; cursor: pointer; transition: border-color .15s ease; accent-color: #111; }
.paywall-method:hover { border-color: #bbb; }
.paywall-method.is-selected { border-color: #111; }
.paywall-pay { width: 100%; padding: 14px; border: none; border-radius: 12px; background: #111; color: #fff; font-size: 16px; font-weight: 700; cursor: pointer; transition: background .15s ease, opacity .15s ease; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.paywall-pay:hover { background: #333; }
.paywall-pay:active { background: #000; }
.paywall-pay:disabled { opacity: .65; cursor: default; }
.paywall-spinner { display: inline-block; width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: paywall-spin .7s linear infinite; }
@keyframes paywall-spin { to { transform: rotate(360deg); } }
.paywall-note { color: #666; font-size: 14px; margin: 8px 0 16px; }
/* Кнопка «Премиум» — на всю ширину под «Новый текст», молния + текст */
.premium-button { width: calc(100% - 24px); margin: 0 12px 8px; background: #fff8e1; border: 1px solid #f3e6b3; border-radius: 8px; padding: 10px 14px; font-size: 14px; font-weight: 600; color: #8a6d00; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: background .15s ease; }
.premium-button:hover { background: #fff0c2; }
.premium-button i { width: 18px; height: 18px; }
/* Текущий тариф в шторке — приглушён, не выбирается */
.paywall-plan.is-current { opacity: .6; cursor: default; border-color: #e6e6e6; background: #fafafa; }
.paywall-plan.is-current:hover { border-color: #e6e6e6; }
/* Тариф пользователя под email + «Сменить план» (legacy, оставляем токены) */
.sidebar-user-plan { font-size: 12px; color: #666; margin: 3px 0 0; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 4px; }
.sidebar-user-plan:hover { color: #111; }
.sidebar-plan-ic { width: 13px; height: 13px; }
.paywall-ic { width: 16px; height: 16px; vertical-align: -3px; }
.paywall-ic-lg { width: 22px; height: 22px; vertical-align: -4px; }
/* Модалка «Как пользоваться» */
.howto-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 1200; padding: 16px; }
.howto-modal { background: #fff; border-radius: 18px; padding: 24px; width: min(94vw, 460px); max-height: 80vh; overflow-y: auto; position: relative; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.howto-modal-close { position: absolute; top: 14px; right: 14px; border: none; background: transparent; color: #9aa0a6; width: 32px; height: 32px; border-radius: 50%; font-size: 22px; line-height: 1; cursor: pointer; }
.howto-modal-close:hover { background: #f1f3f4; color: #444; }
.howto-modal-title { font-size: 19px; font-weight: 700; margin: 0 0 14px; }
.howto-modal-body { font-size: 14px; line-height: 1.55; color: #333; }
.howto-modal-body p { margin: 0 0 10px; }
/* Тост-уведомление */
.memo-toast { position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 12px); background: #111; color: #fff; padding: 12px 20px; border-radius: 12px; font-size: 14px; font-weight: 500; box-shadow: 0 8px 28px rgba(0,0,0,.28); z-index: 2000; opacity: 0; transition: opacity .25s ease, transform .25s ease; pointer-events: none; }
.memo-toast--show { opacity: 1; transform: translate(-50%, 0); }
.sidebar-changeplan-btn { display: block; width: 100%; margin-top: 8px; padding: 8px; border: 1px solid #e6e6e6; border-radius: 10px; background: #fff; color: #444; font-size: 13px; cursor: pointer; transition: border-color .15s ease; }
.sidebar-changeplan-btn:hover { border-color: #bbb; }

/* ========== ACCOUNT MENU (Claude-style) ========== */

/* Обёртка внизу сайдбара — без фона */
.sidebar-account-wrap {
  position: relative;
  padding: 4px 8px 6px;
  order: 2; /* строка-аккаунт всегда в самом низу — и у гостя, и у залогиненного */
}

/* Строка-триггер */
.sidebar-account-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease;
  min-width: 0;
}
.sidebar-account-trigger:hover {
  background: #f0f0f0;
}

/* Аватар-кружок */
.sidebar-account-avatar {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
}
.sidebar-account-avatar svg {
  width: 14px;
  height: 14px;
}

/* Имя */
.sidebar-account-name {
  flex: 0 1 auto;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  color: #1a1a1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Инлайн-план сразу рядом с именем; margin-right:auto отодвигает бургер вправо */
.sidebar-account-plan-inline {
  flex-shrink: 0;
  margin-right: auto;
  font-size: 12px;
  color: #888;
  white-space: nowrap;
}

/* Иконка-бургер (меню) справа */
.sidebar-account-caret {
  flex-shrink: 0;
  margin-left: auto;
  width: 18px;
  height: 18px;
  color: #888;
}

/* Popup-меню (выпадает вверх) */
.sidebar-account-popup {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 8px;
  right: 8px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  padding: 6px 0;
  z-index: 1100;
  min-width: 180px;
}

/* Email-заголовок в popup */
.sidebar-popup-email {
  font-size: 11px;
  color: #999;
  padding: 4px 14px 6px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px solid #f0f0f0;
  margin-bottom: 4px;
}

/* Пункт меню */
.sidebar-popup-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  padding: 8px 14px;
  font-size: 14px;
  color: #1a1a1a;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease;
  font-family: inherit;
  white-space: nowrap;
  text-decoration: none; /* для пункта-ссылки (#sidebar-popup-app), чтобы не подчёркивался */
  box-sizing: border-box;
}
.sidebar-popup-item:hover {
  background: #f5f5f5;
}
.sidebar-popup-item--danger {
  color: #e03131;
}
.sidebar-popup-item--danger:hover {
  background: #fff0f0;
}

/* Иконка в пункте */
.sidebar-popup-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: inherit;
}

/* Стрелка в пункте Язык */
.sidebar-popup-chevron {
  width: 14px;
  height: 14px;
  margin-left: auto;
  color: #bbb;
}

/* Обёртка пункта Язык + flyout-подменю (стиль Claude) */
.sidebar-popup-lang-wrap {
  position: relative;
}
/* Десктоп — открытие по ховеру; тач — по клику (класс .lang-open). */
.sidebar-popup-lang-wrap:hover .sidebar-lang-submenu,
.sidebar-popup-lang-wrap.lang-open .sidebar-lang-submenu {
  display: flex;
}

/* Подменю языков — выезжает вправо от пункта «Язык» */
.sidebar-lang-submenu {
  position: absolute;
  left: 100%;
  top: 0;
  margin-left: 6px;
  display: none;
  flex-direction: column;
  gap: 2px;
  background: #fff;
  border: 1px solid #ececec;
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,.16);
  padding: 6px;
  min-width: 200px;
  z-index: 5;
}

/* Кнопка языка — строка: название слева, галочка справа (видна у активного) */
.sidebar-lang-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: 14px;
  color: #1a1a1a;
  cursor: pointer;
  transition: background 0.12s ease;
  font-family: inherit;
  text-align: left;
}
.sidebar-lang-btn:hover { background: #f3f4f6; }
.sidebar-lang-check { width: 16px; height: 16px; color: #2f6fed; opacity: 0; }
.sidebar-lang-btn--active { font-weight: 600; }
.sidebar-lang-btn--active .sidebar-lang-check { opacity: 1; }

:root[data-theme-resolved="dark"] {
  .sidebar-account-wrap { border-top-color: #374151; }
  .sidebar-account-trigger:hover { background: #2d3748; }
  .sidebar-account-name { color: #f9fafb; }
  .sidebar-account-plan-inline { color: #9ca3af; }
  .sidebar-account-avatar { background: #374151; color: #9ca3af; }
  .sidebar-account-popup { background: #1f2937; border-color: #374151; box-shadow: 0 4px 20px rgba(0,0,0,.4); }
  .sidebar-popup-email { color: #6b7280; border-bottom-color: #374151; }
  .sidebar-popup-item { color: #f9fafb; }
  .sidebar-popup-item:hover { background: #374151; }
  .sidebar-popup-item--danger { color: #fc8181; }
  .sidebar-popup-item--danger:hover { background: #3b1e1e; }
  .sidebar-lang-submenu { background: #1f2937; border-color: #374151; box-shadow: 0 8px 28px rgba(0,0,0,.4); }
  .sidebar-lang-btn { color: #f9fafb; }
  .sidebar-lang-btn:hover { background: #374151; }
  .sidebar-lang-check { color: #8ab4ff; }
}

/* ══════════════════════════════════════════════════════════════════════════
   Тёмная тема — недостающая часть: контейнер сайдбара + основной редактор.
   Включается переключателем «Тема» в меню (data-theme-resolved="dark" на <html>,
   ставит theme-боот-скрипт в <head>). По умолчанию тема светлая.
   ══════════════════════════════════════════════════════════════════════════ */
:root[data-theme-resolved="dark"] {
  /* Контейнер сайдбара: тёмный фон + светлый базовый текст (иначе элементы без
     явного оверрайда наследуют чёрный → невидимы на тёмном). */
  .history-sidebar { background-color: #1f2937; border-right-color: #374151; color: #e5e7eb; }
  .sidebar-segment { background: #0b1220; }
  .sidebar-segment-btn { color: #9ca3af; }
  .sidebar-segment-btn.active { background: #374151; color: #f9fafb; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
  .sidebar-toggle-btn { background: #1f2937; border-color: #374151; color: #cbd5e1; }
  .sidebar-toggle-btn:hover { background: #283548; }
  .sidebar-text-item { border-bottom-color: #2d3748; }
  .sidebar-text-title { color: #f3f4f6; }
  .sidebar-text-preview, .sidebar-text-date, .sidebar-text-meta { color: #9ca3af; }

  /* Основной редактор/контент. */
  body, .btn-container, #toggle-buttons { background-color: #0f172a; }
  body { color: #e5e7eb; }
  main h1, main h2, main h3, h3, #title { color: #f3f4f6; }
  main p, main li { color: #cbd5e1; }

  button, .btn { background-color: #1f2937; color: #e5e7eb; }
  button:hover, .btn:hover { background-color: #374151; }
  button span, .btn span { color: #e5e7eb; }
  button:disabled span, .btn:disabled span { color: #6b7280; }

  #input-area { background: #111827; color: #e5e7eb; }
  #input-area::placeholder { color: #6b7280; }
  #output-area { color: #e5e7eb; }

  /* Скелетон Apple-кнопки (пока CloudKit грузится) — тёмный, иначе светлый
     шиммер белым боксом торчит на тёмном футере. */
  #apple-sign-in-button:empty {
    background: linear-gradient(90deg, #1f2937 25%, #374151 37%, #1f2937 63%);
    background-size: 400% 100%;
  }
  /* Лоадер-скелетон списка текстов — тёмные плейсхолдер-строки. */
  .sidebar-skel-row { background: #2d3748; }
}

