/* ═══════════════════════════════════════════════════════════════════════════
   style.css — стили для Telegram Mini App "База разборов"
   Тёмная тема с поддержкой CSS-переменных Telegram WebApp.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Фиксированная тема приложения (не зависит от Telegram theme vars) ───── */
:root {
  --bg:            #0f172a;
  --text:          #e2e8f0;
  --hint:          #94a3b8;
  --link:          #60a5fa;
  --button:        #3b82f6;
  --button-text:   #f8fafc;
  --secondary-bg:  #1e293b;
  --destructive:   #ef4444;
  --success:       #22c55e;
  --warning:       #f59e0b;
}

/* ─── Сброс и базовые стили ────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  /* Запрещаем растягивание при pull-to-refresh */
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  /* Запрещаем выделение текста на мобильных устройствах */
  -webkit-user-select: none;
  user-select: none;
  /* Разрешаем выделение только в текстовых полях */
}

/* Разрешаем выделение в инпутах и textarea */
input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text);
}

h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  margin-bottom: 6px;
  margin-top: 14px;
}

/* ─── Загрузочный экран ────────────────────────────────────────────────────── */
#app-loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: var(--bg);
  z-index: 9999;
  gap: 16px;
}

#app-loading p {
  color: var(--hint);
  font-size: 14px;
}

/* Спиннер загрузки */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--button);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Анимация появления экрана */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ─── Экраны (SPA) ─────────────────────────────────────────────────────────── */
.screen {
  display: none;
  padding: 16px;
  min-height: 100vh;
  /* Прокрутка внутри экрана */
  overflow-y: auto;
  padding-bottom: 32px;
}

.screen.active {
  display: block;
  animation: fadeIn 0.2s ease-out;
}

/* ─── Карточка ─────────────────────────────────────────────────────────────── */
.card {
  background-color: var(--secondary-bg);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
}

/* ─── Строка поиска ────────────────────────────────────────────────────────── */
.search-container {
  margin-bottom: 4px;
}

.search-container input {
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background-color: var(--secondary-bg);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 12px;
}

.search-container input:focus {
  border-color: var(--button);
}

.search-container input::placeholder {
  color: var(--hint);
}

/* ─── Карточка категории ───────────────────────────────────────────────────── */
.category-card {
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.category-card:active {
  transform: scale(0.98);
  opacity: 0.85;
}

.category-count {
  color: var(--hint);
  font-size: 13px;
  margin-top: 4px;
}

/* ─── Ветка (заголовок в списке) ───────────────────────────────────────────── */
.thread-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
}

/* Тело разбора — полный текст ────────────────────────────────────────────── */
.thread-body {
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  margin: 12px 0;
  color: var(--text);
}

/* Мета-информация (дата, автор) ──────────────────────────────────────────── */
.meta {
  color: var(--hint);
  font-size: 13px;
  margin-top: 6px;
}

