/* ─── Health Dashboard – CSS ─────────────────────────────────────── */

:root {
  /* Status colours */
  --health-below: #c0392b;
  --health-under: #d68910;
  --health-achieved: #1e8449;
  --health-exceptional: #4d57c8;
  --health-neutral: #92959b;
  --health-grid: rgba(101, 104, 111, 0.18);

  /* Fixed macro colours */
  --macro-protein: #4d57c8;
  --macro-carbs: #e05b9a;
  --macro-fat: #e0a020;

  /* Chart card */
  --card-bg: #ffffff;
  --card-border: rgba(0, 0, 0, 0.07);
  --card-shadow: 0 1px 4px rgba(0, 0, 0, 0.06), 0 0 0 1px var(--card-border);
  --card-radius: 8px;
}

/* ─── Base ───────────────────────────────────────────────────────── */

.health-page {
  min-height: 100vh;
}

/* Ensure hidden attribute works even when CSS sets display: flex/grid */
.health-login[hidden],
.health-app[hidden] {
  display: none !important;
}
/* ─── Shared flex helpers ────────────────────────────────────────── */

.health-controls,
.health-ranges,
.health-tabs,
.health-chart__meta,
.health-meal__heading,
.health-workout__heading,
.health-settings__actions {
  display: flex;
  align-items: center;
}

/* ─── Sign-out button (fixed top-right) ──────────────────────────── */

.health-header__actions {
  gap: 1rem;
}

.health-private-label {
  color: var(--muted);
  font-size: 0.72rem;
}

.health-text-button {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 500;
  text-decoration: none;
  transition: color 150ms ease, border-color 150ms ease;
}

.health-text-button:hover {
  color: var(--text);
  border-color: var(--text);
}

/* ─── Login ──────────────────────────────────────────────────────── */

.health-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding-block: 3rem;
}

.health-login__inner {
  width: 100%;
  max-width: 26rem;
  margin-inline: auto;
  padding-inline: var(--page-gutter);
}

.health-login__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  margin-bottom: 1.5rem;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
}

.health-login h1 {
  font-size: clamp(1.6rem, 3.5vw, 2rem);
  max-width: 18em;
}

.health-login .overline {
  margin-bottom: 0.9rem;
}

.health-login__desc {
  margin-top: 0.85rem;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.65;
}

.health-login__form {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
}

.health-login__form label,
.health-settings label {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.health-login__form > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}

.health-login input,
.health-settings input[type="number"],
.health-settings input[type="text"] {
  min-height: 2.6rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.health-login input:focus,
.health-settings input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(77, 87, 200, 0.14);
}

.health-login__form input {
  border-radius: 4px 0 0 4px;
  border-right: none;
}

.health-login__form .btn {
  border-radius: 0 4px 4px 0;
}

.health-form-message {
  min-height: 1.4rem;
  margin-top: 0.6rem;
  color: var(--health-below);
  font-size: 0.78rem;
}

/* ─── Dashboard intro banner ──────────────────────────────── */
/* (intro banner removed — tabs are now the first visible element) */

.health-freshness {
  color: var(--muted);
  font-size: 0.68rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 22rem;
}

/* ─── Sticky tab bar ─────────────────────────────────────────────── */

.health-sticky-controls {
  position: sticky;
  z-index: 90;
  top: 0;
  border-bottom: 1px solid var(--rule);
  background: rgba(247, 247, 244, 0.97);
  backdrop-filter: blur(16px);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.05);
}

.health-controls {
  min-height: 3.5rem;
  justify-content: space-between;
  gap: 1rem;
}

.health-controls__right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

/* ─── Tabs ───────────────────────────────────────────────────────── */

.health-tabs {
  min-width: 0;
  gap: clamp(0.75rem, 2vw, 1.75rem);
  overflow-x: auto;
  scrollbar-width: none;
}

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

.health-tabs button {
  position: relative;
  min-height: 3.5rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition: color 150ms ease;
}

.health-tabs button::after {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  content: "";
  transform: scaleX(0);
  transition: transform 160ms ease;
}

