/* ============================================================
   Family Command Centre — theme-base.css
   ------------------------------------------------------------
   STRUCTURE ONLY: layout, spacing, sizing, interaction states.
   No colour, font-family, radius or shadow value is hardcoded
   here — everything routes through the CSS custom properties
   defined in the active theme file (see css/theme-*.css).

   Layout is LANDSCAPE-FIRST: designed for a kitchen tablet or
   wall display in landscape, with portrait/mobile as fallback.
   ============================================================ */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }

html {
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  font-weight: var(--font-weight-heading);
  margin: 0;
  line-height: 1.25;
}

/* ---------- App frame: sidebar + main (landscape-first) ---------- */
.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--color-bg-accent);
  border-right: 1px solid var(--color-border);
  padding: var(--space-5) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3) var(--space-4);
}
.brand h1 {
  font-size: 1.15rem;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

/* Family photo — large centred upload button in the branding area.
   The edit/remove controls sit in a row BELOW the photo (see
   .brand-photo-actions), never on top of it, so neither can ever
   obscure any part of the image. */
.brand-photo-wrap { flex-shrink: 0; }
.brand-photo-btn {
  width: 176px; height: 176px;
  aspect-ratio: 1 / 1; /* guarantees a true circle no matter what — width/height alone can drift apart under some parent layouts */
  min-width: 176px; min-height: 176px;
  border-radius: 50%;
  border: 3px solid var(--color-border-strong);
  background: var(--color-card);
  cursor: pointer;
  position: relative; /* the photo itself is absolutely positioned inside — see below */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4.2rem;
  overflow: hidden;
  padding: 0;
  flex-shrink: 0;
  box-sizing: border-box;
}
/* Absolutely positioned so the photo can never influence this
   button's own box shape/size — the same fix, and the same reason,
   as the member-avatar photo fix (see theme-base.css member-avatar
   comment): an <img> child can subtly distort a flex/grid parent's
   metrics in a way plain text or an empty state never does. */
.brand-photo-btn img {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

/* Fallback house artwork (shown until a family photo is chosen).
   Must undo the absolute-fill rule above, which is meant for the
   user's photo: the house sits centred at ~2/3 of the circle. */
#brand-photo-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%; height: 100%;
}
.brand-photo-btn #brand-photo-fallback img {
  position: static;
  width: 66%; height: 66%;
  object-fit: contain;
  border-radius: 0;
}
.brand-photo-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}
.brand-photo-edit-badge {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: none;
  padding: 0;
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-size: 0.78rem;
  display: grid;
  place-content: center;
  cursor: pointer; /* a real button — opens the same photo picker as tapping the photo itself */
}
.brand-photo-remove {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: none;
  background: var(--color-danger);
  color: var(--color-on-primary);
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-content: center;
  padding: 0;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  min-height: 48px;                 /* touch-friendly */
  border: none;
  background: transparent;
  border-radius: var(--radius-control);
  cursor: pointer;
  font-family: var(--font-heading);
  font-size: 0.98rem;
  text-align: left;
  color: var(--color-text);
  transition: background 0.15s ease;
}
.nav-btn:hover { background: var(--color-card); }
.nav-btn.active {
  background: var(--color-primary);
  color: var(--color-on-primary);
  box-shadow: var(--shadow-card);
}
.nav-btn .nav-icon {
  width: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

/* Small image icon inline with heading/label text (e.g. the house
   next to "Family name" in Settings) — scales with the text size. */
img.inline-icon {
  width: 1.2em;
  height: 1.2em;
  max-width: none;
  vertical-align: -0.22em;
}

/* Centred artwork at the top of a modal body (e.g. the welcome
   modal's house, moved out of the title, which is text-only). */
img.modal-hero-icon {
  display: block;
  margin: 0 auto var(--space-2);
  width: 64px;
  height: 64px;
}

/* Image nav icons (assets/icons/*.png): transparent-background PNGs,
   auto-cropped so the artwork fills the box — sized against the 48px
   pill height for the same visual weight the emoji icons had. */
.nav-btn .nav-icon img {
  width: 30px;
  height: 30px;
  max-width: none; /* the global img{max-width:100%} collapses it to 0 inside the shrunk flex pill on mobile */
  display: block;
}

.sidebar-footer {
  margin-top: auto;
  padding: var(--space-3);
  font-size: 0.72rem;
  color: var(--color-text-muted);
  line-height: 1.4;
}

.main {
  padding: var(--space-5) var(--space-6);
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- Page headers ---------- */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}
.page-header h2 { font-size: 1.6rem; }
.page-header .page-sub {
  color: var(--color-text-muted);
  font-size: 0.92rem;
  margin-top: var(--space-1);
}

/* ---------- Cards ---------- */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
}
.card + .card { margin-top: var(--space-4); }

