/* ============================================================
   GPT-Free Admin — тёмная тема без внешних зависимостей
   ============================================================ */

:root {
  color-scheme: dark;
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #262626;
  --accent: #10a37f;
  --accent-hover: #1a7f64;
  --text-primary: #ececec;
  --text-secondary: #a1a1a1;
  --text-muted: #6b6b6b;
  --border: #333333;
  --success: #10a37f;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #3b82f6;
  --radius: 12px;
  --sidebar-width: 256px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: #3a3a3a; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #4a4a4a; }

/* ---------- Boot / spinner ---------- */

.boot-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  flex-shrink: 0;
}

.spinner.sm { width: 20px; height: 20px; }
.spinner.lg { width: 40px; height: 40px; }

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

.loading-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px;
  color: var(--text-secondary);
}

/* ---------- Layout ---------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform .25s ease;
}

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

.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, .55);
}

.sidebar-logo {
  height: 64px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
}

.sidebar-nav { padding: 16px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--bg-tertiary); color: var(--text-primary); text-decoration: none; }
.nav-link.active { background: rgba(16, 163, 127, .12); color: var(--accent); }
.nav-link svg { flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

.main-column { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 64px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.topbar-left { display: flex; align-items: center; gap: 16px; min-width: 0; }
.topbar-title { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 16px; }

.menu-btn {
  display: inline-flex;
  padding: 8px;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 8px;
}
.menu-btn:hover { color: var(--text-primary); background: var(--bg-tertiary); }

.admin-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}
.admin-name { font-size: 14px; color: var(--text-secondary); }

.page { flex: 1; padding: 16px; width: 100%; }
.page-inner { display: flex; flex-direction: column; gap: 24px;  }

@media (min-width: 1024px) {
  .sidebar { position: sticky; top: 0; height: 100vh; transform: none; }
  .sidebar-overlay { display: none !important; }
  .page { padding: 24px; }
  .topbar { padding: 0 24px; }
}

/* ---------- Typography / page head ---------- */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 24px; font-weight: 700; }
.page-head p { margin: 4px 0 0; font-size: 14px; color: var(--text-secondary); }
.muted { color: var(--text-secondary); }
.muted-sm { color: var(--text-secondary); font-size: 13px; }
.tiny { font-size: 12px; color: var(--text-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-accent { color: var(--accent); }
.text-error { color: var(--error); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-amber { color: #fbbf24; }

h2.section-title { margin: 0; font-size: 18px; font-weight: 600; }
h3.card-title { margin: 0; font-size: 17px; font-weight: 600; }

/* ---------- Grid / flex helpers ---------- */

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.w-full { width: 100%; }

@media (max-width: 900px) {
  .grid-3, .grid-4, .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; }
}

/* ---------- Cards ---------- */

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.card-head h2, .card-head h3 { margin: 0; font-size: 17px; font-weight: 600; }
.card-body { padding: 24px; }

.metric-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.metric-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; color: var(--text-secondary); }
.metric-value { font-size: 30px; font-weight: 700; line-height: 1.15; margin-bottom: 4px; }
.metric-label { font-size: 14px; color: var(--text-secondary); }
.metric-sub { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.metric-card.accent .metric-value { color: var(--accent); }

.metric-card.gradient-blue { background: linear-gradient(135deg, rgba(59,130,246,.18), rgba(59,130,246,.04)); border-color: rgba(59,130,246,.3); }
.metric-card.gradient-purple { background: linear-gradient(135deg, rgba(168,85,247,.18), rgba(168,85,247,.04)); border-color: rgba(168,85,247,.3); }
.metric-card.gradient-green { background: linear-gradient(135deg, rgba(34,197,94,.18), rgba(34,197,94,.04)); border-color: rgba(34,197,94,.3); }
.metric-card.gradient-gray { background: linear-gradient(135deg, rgba(107,114,128,.18), rgba(107,114,128,.04)); border-color: rgba(107,114,128,.3); }

.stat-inline { display: flex; align-items: baseline; gap: 6px; }
.stat-inline .value { font-size: 24px; font-weight: 700; }
.stat-inline .hint { font-size: 12px; color: var(--text-muted); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
  transition: background .15s, color .15s, opacity .15s;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-tertiary); border-color: var(--border); color: var(--text-primary); }
.btn-secondary:hover { background: #303030; }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  transition: color .15s, background .15s;
}
.icon-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.icon-btn.danger:hover { color: var(--error); }
.icon-btn.success:hover { color: var(--success); }
.icon-btn.accent:hover { color: var(--accent); }
.icon-btn.purple:hover { color: #c084fc; }

.pill-group { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.pill:hover { color: var(--text-primary); }
.pill.active { background: var(--accent); color: #fff; }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }

.input, .select, textarea.input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--text-muted); }
.input:focus, .select:focus, textarea.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(16, 163, 127, .15);
}
.input.icon-left { padding-left: 38px; }
.input.icon-right { padding-right: 38px; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%), linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.search-wrap { position: relative; }
.search-wrap .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; display: flex; }
.search-wrap .clear-btn { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); }

