/* ============================================================
   Health dashboard styles.
   Builds on the warm-paper + dark-ink palette from site.css.
   ============================================================ */

:root {
  --h-card:        #ffffff;
  --h-card-soft:   #faf8f1;
  --h-rule:        #e6e2d8;
  --h-rule-soft:   #efebe0;
  --h-ink:         #1d1d1f;
  --h-ink-2:       #4a4a4d;
  --h-muted:       #8a8784;

  /* Accent palette — desaturated to match the paper feel. */
  --h-amber:       #b45309;
  --h-amber-soft:  #fbe7c4;
  --h-teal:        #0f766e;
  --h-teal-soft:   #ccece4;
  --h-rose:        #b91c1c;
  --h-rose-soft:   #f3d3d3;
  --h-sage:        #4d6a3a;
  --h-sage-soft:   #dde6ce;
}

/* Override the default article max-width — dashboard wants room. */
main:has(.health-dashboard) { max-width: 1200px; }
article.health-dashboard { max-width: none; }

/* ---------- Page head ---------- */
.dash-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 40px;
}
.dash-head h1 {
  font-family: var(--serif);
  font-size: 2.4rem;
  line-height: 1.15;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0 0 0.3em;
}
.dash-head .subtitle {
  color: var(--h-muted);
  font-size: 1.02rem;
  margin: 0;
  max-width: 38em;
}
.dash-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.range-switcher {
  display: inline-flex;
  background: var(--h-card);
  border: 1px solid var(--h-rule);
  border-radius: 999px;
  padding: 3px;
}
.range-btn {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 6px 14px;
  border: 0;
  background: transparent;
  color: var(--h-ink-2);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.range-btn:hover { color: var(--h-ink); }
.range-btn.active {
  background: var(--h-ink);
  color: #fff;
}

.notes-link {
  font-size: 0.85rem;
  color: var(--h-ink-2);
  text-decoration: none;
  border-bottom: 1px dashed var(--h-rule);
  padding-bottom: 1px;
}
.notes-link:hover { color: var(--h-ink); border-bottom-color: var(--h-ink); }

/* ---------- Section ---------- */
.dash-section {
  margin-bottom: 48px;
}
.dash-section-head {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin: 0 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--h-rule);
}
.dash-section-head h2 {
  font-family: var(--serif);
  font-size: 1.6rem;
  font-weight: 500;
  margin: 0;
  letter-spacing: -0.01em;
}
.dash-section-head p {
  margin: 0;
  color: var(--h-muted);
  font-size: 0.9rem;
}

/* ---------- Widget grid ---------- */
.widget-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.widget {
  background: var(--h-card);
  border: 1px solid var(--h-rule);
  border-radius: 14px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 140px;
  position: relative;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.widget:hover { border-color: #cdc7b6; }
.widget.span-2 { grid-column: span 2; }
.widget.span-3 { grid-column: span 3; }
.widget.span-4 { grid-column: span 4; }

.widget-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.widget-title {
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--h-ink-2);
}
.widget-sub,
.widget-target {
  font-size: 0.72rem;
  color: var(--h-muted);
  letter-spacing: 0.04em;
}
.widget-error {
  color: var(--h-rose);
  font-size: 0.85rem;
  padding: 8px;
}

/* Color stripes by accent (left edge marker) */
.widget::before {
  content: "";
  position: absolute;
  left: 0; top: 12px; bottom: 12px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--h-ink);
}
.widget.color-amber::before { background: var(--h-amber); }
.widget.color-teal::before  { background: var(--h-teal); }
.widget.color-rose::before  { background: var(--h-rose); }
.widget.color-sage::before  { background: var(--h-sage); }