.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.card-title h3 {
  font-size: 1.02rem;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.card-title .count-pill {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  background: var(--color-card-alt);
  border-radius: var(--radius-pill);
  padding: 2px 10px;
}

/* ---------- Dashboard grid (landscape-first) ---------- */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--space-4);
  align-items: start;
}
.dash-grid .card { margin: 0; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }

/* Dashboard hero strip */
.hero {
  grid-column: span 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  flex-wrap: wrap;
}
.hero .today-date h2 { font-size: 1.7rem; }
.hero .today-date .hero-sub {
  color: var(--color-text-muted);
  margin-top: var(--space-1);
  font-size: 0.95rem;
}
.hero .family-quote {
  font-family: var(--font-accent);
  font-style: italic;
  font-size: 1.08rem;
  color: var(--color-text-muted);
  text-align: right;
  max-width: 46ch;
  cursor: pointer;
  border-radius: var(--radius-control);
  padding: var(--space-2) var(--space-3);
}
.hero .family-quote:hover { background: var(--color-card-alt); }

/* ---------- Lists ---------- */
.item-list { list-style: none; margin: 0; padding: 0; }
.item-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-2);
  border-bottom: 1px solid var(--color-border);
  min-height: 48px;
}
.item-row:last-child { border-bottom: none; }
.item-row .item-main { flex: 1; min-width: 0; }
.item-row .item-title { font-weight: 500; }
.item-row .item-title.done-text {
  text-decoration: line-through;
  color: var(--color-text-faint);
}
.item-row .item-meta {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 1px;
}
.item-row .item-actions {
  display: flex;
  gap: var(--space-1);
  opacity: 0.85;
}

.time-chip {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-muted);
  width: 76px;     /* fixed, not min-width — a floor still lets long labels
                       ("Mon 20 Jul") grow wider and shift the dot after it */
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Fixed-width "leading slot" so the coloured member dot that follows
   always lands in the same horizontal position on an .item-row,
   whatever comes before it — a checkbox, nothing at all, or (via
   .time-chip's own matching fixed width, in the same px unit so the
   two can never drift apart) a time/date label. Wrap a checkbox in
   this when it's immediately followed by memberDot(), or use it
   empty as a spacer when neither a checkbox nor a time precedes
   the dot. */
.row-lead {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 76px;
  flex-shrink: 0;
}

/* ---------- Badges, dots, chips ---------- */
.dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
.swatch-c1 { background: var(--member-c1); }
.swatch-c2 { background: var(--member-c2); }
.swatch-c3 { background: var(--member-c3); }
.swatch-c4 { background: var(--member-c4); }
.swatch-c5 { background: var(--member-c5); }
.swatch-c6 { background: var(--member-c6); }
.swatch-c7 { background: var(--member-c7); }
.swatch-c8 { background: var(--member-c8); }
.swatch-c9 { background: var(--member-c9); }
.swatch-c10 { background: var(--member-c10); }
.swatch-c11 { background: var(--member-c11); }
.swatch-c12 { background: var(--member-c12); }
.swatch-c13 { background: var(--member-c13); }
.swatch-c14 { background: var(--member-c14); }
.swatch-c15 { background: var(--member-c15); }
.swatch-c16 { background: var(--member-c16); }

.cat-chip {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--color-on-primary);
  border-radius: var(--radius-pill);
  padding: 2px 10px;
  text-transform: capitalize;
  flex-shrink: 0;
}
.cat-school { background: var(--cat-school); }
.cat-homework { background: var(--cat-homework); }
.cat-tutoring { background: var(--cat-tutoring); }
.cat-sport { background: var(--cat-sport); }
.cat-fitness { background: var(--cat-fitness); }
.cat-work { background: var(--cat-work); }
.cat-appointment { background: var(--cat-appointment); }
.cat-birthday { background: var(--cat-birthday); }
.cat-social { background: var(--cat-social); }
.cat-home { background: var(--cat-home); }
.cat-other { background: var(--cat-other); }

