/* ==========================================================================
   Fuel — daily food & workout tracker
   Design: warm "fresh-kitchen" palette, Fraunces + Figtree, a time-rail signature.
   ========================================================================== */

:root {
  /* Surfaces & ink */
  --bg: #f4f6ef;
  --surface: #ffffff;
  --surface-2: #fbfbf7;
  --ink: #23261f;
  --ink-soft: #565a4e;
  --ink-faint: #8b8e81;
  --line: #e7e8df;
  --line-strong: #d9dbce;

  /* Macro hues */
  --cal: #e28a3d;
  --pro: #3e9b63;
  --carb: #d6a93c;
  --fat: #8e79a8;

  /* Extra metric hues (chart) */
  --fiber: #4a9e8f;
  --sugar: #d47ba0;
  --weight: #4f7cc4;

  /* Meal & workout hues */
  --breakfast: #e2a13d;
  --lunch: #3e9b63;
  --dinner: #8e79a8;
  --snack: #5fa3ad;
  --workout: #d9694a;

  /* Brand accent */
  --accent: #3d8f57;
  --accent-strong: #2f7345;
  --accent-ink: #ffffff;
  --warn: #cf6b4a;

  --radius: 15px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(35, 38, 31, 0.05);
  --shadow-md: 0 6px 24px -8px rgba(35, 38, 31, 0.16);
  --shadow-lg: 0 24px 60px -20px rgba(35, 38, 31, 0.32);

  --display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1c17;
    --surface: #232620;
    --surface-2: #1f2119;
    --ink: #ecefe2;
    --ink-soft: #b6b9ac;
    --ink-faint: #868a7b;
    --line: #33362c;
    --line-strong: #40443a;
    --accent: #5cb079;
    --accent-strong: #6fbf89;
    --accent-ink: #12140f;
    --shadow-md: 0 6px 24px -8px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, 0.7);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

#app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 clamp(14px, 4vw, 32px) 64px;
}

/* --- Lock screen ----------------------------------------------------------- */

.lock-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.lock-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  padding: 28px 24px;
  animation: card-in 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.lock-brand { display: flex; align-items: center; gap: 9px; justify-content: center; margin-bottom: 14px; }
.lock-note { font-size: 13.5px; color: var(--ink-soft); text-align: center; margin: 0 0 18px; line-height: 1.5; }
.lock-input {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 9px;
  padding: 11px 13px; font-size: 15px; background: var(--surface); color: var(--ink); margin-bottom: 10px;
}
.lock-remember { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft); margin: 2px 0 14px; }
.lock-remember input { width: 16px; height: 16px; accent-color: var(--accent); }
.lock-error {
  background: color-mix(in srgb, var(--warn) 12%, var(--surface));
  color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  padding: 8px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px;
}
.lock-toggle {
  display: block; width: 100%; text-align: center; background: none; border: none;
  color: var(--ink-soft); font-size: 13px; margin-top: 14px; padding: 4px; cursor: pointer;
}
.lock-toggle:hover { color: var(--accent-strong); text-decoration: underline; }

/* --- App bar --------------------------------------------------------------- */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 4px 14px;
  margin-bottom: 8px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  font-size: 20px;
  color: var(--accent);
  transform: translateY(1px);
}
.brand-name {
  font-family: var(--display);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.date-nav { display: flex; align-items: center; gap: 4px; }
.date-label {
  font-family: var(--display);
  font-size: 16px;
  font-weight: 500;
  color: var(--ink);
  background: none;
  border: none;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  min-width: 168px;
  text-align: center;
}
.date-label:hover { background: var(--surface); }

.bar-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  border: none;
  background: none;
  color: var(--ink-soft);
  font-size: 18px;
  line-height: 1;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface); color: var(--ink); }
.icon-btn.subtle { font-size: 13px; width: 26px; height: 26px; }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn:disabled:hover { background: none; color: var(--ink-soft); }

