/* ==========================================================
   Statistics page: chart colours, page frame, toolbar, chart
   card and tooltip, options panel, overview, money flow,
   entries sheet and print.
   ========================================================== */

/* --- Chart colours ---
   Twelve categorical colours and the colours of income, spending, balance, highlight and
   "other", in both themes. They equal korAccount/Statistics/ChartColors.cs and the tokens in
   brands/koraccount; tests/brand-consistency/check.mjs keeps them so. The canvas charts read
   them through korWebInterop.statsColors; the money flow uses them directly. */
:root {
  --c-chart-1: #3370c7;
  --c-chart-2: #bb4e7f;
  --c-chart-3: #2d8949;
  --c-chart-4: #da7a3f;
  --c-chart-5: #1d97a3;
  --c-chart-6: #9e8406;
  --c-chart-7: #b15511;
  --c-chart-8: #0a4ba0;
  --c-chart-9: #766202;
  --c-chart-10: #93285c;
  --c-chart-11: #06717a;
  --c-chart-12: #03642b;
  --c-chart-income: #2d8949;
  --c-chart-expense: #3370c7;
  --c-chart-balance: #da7a3f;
  --c-chart-highlight: #1d97a3;
  --c-chart-other: #8a909c;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --c-chart-1: #70a6f5;
    --c-chart-2: #ea86af;
    --c-chart-3: #69c27e;
    --c-chart-4: #f9a870;
    --c-chart-5: #6bc8d3;
    --c-chart-6: #d6bd5c;
    --c-chart-7: #c16d39;
    --c-chart-8: #5086d6;
    --c-chart-9: #9c8520;
    --c-chart-10: #c3608a;
    --c-chart-11: #3396a0;
    --c-chart-12: #4c9a5f;
    --c-chart-income: #69c27e;
    --c-chart-expense: #70a6f5;
    --c-chart-balance: #f9a870;
    --c-chart-highlight: #6bc8d3;
    --c-chart-other: #7d8494;
  }
}

:root[data-theme="dark"] {
  --c-chart-1: #70a6f5;
  --c-chart-2: #ea86af;
  --c-chart-3: #69c27e;
  --c-chart-4: #f9a870;
  --c-chart-5: #6bc8d3;
  --c-chart-6: #d6bd5c;
  --c-chart-7: #c16d39;
  --c-chart-8: #5086d6;
  --c-chart-9: #9c8520;
  --c-chart-10: #c3608a;
  --c-chart-11: #3396a0;
  --c-chart-12: #4c9a5f;
  --c-chart-income: #69c27e;
  --c-chart-expense: #70a6f5;
  --c-chart-balance: #f9a870;
  --c-chart-highlight: #6bc8d3;
  --c-chart-other: #7d8494;
}

/* --- Page frame --- */
.stats {
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px 22px 60px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stats-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.stats-h1 {
  margin: 0;
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -.015em;
}

.stats-lead {
  margin: 3px 0 0;
  font-size: var(--fs-md);
  color: var(--c-text-3);
}

.stats-head-actions { display: flex; gap: 8px; flex: none; }

.stats-menu-anchor { position: relative; }

.stats-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
}

/* --- Chart tabs --- */
.stats-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--c-seg-bg);
  border-radius: 11px;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}

.stats-tabs::-webkit-scrollbar { display: none; }

.stats-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--c-text-3);
  text-decoration: none;
  white-space: nowrap;
  scroll-snap-align: start;
  transition: background .15s, color .15s;
}

.stats-tab:hover { color: var(--c-text); background: color-mix(in srgb, var(--c-surface) 55%, transparent); }

.stats-tab.is-active {
  background: var(--c-surface);
  color: var(--c-primary);
  box-shadow: var(--sh-sticky);
}

/* --- Toolbar --- */
.stats-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stats-period { display: flex; align-items: center; gap: 6px; }

.stats-period-btn,
.stats-filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  background: var(--c-surface);
  font: 600 var(--fs-md) var(--font-sans);
  color: var(--c-text-2);
  cursor: pointer;
  white-space: nowrap;
}

