/* ═══════════════════════════════════════════════════════════════
   OnlyRooms Admin v4.0 — Design System
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a2e;
  --bg-elevated: #16213e;
  --bg-input: #0f0f1a;
  --accent-primary: #7c3aed;
  --accent-secondary: #a855f7;
  --accent-gradient: linear-gradient(135deg, #7c3aed 0%, #a855f7 50%, #c084fc 100%);
  --accent-glow: 0 0 20px rgba(124, 58, 237, 0.3);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #475569;
  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 40px rgba(124, 58, 237, 0.15);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-width: 240px;
  --sidebar-collapsed: 64px;
  --topbar-height: 56px;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-elevated: #ffffff;
  --bg-input: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.15);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}
a { color: var(--accent-secondary); text-decoration: none; }
img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ── Login ──────────────────────────────────────────────────── */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: var(--bg-primary);
  background-image: radial-gradient(ellipse at 50% 0%, rgba(124,58,237,0.15) 0%, transparent 60%);
}
.login-box {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-xl); padding: 48px 40px; width: 400px; max-width: 90vw;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  animation: fadeUp 0.5s ease;
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-icon { font-size: 48px; display: block; margin-bottom: 12px; }
.login-logo h1 { font-size: 1.5rem; font-weight: 700; background: var(--accent-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.login-logo p { color: var(--text-muted); font-size: 0.8125rem; margin-top: 4px; }
.login-error { color: var(--danger); font-size: 0.8125rem; text-align: center; margin-top: 12px; min-height: 20px; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 16px; border: none; border-radius: 8px;
  font-size: 0.8125rem; font-weight: 600;
  transition: all var(--transition-fast); position: relative; overflow: hidden;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent-gradient); color: #fff; }
.btn-primary:hover:not(:disabled) { box-shadow: var(--accent-glow); transform: translateY(-1px); }
.btn-secondary { background: transparent; border: 1px solid var(--border); color: var(--accent-secondary); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent-primary); background: rgba(124,58,237,0.1); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-tertiary); }
.btn-sm { padding: 4px 10px; font-size: 0.75rem; }
.btn-full { width: 100%; }
.btn-icon { padding: 8px; }
.btn-spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: spin 0.6s linear infinite; }