.icon-action {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; color: var(--ink-soft);
  border-radius: 8px; padding: 4px 7px;
  transition: background 0.15s, color 0.15s;
}
.icon-action:hover { background: var(--surface); color: var(--ink); }
.icon-action:disabled { opacity: 0.32; cursor: default; }
.icon-action:disabled:hover { background: none; color: var(--ink-soft); }
.icon-action svg { width: 20px; height: 20px; display: block; }
.icon-caption { font-size: 9.5px; font-weight: 600; letter-spacing: 0.02em; line-height: 1; }
@media (max-width: 600px) { .icon-caption { display: none; } }

.save-status {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-faint);
  min-width: 52px;
  text-align: right;
  transition: color 0.2s;
}
.save-status.saved { color: var(--accent); }
.save-status.error { color: var(--warn); }
@media (max-width: 560px) { .save-status { display: none; } }

/* Phones: let the top bar wrap so it fits the screen — brand + actions on the
   first row, the date navigator centered on its own row below. */
@media (max-width: 600px) {
  .app-bar { flex-wrap: wrap; gap: 8px 10px; padding-top: 12px; padding-bottom: 10px; }
  .date-nav { order: 3; flex-basis: 100%; justify-content: center; }
  .date-label { min-width: 0; }
}

/* --- Layout ---------------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.04fr);
  gap: clamp(14px, 2.4vw, 26px);
  align-items: start;
}

.col {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
}

/* --- Buttons --------------------------------------------------------------- */

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface-2);
  transition: transform 0.06s ease, background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}
.btn.primary:hover { background: var(--accent-strong); }
.btn.workout {
  background: color-mix(in srgb, var(--workout) 12%, var(--surface));
  color: var(--workout);
  border-color: color-mix(in srgb, var(--workout) 30%, transparent);
}
.btn.workout:hover { background: color-mix(in srgb, var(--workout) 18%, var(--surface)); }
.btn.ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink-soft);
}
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.copied { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line-strong)); }
.btn.danger { background: var(--warn); color: #fff; }
.btn.danger:hover { background: color-mix(in srgb, var(--warn) 88%, black); }

.confirm-message { font-size: 14px; color: var(--ink-soft); line-height: 1.5; margin: 0 0 4px; }
.btn.full { width: 100%; justify-content: center; text-align: center; margin-top: 4px; }

.link-danger {
  border: none;
  background: none;
  color: var(--warn);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 2px;
  margin-left: auto;
}
.link-danger:hover { text-decoration: underline; }

/* --- Log (left column) ----------------------------------------------------- */

.log-actions { display: flex; gap: 8px; margin-bottom: 14px; }
.log-actions .btn { flex: 1; }

.log-list { display: flex; flex-direction: column; gap: 2px; }

.log-empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--ink-faint);
}
.log-empty-title { font-family: var(--display); font-size: 18px; color: var(--ink-soft); margin: 0 0 4px; }
.log-empty-sub { margin: 0; font-size: 14px; }

.entry { border-radius: var(--radius-sm); }
.entry:hover { background: var(--surface-2); }
.entry.open { background: var(--surface-2); }

.entry-summary {
  width: 100%;
  display: grid;
  grid-template-columns: 42px 12px 1fr auto auto;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  text-align: left;
  padding: 11px 10px;
  border-radius: var(--radius-sm);
}
.entry-time { color: var(--ink-faint); font-size: 13px; font-weight: 600; }
.entry-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--dot, var(--snack));
}
.entry-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.entry-name {
  font-weight: 600; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.entry-tag {
  font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-faint); font-weight: 600;
}
.entry-cal { font-family: var(--display); font-size: 17px; font-weight: 500; }
.entry-cal-unit { font-size: 11px; color: var(--ink-faint); align-self: flex-end; padding-bottom: 3px; }

.entry-detail { display: none; padding: 0 12px 14px 64px; }
.entry.open .entry-detail { display: block; }
.entry-serving { margin: 2px 0 10px; font-size: 13px; color: var(--ink-faint); }

.macro-preview { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; color: var(--ink-soft);
  background: var(--surface); border: 1px solid var(--line);
  padding: 4px 9px 4px 8px; border-radius: var(--radius-pill);
}
.chip::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: var(--chip, var(--accent));
}
.chip b { color: var(--ink); font-weight: 700; }

