/* matura.lol — Statystyka: a dense, dashboard-style query page. Borrows the
   site palette but leans observability-console: compact panels, tabular
   numbers, animated charts. The query dock floats over the bottom; the charts
   sit in an arrow carousel. */

/* Full-viewport, non-scrolling: the carousel fills the space, the dock floats. */
html,
body.stats-page { height: 100%; }
body.stats-page {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.stats-page .footer { display: none; }
.stats {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 12px 20px calc(var(--dock-h, 220px) + 14px);
}
.stats-head { flex: 0 0 auto; }
.stats-head h1 { margin: 0 0 4px; font-size: 28px; letter-spacing: -.5px; }
.stats-sub { color: var(--muted); margin: 0 0 14px; font-size: 13.5px; }

/* ---------- floating query dock ---------- */
.stats-dock {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: min(1100px, calc(100% - 24px));
  z-index: 70;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .34);
  padding: 12px;
  animation: stats-dock-in .4s cubic-bezier(.2, .8, .3, 1) backwards;
}
@keyframes stats-dock-in {
  from { opacity: 0; transform: translate(-50%, 16px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.stats-qbar { display: flex; gap: 8px; flex-wrap: wrap; }
.stats-qbar input {
  flex: 1;
  min-width: 180px;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
}
.stats-qbar input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.stats-run {
  border: 0;
  border-radius: 10px;
  padding: 11px 20px;
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease;
}
.stats-run:hover { filter: brightness(1.06); }
.stats-run:active { transform: scale(.97); }
.stats-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.stats-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
}
.stats-fields select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
}
.stats-error { color: #e5484d; font-size: 13px; margin: 10px 0 0; }
.stats-legal {
  margin: 8px 2px 0;
  font-size: 10.5px;
  color: var(--muted);
  text-align: center;
}
.stats-legal a { color: var(--muted); }

/* ---------- KPI row ---------- */
.stats-kpis { flex: 0 0 auto; display: flex; gap: 12px; flex-wrap: wrap; margin: 0 0 12px; }
.kpi {
  flex: 1 1 160px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  padding: 12px 14px;
  animation: stats-rise .4s cubic-bezier(.2, .8, .3, 1) backwards;
}
.kpi:nth-child(2) { animation-delay: .06s; }
.kpi:nth-child(3) { animation-delay: .12s; }
.kpi b {
  display: block;
  font-size: 24px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kpi span {
  color: var(--muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .9px;
}

/* ---------- carousel ---------- */
.stats-carousel { position: relative; flex: 1 1 auto; min-height: 0; width: 100%; }
.carousel-viewport { overflow: hidden; border-radius: 14px; height: 100%; }
.carousel-track {
  display: flex;
  height: 100%;
  transition: transform .45s cubic-bezier(.2, .8, .3, 1);
}
.slide {
  /* a "bento" card: narrower than the viewport so a 40px gap sits between
     adjacent cards as they slide past each other */
  flex: 0 0 calc(100% - 40px);
  min-width: calc(100% - 40px);
  margin: 0 20px;
  height: 100%;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  overflow: hidden;
}
/* each panel scrolls on its own instead of scrolling the page */
.slide > .stats-bars,
.slide > .stats-ranking,
.slide > .stats-donut,
.slide > .stats-chart,
.slide > .stats-json,
.slide > .stats-trend-table { flex: 1 1 auto; min-height: 0; overflow: auto; }
.slide > .stats-insight { flex: 0 0 auto; }
.slide > .stats-legend { flex: 0 0 auto; }
.stats-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}
.stats-ghost {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 10px;
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}
.stats-ghost:hover { border-color: var(--accent); color: var(--fg); }
.stats-empty { color: var(--muted); font-size: 13px; padding: 12px 14px; margin: 0; }

.carousel-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--fg);
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 2;
  transition: border-color .15s ease, transform .15s ease;
}
.carousel-arrow:hover { border-color: var(--accent); }
.carousel-arrow:active { transform: translateY(-50%) scale(.92); }
.carousel-arrow.prev { left: -8px; }
.carousel-arrow.next { right: -8px; }
.carousel-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}
.carousel-dot {
  width: 9px;
  height: 9px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--line);
  cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}
.carousel-dot.active { background: var(--accent); transform: scale(1.2); }

/* ---------- insight + ranking ---------- */
.stats-insight {
  padding: 16px 16px 6px;
  border-bottom: 1px solid var(--soft);
}
.insight-kicker {
  margin: 0;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}
.insight-big {
  margin: 2px 0 4px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -.5px;
  color: var(--accent);
}
.insight-sub { margin: 2px 0; font-size: 13px; color: var(--muted); }
.insight-sub b { color: var(--fg); }
.stats-ranking { padding: 12px 14px 16px; }
.rank-row {
  display: grid;
  grid-template-columns: 26px minmax(110px, 220px) 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  animation: stats-rise .35s cubic-bezier(.2, .8, .3, 1) backwards;
}
.rank-row:hover { background: var(--soft); }
.rank-num {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.rank-row:nth-child(1) .rank-num { background: var(--accent); color: #fff; }
.rank-row.top .rank-label { font-weight: 700; }
.rank-row.top .rank-num { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); }
.rank-row.top:nth-child(1) .rank-num { background: var(--accent); color: #fff; }
.rank-label { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-track { height: 10px; border-radius: 6px; background: var(--soft); overflow: hidden; }
.rank-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--accent), var(--link));
  transition: width .8s cubic-bezier(.2, .8, .3, 1);
}
.rank-val {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  min-width: 92px;
  text-align: right;
}
.rank-val small { color: var(--muted); }

