/* ---------- Theme tokens: dark theme only (FR-21) ---------- */
:root {
  color-scheme: dark;  /* native controls (date picker, checkboxes, scrollbars) draw dark too */

  --bg: #14171c;
  --surface: #1d2128;
  --text: #e6e8eb;
  --muted: #9aa3af;
  --border: #2d333c;
  --accent: #5b8ef0;
  --accent-text: #0d1117;
  --ok: #4cc47f;
  --over: #f06b6b;   /* "over target" red; 5.4:1 on the card surface */
  --warn: #e0a83a;   /* recipe warnings and the "files need attention" note */
  --bar-bg: #2a3038;
  --radius: 10px;

  /* FR-20: one color per nutrient, used everywhere that nutrient appears.
     Slots 1-5 of the dataviz skill's reference palette (its dark-mode steps),
     in its fixed order, validated for color-blind separation on this surface.
     Red is NOT a nutrient: it stays reserved for "over target" (--over). */
  --nut-calories: #3987e5;  /* blue */
  --nut-protein:  #d95926;  /* orange */
  --nut-netCarbs: #199e70;  /* aqua */
  --nut-fiber:    #c98500;  /* yellow */
  --nut-fat:      #d55181;  /* magenta */

  /* FR-20: page chrome (header band, card headings). Violet and blue, so it
     never looks like a nutrient color or a status color. */
  --brand-1: #3b2f8f;
  --brand-2: #1c5cab;
  --heading: #a99ff0;
  --page-glow: #1f1d3a;
}

/* ---------- Light theme for the recipe areas only (FR-21) ----------
   Put class="theme-light" on an element and everything inside it is light:
   every component reads these tokens through var(--...), so redefining them
   here is all it takes. Used on the Recipes card and the recipe window. */
.theme-light {
  color-scheme: light;  /* light native controls inside, e.g. the servings box */

  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2026;
  --muted: #6b7280;
  --border: #e3e6ea;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --ok: #2e9e5b;
  --over: #d03b3b;
  --warn: #9a6700;
  --bar-bg: #eceff3;

  /* FR-20: the light-surface steps of the same five hues */
  --nut-calories: #2a78d6;
  --nut-protein:  #eb6834;
  --nut-netCarbs: #1baf7a;
  --nut-fiber:    #eda100;
  --nut-fat:      #e87ba4;

  --heading: #4b3cc0;
  color: var(--text);
}

/* FR-20: each nutrient's color, picked up by any element that says which
   nutrient it shows (data-nutrient="protein" etc.). */
[data-nutrient="calories"] { --nut: var(--nut-calories); }
[data-nutrient="protein"]  { --nut: var(--nut-protein); }
[data-nutrient="netCarbs"] { --nut: var(--nut-netCarbs); }
[data-nutrient="fiber"]    { --nut: var(--nut-fiber); }
[data-nutrient="fat"]      { --nut: var(--nut-fat); }

/* ---------- Base ---------- */
* { box-sizing: border-box; }

body {
  margin: 0;
  /* FR-20: a soft violet glow at the top of the page, fading into the plain background */
  background: linear-gradient(180deg, var(--page-glow) 0, var(--bg) 420px) no-repeat, var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }

.muted { color: var(--muted); }

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: .4em .9em;
}
button:hover { border-color: var(--accent); }

input[type="number"] {
  width: 100%;
  padding: .35em .5em;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.banner {
  margin: 0;
  padding: 10px 20px;
  background: var(--over);
  color: #fff;
  font-weight: 600;
}
/* FR-28: "Update available — Reload". Blue, not red: it's news, not an error. */
.update-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--brand-2);
}
.update-banner[hidden] { display: none; }
.update-banner button { color: var(--text); font-weight: 600; }

/* ---------- Layout ---------- */
.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  /* FR-20: colored header band; white text keeps at least 4.5:1 on both ends */
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  color: #fff;
}
.app-header h1 { margin: 0; }
.app-header .date-label { color: #fff; }
/* Controls in the band keep their own light/dark surface, so they keep normal text color */
.app-header button, .app-header input { color: var(--text); }

/* FR-20: card headings in the brand color, with a small gradient marker */
.card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--heading);
}
.card h2::before {
  content: "";
  width: 6px;
  height: 1.1em;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--brand-1), var(--brand-2));
  flex: none;
}