.entry-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.mini-field { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--ink-faint); font-weight: 600; }
.mini-field span { text-transform: uppercase; letter-spacing: 0.05em; }
.mini {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 14px;
  background: var(--surface);
  color: var(--ink);
  width: 88px;
}
select.mini { width: 108px; }

.ex-lines { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.ex-line { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; }
.ex-line-name { font-weight: 600; }
.ex-line-detail { color: var(--ink-faint); }

/* --- Meters (arc gauges) --------------------------------------------------- */

.meters { margin-bottom: 20px; }
.meters-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
@media (max-width: 520px) { .meters-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; } }

.meter { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.arc-wrap { position: relative; width: 100%; max-width: 96px; aspect-ratio: 1; }
.arc { width: 100%; height: 100%; display: block; }
.arc-track { stroke: var(--line-strong); opacity: 0.55; }
.arc-value { transition: stroke-dasharray 0.4s ease; }
.arc-value.over { filter: saturate(1.2); }

.arc-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0;
}
.arc-value-num { font-family: var(--display); font-size: 20px; font-weight: 600; line-height: 1; }
.arc-target { font-size: 10.5px; color: var(--ink-faint); margin-top: 2px; }

.meter-cap { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.meter-label { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.meter-pct { font-size: 11.5px; color: var(--ink-faint); font-weight: 600; }
.meter-pct.over { color: var(--warn); }
.meter-pct.muted { color: var(--ink-faint); font-weight: 500; }

/* --- Trend chart ----------------------------------------------------------- */

.timeline-slot { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }

.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.chart-title { font-family: var(--display); font-size: 18px; font-weight: 600; margin: 0; }

/* Metrics dropdown */
.metric-dropdown { position: relative; }
.metric-btn {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink-soft);
  font-size: 13px; font-weight: 600; padding: 6px 10px;
}
.metric-btn:hover { background: var(--surface-2); color: var(--ink); }
.metric-count { color: var(--accent); font-weight: 700; }
.metric-count:empty { display: none; }
.caret { font-size: 11px; color: var(--ink-faint); }

.metric-panel {
  display: none;
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  min-width: 220px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  padding: 6px;
}
.metric-dropdown.open .metric-panel { display: block; }
.metric-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 8px; cursor: pointer;
}
.metric-row:hover { background: var(--surface-2); }
.metric-row input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); }
.metric-row-label { font-size: 13.5px; font-weight: 600; flex: 1; }
.metric-row-avg { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-faint); }
.smooth-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.smooth-input {
  width: 42px; text-align: center;
  border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 3px 4px; font-size: 12px;
  background: var(--surface); color: var(--ink);
}

/* Read-only legend of active lines */
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; min-height: 18px; }
.legend-static { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; }
.legend-hint { font-size: 12.5px; color: var(--ink-faint); }
.legend-avg {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--ink-faint); background: var(--surface-2);
  padding: 1px 6px; border-radius: var(--radius-pill);
}
.legend-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dot); }
.legend-label { font-weight: 600; }
.legend-val { color: var(--ink-faint); font-weight: 600; }

.chart-plot { position: relative; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-axis { stroke: var(--line); stroke-width: 1; }
.chart-line { stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart-pt { stroke: var(--surface); stroke-width: 1; }
.chart-guide { stroke: var(--ink-faint); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.6; }

.chart-empty { color: var(--ink-faint); font-size: 13px; padding: 28px 8px; text-align: center; }

.chart-tip {
  position: absolute; top: 0;
  transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 9px; box-shadow: var(--shadow-md);
  padding: 8px 10px; font-size: 12px; white-space: nowrap;
  pointer-events: none; z-index: 3;
}
.chart-tip.flip { transform: translateX(-100%); }
.tip-date { font-weight: 700; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 7px; }
.tip-row + .tip-row { margin-top: 2px; }
.tip-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dot); }
.tip-label { color: var(--ink-soft); margin-right: 14px; }
.tip-val { font-weight: 700; margin-left: auto; }

/* --- Time-rail ------------------------------------------------------------- */

.rail-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.rail-title { font-family: var(--display); font-size: 18px; font-weight: 600; margin: 0; }
.rail-sub { font-size: 13px; color: var(--ink-faint); }