.stats-period-btn { min-width: 180px; justify-content: center; color: var(--c-text); }
.stats-period-btn:hover, .stats-filter-btn:hover { border-color: var(--c-text-4); color: var(--c-text); }
.stats-filter-btn.has-active { background: var(--c-chip-bg); border-color: var(--c-row-sel-border); color: var(--c-primary); }

.stats-period .k-icon-btn { width: 32px; height: 32px; border-radius: 8px; }

.stats-options-toggle { display: none; }

/* Segmented control, shared by the grouping and the options. */
.stats-seg {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 9px;
  background: var(--c-seg-bg);
}

.stats-seg-btn {
  padding: 5px 11px;
  border: 0;
  border-radius: 6px;
  background: none;
  font: 600 var(--fs-md) var(--font-sans);
  color: var(--c-text-3);
  cursor: pointer;
  white-space: nowrap;
}

.stats-seg-btn:hover { color: var(--c-text); }
.stats-seg-btn.is-active { background: var(--c-surface); color: var(--c-primary); box-shadow: var(--sh-sticky); }
.stats-short { display: none; }

/* Popovers below a toolbar button. */
.stats-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 101;
  width: 340px;
  max-width: calc(100vw - 32px);
  padding: 14px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-card);
  background: var(--c-surface-raised);
  box-shadow: var(--sh-menu);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stats-filter-pop { width: 380px; max-height: min(70vh, 560px); overflow-y: auto; }
.stats-pop-section { display: flex; flex-direction: column; gap: 8px; }
.stats-pop-actions { display: flex; justify-content: flex-end; }
.stats-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.stats-period-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.stats-chips, .stats-tagcloud { display: flex; flex-wrap: wrap; gap: 6px; }

.stats-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-pill);
  background: var(--c-surface);
  font: 500 var(--fs-md) var(--font-sans);
  color: var(--c-text-2);
  cursor: pointer;
}

.stats-chip:hover { border-color: var(--c-text-4); color: var(--c-text); }
.stats-chip.is-active { background: var(--c-chip-bg); border-color: var(--c-row-sel-border); color: var(--c-primary); }
.stats-chip.is-ignored { color: var(--c-text-4); text-decoration: line-through; background: var(--c-surface-2); }

.stats-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 4px;
  border: 0;
  background: none;
  font: 600 var(--fs-sm) var(--font-sans);
  color: var(--c-primary);
  cursor: pointer;
}

.stats-link:hover { text-decoration: underline; }

/* --- Body: chart and options --- */
.stats-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 14px;
  align-items: start;
}

.stats-body.is-wide { grid-template-columns: minmax(0, 1fr); }
.stats-main { min-width: 0; display: flex; flex-direction: column; gap: 14px; }

.stats-card {
  border: 1px solid var(--c-border-2);
  border-radius: 12px;
  background: var(--c-surface);
  padding: 16px 18px 14px;
  min-width: 0;
}

.stats-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.stats-card-title {
  margin: 0;
  font-size: var(--fs-base);
  font-weight: 700;
  letter-spacing: -.01em;
}

.stats-card-note { font-size: var(--fs-sm); color: var(--c-text-4); }

.stats-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 180px;
  padding: 40px 20px;
  text-align: center;
  color: var(--c-text-4);
  font-size: var(--fs-base);
}

.stats-empty.is-problem { color: var(--c-warn); }

/* --- Chart --- */
.stats-chart { display: flex; flex-direction: column; gap: 12px; }

.stats-canvas {
  position: relative;
  height: clamp(280px, 46vh, 460px);
  cursor: crosshair;
  touch-action: pan-y;
}

.stats-chart.is-pie .stats-canvas { height: clamp(260px, 40vh, 380px); cursor: pointer; }

/* LiveCharts sizes its canvas to the element around it. */
.stats-canvas > div,
.stats-canvas canvas { width: 100%; height: 100%; }

.stats-pie-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.stats-pie-total { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -.02em; }
.stats-pie-caption { font-size: var(--fs-sm); color: var(--c-text-4); }

