/* Health Agent - styles
   Design tokens follow the dataviz skill's reference palette (references/palette.md).
   Light values on :root, dark values re-declared under the OS media query AND under
   :root[data-theme="dark"] so an explicit toggle always wins over the OS setting. */

:root {
  color-scheme: light;
  --surface-page:    #f9f9f7;
  --surface-card:    #fcfcfb;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --gridline:        #e1e0d9;
  --baseline:        #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);

  --series-kcal:     #2a78d6; /* slot 1 blue */
  --series-fat:      #eb6834; /* slot 2 orange */
  --series-protein:  #1baf7a; /* slot 3 aqua */
  --series-carbs:    #eda100; /* slot 4 yellow */
  --series-fiber:    #4a3aa7; /* slot 7 violet */
  --series-weight:   #2a78d6; /* blue, sequential */
  --series-bodyfat:  #eb6834; /* orange, second sequential */

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;

  --delta-good:      #006300;
  --delta-bad:       #d03b3b;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-page:    #0d0d0d;
    --surface-card:    #1a1a19;
    --text-primary:    #ffffff;
    --text-secondary:  #c3c2b7;
    --text-muted:      #898781;
    --gridline:        #2c2c2a;
    --baseline:        #383835;
    --border:          rgba(255, 255, 255, 0.10);

    --series-kcal:     #3987e5;
    --series-fat:      #d95926;
    --series-protein:  #199e70;
    --series-carbs:    #c98500;
    --series-fiber:    #9085e9;
    --series-weight:   #3987e5;
    --series-bodyfat:  #d95926;

    --status-good:     #0ca30c;
    --status-warning:  #fab219;
    --status-serious:  #ec835a;
    --status-critical: #e66767;

    --delta-good:      #0ca30c;
    --delta-bad:       #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-page:    #0d0d0d;
  --surface-card:    #1a1a19;
  --text-primary:    #ffffff;
  --text-secondary:  #c3c2b7;
  --text-muted:      #898781;
  --gridline:        #2c2c2a;
  --baseline:        #383835;
  --border:          rgba(255, 255, 255, 0.10);

  --series-kcal:     #3987e5;
  --series-fat:      #d95926;
  --series-protein:  #199e70;
  --series-carbs:    #c98500;
  --series-fiber:    #9085e9;
  --series-weight:   #3987e5;
  --series-bodyfat:  #d95926;

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #e66767;

  --delta-good:      #0ca30c;
  --delta-bad:       #e66767;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface-page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  padding-bottom: 72px; /* clears the fixed bottom nav on phone */
}

a { color: inherit; }

header.app-header {
  padding: 16px 16px 8px;
  position: sticky;
  top: 0;
  background: var(--surface-page);
  z-index: 5;
}
header.app-header h1 {
  font-size: 18px;
  margin: 0 0 2px;
}
header.app-header .subtitle {
  color: var(--text-secondary);
  font-size: 13px;
}