.rail { position: relative; padding-left: 6px; }
.rail-line {
  position: absolute;
  left: 12px; top: 6px; bottom: 6px;
  width: 2px;
  border-radius: 2px;
  background: linear-gradient(
    to bottom,
    color-mix(in srgb, var(--breakfast) 55%, var(--line)) 0%,
    color-mix(in srgb, var(--lunch) 45%, var(--line)) 40%,
    color-mix(in srgb, var(--dinner) 50%, var(--line)) 100%
  );
}

.rail-nodes { display: flex; flex-direction: column; gap: 12px; }
.rail-node { position: relative; display: grid; grid-template-columns: 26px 1fr; align-items: start; }
.rail-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--dot, var(--snack));
  margin-top: 12px;
  margin-left: 1px;
  box-shadow: 0 0 0 4px var(--surface);
  z-index: 1;
}

.rail-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}
.rail-card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.rail-time { font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.rail-tag {
  font-size: 10px; letter-spacing: 0.05em; text-transform: uppercase; font-weight: 700;
  color: var(--tag, var(--snack));
  background: color-mix(in srgb, var(--tag, var(--snack)) 14%, transparent);
  padding: 2px 7px; border-radius: var(--radius-pill);
}
.rail-name { display: block; font-weight: 600; font-size: 14.5px; }
.rail-card-bottom { display: flex; align-items: baseline; gap: 10px; margin-top: 3px; flex-wrap: wrap; }
.rail-cal { font-family: var(--display); font-size: 15px; font-weight: 500; }
.rail-macros { font-size: 12px; color: var(--ink-faint); }

.rail-empty { color: var(--ink-faint); font-size: 14px; padding: 8px 0 8px 8px; }

/* Multi-day timeline */
.day-dot.current {
  box-shadow: 0 0 0 4px var(--surface), 0 0 0 6px color-mix(in srgb, var(--accent) 40%, transparent);
}
.day-card {
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.day-card:hover { border-color: var(--line-strong); background: var(--surface); }
.day-card.current {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
}
.day-date { font-weight: 600; font-size: 14px; color: var(--ink); }
.day-cal { font-family: var(--display); font-size: 15px; color: var(--ink); margin-left: auto; }
.day-cal b { font-weight: 600; }
.day-cal-unit { font-family: var(--sans); font-size: 11px; color: var(--ink-faint); font-weight: 600; }

.cal-bar {
  height: 5px; border-radius: 3px; margin: 8px 0 7px;
  background: var(--line); overflow: hidden;
}
.cal-bar-fill {
  display: block; height: 100%; border-radius: 3px;
  background: var(--cal);
  transition: width 0.3s ease;
}
.cal-bar-fill.over { background: var(--warn); }

.day-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.day-macros { font-size: 12px; color: var(--ink-faint); }
.day-badge {
  font-size: 10.5px; letter-spacing: 0.04em; text-transform: uppercase; font-weight: 700;
  color: var(--tag, var(--workout));
  background: color-mix(in srgb, var(--tag, var(--workout)) 14%, transparent);
  padding: 2px 8px; border-radius: var(--radius-pill); white-space: nowrap;
}
.day-badge.subtle {
  color: var(--ink-faint); background: var(--surface-2); font-weight: 600;
}
.rail-card-top { align-items: baseline; }

/* Now marker */
.rail-node.now .now-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--surface), 0 0 0 6px color-mix(in srgb, var(--accent) 35%, transparent);
  animation: pulse 2s ease-in-out infinite;
}
.now-card {
  background: transparent; border: 1px dashed color-mix(in srgb, var(--accent) 45%, var(--line));
  padding: 6px 12px;
}
.now-label { font-size: 12px; font-weight: 700; color: var(--accent-strong); letter-spacing: 0.03em; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px var(--surface), 0 0 0 6px color-mix(in srgb, var(--accent) 30%, transparent); }
  50% { box-shadow: 0 0 0 4px var(--surface), 0 0 0 9px color-mix(in srgb, var(--accent) 8%, transparent); }
}

/* --- Calendar popover ------------------------------------------------------ */

