/* Estadístiques (views/stats.js) and the chart kit (ui/charts/). DESIGN v2: few cards, sections split by
   space; inks are flat riso colours that overprint (multiply on paper, screen on the night paper). */

/* chart tokens: on the stats view (its legends sit outside the charts) and on every chart, wherever it is used */
#view[data-view="stats"], .chart {
  --chart-paper: var(--bg);
  --chart-rest: color-mix(in oklab, var(--ink) 14%, var(--bg));
  --chart-band: color-mix(in oklab, var(--ink) 7%, var(--bg));
}

/* ---------- page ---------- */
.sx-sub:empty { display: none; }
.sx-period .segmented button,
.sx-control .segmented button { min-height: 44px; }   /* 44 pt touch target (IOS-REVIEW) */
.sx-body { display: grid; gap: var(--s-10); min-width: 0; }
.sx-body > * { min-width: 0; }
.sx-section { display: grid; gap: var(--s-3); min-width: 0; }
.sx-title { font-size: var(--fs-xl); }
.sx-title:focus { outline: none; }
.sx-caption { color: var(--text-2); font-size: var(--fs-sm); text-wrap: pretty; }
.sx-sub-title { font-size: var(--fs-md); font-weight: 700; letter-spacing: -.01em; margin-top: var(--s-2); }
.sx-empty-note { color: var(--text-2); font-size: var(--fs-sm); }
.sx-lines { color: var(--text-2); font-size: var(--fs-sm); text-wrap: pretty; }
.sx-control { margin-bottom: var(--s-1); }

/* ---------- summary: the numbers are the chart ---------- */
.sx-heroes { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: var(--s-4); }
.sx-hero { display: grid; gap: 2px; align-content: start; }
.sx-hero-num { display: flex; align-items: baseline; gap: var(--s-2); }
.sx-hero-num .display { font-size: var(--fs-3xl); color: var(--ink); }
.sx-hero-unit { font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 650; color: var(--ink); }
.sx-hero-what { font-weight: 600; }
.sx-hero-note { color: var(--text-2); font-size: var(--fs-sm); }
.sx-hero:nth-child(2) .sx-hero-num .display,
.sx-hero:nth-child(2) .sx-hero-unit { color: var(--menstrual-ink); }
.sx-provisional {
  font-size: var(--fs-sm); color: var(--text);
  background: var(--luteal-soft); border-radius: var(--r-sm); padding: var(--s-2) var(--s-3);
}
.sx-provisional strong { color: var(--luteal-ink); }

/* ---------- health + last cycle (quiet bands) ---------- */
.sx-health-slot:empty { display: none; }
.sx-health-item { display: grid; gap: var(--s-2); justify-items: start; }
.sx-health-item + .sx-health-item { padding-top: var(--s-3); box-shadow: inset 0 1px 0 var(--line); }
.sx-health-note { color: var(--text-2); font-size: var(--fs-xs); }
.sx-last > div { display: flex; }

/* ---------- symptoms by phase: one band per phase ---------- */
.sx-phases { display: grid; gap: var(--s-3); }
.sx-phase {
  display: grid; gap: var(--s-2);
  padding: var(--s-4) var(--s-4) var(--s-4) var(--s-5);
  border-radius: var(--r-lg);
  background: var(--p-soft);
  box-shadow: inset 4px 0 0 var(--p);
}
.sx-phase-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; column-gap: var(--s-3); }
.sx-phase-head h3 { font-size: var(--fs-lg); }
.sx-phase-n { color: var(--text-2); font-size: var(--fs-xs); }
.sx-bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s-1); }
.sx-bar {
  display: grid; align-items: center; column-gap: var(--s-3);
  grid-template-columns: minmax(0, 1fr) clamp(56px, 28vw, 180px) 3.2em;   /* no % track: it breaks the row height of wrapped labels */
  flex: none; min-height: 28px; font-size: var(--fs-sm);
}
.sx-bar-label { overflow-wrap: anywhere; line-height: 1.25; padding: 3px 0; }
.sx-bar-track { height: 10px; border-radius: 0 4px 4px 0; background: color-mix(in oklab, var(--ink) 8%, transparent); overflow: hidden; }
.sx-bar-fill { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--p); mix-blend-mode: multiply; }
.sx-bar-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }

