:root, [data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #22252f;
  --border: #2a2d3a;
  --text: #e4e4e7;
  --text-muted: #8b8d97;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --green: #22c55e;
  --green-bg: rgba(34,197,94,0.12);
  --red: #ef4444;
  --red-bg: rgba(239,68,68,0.12);
  --yellow: #eab308;
  --yellow-bg: rgba(234,179,8,0.12);
  --blue: #3b82f6;
  --blue-bg: rgba(59,130,246,0.12);
  --sidebar-w: 240px;
  --chart-grid: #1f2233;
}

[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f8f9fb;
  --surface-hover: #f0f1f4;
  --border: #e2e4e9;
  --text: #1a1d27;
  --text-muted: #6b7280;
  --accent: #4f46e5;
  --accent-light: #6366f1;
  --green: #16a34a;
  --green-bg: rgba(22,163,74,0.08);
  --red: #dc2626;
  --red-bg: rgba(220,38,38,0.06);
  --yellow: #ca8a04;
  --yellow-bg: rgba(202,138,4,0.08);
  --blue: #2563eb;
  --blue-bg: rgba(37,99,235,0.06);
  --chart-grid: #e5e7eb;
}

.theme-toggle { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 16px; color: var(--text-muted); transition: all 0.2s; }
.theme-toggle:hover { border-color: var(--accent); color: var(--text); }

* { margin: 0; padding: 0; box-sizing: border-box; transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); padding: 20px 0; position: fixed; top: 0; left: 0; height: 100vh; display: flex; flex-direction: column; z-index: 10; transition: width 0.25s ease; overflow: hidden; }
.sidebar.collapsed { width: 60px; }
.sidebar-brand { padding: 0 20px 24px; border-bottom: 1px solid var(--border); margin-bottom: 8px; white-space: nowrap; }
.sidebar-brand h1 { font-size: 18px; font-weight: 700; color: var(--accent-light); }
.sidebar.collapsed .sidebar-brand { padding: 12px 12px 20px; justify-content: center; align-items: center; }
.sidebar.collapsed .sidebar-brand > div:first-child { display: none; }
.sidebar.collapsed .sidebar-toggle { width: 36px; height: 36px; padding: 0; font-size: 18px; display: flex; align-items: center; justify-content: center; }
.sidebar.collapsed .sidebar-brand span { display: none; }
.sidebar-brand span { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 20px; color: var(--text-muted); cursor: pointer; transition: all 0.15s; font-size: 13px; text-decoration: none; white-space: nowrap; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; gap: 0; }
.sidebar.collapsed .nav-item span:last-child { display: none; }
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active { color: var(--accent-light); background: rgba(99,102,241,0.08); border-right: 2px solid var(--accent); }
.nav-section { padding: 16px 20px 6px; font-size: 10px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--text-muted); white-space: nowrap; }
.sidebar.collapsed .nav-section { visibility: hidden; padding: 8px 0 2px; }
.sidebar-footer { margin-top: auto; padding: 16px 20px; border-top: 1px solid var(--border); white-space: nowrap; }
.sidebar.collapsed .sidebar-footer { padding: 16px 8px; }
.sidebar.collapsed .admin-badge span:not(.dot) { display: none; }
.sidebar-toggle { background: none; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; color: var(--text-muted); font-size: 14px; padding: 4px 8px; transition: all 0.15s; }
.sidebar-toggle:hover { background: var(--surface-hover); color: var(--text); }
.admin-badge { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.admin-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }

/* Main */
.main { margin-left: var(--sidebar-w); flex: 1; padding: 24px 32px; transition: margin-left 0.25s ease; }
.main.sidebar-collapsed { margin-left: 60px; }

/* Header */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 28px; }
.page-header h2 { font-size: 22px; font-weight: 600; }
.header-meta { display: flex; align-items: center; gap: 16px; }
.live-badge { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--green); background: var(--green-bg); padding: 4px 12px; border-radius: 20px; }
.live-badge .pulse { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.time-display { font-size: 12px; color: var(--text-muted); }

/* Cards Grid */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.stat-card .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 8px; }
.stat-card .value { font-size: 28px; font-weight: 700; }
.stat-card .change { font-size: 11px; margin-top: 6px; display: flex; align-items: center; gap: 4px; }
.stat-card .change.up { color: var(--green); }
.stat-card .change.down { color: var(--red); }

/* Charts */
.charts-row { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.chart-card .chart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.chart-card .chart-title { font-size: 14px; font-weight: 600; }
.chart-card .chart-subtitle { font-size: 11px; color: var(--text-muted); }
.chart-container { position: relative; height: 220px; }

/* Tables */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 24px; }
.table-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.table-title { font-size: 14px; font-weight: 600; }
.search-box { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; color: var(--text); font-size: 12px; width: 220px; outline: none; }
.search-box:focus { border-color: var(--accent); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); padding: 10px 12px; border-bottom: 1px solid var(--border); }
td { padding: 12px; font-size: 13px; border-bottom: 1px solid var(--border); }
tr:hover td { background: var(--surface-hover); }
.badge { font-size: 10px; padding: 3px 8px; border-radius: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.badge-paid { background: var(--green-bg); color: var(--green); }
.badge-free { background: var(--blue-bg); color: var(--blue); }
.badge-trial { background: var(--yellow-bg); color: var(--yellow); }
.badge-active { background: var(--green-bg); color: var(--green); }
.badge-deactivated { background: var(--red-bg); color: var(--red); }

/* Tabs */
.tabs { display: flex; gap: 0; margin-bottom: 24px; border-bottom: 1px solid var(--border); }
.tab { padding: 10px 20px; font-size: 13px; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.15s; text-decoration: none; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-light); border-bottom-color: var(--accent); }

