:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-weak: #eef2ff;
  --good: #16a34a;
  --bad: #dc2626;
  --radius: 8px;
  --radius-card: 14px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .04);

  /* LazyCRM segment palette — used for entity/status badges */
  --seg-blue: #2563eb;
  --seg-green: #16a34a;
  --seg-amber: #f59e0b;
  --seg-orange: #f97316;
  --seg-red: #ef4444;
  --seg-violet: #7c3aed;
  --seg-slate: #64748b;
  --seg-gray: #9ca3af;
  --seg-sky: #0ea5e9;

  --sidebar-bg: #1a1a2e;
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #9ca3af;
  --sidebar-active: #3b82f6;
  --sidebar-hover: rgba(255, 255, 255, .08);
  --sidebar-line: rgba(255, 255, 255, .1);

  /* LazyCRM chart series palette */
  --chart-1: #2563eb;
  --chart-2: #16a34a;
  --chart-3: #f59e0b;
  --chart-4: #ef4444;
  --chart-5: #7c3aed;
  --chart-6: #0d9488;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  padding: 20px 0;
}

.sidebar .brand {
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  padding: 0 20px 16px;
  border-bottom: 1px solid var(--sidebar-line);
  margin-bottom: 12px;
}

.sidebar .group-label {
  padding: 16px 20px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--sidebar-muted);
}

.sidebar .group-label.accent {
  color: var(--good);
  font-weight: 700;
}

.sidebar .subgroup-label {
  padding: 10px 20px 2px;
  font-size: 11px;
  color: var(--sidebar-text);
}

.sidebar .subgroup-label:not(:first-of-type) {
  margin-top: 2px;
}

.sidebar a.sub-link {
  margin-left: 18px;
}

.sidebar a {
  display: block;
  margin: 2px 10px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
}

.sidebar a:hover {
  background: var(--sidebar-hover);
}

.sidebar a.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
}

.main {
  flex: 1;
  /* Без этого .main как flex-элемент растягивается по самой широкой таблице
     (min-width: auto), и вся страница уезжает за край окна. С ним широкая
     таблица прокручивается внутри своей карточки (.card overflow-x: auto). */
  min-width: 0;
  padding: 28px 36px;
  max-width: 1200px;
}

/* Ссылки в контенте — акцентным цветом темы. Без этого браузерный синий
   (#0000ee) в тёмной теме почти не виден. Стоит раньше кнопок и
   переключателей, чтобы их собственные цвета (равная специфичность, правило
   ниже по файлу) по-прежнему брали верх. */
.main a {
  color: var(--accent);
}

/* Opt-in per page (see {% block main_class %}) for tables with too many
   columns to fit comfortably in the standard 1200px column — e.g. the App
   funnel page's 10-column table. No cap at all: .main is already flex:1
   inside .shell, so this just lets it fill all remaining space next to the
   220px sidebar instead of stopping at an arbitrary width. */
.main-wide {
  max-width: none;
}

.main h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.subtitle {
  color: var(--text-muted);
  margin: 0 0 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 20px;
  margin-bottom: 20px;
  overflow-x: auto;
}

.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.entity-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 18px 20px;
}

.entity-card .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
}

.entity-card .name {
  font-weight: 600;
  font-size: 14px;
}

.entity-card .count {
  font-size: 28px;
  font-weight: 700;
  margin-top: 8px;
}

.entity-card .pct {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

th, td {
  padding: 7px 10px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

th:first-child, td:first-child {
  text-align: left;
}

thead th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

tbody tr:hover {
  background: var(--accent-weak);
}

tfoot td {
  font-weight: 700;
  border-top: 2px solid var(--border);
  border-bottom: none;
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.pill.good { background: #dcfce7; color: var(--good); }
.pill.bad { background: #fee2e2; color: var(--bad); }

/* Full-cell fill for pass/fail table cells (e.g. cohort payback) — color-mix
   over the current surface so it reads correctly in both themes without a
   separate dark override, same technique as the research article tables. */
.cell-good { background-color: color-mix(in srgb, var(--good) 16%, transparent); }
.cell-bad { background-color: color-mix(in srgb, var(--bad) 12%, transparent); }

.granularity-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

.granularity-toggle a {
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  border-right: 1px solid var(--border);
}

.granularity-toggle a:last-child { border-right: none; }

.granularity-toggle a.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.chart-legend .dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
}

form.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: end;
  margin-bottom: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}

label {
  font-size: 12px;
  color: var(--text-muted);
}

input, select, textarea {
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}

textarea {
  resize: vertical;
}

button, .btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

button.secondary, .btn.secondary {
  background: var(--surface);
  color: var(--accent);
}

.stat-row {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  min-width: 140px;
}

.stat .label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat .value {
  font-size: 22px;
  font-weight: 700;
}

.empty {
  color: var(--text-muted);
  font-style: italic;
  padding: 20px 0;
}

.segment-list a.name {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f26;
    --border: #2b2f38;
    --text: #e6e8eb;
    --text-muted: #9aa1ac;
    --accent: #6d9bff;
    --accent-weak: #1e2a45;
    --good: #4ade80;
    --bad: #f87171;
  }
  .pill.good { background: #123420; }
  .pill.bad { background: #3a1616; }
}