/* ---------- heat map selector ---------- */
.sx-heat-chips .chip { font-size: var(--fs-xs); }
/* full (8 rows): the others look quieter, and a tap on one nudges it and says why (.sx-heat-hint, #live) */
.sx-heat-chips .chip.is-blocked { opacity: .55; }
.sx-heat-chips .chip.sx-nudge { animation: sx-nudge .32s ease-out; }
@keyframes sx-nudge { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.sx-heat-hint { color: var(--text-2); font-size: var(--fs-xs); }
.sx-heat-hint:empty { display: none; }
.sx-heat-more { display: flex; }
.sx-note { color: var(--text-2); font-size: var(--fs-xs); text-wrap: pretty; }

/* ---------- compare ---------- */
.sx-compare-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: var(--s-3); }
.sx-field { display: grid; gap: var(--s-1); min-width: 0; }
.sx-field-label { font-size: var(--fs-xs); color: var(--text-2); font-weight: 600; }
.sx-select {
  appearance: none; -webkit-appearance: none;
  min-height: 44px; width: 100%; min-width: 0;
  padding: 0 var(--s-8) 0 var(--s-3);
  border: 0; border-radius: var(--r-sm);
  background: var(--surface-2) no-repeat right var(--s-3) center / 10px 6px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(-45deg, transparent 50%, var(--text-2) 50%);
  background-size: 5px 5px, 5px 5px;
  background-position: right calc(var(--s-3) + 5px) center, right var(--s-3) center;
  color: var(--ink); font: inherit; font-size: max(16px, var(--fs-sm)); font-weight: 600;   /* under 16px iOS zooms on focus */
  box-shadow: inset 0 0 0 1px var(--line);
}
.sx-compare-out { display: grid; gap: var(--s-3); }
.sx-compare-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.sx-compare-table th, .sx-compare-table td { text-align: left; vertical-align: top; padding: var(--s-2) var(--s-2) var(--s-2) 0; }
.sx-compare-table thead th { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-md); }
.sx-compare-table tbody th { color: var(--text-2); font-weight: 500; width: 36%; }
.sx-compare-table tbody tr + tr > * { box-shadow: inset 0 1px 0 var(--line); }

/* ---------- empty ---------- */
.sx-emptystate { display: grid; justify-items: start; gap: var(--s-4); padding: var(--s-4) 0; }
.sx-emptystate h2 { font-size: var(--fs-xl); }

/* =====================================================================================================
   charts (ui/charts/). Kept here because this file is the chart kit's owner; another screen that uses the
   kit gets them too (every view stylesheet is linked in index.html). Tokens only.
   ===================================================================================================== */
.chart { margin: 0; display: grid; gap: var(--s-2); min-width: 0; }
.chart-plot { position: relative; min-width: 0; }
.chart > * { min-width: 0; }   /* a wide data table scrolls inside its box, never widens the page */
.chart-svg { display: block; overflow: hidden; touch-action: pan-y; -webkit-user-select: none; user-select: none; }
.chart-svg:focus { outline: none; }
.chart-svg:focus-visible { outline: 3px solid var(--ovulation); outline-offset: 4px; border-radius: var(--r-xs); }

.chart-text { font-family: var(--font-text); font-size: var(--fs-xs); fill: var(--text-2); }
.chart-text.is-axis { font-variant-numeric: tabular-nums; }
.chart-text.is-value { fill: var(--ink); font-weight: 650; }
.chart-text.is-band { fill: var(--text-2); font-weight: 600; }