.health-tabs button:hover {
  color: var(--text);
}

.health-tabs button[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
}

.health-tabs button[aria-current="page"]::after {
  transform: scaleX(1);
}

/* ─── Range buttons ──────────────────────────────────────────────── */

.health-ranges {
  flex: 0 0 auto;
  gap: 0.3rem;
}

.health-ranges button {
  min-height: 1.85rem;
  padding: 0 0.65rem;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
  transition: color 140ms ease, background 140ms ease, border-color 140ms ease;
}

.health-ranges button:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.05);
}

.health-ranges button[aria-pressed="true"] {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

/* ─── Status line ────────────────────────────────────────────────── */

.health-status {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 2rem;
  padding-top: 0.75rem;
  color: var(--muted);
  font-size: 0.72rem;
}

/* Loading spinner */
.health-status:not(:empty)::before {
  content: "";
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border: 1.5px solid var(--rule-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: health-spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes health-spin {
  to { transform: rotate(360deg); }
}

/* ─── Content area ───────────────────────────────────────────────── */

.health-content {
  padding-bottom: var(--section-space);
}

/* ─── Section heading ────────────────────────────────────────────── */

.health-section-heading {
  display: grid;
  grid-template-columns: minmax(8rem, 1.5fr) minmax(0, 8.5fr);
  gap: clamp(1.5rem, 5vw, 4rem);
  padding-block: 1.25rem;
  border-bottom: 1px solid var(--text);
  margin-top: 0;
}

.health-section-heading h2 {
  font-size: clamp(1.2rem, 2vw, 1.5rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.health-section-heading p:last-child {
  max-width: 48rem;
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.6;
}

/* ─── Chart grid ─────────────────────────────────────────────────── */

.health-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  padding-block: 1.25rem 0;
}

/* ─── Chart card ─────────────────────────────────────────────────── */

.health-chart {
  min-width: 0;
  padding: clamp(1.1rem, 2.5vw, 1.75rem);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
}

/* Remove old border-based separators */
.health-chart:nth-child(odd),
.health-chart:nth-child(even) {
  padding-inline: clamp(1.1rem, 2.5vw, 1.75rem);
  border-right: 1px solid var(--card-border);
}

.health-chart--wide {
  grid-column: 1 / -1;
}

/* ─── Chart heading ──────────────────────────────────────────────── */

.health-chart__heading {
  min-height: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.health-chart__heading h3 {
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

/* ─── Chart meta chips ───────────────────────────────────────────── */

.health-chart__meta {
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  margin-top: 0;
  color: var(--muted);
  font-size: 0.7rem;
}

.health-chart__meta span {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--rule);
  line-height: 1.5;
}

/* ─── Canvas ─────────────────────────────────────────────────────── */

.health-chart__canvas {
  position: relative;
  height: 16rem;
  margin-top: 1rem;
}

.health-chart--wide .health-chart__canvas {
  height: 19rem;
}

/* ─── Chart data table (details/summary) ─────────────────────────── */

.health-chart details {
  margin-top: 1rem;
  border-top: 1px solid var(--rule);
}

.health-chart summary {
  padding-block: 0.65rem;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: color 140ms ease;
  user-select: none;
}

.health-chart summary:hover {
  color: var(--text);
}

/* ─── Data table ─────────────────────────────────────────────────── */

.health-table-wrap {
  overflow-x: auto;
  margin-top: 0.25rem;
}

.health-table {
  width: 100%;
  min-width: 34rem;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.health-table th,
.health-table td {
  padding: 0.55rem 0.85rem 0.55rem 0;
  border-top: 1px solid var(--rule);
  text-align: left;
}

.health-table th {
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.health-table tbody tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.018);
}

.health-table tbody tr:hover td {
  background: rgba(77, 87, 200, 0.04);
}

/* ─── Empty state ────────────────────────────────────────────────── */

.health-empty {
  padding: 3rem 1.5rem;
  border: 1.5px dashed var(--rule-strong);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  margin-block: 1.25rem;
}

/* ─── Day picker ─────────────────────────────────────────────────── */

.health-day-picker {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  padding-block: 1.25rem;
  border-bottom: 1px solid var(--rule);
}

.health-day-picker label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.health-day-picker input[type="date"] {
  display: block;
  margin-top: 0.35rem;
  min-height: 2.25rem;
  padding-inline: 0.65rem;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  transition: border-color 150ms ease;
}

.health-day-picker input[type="date"]:focus {
  outline: none;
  border-color: var(--accent);
}

/* ─── Detail list (meals / workouts / sleep) ─────────────────────── */

.health-detail-list {
  border-top: 1px solid var(--rule);
  margin-top: 0.5rem;
}

.health-meal,
.health-workout,
.health-sleep-record {
  padding-block: 1.25rem;
  border-bottom: 1px solid var(--rule);
}

.health-meal__heading,
.health-workout__heading {
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.65rem;
}

.health-meal__heading h3,
.health-workout__heading h3 {
  font-size: 0.92rem;
  font-weight: 600;
}

.health-meal__heading span,
.health-workout__heading span,
.health-record-meta {
  color: var(--muted);
  font-size: 0.75rem;
}

/* ─── Food list ──────────────────────────────────────────────────── */

.health-food-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.health-food-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 6rem repeat(3, auto);
  gap: 0.75rem 1.25rem;
  padding-block: 0.55rem;
  border-top: 1px solid var(--rule);
  font-size: 0.78rem;
  align-items: center;
}

.health-food-list li:hover {
  background: rgba(0, 0, 0, 0.02);
}

.health-food-list span:first-child {
  font-weight: 500;
  color: var(--text);
}

/* Calorie count — make it stand out */
.health-food-list span:nth-child(2) {
  color: var(--text);
  font-weight: 500;
  text-align: right;
}

/* Macro pills (P / C / F) */
.health-food-list span:nth-child(3),
.health-food-list span:nth-child(4),
.health-food-list span:nth-child(5) {
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 0.72rem;
}

/* ─── Settings form ──────────────────────────────────────────────── */

.health-settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem 1.5rem;
  max-width: 48rem;
  padding-block: 1.75rem;
}

.health-settings > div {
  padding: 1rem 1.1rem;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--card-bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.health-settings label {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.health-settings input[type="number"] {
  width: 100%;
  min-height: 2.4rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.health-settings input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(77, 87, 200, 0.12);
}

.health-settings__toggle {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--card-bg);
}

.health-settings__toggle input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.health-settings__toggle label {
  margin: 0;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}

.health-settings__actions {
  grid-column: 1 / -1;
  gap: 1rem;
  padding-top: 0.25rem;
}

.health-settings__actions .btn {
  min-width: 10rem;
}

/* ─── Responsive ─────────────────────────────────────────────────── */

@media (max-width: 760px) {
  .health-login {
    align-items: flex-start;
    padding-top: 4rem;
  }

  .health-controls {
    align-items: stretch;
    flex-direction: column;
    gap: 0;
    padding-block: 0.35rem;
  }

  .health-controls__right {
    border-top: 1px solid var(--rule);
    padding-block: 0.4rem;
    gap: 0.5rem;
  }

  .health-tabs {
    width: 100%;
  }

  .health-ranges {
    padding-block: 0.2rem;
  }

  .health-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .health-chart,
  .health-chart:nth-child(odd),
  .health-chart:nth-child(even) {
    padding-inline: clamp(1rem, 4vw, 1.4rem);
    border-right: 1px solid var(--card-border);
  }

  .health-section-heading {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .health-food-list li {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .health-food-list span:nth-child(3),
  .health-food-list span:nth-child(4) {
    display: none;
  }

  .health-settings {
    grid-template-columns: 1fr;
  }

  .health-settings__toggle,
  .health-settings__actions {
    grid-column: auto;
  }
}

@media (max-width: 480px) {
  .health-chart__canvas {
    height: 13rem;
  }

  .health-chart--wide .health-chart__canvas {
    height: 15rem;
  }
}