.layout {
  display: grid;
  /* min() lets cards shrink below 340px on narrow windows instead of overflowing. */
  grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr));
  gap: 16px;
  padding: 16px 16px 40px;
  max-width: 1200px;
  margin: 0 auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}

.small { font-size: .85em; }

/* ---------- Day controls (FR-1) ---------- */
#day-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
.date-label { font-weight: 600; min-width: 2.6em; text-align: right; }

.date-nav {
  display: inline-flex;
  flex-wrap: wrap;   /* narrow windows: wrap instead of scrolling the page sideways */
  align-items: center;
  gap: 6px;
}
.date-nav input[type="date"] {
  padding: .3em .5em;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}
.date-nav .icon-button { font-size: 1.2em; line-height: 1; }
button:disabled { opacity: .45; cursor: default; }
button:disabled:hover { border-color: var(--border); }

.toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  background: var(--bg);
}
.toggle button {
  border: 0;
  border-radius: 999px;
  background: transparent;
  padding: .35em 1.1em;
  font-weight: 600;
  color: var(--muted);
}
.toggle button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

/* ---------- Progress meters (FR-9, FR-10) ---------- */
.meter { margin-bottom: 14px; }
.meter:last-child { margin-bottom: 0; }
.meter-head, .meter-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.meter-label { font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
/* FR-20: a colored dot by the label names the nutrient's color; the label text itself stays in the text color */
.meter-label::before, .chip[data-nutrient]::before, .trend-stat[data-nutrient] > span::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--nut);
  flex: none;
}
.over-flag { color: var(--over); font-weight: 700; margin-right: auto; }
.meter-foot { font-size: .85em; color: var(--muted); justify-content: flex-end; }

.bar {
  height: 10px;
  margin: 4px 0;
  border-radius: 999px;
  background: var(--bar-bg);
  overflow: hidden;
}
.fill {
  height: 100%;
  border-radius: inherit;
  background: var(--nut, var(--ok));  /* FR-20: the nutrient's own color */
  transition: width .25s ease;
}
/* FR-10 + FR-20: over target keeps the nutrient's color (so it's still
   recognisable) and adds a red outline plus the "⚠ Over target" text. */
.meter.over .bar { outline: 2px solid var(--over); outline-offset: 1px; }
.meter.over .meter-foot { color: var(--over); font-weight: 600; }

/* ---------- Daily log (FR-7, FR-8) ---------- */
.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.log-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.log-entry:last-child { border-bottom: 0; }
.log-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.log-title { font-weight: 600; overflow-wrap: anywhere; }
/* FR-18: eaten checkbox; unticked entries are dimmed and don't count */
.log-hint { margin: 0; flex: 1; min-width: 12em; }
/* FR-19: the hint and the Tick all button share a row; they wrap on narrow screens */
.log-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 4px; }
.eaten-box { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--accent); cursor: pointer; }
.log-entry.not-eaten .log-main { opacity: .6; }

/* FR-26: open the recipe a log item came from */
.open-recipe { padding: .25em .7em; font-size: .85em; color: var(--accent); }
/* Recipe, servings and remove stay together on the right. Narrow screens: the
   name keeps at least ~10em and the whole group moves to a second line,
   instead of squeezing the name letter by letter. */
.entry-controls { display: inline-flex; align-items: center; gap: 10px; margin-left: auto; flex: none; }
.log-entry .log-toggle { flex: 1 1 10em; }
.log-entry .log-title { overflow-wrap: break-word; }
.entry-note { flex-basis: 100%; margin: 2px 0 0 30px; color: var(--warn); }
.entry-note:empty { display: none; }

