/* BrainSpark admin — SaaS-style theme on top of Bootstrap 5.3 */
:root {
  --bs-primary: #4a3aa7;
  --bs-primary-rgb: 74, 58, 167;
  --bs-link-color: #4a3aa7;
  --bs-link-hover-color: #3a2d86;
  --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --app-bg: #f6f6f3;
  --surface: #fcfcfb;
  --sidebar-bg: #15141f;
  --sidebar-ink: #b9b7c9;
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 72px;
  --hairline: rgba(11, 11, 11, .08);
  /* chart tokens (validated reference palette, light) */
  --viz-1: #2a78d6; --viz-2: #eb6834; --viz-3: #1baf7a; --viz-4: #eda100;
  --viz-5: #e87ba4; --viz-6: #008300; --viz-7: #4a3aa7; --viz-8: #e34948;
  --viz-grid: #e1e0d9; --viz-axis: #c3c2b7; --viz-muted: #898781; --viz-ink: #52514e;
}
[data-bs-theme="dark"] {
  --bs-primary: #9085e9;
  --bs-primary-rgb: 144, 133, 233;
  --bs-link-color: #b2aaf2;
  --bs-link-hover-color: #cfc9f8;
  --bs-body-bg: #0d0d0d;
  --app-bg: #0d0d0d;
  --surface: #1a1a19;
  --sidebar-bg: #121119;
  --hairline: rgba(255, 255, 255, .09);
  --viz-1: #3987e5; --viz-2: #d95926; --viz-3: #199e70; --viz-4: #c98500;
  --viz-5: #d55181; --viz-6: #008300; --viz-7: #9085e9; --viz-8: #e66767;
  --viz-grid: #2c2c2a; --viz-axis: #383835; --viz-muted: #898781; --viz-ink: #c3c2b7;
}

body { background: var(--app-bg); }
.btn-primary { --bs-btn-bg: var(--bs-primary); --bs-btn-border-color: var(--bs-primary); --bs-btn-hover-bg: #3a2d86; --bs-btn-hover-border-color: #3a2d86; --bs-btn-active-bg: #33277a; }
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0d0d0d; --bs-btn-hover-bg: #a79ef0; --bs-btn-hover-border-color: #a79ef0; --bs-btn-hover-color: #0d0d0d; }
.text-bg-primary { background-color: var(--bs-primary) !important; }
.form-control:focus, .form-select:focus { border-color: rgba(var(--bs-primary-rgb), .6); box-shadow: 0 0 0 .2rem rgba(var(--bs-primary-rgb), .15); }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--sidebar-bg); color: var(--sidebar-ink); position: fixed; inset: 0 auto 0 0; z-index: 1040;
  display: flex; flex-direction: column; transition: width .2s ease, transform .2s ease; }
.sidebar-brand { display: flex; align-items: center; gap: .65rem; padding: 1.1rem 1.15rem; color: #fff; font-weight: 600; letter-spacing: .01em; }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #6f5ff0, #4a3aa7); color: #fff; flex: none; }
.brand-mark-lg { width: 48px; height: 48px; font-size: 1.4rem; border-radius: 14px; }
.sidebar-nav { overflow-y: auto; padding: .25rem .65rem 1.5rem; flex: 1; }
.nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #6d6a80; padding: 1rem .6rem .35rem; white-space: nowrap; }
.sidebar .nav-link { display: flex; align-items: center; gap: .75rem; color: var(--sidebar-ink); padding: .5rem .65rem; border-radius: 8px; font-size: .9rem; white-space: nowrap; }
.sidebar .nav-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; }
.sidebar .nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar .nav-link.active { background: rgba(144, 133, 233, .18); color: #fff; box-shadow: inset 3px 0 0 #9085e9; }
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; transition: margin .2s ease; }
.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
.sidebar-collapsed .sidebar .brand-text, .sidebar-collapsed .sidebar .nav-link span, .sidebar-collapsed .nav-section { display: none; }
.sidebar-collapsed .sidebar .nav-link { justify-content: center; }
.sidebar-collapsed .main { margin-left: var(--sidebar-w-collapsed); }
.sidebar-backdrop { display: none; }

.topbar { position: sticky; top: 0; z-index: 1030; display: flex; align-items: center; gap: .75rem; padding: .6rem 1.25rem;
  background: color-mix(in srgb, var(--app-bg) 85%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--hairline); }