.badge {
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: var(--radius-pill);
  padding: 2px 10px;
}
.badge-overdue { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-soon { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-muted { background: var(--color-card-alt); color: var(--color-text-muted); }
.badge-done { background: var(--color-success-soft); color: var(--color-success); }
.badge-progress { background: var(--color-warning-soft); color: var(--color-warning); }

/* Calendar colour legend: member name + swatch, wraps on small widths. */
.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-4);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 46px;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  cursor: pointer;
  font-family: var(--font-heading);
  font-size: 0.95rem;
  transition: background 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
}
.btn-primary:hover { background: var(--color-primary-strong); }
.btn-secondary {
  background: var(--color-card);
  border-color: var(--color-border-strong);
  color: var(--color-text);
}
.btn-secondary:hover { background: var(--color-card-alt); }
.btn-danger {
  background: var(--color-danger-soft);
  color: var(--color-danger);
}
.btn-sm { min-height: 36px; padding: 2px var(--space-3); font-size: 0.85rem; }

/* Small icon-only action button (edit/delete on rows) */
.icon-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius-control);
  min-width: 40px;
  min-height: 40px;
  font-size: 1rem;
  color: var(--color-text-muted);
}
.icon-btn:hover { background: var(--color-card-alt); color: var(--color-text); }

/* ---------- Checkboxes (large, touch-friendly) ---------- */
.check {
  appearance: none;
  -webkit-appearance: none;
  width: 26px; height: 26px;
  flex-shrink: 0;
  border: 2px solid var(--color-border-strong);
  border-radius: var(--radius-checkbox);
  background: var(--color-card);
  cursor: pointer;
  display: inline-grid;
  place-content: center;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.check:checked {
  background: var(--color-success);
  border-color: var(--color-success);
}
.check:checked::after {
  content: "✓";
  color: var(--color-on-primary);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}

/* ---------- Forms ---------- */
.field { margin-bottom: var(--space-4); }
.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}
.field input[type="text"],
.field input[type="email"],
.field input[type="date"],
.field input[type="time"],
.field select,
.field textarea {
  width: 100%;
  min-height: 46px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-control);
  background: var(--color-card);
}
.field textarea { min-height: 72px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
  border-color: var(--color-primary);
}
.field-row { display: flex; gap: var(--space-3); }
.field-row .field { flex: 1; }
.field-hint { font-size: 0.78rem; color: var(--color-text-muted); margin-top: var(--space-1); }
.field-hint a { color: var(--color-primary); font-weight: 600; text-decoration: none; }
.field-hint a:hover { text-decoration: underline; }

/* Time fields: muted until a value is actually committed. The browser's
   empty-state hint ("--:-- --"), and iPad Safari's greyed picker preview,
   both render in the muted colour; a genuinely saved value flips to the
   solid text colour via .has-value (toggled in app.js). This gives users
   a visible difference between "example/preview" and "what I set". */
.field input[type="time"] { color: var(--color-text-muted); }
.field input[type="time"].has-value { color: var(--color-text); }

/* License gate: full-screen overlay shown before the planner on
   devices that haven't been activated yet (see js/license-gate.js).
   Sits above everything, painted with the theme background so the
   planner underneath is fully hidden until unlock. */
