/* ============================================================
   styles.css — Kaspersky-style (бело-зелёный)
   index.html, stats.html, profile.html, review.html,
   sms.html, phrase.html, chats.html
   ============================================================ */

/* ============ Переменные ============ */
:root {
  --primary: #00A651;
  --primary-hover: #008a44;
  --primary-dark: #00722f;
  --primary-light: #e8f5ee;
  --primary-soft: #f2faf6;

  --text: #1a1a1a;
  --text-light: #3a3a3a;
  --text-muted: #6b7280;
  --text-dim: #9aa1a9;

  --border: #e2e6ea;
  --border-light: #eef2f5;
  --bg-soft: #f6f8fa;
  --bg-white: #ffffff;

  --error: #d9363e;
  --error-bg: #fdecee;
  --success-bg: #e8f5ee;
  --success-text: #00722f;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);
}

/* ============ Сброс ============ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  background: var(--bg-soft);
  padding-bottom: env(safe-area-inset-bottom);
  font-size: 15px;
  line-height: 1.5;
}

/* ============ Анимации ============ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.12); opacity: 0.85; }
}

/* ============ Утилита скрытия ============ */
.hidden { display: none !important; }

/* ============================================================
   ОБЩИЕ КОМПОНЕНТЫ
   ============================================================ */

/* ---------- Шапка ---------- */
.topbar {
  background: var(--bg-white);
  padding: 14px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 700;
  font-size: 18px;
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.brand::before {
  content: '';
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: inset -3px -3px 0 var(--primary-dark);
}

.user-area {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 14px;
  color: var(--text-light);
}

.logout-btn {
  padding: 8px 16px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-light);
  transition: all 0.15s ease;
  min-height: 36px;
}
.logout-btn:hover {
  background: var(--error-bg);
  border-color: var(--error);
  color: var(--error);
}
.logout-btn:active { transform: scale(0.97); }

/* ---------- Ссылка-навигация в шапке ---------- */
.nav-link {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: none;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
}
.nav-link:hover { background: var(--primary-light); }
.nav-link:active { transform: scale(0.97); }

/* ---------- Поля формы ---------- */
.form-group {
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
}

.form-group label {
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-light);
}
.form-group label .req { color: var(--error); }

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  font-family: inherit;
  background: var(--bg-white);
  color: var(--text);
  min-height: 46px;
}

.form-group input:hover,
.form-group select:hover,
.form-group textarea:hover { border-color: #c8ced4; }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,166,81,0.15);
}

.form-group input.error,
.form-group select.error,
.form-group textarea.error {
  border-color: var(--error);
  box-shadow: 0 0 0 3px rgba(217,54,62,0.1);
}

.form-group textarea { resize: vertical; min-height: 100px; line-height: 1.5; }