/* ---------- stat ---------- */
.stat-body {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: auto;
}
.stat-value {
  font-family: var(--serif);
  font-size: 2.6rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--h-ink);
}
.stat-meta {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.stat-unit {
  font-size: 0.9rem;
  color: var(--h-muted);
  font-weight: 500;
}
.stat-delta {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--h-rule-soft);
  color: var(--h-ink-2);
}
.stat-delta.up   { background: #dde6ce; color: #3a5527; }
.stat-delta.down { background: #f3d3d3; color: #8a1f1f; }
.stat-delta.flat { background: var(--h-rule-soft); color: var(--h-ink-2); }

/* ---------- chart wrap (line/bar) ---------- */
.chart-wrap {
  position: relative;
  flex: 1;
  min-height: 130px;
  margin-top: 4px;
}
.widget--line, .widget--bar { min-height: 200px; }
.widget--line.span-2, .widget--bar.span-2 { min-height: 220px; }

/* ---------- consistency grid ---------- */
/* Fixed cell size (GitHub-contribution-graph style). Cells don't
   stretch to fill the widget — the widget anchors to a normal
   height and the grid sits at top-left. */
.widget--consistency { min-height: 160px; }

.consistency-grid {
  --ccell: 14px;
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, var(--ccell));
  grid-auto-columns: var(--ccell);
  gap: 3px;
  justify-content: start;
  align-content: start;
  padding: 2px 0;
}
/* Weekly cadence: fewer, larger cells in a single row. */
.consistency-grid.weekly {
  --ccell: 20px;
  grid-template-rows: var(--ccell);
  grid-auto-columns: var(--ccell);
  gap: 4px;
}
.consistency-grid .ccell {
  width: var(--ccell);
  height: var(--ccell);
  border-radius: 3px;
  background: var(--h-rule-soft);
  transition: background 0.15s;
  cursor: default;
}
.consistency-grid .ccell.miss   { background: #ece7d8; }
.consistency-grid .ccell.no-data{ background: transparent; border: 1px dashed var(--h-rule); }
.consistency-grid .ccell.done   { background: var(--h-ink); }

.widget.color-amber .ccell.done { background: var(--h-amber); }
.widget.color-teal  .ccell.done { background: var(--h-teal); }
.widget.color-rose  .ccell.done { background: var(--h-rose); }
.widget.color-sage  .ccell.done { background: var(--h-sage); }

.consistency-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--h-muted);
  margin-top: 4px;
}
.cl-cell {
  width: 11px; height: 11px; border-radius: 2px;
}
.cl-cell.cl-empty  { background: #ece7d8; }
.cl-cell.cl-filled { background: var(--h-ink); }
.widget.color-amber .cl-cell.cl-filled { background: var(--h-amber); }
.widget.color-teal  .cl-cell.cl-filled { background: var(--h-teal); }
.widget.color-rose  .cl-cell.cl-filled { background: var(--h-rose); }
.widget.color-sage  .cl-cell.cl-filled { background: var(--h-sage); }
.cl-label { margin-right: 10px; }

/* ---------- streak ---------- */
.streak-body {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
}
.streak-current {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.streak-num {
  font-family: var(--serif);
  font-size: 2.6rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.02em;
}
.streak-lbl {
  font-size: 0.78rem;
  color: var(--h-muted);
  letter-spacing: 0.04em;
}
.streak-best {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--h-ink-2);
  font-weight: 600;
}

/* ---------- category (workout mix) ---------- */
.widget--category { min-height: 160px; }
.category-bar {
  display: flex;
  width: 100%;
  height: 22px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--h-rule-soft);
  margin-top: 6px;
}
.cat-seg {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  transition: filter 0.15s;
  white-space: nowrap;
  overflow: hidden;
}
.cat-seg:hover { filter: brightness(1.08); }
.cat-empty {
  color: var(--h-muted);
  font-style: italic;
  font-size: 0.85rem;
  padding: 4px;
}
.category-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 12px;
}
.cat-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--h-ink-2);
  white-space: nowrap;
}
.cat-item.zero { opacity: 0.45; }
.cat-dot {
  width: 10px; height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
.cat-label { color: var(--h-ink-2); }
.cat-count {
  font-weight: 600;
  color: var(--h-ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cat-pct { color: var(--h-muted); font-weight: 500; margin-left: 2px; }

/* ---------- gauge ---------- */
.gauge-body { margin-top: auto; }
.gauge-value {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 8px;
}
.gauge-value span:first-child {
  font-family: var(--serif);
  font-size: 2.2rem;
  font-weight: 500;
  line-height: 1;
}
.gauge-unit {
  font-size: 0.9rem;
  color: var(--h-muted);
}
.gauge-track {
  height: 8px;
  background: var(--h-rule-soft);
  border-radius: 999px;
  overflow: hidden;
}
.gauge-fill {
  height: 100%;
  background: var(--h-ink);
  border-radius: 999px;
  transition: width 0.4s ease;
}
.widget.color-amber .gauge-fill { background: var(--h-amber); }
.widget.color-teal  .gauge-fill { background: var(--h-teal); }
.widget.color-rose  .gauge-fill { background: var(--h-rose); }
.widget.color-sage  .gauge-fill { background: var(--h-sage); }

.gauge-pct {
  font-size: 0.78rem;
  color: var(--h-muted);
  margin-top: 6px;
  font-weight: 500;
}

/* ---------- footer note ---------- */
.dash-note {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--h-rule);
  color: var(--h-muted);
  font-size: 0.82rem;
  font-style: italic;
}

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .widget-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .widget.span-3, .widget.span-4 { grid-column: span 3; }
}
@media (max-width: 820px) {
  .widget-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .widget.span-2, .widget.span-3, .widget.span-4 { grid-column: span 2; }
  .dash-head { flex-direction: column; align-items: stretch; }
  .dash-controls { align-items: flex-start; }
}
@media (max-width: 520px) {
  .widget-grid { grid-template-columns: 1fr; }
  .widget,
  .widget.span-2, .widget.span-3, .widget.span-4 { grid-column: span 1; }
}