.cal-pop {
  z-index: 70;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 12px;
  animation: card-in 0.14s ease;
}
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-month { font-family: var(--display); font-weight: 600; font-size: 15px; }
.cal-nav {
  border: none; background: none; color: var(--ink-soft);
  width: 30px; height: 30px; border-radius: 8px; font-size: 18px; line-height: 1;
}
.cal-nav:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.cal-nav:disabled { opacity: 0.3; cursor: default; }

.cal-dow {
  display: grid; grid-template-columns: repeat(7, 1fr);
  text-align: center; font-size: 11px; font-weight: 600;
  color: var(--ink-faint); margin-bottom: 4px;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-blank { aspect-ratio: 1; }
.cal-day {
  position: relative; aspect-ratio: 1;
  border: none; background: none; border-radius: 9px;
  font-size: 13px; color: var(--ink); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.cal-day:hover:not(:disabled) { background: var(--surface-2); }
.cal-day.today { color: var(--accent); font-weight: 700; }
.cal-day.selected { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.cal-day.selected.today { color: var(--accent-ink); }
.cal-day.marked::after {
  content: ''; position: absolute; bottom: 3px; left: 50%; transform: translateX(-50%);
  width: 4px; height: 4px; border-radius: 50%; background: var(--accent);
}
.cal-day.selected.marked::after { background: var(--accent-ink); }
.cal-day.future { color: var(--ink-faint); opacity: 0.35; cursor: default; }
.cal-day:disabled { cursor: default; }
.cal-day:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.cal-foot { margin-top: 8px; display: flex; justify-content: center; }
.cal-today {
  border: 1px solid var(--line-strong); background: transparent; color: var(--ink-soft);
  font-size: 12.5px; font-weight: 600; padding: 5px 14px; border-radius: var(--radius-pill);
}
.cal-today:hover { background: var(--surface-2); color: var(--ink); }

/* --- Modal ----------------------------------------------------------------- */

.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: flex-start; justify-content: center;
  padding: clamp(16px, 6vh, 72px) 16px 16px;
  background: color-mix(in srgb, #23261f 42%, transparent);
  backdrop-filter: blur(3px);
  animation: overlay-in 0.16s ease;
  overflow-y: auto;
}
.modal-overlay.closing { animation: overlay-out 0.14s ease forwards; }
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes overlay-out { to { opacity: 0; } }

.modal-card {
  width: 100%; max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: card-in 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes card-in { from { transform: translateY(12px) scale(0.99); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.modal-title { font-family: var(--display); font-size: 20px; font-weight: 600; margin: 0; }
.modal-body { padding: 16px; }

/* Add wizard */
.add-picker { display: flex; flex-direction: column; gap: 8px; }
.add-card {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 14px 16px;
  transition: border-color 0.15s, background 0.15s, transform 0.06s;
}
.add-card:hover { border-color: var(--line-strong); background: var(--surface); }
.add-card:active { transform: translateY(1px); }
.add-card-icon { font-size: 24px; line-height: 1; }
.add-card-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.add-card-label { font-weight: 600; font-size: 15px; }
.add-card-desc { font-size: 12.5px; color: var(--ink-faint); }
.add-card-chevron { color: var(--ink-faint); font-size: 20px; }

.back-link {
  border: none; background: none; color: var(--ink-soft);
  font-size: 13px; font-weight: 600; padding: 0 0 12px; margin: 0;
}
.back-link:hover { color: var(--ink); }

/* Forms */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--ink-soft); letter-spacing: 0.01em; }
.field-hint { font-size: 11.5px; color: var(--ink-faint); }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }

.field input, .field select, .search-input, .mini {
  background: var(--surface);
  color: var(--ink);
}
.field input, .field select {
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 14.5px;
  width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible, .result-row:focus-visible, .date-label:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form-note { font-size: 13px; color: var(--ink-faint); margin: 0 0 14px; }
.form-error {
  background: color-mix(in srgb, var(--warn) 12%, var(--surface));
  color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  padding: 8px 12px; border-radius: 9px; font-size: 13px; margin: 4px 0 12px;
}

.nutrient-group { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px 4px; margin: 0 0 12px; }
.nutrient-group legend { font-size: 12px; font-weight: 700; color: var(--ink-soft); padding: 0 6px; }
.nutrient-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.nutrient-grid .field { margin-bottom: 6px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* Targets: calorie + ratio calculator */
.ratio-label { display: block; margin-bottom: 6px; }
.ratio-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.ratio-row input {
  width: 100%; text-align: center;
  border: 1px solid var(--line-strong); border-radius: 9px;
  padding: 9px 8px; font-size: 15px;
  background: var(--surface); color: var(--ink);
}
.ratio-colon { color: var(--ink-faint); font-weight: 700; }
.targets-preview { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 16px; }
.tp-macro {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12.5px; color: var(--ink-soft);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-pill); padding: 5px 11px 5px 9px;
}
.tp-macro::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--chip); }
.tp-macro b { color: var(--ink); font-weight: 700; }
.tp-pct { color: var(--ink-faint); }
.targets-preview-empty { font-size: 12.5px; color: var(--ink-faint); }
.extras-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 4px; margin-bottom: 4px; }
.extras-head .field-label { margin: 0; }
.field input.auto { color: var(--ink-faint); font-style: italic; }

/* Search + results (add food) */
.search-input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 15px;
  margin-bottom: 10px;
}
.result-list { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.result-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; text-align: left;
  background: none; border: none; border-radius: 8px;
  padding: 10px 11px; font-size: 14.5px; color: var(--ink);
}
.result-row:hover { background: var(--surface-2); }
.result-name { font-weight: 600; }
.result-brand { color: var(--ink-faint); font-weight: 500; }
.result-cal { color: var(--ink-faint); font-size: 13px; white-space: nowrap; }
.empty-hint { color: var(--ink-faint); font-size: 14px; padding: 16px 4px; text-align: center; }

