/* ── Layout ─────────────────────────────────────────────────── */
:root {
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --sidebar-bg: #1a1d23;
  --sidebar-hover: #2a2f3a;
  --sidebar-active: #0d6efd;
  --brand-color: #fff;
}

html, body { height: 100%; margin: 0; }

.app-shell {
  height: 100vh;
  overflow: hidden;
  background: #f0f2f5;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: #c9d1d9;
  height: 100vh;
  overflow-y: auto;
  transition: width 0.25s ease;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  padding: 1.1rem 1.25rem;
  font-weight: 700;
  font-size: 1rem;
  color: var(--brand-color);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar .nav-link {
  color: #8b949e;
  padding: 0.55rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  border-left: 3px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar .nav-link:hover {
  color: #fff;
  background: var(--sidebar-hover);
}

.sidebar .nav-link.active {
  color: #fff;
  background: rgba(13,110,253,0.18);
  border-left-color: var(--sidebar-active);
}

.sidebar .nav-section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6c737a;
  padding: 1rem 1.25rem 0.35rem;
}

.sidebar-footer {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: #6c737a;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6c737a;
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-dot.ok      { background: #198754; }
.status-dot.error   { background: #dc3545; }
.status-dot.loading { background: #ffc107; }

/* ── Top bar ─────────────────────────────────────────────────── */
.content-wrapper { overflow: hidden; }

.topbar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
}

/* ── Main content ─────────────────────────────────────────────── */
.main-content {
  overflow-y: auto;
}

/* ── KPI Cards ─────────────────────────────────────────────────── */
.kpi-card {
  background: #fff;
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  border: 1px solid #e5e7eb;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.kpi-card .kpi-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  color: #111827;
}

.kpi-card .kpi-label {
  font-size: 0.8rem;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.35rem;
}

.kpi-card .kpi-icon {
  font-size: 2rem;
  opacity: 0.15;
}

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  border: 1px solid #e5e7eb;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  border-radius: 10px;
}

.card-title { font-size: 0.95rem; font-weight: 600; color: #374151; }

/* ── Dashboard header ──────────────────────────────────────────── */
.dashboard-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 0.2rem;
}

/* ── Tables ────────────────────────────────────────────────────── */
.data-table { font-size: 0.875rem; }
.data-table thead th {
  background: #f9fafb;
  font-weight: 600;
  border-bottom: 2px solid #e5e7eb;
  white-space: nowrap;
}
.data-table tbody tr:hover { background: #f0f7ff; }

/* ── SQL Editor ────────────────────────────────────────────────── */
.sql-editor {
  font-family: "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
  font-size: 0.875rem;
  background: #1e2330;
  color: #e2e8f0;
  border: 1px solid #374151;
  border-radius: 6px;
  resize: vertical;
  min-height: 140px;
  width: 100%;
  padding: 0.75rem 1rem;
}
.sql-editor:focus { outline: none; border-color: #0d6efd; box-shadow: 0 0 0 2px rgba(13,110,253,0.25); }

/* ── Error / empty states ──────────────────────────────────────── */
.state-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: #9ca3af;
  text-align: center;
}
.state-block i { font-size: 2.5rem; margin-bottom: 0.75rem; }
.state-block.error { color: #dc3545; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .sidebar { position: fixed; left: -100%; transition: left 0.25s; }
  .sidebar.open { left: 0; }
}

/* ── Cohort Analysis ─────────────────────────────────────────────── */
.filter-group-label {
  font-size: 0.85rem;
  display: flex;
  align-items: center;
}

.logic-toggle {
  background: #f0f2f5;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  border: 1px solid #e5e7eb;
  white-space: nowrap;
}
.logic-toggle .form-check { margin: 0; }
.logic-toggle .form-check-label { font-size: 0.85rem; font-weight: 600; cursor: pointer; }

/* Tab card combo */
.card-tab-content {
  border-top-left-radius: 0 !important;
  border-top: none !important;
}

/* Summary bar */
.summary-bar {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 0.75rem 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.summary-pill { display: flex; flex-direction: column; }
.summary-pill-value { font-size: 1.1rem; font-weight: 700; line-height: 1.1; }
.summary-pill-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; }
.filter-desc { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* TomSelect overrides – match our card style */
.ts-wrapper.multi .ts-control { background: #fff; border-color: #dee2e6; border-radius: 6px; }
.ts-wrapper.focus .ts-control  { border-color: #0d6efd; box-shadow: 0 0 0 2px rgba(13,110,253,.2); }
.ts-dropdown {
  border-color: #dee2e6;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}
.ts-dropdown .option,
.ts-dropdown .optgroup-header {
  background: #fff;
  color: #111827;
}
.ts-dropdown .option:hover,
.ts-dropdown .option.active,
.ts-dropdown .option[aria-selected="true"].active,
.ts-dropdown [data-selectable].option:hover,
.ts-dropdown [data-selectable].option.active {
  background: #e7f1ff !important;
  color: #0b3d91 !important;
}
.ts-dropdown .option.selected,
.ts-dropdown [data-selectable].option.selected {
  background: #dbeafe;
  color: #1e3a8a;
  font-weight: 600;
}

/* ── Print / PDF ──────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, #filter-card, #btn-print, .btn { display: none !important; }
  .app-shell { display: block !important; }
  .content-wrapper { overflow: visible !important; }
  .main-content { overflow: visible !important; padding: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #dee2e6 !important; }
  .tab-pane { display: block !important; opacity: 1 !important; }
  .nav-tabs { display: none !important; }
  .card-tab-content { border: none !important; padding: 0 !important; }
}
