/* ==================== Statistik-vyn ==================== */

.statistik section { margin-bottom: var(--s3); }

/* ---- Filterrad (sticky under topbaren) ---- */
.filterbar {
  position: sticky; top: calc(0px - var(--s6)); /* kompenserar vyns padding så listen fäster kant i kant */ z-index: 5;
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
  background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow);
  padding: var(--s4); margin-bottom: var(--s4);
}
.filterbar .field { min-width: 160px; flex: none; }
.filterbar > .btn { flex: none; }
.filterbar-badge { align-self: center; margin-left: auto; }

/* ---- Sökbart flerval för skolor ---- */
.filterbar .school-field { position: relative; min-width: 240px; }
.multi-select-trigger {
  display: block; min-height: 40px; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.multi-select-trigger.has-selection {
  border-color: var(--cyan); background-color: var(--cyan-050);
  color: var(--cyan-deep); font-weight: 600;
}
.school-picker[hidden] { display: none; }
.school-picker {
  position: absolute; z-index: 20; top: calc(100% + 8px); left: 0;
  width: min(380px, calc(100vw - 32px)); padding: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: 0 16px 38px rgba(13, 27, 34, .18);
}
.school-picker-search .input { padding-top: 8px; padding-bottom: 8px; }
.school-picker-status {
  min-height: 18px; margin: 9px 2px 6px;
  color: var(--muted); font-size: 12px;
}
.school-option-list {
  max-height: 260px; overflow-y: auto; border: 1px solid var(--line);
  border-radius: var(--r-md); background: var(--card);
}
.school-option {
  display: flex; align-items: flex-start; gap: 10px; padding: 9px 10px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.school-option:last-child { border-bottom: 0; }
.school-option:hover { background: var(--cyan-050); }
.school-option:has(input:focus-visible) {
  outline: 2px solid var(--cyan); outline-offset: -2px;
}
.school-option input { margin-top: 3px; accent-color: var(--cyan-deep); flex: none; }
.school-option span { min-width: 0; }
.school-option strong { display: block; font-size: 13.5px; line-height: 1.35; }
.school-option small { display: block; margin-top: 2px; color: var(--muted); font-size: 11.5px; }
.school-picker-empty { padding: 22px 12px; color: var(--muted); text-align: center; font-size: 13px; }
.school-picker-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding-top: 12px;
}

/* ---- KPI-kort ---- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
}
.kpi { position: relative; overflow: hidden; padding: var(--s4) var(--s5); }
.kpi-label {
  font-size: 12.5px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 6px;
  padding-right: 44px;
}
.kpi-value { font-size: 28px; font-weight: 800; line-height: 1.15; color: var(--ink); }
.kpi-skel { display: inline-block; width: 72px; height: 24px; margin: 4px 0; }
.kpi-delta { margin-top: 8px; display: flex; align-items: center; gap: 8px; min-height: 20px; flex-wrap: wrap; }
.kpi-delta .badge .icon { --i: 12px; }
.kpi-prev { font-size: 11.5px; color: var(--grey); }
.kpi-bgicon { position: absolute; top: 10px; right: 12px; opacity: .1; color: var(--cyan-deep); pointer-events: none; }
.kpi-bgicon .icon { --i: 40px; }

/* ---- Samlad jämförelse per juridiskt kön ---- */
.gender-card { padding: var(--s4) var(--s5) var(--s5); }
.gender-skel { height: 150px; margin-top: 14px; border-radius: var(--r-md); }
.gender-scope-note {
  margin-top: 12px; padding: 9px 12px; background: var(--cyan-050);
  border-radius: var(--r-md); color: var(--muted); font-size: 12px; line-height: 1.5;
}
.gender-scope-note strong { color: var(--ink); }
.gender-table-scroll {
  overflow-x: auto; margin-top: 14px;
  border: 1px solid var(--line); border-radius: var(--r-md);
}
.gender-table {
  width: 100%; min-width: 480px; table-layout: fixed;
  border-collapse: separate; border-spacing: 0;
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.gender-table th, .gender-table td {
  padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle;
}
.gender-table thead th {
  background: var(--cyan-050); color: var(--muted); font-size: 11px;
  font-weight: 700; letter-spacing: .025em; line-height: 1.3; text-align: center;
}
.gender-table thead th:first-child { text-align: left; }
.gender-table th:first-child { width: 40%; }
.gender-table tbody th {
  background: var(--card); color: var(--ink);
  font-size: 13.5px; font-weight: 700; text-align: left;
}
.gender-table td { text-align: center; }
.gender-table tbody tr:last-child > * { border-bottom: 0; }
.gender-table tbody tr:hover > * { background-color: var(--cyan-050); }
.gender-value { display: block; color: var(--ink); font-size: 15px; line-height: 1.25; }
.gender-table td small {
  display: block; margin-top: 2px; color: var(--grey); font-size: 10.5px; font-weight: 500;
}
.gender-table-note, .gender-empty {
  color: var(--muted); font-size: 12px; line-height: 1.45;
}
.gender-table-note { margin-top: 8px; }
.gender-empty { padding: 32px 12px 22px; text-align: center; }
.gender-error { margin-top: 14px; padding: 22px; border: 1px solid var(--line); border-radius: var(--r-md); }

/* ---- Diagramrutnät ---- */
.chart-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.span-4  { grid-column: span 4; }
.span-6  { grid-column: span 6; }
.span-8  { grid-column: span 8; }
.span-12 { grid-column: span 12; }

/* ---- Diagramkort ---- */
.chart-card { padding: var(--s4) var(--s5) var(--s5); display: flex; flex-direction: column; gap: 12px; }
.chart-head { display: flex; align-items: flex-start; gap: 12px; }
.chart-titles { flex: 1; min-width: 0; }
.chart-head h3 { font-size: 14.5px; font-weight: 700; line-height: 1.3; }
.chart-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.chart-tools { display: flex; align-items: center; gap: 8px; flex: none; flex-wrap: wrap; justify-content: flex-end; }
.chart-tools .tabs { padding: 3px; }
.chart-tools .tab { padding: 4px 10px; font-size: 12.5px; }
.chart-tools .select { width: auto; min-width: 88px; padding: 6px 30px 6px 10px; font-size: 13px; }
.chart-head .btn-icon { width: 30px; height: 30px; flex: none; }

.chart-body { position: relative; height: 300px; }
.span-12 > .chart-body { height: 360px; }
.chart-body > canvas { max-width: 100%; }

.chart-state {
  position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center;
}
.chart-skel { position: absolute; inset: 0; border-radius: 12px; }
.chart-empty {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  color: var(--muted); font-size: 13.5px; text-align: center; padding: var(--s4);
}

/* ---- Statistik-chips (r, KI, p, n ...) ---- */
.stat-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.stat-chips .chip {
  font-size: 13px; font-weight: 600; color: var(--ink);
  background: var(--cyan-050); border-radius: var(--r-full); padding: 4px 12px;
}

/* ---- Stratifierade småmultiplar ---- */
.strata-row { position: absolute; inset: 0; display: flex; gap: 12px; overflow-x: auto; }
.mini-chart { flex: 1 1 0; min-width: 170px; display: flex; flex-direction: column; }
.mini-title { font-size: 12px; font-weight: 700; color: var(--muted); text-align: center; margin-bottom: 4px; }
.mini-body { position: relative; flex: 1; min-height: 0; }
.mini-none { font-size: 12.5px; color: var(--grey); text-align: center; padding-top: 40%; }
.strat-toggle.active { background: var(--cyan-100); color: var(--cyan-deep); box-shadow: var(--shadow-sm); }

/* ---- Inom samma skolor-statistik ---- */
.within-stat {
  border-top: 1px solid var(--line); padding-top: 10px;
  font-size: 12.5px; color: var(--muted); line-height: 1.5;
}
.within-stat strong { display: block; font-size: 17px; font-weight: 800; color: var(--cyan-deep); }

/* ---- Värmekarta (region x månad) ---- */
.heatmap-scroll { overflow-x: auto; padding-bottom: 4px; }
.heatmap { display: grid; gap: 3px; align-items: center; width: max-content; }
.heatmap-collabel {
  writing-mode: vertical-rl; transform: rotate(180deg);
  font-size: 10.5px; color: var(--muted); justify-self: center; padding: 2px 0;
}
.heatmap-rowlabel { font-size: 12px; color: var(--muted); padding-right: 10px; white-space: nowrap; }
.heatmap-cell { width: 22px; height: 22px; border-radius: 3px; background: var(--cyan-050); }
.heatmap-cell.none {
  background: repeating-linear-gradient(45deg, #F1F5F7 0 4px, #FAFCFD 4px 8px);
}
.heatmap-legend {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  font-size: 11.5px; color: var(--muted);
}
.heatmap-legend i {
  width: 120px; height: 8px; border-radius: var(--r-full);
  background: linear-gradient(90deg, rgba(0, 189, 250, .04), rgba(0, 189, 250, 1));
}

/* ---- Kvarhållning (mini-KPI) ---- */
.retention-grid {
  display: grid; grid-template-columns: 1fr; gap: 14px;
  align-content: center; flex: 1;
}
.mini-stat { padding: 4px 0; border-bottom: 1px solid var(--line); }
.mini-stat:last-child { border-bottom: 0; }
.mini-stat .v { font-size: 24px; font-weight: 800; color: var(--ink); line-height: 1.2; }
.mini-stat .l { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---- Region/skola-tabell ---- */
.breakdown-card { padding: var(--s4) var(--s5) var(--s5); }
.breakdown-tools { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.table-scroll {
  overflow: auto; max-height: 520px;
  border: 1px solid var(--line); border-radius: var(--r-md);
}
.breakdown-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.breakdown-table th {
  position: sticky; top: 0; z-index: 2;
  background: var(--cyan-050); color: var(--muted);
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  text-align: left; padding: 9px 12px; cursor: pointer; user-select: none;
  white-space: nowrap; border-bottom: 1px solid var(--line);
}
.breakdown-table th:hover { color: var(--cyan-deep); }
.breakdown-table th .sort-arrow { color: var(--cyan-deep); }
.breakdown-table td { padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.breakdown-table tbody tr:last-child td { border-bottom: 0; }
.breakdown-table tbody tr:hover td { background: var(--cyan-050); }
.breakdown-table th.num, .breakdown-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.breakdown-table td.supp { color: var(--grey); font-style: italic; }
.cell-bar { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.microbar {
  width: 64px; height: 6px; background: var(--cyan-050);
  border-radius: var(--r-full); overflow: hidden; flex: none;
}
.microbar i { display: block; height: 100%; background: var(--cyan); border-radius: var(--r-full); }

/* ---- "Så räknar vi" ---- */
.method-row { margin-top: 12px; }
details.method { font-size: 13px; color: var(--muted); }
details.method summary {
  cursor: pointer; color: var(--cyan-deep); font-weight: 600; font-size: 12.5px;
  list-style: none; display: inline-flex; align-items: center; gap: 8px; user-select: none;
}
details.method summary::-webkit-details-marker { display: none; }
details.method summary::before {
  content: ""; width: 6px; height: 6px; margin-top: -3px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg); transition: transform var(--t-fast); flex: none;
}
details.method[open] summary::before { transform: rotate(45deg); margin-top: -5px; }
details.method > div {
  margin-top: 8px; padding: 12px 16px; background: var(--cyan-050);
  border-radius: var(--r-md); line-height: 1.55; max-width: 860px;
}
details.method p + p { margin-top: 8px; }
details.method strong { color: var(--ink); }

/* ---- Felkort ---- */
.stat-error {
  display: flex; align-items: center; gap: 14px;
  color: var(--muted); font-size: 13.5px;
}
.stat-error.span-12 { grid-column: span 12; }

/* ---- Snurrande laddikon (presentation-knappen) ---- */
.icon.spin { animation: statSpin 1s linear infinite; }
@keyframes statSpin { to { transform: rotate(360deg); } }

/* ---- Responsivt ---- */
@media (max-width: 900px) {
  .chart-grid { grid-template-columns: 1fr; }
  .span-4, .span-6, .span-8, .span-12 { grid-column: auto; }
  .span-12 > .chart-body { height: 300px; }
  .filterbar { position: static; }
  .filterbar .field { flex: 1 1 140px; min-width: 140px; }
  .filterbar .school-field { flex-basis: 240px; min-width: 220px; }
  .filterbar-badge { margin-left: 0; }
  .chart-head { flex-wrap: wrap; }
}

@media (max-width: 560px) {
  .filterbar .school-field { flex-basis: 100%; }
  .school-picker { width: min(380px, calc(100vw - 56px)); }
  .gender-card { padding-left: var(--s4); padding-right: var(--s4); }
}

/* ============ Förklaringsfönster ("i"-knappar) ============ */
.info-btn { width: 28px; height: 28px; color: var(--grey); flex: none; }
.info-btn:hover { color: var(--cyan-deep); background: var(--cyan-050); }
.kpi .kpi-info { position: absolute; top: 8px; right: 8px; }
.kpi { position: relative; }

.explainer { max-width: 560px; }
.explainer-body { text-align: left; }
.explainer-art {
  display: flex; align-items: center; justify-content: center;
  background: var(--cyan-050); border-radius: var(--r-md);
  padding: 14px; margin-bottom: var(--s4); min-height: 150px;
}
.explainer-art svg { max-width: 100%; height: auto; }
.explainer-heading { font-size: 15.5px; margin-bottom: 8px; }
.explainer-text { font-size: 14px; line-height: 1.6; color: var(--ink); }
.explainer-text p { margin-bottom: 10px; }
.explainer-text p:last-child { margin-bottom: 0; }
.explainer-text b { color: var(--cyan-deep); }
.explainer-foot { align-items: center; justify-content: space-between; }
.explainer-dots { display: flex; gap: 7px; }
.explainer-dot {
  width: 8px; height: 8px; border-radius: 2px; background: var(--line);
  transform: rotate(45deg); cursor: pointer; transition: background var(--t-fast);
}
.explainer-dot.on { background: var(--cyan); }