/* ─── Статистическая строка ────────────────────────────────────────────────── */
.stats-bar {
  text-align: center;
  color: var(--hint);
  font-size: 13px;
  margin-bottom: 16px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

/* ─── Кнопки ───────────────────────────────────────────────────────────────── */

/* Основная кнопка */
.btn-primary {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  background-color: var(--button);
  color: var(--button-text);
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin: 10px 0;
  transition: opacity 0.15s ease, transform 0.1s ease;
  display: block;
}

.btn-primary:active {
  opacity: 0.85;
  transform: scale(0.99);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Вторичная кнопка */
.btn-secondary {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  background-color: transparent;
  color: var(--link);
  border: 1px solid var(--link);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  margin: 10px 0;
  transition: background-color 0.15s ease, opacity 0.15s ease;
  display: block;
}

.btn-secondary:active {
  background-color: rgba(94, 170, 255, 0.1);
  opacity: 0.85;
}

/* Кнопка администратора */
.btn-admin {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  background-color: rgba(255, 170, 0, 0.15);
  color: var(--warning);
  border: 1px solid var(--warning);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  margin: 10px 0;
  transition: background-color 0.15s ease;
  display: block;
}

.btn-admin:active {
  background-color: rgba(255, 170, 0, 0.25);
}

/* Кнопка опасного действия (удалить) */
.btn-danger {
  background-color: var(--destructive);
  color: white;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.btn-danger:active {
  opacity: 0.8;
}

/* Кнопка успеха (одобрить) */
.btn-success {
  background-color: var(--success);
  color: white;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.btn-success:active {
  opacity: 0.8;
}

/* Кнопка предупреждения (доработка) */
.btn-warn {
  background-color: var(--warning);
  color: black;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.btn-warn:active {
  opacity: 0.8;
}

/* ─── Поля ввода ───────────────────────────────────────────────────────────── */

/* Select */
select {
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  background-color: var(--secondary-bg);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 15px;
  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 d='M1 1l5 5 5-5' stroke='%23999' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  cursor: pointer;
}

select:focus {
  border-color: var(--button);
}

/* Текстовый инпут */
input[type="text"] {
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  background-color: var(--secondary-bg);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus {
  border-color: var(--button);
}

input[type="text"]::placeholder {
  color: var(--hint);
}

/* Textarea */
textarea {
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  background-color: var(--secondary-bg);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 14px;
  line-height: 1.6;
  outline: none;
  resize: vertical;
  transition: border-color 0.2s;
  font-family: inherit;
}

textarea:focus {
  border-color: var(--button);
}

textarea::placeholder {
  color: var(--hint);
}

/* ─── Бриф-шаблон ──────────────────────────────────────────────────────────── */
.brief-box {
  background-color: rgba(255, 255, 255, 0.05);
  border-left: 3px solid var(--button);
  padding: 12px 16px;
  margin: 10px 0;
  font-size: 13px;
  color: var(--hint);
  white-space: pre-line;
  border-radius: 0 8px 8px 0;
  line-height: 1.7;
}

/* ─── Карточка ответа ──────────────────────────────────────────────────────── */
.reply-card {
  border-left: 3px solid var(--button);
  padding: 12px 14px;
  margin-bottom: 8px;
  background-color: var(--secondary-bg);
  border-radius: 0 10px 10px 0;
}

/* ─── Бейдж (счётчик ответов) ──────────────────────────────────────────────── */
.badge {
  background-color: var(--button);
  color: var(--button-text);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  margin-left: 8px;
  vertical-align: middle;
}

/* ─── Статусные бейджи ─────────────────────────────────────────────────────── */
.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* На модерации */
.status-pending {
  background-color: var(--warning);
  color: black;
}

/* Опубликован */
.status-approved {
  background-color: var(--success);
  color: white;
}

/* Отклонён */
.status-rejected {
  background-color: var(--destructive);
  color: white;
}

/* На доработке */
.status-revision {
  background-color: rgba(255, 170, 0, 0.25);
  color: var(--warning);
  border: 1px solid var(--warning);
}

/* ─── Карточка в админ-панели ──────────────────────────────────────────────── */
.admin-card {
  background-color: var(--secondary-bg);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: border-color 0.2s;
}

.admin-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

/* Панель действий в карточке администратора */
.admin-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
  align-items: center;
}

/* ─── Секция ответа ────────────────────────────────────────────────────────── */
#reply-form {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* ─── Заголовок секции ─────────────────────────────────────────────────────── */
.section-title {
  font-size: 16px;
  font-weight: 600;
  margin: 16px 0 8px;
  color: var(--text);
}

/* ─── Экран успеха (после отправки разбора) ────────────────────────────────── */
#create-success {
  text-align: center;
  padding: 40px 20px;
  animation: fadeIn 0.3s ease;
}

#create-success p {
  margin-bottom: 10px;
  color: var(--hint);
  font-size: 15px;
}

#create-success p:first-child {
  font-size: 17px;
  color: var(--text);
  font-weight: 600;
}

/* ─── Группа полей формы ───────────────────────────────────────────────────── */
.field-group {
  margin-bottom: 4px;
}

/* ─── Модальные окна ───────────────────────────────────────────────────────── */

/* Подложка модала */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  /* Анимация появления */
  animation: fadeIn 0.15s ease;
}

/* Карточка модала */
.modal-card {
  background-color: var(--secondary-bg);
  border-radius: 16px;
  padding: 24px 20px;
  max-width: 320px;
  width: 90%;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.modal-card p,
.modal-card label {
  font-size: 15px;
  color: var(--text);
  margin-bottom: 0;
  margin-top: 0;
  font-weight: 500;
  text-align: center;
}

/* Кнопки в модале */
.modal-buttons {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  justify-content: center;
}

.modal-buttons button {
  padding: 10px 20px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: opacity 0.15s;
  flex: 1;
}

.modal-buttons button:active {
  opacity: 0.8;
}

/* Кнопка "Отмена" */
#modal-cancel,
#comment-cancel {
  background-color: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

/* Кнопка "Подтвердить" (красная — опасное действие) */
#modal-ok {
  background-color: var(--destructive);
  color: white;
}

/* Кнопка "Отправить комментарий" */
#comment-ok {
  background-color: var(--button);
  color: var(--button-text);
}

/* Textarea внутри модала комментария */
#comment-text {
  margin-top: 12px;
  min-height: 80px;
}

/* ─── Toast-уведомление ────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 10px;
  background-color: rgba(30, 30, 50, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  max-width: 85vw;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 999;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

#toast.show {
  opacity: 1;
}

/* ─── Результаты поиска ────────────────────────────────────────────────────── */
#search-results {
  margin-top: 4px;
}

/* ─── Вспомогательные классы ───────────────────────────────────────────────── */

/* Центрирование */
.text-center {
  text-align: center;
}

/* Цвет подсказки */
.text-hint {
  color: var(--hint);
}

/* Отступ сверху */
.mt-8 {
  margin-top: 8px;
}

.mt-16 {
  margin-top: 16px;
}

/* Тонкий разделитель */
.divider {
  height: 1px;
  background-color: rgba(255, 255, 255, 0.06);
  margin: 16px 0;
}

/* ─── Скроллбар (Webkit) ────────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

/* ─── Адаптация для больших экранов ────────────────────────────────────────── */
@media (min-width: 480px) {
  .screen {
    max-width: 480px;
    margin: 0 auto;
  }
}