.stats-tip {
  position: fixed;
  z-index: 120;
  min-width: 190px;
  max-width: 300px;
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: var(--c-surface-raised);
  box-shadow: var(--sh-menu);
  transform: translate(14px, -50%);
  pointer-events: none;
  font-size: var(--fs-md);
}

.stats-tip-title { font-weight: 700; margin-bottom: 6px; }
.stats-tip-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.stats-tip-name { flex: 1; color: var(--c-text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats-tip-value { font-weight: 600; }
.stats-tip-remark { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--c-border-2); color: var(--c-warn); font-size: var(--fs-sm); }
.stats-tip-hint { margin-top: 6px; font-size: var(--fs-xs); color: var(--c-text-4); }

.stats-dot {
  --dot: currentColor;
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: 3px;
  background: var(--dot);
}

.stats-dot.is-dashed { height: 3px; border-radius: 2px; }

.stats-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stats-legend.is-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}

.stats-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 5px 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  font: var(--fs-md) var(--font-sans);
  color: var(--c-text-2);
  cursor: pointer;
  text-align: left;
}

.stats-legend-item:hover { background: var(--c-row-hover); border-color: var(--c-border-2); }
.stats-legend-item.is-off { opacity: .45; }
.stats-legend-item.is-off .stats-legend-name { text-decoration: line-through; }
.stats-legend-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats-legend-value { font-weight: 600; color: var(--c-text); }
.stats-legend-share { min-width: 38px; text-align: right; color: var(--c-text-4); font-size: var(--fs-sm); }

/* --- Table under the chart --- */
.stats-table-wrap {
  margin-top: 14px;
  overflow-x: auto;
  border: 1px solid var(--c-border-2);
  border-radius: 10px;
}

.stats-table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }

.stats-table th,
.stats-table td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--c-border-2);
  white-space: nowrap;
}

.stats-table thead th {
  position: sticky;
  top: 0;
  background: var(--c-surface-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--c-text-4);
  text-align: right;
}

.stats-table thead th:first-child,
.stats-table tbody th { text-align: left; }
.stats-table tbody th { position: sticky; left: 0; background: var(--c-surface); font-weight: 500; color: var(--c-text-2); }
.stats-table td { text-align: right; }
.stats-table tbody tr:last-child > * { border-bottom: 0; }
.stats-table tbody tr:hover > * { background: var(--c-row-hover); }

/* --- Options --- */
.stats-side {
  position: sticky;
  top: 12px;
  border: 1px solid var(--c-border-2);
  border-radius: 12px;
  background: var(--c-surface);
  padding: 14px 16px 16px;
}

.stats-side-title {
  margin: 0 0 12px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--c-text-4);
}

.stats-options { display: flex; flex-direction: column; gap: 14px; }
.stats-opt-group { display: flex; flex-direction: column; gap: 7px; }
.stats-opt-label { font-size: var(--fs-sm); font-weight: 600; color: var(--c-text-2); }
.stats-opt-hint { font-size: var(--fs-sm); color: var(--c-text-4); line-height: 1.45; }
.stats-options .stats-seg { align-self: flex-start; flex-wrap: wrap; }
.stats-amount .k-input { width: 140px; }

.stats-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--fs-md);
  color: var(--c-text-2);
  cursor: pointer;
}

.stats-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }

.stats-switch-track {
  position: relative;
  width: 32px;
  height: 18px;
  flex: none;
  border-radius: 10px;
  background: var(--c-track);
  border: 1px solid var(--c-border);
  transition: background .15s, border-color .15s;
}

.stats-switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--c-surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .25);
  transition: transform .15s;
}

.stats-switch input:checked + .stats-switch-track { background: var(--c-primary); border-color: var(--c-primary); }
.stats-switch input:checked + .stats-switch-track::after { transform: translateX(14px); }
.stats-switch input:focus-visible + .stats-switch-track { box-shadow: var(--focus-ring); }

.stats-check-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stats-check-search { padding: 7px 10px; font-size: var(--fs-md); }

.stats-checklist {
  display: flex;
  flex-direction: column;
  max-height: 260px;
  overflow-y: auto;
  margin: 0 -6px;
}