/* FR-22: the item name is a button that opens its nutrition panel */
.log-entry { flex-wrap: wrap; }
.log-toggle {
  border: 0;
  background: none;
  padding: 2px 4px;
  margin: -2px -4px;
  text-align: left;
  color: inherit;
  border-radius: 6px;
}
.log-toggle:hover { background: var(--bar-bg); }
.log-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.log-toggle .log-title::after { content: " ▸"; color: var(--muted); font-weight: 400; }
.log-toggle[aria-expanded="true"] .log-title::after { content: " ▾"; }
.entry-details {
  flex-basis: 100%;
  margin: 2px 0 4px 30px;  /* lines up with the name, past the checkbox */
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
}
.entry-details p { margin: 0; }
.entry-nutrients {
  list-style: none;
  margin: 6px 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));  /* all five on one row in the Log card */
  gap: 5px;
}
.entry-nutrients li {
  display: grid;
  min-width: 0;
  padding: 4px 6px;
  font-size: .9em;
  border-left: 4px solid var(--nut);  /* FR-20 nutrient color */
  border-radius: 4px;
  background: var(--surface);
}
.log-entry.not-eaten .log-title { font-weight: 500; }
.servings-field { display: inline-flex; align-items: center; gap: 4px; }
.servings-field input { width: 4.8em; }

/* ---------- Quick add (FR-14) ---------- */
.quick-add {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.quick-add summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.quick-add form { margin-top: 10px; display: grid; gap: 10px; }
.quick-add label { display: grid; gap: 3px; font-size: .9em; font-weight: 500; }
.quick-add input[type="text"] {
  width: 100%;
  padding: .35em .5em;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}
.qa-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 8px;
}
.quick-add p { margin: 0; }
.qa-errors { margin: 0; padding-left: 18px; }
.quick-add button[type="submit"] { justify-self: start; }

/* ---------- Trends (FR-17) ---------- */
.card.wide { grid-column: 1 / -1; }
#trends-body { position: relative; }
.trend-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.trend-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}
.trend-stat {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.trend-stat strong { font-size: 1.1rem; }
/* FR-20: nutrient average tiles get a colored edge and dot */
.trend-stat[data-nutrient] { border-left: 4px solid var(--nut); }
.trend-stat[data-nutrient] > span { display: inline-flex; align-items: center; gap: 5px; }
#trends-body > p { margin: 8px 0 0; }
.trend-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr));
  gap: 8px 24px;
  margin-top: 8px;
}
.trend-chart { min-width: 0; }
.trend-chart h3 { font-size: .95rem; margin: 12px 0 4px; }
.trend-chart svg { display: block; max-width: 100%; }
.trend-chart text.axis { fill: var(--muted); font-size: 11px; font-family: inherit; }
.trend-chart line.grid { stroke: var(--border); stroke-width: 1; }
.trend-chart line.baseline { stroke: var(--muted); stroke-width: 1; }
.trend-chart .bar { fill: var(--accent); }
/* FR-20: each chart's bars in its nutrient's color */
.trend-chart[data-chart="calories"] .bar { fill: var(--nut-calories); }
.trend-chart[data-chart="protein"] .bar { fill: var(--nut-protein); }
.trend-chart .target-tick { stroke: var(--text); stroke-width: 2; stroke-linecap: round; }
.trend-chart .marks { pointer-events: none; }  /* hover/focus land on the hit areas below */
.trend-chart rect.hit { fill: transparent; cursor: default; outline: none; }
.trend-chart rect.hit:hover, .trend-chart rect.hit:focus { fill: var(--bar-bg); }
.trend-chart rect.hit:focus-visible { stroke: var(--accent); stroke-width: 2; }
.trend-table { margin-top: 10px; }
.trend-table summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.chart-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  padding: 6px 9px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .15);
  font-size: .82em;
  line-height: 1.45;
  white-space: nowrap;
}
.chart-tooltip .tip-date { font-weight: 600; margin-bottom: 2px; }

/* ---------- Load a saved meal plan (FR-16) ---------- */
.plan-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  font-size: .9em;
}
.plan-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.plan-table { width: 100%; border-collapse: collapse; margin: 14px 0 8px; font-size: .92em; }
.plan-table th, .plan-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.plan-table th { font-size: .85em; color: var(--muted); }
.plan-notes { padding-left: 18px; margin: 8px 0 14px; }
.plan-notes li { margin: 3px 0; }

/* ---------- Backup (FR-15) ---------- */
.subhead {
  font-size: .95rem;
  margin: 18px 0 4px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
#backup p { margin: 0 0 8px; }
.backup-message { margin-top: 8px !important; }

/* ---------- Shared controls ---------- */
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.button-row { display: inline-flex; flex-wrap: wrap; gap: 8px; }
.error { color: var(--over); }
code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: .88em;
  background: var(--bar-bg);
  padding: .05em .35em;
  border-radius: 4px;
}