/* ── Form Elements ──────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }
.form-group label { font-size: 0.75rem; color: var(--text-secondary); font-weight: 500; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

input[type="text"], input[type="number"], input[type="password"], input[type="email"],
input[type="url"], input[type="search"], textarea, select {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 8px 12px; color: var(--text-primary); font-size: 0.875rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.15);
}
textarea { resize: vertical; min-height: 80px; }
textarea.tall { min-height: 200px; }
input::placeholder, textarea::placeholder { color: var(--text-muted); }

/* ── Toggle ─────────────────────────────────────────────────── */
.toggle { position: relative; display: inline-flex; width: 44px; height: 24px; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
  position: absolute; inset: 0; background: var(--bg-tertiary); border-radius: 24px;
  border: 1px solid var(--border); transition: all var(--transition-normal);
}
.toggle-slider::before {
  content: ''; position: absolute; height: 18px; width: 18px; left: 2px; bottom: 2px;
  background: var(--text-secondary); border-radius: 50%; transition: all var(--transition-normal);
}
.toggle input:checked + .toggle-slider { background: var(--accent-primary); border-color: var(--accent-primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); background: #fff; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.card:hover { border-color: var(--border-hover); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 0.875rem; font-weight: 600; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; }

/* ── Stat Cards ─────────────────────────────────────────────── */
.stat-card {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
  transition: all var(--transition-fast);
}
.stat-card:hover { border-color: var(--border-hover); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-icon { font-size: 1.25rem; margin-bottom: 8px; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.stat-label { font-size: 0.75rem; color: var(--text-muted); }
.stat-change { font-size: 0.75rem; font-weight: 600; margin-top: 8px; display: flex; align-items: center; gap: 4px; }
.stat-change.up, .stat-change.positive { color: var(--success); }
.stat-change.down, .stat-change.negative { color: var(--danger); }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.data-table th {
  text-align: left; padding: 10px 14px; font-weight: 600; color: var(--text-secondary);
  background: var(--bg-tertiary); border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none; white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.data-table th:hover { color: var(--text-primary); }
.data-table th .sort-arrow { margin-left: 4px; opacity: 0.4; }
.data-table th.sorted .sort-arrow { opacity: 1; color: var(--accent-primary); }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: var(--bg-tertiary); }
.data-table tr:last-child td { border-bottom: none; }
.table-empty { text-align: center; padding: 40px; color: var(--text-muted); }

.pagination { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; font-size: 0.8125rem; }
.pagination-info { color: var(--text-muted); }
.pagination-buttons { display: flex; gap: 4px; }
.pagination-btn {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-secondary); color: var(--text-secondary); font-size: 0.75rem; cursor: pointer;
  transition: all var(--transition-fast);
}
.pagination-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }
.pagination-btn.active { background: var(--accent-primary); color: #fff; border-color: var(--accent-primary); }

/* ── Tabs ───────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab {
  padding: 10px 16px; font-size: 0.8125rem; font-weight: 500; color: var(--text-muted);
  border: none; background: none; cursor: pointer; position: relative; white-space: nowrap;
  transition: color var(--transition-fast);
}
/* Character editor tabs — wrap to 2 rows */
#char-editor-tabs .tabs { flex-wrap: wrap; overflow-x: visible; }
#char-editor-tabs .tab { padding: 8px 12px; font-size: 0.75rem; }
.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--accent-primary); }
.tab.active::after {
  content: ''; position: absolute; bottom: -1px; left: 0; right: 0; height: 2px;
  background: var(--accent-gradient); border-radius: 2px 2px 0 0;
}

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 10px; font-size: 0.6875rem; font-weight: 600;
}
.badge-success { background: rgba(16,185,129,0.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-info { background: rgba(59,130,246,0.15); color: var(--info); }
.badge-purple { background: rgba(124,58,237,0.15); color: var(--accent-secondary); }
.badge-soon { background: rgba(245,158,11,0.15); color: var(--warning); font-size: 0.5625rem; margin-left: auto; }

/* ── App Layout ─────────────────────────────────────────────── */
.app-shell { display: grid; grid-template-columns: var(--sidebar-width) 1fr; grid-template-rows: var(--topbar-height) 1fr; height: 100vh; }
.app-shell.sidebar-collapsed { grid-template-columns: var(--sidebar-collapsed) 1fr; }

/* ── Top Bar ────────────────────────────────────────────────── */
.topbar {
  grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; background: var(--bg-secondary); border-bottom: 1px solid var(--border);
  z-index: 100; gap: 16px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.sidebar-toggle { background: none; border: none; color: var(--text-secondary); padding: 4px; display: flex; }
.sidebar-toggle:hover { color: var(--text-primary); }
.topbar-brand { display: flex; align-items: center; gap: 8px; }
.brand-icon { font-size: 1.25rem; }
.brand-text { font-weight: 700; font-size: 0.9375rem; }
.brand-label { font-weight: 400; color: var(--text-muted); font-size: 0.75rem; }
.topbar-center { flex: 1; max-width: 480px; }
.search-box { position: relative; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search-box input {
  width: 100%; padding: 8px 12px 8px 36px; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  font-size: 0.8125rem; color: var(--text-primary);
}
.search-box input:focus { border-color: var(--accent-primary); box-shadow: 0 0 0 3px rgba(124,58,237,0.15); outline: none; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.theme-toggle { background: none; border: none; color: var(--text-secondary); padding: 6px; display: flex; border-radius: var(--radius-sm); }
.theme-toggle:hover { background: var(--bg-tertiary); color: var(--text-primary); }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: block !important; }
.topbar-user { display: flex; align-items: center; gap: 8px; }
.user-avatar { font-size: 1.125rem; }
.user-name { font-size: 0.8125rem; font-weight: 500; color: var(--text-secondary); }

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  grid-row: 2; background: var(--bg-secondary); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden;
  transition: width var(--transition-normal);
}
.sidebar-nav { flex: 1; padding: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: var(--radius-md); color: var(--text-secondary); font-size: 0.8125rem;
  font-weight: 500; transition: all var(--transition-fast); text-decoration: none;
  margin-bottom: 2px; white-space: nowrap;
}
.nav-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.nav-item.active { background: rgba(124,58,237,0.15); color: var(--accent-secondary); }
.nav-item svg { flex-shrink: 0; }
.nav-coming-soon { opacity: 0.5; }
.nav-divider { height: 1px; background: var(--border); margin: 8px 12px; }
.nav-label { font-size: 0.625rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); padding: 4px 20px 2px; }
.sidebar-collapsed .nav-label { display: none; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); }
.version { font-size: 0.6875rem; color: var(--text-muted); }
.sidebar-collapsed .nav-item span:not(.badge) { display: none; }
.sidebar-collapsed .badge { display: none; }
.sidebar-collapsed .sidebar-footer .version { display: none; }

/* ── Main Content ───────────────────────────────────────────── */
.main-content {
  grid-row: 2; overflow-y: auto; padding: 24px;
  background: var(--bg-primary);
}
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-title { font-size: 1.25rem; font-weight: 700; }
.page-actions { display: flex; gap: 8px; }

/* ── Stat Grid ──────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stats-grid-small { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.chart-grid, .charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-grid .card, .charts-grid .card { min-height: 300px; }

/* ── Dashboard Bottom ──────────────────────────────────────── */
.dashboard-bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }

