:root {
  --bg: #fdf4f9;
  --bg-2: #f7e8f1;
  --panel: #ffffff;
  --panel-2: #fbeef5;
  --text: #3d2f3a;
  --muted: #9a7e90;
  --accent: #e0609e;      /* rose */
  --accent-2: #a874d6;    /* lavender */
  --good: #2f9e6a;
  --bad: #d24d78;
  --border: #f0d7e6;
  --shadow: 0 6px 20px rgba(180, 90, 140, 0.10);
  --heading: #4a3543;
  --nav-bg: rgba(255, 255, 255, 0.85);
  --toggle-off: #dcc7d6;
}

* { box-sizing: border-box; }

/* `hidden` must actually hide. The attribute's UA style is `display: none`, which any later rule
   that sets `display` silently beats — and `form .field { display: flex }` does exactly that, so
   [hidden] fields stayed on screen. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.nav {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .5rem 1rem;
  padding: .75rem 1.25rem; background: var(--nav-bg);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--accent); }
.nav-links { display: flex; align-items: center; flex-wrap: wrap; gap: .25rem 1rem; }
.nav-links a { color: var(--muted); font-size: .95rem; }
.nav-links a:hover { color: var(--accent); text-decoration: none; }

/* Nav as a checkbox-toggle. Desktop: the ☰ label and the checkbox are hidden, and the links show
   inline exactly as before. Mobile (≤760px): the ☰ shows and the checked state drops the links into
   a full-width drawer. CSS-only — no JS to break, and Turbo re-renders the checkbox unchecked. */
.nav-check { display: none; }                 /* the toggle state holder — never shown itself */
.nav-toggle { display: none; }                /* desktop: no hamburger */
@media (max-width: 760px) {
  /* z-index raises the whole nav's stacking context (it already is one — .nav has backdrop-filter)
     above the page content, so the absolutely-positioned drawer paints over the cards below it.
     Without this the drawer's own z-index is trapped inside the nav context at the page's base level,
     and later-in-DOM content (the habit tracker) painted through the open menu. */
  .nav { position: relative; z-index: 100; }
  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 1.4rem; line-height: 1;
    color: var(--accent); padding: .25rem .5rem; border-radius: 8px;
    user-select: none; -webkit-tap-highlight-color: transparent;
  }
  .nav-links { display: none; }               /* closed: hide the drawer */
  .nav-check:checked ~ .nav-links {
    display: flex;
    position: absolute; left: 0; right: 0; top: 100%; z-index: 100;
    flex-direction: column; align-items: stretch; gap: .1rem;
    /* Opaque (not the translucent --nav-bg): the drawer overlays page content, so a see-through
       panel let the text behind it bleed through and read as overlapping. */
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    padding: .5rem 1.25rem 1rem; box-shadow: var(--shadow);
  }
  .nav-check:checked ~ .nav-links a,
  .nav-check:checked ~ .nav-links form { padding: .5rem 0; font-size: 1rem; }
}

.container { max-width: 920px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }

h1 { font-size: 1.6rem; margin: .2rem 0 1rem; color: var(--heading); }
h2 { font-size: 1.2rem; margin: 1.5rem 0 .75rem; color: var(--heading); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 1.1rem 1.25rem; margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* A stat-tile row floating on the page gets the same gap below it as cards have between them, so it
   doesn't butt straight into the next box. Inside a card, spacing is the card's job (and the inner
   elements keep their own margins), so reset it there — this only changes page-level stat rows. */
.grid, .stat-row { margin-bottom: 1.25rem; }
.card .grid, .card .stat-row { margin-bottom: 0; }

/* Keeps a fixed number of stat cards on one row (e.g. the 4 measurement stats). */
.grid-4 { display: grid; gap: .75rem; grid-template-columns: repeat(4, 1fr); }
@media (max-width: 620px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }

/* Weight-page stat row: stretch to fill whether there are 3 or 4 cards. */
.stat-row { display: grid; gap: 1rem; }
.stat-row.cols-3 { grid-template-columns: repeat(3, 1fr); }
.stat-row.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 760px) {
  .stat-row.cols-3, .stat-row.cols-4 { grid-template-columns: repeat(2, 1fr); }
}
/* Hold 2-up down to a very narrow phone — big-number tiles read fine at ~160px, and 1-up wasted
   half the screen on a 390px device. Only the tiniest widths (<360px) fall back to a single column. */
@media (max-width: 360px) {
  .stat-row.cols-3, .stat-row.cols-4 { grid-template-columns: 1fr; }
}

/* A stat tile has to define itself on ANY background — it isn't always inside a white .card (on the
   dashboard and admin panels it floats straight on the page, where --panel-2 is nearly identical to
   --bg and washes out). Rather than hand-add a "tile" colour to every palette, derive one: mix the
   background toward the theme's OWN accent, so it's a clearly darker shade that keeps the theme's hue
   (mixing toward --text instead just greys it out to mud). Works in every theme, custom included.
   Border + soft lift on top. */
.stat { background: color-mix(in oklab, var(--bg) 80%, var(--accent));
  border: 1px solid var(--border); border-radius: 12px;
  padding: .9rem 1rem; box-shadow: 0 1px 3px rgba(120, 60, 90, 0.06); }
.stat .big { font-size: 1.7rem; font-weight: 700; color: var(--heading); }
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.up { color: var(--bad); }
.down { color: var(--good); }