/* ---------- Recipe library (FR-3, FR-4, FR-5) ---------- */
.lib-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.tabs button {
  border-radius: 999px;
  padding: .25em .8em;
  font-size: .9em;
}
.tabs button[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.tabs .count { opacity: .7; font-size: .85em; }

.recipe-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.recipe-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
}
.recipe-item:hover { border-color: var(--accent); }
.recipe-title { font-weight: 600; }

/* FR-23: the recipe button and its "+ Add" button share one row and look like one card */
.recipe-row { display: flex; align-items: stretch; }
.recipe-row .recipe-item { flex: 1; min-width: 0; border-radius: 8px 0 0 8px; }
.add-from-list {
  flex: none;
  border-radius: 0 8px 8px 0;
  border-left: 0;
  padding: 0 14px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}
.add-from-list:hover { background: var(--accent); color: var(--accent-text); }
.add-from-list.added { background: #1e7b46; border-color: #1e7b46; color: #fff; }  /* dark green: white text at 5.4:1 */

/* ---------- Weight log (FR-25) ---------- */
/* The average line is violet (dataviz palette slot 7, dark step), a hue no
   nutrient uses; the daily dots are neutral grey, so the trend line leads. */
#weight { --weight-avg: #9085e9; --weight-dot: #9aa3af; }
.weight-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 10px; margin-bottom: 14px; }
.weight-form label { display: grid; gap: 4px; font-weight: 600; }
.weight-form input {
  width: 8em;
  padding: .35em .5em;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}
.weight-message { flex-basis: 100%; margin: 0; }
.weight-message:empty { display: none; }
.weight-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 12px 0 4px; color: var(--muted); }
.weight-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--weight-dot); }
.legend-line { width: 18px; height: 2px; border-radius: 1px; background: var(--weight-avg); }
.weight-chart svg { display: block; max-width: 100%; }
.weight-chart text.axis { fill: var(--muted); font-size: 11px; font-family: inherit; }
.weight-chart line.grid { stroke: var(--border); stroke-width: 1; }
.weight-chart .avg-line { fill: none; stroke: var(--weight-avg); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.weight-chart .weigh-in { fill: var(--weight-dot); stroke: var(--surface); stroke-width: 2; }  /* 2px surface ring */
.weight-chart .marks { pointer-events: none; }
.weight-chart rect.hit { fill: transparent; outline: none; }
.weight-chart rect.hit:hover, .weight-chart rect.hit:focus { fill: var(--bar-bg); }
.weight-chart rect.hit:focus-visible { stroke: var(--accent); stroke-width: 2; }

/* ---------- What fits? (FR-24) ---------- */
.fit-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.fit-item { display: flex; align-items: stretch; }
.fit-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px 0 0 8px;
  background: var(--bg);
}
.fit-title { font-weight: 600; }
.fit-item .chips { margin-top: 2px; }
.over-text { color: var(--over); font-weight: 600; }
.fits-note { margin: 8px 0 0; color: var(--ok); font-weight: 600; }
.fits-note:empty { display: none; }

/* Read by screen readers, not shown on screen */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.warn-flag { color: var(--warn); cursor: help; }

.chips { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 6px; }
.chip {
  font-size: .8em;
  background: var(--bar-bg);
  border-radius: 999px;
  padding: .1em .6em;
  white-space: nowrap;
}
.chip[data-nutrient] { display: inline-flex; align-items: center; gap: 4px; }
.chip[data-nutrient]::before { width: 7px; height: 7px; }

.problems {
  margin-top: 12px;
  border: 1px solid var(--warn);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: .9em;
}
.problems summary { cursor: pointer; font-weight: 600; color: var(--warn); }
.problems ul { margin: 8px 0 0; padding-left: 18px; }

/* ---------- Recipe detail dialog (FR-6) ---------- */
dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 20px 24px 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.dialog-head h2 { font-size: 1.3rem; margin-bottom: .2em; }
.dialog-head p { margin: 0; }
.icon-button {
  flex: none;
  width: 2.2em;
  height: 2.2em;
  padding: 0;
  border-radius: 50%;
}
.per-serving-label { margin: 14px 0 0; }
.chip.tag { background: transparent; border: 1px solid var(--border); }