.checkbox { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ---------- Alerts ---------- */

.alert {
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  font-size: 14px;
}
.alert-error { background: rgba(239, 68, 68, .1); border-color: rgba(239, 68, 68, .5); color: #fca5a5; }
.alert-success { background: rgba(16, 163, 127, .1); border-color: rgba(16, 163, 127, .5); color: #6ee7b7; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data thead { background: var(--bg-tertiary); }
table.data th {
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-secondary);
  white-space: nowrap;
}
table.data td { padding: 12px 16px; border-top: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
table.data tbody tr:hover { background: rgba(38, 38, 38, .5); }
table.data td.right, table.data th.right { text-align: right; }
table.data td.center, table.data th.center { text-align: center; }
table.data .empty-cell { text-align: center; color: var(--text-secondary); padding: 32px 16px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-success { background: rgba(16, 163, 127, .14); color: #34d399; }
.badge-error { background: rgba(239, 68, 68, .14); color: #f87171; }
.badge-warning { background: rgba(245, 158, 11, .14); color: #fbbf24; }
.badge-info { background: rgba(59, 130, 246, .14); color: #60a5fa; }
.badge-purple { background: rgba(168, 85, 247, .14); color: #c084fc; }
.badge-muted { background: rgba(107, 107, 107, .16); color: var(--text-secondary); }

/* ---------- Pagination ---------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-secondary);
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, .65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 18px; font-weight: 600; }
.modal-head p { margin: 4px 0 0; font-size: 13px; color: var(--text-secondary); }
.modal-body { padding: 24px; overflow-y: auto; }
.modal-foot { display: flex; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--border); }
.modal-foot .btn { flex: 1; }

/* ---------- Funnels ---------- */

.funnel-list { display: flex; flex-direction: column; gap: 16px; }
.funnel-row .funnel-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.funnel-row .funnel-name { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-secondary); }
.funnel-row .funnel-numbers { text-align: right; font-size: 14px; }
.funnel-row .funnel-numbers .count { font-weight: 600; color: var(--text-primary); }
.funnel-row .funnel-numbers .conv { font-size: 12px; color: var(--text-muted); margin-left: 6px; }
.funnel-row .step { font-size: 12px; color: var(--accent); margin-top: 2px; }
.funnel-track { width: 100%; height: 14px; border-radius: 999px; background: var(--bg-tertiary); overflow: hidden; }
.funnel-fill { height: 100%; border-radius: 999px; transition: width .5s ease; }
.funnel-summary { margin-top: 20px; padding: 16px; border-radius: 10px; background: var(--bg-tertiary); }
.issues-box { margin-top: 20px; padding: 16px; border-radius: 10px; background: rgba(239, 68, 68, .08); border: 1px solid rgba(239, 68, 68, .3); }
.issues-box h4 { margin: 0 0 8px; font-size: 14px; color: #f87171; }
.issues-box p { margin: 4px 0; font-size: 14px; color: var(--text-secondary); }
.tips-box { margin-top: 16px; padding: 16px; border-radius: 10px; background: rgba(16, 163, 127, .08); border: 1px solid rgba(16, 163, 127, .3); }
.tips-box h4 { margin: 0 0 8px; font-size: 14px; color: #34d399; }
.tips-box p { margin: 4px 0; font-size: 14px; color: var(--text-secondary); }

/* ---------- Charts ---------- */

.chart-box { position: relative; width: 100%; height: 280px; }
.chart-box.tall { height: 320px; }
.chart-box.short { height: 200px; }
.chart-empty { height: 100%; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); font-size: 14px; text-align: center; padding: 16px; }

/* ---------- Misc ---------- */

.avatar-badge {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(16, 163, 127, .18);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.chat-list { display: flex; flex-direction: column; gap: 16px; }
.chat-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; transition: background .15s; }
.chat-card:hover { background: #202020; }
.chat-card-main { cursor: pointer; flex: 1; min-width: 0; }
.chat-title { font-size: 16px; font-weight: 600; margin: 0 0 8px; }

.message-scroll { max-height: 600px; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.message-row { display: flex; align-items: flex-start; min-width: 0; }
.message-row.user { justify-content: flex-end; }
.message-row.assistant { justify-content: flex-start; }
.message-bubble { max-width: 80%; border-radius: 18px; padding: 12px 16px; white-space: normal; overflow-wrap: anywhere; word-break: normal; flex: 0 1 auto; width: fit-content; align-self: flex-start; }
.message-row.user .message-bubble { background: var(--accent); color: #fff; }
.message-row.assistant .message-bubble { background: var(--bg-tertiary); color: var(--text-primary); }
.message-author { font-size: 12px; font-weight: 500; opacity: .7; margin-bottom: 4px; }
.message-time { font-size: 11px; opacity: .5; margin-top: 8px; }

.image-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (min-width: 640px) { .image-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) { .image-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .image-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

.image-card { position: relative; background: var(--bg-tertiary); border: 1px solid rgba(51, 51, 51, .7); border-radius: 10px; overflow: hidden; }
.image-card:hover { border-color: rgba(16, 163, 127, .5); }
.image-thumb { aspect-ratio: 1 / 1; background: #1f2937; cursor: pointer; position: relative; overflow: hidden; }
.image-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-overlay { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); opacity: 0; transition: opacity .15s; display: flex; align-items: center; justify-content: center; gap: 8px; }
.image-card:hover .image-overlay { opacity: 1; }
.image-meta { padding: 12px; }
.image-meta .prompt { font-size: 12px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.image-meta .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--text-muted); }

.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: 100%; max-width: 420px; }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 { margin: 0 0 8px; font-size: 30px; font-weight: 700; }
.login-logo p { margin: 0; color: var(--text-secondary); }
.login-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; display: flex; flex-direction: column; gap: 20px; }
.login-footer { text-align: center; color: var(--text-muted); font-size: 13px; margin-top: 24px; }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab { padding: 8px 14px; border-radius: 8px; border: 1px solid transparent; background: var(--bg-secondary); color: var(--text-secondary); font-weight: 500; }
.tab:hover { color: var(--text-primary); }
.tab.active { background: var(--accent); color: #fff; }

.toggle-row { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-secondary); cursor: pointer; }

.tier-grid { display: grid; grid-template-columns: 1fr 1fr 44px; gap: 12px; align-items: center; }
.tier-head { padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); }

.kv { display: flex; flex-direction: column; gap: 4px; }
.kv .k { font-size: 12px; color: var(--text-muted); }
.kv .v { font-size: 15px; font-weight: 600; }

.skeleton { background: var(--bg-tertiary); border-radius: 8px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

.hidden { display: none !important; }
