/* ═══════════════════════════════════════════
   DocAI — Global Styles
   Цвет акцента: #1D9E75
   Шрифты: Geologica + JetBrains Mono
═══════════════════════════════════════════ */

:root {
  --accent: #1D9E75;
  --accent-hover: #178a64;
  --accent-light: #E8F8F3;
  --accent-mid: #B2E8D7;
  --bg: #FFFFFF;
  --bg-secondary: #F8FAFB;
  --bg-tertiary: #F0F3F5;
  --border: #E2E8ED;
  --border-light: #EEF1F4;
  --text: #1A1F2E;
  --text-secondary: #5A6478;
  --text-muted: #9BA3B2;
  --red: #E53E3E;
  --red-light: #FFF5F5;
  --blue: #3182CE;
  --blue-light: #EBF8FF;
  --orange: #DD6B20;
  --orange-light: #FFFAF0;
  --purple: #805AD5;
  --purple-light: #FAF5FF;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --sidebar-w: 260px;
  --transition: 0.18s ease;
}

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

html { font-size: 15px; }

body {
  font-family: 'Geologica', sans-serif;
  background: var(--bg-secondary);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

code, pre, .mono { font-family: 'JetBrains Mono', monospace; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ─── Кнопки ─────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-outline { background: #fff; color: var(--text); border-color: var(--border); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-icon {
  padding: 6px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.btn-icon.warning:hover { border-color: var(--orange); color: var(--orange); background: var(--orange-light); }
.btn-icon.danger:hover { border-color: var(--red); color: var(--red); background: var(--red-light); }
.btn-icon.success:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-decoration: underline;
}

/* ─── Формы ──────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.form-input {
  padding: 9px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color var(--transition);
  outline: none;
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(29,158,117,.12); }
.form-input::placeholder { color: var(--text-muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input-wrap { position: relative; }
.input-wrap .form-input { padding-right: 42px; width: 100%; }
.toggle-pass {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  display: flex; align-items: center;
}
.toggle-pass:hover { color: var(--accent); }

/* ─── Алерты ─────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 14px;
}
.alert-error { background: var(--red-light); color: var(--red); border: 1px solid #fed7d7; }
.alert-success { background: var(--accent-light); color: var(--accent); border: 1px solid var(--accent-mid); }

/* ─── Бейджи ──────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.badge-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.badge-status.active { background: var(--accent-light); color: var(--accent); }
.badge-status.suspended { background: #FFF5F5; color: var(--red); }

.badge-role {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.badge-role.admin { background: var(--purple-light); color: var(--purple); }
.badge-role.user { background: var(--bg-tertiary); color: var(--text-secondary); }

/* ─── Карточки ───────────────────────────── */
.card {
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 16px 20px; }
.card-body.p-0 { padding: 0; }
.mt-4 { margin-top: 20px; }

/* ─── Таблицы ────────────────────────────── */
.simple-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.simple-table th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}
.simple-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.simple-table tr:last-child td { border-bottom: none; }
.simple-table tr:hover td { background: var(--bg-secondary); }

.users-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.users-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  white-space: nowrap;
}
.users-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.users-table tr:last-child td { border-bottom: none; }
.users-table tr:hover td { background: var(--bg-secondary); }

.user-cell { display: flex; align-items: center; gap: 10px; }
.user-fullname { font-weight: 500; }
.text-muted { color: var(--text-muted); font-size: 13px; }
.action-btns { display: flex; gap: 6px; }

/* ─── Аватары ────────────────────────────── */
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 15px; flex-shrink: 0;
}
.user-avatar-sm {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px; flex-shrink: 0;
}