.form-group select:disabled {
  background: var(--bg-soft);
  color: var(--text-dim);
  cursor: not-allowed;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ---------- Ошибки ---------- */
.error-message {
  color: var(--error);
  font-size: 12px;
  margin-top: 6px;
  display: none;
  line-height: 1.3;
}
.error-message.show { display: block; }

/* ---------- Основная кнопка ---------- */
.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  letter-spacing: 0.2px;
  min-height: 48px;
  touch-action: manipulation;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:active:not(:disabled) { background: var(--primary-dark); transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---------- Кнопка второго уровня ---------- */
.btn-secondary {
  width: 100%;
  padding: 14px;
  background: var(--bg-white);
  color: var(--text-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  min-height: 48px;
}
.btn-secondary:hover { background: var(--bg-soft); border-color: #c8ced4; }
.btn-secondary:active { transform: scale(0.98); }

/* ---------- Сообщения от сервера ---------- */
.server-message {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  text-align: center;
  display: none;
  line-height: 1.4;
  border: 1px solid transparent;
}
.server-message.success {
  display: block;
  background: var(--success-bg);
  color: var(--success-text);
  border-color: #c6e6d3;
}
.server-message.error {
  display: block;
  background: var(--error-bg);
  color: var(--error);
  border-color: #f5c2c6;
}

/* ---------- Спиннер ---------- */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

/* ---------- Подсказка с демо-данными ---------- */
.demo-hint {
  text-align: center;
  color: var(--primary-dark);
  background: var(--primary-light);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 24px;
  font-weight: 500;
  border: 1px solid #c6e6d3;
}

/* ============================================================
   КОНТЕЙНЕРЫ
   ============================================================ */
.container {
  max-width: 760px;
  margin: 40px auto;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  box-shadow: var(--shadow-md);
  animation: fadeIn 0.4s ease;
}

.container h1 { font-size: 26px; margin-bottom: 6px; color: var(--text); font-weight: 700; }
.container .subtitle { color: var(--text-muted); font-size: 14px; margin-bottom: 32px; }

.container-narrow { max-width: 480px; }

/* ============================================================
   СТРАНИЦА ВХОДА (body.login-page)
   ============================================================ */
body.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 15% 10%, rgba(0,166,81,0.06) 0%, transparent 45%),
    radial-gradient(circle at 85% 90%, rgba(0,166,81,0.05) 0%, transparent 45%),
    var(--bg-soft);
}

.login-container {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  animation: fadeIn 0.4s ease;
}

.login-container h1 {
  text-align: center;
  color: var(--text);
  margin-bottom: 8px;
  font-size: 26px;
  font-weight: 700;
}
.login-container .subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-size: 14px;
}

.password-wrapper { position: relative; }

.toggle-password {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 18px;
  padding: 6px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.toggle-password:hover { color: var(--primary); background: var(--primary-light); }

.remember-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  font-size: 14px;
  gap: 12px;
}
.remember-row label { display: flex; align-items: center; gap: 6px; color: var(--text-light); cursor: pointer; }
.remember-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.remember-row a { color: var(--primary); text-decoration: none; font-weight: 500; }
.remember-row a:hover { color: var(--primary-hover); text-decoration: underline; }

.btn-login {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  min-height: 48px;
}
.btn-login:hover:not(:disabled) { background: var(--primary-hover); }
.btn-login:active:not(:disabled) { transform: translateY(1px); }
.btn-login:disabled { opacity: 0.6; cursor: not-allowed; }

/* ============================================================
   СЕКЦИИ АНКЕТЫ
   ============================================================ */
fieldset.section {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  min-width: 0;
  background: var(--bg-white);
}

fieldset.section legend {
  padding: 0 8px;
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 14px;
  letter-spacing: 0.2px;
}
fieldset.section legend .optional {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 13px;
  margin-left: 4px;
}

fieldset.section-after {
  margin-top: 28px;
  margin-bottom: 0;
  background: var(--bg-soft);
  border-color: var(--border-light);
}
fieldset.section-after legend { color: var(--text-muted); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.form-grid .form-group { margin-bottom: 0; }
.form-group.full { grid-column: 1 / -1; }

/* ============================================================
   СТРАНИЦА ОБЗОРА (review.html)
   ============================================================ */
.review-list {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 12px 16px;
  font-size: 15px;
}
.review-list dt { color: var(--text-muted); font-weight: 500; }
.review-list dd { color: var(--text); font-weight: 600; word-break: break-word; }

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}

/* ============================================================
   СТРАНИЦА SMS (sms.html)
   ============================================================ */
.sms-input {
  font-size: 24px !important;
  letter-spacing: 8px;
  text-align: center;
  font-weight: 700;
  padding: 16px 14px !important;
  font-variant-numeric: tabular-nums;
}

.resend-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  text-decoration: underline;
}
.link-btn:hover { color: var(--primary-hover); }

/* ============================================================
   СТРАНИЦА КОДОВОЙ ФРАЗЫ (phrase.html)
   ============================================================ */
.phrase-hint {
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg-soft);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 20px;
  line-height: 1.5;
}

#phrase, #phraseConfirm { letter-spacing: 0.3px; }

/* ============================================================
   СТРАНИЦА ЧАТОВ (chats.html)
   ============================================================ */
.progress-block {
  background: var(--primary-soft);
  border: 1px solid #c6e6d3;
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 24px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 12px;
}

#progressPercent { color: var(--primary-dark); font-size: 16px; font-weight: 700; }

.progress-bar {
  width: 100%;
  height: 10px;
  background: #d9e9e0;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 20px;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.progress-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stat {
  text-align: center;
  background: var(--bg-white);
  border: 1px solid #c6e6d3;
  border-radius: var(--radius);
  padding: 12px 8px;
}

.stat-value {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--primary-dark);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.stage-log { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }

.stage {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--text-muted);
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.stage-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  transition: all 0.15s;
}

.stage.active {
  color: var(--text);
  background: var(--primary-light);
  border-color: #c6e6d3;
}
.stage.active .stage-icon {
  border-color: var(--primary);
  color: var(--primary);
  animation: pulse 1.4s infinite;
}