.stats-check {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 6px;
  border-radius: 6px;
  font-size: var(--fs-md);
  color: var(--c-text-2);
  cursor: pointer;
}

.stats-check:hover { background: var(--c-row-hover); }
.stats-check input { accent-color: var(--c-primary); width: 15px; height: 15px; flex: none; }
.stats-check span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats-check.is-sub { padding-left: 26px; }
.stats-check.is-gathered { opacity: .5; }

/* --- Overview --- */
.ov-kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.ov-kpi {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 13px 14px;
  border: 1px solid var(--c-border-2);
  border-radius: 11px;
  background: var(--c-surface);
  font-family: var(--font-sans);
  text-align: left;
  color: var(--c-text);
}

button.ov-kpi { cursor: pointer; }
button.ov-kpi:hover { border-color: var(--c-border); box-shadow: var(--sh-sticky); }

.ov-kpi-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--c-text-4);
}

.ov-kpi-value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.ov-kpi-sub { font-size: var(--fs-sm); color: var(--c-text-4); }

.ov-meter {
  position: relative;
  height: 6px;
  margin-top: 8px;
  border-radius: 4px;
  background: var(--c-track);
}

.ov-meter-fill { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--c-warn); }
.ov-meter-fill.is-good { background: var(--c-pos); }
.ov-meter-target { position: absolute; top: -3px; width: 2px; height: 12px; border-radius: 1px; background: var(--c-text-2); }

.ov-insight {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: 0;
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--c-chip-bg);
  color: var(--c-text-2);
  font-size: var(--fs-md);
  line-height: 1.5;
}

.ov-insight .icon { flex: none; margin-top: 2px; color: var(--c-primary); }

.ov-grid {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: 14px;
}

.ov-donut .stats-legend.is-list { grid-template-columns: 1fr; max-height: 250px; overflow-y: auto; }

.ov-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.ov-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--c-border-2);
  border-radius: 11px;
  background: var(--c-surface);
}

.ov-card-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ov-card-value { font-size: var(--fs-md); color: var(--c-text-2); }
.ov-card-value small { color: var(--c-text-4); margin-left: 4px; }

.ov-heat-scale {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-xs);
  color: var(--c-text-4);
}

.ov-heat-scale i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--c-chart-expense) calc(var(--l) * 100%), var(--c-track));
}

.ov-heat-days,
.ov-heat-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 7), minmax(0, 1fr));
  gap: 5px;
}

.ov-heat-days { --cols: 7; margin-bottom: 5px; font-size: var(--fs-xs); color: var(--c-text-4); text-align: center; }
.ov-heat-grid.is-days { max-width: 520px; }

.ov-heat-cell {
  aspect-ratio: 1.6;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 4px 6px;
  border: 0;
  border-radius: 6px;
  background: color-mix(in srgb, var(--c-chart-expense) calc(var(--l, 0) * 100%), var(--c-track));
  font: 500 var(--fs-xs) var(--font-sans);
  color: var(--c-text-3);
  cursor: pointer;
}

.ov-heat-grid.is-weeks .ov-heat-cell { aspect-ratio: 2.4; }
.ov-heat-cell:hover { outline: 2px solid var(--c-text-4); outline-offset: 1px; }
.ov-heat-cell.is-pad { background: none; cursor: default; }
.ov-heat-cell.is-pad:hover { outline: 0; }

/* --- Money flow --- */
.sankey-wrap { overflow-x: auto; }
.sankey { width: 100%; height: auto; display: block; }

.sankey-link {
  fill: none;
  stroke-opacity: .34;
  transition: stroke-opacity .15s;
}

.sankey-link:hover { stroke-opacity: .55; }
.sankey-wrap.has-focus .sankey-link { stroke-opacity: .1; }
.sankey-wrap.has-focus .sankey-link.is-lit { stroke-opacity: .55; }
.sankey-wrap.has-focus .sankey-node:not(.is-lit) { opacity: .45; }

.sankey-node.can-open { cursor: pointer; }
.sankey-label { font-family: var(--font-sans); font-size: 13px; font-weight: 500; fill: var(--c-text); }
.sankey-value { font-size: 12px; font-weight: 400; fill: var(--c-text-3); font-variant-numeric: tabular-nums; }