.mode-banner {
  margin: 8px 16px 0;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  background: color-mix(in srgb, var(--status-warning) 18%, var(--surface-card));
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.placeholder-banner {
  margin: 12px 16px 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  background: color-mix(in srgb, var(--status-warning) 14%, var(--surface-card));
  border: 1px solid var(--border);
}
.placeholder-banner strong { color: var(--text-primary); }

main {
  padding: 12px 16px 24px;
  max-width: 720px;
  margin: 0 auto;
}

section.view { display: none; }
section.view.active { display: block; }

.card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}
.card h2 {
  font-size: 14px;
  margin: 0 0 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.card h3 {
  font-size: 13px;
  margin: 14px 0 8px;
  color: var(--text-secondary);
}

.stat-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.stat-tile {
  flex: 1 1 90px;
}
.stat-tile .value {
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: proportional-nums;
}
.stat-tile .label {
  font-size: 12px;
  color: var(--text-muted);
}
.stat-tile .delta {
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.delta.up { color: var(--delta-bad); }
.delta.down { color: var(--delta-good); }
.delta.flat { color: var(--text-muted); }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data-table th, table.data-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--gridline);
}
table.data-table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
table.data-table td.num, table.data-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.table-scroll { overflow-x: auto; }

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.status-good { background: color-mix(in srgb, var(--status-good) 20%, transparent); color: var(--status-good); }
.badge.status-warning { background: color-mix(in srgb, var(--status-warning) 25%, transparent); color: #7a5200; }
.badge.status-serious { background: color-mix(in srgb, var(--status-serious) 22%, transparent); color: #8a3410; }
.badge.status-critical { background: color-mix(in srgb, var(--status-critical) 20%, transparent); color: var(--status-critical); }
.badge.status-muted { background: color-mix(in srgb, var(--text-muted) 20%, transparent); color: var(--text-secondary); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
}
.legend .swatch {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: middle;
}

.chart-wrap svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-wrap { position: relative; }
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  opacity: 0;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  z-index: 3;
}

.excluded-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}
.excluded-note .dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--gridline);
  border: 1px solid var(--baseline);
  margin-right: 4px;
  vertical-align: middle;
}

.filter-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.filter-row button {
  font: inherit;
  font-size: 12.5px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text-secondary);
  cursor: pointer;
}
.filter-row button.active {
  background: var(--text-primary);
  color: var(--surface-page);
  border-color: var(--text-primary);
}

.tabbar-wrap {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  flex-direction: column;
  z-index: 10;
}
nav.tabbar {
  display: flex;
  background: var(--surface-card);
  border-top: 1px solid var(--border);
}
nav.tabbar button {
  flex: 1;
  font: inherit;
  font-size: 11.5px;
  padding: 9px 2px 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
nav.tabbar button.active {
  color: var(--series-kcal);
  font-weight: 600;
}

.token-gate {
  max-width: 380px;
  margin: 20vh auto 0;
  padding: 20px;
  text-align: center;
}
.token-gate input {
  width: 100%;
  padding: 10px;
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text-primary);
  margin: 10px 0;
}
.token-gate button {
  font: inherit;
  padding: 9px 16px;
  border-radius: 8px;
  border: none;
  background: var(--series-kcal);
  color: #fff;
  cursor: pointer;
}

.intervention-item {
  border-bottom: 1px solid var(--gridline);
  padding: 10px 0;
}
.intervention-item:last-child { border-bottom: none; }
.intervention-item .meta {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.intervention-item .detail { font-size: 13.5px; }
.intervention-item .wording {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--text-secondary);
  font-style: italic;
}

.empty-state {
  color: var(--text-muted);
  font-size: 13px;
  padding: 12px 0;
}

/* ---------------------------------------------------------------- Two-row nav
   Primary (large) sits above secondary (small, muted) within the fixed bottom
   wrap - .tabbar-wrap is the single fixed/bottom:0 element; both <nav>s inside it
   are laid out in normal flex-column flow, primary first. */
nav.tabbar-primary button { font-size: 12.5px; padding: 11px 2px 9px; }
nav.tabbar-secondary { border-top: 1px solid var(--gridline); }
nav.tabbar-secondary button { font-size: 10.5px; padding: 5px 2px 6px; color: var(--text-muted); }
nav.tabbar-secondary button.active { color: var(--series-kcal); font-weight: 600; }
body { padding-bottom: 96px; }

/* ---------------------------------------------------------------- Goal bars (Today) */
.goal-bar-track {
  position: relative;
  height: 18px;
  border-radius: 6px;
  background: var(--gridline);
  overflow: visible;
  margin-top: 18px;
}
.goal-bar-fill {
  height: 100%;
  border-radius: 6px 0 0 6px;
  transition: width 0.2s ease;
}
.goal-marker { position: absolute; top: -16px; bottom: 0; transform: translateX(-1px); }
.goal-marker-line { width: 2px; height: 34px; background: var(--text-primary); opacity: 0.55; }
.goal-marker-label {
  position: absolute; top: -16px; left: 50%; transform: translateX(-50%);
  font-size: 10.5px; white-space: nowrap; color: var(--text-secondary);
}
/* Two markers land within 18% of each other on narrow screens - drop the later label to a
   second row below the bar so the two never overlap. */