.chart-grid { stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
.chart-axis { stroke: color-mix(in oklab, var(--ink) 30%, transparent); stroke-width: 1; shape-rendering: crispEdges; }
.chart-ref { stroke: var(--ink); stroke-width: 1.25; opacity: .7; }
.chart-median { stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.chart-band { fill: var(--chart-band); }
.chart-band.is-normal { fill: var(--chart-band); }
.chart-crosshair { stroke: var(--ink); stroke-width: 1; opacity: 0; shape-rendering: crispEdges; pointer-events: none; }
.chart-crosshair.is-on { opacity: .35; }
.chart-hit { fill: transparent; }
.chart-stub { stroke: var(--text-3); stroke-width: 2; stroke-dasharray: 2 3; stroke-linecap: round; }

/* riso overprint */
.chart .riso { mix-blend-mode: multiply; }
@media (prefers-color-scheme: dark) { .chart .riso { mix-blend-mode: screen; } }

.chart-mark { transition: opacity var(--t-fast); }
.chart-mark.is-faint { opacity: .5; }
.chart-mark.is-active { stroke: var(--ink); stroke-width: 2; }
/* stacked segments: a 2 px paper gap between touching inks (drawn as a paper stroke under the fill) */
.chart-seg { stroke: var(--chart-paper); stroke-width: 4; paint-order: stroke; stroke-linejoin: round; }
.chart-row.is-open .chart-rest { fill: none; stroke-width: 1.5; stroke-dasharray: 3 3; }
.chart-row.is-faded .chart-mark, .chart-row.is-faded .chart-dot { opacity: .38; }
.chart-row.is-active .chart-rest:not([style*="stroke"]) { fill: color-mix(in oklab, var(--ink) 26%, var(--bg)); }
.chart-row.is-active .chart-text.is-axis { fill: var(--ink); font-weight: 650; }
.chart-dot { fill: var(--ink); stroke: var(--chart-paper); stroke-width: 2; paint-order: stroke; }
.chart-strike { stroke: var(--ink); stroke-width: 1.5; stroke-linecap: round; pointer-events: none; }

.chart-line { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.chart-dot-mark { stroke: var(--chart-paper); stroke-width: 2; paint-order: stroke; }
.chart-dot-mark.is-hollow { fill: var(--chart-paper); stroke-width: 2; paint-order: normal; }
.chart-dot-mark.is-active { r: 6.5; }
.chart-anchor { fill: var(--ink); opacity: 0; }
.chart-anchor.is-active { opacity: 1; stroke: var(--chart-paper); stroke-width: 2; paint-order: stroke; }

.chart-cell.is-zero { fill: none; stroke: var(--line); stroke-width: 1; }
.chart-cell.is-empty { fill: var(--text-3); opacity: .6; }
.chart-cell.is-active { stroke: var(--ink); stroke-width: 2; }
circle.chart-cell.is-active { opacity: 1; r: 3; }
.chart-cell-strong { fill: var(--chart-paper); pointer-events: none; }

/* tooltip: the value leads, the label follows */
.chart-tip {
  position: absolute; left: 0; top: 0; z-index: 2; pointer-events: none;
  max-width: min(80%, 18rem);
  display: grid; grid-template-columns: auto 1fr; column-gap: var(--s-2); align-items: center;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--ink); color: var(--bg);
  font-size: var(--fs-xs); line-height: 1.25;
  box-shadow: var(--shadow-3);
}
.chart-tip-key { grid-row: 1; width: 12px; height: 3px; border-radius: 2px; }
.chart-tip-key[hidden] { display: none; }
.chart-tip-value { grid-row: 1; font-size: var(--fs-sm); font-weight: 700; }
.chart-tip-key[hidden] + .chart-tip-value { grid-column: 1 / -1; }
.chart-tip-label { grid-column: 1 / -1; opacity: .85; }

/* legend: the key mirrors the mark */
.chart-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); font-size: var(--fs-xs); color: var(--text-2); }
.chart-legend li { display: inline-flex; align-items: center; gap: var(--s-2); min-height: 20px; }
.chart-key { flex: none; display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--key, var(--ink)); }
.chart-key.is-thin { height: 6px; }
.chart-key.is-line { width: 16px; height: 1.5px; opacity: .55; }
.chart-key.is-thick { width: 16px; height: 3px; border-radius: 2px; }
.chart-key.is-dot { width: 9px; height: 9px; border-radius: 50%; }
.chart-key.is-ring { width: 9px; height: 9px; border-radius: 50%; background: none; box-shadow: inset 0 0 0 2px var(--key, var(--ink)); }
.chart-key.is-band { width: 16px; box-shadow: inset 0 0 0 1px var(--line); }

/* heat-map scale */
.chart-scale { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1) var(--s-2); font-size: var(--fs-xs); color: var(--text-2); }
.chart-scale-steps { display: inline-flex; gap: 3px; }
.chart-scale-step { width: 18px; height: 12px; border-radius: 3px; }
.chart-scale-empty { display: inline-flex; align-items: center; gap: var(--s-1); margin-left: var(--s-2); }
.chart-scale-empty i { width: 3px; height: 3px; border-radius: 50%; background: var(--text-3); }
.chart-scale-strong { display: inline-flex; align-items: center; gap: var(--s-1); margin-left: var(--s-2); }
.chart-scale-strong i { display: inline-grid; place-items: center; width: 18px; height: 12px; border-radius: 3px; }
.chart-scale-strong b { width: 5px; height: 5px; border-radius: 50%; background: var(--chart-paper); }
.chart-key.is-strike { width: 16px; height: 8px; border-radius: 2px; background: linear-gradient(var(--ink), var(--ink)) center / 100% 1.5px no-repeat, color-mix(in oklab, var(--key, var(--ink)) 38%, var(--bg)); }

/* the data table (accessible twin) */
.chart-table summary {
  display: inline-flex; align-items: center; min-height: 44px; cursor: pointer;
  color: var(--menstrual-ink); font-size: var(--fs-sm); font-weight: 650;
  list-style: none;
}
.chart-table summary::-webkit-details-marker { display: none; }
.chart-table summary::after { content: ""; width: 7px; height: 7px; margin-left: var(--s-2); border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg) translateY(-2px); transition: transform var(--t-fast); }
.chart-table[open] summary::after { transform: rotate(-135deg) translateY(-2px); }
.chart-table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chart-table:not([open]) .chart-table-scroll { display: none; }
.chart-table table { border-collapse: collapse; font-size: var(--fs-xs); min-width: 100%; }
.chart-table th, .chart-table td { padding: 6px var(--s-3) 6px 0; text-align: left; white-space: nowrap; }
.chart-table thead th { color: var(--text-2); font-weight: 600; }
.chart-table tbody tr + tr > * { box-shadow: inset 0 1px 0 var(--line); }
.chart-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.chart-table tbody th { font-weight: 500; }

@media (prefers-reduced-motion: reduce) {
  .chart-mark, .chart-table summary::after { transition: none; }
  .sx-heat-chips .chip.sx-nudge { animation: none; }
}
@media (forced-colors: active) {
  .chart-mark, .chart-seg, .chart-dot-mark, .chart-cell { forced-color-adjust: none; }
}
@media (prefers-color-scheme: dark) { .sx-bar-fill { mix-blend-mode: screen; } }