/* Add to log (FR-7) */
.add-to-log {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
  background: var(--bar-bg);
}
.add-to-log label { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.add-to-log input { width: 5.5em; }
.add-error { flex-basis: 100%; }

/* Rendered recipe Markdown */
.markdown { margin-top: 18px; border-top: 1px solid var(--border); }
.markdown h1 { font-size: 1.25rem; margin-top: 1.2em; }
.markdown h2 { font-size: 1.1rem; margin-top: 1.3em; }
.markdown h3 { font-size: 1rem; margin-top: 1.1em; }
.markdown h4, .markdown h5, .markdown h6 { font-size: .95rem; margin-top: 1em; }
.markdown p, .markdown ul, .markdown ol { margin: .5em 0; }
.markdown ul, .markdown ol { padding-left: 1.4em; }
.markdown li { margin: .15em 0; }
.markdown hr { border: 0; border-top: 1px solid var(--border); margin: 1.2em 0; }
.markdown table {
  display: block;          /* lets wide tables scroll instead of overflowing */
  overflow-x: auto;
  border-collapse: collapse;
  margin: .6em 0;
  font-size: .9em;
}
.markdown th, .markdown td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
  vertical-align: top;
}
.markdown th { background: var(--bar-bg); }

/* ---------- Targets editor (FR-2) ---------- */
.targets-table {
  width: 100%;
  border-collapse: collapse;
}
.targets-table th, .targets-table td {
  padding: 4px 6px;
  text-align: left;
}
.targets-table thead th { font-size: .85em; color: var(--muted); }
.targets-table tbody th { font-weight: 500; white-space: nowrap; }

/* Highlight the column for the selected day type. */
.targets-table[data-active="workout"] th[data-col="workout"],
.targets-table[data-active="rest"] th[data-col="rest"] {
  color: var(--accent);
}
.targets-table[data-active="workout"] input[data-type="workout"],
.targets-table[data-active="rest"] input[data-type="rest"] {
  border-color: var(--accent);
}

/* ---------- Phones (FR-29) ----------
   Everything phone-specific lives here, so the desktop layout can't change.
   Apple's guideline: touch targets at least 44 x 44 px. Text inputs at least
   16 px, or Safari on iPhone zooms the page in when you tap them. */
.tap-target { display: inline-flex; align-items: center; justify-content: center; flex: none; cursor: pointer; }

@media (max-width: 640px) {
  button, [role="tab"] { min-height: 44px; min-width: 44px; }
  .icon-button { width: 44px; height: 44px; }
  summary { display: flex; align-items: center; min-height: 44px; }
  input, select, textarea { font-size: 16px; }

  /* The log checkbox keeps its size; its label around it is the 44 px tap area.
     Negative margins stop the bigger tap area from pushing the row apart. */
  .log-entry .tap-target { width: 44px; height: 44px; margin: -12px -10px -12px -12px; }
  .entry-details, .entry-note { margin-left: 22px; }

  /* Date controls on two lines: "‹ Mon [date] ›", then "Today" with the
     Workout/Rest toggle. display: contents lets the date-nav's children take
     part in this grid directly, with no markup change. */
  #day-controls {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    grid-template-areas: "prev label date next" "today today type type";
    align-items: center;
    gap: 8px;
    width: 100%;
  }
  #day-controls .date-nav { display: contents; }
  #day-controls [data-nav="-1"] { grid-area: prev; }
  #day-controls .date-label { grid-area: label; min-width: 0; }
  #day-controls [data-date-input] { grid-area: date; min-width: 0; width: 100%; }
  #day-controls [data-nav="1"] { grid-area: next; }
  #day-controls [data-nav="today"] { grid-area: today; justify-self: start; }
  #day-controls .toggle { grid-area: type; justify-self: end; }

  /* Recipe window: the whole screen, with the close button always in view. */
  dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    padding: 0 16px 24px;
    border: 0;
    border-radius: 0;
  }
  .dialog-head {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 10px 0 8px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }
}