.stage.done { color: var(--text); }
.stage.done .stage-icon {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ============================================================
   СТРАНИЦА СТАТИСТИКИ (stats.html)
   ============================================================ */

/* ---------- Сводка ---------- */
.stats-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.summary-card {
  background: var(--primary-soft);
  border: 1px solid #c6e6d3;
  border-radius: var(--radius-lg);
  padding: 16px;
  text-align: center;
}

.summary-value {
  display: block;
  font-size: 26px;
  font-weight: 700;
  color: var(--primary-dark);
  font-variant-numeric: tabular-nums;
}

.summary-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* ---------- Список загрузок ---------- */
.uploads-list { display: flex; flex-direction: column; gap: 12px; }

.upload-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.upload-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 16px rgba(0,166,81,0.1);
  transform: translateY(-1px);
}
.upload-card.active { border-color: var(--primary); background: var(--primary-soft); }

.upload-status {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.upload-status.done     { background: var(--primary-light); color: var(--primary-dark); }
.upload-status.active-s { background: var(--primary-light); color: var(--primary); animation: pulse 1.4s infinite; }
.upload-status.error-s  { background: var(--error-bg); color: var(--error); }

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

.upload-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.upload-progress {
  margin-top: 8px;
  height: 6px;
  background: #d9e9e0;
  border-radius: 999px;
  overflow: hidden;
}
.upload-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.3s;
}

.upload-arrow { flex-shrink: 0; color: var(--text-muted); font-size: 18px; }

/* ---------- Пустое состояние ---------- */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.6; }
.empty-state p { line-height: 1.6; font-size: 14px; }

/* ---------- Модальное окно ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: fadeIn 0.3s ease;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 { font-size: 18px; color: var(--text); font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--error-bg); color: var(--error); }

.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }

.modal-actions {
  padding: 16px 24px 20px;
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--border-light);
  flex-wrap: wrap;
}

.detail-list {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 10px 16px;
  font-size: 14px;
}
.detail-list dt { color: var(--text-muted); font-weight: 500; }
.detail-list dd { color: var(--text); font-weight: 600; word-break: break-word; }

.modal-actions button {
  flex: 1;
  min-width: 120px;
  padding: 12px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  min-height: 44px;
}
.modal-actions .btn-primary-sm { background: var(--primary); color: #fff; }
.modal-actions .btn-primary-sm:hover { background: var(--primary-hover); }

.modal-actions .btn-secondary-sm {
  background: var(--bg-white);
  color: var(--text-light);
  border: 1px solid var(--border);
}
.modal-actions .btn-secondary-sm:hover { background: var(--bg-soft); }

/* ============================================================
   ПРОСМОТР И АНАЛИЗ ЗАГРУЗКИ (внутри модалки stats.html)
   ============================================================ */

/* ---------- Просмотр: заголовок ---------- */
.viewer-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--primary-soft);
  border: 1px solid #c6e6d3;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.viewer-header b { color: var(--primary-dark); }

/* ---------- Список чатов ---------- */
.chat-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 4px;
}

.chat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  transition: background 0.15s, border-color 0.15s;
}
.chat-row:hover { background: var(--bg-soft); border-color: var(--border); }

.chat-index {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-info { flex: 1; min-width: 0; }

.chat-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}

.chat-badge { flex-shrink: 0; font-size: 14px; font-weight: 700; color: var(--primary); }

/* ---------- Анализ: KPI-карточки ---------- */
.analysis-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.analysis-kpi {
  text-align: center;
  background: var(--primary-soft);
  border: 1px solid #c6e6d3;
  border-radius: var(--radius);
  padding: 14px 8px;
}

.kpi-value {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--primary-dark);
  font-variant-numeric: tabular-nums;
}

.kpi-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ---------- Заголовки секций анализа ---------- */
.analysis-h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin: 20px 0 10px;
}
.analysis-h3:first-of-type { margin-top: 0; }

/* ---------- Топ чатов ---------- */
.top-list { display: flex; flex-direction: column; gap: 8px; }