.add-detail:not(:empty) {
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line);
}
.detail-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.detail-name { font-family: var(--display); font-size: 18px; font-weight: 600; }
.detail-serving { font-size: 12.5px; color: var(--ink-faint); }

/* Workout dialog */
.exercise-head {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 12px; font-weight: 600; color: var(--ink-soft); margin: 6px 0 6px;
}
.exercise-cols { color: var(--ink-faint); font-weight: 500; font-size: 11px; }
.exercise-list { display: flex; flex-direction: column; gap: 6px; }
.exercise-row { display: grid; grid-template-columns: 1.6fr 0.7fr 0.7fr 0.9fr 0.7fr 26px; gap: 6px; align-items: center; }
.exercise-row input { border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 8px; font-size: 13.5px; background: var(--surface); color: var(--ink); width: 100%; }
.ex-num { text-align: center; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink-soft); margin: 12px 0; }
.checkbox-row input { width: 16px; height: 16px; accent-color: var(--accent); }

/* Meal builder */
.meal-items { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.meal-item { display: grid; grid-template-columns: 1fr 72px auto 26px; align-items: center; gap: 8px; }
.meal-item-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-item-unit { font-size: 11.5px; color: var(--ink-faint); white-space: nowrap; }
.meal-items-head { font-size: 12px; font-weight: 600; color: var(--ink-soft); margin: 8px 0 6px; }
.meal-total { font-size: 13px; font-weight: 600; color: var(--ink-soft); margin: 2px 0 12px; }
.meal-name {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 9px;
  padding: 9px 11px; font-size: 14.5px; background: var(--surface); color: var(--ink); margin-bottom: 4px;
}

/* Preset chips */
.preset-box:not(:empty) { margin-bottom: 14px; }
.preset-label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.preset-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.preset-chip {
  display: inline-flex; align-items: stretch;
  border: 1px solid var(--line-strong); border-radius: var(--radius-pill);
  overflow: hidden; background: var(--surface);
}
.preset-load {
  border: none; background: none; color: var(--ink);
  font-size: 13px; font-weight: 600; padding: 6px 4px 6px 12px;
}
.preset-load:hover { color: var(--accent-strong); }
.preset-del {
  border: none; background: none; color: var(--ink-faint);
  font-size: 11px; padding: 6px 9px 6px 6px; line-height: 1;
}
.preset-del:hover { color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); }

@media (max-width: 480px) {
  .exercise-row { grid-template-columns: 1fr 1fr 1fr; }
  .exercise-row .icon-btn { grid-column: 3; justify-self: end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