.license-gate {
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
.license-gate-card {
  max-width: 430px;
  width: 100%;
  text-align: center;
  padding: var(--space-6) var(--space-5);
}
.license-gate-logo { width: 72px; height: 72px; margin: 0 auto var(--space-3); display: block; }
.license-gate-sub { color: var(--color-text-muted); margin: var(--space-2) 0 var(--space-4); }
.license-gate-card .field { text-align: left; }
.license-gate-card input { text-transform: uppercase; letter-spacing: 0.06em; }
.license-gate-card input::placeholder { text-transform: none; letter-spacing: normal; }
.license-gate-btn { width: 100%; margin-top: var(--space-2); }
.license-gate-error {
  background: var(--color-danger-bg, #FDECEC);
  color: var(--color-danger, #C0392B);
  border-radius: var(--radius-control);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-2);
  font-size: 0.9rem;
}
.license-gate-foot { margin-top: var(--space-4); font-size: 0.78rem; color: var(--color-text-muted); }
.license-gate-error a { color: inherit; font-weight: 700; }
.license-gate-links { margin-top: var(--space-3); font-size: 0.88rem; }
.license-gate-links a { color: var(--color-text-muted); }
/* Neutral (non-error) outcome message, e.g. "we've sent your code". */
.license-gate-info {
  background: var(--color-success-bg, #E7F6EC);
  color: var(--color-success, #2E7D4F);
  border-radius: var(--radius-control);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-2);
  font-size: 0.9rem;
}

/* Device management page (manage-devices.html) — extends the gate card. */
.manage-devices .license-gate-card { max-width: 500px; }
.md-summary {
  margin: var(--space-4) 0 var(--space-2);
  font-weight: 600;
  text-align: left;
}
.manage-devices .item-list { text-align: left; }
.manage-devices .badge {
  background: var(--color-primary);
  color: var(--color-on-primary);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.72rem;
  vertical-align: middle;
}

/* Medication Hub: today's dose ticks shown as small tappable chips
   inside a medication row (one chip per dose time). */
.med-doses { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.med-dose-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: 999px;
  background: var(--color-card);
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
}
.med-dose-chip.done {
  background: var(--color-success-bg, #E7F6EC);
  border-color: var(--color-success, #2E9E5B);
  color: var(--color-success, #2E9E5B);
  font-weight: 600;
}
/* Dose time rows in the add/edit medication form. */
.med-time-row { display: flex; gap: var(--space-2); align-items: center; margin-bottom: var(--space-2); }
.med-time-row input[type="time"] { flex: 1; }
/* Checkbox-with-label line (e.g. the Add to Calendar toggle). */
.check-label { display: flex; align-items: center; gap: var(--space-2); cursor: pointer; font-weight: 600; }

/* Inline add bar (e.g. shopping quick add, priorities) */
.add-bar { display: flex; gap: var(--space-2); }
.add-bar input[type="text"] {
  flex: 1;
  min-height: 46px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-control);
  background: var(--color-card);
  min-width: 0;
}
.add-bar select {
  min-height: 46px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-control);
  background: var(--color-card);
  padding: 0 var(--space-2);
}

/* Colour swatch picker (family member colour) */
.swatch-picker { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.swatch-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  padding: 0;
}
.swatch-btn.selected {
  border-color: var(--color-text);
  box-shadow: var(--shadow-card);
}

/* Weekday multi-select (chore frequency) */
.weekday-picker { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.weekday-btn {
  min-width: 46px; min-height: 46px;
  border-radius: var(--radius-control);
  border: 1px solid var(--color-border-strong);
  background: var(--color-card);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
}
.weekday-btn.selected {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-on-primary);
}

/* Segmented control (frequency type, calendar view toggle) */
.segmented {
  display: inline-flex;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-control);
  overflow: hidden;
  background: var(--color-card);
}
.segmented button {
  border: none;
  background: transparent;
  padding: var(--space-2) var(--space-4);
  min-height: 44px;
  cursor: pointer;
  font-family: var(--font-heading);
  font-size: 0.9rem;
  color: var(--color-text-muted);
}
.segmented button.selected {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

/* ---------- Family member cards ---------- */
.member-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}
/* Wider columns than .member-grid — goal rows carry a due date,
   a status badge and two action icons, which need more room per
   card to stay on one line instead of bunching/wrapping. */
.goals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: var(--space-4);
  align-items: start;
}
/* The global ".card + .card" rule below (a DOM-adjacency selector
   meant for cards stacked in normal block flow) doesn't know these
   two containers are CSS Grid — it still matches every card except
   the very first one in DOM order and gives it an extra top margin,
   which a grid then applies WITHIN that card's own row-track space,
   silently nudging it down relative to its actual row-mates. That
   was the real cause of a card looking "misaligned" in its row —
   nothing to do with photos vs. initials. Grid spacing is already
   handled correctly by each grid's own `gap`, so this margin is
   pure noise here and must be zeroed out. */
.member-grid .card, .goals-grid .card { margin-top: 0; }
.member-card {
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  height: 100%; /* Goals page: matches the tallest card in its own grid row */
  box-sizing: border-box;
}
/* Family page cards: ONE fixed height for every card on the whole
   page, not row-relative stretching — a short-content card in row 2
   must be identical in size to a long-content card in row 1. Content
   that doesn't fit scrolls inside .member-today instead of growing
   the card. */
.member-grid .member-card {
  height: 280px;
  cursor: pointer; /* only Family page cards open the per-person "Today" mini-view on click */
}
.member-grid .member-today {
  flex: 1;
  overflow-y: auto;
  min-height: 0; /* required so a flex child can actually shrink and scroll instead of overflowing the fixed-height card */
}
.member-grid .member-notes {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.member-head { display: flex; align-items: center; gap: var(--space-3); }

/* Reordering (Family Members page): plain up/down buttons, stacked
   in a compact column so they sit comfortably in the card header
   next to the avatar. Simple button clicks — no gesture/drag logic
   to go wrong, and identical behaviour for mouse, touch or stylus. */
.reorder-btns { display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
.reorder-btn {
  border: none;
  background: transparent;
  color: var(--color-text-faint);
  font-size: 0.6rem;
  line-height: 1;
  min-width: 26px;
  min-height: 22px;
  border-radius: var(--radius-control);
}
.reorder-btn:hover:not(:disabled) { background: var(--color-card-alt); color: var(--color-text-muted); }
.reorder-btn:disabled { opacity: 0.25; cursor: default; }
.member-avatar {
  width: 52px; height: 52px;
  min-width: 52px; min-height: 52px; /* belt-and-braces: can never be squeezed narrower by its flex siblings */
  border-radius: 50%;
  position: relative; /* the photo is absolutely positioned inside this — see below */
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-on-primary);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.3rem;
  flex-shrink: 0;
  overflow: hidden;
  box-sizing: border-box;
  border: 3px solid transparent; /* coloured by the swatch-cN modifier below — stays visible even when a photo covers the fill colour */
}
/* Absolutely positioned and taken out of normal flow on purpose: an
   <img> child — unlike the plain initial-letter text it replaces —
   can otherwise very subtly influence a flex/grid parent's box
   metrics (e.g. via intrinsic-size or baseline quirks), which is
   exactly what caused one card's whole header row to sit a pixel or
   two off from its neighbours. Taking it out of flow entirely makes
   that structurally impossible, regardless of the photo's own size. */
.member-avatar img {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

/* Photo upload widget inside the Add/Edit member form. */
.avatar-upload { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.avatar-preview {
  width: 64px; height: 64px;
  min-width: 64px; min-height: 64px;
  border-radius: 50%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-on-primary);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.4rem;
  flex-shrink: 0;
  overflow: hidden;
  box-sizing: border-box;
  border: 3px solid transparent; /* same coloured ring as .member-avatar */
}
.avatar-preview img {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

/* Coloured ring around a member's photo/avatar so their assigned
   colour stays visible even when a photo covers the fill colour
   (.member-avatar and .avatar-preview both use this). */
.member-avatar.swatch-c1, .avatar-preview.swatch-c1 { border-color: var(--member-c1); }
.member-avatar.swatch-c2, .avatar-preview.swatch-c2 { border-color: var(--member-c2); }
.member-avatar.swatch-c3, .avatar-preview.swatch-c3 { border-color: var(--member-c3); }
.member-avatar.swatch-c4, .avatar-preview.swatch-c4 { border-color: var(--member-c4); }
.member-avatar.swatch-c5, .avatar-preview.swatch-c5 { border-color: var(--member-c5); }
.member-avatar.swatch-c6, .avatar-preview.swatch-c6 { border-color: var(--member-c6); }
.member-avatar.swatch-c7, .avatar-preview.swatch-c7 { border-color: var(--member-c7); }
.member-avatar.swatch-c8, .avatar-preview.swatch-c8 { border-color: var(--member-c8); }
.member-avatar.swatch-c9, .avatar-preview.swatch-c9 { border-color: var(--member-c9); }
.member-avatar.swatch-c10, .avatar-preview.swatch-c10 { border-color: var(--member-c10); }
.member-avatar.swatch-c11, .avatar-preview.swatch-c11 { border-color: var(--member-c11); }
.member-avatar.swatch-c12, .avatar-preview.swatch-c12 { border-color: var(--member-c12); }
.member-avatar.swatch-c13, .avatar-preview.swatch-c13 { border-color: var(--member-c13); }
.member-avatar.swatch-c14, .avatar-preview.swatch-c14 { border-color: var(--member-c14); }
.member-avatar.swatch-c15, .avatar-preview.swatch-c15 { border-color: var(--member-c15); }
.member-avatar.swatch-c16, .avatar-preview.swatch-c16 { border-color: var(--member-c16); }
.member-role {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}
.member-notes {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: var(--space-2);
}
.member-today {
  margin-top: var(--space-3);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-3);
  font-size: 0.85rem;
}
.member-today .today-line {
  display: flex;
  gap: var(--space-2);
  padding: 2px 0;
  color: var(--color-text-muted);
}

/* ---------- Calendar month grid ---------- */
.cal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.cal-toolbar .cal-month-label {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 600;
  min-width: 12ch;
  text-align: center;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--space-1);
}
.cal-dow {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-text-muted);
  padding: var(--space-2) 0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.cal-cell {
  min-height: 92px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  padding: var(--space-1) var(--space-2);
  cursor: pointer;
  overflow: hidden;
  text-align: left;
  font-family: inherit;
  transition: box-shadow 0.12s ease;
}
.cal-cell:hover { box-shadow: var(--shadow-card); }
.cal-cell.other-month { opacity: 0.4; }
.cal-cell.today-cell {
  border: 2px solid var(--color-primary);
  background: var(--color-primary-soft);
}
.cal-cell .cal-daynum {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-text-muted);
}
.cal-event-chip {
  display: block;
  font-size: 0.7rem;
  color: var(--color-on-primary);
  border-radius: var(--radius-chip);
  padding: 1px 6px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-more {
  font-size: 0.68rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* Grouped list view (calendar list mode, shopping categories) */
.group-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin: var(--space-4) 0 var(--space-1);
}
.group-label:first-child { margin-top: 0; }

/* ---------- Empty states ---------- */
.empty-state {
  text-align: center;
  color: var(--color-text-muted);
  padding: var(--space-5) var(--space-4);
  font-size: 0.92rem;
}
.empty-state .empty-icon { font-size: 1.8rem; display: block; margin-bottom: var(--space-2); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--color-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-modal);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--space-5);
}
.modal h3 { font-size: 1.15rem; margin-bottom: var(--space-4); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-5);
  flex-wrap: wrap;
}
.modal-actions .btn-danger { margin-right: auto; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: var(--space-5);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--color-text);
  color: var(--color-bg);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-raised);
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Reminder pop-up (js/reminders.js builds this DOM) ---------- */
.reminder-popup {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  max-width: 360px;
  width: calc(100vw - var(--space-5) * 2);
  background: var(--color-card);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-modal);
  padding: var(--space-4);
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  flex-wrap: wrap;
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 250;
}
.reminder-popup.open { opacity: 1; pointer-events: auto; transform: translateY(0); }
.reminder-popup-icon { font-size: 1.6rem; line-height: 1; flex-shrink: 0; }
.reminder-popup-body { flex: 1; min-width: 160px; }
.reminder-popup-title { font-family: var(--font-heading); font-weight: 700; font-size: 1rem; }
.reminder-popup-meta { font-size: 0.82rem; color: var(--color-text-muted); margin-top: 2px; }
.reminder-popup-queue { font-size: 0.76rem; color: var(--color-text-faint); margin-top: 4px; }
.reminder-popup-actions {
  display: flex;
  gap: var(--space-2);
  width: 100%;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ---------- Quick Add (dashboard) ---------- */
.quick-add-form { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.quick-add-input-wrap { position: relative; flex: 1; min-width: 220px; }
.quick-add-input-wrap input[type="text"] {
  width: 100%;
  min-height: 50px;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-control);
  background: var(--color-card);
  font-size: 1rem;
  box-sizing: border-box;
}
/* Room for the mic icon sitting inside the field, right-aligned —
   only applied when the button actually exists (browser supports
   Speech Recognition); otherwise the field uses its normal padding. */
.quick-add-input-wrap.has-mic input[type="text"] { padding-right: 46px; }
.quick-add-hint { font-size: 0.8rem; color: var(--color-text-muted); margin-top: var(--space-2); }
.mic-btn {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 38px; height: 38px;
  min-width: 38px; min-height: 38px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 1.15rem;
  border-radius: 50%;
  display: grid;
  place-content: center;
  padding: 0;
}
.mic-btn:hover { background: var(--color-card-alt); }
.mic-btn.listening {
  background: var(--color-danger-soft);
  color: var(--color-danger);
  animation: mic-pulse 1s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* ---------- Toggle switch (Settings: sound alerts) ---------- */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; inset: 0;
  background: var(--color-border-strong);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background 0.15s ease;
}
.switch-track::before {
  content: "";
  position: absolute;
  width: 20px; height: 20px;
  left: 3px; top: 3px;
  background: var(--color-card);
  border-radius: 50%;
  transition: transform 0.15s ease;
  box-shadow: var(--shadow-card);
}
.switch input:checked + .switch-track { background: var(--color-primary); }
.switch input:checked + .switch-track::before { transform: translateX(20px); }
.switch-row { display: flex; align-items: center; gap: var(--space-3); }

/* ---------- Settings page ---------- */
.settings-note {
  font-size: 0.88rem;
  color: var(--color-text-muted);
  line-height: 1.55;
}
.settings-actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-3);
}