.top-row {
  display: grid;
  grid-template-columns: 24px 1fr 100px 44px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.top-rank {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.top-name {
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-bar-wrap { height: 8px; background: #d9e9e0; border-radius: 999px; overflow: hidden; }
.top-bar-fill { height: 100%; background: var(--primary); border-radius: 999px; transition: width 0.3s ease; }

.top-value {
  text-align: right;
  color: var(--primary-dark);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- Распределение по типам ---------- */
.type-list { display: flex; flex-direction: column; gap: 8px; }

.type-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  padding: 8px 10px;
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
}

.type-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.type-name { flex: 1; color: var(--text); font-weight: 500; }
.type-value { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ---------- График по дням ---------- */
.day-chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  align-items: end;
  height: 120px;
  padding: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
}

.day-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 6px;
}

.day-bar {
  width: 100%;
  max-width: 28px;
  min-height: 4px;
  background: var(--primary);
  border-radius: 4px 4px 2px 2px;
  transition: height 0.3s ease;
}

.day-label { font-size: 11px; color: var(--text-muted); font-weight: 600; }

/* ============================================================
   МОБИЛЬНАЯ АДАПТАЦИЯ
   ============================================================ */

@media (max-width: 768px) {
  .topbar { padding: 12px 20px; }
  .container {
    margin: 24px 16px;
    padding: 28px 24px;
    border-radius: var(--radius-lg);
  }
  .container h1 { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr; gap: 16px; }
  fieldset.section { padding: 20px; }
}

@media (max-width: 480px) {
  body.login-page { padding: 12px; align-items: flex-start; padding-top: 24px; }

  .topbar {
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top));
    flex-wrap: wrap;
    gap: 8px;
  }
  .brand { font-size: 16px; }
  .user-area .username { display: none; }
  .user-area { gap: 8px; flex-wrap: wrap; }
  .nav-link { padding: 6px 10px; font-size: 13px; min-height: 40px; }

  .form-group input,
  .form-group select,
  .form-group textarea { min-height: 48px; padding: 13px 12px; }
  .form-group label { font-size: 13px; }

  .btn-primary, .btn-login { padding: 16px; font-size: 16px; min-height: 50px; }

  .logout-btn { padding: 8px 12px; font-size: 13px; min-height: 40px; }

  .login-container { padding: 28px 22px; }
  .login-container h1 { font-size: 22px; }
  .toggle-password { min-width: 44px; min-height: 44px; right: 4px; }

  .container { margin: 12px; padding: 22px 16px; }
  .container h1 { font-size: 20px; }
  .container .subtitle { margin-bottom: 20px; font-size: 13px; }

  fieldset.section { padding: 16px; margin-bottom: 16px; }
  fieldset.section legend { font-size: 12px; padding: 0 6px; }
  fieldset.section-after { margin-top: 24px; }

  .review-list { grid-template-columns: 1fr; gap: 4px 0; }
  .review-list dt { font-size: 12px; margin-top: 10px; }
  .review-list dd { font-size: 15px; margin-bottom: 4px; }
  .review-list dt:first-child { margin-top: 0; }
  .action-row { grid-template-columns: 1fr; }

  .sms-input { font-size: 22px !important; letter-spacing: 6px; }

  .progress-stats { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 18px; }
  .progress-block { padding: 16px; }
  .stage { font-size: 13px; padding: 8px; }

  .stats-summary { grid-template-columns: 1fr 1fr; }
  .summary-card:last-child { grid-column: 1 / -1; }
  .summary-value { font-size: 22px; }
  .upload-card { padding: 12px 14px; gap: 12px; }
  .upload-status { width: 40px; height: 40px; font-size: 16px; }
  .upload-title { font-size: 14px; }
  .upload-meta { font-size: 11px; gap: 8px; }
  .detail-list { grid-template-columns: 1fr; gap: 4px; }
  .detail-list dt { font-size: 12px; margin-top: 8px; }
  .detail-list dd { font-size: 14px; margin-bottom: 4px; }
  .modal-actions button { min-width: 100%; }

  /* Просмотр / анализ */
  .analysis-summary { grid-template-columns: 1fr 1fr; }
  .analysis-kpi:last-child { grid-column: 1 / -1; }
  .kpi-value { font-size: 18px; }

  .top-row { grid-template-columns: 22px 1fr 60px 36px; gap: 8px; }
  .top-name { font-size: 12px; }
  .top-value { font-size: 12px; }

  .chat-list { max-height: 320px; }
  .chat-name { font-size: 13px; }
  .chat-meta { font-size: 11px; }

  .day-chart { height: 100px; gap: 4px; padding: 8px; }
  .day-bar { max-width: 20px; }
  .day-label { font-size: 10px; }
}

@media (max-width: 360px) {
  .container { margin: 8px; padding: 18px 12px; }
  .form-group input,
  .form-group select,
  .form-group textarea { padding: 11px; font-size: 16px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .container { margin: 12px auto; }
  .topbar { position: static; }
  body.login-page { align-items: flex-start; }
}

/* Табы на index.html */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  background: var(--bg-soft);
  padding: 4px;
  border-radius: var(--radius);
}
.tab {
  flex: 1;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.tab.active {
  background: var(--bg-white);
  color: var(--primary-dark);
  box-shadow: var(--shadow-sm);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Бейдж ДЕМО */
.badge-demo {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #fef3c7;
  color: #92400e;
  text-transform: uppercase;
}


/* ============================================================
   АДМИН-ПАНЕЛЬ
   ============================================================ */

.admin-page .container { max-width: 960px; }

.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.admin-toolbar h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}
.btn-sm {
  width: auto !important;
  padding: 10px 16px;
  font-size: 14px;
  min-height: 40px;
}

.admin-subtitle {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-light);
  margin: 24px 0 10px;
}

.admin-list { display: flex; flex-direction: column; gap: 10px; }

.admin-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  background: var(--bg-soft);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}