.goal-marker-stacked .goal-marker-label { top: 40px; }
.goal-marker.marker-red .goal-marker-line { background: var(--status-critical); }
.goal-marker.marker-orange .goal-marker-line { background: var(--status-warning); }
.goal-bar-over { font-size: 12px; color: var(--status-critical); margin-top: 4px; }
.bar-summary { font-size: 13.5px; margin-top: 10px; line-height: 1.7; }
.bar-summary strong { font-size: 15px; }
.basis-line { font-size: 12px; color: var(--text-muted); margin: 8px 0 0; }

.maintenance-override { margin-top: 10px; }
.maintenance-override label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.maintenance-override input {
  width: 140px; padding: 7px 9px; font: inherit; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-card); color: var(--text-primary);
}

.primary-btn {
  font: inherit; padding: 10px 16px; border-radius: 8px; border: none;
  background: var(--series-kcal); color: #fff; cursor: pointer; margin-top: 10px;
}
.primary-btn:disabled { opacity: 0.5; cursor: default; }

/* ---------------------------------------------------------------- Today entries */
.entry-item { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--gridline); }
.entry-item:last-child { border-bottom: none; }
.entry-time { flex: 0 0 44px; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; padding-top: 1px; }
.entry-body { flex: 1; min-width: 0; }
.entry-desc { font-size: 13.5px; }
.entry-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
#today-entries h3 { font-size: 12px; color: var(--text-secondary); margin: 12px 0 4px; text-transform: uppercase; letter-spacing: 0.03em; }

/* ---------------------------------------------------------------- Supplements */
.supplement-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--gridline); flex-wrap: wrap;
}
.supplement-item:last-child { border-bottom: none; }
.supplement-check { display: flex; align-items: center; gap: 6px; font-size: 13.5px; }
.supplement-name { font-weight: 500; }
.badge.label-needed { background: color-mix(in srgb, var(--status-warning) 25%, transparent); color: #7a5200; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper-btn {
  width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface-card); color: var(--text-primary); font: inherit; cursor: pointer;
}
.stepper-amount {
  width: 52px; text-align: center; padding: 4px; font: inherit; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface-card); color: var(--text-primary);
}
.stepper-unit { font-size: 11.5px; color: var(--text-muted); min-width: 56px; }
.selected-count { font-size: 12.5px; color: var(--text-muted); align-self: center; }

details { margin-top: 12px; }
details summary { cursor: pointer; font-size: 13px; color: var(--text-secondary); padding: 6px 0; }
.add-form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px;
}
.add-form-grid label.add-form-full { grid-column: 1 / -1; }
.add-form-grid label, .micro-grid label {
  display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--text-secondary);
}
.add-form-grid input, .micro-grid input {
  padding: 7px 9px; font: inherit; font-size: 13px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface-card); color: var(--text-primary);
}
.micro-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-top: 8px;
}
.form-error { color: var(--status-critical); font-size: 12.5px; margin-top: 6px; }

#checkin-progress { margin-top: 10px; font-size: 12.5px; }
.checkin-progress-line { padding: 3px 0; color: var(--text-secondary); }
.checkin-progress-line.error { color: var(--status-critical); }
#checkin-summary { margin-top: 12px; }
.checkin-status { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
#checkin-summary pre {
  white-space: pre-wrap; font-family: inherit; font-size: 12.5px; background: var(--surface-page);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px;
}

/* ---------------------------------------------------------------- Explore */
.chip-static { opacity: 0.5; cursor: default; }