/* ---------- Utility ---------- */
.muted { color: var(--color-text-muted); }
.small { font-size: 0.85rem; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.hidden { display: none !important; }

/* ============================================================
   Responsive fallbacks — portrait tablet & mobile are secondary
   to the primary landscape layout.
   ============================================================ */
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: 0;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    padding: var(--space-2) var(--space-3);
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    z-index: 50;
  }
  .brand { flex-direction: row; text-align: left; padding: 0 var(--space-3); white-space: nowrap; }
  .brand-photo-btn { width: 36px; height: 36px; min-width: 36px; min-height: 36px; font-size: 1.1rem; }
  .brand-photo-actions { display: none; } /* editing the family photo is a rare, deliberate action — better done from the full sidebar than the compact mobile top bar */
  .brand h1 { font-size: 1rem; }
  .nav-btn { width: auto; white-space: nowrap; padding: var(--space-2) var(--space-3); }
  .nav-btn .nav-label { display: none; }
  .nav-btn .nav-icon { width: auto; }
  .sidebar-footer { display: none; }
  .main { padding: var(--space-4); }
  .dash-grid > * { grid-column: span 12 !important; }
  .hero .family-quote { text-align: left; }
  .cal-cell { min-height: 64px; }
  .cal-event-chip { display: none; }
  .cal-cell .cal-dots { display: flex; gap: 3px; margin-top: 4px; flex-wrap: wrap; }
}