/* ─── Модальные окна ─────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 100%; max-width: 520px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 4px;
  border-radius: var(--radius-sm); transition: color var(--transition);
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-light);
  display: flex; gap: 10px; justify-content: flex-end;
}

/* ═══════════════════════════════════════════
   LOGIN PAGE
═══════════════════════════════════════════ */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #F0FAF7 0%, #FFFFFF 60%, #F0F8FF 100%);
  padding: 24px;
}
.login-card {
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.logo-text { font-size: 20px; font-weight: 700; color: var(--text); }
.login-title { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.login-subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }
.login-form { margin-top: 4px; }
.login-footer { margin-top: 24px; color: var(--text-muted); font-size: 13px; }

/* ═══════════════════════════════════════════
   APP LAYOUT (Chat)
═══════════════════════════════════════════ */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.sidebar-header {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}
.sidebar-new-btn {
  margin: 12px 12px 4px;
  width: calc(100% - 24px);
  font-size: 13px;
}
.sidebar-section-title {
  padding: 10px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: rgba(255,255,255,.35);
}
.sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}
.session-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.65);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  text-decoration: none;
}
.session-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.session-item.active { background: rgba(29,158,117,.25); color: #fff; }
.session-item-icon { flex-shrink: 0; opacity: .7; }
.session-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-delete-btn {
  display: none;
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,.4); padding: 2px;
  border-radius: 3px; flex-shrink: 0;
}
.session-item:hover .session-delete-btn { display: flex; align-items: center; }
.session-delete-btn:hover { color: #fc8181; background: rgba(255,255,255,.1); }
.sessions-empty { color: rgba(255,255,255,.3); font-size: 13px; padding: 12px 10px; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin: 0 8px 4px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.6);
  font-size: 13px;
  transition: all var(--transition);
}
.sidebar-link:hover { background: rgba(255,255,255,.08); color: #fff; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
}
.user-info { flex: 1; overflow: hidden; }
.user-name {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,.9);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-role { font-size: 11px; color: rgba(255,255,255,.4); }
.logout-btn {
  color: rgba(255,255,255,.4);
  display: flex; align-items: center;
  transition: color var(--transition);
}
.logout-btn:hover { color: #fc8181; }

/* ─── Main content ────────────────────────── */
.main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* ─── Welcome screen ──────────────────────── */
.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 32px;
  gap: 16px;
}
.welcome-icon {
  width: 80px; height: 80px;
  background: var(--accent-light);
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 8px;
}
.welcome-screen h2 { font-size: 24px; font-weight: 700; }
.welcome-screen p { color: var(--text-secondary); max-width: 420px; font-size: 15px; }
.welcome-formats { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 8px; }
.welcome-formats span { font-size: 13px; color: var(--text-muted); }
.format-badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }

/* ─── Session layout ──────────────────────── */
.session-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-light);
  background: #fff;
  flex-shrink: 0;
}
.session-title-wrap { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.session-title {
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
}
.session-title:hover { background: var(--bg-secondary); border-color: var(--border); }
.session-title-input {
  display: none;
  font-size: 15px;
  font-weight: 600;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-family: inherit;
  background: #fff;
  outline: none;
  flex: 1;
}
.session-header-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ─── Upload area ─────────────────────────── */
.upload-area {
  margin: 12px 20px 0;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-secondary);
  flex-shrink: 0;
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}
.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 14px;
}
.upload-placeholder small { color: var(--text-muted); font-size: 12px; }

/* ─── Files list ──────────────────────────── */
.files-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 20px;
  flex-shrink: 0;
  max-height: 100px;
  overflow-y: auto;
}
.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.file-icon {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-light);
  padding: 2px 5px;
  border-radius: 3px;
}
.file-info { display: flex; flex-direction: column; }
.file-name { font-weight: 500; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--text-muted); font-size: 11px; }
.file-delete {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 2px; border-radius: 3px;
  display: flex; align-items: center;
}
.file-delete:hover { color: var(--red); }

/* ─── Chat ────────────────────────────────── */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 20px 16px;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
}

.message {
  display: flex;
  gap: 10px;
  max-width: 85%;
}
.message-user { align-self: flex-end; flex-direction: row-reverse; }
.message-assistant { align-self: flex-start; }

.message-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.message-user .message-avatar { background: var(--accent); color: #fff; }
.message-assistant .message-avatar { background: var(--bg-tertiary); color: var(--text-secondary); font-size: 11px; }

.message-body { display: flex; flex-direction: column; gap: 3px; }
.message-user .message-body { align-items: flex-end; }

.message-content {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.message-user .message-content {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius) 4px var(--radius) var(--radius);
}
.message-assistant .message-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
}
.message-time { font-size: 11px; color: var(--text-muted); padding: 0 4px; }