form .field { margin-bottom: .8rem; display: flex; flex-direction: column; gap: .25rem; }
label { color: var(--muted); font-size: .85rem; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], select, textarea {
  /* Theme-aware, not a hardcoded #fff: on a dark theme (Midnight) a white field left the
     var(--text) type near-white-on-white and unreadable. var(--bg) keeps type legible on every
     theme and sets the field apart from the card (var(--panel)) it usually sits on. */
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: .5rem .6rem; font-size: 1rem; width: 100%;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
/* No spinner arrows on number inputs anywhere — nudging a weight or a calorie count one unit
   at a time is never what you want here, and they eat room in narrow fields. Type the number. */
input[type=number] { appearance: textfield; -moz-appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.inline-form { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; }
.inline-form .field { margin-bottom: 0; }
/* Fields share one line by grow factor (basis 0 avoids the inputs' wide intrinsic
   width forcing a wrap); the date gets extra room to show in full. */
.entry-form { flex-wrap: nowrap; }
.entry-form .field { flex: 1 1 0; min-width: 4rem; }
.entry-form .field:first-child { flex: 1.5 1 0; min-width: 10rem; }
.entry-form input[type="number"], .entry-form input[type="date"] { width: 100%; }

button, .btn, input[type=submit] {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: .5rem .9rem; font-size: .95rem; font-weight: 600; cursor: pointer;
}
button:hover, .btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn-ghost { background: #fff; color: var(--accent); border: 1px solid var(--border); }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; }
.linkish { background: none; color: var(--muted); padding: 0; font-weight: 400; }
.linkish:hover { color: var(--bad); filter: none; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid var(--border); }
.flash-notice { background: #e8f7ee; border-color: #b6e3ca; color: #1f7a4d; }
/* An error has to survive the app's own palette — everything here is soft pink, so a soft pink
   error box just reads as more app. Hence the heavy left rule, the darker border and the ⛔:
   the message should be unmistakable at a glance, not something you decode. */
.flash-alert, .flash-error { background: #fde7ee; border: 2px solid #d5386e;
  border-left-width: 6px; color: #8c1740; }
/* Errors stay until dismissed, and stay in the page flow so the text can be selected and copied.
   A floating toast that erases itself is fine for "Saved"; it's useless for "that didn't work". */
.flash-sticky { display: flex; align-items: flex-start; gap: .6rem; }
.flash-sticky .flash-body { flex: 1; }
.flash-sticky .flash-label { flex: 0 0 auto; font-size: 1.05rem; line-height: 1.35; }
.flash-sticky strong { font-weight: 700; }
.flash-close { background: none; border: 0; padding: 0 .15rem; margin: 0; line-height: 1;
  font-size: 1.25rem; color: inherit; opacity: .55; box-shadow: none; cursor: pointer; }
.flash-close:hover { opacity: 1; background: none; filter: none; }

.flash-token { background: var(--panel-2); }
.flash-token code { display: block; margin-top: .3rem; word-break: break-all; color: var(--accent-2); }

.errors { color: var(--bad); font-size: .9rem; margin-bottom: .8rem; }

.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; align-items: center; gap: .6rem; padding: .4rem 0; border-bottom: 1px solid var(--border); }
.done-badge { color: var(--good); }
.todo-badge { color: var(--muted); }

.photo-grid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.photo-grid img { width: 100%; height: 140px; object-fit: cover; border-radius: 8px; }

.slideshow { text-align: center; }
.slideshow img { max-width: 100%; max-height: 65vh; border-radius: 12px; }
.slideshow .caption { color: var(--muted); margin-top: .5rem; }
.slideshow .controls { margin-top: 1rem; display: flex; gap: .6rem; justify-content: center; align-items: center; }

.auth-wrap { max-width: 380px; margin: 3rem auto; }
.row-actions { display: flex; gap: .5rem; }

/* The six-digit sign-in code. Big, monospaced, generously spaced — you are copying digits across
   from another screen, and every bit of legibility is worth it. */
.code-input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.6rem;
  letter-spacing: .35em; text-align: center; padding: .6rem; }

/* Sign-in: the "email me a link instead" way out, under the password box. It's a submit button, so
   it needs to out-specify `input[type=submit]` to stop looking like the primary action — it's the
   fallback, not the thing most people came here to press. */
.auth-alt { margin-top: 1rem; padding-top: .85rem; border-top: 1px solid var(--border); }
input[type=submit].linkish, button.linkish {
  background: none; color: var(--muted); padding: 0; font-weight: 400;
  text-decoration: underline; box-shadow: none;
}
input[type=submit].linkish:hover, button.linkish:hover { color: var(--accent); filter: none; }
/* The address carried into the password step — shown, not editable. */
input.readonly { background: var(--bg); color: var(--muted); }

/* Hydration: "just tap it". Big, thumb-sized targets — this is a button you press ten times a day
   on a phone, not a form you fill in. */
.water-taps { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: .9rem; }
.water-tap-form { display: contents; }
.water-tap { display: flex; flex-direction: column; align-items: center; gap: .1rem;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: .55rem .9rem; min-width: 5.5rem; cursor: pointer; }
.water-tap:hover { border-color: var(--accent); background: #fff; filter: none; }
.water-tap-name { font-weight: 600; font-size: .9rem; }
.water-tap-size { font-size: .78rem; color: var(--muted); font-weight: 400; }
.water-custom { display: flex; align-items: center; gap: .4rem; }
.water-custom input[type=number] { width: 5rem; }
.cal-fill.water-fill { background: #5bb6d6; }   /* out-specify .cal-fill, declared later */

/* Today's drinks: one chip per tap, each removable — which is the whole reason water is rows and
   not a counter. */
.water-log { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .9rem;
  padding-top: .75rem; border-top: 1px solid var(--border); }
.water-chip { display: inline-flex; align-items: center; gap: .3rem; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 999px; padding: .2rem .3rem .2rem .65rem;
  font-size: .85rem; }
.water-chip form { display: inline-flex; }
.water-undo { font-size: 1rem; line-height: 1; padding: 0 .25rem; }

/* Sharing (#20): the scope chips, the coach's banner, the public report page. */
.link-card { padding: .75rem .85rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel-2); }
.link-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.link-copy { display: flex; gap: .5rem; margin-top: .6rem; }
.link-copy input { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .8rem; background: var(--bg); }
.share-row-actions { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; margin-top: .6rem; padding-top: .6rem; border-top: 1px solid var(--border); }
.cadence-form { display: flex; align-items: center; gap: .5rem; }
.cadence-form label { white-space: nowrap; }
.cadence-form select { width: auto; }
.share-scopes { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: .5rem 0 .9rem; }
.shared-bar { background: #4a3543; }
.report-head { margin: 2rem 0 1rem; }
.report-head h1 { margin-bottom: .2rem; }
.report-footer { margin: 2rem 0 3rem; text-align: center; }
.report-photo { margin: 0; }
.report-photo img { width: 100%; height: 180px; object-fit: cover; border-radius: 8px; }

/* Settings › Food: the meal editor. One row per meal — reorder, rename, retime, remove. */
.meal-list { display: flex; flex-direction: column; gap: .5rem; margin: .75rem 0 1rem; }
.meal-row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }
.meal-row-form { display: flex; align-items: center; gap: .6rem; flex: 1 1 auto; }
.meal-row-form .field { margin: 0; }
.meal-row-form input[type=text] { min-width: 9rem; }
.meal-order { display: flex; gap: .15rem; }
.meal-order form { display: inline; }
.meal-order .linkish { font-size: 1rem; padding: 0 .2rem; }
.meal-order .linkish:disabled { opacity: .25; cursor: default; }

/* An explanation that belongs to the page, not a passing toast. Two paragraphs on purpose: what
   happened, then what to do about it — one run-on sentence makes the reader find the second half. */
.note { margin: 0 0 1rem; padding: .65rem .85rem; border-radius: 8px; font-size: .9rem;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text); }
.note p { margin: 0; }
.note p + p { margin-top: .5rem; }

/* The "no account for that address" message on the sign-up page: an error, wearing the error's
   clothes, but part of the page rather than a flash — so no dismiss button. */
.note-error p { margin: 0; }
.note-error p + p { margin-top: .45rem; }
.note-error a { color: inherit; text-decoration: underline; font-weight: 600; }

/* "or" rule between the email form and the Google button. */
.auth-or { display: flex; align-items: center; gap: .75rem; margin: 1.25rem 0 1rem; color: var(--muted);
  font-size: .8rem; }
.auth-or::before, .auth-or::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* Google's brand guidelines: their button is white with their own G, not our accent colour —
   people look for a button that matches what they see everywhere else. */
.btn-google { display: inline-flex; align-items: center; justify-content: center; gap: .6rem;
  width: 100%; background: #fff; color: #1f1f1f; border: 1px solid #dadce0; border-radius: 8px;
  padding: .6rem 1rem; font-weight: 500; box-shadow: none; }
.btn-google:hover { background: #f7f8f8; filter: none; border-color: #d2d5d9; }
.btn-google .google-g { flex: 0 0 auto; }

/* "Confirm it's you" — the step-up gate on the account panel. */
.confirm-gate { margin-top: .5rem; padding: .85rem 1rem; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); }
.confirm-gate p:first-child { margin-top: 0; }

/* Exercise logging */
.ex-block { padding: .8rem 0; border-bottom: 1px solid var(--border); }
.ex-block:last-child { border-bottom: none; }
.ex-head { margin-bottom: .4rem; }
.entry-list { list-style: none; margin: 0 0 .5rem; padding: 0; }
.entry-list li { display: flex; align-items: center; gap: .5rem; padding: .2rem 0; }
.entry-del { font-size: 1.1rem; line-height: 1; }
.entry-del:hover { color: var(--bad); }
.reading-day-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .3rem; }
.log-day { padding: .3rem 0 .8rem; border-bottom: 1px solid var(--border); margin-bottom: .4rem; }
.log-day:last-child { border-bottom: none; }
.log-date { display: inline-block; font-size: .8rem; font-weight: 700; color: #fff;
  background: var(--accent); padding: .25rem .7rem; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: .55rem; }
.log-day .entry-list li { flex-wrap: wrap; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; }
.log-more { text-align: right; margin-top: .6rem; }

/* Habit tracker — one row per activity, cells per day */
.habit-grid { overflow-x: auto; padding-bottom: .2rem; }
/* width:max-content so the row box spans its full content, not just the scrollport — without it the
   sticky label's containing block is clipped to the visible width and scrolls away instead of pinning. */
.habit-row { display: flex; align-items: center; gap: .5rem; margin-bottom: 3px; width: max-content; }
.habit-label { flex: 0 0 130px; width: 130px; text-align: right; font-size: .8rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  /* Pinned to the left so the row labels stay visible while the day cells scroll (the grid loads
     scrolled to the most-recent end via the scroll-end controller). Opaque so cells pass behind. */
  position: sticky; left: 0; z-index: 1; background: var(--panel); }
.habit-label a { color: var(--text); }
.habit-label a:hover { color: var(--accent); }
.habit-cells { display: flex; gap: 2px; }
.habit-streak { flex: 0 0 auto; min-width: 42px; margin-left: .5rem; text-align: left;
  font-size: .8rem; color: var(--muted); white-space: nowrap; }
.habit-streak.streak-on { color: var(--accent); font-weight: 600; }
.hm-cell { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }
.hm-cell:hover { outline: 1px solid var(--accent); outline-offset: 1px; }
/* Empty day: a muted cell that recedes into the theme (a bright fixed grey shouted on dark themes),
   with a diagonal slash in the muted colour so it still clearly reads as "none". */
.hm-0 { background: var(--bg-2);
  /* A softened slash — still legible as "none", but blended toward transparent so it doesn't read as
     bold, high-contrast marks against the muted cell. */
  background-image: linear-gradient(135deg, transparent 43%,
    color-mix(in oklab, var(--muted) 42%, transparent) 43%,
    color-mix(in oklab, var(--muted) 42%, transparent) 57%, transparent 57%); }
/* Activity intensity, derived from the theme's accent so it fits every palette (rose on Blossom,
   green on Mint, pink on Midnight). The cell count is [times done, 4].min, so hm-1 is "did it once"
   — by far the most common "done" state, and it must read as *clearly done*, a stark jump from an
   empty day, not a faint tint one step above nothing. So hm-1 already lands at a strong accent, and
   hm-2..hm-4 (twice, three times, 4+ — all rarer) intensify from there up to and just past full. */
.hm-1 { background: color-mix(in oklab, var(--bg) 32%, var(--accent)); }
.hm-2 { background: color-mix(in oklab, var(--bg) 16%, var(--accent)); }
.hm-3 { background: var(--accent); }
.hm-4 { background: color-mix(in oklab, var(--accent) 80%, var(--accent-2)); }
.heatmap-legend { display: flex; align-items: center; gap: 4px; margin-top: .5rem; }
.heatmap-legend .hm-cell { display: inline-block; }

/* Settings tab bar */
.tabs { display: flex; flex-wrap: wrap; gap: .2rem; margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border); }
.tab { background: none; color: var(--muted); border: none;
  border-bottom: 2px solid transparent; border-radius: 8px 8px 0 0;
  padding: .55rem .95rem; font-weight: 600; font-size: .95rem; cursor: pointer; }
.tab:hover { color: var(--accent); filter: none; }
.tab-on { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.tab-panel-on { display: block; }

/* Toggle switch — reusable replacement for bare checkboxes */
.toggle { display: inline-flex; align-items: center; gap: .6rem; cursor: pointer;
  color: var(--text); font-size: .95rem; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-track { position: relative; flex: 0 0 auto; width: 42px; height: 24px;
  background: var(--toggle-off); border-radius: 999px; transition: background .15s ease; }
.toggle-track::after { content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .15s ease; }
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(18px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle input:disabled + .toggle-track { opacity: .5; cursor: default; }

/* Floating toast for transient flash notices (seen regardless of scroll) */
.flash-toast { position: fixed; top: 1rem; left: 50%; transform: translateX(-50%);
  z-index: 1000; min-width: 240px; max-width: 90vw; text-align: center;
  box-shadow: var(--shadow); cursor: pointer; animation: toastIn .2s ease-out; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); } }
.flash-toast.hiding { opacity: 0; transition: opacity .4s ease; }

/* BMI settings */
/* Subsection headers within a panel: a divider line + breathing room above each. */
.subhead { margin: 1.5rem 0 .5rem; padding-top: 1.5rem; font-size: 1rem;
  border-top: 1px solid var(--border); }
.subhead + .small.muted { margin-top: 0; }
.height-row { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; }
.height-row .field { margin-bottom: 0; }
.height-row .hgrow { flex: 1 1 8rem; }   /* stretch selector + inputs to fill the row */
.height-row .hsave { flex: 0 0 auto; }
.cat-actions { display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; margin-top: .9rem; }

/* Exercises tab */
.ex-list { display: flex; flex-direction: column; }
.ex-row { display: flex; align-items: center; gap: .7rem; padding: .55rem 0;
  border-bottom: 1px solid var(--border); }
.ex-row:last-child { border-bottom: none; }
.ex-toggle-form { margin: 0; }
.ex-main { flex: 1 1 auto; display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.ex-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Name + Kind share a line; Name grows. */
.ex-namekind { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.ex-namekind .field { margin-bottom: 0; }
/* Per-kind default fields + inline Add button sit on one wrapping row. */
.kfields-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: .3rem; }
.kf-submit { margin-left: auto; }
.kfields { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.kfields .field { margin-bottom: 0; flex: 0 0 auto; }
.kfields input[type="number"] { width: 6rem; }
.kfields select { width: auto; }
/* Appearance / theme swatches */
.theme-grid { display: flex; flex-wrap: wrap; gap: .9rem; margin-top: .3rem; }
.theme-swatch { position: relative; display: flex; flex-direction: column; align-items: center;
  gap: .35rem; width: 88px; cursor: pointer; }
.theme-swatch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.swatch-preview { width: 88px; height: 58px; border-radius: 10px; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; }
.sw-card { width: 60%; height: 58%; border-radius: 6px; display: flex; gap: 5px;
  align-items: center; justify-content: center; box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.sw-dot { width: 13px; height: 13px; border-radius: 50%; }
.sw-name { font-size: .8rem; color: var(--muted); }
.sw-custom { font-size: 1.7rem; background: var(--panel-2); }
.theme-swatch input:checked + .swatch-preview { outline: 3px solid var(--accent); outline-offset: 2px; }
.theme-swatch input:checked ~ .sw-name { color: var(--accent); font-weight: 600; }

.starter-list { display: flex; flex-wrap: wrap; gap: .5rem; }
.starter-btn { display: inline-flex; align-items: center; gap: .4rem; }
.starter-btn form, .starter-list form { margin: 0; }
/* A settings group that greys out until its precondition is met (BMI needs a height;
   meal times need the time-of-day switch on). Disabling the fieldset blocks it too. */
.lockable { border: 0; margin: 0; padding: 0; min-width: 0; }
.lockable:disabled { opacity: .5; }
/* A locked field on the meal editor: the start times mean nothing with the guess switched off. */
.field.locked { opacity: .5; }
.locked-note { margin: 1.5rem 0 0; padding: .6rem .85rem; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  font-size: .9rem; font-weight: 600; }
/* The hour selects sit in an .inline-form, whose fields have no bottom margin — so the
   Save button needs its own gap or it crowds them. */
.meal-times input[type=submit] { margin-top: 1rem; }
.bmi-cat-row { display: flex; align-items: end; gap: .6rem; margin-bottom: .5rem; }
.bmi-cat-row .field { margin-bottom: 0; flex: 1 1 0; }
.bmi-cat-row .bmi-min { flex: 0 0 90px; }
.bmi-cat-row .bmi-color { flex: 0 0 60px; }
.bmi-cat-row input[type=color] { height: 38px; padding: 2px; cursor: pointer; }
.bmi-remove { flex: 0 0 auto; }
/* BMI card on the weight page */
.stat .cat-pill { display: inline-block; margin-top: .25rem; padding: .1rem .5rem;
  border-radius: 999px; font-size: .75rem; font-weight: 600; color: #fff; }

/* Admin: the impersonation bar. Deliberately loud and unlike the rest of the app — the failure
   mode to prevent is an admin forgetting whose account they're in. */
.impersonation-bar { position: sticky; top: 0; z-index: 1500; display: flex; flex-wrap: wrap;
  align-items: center; justify-content: space-between; gap: .6rem;
  padding: .55rem 1rem; background: #b45309; color: #fff; font-size: .9rem; }
.impersonation-bar.writing { background: var(--bad); }
.impersonation-bar strong { color: #fff; }
.impersonation-bar .small { opacity: .85; }
.impersonation-bar .imp-actions { display: flex; gap: .4rem; }
.impersonation-bar form { margin: 0; }
.impersonation-bar .btn-sm { background: #fff; color: #7c2d12; border: 0; }
.impersonation-bar .btn-ghost { background: transparent; color: #fff; border: 1px solid #fff; }

/* Admin panel */
.nav-admin { font-weight: 600; }

/* Development-only nav item (Mail). Dotted underline so it reads as scaffolding, not product —
   nobody should mistake it for something their users can see. */
.nav-dev { font-weight: 600; text-decoration: underline dotted; text-underline-offset: 3px; }

/* The letter_opener_web inbox, framed. It's a two-pane UI (list + preview) and wants room; a short
   frame would put a scrollbar inside a scrollbar. */
.mail-frame { display: block; width: 100%; height: 75vh; min-height: 30rem; border: 1px solid var(--border);
  border-radius: .5rem; background: #fff; }
.admin-nav { display: flex; flex-wrap: wrap; align-items: baseline; gap: 1rem; margin: -.4rem 0 1rem; }
.admin-table { width: 100%; border-collapse: collapse; margin-top: .75rem; }
.admin-table th { text-align: left; font-size: .75rem; text-transform: uppercase;
  letter-spacing: .03em; color: var(--muted); border-bottom: 1px solid var(--border);
  padding: .35rem .5rem; }
.admin-table td { padding: .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.admin-table tr:last-child td { border-bottom: 0; }
.pill { display: inline-block; padding: .05rem .45rem; border-radius: 999px; font-size: .7rem;
  font-weight: 700; background: var(--accent); color: #fff; vertical-align: middle; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 700px) { .grid-2 { grid-template-columns: 1fr; } }

/* Admin › Backups */
.backup-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.backup-row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  white-space: nowrap; }
.backup-row-actions form { margin: 0; }
.restore-form { display: flex; align-items: center; gap: .3rem; }
.restore-phrase { width: 8rem; font-size: .8rem; padding: .25rem .4rem; }

/* Settings › Account */
.data-counts { display: flex; flex-wrap: wrap; gap: .35rem .9rem; color: var(--muted);
  font-size: .9rem; margin-top: .5rem; }
.data-counts strong { color: var(--heading); }
.radio-line { display: flex; align-items: baseline; gap: .5rem; margin-bottom: .4rem;
  color: var(--text); font-size: .9rem; cursor: pointer; }
.radio-line input { flex: 0 0 auto; }
.danger-head { color: var(--bad); }
.danger-zone { border: 1px solid var(--bad); border-radius: 10px; padding: .9rem 1rem;
  background: color-mix(in srgb, var(--bad) 5%, transparent); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }

/* Dashboard entry rows: name on the left, what was logged on the right. */
.dash-row { display: flex; align-items: baseline; gap: .6rem; }
.dash-main { flex: 1 1 auto; min-width: 0; }
.dash-date { flex: 0 0 3.5rem; }

/* Food journal */
.food-total { margin: .2rem 0 .6rem; }
.food-total .big { font-size: 1.7rem; font-weight: 700; color: var(--heading); }
.cal-bar { height: 8px; border-radius: 999px; background: var(--panel-2);
  overflow: hidden; margin-top: .45rem; max-width: 340px; }
.cal-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .2s ease; }

/* The day's two numbers, side by side: calories on the left, the macro split on the right (#11).
   Wraps to stacked on a phone rather than squeezing both — the bar is useless at 80px wide. */
.day-totals { display: flex; flex-wrap: wrap; gap: 1rem 2.5rem; align-items: flex-start;
  justify-content: space-between; }
.macro-total { flex: 1 1 260px; max-width: 420px; margin: .2rem 0 .6rem; }

/* Dashboard food card: the blocks (calories, optional macros, optional water) share the width
   evenly and stretch, so there's no dead gap in the middle — and they shrink as more are added.
   Each block is an equal-height column with its bar pinned to the bottom (margin-top:auto), so all
   three bars line up regardless of header height or a "no macros logged" note. Wraps on a phone. */
.dash-food-totals { justify-content: flex-start; gap: 1rem 1.5rem; align-items: stretch; }
.dash-food-totals > * { flex: 1 1 12rem; max-width: none; min-width: 0; margin: 0;
  display: flex; flex-direction: column; }
.dash-food-totals .db-line { margin: .1rem 0 0; }
.dash-food-totals .cal-bar,
.dash-food-totals .macro-bar { margin-top: auto; max-width: none; height: 8px; }
.macro-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem;
  justify-content: space-between; }
.macro-head .label { color: var(--muted); font-size: .85rem; }
.macro-figures { display: flex; gap: .7rem; font-size: .9rem; }
.macro-figure strong { color: var(--heading); font-weight: 600; }
/* Share of the day's total grams, shown next to each figure (e.g. 25g PROT · 50%). */
.macro-pct { color: var(--muted); font-variant-numeric: tabular-nums; }
.macro-pct::before { content: "· "; }

/* One bar, three segments. Widths are the share of grams — deliberately NOT of calories: this app
   never turns macros into energy (that's the 4/4/9 arithmetic we refuse to apply to the calorie
   field), so the bar shows exactly the numbers that were typed in. */
.macro-bar { display: flex; height: 10px; border-radius: 999px; background: var(--panel-2);
  overflow: hidden; margin-top: .45rem; }
.macro-seg { height: 100%; transition: width .2s ease; }
.macro-bar-empty { opacity: .6; }

/* Three colours that have to stay apart on all six themes. They're a categorical set defined per
   theme (Theme::BASE + overrides), NOT accent-derived — deriving them from accent/accent-2/good
   collapsed to three near-identical greens on Mint. See the macro-* vars in theme.rb. */
.macro-fat_grams     { background: var(--macro-fat); }
.macro-carb_grams    { background: var(--macro-carb); }
.macro-protein_grams { background: var(--macro-protein); }
.macro-figure.macro-fat_grams,
.macro-figure.macro-carb_grams,
.macro-figure.macro-protein_grams { background: none; }   /* the figures are text, not swatches */
.macro-figure::before { content: ""; display: inline-block; width: .55rem; height: .55rem;
  border-radius: 50%; margin-right: .3rem; }
.macro-figure.macro-fat_grams::before     { background: var(--macro-fat); }
.macro-figure.macro-carb_grams::before    { background: var(--macro-carb); }
.macro-figure.macro-protein_grams::before { background: var(--macro-protein); }
.food-macros { display: block; }
.field-macro input[type="number"] { width: 4.5rem; }

/* How much do you want to log? (#10) — the three levels, as tappable rows. */
.level-list { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.level-option { display: flex; align-items: flex-start; gap: .6rem; padding: .7rem .8rem;
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
  background: var(--panel); min-height: 44px; }
.level-option:hover { border-color: var(--accent); }
.level-option:has(input:checked) { border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent); background: var(--panel-2); }
.level-option input { margin-top: .2rem; flex: 0 0 auto; }
.level-body { display: flex; flex-direction: column; gap: .1rem; }
.level-name { font-weight: 600; color: var(--heading); }
.food-item { display: flex; align-items: center; gap: .6rem; }
.food-thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; flex: 0 0 auto; display: block; }
.food-thumb-link { flex: 0 0 auto; display: inline-flex; cursor: zoom-in; }
.food-thumb-link:hover .food-thumb { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Click-to-enlarge photo lightbox */
.lightbox { position: fixed; inset: 0; z-index: 2000; display: none; align-items: center;
  justify-content: center; padding: 2rem; background: rgba(0, 0, 0, 0.78); cursor: zoom-out; }
.lightbox.open { display: flex; }
.lightbox img { max-width: 92vw; max-height: 88vh; border-radius: 10px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5); }
.food-desc { flex: 1 1 auto; min-width: 0; }
.food-cal { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.quick-thumb { width: 20px; height: 20px; object-fit: cover; border-radius: 4px; vertical-align: middle; }

/* Quick add / Recent foods: a meal picker that governs whichever chip you tap.
   Ruled off from the Log-food form above it, which has a meal dropdown of its own. */
.quick-add { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.meal-chips { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem;
  margin: 0 0 .75rem; }
.meal-chips > .small { margin-right: .25rem; }
.meal-chip { position: relative; display: inline-flex; }
.meal-chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.meal-chip span { display: inline-block; padding: .3rem .7rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--muted);
  font-size: .85rem; cursor: pointer; user-select: none; }
.meal-chip span:hover { border-color: var(--accent); color: var(--text); }
.meal-chip input:checked + span { background: var(--accent); border-color: var(--accent);
  color: #fff; font-weight: 600; }
.meal-chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
/* A chip pairs the "add" button with a ☆ that promotes it into Quick Add. */
.food-chip { display: inline-flex; align-items: center; gap: .15rem; }
.chip-star { padding-left: .35rem; padding-right: .35rem; color: var(--muted); }
.chip-star:hover { color: var(--accent); }
.entry-star { font-size: 1.05rem; line-height: 1; color: var(--muted); }
.entry-star:hover { color: var(--accent); }
/* Log-food form: keep inputs + button on one line; description grows, calories is small. */
.food-form .field { flex: 0 0 auto; }
.food-form .food-desc { flex: 3 1 14rem; }
.food-form select { width: auto; }
.food-form input[type="number"] { width: 5rem; }
.food-form input[type="file"] { max-width: 200px; }

.range-bar { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: 1rem; }
.chip {
  padding: .35rem .8rem; border-radius: 999px; font-size: .85rem;
  background: var(--panel); border: 1px solid var(--border); color: var(--muted);
}
.chip:hover { color: var(--accent); text-decoration: none; }
.chip-on { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }

/* ---- Setup wizard (#3) ---------------------------------------------------- */
.wizard { max-width: 40rem; margin: 1.5rem auto; }
.wizard-card { padding: 1.6rem 1.5rem; }

/* Progress line over the numbered steps. */
.wizard-progress { margin-bottom: .9rem; }
.wizard-progress-label { font-size: .8rem; color: var(--muted); }
.wizard-progress-track { height: 6px; border-radius: 999px; background: var(--panel-2);
  overflow: hidden; margin-top: .35rem; }
.wizard-progress-fill { height: 100%; background: var(--accent); border-radius: 999px;
  transition: width .25s ease; }

/* Hero (welcome / done). */
.wizard-hero { text-align: center; padding: .5rem 0; }
.wizard-mark { font-size: 2.6rem; line-height: 1; }
.wizard-hero h1 { color: var(--heading); margin: .6rem 0 .4rem; }
.wizard-lede { color: var(--muted); line-height: 1.55; max-width: 32rem; margin: 0 auto 1.2rem; }
.wizard-cta { display: flex; flex-direction: column; align-items: center; gap: .5rem; margin-top: 1rem; }
.wizard-secondary { margin-top: .2rem; }

/* Configuration steps. */
.wizard-title { color: var(--heading); margin: 0 0 .3rem; }
.wizard-blurb { color: var(--muted); line-height: 1.5; margin: 0 0 1.1rem; }
.wizard-form .field { margin-bottom: 1rem; }
.wizard-rule { border: none; border-top: 1px solid var(--border); margin: 1.2rem 0; }
.wizard-row { display: flex; flex-wrap: wrap; gap: 1rem; }
.wizard-row .field { flex: 1 1 10rem; }

/* Back / Continue row. */
.wizard-nav { display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; margin-top: 1.4rem; }

/* Feature toggles, as roomy rows with a description. */
.wizard-toggles { display: flex; flex-direction: column; gap: .3rem; }
.wizard-toggle { display: flex; align-items: flex-start; gap: .7rem; padding: .7rem .6rem;
  border-radius: 10px; cursor: pointer; }
.wizard-toggle:hover { background: var(--panel-2); }
.wizard-toggle-body { display: flex; flex-direction: column; gap: .1rem; }
.wizard-toggle-name { font-weight: 600; color: var(--heading); }
/* Hide the native checkbox and drive the shared .toggle-track from it, same as .toggle does. */
.wizard-toggle input[type="checkbox"] { position: absolute; opacity: 0; width: 1px; height: 1px; }
.wizard-toggle input:checked + .toggle-track { background: var(--accent); }
.wizard-toggle input:checked + .toggle-track::after { transform: translateX(18px); }
.wizard-toggle input:focus-visible + .toggle-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Connect step info cards. */
.wizard-info { display: flex; flex-direction: column; gap: .8rem; margin: 1rem 0; }
.wizard-info-item { display: flex; gap: .8rem; align-items: flex-start; padding: .8rem;
  border: 1px solid var(--border); border-radius: 10px; }
.wizard-info-icon { font-size: 1.5rem; line-height: 1; }
.wizard-info-item p { margin: .2rem 0 0; }

.wizard-summary { text-align: left; max-width: 30rem; margin: 1rem auto 0; line-height: 1.7;
  list-style: none; padding: 0; }
.wizard-summary li { padding: .3rem 0; border-bottom: 1px solid var(--border); }

.wizard-escape { text-align: center; margin-top: 1rem; }
.btn-lg { font-size: 1.05rem; padding: .8rem 2rem; }

.setup-again { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; padding: .8rem 1rem; margin-bottom: 1.2rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--panel-2); }
.setup-again strong { display: block; color: var(--heading); }
.setup-again .btn { flex: 0 0 auto; }

/* Height entered inline: the unit dropdown sits on the same row as the input(s). */
.height-inline { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.height-inline select { width: auto; flex: 0 0 auto; }
.height-ftin, .height-cm { display: inline-flex; align-items: center; gap: .35rem; }
.height-inline input[type="number"] { width: 4.5rem; }
.height-unit-label { color: var(--muted); font-size: .85rem; }

/* Admin › Email panel controls */
.email-controls { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; align-items: center;
  justify-content: space-between; margin-bottom: 1rem; }
.email-range { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.email-bucket { display: flex; align-items: center; gap: .4rem; margin: 0; }
.email-bucket select { width: auto; }

/* Settings › Connections. Three plain sections; grouped setup steps in soft bordered blocks so the
   token form, the phone steps, and the Claude steps read as distinct things, not one long scroll. */
.subhead-first { padding-top: 0; }
.conn-token-form { margin: .6rem 0 1rem; }
.conn-tokens { margin: .5rem 0 0; }
.conn-block { border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2);
  padding: .8rem 1rem; margin: .5rem 0; }
.conn-block-title { font-weight: 600; color: var(--heading); margin: 0 0 .3rem; }
.conn-block p:last-child { margin-bottom: 0; }
.conn-steps { margin: .4rem 0 .6rem 1.1rem; padding: 0; color: var(--muted); font-size: .9rem; }
.conn-steps li { margin: .2rem 0; }
.conn-indent { margin-left: 1.1rem; }
.conn code { background: var(--panel); border: 1px solid var(--border); border-radius: 5px;
  padding: .05rem .32rem; font-size: .85em; word-break: break-word; }
.conn-json { background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: .7rem .85rem; margin: .3rem 0 .6rem; font-size: .78rem; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word; }
.conn-advanced { margin: .3rem 0 .6rem; }
.conn-advanced summary { cursor: pointer; color: var(--muted); }

/* ---- Settings: per-section pages with a left-nav (#7) ---------------------- */
.settings-layout { display: flex; gap: 1.25rem; align-items: flex-start; }
.settings-content { flex: 1 1 auto; min-width: 0; margin-bottom: 1.25rem; }

.settings-nav { flex: 0 0 11rem; display: flex; flex-direction: column; gap: .15rem;
  position: sticky; top: 1rem; }
.settings-nav-item { display: block; padding: .5rem .75rem; border-radius: 8px; color: var(--muted);
  font-size: .95rem; line-height: 1.2; }
.settings-nav-item:hover { background: var(--panel-2); color: var(--accent); text-decoration: none; }
.settings-nav-item.is-active { background: var(--accent); color: #fff; font-weight: 600; }
.settings-nav-item.is-active:hover { color: #fff; }

/* On a phone the sidebar becomes a wrapping row of pills above the content. */
@media (max-width: 720px) {
  /* Stretch, not flex-start: as a column the content card would otherwise size to its max-content
     width and spill past the viewport. Desktop keeps flex-start (sidebar + content top-aligned). */
  .settings-layout { flex-direction: column; align-items: stretch; }
  .settings-nav { flex: none; width: 100%; flex-direction: row; flex-wrap: wrap;
    position: static; gap: .3rem; margin-bottom: .25rem; }
  .settings-nav-item { padding: .4rem .7rem; border: 1px solid var(--border); }
  .settings-nav-item.is-active { border-color: var(--accent); }
}

.bmi-reset { margin-top: .6rem; }
.custom-theme-save { margin-top: .6rem; }

/* Workout route map (Leaflet). Needs an explicit height or Leaflet renders 0px. */
.route-map { height: 340px; width: 100%; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border); }
.route-map .leaflet-container { background: var(--panel-2); }

/* ============================================================================
   Sleep (#6). Stage colours are derived from the theme's accents rather than
   fixed, so the panel fits every palette — the lesson from the habit tracker.
   ============================================================================ */
/* Fields sharing a line (night / bedtime / wake time / submit), wrapping on a narrow screen. */
.field-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: .4rem; }
.field-row .field { margin-bottom: 0; flex: 1 1 9rem; }
.field-row .field-night { flex: 1 1 11rem; }   /* a date needs a touch more room than a time */

.sleep-row { padding: .75rem 0; border-bottom: 1px solid var(--border); }
.sleep-row:last-child { border-bottom: 0; }
.sleep-row-head { display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; }
.sleep-date { font-weight: 600; }
.sleep-figures { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }

/* One night's stages, proportional — the macro bar's sibling. The 2px surface-coloured gap
   between segments is load-bearing, not decoration: it keeps adjacent fills from reading as one
   blob at this height. */
.stage-bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden;
  background: var(--panel-2); margin: .5rem 0 .4rem; gap: 2px; }
.stage-seg { height: 100%; transition: width .2s ease; }
.stage-deep  { background: var(--sleep-deep); }
.stage-core  { background: var(--sleep-core); }
.stage-rem   { background: var(--sleep-rem); }
.stage-awake { background: var(--sleep-awake); }
.stage-figures { display: flex; flex-wrap: wrap; gap: .75rem; color: var(--muted); }
.stage-figure { display: inline-flex; align-items: center; gap: .3rem; }
.stage-figure strong { color: var(--text); }
.stage-dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* Overnight vitals: sparse by nature, so this is a wrapping row of whatever exists. */
.vitals-row { display: flex; flex-wrap: wrap; gap: .9rem; margin-top: .5rem; }
.vital { display: inline-flex; align-items: baseline; gap: .3rem; font-size: .85rem; }
.vital-label { color: var(--muted); }
.vital-value { font-weight: 600; }

/* Which reading a night is using, and the pin that overrides it. */
.reading-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.reading-row:last-child { border-bottom: 0; }
.reading-row.is-current { color: var(--text); }
.pill-current { background: var(--good); color: #fff; }
.pill-manual { background: var(--accent-2); color: #fff; }
.pill-chosen { background: var(--accent); color: #fff; }

/* ============================================================================
   Public landing page (pages#home, layouts/public). All scoped to the public
   pages so none of this touches the app itself. Theme-aware via the CSS vars.
   ============================================================================ */
.btn-accent { background: var(--accent); color: #fff; }

body.public { background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%); }

.pub-nav {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1080px; margin: 0 auto; padding: 1.1rem 1.25rem;
}
.pub-nav .brand { font-size: 1.2rem; }
.pub-nav-links { display: flex; align-items: center; gap: 1rem; }
.pub-link { color: var(--muted); font-weight: 600; }
.pub-link:hover { color: var(--accent); }

.landing { max-width: 1080px; margin: 0 auto; padding: 0 1.25rem; }
.landing .section-title {
  font-size: 1.7rem; color: var(--heading); text-align: center; margin: 0 0 1.5rem;
}

/* --- Hero --- */
.hero {
  display: grid; grid-template-columns: 1.05fr 1fr; gap: 3rem; align-items: center;
  padding: 3.5rem 0 4rem;
}
.hero-title {
  font-size: clamp(2.2rem, 5vw, 3.4rem); line-height: 1.08; margin: 0 0 1rem;
  color: var(--heading); letter-spacing: -0.02em;
}
.hero-sub { font-size: 1.15rem; line-height: 1.55; color: var(--text); margin: 0 0 1.6rem; max-width: 34ch; }
.hero-cta { display: flex; flex-wrap: wrap; gap: .8rem; margin-bottom: 1rem; }
.hero-note { margin: 0; }

.hero-art { display: flex; justify-content: center; }
.mock-card {
  width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); padding: 1.1rem 1.2rem 1.3rem;
}
.mock-card-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .6rem; }
.mock-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.mock-chart { width: 100%; height: auto; display: block; }
.mock-stats { display: flex; gap: 1rem; margin-top: .9rem; }
.mock-stat { display: flex; flex-direction: column; flex: 1; }
.mock-stat-n { font-size: 1.25rem; font-weight: 700; color: var(--heading); }

/* --- Features --- */
.features { padding: 2rem 0 3rem; }
.feature-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.1rem;
}
.feature {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 1.4rem; box-shadow: var(--shadow);
}
.feature-icon { font-size: 1.8rem; line-height: 1; margin-bottom: .7rem; }
.feature h3 { margin: 0 0 .5rem; font-size: 1.1rem; color: var(--heading); }
.feature p { margin: 0; color: var(--text); line-height: 1.5; font-size: .95rem; }

/* --- Integrations / data-ownership strip --- */
.strip { padding: 2.5rem 0; }
.strip-inner {
  display: grid; grid-template-columns: 1fr 1fr; gap: 2.5rem;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 18px;
  padding: 2.2rem;
}
.strip-copy .section-title { text-align: left; font-size: 1.4rem; margin-bottom: .8rem; }
.strip-copy p { margin: 0 0 1rem; line-height: 1.55; }
.strip-list { list-style: none; padding: 0; margin: 0; }
.strip-list li { padding: .3rem 0; color: var(--text); }

/* --- Final CTA --- */
.cta-band {
  text-align: center; padding: 3.5rem 1.5rem 4rem; margin: 2rem 0 3rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 20px; color: #fff;
}
.cta-band h2 { color: #fff; font-size: 1.8rem; margin: 0 0 1.3rem; }
.cta-band .btn-accent { background: #fff; color: var(--accent); }
.cta-band .muted { color: rgba(255,255,255,0.85); margin: .9rem 0 0; }

/* --- Footer --- */
.pub-footer { border-top: 1px solid var(--border); margin-top: 1rem; }
.pub-footer-inner {
  max-width: 1080px; margin: 0 auto; padding: 1.6rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.pub-footer-links { display: flex; gap: 1.1rem; }
.pub-footer-links a { color: var(--muted); }
.pub-footer-links a:hover { color: var(--accent); }

@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; gap: 2rem; padding: 2rem 0 2.5rem; text-align: center; }
  .hero-sub { max-width: none; }
  .hero-cta { justify-content: center; }
  .hero-art { order: -1; }
  .feature-grid { grid-template-columns: 1fr; }
  .strip-inner { grid-template-columns: 1fr; gap: 1.8rem; padding: 1.6rem; }
}
@media (max-width: 560px) {
  .pub-nav { padding: .9rem 1rem; }
  .pub-nav-links { gap: .6rem; }
}

/* ============================================================================
   Mobile refinements (audited 2026-07-26 — see ai/MOBILE_PLAN.md)
   All additive / mobile-only: desktop layout above these breakpoints is unchanged.
   ============================================================================ */

/* 2. Inline add-forms wrap tidily on a phone instead of full-column stacking.
   The first pass forced a full-width column — correct (no more crushed date / clipped button) but it
   wasted a whole row on every tiny field. Instead, keep the row and let it WRAP, sizing each field by
   its input type so compact ones share a line: numbers stay narrow (several across), date/time get
   room, text/notes take a full row. Ghost/link buttons sit inline; the primary submit spans its row.
   Scoped with :not(.food-form) so the bespoke food logger keeps its own layout.
   (`.inline-form` already sets flex-wrap:wrap + align-items:end; the missing piece was per-field
   sizing so fields wrap instead of shrinking to nothing.) */
@media (max-width: 560px) {
  .inline-form:not(.food-form) .field { flex: 1 1 auto; min-width: 0; margin-bottom: 0; }
  .inline-form:not(.food-form) .field > input,
  .inline-form:not(.food-form) .field > select,
  .inline-form:not(.food-form) .field > textarea { width: 100%; }
  .inline-form:not(.food-form) .field:has(> input[type="number"]) { flex-basis: 4.5rem; }
  /* min-width:auto (not the general 0) so a date/time field never shrinks below its native control:
     iOS date inputs don't shrink, so a too-narrow box let the control overflow into the next field.
     With auto, the field stays at least control-width and wraps to its own line if there's no room. */
  .inline-form:not(.food-form) .field:has(> input[type="date"]),
  .inline-form:not(.food-form) .field:has(> input[type="time"]) { flex-basis: 9rem; min-width: auto; }
  /* iOS Safari sizes native date/time controls by their own intrinsic width and IGNORES `width`
     until the native appearance is reset — so the control spilled past its box into the next field
     (min-width couldn't help; the control just didn't honour the box). Resetting appearance makes
     width:100% and the flex sizing actually constrain it. The app's border/padding/background still
     apply, and tapping still opens the iOS picker. Scoped to mobile so desktop controls are untouched.
     (Never reproduced on Firefox/Chromium — this is specific to the iOS native control.) */
  input[type="date"], input[type="time"] { -webkit-appearance: none; appearance: none; min-width: 0; }
  .inline-form:not(.food-form) .field:has(> input[type="text"]),
  .inline-form:not(.food-form) .field:has(> input[type="email"]),
  .inline-form:not(.food-form) .field:has(> textarea) { flex-basis: 100%; }
  /* the exercise loggers force a single nowrap row on desktop — let them wrap on a phone */
  .inline-form.entry-form { flex-wrap: wrap; }
  .inline-form.entry-form .field,
  .inline-form.entry-form .field:first-child { min-width: 0; }
  /* ghost / link buttons stay inline at natural width (Today, Apply range) */
  .inline-form:not(.food-form) > .btn-ghost,
  .inline-form:not(.food-form) > a.btn { flex: 0 0 auto; align-self: flex-end; }
  /* the primary submit spans whatever row it lands on — clear and tappable */
  .inline-form:not(.food-form) > input[type="submit"]:not(.btn-ghost),
  .inline-form:not(.food-form) > button[type="submit"]:not(.btn-ghost) { flex: 1 1 100%; }
}

/* 9. Sleep "Log a night" (a .field-row, not an .inline-form): date on its own row, the two times
   side by side, submit full-width. On real iOS the AM/PM time inputs are wide enough to wrap
   unevenly otherwise. */
@media (max-width: 560px) {
  /* Prefixed with .entry-form to out-specify `.entry-form .field:first-child` (0,3,0), which would
     otherwise force the date field to flex:1.5 1 0. No-shrink on the date and submit so each claims
     a full row and the two time fields pair up on the row between them. */
  .entry-form .field-row .field { flex: 1 1 7rem; min-width: 0; }
  .entry-form .field-row .field-night,
  .entry-form .field-row .field:has(> input[type="submit"]) { flex: 1 0 100%; }
}

/* 7. History tables (Weight, Measurements) don't wrap every cell to a different height on a phone —
   which made the flex `.row-actions` cell's bottom border float up above the others and look messy.
   Nowrap keeps rows uniform (borders align) and the .table-scroll wrapper lets them swipe sideways,
   same as the admin tables. */
@media (max-width: 560px) {
  .log-table { white-space: nowrap; }
}

/* 3. Compact stat-card grids pack 2-up on a phone instead of one-per-row.
   Scoped to `.grid.stat-2up` (the workout-detail metrics) rather than every `.grid`: the general
   grid floor of 200px stays, so cards with longer values (the dashboard's "30.59 / 39.09 in") keep
   their full width and don't wrap. Only these short label+number tiles pack two across, halving the
   workout-detail scroll. */
@media (max-width: 560px) {
  .grid.stat-2up { grid-template-columns: repeat(2, 1fr); }
}

/* 4. Wide tables scroll inside their own box instead of widening the whole page.
   Two techniques:
   (a) User-facing tables (Sharing, Connections) get a .table-scroll wrapper so cells keep wrapping
       naturally and it only scrolls when genuinely too wide. No width gate: a table that already
       fits never scrolls, so desktop is untouched.
   (b) Admin tables are dense and admin-only — below 760px turn each into its own horizontal-scroll
       block (nowrap keeps rows readable; swipe to see more columns). Markup-free, covers all of them
       (Users +316px was the worst), and desktop (>760px) is unchanged. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
@media (max-width: 760px) {
  .admin-table { display: block; overflow-x: auto; white-space: nowrap; max-width: 100%; }
}

/* ============================================================================
   Panel layout editor (Settings — reorder + show/hide a panel's cards)
   ============================================================================ */
.layout-editor { margin: .5rem 0 1rem; }
.layout-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.layout-row {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg);
}
.layout-row.is-dragging { opacity: .5; }
.layout-row.is-off { opacity: .6; }
.layout-handle { flex: 0 0 auto; cursor: grab; color: var(--muted); font-size: 1.1rem;
  line-height: 1; user-select: none; touch-action: none; }
.layout-handle:active { cursor: grabbing; }
.layout-card-label { flex: 1 1 auto; min-width: 0; font-weight: 600; color: var(--heading); }
.layout-card-label .muted { font-weight: 400; }
.layout-actions { flex: 0 0 auto; display: flex; align-items: center; gap: .3rem; }
.layout-move {
  border: 1px solid var(--border); background: var(--panel); color: var(--accent);
  border-radius: 7px; width: 30px; height: 30px; line-height: 1; font-size: .8rem;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.layout-move:hover { border-color: var(--accent); }
.layout-vis { margin-left: .2rem; }
.layout-hint { margin-top: .7rem; }
