/* Progress & Streaks screens: progress charts, streak card, note aggregate. */

:root {
  /* Chart series palette (read by chart_controller.js at render time). */
  --series-1: #4f46e5;
  --series-2: #c2410c;
  --series-3: #0f766e;
  --series-4: #a21caf;
  --series-5: #a16207;
  --series-6: #1d4ed8;
}
:root[data-theme="dark"] {
  --series-1: #a5a6ff;
  --series-2: #fb923c;
  --series-3: #34d3b4;
  --series-4: #e879f9;
  --series-5: #facc15;
  --series-6: #60a5fa;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --series-1: #a5a6ff;
    --series-2: #fb923c;
    --series-3: #34d3b4;
    --series-4: #e879f9;
    --series-5: #facc15;
    --series-6: #60a5fa;
  }
}

/* ---- Day switcher: horizontally scrollable pill row on small screens ---- */
.progress-days { flex-wrap: nowrap; overflow-x: auto; padding-bottom: var(--space-1); scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.progress-days::-webkit-scrollbar { display: none; }
.progress-days .type-btn { flex: 0 0 auto; min-height: var(--tap); white-space: nowrap; }
@media (min-width: 720px) { .progress-days { flex-wrap: wrap; overflow: visible; } }

.stat-tile__value--sm { font-size: var(--text-xl); padding-top: 0.3rem; }
.progress-stats { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 420px) {
  .progress-stats { gap: var(--space-2); }
  .progress-stats .stat-tile { padding: var(--space-3); }
  .progress-stats .stat-tile__value { font-size: var(--text-xl); }
  .progress-stats .stat-tile__value--sm { font-size: var(--text-lg); padding-top: 0.2rem; }
  .progress-stats .stat-tile__label { font-size: 0.65rem; }
}

/* ---- Streak card ---------------------------------------------------------- */
.streak-section { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
.streak-card {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-4);
  background: linear-gradient(135deg, var(--streak-soft), var(--surface) 70%);
  border: 1px solid var(--streak);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.streak-card--idle { border-color: var(--border-strong); background: var(--surface); }
.streak-card--risk { box-shadow: 0 0 0 1px var(--streak), var(--shadow-sm); }
.streak-card__flame { font-size: 2.4rem; line-height: 1; flex: 0 0 auto; }
.streak-card__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.streak-card__title { color: var(--streak); overflow-wrap: anywhere; }
.streak-card__count { display: flex; align-items: baseline; gap: var(--space-2); flex-wrap: wrap; }
.streak-card__num { font-size: var(--text-3xl); font-weight: 800; line-height: 1; color: var(--streak); font-variant-numeric: tabular-nums; }
.streak-card__unit { font-weight: 700; }
.streak-card__meta { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; font-size: var(--text-sm); }
.streak-card__progress { display: flex; flex-direction: column; gap: var(--space-1); }
.streak-bar { height: 10px; border-radius: var(--radius-pill); background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.streak-bar__fill { height: 100%; background: var(--streak); border-radius: var(--radius-pill); transition: width 0.3s ease; }
.streak-card--done .streak-bar__fill { background: var(--success); }
.streak-card__caption { font-size: var(--text-sm); color: var(--text-muted); }
.streak-card__risk { color: var(--streak); font-weight: 700; }
.streak-card__save { align-self: flex-start; min-height: 40px; }
.streak-card--compact { padding: var(--space-3); }
.streak-card--compact .streak-card__num { font-size: var(--text-2xl); }
.streak-card--compact .streak-card__flame { font-size: 1.8rem; }

/* ---- Charts --------------------------------------------------------------- */
.chart-grid { grid-template-columns: repeat(auto-fill, minmax(min(420px, 100%), 1fr)); }
.chart-card { min-width: 0; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.chart-card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.chart-card h3 { font-size: var(--text-base); font-weight: 700; color: var(--text); margin: 0; overflow-wrap: anywhere; }
.chart-card__stats { display: flex; align-items: center; gap: var(--space-2); }
.chart-card__latest { font-size: var(--text-xl); font-weight: 800; font-variant-numeric: tabular-nums; }
.chart-canvas { position: relative; height: 240px; }
@media (max-width: 520px) { .chart-canvas { height: 220px; } }
.chart-canvas canvas { position: absolute; inset: 0; }

.chart-legend { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chart-legend:empty { display: none; }
.metric-chip {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: 40px; padding: 0.35rem 0.9rem;
  border-radius: var(--radius-pill); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text-muted);
  font: inherit; font-size: var(--text-sm); font-weight: 600; cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.metric-chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.metric-chip:hover { background: var(--surface-2); }
.metric-chip__dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; }
.metric-chip[aria-pressed="false"] .metric-chip__dot { opacity: 0.35; }

/* ---- Chart view controls (per card, device-local prefs) ------------------ */
.chart-body { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.chart-options { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); min-width: 0; }
.chart-options > summary {
  display: flex; align-items: center; gap: var(--space-2);
  min-height: 40px; padding: 0.35rem var(--space-3);
  font-size: var(--text-sm); font-weight: 600; color: var(--text-muted);
  cursor: pointer; list-style: none; border-radius: var(--radius-sm);
  overflow-wrap: anywhere;
}
.chart-options > summary::-webkit-details-marker { display: none; }
.chart-options > summary::before { content: "▸"; flex: 0 0 auto; color: var(--text-muted); transition: transform 0.15s; }
.chart-options[open] > summary::before { transform: rotate(90deg); }
.chart-options > summary:hover { color: var(--text); }
.chart-options > summary:focus-visible { outline: none; box-shadow: var(--ring); }
.chart-options__body { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-2) var(--space-3) var(--space-3); border-top: 1px solid var(--border); }
.chart-options__row { display: flex; align-items: center; gap: var(--space-2) var(--space-3); flex-wrap: wrap; min-width: 0; }
.chart-options__label { flex: 0 0 7rem; display: inline-flex; align-items: center; gap: 0.15rem; font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); }
/* ⓘ toggle for a control's hint: tap/click, no hover (touch has none). 32px hit area. */
.chart-options__info { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; width: 32px; height: 32px; margin: -6px 0; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--text-muted); font-size: var(--text-sm); line-height: 1; cursor: pointer; }
.chart-options__info:hover, .chart-options__info[aria-expanded="true"] { color: var(--accent-text); background: var(--surface-2); }
.chart-options__info:focus-visible { outline: none; box-shadow: var(--ring); }
.chart-options__row select { width: auto; flex: 1 1 10rem; max-width: 16rem; padding: 0.4rem 0.5rem; font-size: var(--text-sm); }
/* One-line muted hint under each control; wraps to its own line. */
.chart-options__hint { flex: 1 1 100%; margin: 0; font-size: var(--text-xs); line-height: 1.4; color: var(--text-muted); overflow-wrap: anywhere; }
.chart-options__check { display: inline-flex; align-items: center; gap: var(--space-2); min-height: 40px; font-size: var(--text-sm); font-weight: 600; cursor: pointer; }

/* Segmented button group (aria-pressed), same look as .theme-seg. */
.chart-seg { display: flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: var(--radius); min-width: 0; }
.chart-seg button {
  flex: 1 0 auto; min-height: 36px; padding: 0.25rem 0.7rem;
  border: 0; border-radius: var(--radius-sm); background: transparent;
  color: var(--text-muted); font: inherit; font-size: var(--text-xs); font-weight: 700; cursor: pointer;
}
.chart-seg button:hover { color: var(--text); }
.chart-seg button:focus-visible { outline: none; box-shadow: var(--ring); }
.chart-seg button[aria-pressed="true"] { background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-sm); }