/* ─── Панель экспорта под сообщением AI ──── */
.msg-export-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.msg-export-label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  margin-right: 2px;
}
.msg-export-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.msg-export-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}
.msg-export-btn:disabled {
  opacity: .6;
  cursor: wait;
}
.mfmt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 16px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 800;
  color: #fff;
  font-family: 'JetBrains Mono', monospace;
  flex-shrink: 0;
}
.mfmt.docx { background: #2B5797; }
.mfmt.pdf  { background: #C53030; }
.mfmt.xlsx { background: #1E6E42; }
.mfmt.csv  { background: #744210; }

/* Стриминг — анимация набора */
.message-content.streaming::after {
  content: '▋';
  animation: blink .8s infinite;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* ─── Chat input ──────────────────────────── */
.chat-input-wrap {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 10px 0 0;
  border-top: 1px solid var(--border-light);
}
.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  overflow-y: auto;
  outline: none;
  transition: border-color var(--transition);
  line-height: 1.5;
  scrollbar-width: thin;
}
.chat-input:focus { border-color: var(--accent); }
.send-btn {
  width: 44px; height: 44px;
  border-radius: var(--radius);
  background: var(--accent); color: #fff; border: none;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background var(--transition);
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { background: var(--border); cursor: not-allowed; }

/* ─── Export modal ────────────────────────── */
.modal-desc { color: var(--text-secondary); font-size: 14px; margin-bottom: 18px; }
.export-formats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.export-format-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  transition: all var(--transition);
  font-weight: 500;
}
.export-format-btn:hover { border-color: var(--accent); background: var(--accent-light); color: var(--accent); }
.export-fmt-icon {
  width: 40px; height: 40px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; font-weight: 700; color: #fff;
}
.export-fmt-icon.docx { background: #2B5797; }
.export-fmt-icon.pdf { background: #C53030; }
.export-fmt-icon.xlsx { background: #1E6E42; }
.export-fmt-icon.pptx { background: #C04000; }
.export-fmt-icon.txt { background: #4A5568; }
.export-fmt-icon.md { background: #2D3748; }

#exportStatus { margin-top: 14px; }
#exportStatus .downloading {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 14px;
}
#exportStatus .download-ready {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
}
#exportStatus .download-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  background: var(--accent); color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 500; font-size: 14px;
  text-decoration: none;
}

/* ═══════════════════════════════════════════
   ADMIN LAYOUT
═══════════════════════════════════════════ */
.admin-layout {
  display: flex;
  min-height: 100vh;
}
.admin-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.admin-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.admin-nav { padding: 12px 8px; flex: 1; }
.admin-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.6);
  font-size: 14px;
  transition: all var(--transition);
  margin-bottom: 2px;
}
.admin-nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.admin-nav-item.active { background: rgba(29,158,117,.25); color: #fff; }
.admin-sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.admin-main {
  flex: 1;
  padding: 28px 32px;
  max-width: 1200px;
  overflow-y: auto;
}
.admin-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}
.admin-page-header h1 { font-size: 22px; font-weight: 700; }
.admin-page-header p { color: var(--text-secondary); font-size: 14px; margin-top: 3px; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
}
.stat-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon.green { background: var(--accent-light); color: var(--accent); }
.stat-icon.blue { background: var(--blue-light); color: var(--blue); }
.stat-icon.purple { background: var(--purple-light); color: var(--purple); }
.stat-icon.orange { background: var(--orange-light); color: var(--orange); }
.stat-icon.teal { background: #E6FFFA; color: #2C7A7B; }
.stat-icon.gray { background: var(--bg-tertiary); color: var(--text-secondary); }

.stat-value { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* Dashboard grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 900px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .admin-sidebar { width: 200px; }
  .admin-main { padding: 20px; }
}

@media (max-width: 640px) {
  .app-layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; }
  .export-formats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
}

/* Loading spinner */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(29,158,117,.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Шаблоны анализа ────────────────────── */
.tpl-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 2px;
  transition: all var(--transition);
  white-space: nowrap;
}
.tpl-toggle-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}
.tpl-toggle-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.templates-panel {
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  animation: slideUp .15s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.templates-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 0;
  border-bottom: 1px solid var(--border-light);
}

.templates-tabs {
  display: flex;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 0;
}
.templates-tabs::-webkit-scrollbar { display: none; }

.tpl-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border: none;
  border-bottom: 2.5px solid transparent;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
  border-radius: 0;
  margin-bottom: -1px;
}
.tpl-tab:hover { color: var(--accent); }
.tpl-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: transparent;
}

.tpl-close-btn {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  margin-bottom: 2px;
}
.tpl-close-btn:hover { background: var(--bg-tertiary); color: var(--text); }

.templates-list {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.templates-list::-webkit-scrollbar { height: 4px; }
.templates-list::-webkit-scrollbar-track { background: transparent; }
.templates-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.tpl-card {
  flex-shrink: 0;
  width: 220px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition);
}
.tpl-card:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.tpl-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}
.tpl-card-text {
  font-size: 11.5px;
  color: var(--text-secondary);
  line-height: 1.45;
}