.admin-card {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}
.admin-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.admin-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.admin-card-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.admin-card-body { margin-top: 8px; }
.admin-card-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 6px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 600;
}
.chip-muted {
  background: var(--bg-soft);
  color: var(--text-muted);
}

.admin-form {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 8px;
}
.admin-form .form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.admin-form .form-group { margin-bottom: 12px; }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.admin-table th,
.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  font-size: 14px;
  text-align: left;
}
.admin-table th {
  background: #fafafa;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table .muted { color: var(--text-muted); font-size: 12px; }

/* Модалки админки используют общие .modal-* */

@media (max-width: 720px) {
  .admin-form .form-grid { grid-template-columns: 1fr; }
  .admin-toolbar h2 { font-size: 16px; }
}

/* ============ ЧАТЫ (chats.html) ============ */
.chats-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  min-height: 420px;
}
.chats-sidebar {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-white);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chats-sidebar-head {
  padding: 12px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chats-sidebar-head span {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.chats-sidebar-head input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}
.chats-list {
  flex: 1;
  overflow-y: auto;
  max-height: 520px;
}
.chat-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background .15s;
}
.chat-item:hover { background: var(--bg-soft); }
.chat-item.active { background: var(--primary-light); }
.chat-item-name { font-size: 14px; font-weight: 600; color: var(--text); }
.chat-item-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.chats-content {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-white);
  padding: 14px;
  display: flex;
  flex-direction: column;
  min-height: 420px;
}
.messages-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 10px;
}
.messages-title { font-size: 16px; font-weight: 700; color: var(--text); }
.messages-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.messages-nav { display: flex; align-items: center; gap: 8px; }
.messages-nav span { font-size: 13px; color: var(--text-muted); }
.messages-list {
  flex: 1;
  overflow-y: auto;
  max-height: 480px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}
.msg {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg-soft);
  max-width: 85%;
}
.msg-out { align-self: flex-end; background: var(--primary-light); }
.msg-in { align-self: flex-start; }
.msg-head {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.msg-sender { font-weight: 600; color: var(--primary-dark); }
.msg-body { font-size: 14px; color: var(--text); word-wrap: break-word; overflow-wrap: anywhere; }
.msg-text-hidden { color: var(--text-muted); font-style: italic; }
.notice {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

@media (max-width: 720px) {
  .chats-layout { grid-template-columns: 1fr; }
  .chats-list { max-height: 260px; }
  .messages-list { max-height: 360px; }
}

/* ============ КОНТАКТЫ ============ */
#contactsWrap .chats-sidebar-head {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-white);
  margin-bottom: 12px;
}
#contactsWrap .chats-sidebar-head span {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  display: block;
  margin-bottom: 8px;
}
#contactsWrap .chats-sidebar-head input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}
#contactsWrap .admin-table .muted { color: var(--text-muted); font-size: 13px; }

.chat-item-static {
  cursor: default;
}
.chat-item-static:hover {
  background: var(--bg-white);   /* не подсвечивать при наведении */
}

.chats-layout.single-col {
  grid-template-columns: 1fr;
}
.chats-layout.single-col .chats-sidebar {
  max-height: 600px;   /* чтобы список не растягивался на всю высоту */
}


.chats-page .action-row {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}