/* SahajMobile Cascade theme, layered over Bootstrap 5.
   Design tokens switch with data-bs-theme on <html>; everything below reads tokens only.
   Chart colours live in theme.py (same values). */

/* ---------- Tokens ---------- */
html[data-bs-theme="dark"] {
  color-scheme: dark;
  --page: #0F0C14;
  --surface: #18141F;
  --surface-2: #211B2A;
  --surface-3: #2D2638;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #F2EEF5;
  --text-2: #B9B1C4;
  --muted: #8A8296;
  --accent: #E8487F;          /* rose */
  --accent-hover: #F0639A;
  --accent-soft: rgba(232, 72, 127, 0.14);
  --accent-rgb: 232, 72, 127;
  --accent-2: #7176F2;        /* indigo */
  --accent-2-soft: rgba(113, 118, 242, 0.16);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
html[data-bs-theme="light"] {
  color-scheme: light;
  --page: #F6F4F8;
  --surface: #FFFFFF;
  --surface-2: #F3EFF6;
  --surface-3: #E7E0ED;
  --border: rgba(28, 16, 40, 0.08);
  --border-strong: rgba(28, 16, 40, 0.16);
  --text: #1C1424;
  --text-2: #5B5266;
  --muted: #8C8497;
  --accent: #D6336C;
  --accent-hover: #BF2A5E;
  --accent-soft: rgba(214, 51, 108, 0.10);
  --accent-rgb: 214, 51, 108;
  --accent-2: #5C5FE0;
  --accent-2-soft: rgba(92, 95, 224, 0.12);
  --shadow: 0 1px 2px rgba(28, 16, 40, 0.05), 0 2px 10px rgba(28, 16, 40, 0.04);
}

/* Bootstrap + Dash 4 components read these */
html[data-bs-theme] {
  --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --bs-body-bg: var(--page);
  --bs-body-color: var(--text);
  --bs-emphasis-color: var(--text);
  --bs-heading-color: var(--text);
  --bs-secondary-color: var(--text-2);
  --bs-tertiary-color: var(--muted);
  --bs-border-color: var(--border);
  --bs-secondary-bg: var(--surface-2);
  --bs-tertiary-bg: var(--surface-2);
  --bs-card-bg: var(--surface);
  --bs-primary: var(--accent);
  --bs-primary-rgb: var(--accent-rgb);
  --bs-link-color: var(--accent);
  --bs-link-hover-color: var(--accent-hover);

  --Dash-Text-Strong: var(--text);
  --Dash-Text-Primary: var(--text);
  --Dash-Text-Weak: var(--text-2);
  --Dash-Text-Disabled: var(--muted);
  --Dash-Fill-Inverse-Strong: var(--surface-2);
  --Dash-Fill-Interactive-Strong: var(--accent);
  --Dash-Fill-Interactive-Weak: var(--accent-soft);
  --Dash-Fill-Primary-Hover: var(--accent-soft);
  --Dash-Fill-Primary-Active: var(--accent-soft);
  --Dash-Fill-Disabled: var(--surface-3);
  --Dash-Stroke-Weak: var(--border-strong);
  --Dash-Stroke-Strong: var(--muted);
  --Dash-Shading-Weak: rgba(0, 0, 0, 0.35);
  --Dash-Shading-Strong: rgba(0, 0, 0, 0.55);
}

body {
  background: var(--page);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Shell ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 248px; z-index: 1030;
  display: flex; flex-direction: column; gap: 4px;
  padding: 20px 14px; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; color: var(--text); text-decoration: none; }
.brand:hover { color: var(--text); }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #FFFFFF; font-weight: 700; font-size: 13px; letter-spacing: 0.02em;
}
.brand-name { font-weight: 600; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav-section { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 8px 10px 6px; }
.sidebar .nav { gap: 2px; }
.sidebar .nav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text-2); font-size: 14px; font-weight: 500;
}
.sidebar .nav-link i { font-size: 16px; color: var(--muted); }
.sidebar .nav-link:hover { background: var(--surface-2); color: var(--text); }
.sidebar .nav-link.active { background: var(--accent-soft); color: var(--accent); }
.sidebar .nav-link.active i { color: var(--accent); }

.content { margin-left: 248px; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 1020;
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 32px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--page) 82%, transparent);
  backdrop-filter: blur(10px);
}
.topbar-crumb { font-size: 13px; color: var(--muted); }
.theme-toggle .form-check { margin: 0; }
.theme-toggle .form-check-label { font-size: 13px; color: var(--text-2); }
.page { padding: 24px 32px 48px; max-width: 1640px; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.page-subtitle { font-size: 14px; color: var(--text-2); margin-top: 4px; }
.snapshot-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600;
}

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.card-body { padding: 18px 20px; }
.graph-card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.card-title-sm { font-size: 15px; font-weight: 600; margin: 0; }
.card.graph-card-transparent { background: transparent; border: 0; box-shadow: none; }
/* Fill card: sized by its neighbours; the figure is absolutely positioned so it can't stretch them */
.graph-card-fill { position: relative; height: 100%; }
.graph-card-fill .graph-fill { position: absolute; inset: 8px; }