/* ---- Calendar view: 7 rows (Mon–Sun) x N week columns -------------------- */
.chart-calendar { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.cal-scroll { overflow-x: auto; max-width: 100%; padding-bottom: var(--space-1); -webkit-overflow-scrolling: touch; }
.cal { --cal-cell: 13px; --cal-gap: 3px; display: inline-flex; gap: var(--space-2); }
.cal__days, .cal__grid { display: grid; grid-template-rows: repeat(7, var(--cal-cell)); gap: var(--cal-gap); }
.cal__days span { font-size: 0.625rem; line-height: var(--cal-cell); color: var(--text-muted); }
.cal__grid { grid-auto-flow: column; grid-auto-columns: var(--cal-cell); }
.cal__cell { width: var(--cal-cell); height: var(--cal-cell); border-radius: 3px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); }
.cal__cell[data-level="1"] { background: color-mix(in srgb, var(--series-1) 30%, var(--surface-2)); box-shadow: none; }
.cal__cell[data-level="2"] { background: color-mix(in srgb, var(--series-1) 55%, var(--surface-2)); box-shadow: none; }
.cal__cell[data-level="3"] { background: color-mix(in srgb, var(--series-1) 78%, var(--surface-2)); box-shadow: none; }
.cal__cell[data-level="4"] { background: var(--series-1); box-shadow: none; }

/* ---- Note-day aggregate --------------------------------------------------- */
.segmented { display: flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: var(--radius-pill); margin-bottom: var(--space-4); max-width: 360px; }
.segmented .type-btn { flex: 1; justify-content: center; border: 0; background: transparent; color: var(--text-muted); min-height: var(--tap); }
.segmented .type-btn:hover { background: transparent; color: var(--text); }
.segmented .type-btn.active { background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-sm); }
.note-group__head { font-size: var(--text-base); display: flex; align-items: baseline; gap: var(--space-2); flex-wrap: wrap; }
.note-group__count { font-weight: 400; font-size: var(--text-sm); }
.note-entry__meta { display: flex; gap: var(--space-3); align-items: baseline; font-size: var(--text-sm); }
.note-entry__open { font-weight: 600; }
.note-entry__body { margin-top: var(--space-1); overflow-wrap: anywhere; }
.note-entry__body p + p { margin-top: var(--space-2); }