/* ── Filters Bar ───────────────────────────────────────────── */
.filters-bar { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
.filters-bar .select { width: auto; min-width: 160px; }
.search-box-page { flex: 1; min-width: 200px; max-width: 360px; }

/* ── Form Grid ─────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-actions { margin-top: 20px; display: flex; gap: 8px; justify-content: flex-end; }

/* ── Character Grid ─────────────────────────────────────────── */
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.char-card {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden; cursor: pointer;
  transition: all var(--transition-fast); position: relative;
  display: flex; flex-direction: column;
}
.char-card:hover { border-color: var(--border-hover); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.char-card-avatar { width: 100%; aspect-ratio: 1; background: var(--bg-tertiary); display: flex; align-items: center; justify-content: center; font-size: 3rem; overflow: hidden; }
.char-card-avatar img { width: 100%; height: 100%; object-fit: cover; }
.char-card-emoji { font-size: 3rem; }
.char-card-info { padding: 14px; flex: 1; }
.char-card-name { font-weight: 600; font-size: 0.875rem; margin-bottom: 6px; }
.char-card-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.char-card-stats { font-size: 0.6875rem; color: var(--text-muted); }
.char-card-toggle { position: absolute; top: 10px; right: 10px; z-index: 2; }
.char-avatar { width: 100%; aspect-ratio: 1; background: var(--bg-tertiary); display: flex; align-items: center; justify-content: center; font-size: 3rem; overflow: hidden; }
.char-avatar img { width: 100%; height: 100%; object-fit: cover; }
.char-info { padding: 14px; }
.char-name { font-weight: 600; font-size: 0.875rem; margin-bottom: 4px; }
.char-meta { font-size: 0.75rem; color: var(--text-muted); display: flex; gap: 8px; flex-wrap: wrap; }
.char-status { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-top: 1px solid var(--border); }
.char-stats { font-size: 0.6875rem; color: var(--text-muted); }

/* ── Activity Feed ──────────────────────────────────────────── */
.activity-feed, .feed { max-height: 400px; overflow-y: auto; }
.feed-item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.8125rem; align-items: center; }
.feed-item:last-child { border-bottom: none; }
.feed-icon { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.875rem; flex-shrink: 0; background: var(--bg-tertiary); }
.feed-body { flex: 1; }
.feed-text { color: var(--text-primary); flex: 1; }
.feed-time { font-size: 0.6875rem; color: var(--text-muted); white-space: nowrap; margin-left: auto; }
.feed-empty { text-align: center; padding: 24px; color: var(--text-muted); font-size: 0.8125rem; }
.feed-details { display: block; font-size: 0.75rem; color: var(--text-muted); }

/* ── Live Dot ──────────────────────────────────────────────── */
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); display: inline-block; }
.live-dot.connected { background: var(--success); box-shadow: 0 0 8px rgba(16,185,129,0.5); animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ── Top Characters ────────────────────────────────────────── */
.top-char-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.top-char-item:last-child { border-bottom: none; }
.top-char-rank { font-size: 0.75rem; font-weight: 700; color: var(--text-muted); min-width: 28px; }
.top-char-avatar { font-size: 1.5rem; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; background: var(--bg-tertiary); border-radius: 50%; }
.top-char-info { flex: 1; }
.top-char-name { font-weight: 600; font-size: 0.875rem; }
.top-char-meta { font-size: 0.6875rem; color: var(--text-muted); }

/* ── Toast ──────────────────────────────────────────────────── */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 10000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px 16px; min-width: 280px; max-width: 400px;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px;
  animation: slideInRight 0.3s ease; position: relative; overflow: hidden;
}
.toast-icon { font-size: 1.125rem; }
.toast-text { flex: 1; font-size: 0.8125rem; }
.toast-close { background: none; border: none; color: var(--text-muted); font-size: 1rem; padding: 0; }
.toast-progress { position: absolute; bottom: 0; left: 0; height: 3px; border-radius: 0 0 var(--radius-md) var(--radius-md); animation: shrink linear forwards; }
.toast.success .toast-progress { background: var(--success); }
.toast.warning .toast-progress { background: var(--warning); }
.toast.danger .toast-progress { background: var(--danger); }
.toast.info .toast-progress { background: var(--info); }