@media (min-width: 981px) {
  .cal-cell .cal-dots { display: none; }
}

/* ---------- Meal Planner grid (Meal Planner page only) ---------- */
.table-scroll { overflow-x: auto; }
.meal-grid { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 640px; }
.meal-grid th, .meal-grid td {
  padding: var(--space-3);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.meal-grid th {
  font-family: var(--font-heading);
  font-size: 0.8rem;
  color: var(--color-text-muted);
  font-weight: 700;
}
.meal-grid td.meal-day-label {
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}
.meal-cell {
  cursor: pointer;
  border-radius: var(--radius-control);
  transition: background 0.12s ease;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meal-cell:hover { background: var(--color-card-alt); }

/* ---------- Print (Shopping list "🖨️ Print" button) ---------- */
.print-only { display: none; }
.print-checkbox {
  width: 14px; height: 14px;
  border: 1.5px solid var(--color-text);
  flex-shrink: 0;
}
@media print {
  .sidebar, .modal-overlay, .toast, .reminder-popup, .page-header .btn, .no-print { display: none !important; }
  .print-only { display: inline-block; }
  .app { display: block; }
  .main { padding: 0; max-width: none; }
  body { background: var(--color-card); }
  .card { box-shadow: none; border: none; }
  #shop-print-area .item-row { break-inside: avoid; }
}