/* On a phone the flow is drawn smaller than the screen it fills; larger type keeps it legible. */
.sankey.is-compact .sankey-label { font-size: 19px; }
.sankey.is-compact .sankey-value { font-size: 17px; }

/* --- Entries sheet --- */
.drill {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(460px, 100vw);
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: -12px 0 32px rgba(15, 23, 42, .14);
  display: none;
  flex-direction: column;
}

.drill[open] { display: flex; animation: drill-in .22s ease-out; }
.drill::backdrop { background: var(--c-overlay); }

@keyframes drill-in {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.drill-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 12px;
}

.drill-title { margin: 0; font-size: var(--fs-lg); font-weight: 700; letter-spacing: -.01em; }
.drill-sub { margin-top: 2px; font-size: var(--fs-md); color: var(--c-text-3); }

.drill-summary {
  display: flex;
  gap: 22px;
  padding: 0 18px 14px;
  border-bottom: 1px solid var(--c-border-2);
}

.drill-kpi-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--c-text-4);
}

.drill-kpi { font-size: var(--fs-lg); font-weight: 700; }
.drill-list { flex: 1; overflow-y: auto; padding: 6px 8px 20px; }

.drill-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 58px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  background: none;
  font-family: var(--font-sans);
  text-align: left;
  color: var(--c-text);
  cursor: pointer;
}

.drill-row:hover, .drill-row:focus-visible { background: var(--c-row-hover); outline: none; }
.drill-date { width: 58px; flex: none; font-size: var(--fs-sm); color: var(--c-text-3); }
.drill-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.drill-recipient { font-size: var(--fs-base); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drill-meta { font-size: var(--fs-sm); color: var(--c-text-4); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drill-amount { flex: none; font-weight: 600; }

/* --- Narrower screens --- */
@media (max-width: 1100px) {
  .stats-body { grid-template-columns: minmax(0, 1fr); }
  .stats-options-toggle { display: inline-flex; }
  .stats-side { display: none; position: static; }
  .stats-side.is-open { display: block; order: -1; }
  .stats-side.is-open .stats-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px 22px; }
  .ov-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ov-grid { grid-template-columns: minmax(0, 1fr); }
  .ov-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .stats { padding: 14px 16px 40px; gap: 12px; }
  .stats-lead { display: none; }
  .stats-head { align-items: center; }
  .stats-export-btn { padding: 7px 10px; }
  .stats-tabs { margin: 0 -16px; border-radius: 0; padding: 4px 12px; }
  .stats-period { flex: 1 1 100%; }
  .stats-period-btn { flex: 1; min-width: 0; }
  .stats-long { display: none; }
  .stats-short { display: inline; }
  .stats-card { padding: 14px 12px 12px; border-radius: 11px; }
  .stats-canvas { height: 300px; }
  .stats-pop { position: fixed; left: 16px; right: 16px; top: auto; bottom: 16px; width: auto; max-height: 75vh; overflow-y: auto; }
  .ov-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ov-kpi-value { font-size: var(--fs-xl); }
  .ov-cards { grid-template-columns: minmax(0, 1fr); }
  .drill {
    inset: auto 0 0 0;
    width: 100vw;
    height: 86dvh;
    border-left: 0;
    border-top: 1px solid var(--c-border);
    border-radius: 16px 16px 0 0;
  }
  .drill[open] { animation-name: drill-up; }
}

@keyframes drill-up {
  from { transform: translateY(32px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* --- Print: the chart and its table, without the app around them --- */
@media print {
  .rail, .mobile-header, .drawer, .stats-head-actions, .stats-tabs, .stats-toolbar, .stats-side, .stats-tip, .drill { display: none !important; }
  .shell-content { overflow: visible !important; }
  .stats { max-width: none; padding: 0; }
  .stats-body { grid-template-columns: minmax(0, 1fr); }
  .stats-card { border: 0; padding: 0; }
  .stats-canvas { height: 420px; }
  .stats-table-wrap { border: 0; overflow: visible; }
}