/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(8px);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-lg); width: 560px; max-width: 90vw; max-height: 85vh;
  display: flex; flex-direction: column; animation: scaleIn 0.2s ease;
  box-shadow: var(--shadow-lg);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.5rem; line-height: 1; padding: 0; }
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ── SlideOver ──────────────────────────────────────────────── */
.slideover-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px);
  z-index: 1000; animation: fadeIn 0.2s ease;
}
.slideover {
  position: absolute; right: 0; top: 0; bottom: 0; width: 480px; max-width: 90vw;
  background: var(--bg-elevated); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; animation: slideInRight 0.3s ease;
  box-shadow: var(--shadow-lg);
}
.slideover-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.slideover-title { font-size: 1rem; font-weight: 600; }
.slideover-close { background: none; border: none; color: var(--text-muted); font-size: 1.5rem; line-height: 1; }
.slideover-close:hover { color: var(--text-primary); }
.slideover-body { flex: 1; overflow-y: auto; padding: 20px; }

/* ── Spinner ────────────────────────────────────────────────── */
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--accent-primary); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.page-loader { display: flex; align-items: center; justify-content: center; height: 100%; }

/* ── Empty State ────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; display: block; }
.empty-state .empty-text { font-size: 0.9375rem; margin-bottom: 16px; }

/* ── Photo Grid ─────────────────────────────────────────────── */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin-top: 8px; }
.photo-item {
  position: relative; aspect-ratio: 3/4; border-radius: var(--radius-sm); overflow: hidden;
  background: var(--bg-input); border: 2px dashed var(--border); cursor: pointer;
  transition: border-color var(--transition-fast);
}
.photo-item:hover { border-color: var(--accent-primary); }
.photo-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-item video { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.photo-delete {
  position: absolute; top: 4px; right: 4px; width: 20px; height: 20px;
  background: var(--danger); color: #fff; border: none; border-radius: 50%;
  font-size: 0.6875rem; display: none; align-items: center; justify-content: center;
}
.photo-item:hover .photo-delete { display: flex; }
.photo-upload {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; color: var(--text-muted); font-size: 0.6875rem; border-style: dashed;
}
.photo-upload span { font-size: 1.25rem; }

/* ── Tier Labels ────────────────────────────────────────────── */
.tier-label { font-size: 0.6875rem; font-weight: 600; margin: 12px 0 4px; padding: 2px 8px; border-radius: 4px; display: inline-block; }
.tier-public { background: rgba(16,185,129,0.15); color: var(--success); }
.tier-personal { background: rgba(245,158,11,0.15); color: var(--warning); }
.tier-exclusive { background: rgba(239,68,68,0.15); color: var(--danger); }

/* ── Section / Form Section ─────────────────────────────────── */
.section { margin-bottom: 24px; }
.section-title { font-size: 0.875rem; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.section-divider { height: 1px; background: var(--border); margin: 24px 0; }

/* ── Conversation Viewer ────────────────────────────────────── */
.chat-viewer-header { font-weight: 600; font-size: 0.875rem; padding: 10px 0; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.chat-messages { max-height: 400px; overflow-y: auto; padding: 12px; background: var(--bg-input); border-radius: var(--radius-md); }
.chat-msg { margin-bottom: 8px; padding: 8px 12px; border-radius: 12px; max-width: 80%; font-size: 0.8125rem; }
.chat-msg.user, .chat-msg-user { background: var(--accent-primary); color: #fff; margin-left: auto; border-bottom-right-radius: 4px; }
.chat-msg.assistant, .chat-msg-bot { background: var(--bg-tertiary); color: var(--text-primary); border-bottom-left-radius: 4px; }
.chat-msg-text { line-height: 1.4; }
.chat-msg-time { font-size: 0.625rem; color: var(--text-muted); margin-top: 2px; }
.chat-msg-user .chat-msg-time { color: rgba(255,255,255,0.6); }

/* ── Coming Soon ────────────────────────────────────────────── */
.coming-soon-page { display: flex; align-items: center; justify-content: center; min-height: 60vh; }
.coming-soon-card { text-align: center; max-width: 480px; padding: 48px 32px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-md); }
.coming-soon-icon { font-size: 4rem; margin-bottom: 16px; }
.coming-soon-title { font-size: 1.75rem; font-weight: 700; margin-bottom: 8px; }
.coming-soon-desc { color: var(--text-secondary); margin-bottom: 24px; font-size: 0.875rem; line-height: 1.6; }
.coming-soon-features { display: flex; flex-direction: column; gap: 10px; text-align: left; margin-bottom: 24px; }
.coming-soon-feature { display: flex; align-items: center; gap: 10px; font-size: 0.875rem; color: var(--text-secondary); }
.feature-check { color: var(--success); font-weight: 700; }
.coming-soon-badge { margin-top: 8px; }

/* ── Heatmap ────────────────────────────────────────────────── */
.heatmap { display: grid; grid-template-columns: 40px repeat(24, 1fr); gap: 2px; font-size: 0.625rem; }
.heatmap-label { display: flex; align-items: center; color: var(--text-muted); }
.heatmap-cell {
  aspect-ratio: 1; border-radius: 3px; transition: opacity var(--transition-fast);
}
.heatmap-cell:hover { outline: 1px solid var(--accent-primary); }

/* ── Funnel ─────────────────────────────────────────────────── */
.funnel { display: flex; flex-direction: column; gap: 8px; }
.funnel-step { display: flex; align-items: center; gap: 12px; }
.funnel-bar { height: 32px; background: var(--accent-gradient); border-radius: var(--radius-sm); transition: width 0.5s ease; display: flex; align-items: center; padding: 0 12px; color: #fff; font-size: 0.75rem; font-weight: 600; min-width: 40px; }
.funnel-label { font-size: 0.75rem; color: var(--text-secondary); min-width: 120px; }

/* ── User Profile (SlideOver) ──────────────────────────────── */
.user-profile { display: flex; flex-direction: column; gap: 16px; }
.user-profile-header { display: flex; align-items: center; gap: 16px; }
.user-avatar-big { width: 48px; height: 48px; border-radius: 50%; background: var(--accent-gradient); display: flex; align-items: center; justify-content: center; font-size: 1.25rem; font-weight: 700; color: #fff; flex-shrink: 0; }
.user-meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
.user-stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.user-stat { text-align: center; padding: 10px; background: var(--bg-tertiary); border-radius: var(--radius-md); }
.stat-num { display: block; font-size: 1.25rem; font-weight: 700; }
.stat-lbl { display: block; font-size: 0.625rem; color: var(--text-muted); text-transform: uppercase; }
.user-actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 8px; border-top: 1px solid var(--border); }

/* ── Conversation List ─────────────────────────────────────── */
.convo-list { max-height: 200px; overflow-y: auto; }
.convo-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; transition: background var(--transition-fast); border-bottom: 1px solid var(--border); }
.convo-item:hover { background: var(--bg-tertiary); }
.convo-char { font-weight: 600; font-size: 0.8125rem; }
.convo-meta { font-size: 0.6875rem; color: var(--text-muted); }

/* ── Media Upload ──────────────────────────────────────────── */
.media-section { margin-bottom: 20px; }
.media-section h4 { font-size: 0.875rem; font-weight: 600; margin-bottom: 8px; }
.media-upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius-md);
  padding: 24px; text-align: center; cursor: pointer; color: var(--text-muted);
  transition: all var(--transition-fast); font-size: 0.8125rem;
}
.media-upload-zone:hover { border-color: var(--accent-primary); background: rgba(124,58,237,0.05); }
.avatar-preview { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; margin: 0 auto; }
.tier-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tier-tabs .btn.active { background: var(--accent-primary); color: #fff; }

/* ── Settings ──────────────────────────────────────────────── */
.settings-form { max-width: 800px; }
.settings-group-title { font-size: 0.875rem; font-weight: 600; margin: 20px 0 10px; color: var(--text-secondary); }

/* ── Test AI Result ────────────────────────────────────────── */
.test-result { padding: 16px; border-radius: var(--radius-md); margin-top: 12px; }
.test-result.test-success { background: rgba(16,185,129,0.1); border: 1px solid rgba(16,185,129,0.2); }
.test-result.test-error { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.2); }
.test-status { font-weight: 700; font-size: 1rem; margin-bottom: 8px; }
.test-engine, .test-model, .test-latency { font-size: 0.8125rem; color: var(--text-secondary); margin-bottom: 4px; }
.test-response { margin-top: 12px; }
.test-response pre { background: var(--bg-input); padding: 12px; border-radius: var(--radius-sm); font-size: 0.8125rem; overflow-x: auto; white-space: pre-wrap; }
.test-error-msg { color: var(--danger); font-size: 0.8125rem; margin-top: 8px; }

/* ── Skeleton ──────────────────────────────────────────────── */
.skeleton { position: relative; overflow: hidden; }
.skeleton::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
  animation: shimmer 1.5s infinite;
}
.skeleton-text { height: 14px; width: 60%; background: var(--bg-tertiary); border-radius: 4px; margin: 8px auto; }
@keyframes shimmer { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

/* ── Admin Cards ───────────────────────────────────────────── */
.admin-list { display: flex; flex-direction: column; gap: 12px; }
.audit-log { max-height: 600px; overflow-y: auto; }

/* ── Select / Input / Textarea classes ─────────────────────── */
.select { appearance: none; background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e"); background-position: right 8px center; background-repeat: no-repeat; background-size: 16px; padding-right: 30px; }
.input { /* inherits from input[type="text"] */ }
.textarea { /* inherits from textarea */ }
.range { width: 100%; accent-color: var(--accent-primary); }

/* ── Telegram WebApp ───────────────────────────────────────── */
.tg-hidden { display: none !important; }
.tg-mode { grid-template-rows: 1fr !important; }
.tg-mode .main-content { grid-row: 1; }

/* ── Animations ─────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
@keyframes slideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shrink { from { width: 100%; } to { width: 0%; } }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .app-shell { grid-template-columns: var(--sidebar-collapsed) 1fr; }
  .nav-item span:not(.badge) { display: none; }
  .badge { display: none; }
  .sidebar-footer .version { display: none; }
  .chart-grid, .charts-grid { grid-template-columns: 1fr; }
  .dashboard-bottom { grid-template-columns: 1fr; }
}

/* Tooltip help icons */
.tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  cursor: help;
  margin-left: 6px;
  vertical-align: middle;
  flex-shrink: 0;
  line-height: 1;
  font-style: normal;
}
.tip:hover {
  color: var(--accent-secondary);
  border-color: var(--accent-primary);
  background: var(--bg-elevated);
}
/* Floating tooltip popup (appended to body via JS) */
.tip-popup {
  position: fixed;
  z-index: 99999;
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 400;
  white-space: normal;
  width: max-content;
  max-width: 300px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-hover);
  line-height: 1.5;
  pointer-events: none;
  animation: fadeIn 0.15s ease;
}
/* Test AI result styles */
.test-result {
  margin-top: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  line-height: 1.5;
  border: 1px solid var(--border);
  background: var(--bg-input);
}
.test-result.test-success {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.08);
}
.test-result.test-error {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.08);
}