.topbar-search { position: relative; flex: 1; max-width: 460px; }
.topbar-search i { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--bs-secondary-color); }
.topbar-search .form-control { padding-left: 2.2rem; border-radius: 10px; background: var(--surface); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .35rem; }
.btn-icon { width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; color: var(--bs-body-color); }
.btn-icon:hover { background: var(--hairline); }
.notif-dot { position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: #d03b3b; box-shadow: 0 0 0 2px var(--app-bg); }
.notif-menu { width: 340px; padding: 0; }
.notif-list { max-height: 380px; overflow-y: auto; }
.notif-item { display: flex; gap: .6rem; padding: .65rem 1rem; border-bottom: 1px solid var(--hairline); text-decoration: none; color: inherit; font-size: .85rem; }
.notif-item:hover { background: var(--hairline); }
.user-btn { display: flex; align-items: center; gap: .5rem; border: 0; padding: .25rem .5rem; border-radius: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #4a3aa7; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: .85rem; }
.content { padding: 1.5rem 1.5rem 3rem; max-width: 1600px; }

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; }
  .sidebar-open .sidebar { transform: none; }
  .sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 1035; }
  .main, .sidebar-collapsed .main { margin-left: 0; }
  .sidebar-collapsed .sidebar .brand-text, .sidebar-collapsed .sidebar .nav-link span, .sidebar-collapsed .nav-section { display: initial; }
  .content { padding: 1rem 1rem 2.5rem; }
}

/* Page header */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.35rem; font-weight: 650; margin: 0; }
.page-header .subtitle { color: var(--bs-secondary-color); font-size: .875rem; margin-top: .15rem; }

/* Cards */
.card { --bs-card-bg: var(--surface); --bs-card-border-color: var(--hairline); border-radius: 14px; box-shadow: 0 1px 2px rgba(0, 0, 0, .03); }
.card-header { background: transparent; border-bottom-color: var(--hairline); font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; padding: .85rem 1.1rem; }
.card-header .small { font-weight: 400; }
.kpi { padding: 1rem 1.1rem; height: 100%; }
.kpi-label { font-size: .78rem; color: var(--bs-secondary-color); display: flex; align-items: center; justify-content: space-between; gap: .25rem; }
.kpi-value { font-size: 1.6rem; font-weight: 650; line-height: 1.2; margin-top: .35rem; }
.kpi-sub { font-size: .76rem; color: var(--bs-secondary-color); margin-top: .2rem; }
.kpi-unavailable { font-size: .95rem; font-weight: 500; color: var(--bs-secondary-color); }
.delta-up { color: #006300; } [data-bs-theme="dark"] .delta-up { color: #0ca30c; }
.delta-down { color: #b42a2a; } [data-bs-theme="dark"] .delta-down { color: #e66767; }

.freshness { display: inline-flex; align-items: center; gap: .25rem; font-size: .68rem; font-weight: 500; padding: .1rem .45rem; border-radius: 999px; white-space: nowrap; cursor: help; }
.freshness-live { background: rgba(12, 163, 12, .12); color: #006300; }
.freshness-delayed { background: rgba(137, 135, 129, .15); color: var(--bs-secondary-color); }
.freshness-estimate { background: rgba(250, 178, 25, .18); color: #8a5a00; }
[data-bs-theme="dark"] .freshness-live { color: #0ca30c; }
[data-bs-theme="dark"] .freshness-estimate { color: #fab219; }

/* Tables */
.table { --bs-table-bg: transparent; margin-bottom: 0; font-size: .875rem; }
.table > thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--bs-secondary-color); font-weight: 600; border-bottom-color: var(--hairline); white-space: nowrap; }
.table > :not(caption) > * > * { padding: .6rem .75rem; border-bottom-color: var(--hairline); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: rgba(var(--bs-primary-rgb), .04); }
.bs-badge { font-weight: 500; font-size: .72rem; }
.bs-badge i { font-size: .7rem; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.filters .form-control, .filters .form-select { min-width: 140px; }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--bs-secondary-color); }
.empty-state > i { font-size: 2rem; display: block; margin-bottom: .5rem; opacity: .6; }
.empty-state h6 { color: var(--bs-body-color); margin-bottom: .25rem; }
.empty-state p { font-size: .85rem; max-width: 420px; margin: 0 auto .75rem; }

/* Charts */
.chart-box { position: relative; height: 260px; }
.chart-box.sm { height: 200px; }
.chart-box .chart-state { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; color: var(--bs-secondary-color); font-size: .85rem; text-align: center; }
.skeleton { background: linear-gradient(90deg, var(--hairline) 25%, transparent 50%, var(--hairline) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.kpi .skeleton { height: 30px; width: 60%; margin-top: .4rem; }

.json-editor { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; min-height: 180px; }
pre.json { font-size: .78rem; background: var(--hairline); padding: .75rem; border-radius: 8px; max-height: 360px; overflow: auto; margin: 0; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 .9rem 1.4rem; border-left: 2px solid var(--hairline); margin-left: .4rem; font-size: .85rem; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--viz-1); box-shadow: 0 0 0 2px var(--surface); }
.media-tile { border: 1px solid var(--hairline); border-radius: 10px; overflow: hidden; background: var(--surface); }
.media-tile img { width: 100%; height: 140px; object-fit: contain; background: repeating-conic-gradient(var(--hairline) 0 25%, transparent 0 50%) 50% / 16px 16px; }
.heat-cell { text-align: center; font-variant-numeric: tabular-nums; font-size: .78rem; }

/* Auth */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem;
  background: radial-gradient(1200px 600px at 10% -10%, rgba(74, 58, 167, .18), transparent), var(--app-bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--hairline); border-radius: 18px; padding: 2rem; box-shadow: 0 10px 40px rgba(0, 0, 0, .06); }