/* ---------- Filters ---------- */
.filter-group { display: flex; flex-direction: column; gap: 6px; }
.filter-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.filter-group > :last-child { min-height: 38px; display: flex; align-items: center; }
.filter-group .form-switch { margin: 0; }
.filter-group .form-check-label { font-size: 14px; color: var(--text); }

/* Segmented control (RadioItems rendered as buttons) */
.segmented { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.segmented .form-check { margin: 0; padding: 0; min-height: 0; }
.segmented .btn-seg {
  display: inline-block; padding: 5px 12px; border-radius: 7px; cursor: pointer; user-select: none;
  font-size: 13px; font-weight: 500; color: var(--text-2); background: transparent; transition: background .15s, color .15s;
}
.segmented .btn-seg:hover { color: var(--text); }
.segmented .btn-seg.active { background: var(--accent); color: #FFFFFF; }

/* Switches: flex layout with a real gap instead of Bootstrap's negative-margin float */
.form-switch { display: flex; align-items: center; gap: 10px; padding-left: 0; min-height: 0; }
.form-switch .form-check-input { float: none; margin: 0; width: 2.25em; height: 1.25em; cursor: pointer; }
.form-switch .form-check-label { cursor: pointer; }

/* Form controls in brand colour */
.form-check-input { background-color: var(--surface-3); border-color: var(--border-strong); }
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.form-check-input:focus { border-color: var(--accent); box-shadow: 0 0 0 0.2rem var(--accent-soft); }
.form-switch .form-check-input:focus:not(:checked) { border-color: var(--border-strong); }

/* ---------- Stat tiles ---------- */
.stat { padding: 16px 18px; }
.stat-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.stat-icon {
  width: 30px; height: 30px; border-radius: 8px; flex: none; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 15px;
}
.stat-icon.alt { background: var(--accent-2-soft); color: var(--accent-2); }
.stat-label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.stat-value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; }
.stat-sub { font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.4; }

/* ---------- Tabs ---------- */
.nav-tabs { border-bottom: 1px solid var(--border); gap: 4px; }
.nav-tabs .nav-link {
  border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; border-radius: 0;
  padding: 10px 14px; color: var(--text-2); font-weight: 500; background: transparent;
}
.nav-tabs .nav-link:hover { color: var(--text); border-bottom-color: var(--border-strong); }
.nav-tabs .nav-link.active { color: var(--text); background: transparent; border-bottom-color: var(--accent); }

/* ---------- Filter card ---------- */
.filter-card { position: sticky; top: 68px; z-index: 1015; }   /* 56px topbar + 12px gap */
/* paint the gap above the stuck card with the page colour so content doesn't show through */
.filter-card::before { content: ""; position: absolute; left: -1px; right: -1px; top: -13px; height: 13px; background: var(--page); }
.filter-card .card-body { padding: 14px 18px; }
.filter-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px 24px; }
.filter-divider { width: 1px; align-self: stretch; background: var(--border); }
.filter-add { margin-left: auto; align-self: flex-end; min-width: 190px; }
.date-range { display: flex; align-items: center; gap: 8px; }
.date-range-arrow { color: var(--muted); font-size: 14px; }

/* Active categorical filters: pills on a second row */
.cat-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.cat-row:has(.cat-filters:empty) { display: none; }
.cat-filters { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }
.cat-item {
  display: flex; align-items: center; gap: 8px; padding: 3px 4px 3px 12px;
  width: 340px; max-width: 100%; flex: 0 1 auto;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
}
.cat-label { font-size: 12px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.cat-item .dash-dropdown-wrapper { flex: 1; min-width: 0; }
.cat-item .cat-values { width: 100%; }
.cat-remove { border: 0; background: transparent; color: var(--muted); padding: 4px 6px; line-height: 1; border-radius: 6px; }
.cat-remove:hover { color: var(--accent); background: var(--accent-soft); }
.cat-clear { border: 0; background: transparent; color: var(--accent); font-size: 13px; font-weight: 500; padding: 4px 8px; border-radius: 6px; white-space: nowrap; align-self: flex-start; margin-top: 6px; }
.cat-clear:hover { background: var(--accent-soft); }

/* ---------- Tab toolbar (controls that drive a whole tab) ---------- */
.tab-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