@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: -260px; top: var(--topbar-height); bottom: 0;
    width: var(--sidebar-width); z-index: 200; transition: left var(--transition-normal);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { left: 0; }
  .sidebar.open + .sidebar-backdrop { display: block; }
  .sidebar-backdrop {
    display: none; position: fixed; inset: 0; top: var(--topbar-height);
    background: rgba(0,0,0,0.4); z-index: 199;
  }
  .nav-item span { display: inline; }
  .badge { display: inline-flex; }
  .main-content { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar-center { display: none; }
  .brand-text { display: none; }
  .form-row, .form-grid { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr; }
  .slideover { width: 100vw; }
  .char-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .user-stats-row { grid-template-columns: repeat(2, 1fr); }
  .dashboard-bottom { grid-template-columns: 1fr; }
  .modal { width: 100vw; max-width: 100vw; max-height: 100vh; border-radius: 0; }
}

/* ── System Page — Error Log & Nav Badge ────────────────────── */
.nav-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--danger); color: #fff; font-size: 0.625rem; font-weight: 700;
  border-radius: 9px; margin-left: auto;
}
.error-log-list { display: flex; flex-direction: column; gap: 8px; }
.error-log-item {
  background: var(--bg-secondary); border-radius: var(--radius-md);
  padding: 12px 16px; border-left: 3px solid var(--danger);
  transition: opacity 0.2s;
}
.error-log-item.acked { opacity: 0.5; border-left-color: var(--text-muted); }
.error-log-item.unread { border-left-color: var(--danger); }
.error-log-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 6px;
}
.error-source {
  font-weight: 600; font-size: 0.85rem; color: var(--danger);
}
.error-time {
  font-size: 0.75rem; color: var(--text-muted); margin-left: auto;
}
.error-message {
  font-size: 0.85rem; color: var(--text-primary); word-break: break-word;
}
.error-context {
  font-size: 0.75rem; color: var(--text-secondary); margin-top: 4px;
}
.error-trace-details { margin-top: 8px; }
.error-trace-details summary {
  font-size: 0.75rem; color: var(--text-muted); cursor: pointer;
  user-select: none;
}
.error-traceback {
  font-size: 0.7rem; background: var(--bg-tertiary); padding: 8px 12px;
  border-radius: var(--radius-sm); overflow-x: auto; max-height: 200px;
  margin-top: 4px; color: var(--text-secondary); white-space: pre-wrap;
  word-break: break-all;
}