/* AI Usage */
.cost-highlight { font-size: 36px; font-weight: 700; color: var(--accent-light); }
.cost-highlight small { font-size: 14px; color: var(--text-muted); font-weight: 400; }
.model-breakdown { display: flex; gap: 16px; margin-top: 12px; }
.model-tag { font-size: 11px; padding: 4px 10px; background: var(--bg); border-radius: 6px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.model-tag .dot { width: 8px; height: 8px; border-radius: 50%; }

/* Live Feed */
.feed-list { max-height: 320px; overflow-y: auto; }
.feed-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.feed-icon { width: 28px; height: 28px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }
.feed-icon.ai { background: rgba(99,102,241,0.15); color: var(--accent-light); }
.feed-icon.user { background: var(--green-bg); color: var(--green); }
.feed-icon.error { background: var(--red-bg); color: var(--red); }
.feed-text { font-size: 12px; color: var(--text); line-height: 1.5; }
.feed-text .muted { color: var(--text-muted); }
.feed-time { font-size: 10px; color: var(--text-muted); margin-left: auto; white-space: nowrap; flex-shrink: 0; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Mini stat */
.mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.mini-stat { background: var(--bg); border-radius: 8px; padding: 12px 14px; }
.mini-stat .label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.mini-stat .val { font-size: 18px; font-weight: 700; margin-top: 4px; }

/* User detail card */
.user-profile { display: flex; gap: 20px; align-items: center; margin-bottom: 20px; }
.avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; color: white; }
.user-info h3 { font-size: 16px; font-weight: 600; }
.user-info p { font-size: 12px; color: var(--text-muted); }

/* Buttons */
.btn { padding: 7px 14px; border-radius: 8px; font-size: 12px; font-weight: 500; border: none; cursor: pointer; transition: all 0.15s; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-light); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.btn-outline:hover { border-color: var(--text-muted); color: var(--text); }
.btn-danger { background: var(--red-bg); color: var(--red); border: 1px solid rgba(239,68,68,0.2); }

/* Analytics grid */
.analytics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }

/* Subscription cards */
.sub-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.sub-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; text-align: center; }
.sub-card .tier { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-bottom: 8px; }
.sub-card .count { font-size: 40px; font-weight: 700; }
.sub-card .percent { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Pagination */
.pagination { display: flex; gap: 4px; justify-content: center; margin-top: 16px; }
.pagination a, .pagination span { padding: 6px 12px; border-radius: 6px; font-size: 12px; text-decoration: none; color: var(--text-muted); border: 1px solid var(--border); }
.pagination a:hover { background: var(--surface-hover); color: var(--text); }
.pagination .active { background: var(--accent); color: white; border-color: var(--accent); }
.pagination .disabled { opacity: 0.4; pointer-events: none; }

/* Login */
.login-container { display: flex; align-items: center; justify-content: center; min-height: 100vh; width: 100%; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 40px; width: 380px; }
.login-card h1 { font-size: 22px; font-weight: 700; color: var(--accent-light); margin-bottom: 4px; }
.login-card p { font-size: 13px; color: var(--text-muted); margin-bottom: 28px; }
.login-card label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; display: block; }
.login-card input { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 14px; margin-bottom: 16px; outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-card .btn-primary { width: 100%; padding: 12px; font-size: 14px; margin-top: 8px; }
.login-error { color: var(--red); font-size: 12px; margin-bottom: 16px; padding: 8px 12px; background: var(--red-bg); border-radius: 8px; }

/* Flash message */
.flash-success { color: var(--green); font-size: 12px; margin-bottom: 16px; padding: 8px 12px; background: var(--green-bg); border-radius: 8px; }

/* ═══ Timeline Intelligence ═══ */
.timeline-page { background: #0a0e27; margin: -24px -32px; padding: 24px 32px; min-height: calc(100vh - 0px); }
.timeline-page .page-header { border-bottom: 1px solid #1e2035; padding-bottom: 16px; }
.timeline-page .page-header h2 { color: #e4e4e7; }
.timeline-page .table-card { background: #111427; border-color: #1e2035; }
.timeline-page th { color: #6b7280; }
.timeline-page td { color: #e4e4e7; border-bottom-color: #1e2035; }
.timeline-page tr:hover td { background: #161938; }

.timeline-layout { display: grid; grid-template-columns: 180px 1fr 220px; gap: 16px; margin-bottom: 24px; }
.timeline-left-panel { padding-top: 40px; }
.timeline-globe-wrapper { display: flex; align-items: center; justify-content: center; min-height: 500px; }
.timeline-right-panel { padding-top: 20px; }

.timeline-stat-card { background: #111427; border: 1px solid #1e2035; border-radius: 10px; padding: 14px 16px; margin-bottom: 10px; }
.timeline-stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: #6b7280; }
.timeline-stat-value { font-size: 22px; font-weight: 700; color: #e4e4e7; margin-top: 4px; }
.timeline-stat-row { display: flex; align-items: baseline; justify-content: space-between; margin-top: 4px; }

.timeline-bottom { display: grid; grid-template-columns: 1fr 340px; gap: 16px; }

@media (max-width: 1024px) {
  .timeline-layout { grid-template-columns: 1fr; }
  .timeline-left-panel { display: none; }
  .timeline-right-panel { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .timeline-bottom { grid-template-columns: 1fr; }
}