/* ---------- donut ---------- */
.stats-donut { padding: 16px; }
.donut-wrap { position: relative; width: min(280px, 70%); margin: 0 auto; }
.donut { width: 100%; height: auto; display: block; }
.donut circle { transition: stroke-dasharray .8s cubic-bezier(.2, .8, .3, 1); }
.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
}
.donut-center b { font-size: 26px; font-variant-numeric: tabular-nums; }
.donut-center span {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .9px;
  color: var(--muted);
  line-height: 1.3;
}
.donut-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  justify-content: center;
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--muted);
}
.donut-leg { display: inline-flex; align-items: center; gap: 6px; }
.donut-leg small { color: var(--fg); font-variant-numeric: tabular-nums; }
.donut-leg .swatch,
.legend-item .swatch { width: 10px; height: 10px; border-radius: 3px; }

/* ---------- distribution bars ---------- */
.stats-bars { padding: 10px 14px 14px; max-height: 52vh; overflow: auto; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 220px) 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 5px 6px;
  border-radius: 8px;
  cursor: pointer;
  animation: stats-rise .35s cubic-bezier(.2, .8, .3, 1) backwards;
}
.bar-row:hover { background: var(--soft); }
.bar-label {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-track { height: 10px; border-radius: 6px; background: var(--soft); overflow: hidden; }
.bar-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--accent), var(--link));
  transition: width .7s cubic-bezier(.2, .8, .3, 1);
}
.bar-val {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  min-width: 92px;
  text-align: right;
}
.bar-val small { color: var(--muted); }

/* ---------- trend chart ---------- */
.stats-chart { padding: 10px 14px 6px; }
.stats-chart svg { width: 100%; height: auto; display: block; }
.stats-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding: 2px 14px 12px;
  font-size: 12px;
  color: var(--muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item .swatch { width: 10px; height: 10px; border-radius: 3px; }

/* ---------- JSON + tables ---------- */
.stats-json {
  margin: 0;
  padding: 14px;
  font-size: 12px;
  line-height: 1.5;
  overflow: auto;
  max-height: 52vh;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.stats-trend-table { overflow: auto; max-height: 52vh; }
.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-table th,
.stats-table td {
  text-align: right;
  padding: 6px 14px;
  border-bottom: 1px solid var(--soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stats-table th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--card); }
.stats-table th:first-child,
.stats-table td:first-child { text-align: left; }
.stats-note { color: var(--muted); font-size: 12px; margin-top: 18px; }

/* ---------- load / hover / move motion ---------- */
.stats-carousel { animation: stats-rise .5s cubic-bezier(.2, .8, .3, 1) backwards; }
.carousel-track { will-change: transform; }
/* while sliding, the incoming panel sharpens and the outgoing one fades */
.slide {
  opacity: .35;
  transform: scale(.985);
  transition: opacity .45s ease, transform .45s ease;
}
.slide.active { opacity: 1; transform: scale(1); }

.kpi { transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
.kpi:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow); }

.bar-row, .rank-row { transition: background .15s ease, transform .15s ease; }
.bar-row:hover, .rank-row:hover { background: var(--soft); transform: translateX(3px); }
.bar-fill, .rank-fill {
  transition: width .8s cubic-bezier(.2, .8, .3, 1), filter .2s ease;
}
.bar-row:hover .bar-fill,
.rank-row:hover .rank-fill { filter: brightness(1.14) saturate(1.1); }

.donut circle { transition: stroke-width .2s ease; }
.donut circle:hover { stroke-width: 33; }
.donut-leg, .legend-item { transition: color .15s ease; }
.donut-leg:hover, .legend-item:hover { color: var(--fg); }

.carousel-dot:hover { background: var(--accent); transform: scale(1.3); }
.stats-run:hover { transform: translateY(-1px); filter: brightness(1.06); }
.carousel-arrow:hover { transform: translateY(-50%) scale(1.08); }

.stats-insight { animation: stats-fade-in .5s ease backwards; }
.stats-insight .insight-big { animation: stats-fade-in .55s .05s ease backwards; }
@keyframes stats-fade-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- animation ---------- */
@keyframes stats-draw { to { stroke-dashoffset: 0; } }
@keyframes stats-pop {
  from { opacity: 0; transform: scale(.2); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes stats-rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .carousel-track,
  .slide,
  .bar-fill,
  .rank-fill { transition: none; }
  .bar-row, .rank-row, .kpi, .stats-dock, .stats-carousel { animation: none; }
  .slide { opacity: 1; transform: none; }
}
@media (max-width: 720px) {
  .stats { padding-bottom: 420px; }
  .stats-fields { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .carousel-arrow.prev { left: 2px; }
  .carousel-arrow.next { right: 2px; }
}
@media (max-width: 560px) {
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-track { grid-column: 1 / -1; order: 3; }
}
