/* Estadísticas. Usa las variables de app.css: el color del bebé (--accent) tiñe
   las gráficas y el tema claro/oscuro sale de prefers-color-scheme o de data-theme.
   «Mi archivo» (visor.css) usa estas mismas clases. */

.stats { display: flex; flex-direction: column; gap: 12px; padding-bottom: 16px; }
.st-period .chip { min-height: 48px; }
.st-note { font-size: 14px; text-align: center; }
.stats .notice { margin-bottom: 0; }

.st-selbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 4px 0 14px; border-radius: 14px;
  background: var(--tint);
  border: 1px solid var(--line);
  font-size: 15px; font-weight: 600;
}
.st-selbar span::first-letter { text-transform: uppercase; }

.st-card { display: flex; flex-direction: column; gap: 10px; padding: 16px 14px; min-width: 0; }
.st-head { display: flex; flex-direction: column; gap: 2px; }
.st-headsub { font-size: 14px; }
.st-sub { font-size: 15px; font-weight: 600; color: var(--muted); margin-top: 4px; }
.st-empty h2 { font-size: 19px; }

/* Cifras: media grande, rango y días debajo. */
.st-figs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.st-figs .figure { background: var(--bg); }
.st-figs .st-wide { grid-column: 1 / -1; }
.st-figs .figure-value { font-size: 22px; }
.st-figs .figure-sub { font-variant-numeric: tabular-nums; }

/* Gráficas */
.st-chart { width: 100%; min-width: 0; }
.st-chart svg { display: block; overflow: visible; font-family: inherit; -webkit-user-select: none; user-select: none; }
.st-grid { stroke: var(--line); stroke-width: 1; }
.st-grid.is-minor { stroke-dasharray: 2 3; }
.st-base { stroke: color-mix(in oklab, var(--muted) 60%, transparent); stroke-width: 1; }
.st-axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.st-axis.is-strong, .st-rowlabel.is-strong { fill: var(--ink); font-weight: 700; }
.st-rowlabel { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.st-val { fill: var(--ink); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.st-val.is-sel { font-weight: 800; }
.st-night, .st-bar { fill: var(--accent); }
.st-nap { fill: var(--nap); }
.st-zero { fill: var(--muted); }
.st-cell { fill: none; stroke: var(--line); stroke-width: 1.5; }
.st-bar.is-sel, .st-cell.is-sel { stroke: var(--ink); stroke-width: 2; }
.st-cellnum { fill: var(--on-accent); font-size: 10px; font-weight: 700; pointer-events: none; }
.is-partial { opacity: 0.55; }
.is-open { opacity: 0.7; }
/* Barras de hoy (sin terminar) y sueño en curso: más claras mezclando con blanco, no con el fondo
   (en oscuro, la transparencia sobre el fondo casi negro daba un marrón apagado). */
.st-night.is-partial, .st-bar.is-partial { opacity: 1; fill: color-mix(in oklab, var(--accent) 55%, #fff); }
.st-nap.is-partial { opacity: 1; fill: color-mix(in oklab, var(--nap) 55%, #fff); }
.st-night.is-open { opacity: 1; fill: color-mix(in oklab, var(--accent) 70%, #fff); }
.st-nap.is-open { opacity: 1; fill: color-mix(in oklab, var(--nap) 70%, #fff); }
.st-feeddot { fill: var(--ink); stroke: var(--surface); stroke-width: 1.5; }
.st-now { stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.st-mean { stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 4 4; opacity: 0.55; pointer-events: none; }
.st-sel { fill: color-mix(in oklab, var(--accent) 18%, transparent); }
.st-hit { fill: transparent; cursor: pointer; }

.st-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); }
.st-legend li { display: inline-flex; align-items: center; gap: 6px; }
.st-key { display: inline-block; width: 14px; height: 10px; border-radius: 3px; }
.st-key.st-night { background: var(--accent); }
.st-key.st-nap { background: var(--nap); }
.st-key.st-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink); }
.st-key.st-meanline { height: 0; border-top: 2px dashed var(--ink); opacity: 0.55; border-radius: 0; }

.st-readout {
  font-size: 15px; font-variant-numeric: tabular-nums;
  padding: 8px 12px; border-radius: 12px; background: var(--bg);
}
.st-readout::first-letter { text-transform: uppercase; }
.st-foot { font-size: 13px; line-height: 1.35; }
.stats > .st-foot { padding: 0 4px; }

/* Tabla equivalente */
.st-table summary {
  min-height: 44px; display: flex; align-items: center;
  color: var(--strong); font-size: 15px; cursor: pointer; list-style: none;
}
.st-table summary::-webkit-details-marker { display: none; }
.st-table summary::before { content: "▸"; display: inline-block; width: 1.1em; transition: transform 0.15s; }
.st-table[open] summary::before { transform: rotate(90deg); }
.st-scroll { overflow-x: auto; max-width: 100%; }
.st-table table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.st-table th, .st-table td { text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.st-table thead th { color: var(--muted); font-weight: 600; font-size: 13px; }
.st-table tbody th { font-weight: 600; white-space: nowrap; text-transform: capitalize; }
.st-medlist { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.st-medlist li { display: flex; flex-direction: column; padding: 6px 0; border-bottom: 1px solid var(--line); }
.st-medlist strong { text-transform: capitalize; }

/* Descargar */
.st-card > p.muted { font-size: 15px; }
.st-download { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.st-download .btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; }
.st-download small { font-size: 13px; font-weight: 400; color: var(--muted); }
.st-archive { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 100%; }
.st-archive small { font-size: 13px; font-weight: 400; line-height: 1.3; opacity: 0.85; }

/* Cargar datos (solo en la app; el visor no lo usa) */
.st-load .notice { margin: 0; display: flex; flex-direction: column; gap: 6px; color: var(--ink); }
.st-load .notice ul { margin: 0; padding-left: 20px; }
.st-load-pick { position: relative; display: flex; align-items: center; justify-content: center; width: 100%; cursor: pointer; }
.st-load-pick input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.st-load-pick:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.st-load-pick.is-disabled { opacity: 0.4; pointer-events: none; }
.st-load-error { color: var(--danger); }
.st-load-demo { color: var(--muted); font-size: 14px; }

/* Ventana ancha: todo el ancho menos los márgenes, en una rejilla de tarjetas
   (la línea de tiempo, a lo ancho). Cada tarjeta, como mucho unos 75 caracteres de texto. */
@media (min-width: 900px) {
  .stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); gap: 16px; align-items: start; }
  .stats > :not(.st-card) { grid-column: 1 / -1; }
  .stats > .st-span, .stats > .st-empty { grid-column: 1 / -1; }
  .stats > .st-period { max-width: 520px; }
  .stats > .st-foot { max-width: 75ch; }
  .st-card p, .st-card .st-foot { max-width: 75ch; }
}
