/* CalTrack — phone-first responsive UI */

/* Shared / theme-agnostic values */
:root {
  --radius: 16px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --fab-size: 56px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

/* ── Dark theme ─────────────────────────────────────────── */
[data-theme="dark"] {
  --bg: #0b1220;
  --bg-elevated: #121a2b;
  --bg-card: #162033;
  --border: #243049;
  --text: #e8eef9;
  --muted: #8b9bb8;
  --primary: #14b8a6;
  --primary-dim: #0f766e;
  --primary-soft: rgba(20, 184, 166, 0.15);
  --danger: #f87171;
  --warn: #fbbf24;
  --good: #34d399;
  --medium: #fbbf24;
  --bad: #f87171;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);

  /* Theme-dependent colours that appear as hardcoded hex / rgba */
  --btn-text: #042f2e;
  --topbar-bg: rgba(11, 18, 32, 0.85);
  --hero-gradient-start: #16324a;
  --progress-track-bg: rgba(255, 255, 255, 0.06);
  --macro-bg: rgba(0, 0, 0, 0.18);
  --thumb-badge-bg: rgba(0, 0, 0, 0.55);
  --remove-btn-bg: rgba(0, 0, 0, 0.65);
  --analyzing-bg: rgba(5, 10, 20, 0.78);
  --goal-label-bg: rgba(11, 18, 32, 0.85);
  --text-meal-gradient-start: #16324a;
  --thumb-text-gradient-start: #1a2740;
  --thumb-text-gradient-end: #121a2b;
  --flash-error-text: #fecaca;
  --login-card-bg: #162033;
  --login-input-border: #243049;
  --login-input-bg: #121a2b;
  --login-subtitle: #8b9bb8;
  --login-remember-text: #94a3b8;
  --login-ban-bg: rgba(248, 113, 113, 0.08);
  --login-ban-border: rgba(248, 113, 113, 0.35);
  --login-ban-text: #fca5a5;
  --over-bar-start: #dc2626;
  --over-bar-end: #f97316;
  --under-bar-start: #059669;
  --lacking-bar-start: #d97706;
  --bar-deficit-start: #6ee7b7;
  --bar-deficit-end: #059669;
  --bar-excess-start: #fca5a5;
  --bar-excess-end: #dc2626;
  --bar-none-bg: rgba(255, 255, 255, 0.06);
}

/* ── Light theme ───────────────────────────────────────── */
[data-theme="light"] {
  --bg: #f5f7fa;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --border: #d1d9e6;
  --text: #1a2030;
  --muted: #64748b;
  --primary: #0d9488;
  --primary-dim: #0f766e;
  --primary-soft: rgba(13, 148, 136, 0.10);
  --danger: #ef4444;
  --warn: #d97706;
  --good: #059669;
  --medium: #d97706;
  --bad: #ef4444;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.08);

  --btn-text: #ffffff;
  --topbar-bg: rgba(245, 247, 250, 0.85);
  --hero-gradient-start: #e0f7f4;
  --progress-track-bg: rgba(0, 0, 0, 0.08);
  --macro-bg: rgba(0, 0, 0, 0.04);
  --thumb-badge-bg: rgba(255, 255, 255, 0.7);
  --remove-btn-bg: rgba(255, 255, 255, 0.85);
  --analyzing-bg: rgba(255, 255, 255, 0.8);
  --goal-label-bg: rgba(255, 255, 255, 0.9);
  --text-meal-gradient-start: #e0f7f4;
  --thumb-text-gradient-start: #dce4ee;
  --thumb-text-gradient-end: #f0f4fa;
  --flash-error-text: #dc2626;
  --login-card-bg: #ffffff;
  --login-input-border: #d1d9e6;
  --login-input-bg: #f5f7fa;
  --login-subtitle: #64748b;
  --login-remember-text: #475569;
  --login-ban-bg: rgba(239, 68, 68, 0.06);
  --login-ban-border: rgba(239, 68, 68, 0.3);
  --login-ban-text: #dc2626;
  --over-bar-start: #ef4444;
  --over-bar-end: #f97316;
  --under-bar-start: #059669;
  --lacking-bar-start: #d97706;
  --bar-deficit-start: #34d399;
  --bar-deficit-end: #059669;
  --bar-excess-start: #fca5a5;
  --bar-excess-end: #ef4444;
  --bar-none-bg: rgba(0, 0, 0, 0.08);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-top: var(--safe-top);
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button, select, input { font: inherit; color: inherit; }

.app-shell {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(96px + var(--safe-bottom));
  position: relative;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  min-height: 56px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: -0.02em;
  flex-shrink: 0;
  text-decoration: none;
  color: inherit;
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #0ea5e9);
  display: grid;
  place-items: center;
  font-size: 16px;
}
.brand-text { font-size: 1.05rem; }
/* When a page title is present, keep only the logo mark so the bar stays roomy */
.topbar-inner:has(.topbar-title) .brand .brand-text {
  display: none;
}
.topbar-meta { margin-left: auto; }
.topbar-title {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  line-height: 1.2;
}
.back-link {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

/* Main */
.main { padding: 16px; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.hidden { display: none !important; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  white-space: nowrap;
}
.pill-warn {
  background: rgba(251, 191, 36, 0.12);
  border-color: rgba(251, 191, 36, 0.35);
  color: var(--warn);
}

/* Hero / summary cards */
.hero-card {
  background: linear-gradient(160deg, var(--hero-gradient-start) 0%, var(--bg-card) 55%);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.hero-card.compact { padding: 14px; }
.hero-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}
.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  color: var(--primary);
  font-weight: 600;
}
.hero-title {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}
.hero-cals { text-align: right; }
.big-num {
  display: block;
  font-size: 1.8rem;
  font-weight: 750;
  letter-spacing: -0.03em;
  line-height: 1;
}
.unit { color: var(--muted); font-size: 0.85rem; }

.progress {
  height: 10px;
  background: var(--progress-track-bg);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 14px;
}
.progress.thin { height: 6px; margin: 10px 0; }
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-dim), var(--primary));
  border-radius: 999px;
  transition: width 0.35s ease;
  min-width: 2px;
}
.progress-bar.over {
  background: linear-gradient(90deg, var(--over-bar-start), var(--over-bar-end));
}
.progress-bar.under {
  background: linear-gradient(90deg, var(--under-bar-start), var(--good));
}
.day-cals.under strong { color: var(--good); }
.day-cals.over strong { color: var(--bad); }
.text-deficit { color: var(--good) !important; }
.text-excess { color: var(--bad) !important; }
.tag-deficit, .tag-excess {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.tag-deficit { background: rgba(52, 211, 153, 0.15); color: var(--good); }
.tag-excess { background: rgba(248, 113, 113, 0.15); color: var(--bad); }
.pill-ok {
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.35);
  color: var(--good);
}
.nav-pill {
  background: var(--primary-soft);
  border-color: rgba(20, 184, 166, 0.35);
  color: var(--primary);
  font-weight: 650;
}
.linkish { color: var(--primary); text-decoration: none; }

/* Day page: calorie + macro goal bars */
.goal-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.goal-row .progress {
  margin-bottom: 0;
}
.goal-row-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}
.goal-name {
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.goal-meta {
  font-size: 0.88rem;
  text-align: right;
  white-space: nowrap;
}
.goal-meta strong {
  font-weight: 700;
  color: var(--text);
}
.goal-meta.text-excess strong { color: var(--bad); }
.goal-meta.text-deficit strong { color: var(--good); }
.goal-pct-chip {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.02em;
  vertical-align: middle;
}
.goal-pct-chip.under {
  background: rgba(52, 211, 153, 0.15);
  color: var(--good);
}
.goal-pct-chip.track {
  background: var(--primary-soft);
  color: var(--primary);
}
.goal-pct-chip.over {
  background: rgba(248, 113, 113, 0.15);
  color: var(--bad);
}
.goal-pct-chip.lacking {
  background: rgba(251, 191, 36, 0.18);
  color: var(--medium);
}
.text-lacking { color: var(--medium); }
.text-lacking strong { color: var(--medium) !important; }
.progress-bar.lacking {
  background: linear-gradient(90deg, var(--lacking-bar-start), #fbbf24);
}
.metric-pills { margin-top: -4px; margin-bottom: 16px; }
.summary-card, .week-alcohol-card {
  margin-bottom: 14px;
  padding: 14px;
}
.summary-card .goal-row + .goal-row { margin-top: 10px; }
.summary-title {
  margin: 0 0 4px;
  font-size: 0.95rem;
}

.macro-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
  background: var(--macro-bg);
  border-radius: var(--radius-sm);
  padding: 10px 4px;
}
.macro-val { display: block; font-weight: 700; font-size: 0.95rem; }
.macro-lbl { display: block; color: var(--muted); font-size: 0.72rem; margin-top: 2px; }

/* Sections */
.section { margin-bottom: 24px; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

/* Day list */
.day-list, .meal-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.day-card, .meal-card, .card {
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  transition: border-color 0.15s, transform 0.15s;
}
.day-card:active, .meal-card:active { transform: scale(0.99); }
.day-card.is-today { border-color: rgba(20, 184, 166, 0.45); }
.day-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.day-label { font-weight: 700; font-size: 1.02rem; }
.day-sub { margin-top: 2px; font-size: 0.82rem; }
.day-cals strong { font-size: 1.15rem; }
.day-cals.over strong { color: var(--warn); }
.day-macros { margin-top: 8px; }

.thumb-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.thumb-row::-webkit-scrollbar { display: none; }
.thumb {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg);
  border: 1px solid var(--border);
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.thumb-badge {
  position: absolute;
  right: 2px;
  bottom: 2px;
  font-size: 0.7rem;
  line-height: 1;
  background: var(--thumb-badge-bg);
  border-radius: 6px;
  padding: 2px 3px;
}
.thumb.more {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

/* Meal cards */
.meal-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
}
.meal-photo {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg);
  border: 1px solid var(--border);
}
.meal-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.meal-body { flex: 1; min-width: 0; }
.meal-type {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 2px;
}
.meal-name {
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.meal-stats { font-size: 0.82rem; color: var(--muted); }
.meal-stats strong { color: var(--text); }
.dot { opacity: 0.5; margin: 0 2px; }
.chevron {
  color: var(--muted);
  font-size: 1.4rem;
  padding-right: 4px;
}

/* Ratings */
.rating-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.rating-good { background: rgba(52, 211, 153, 0.15); color: var(--good); }
.rating-medium { background: rgba(251, 191, 36, 0.15); color: var(--medium); }
.rating-bad { background: rgba(248, 113, 113, 0.15); color: var(--bad); }
.rating-unknown { background: rgba(139, 155, 184, 0.15); color: var(--muted); }

/* Meal detail */
.meal-hero {
  margin: -16px -16px 16px;
}
.photo-full img {
  width: 100%;
  max-height: 55vh;
  object-fit: cover;
  background: #000;
}
.meal-detail-title {
  margin: 0 0 6px;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 16px 0;
}
.stat-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
}
.stat-tile.primary {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, rgba(20, 184, 166, 0.18), var(--bg-card));
  border-color: rgba(20, 184, 166, 0.35);
}
.stat-val {
  display: block;
  font-size: 1.35rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}
.stat-tile.primary .stat-val { font-size: 2rem; }
.stat-lbl {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
}
.commentary h3, .card h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}
.commentary p, .card p { margin: 0; line-height: 1.5; }
.card-error {
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.08);
  margin-top: 12px;
}
.danger-zone {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.error-text { color: var(--danger); }

/* Forms */
.add-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 650; }
.field-hint { color: var(--muted); font-size: 0.82rem; margin-bottom: 2px; }
.select {
  appearance: none;
  background: var(--bg-card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238b9bb8' d='M1 1l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 14px center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 40px 14px 14px;
  font-size: 1rem;
}
.select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.photo-picker {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  min-height: 220px;
  overflow: hidden;
  background: var(--bg-elevated);
}
/* Visually hidden — opened via Camera / Gallery buttons (capture toggled in JS) */
.photo-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}
.photo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 220px;
  padding: 24px;
  text-align: center;
}
.photo-placeholder-compact {
  min-height: 88px;
  padding: 14px;
}
.photo-placeholder-compact .camera-icon {
  font-size: 1.5rem;
  margin-bottom: 0;
}
.photo-placeholder-compact .photo-source-row {
  margin-top: 4px;
}
.camera-icon { font-size: 2.4rem; margin-bottom: 4px; }
.photo-source-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
  width: 100%;
}
.photo-source-btn {
  flex: 1 1 auto;
  min-width: 7.5rem;
  max-width: 11rem;
  padding: 10px 14px;
  font-size: 0.9rem;
}
.photo-preview {
  width: 100%;
  min-height: 220px;
  max-height: 360px;
  object-fit: cover;
}

/* Multi-photo previews (pending uploads) */
.photo-preview-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.photo-thumb-card {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg);
}
.photo-thumb-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-thumb-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 999px;
  background: var(--remove-btn-bg);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* Existing photos on edit form */
.existing-photo-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}
.existing-photo-card {
  display: block;
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
}
.existing-photo-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}
.existing-photo-check {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  font-size: 0.82rem;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}
.existing-photo-card.marked-delete {
  opacity: 0.55;
  outline: 2px solid var(--bad);
  outline-offset: -2px;
}
.existing-photo-card.marked-delete img {
  filter: grayscale(0.7);
}

/* Meal detail multi-photo gallery */
.photo-gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  background: #000;
}
.photo-gallery-item {
  display: block;
  aspect-ratio: 1;
  overflow: hidden;
}
.photo-gallery-item:first-child:nth-last-child(odd) {
  grid-column: 1 / -1;
  aspect-ratio: 16 / 10;
}
.photo-gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  font-weight: 650;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), #0ea5e9);
  color: var(--btn-text);
}
.btn-danger {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.35);
  width: 100%;
}
.btn-block { width: 100%; }

/* FAB */
.fab {
  position: fixed;
  right: max(16px, calc(50% - 260px + 16px));
  bottom: calc(20px + var(--safe-bottom));
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--primary), #0ea5e9);
  color: var(--btn-text);
  border-radius: 999px;
  padding: 0 20px 0 4px;
  min-height: var(--fab-size);
  box-shadow: 0 10px 28px rgba(20, 184, 166, 0.35);
  font-weight: 750;
}
.fab-plus {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.8rem;
  line-height: 1;
  background: rgba(255, 255, 255, 0.2);
}
.fab-label { padding-right: 4px; }

/* Empty */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 8px; }
.empty-state h3 { margin: 0 0 8px; }
.empty-state p { color: var(--muted); margin: 0 0 18px; line-height: 1.45; }

.btn-group-side {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}
.btn-group-side .flex-1 {
  flex: 1;
}

/* Home: unanalyzed meals alert */
.alert-banner {
  margin: 0 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 14px 14px;
}
.alert-banner-warn {
  border-color: rgba(251, 191, 36, 0.45);
  background: rgba(251, 191, 36, 0.1);
}
.alert-banner-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.alert-banner-text {
  flex: 1 1 160px;
  min-width: 0;
}
.alert-banner-text strong {
  font-size: 0.98rem;
  letter-spacing: -0.01em;
}
.alert-banner-cta {
  margin: 0;
  flex-shrink: 0;
}
.btn-sm {
  padding: 10px 14px;
  font-size: 0.9rem;
  border-radius: 12px;
}
.analyze-all-progress {
  max-width: 280px;
  margin-left: auto;
  margin-right: auto;
}

/* Flash */
.flash-stack {
  padding: 10px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.flash {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  line-height: 1.35;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}
.flash-success {
  border-color: rgba(52, 211, 153, 0.35);
  background: rgba(52, 211, 153, 0.1);
  color: var(--good);
}
.flash-error {
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.1);
  color: var(--flash-error-text);
}

/* Analyzing overlay (short upload wait on form submit) */
.analyzing-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--analyzing-bg);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 24px;
}
.analyzing-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  box-shadow: var(--shadow);
}
.analyzing-card h3 { margin: 14px 0 6px; }
.analyzing-card p { margin: 0; }
.spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto;
  border: 3px solid rgba(20, 184, 166, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner-lg {
  width: 56px;
  height: 56px;
  border-width: 4px;
}
.spinner-sm {
  width: 22px;
  height: 22px;
  border-width: 2px;
  margin: 0;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Dedicated analyzing wait page */
.analyzing-page {
  display: flex;
  justify-content: center;
  padding-top: 12px;
}
.analyzing-page-card {
  text-align: center;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}
.analyzing-page-card h1 {
  font-size: 1.35rem;
  margin: 18px 0 8px;
  letter-spacing: -0.02em;
}
.analyzing-page-card > .muted {
  margin: 0 0 8px;
  line-height: 1.45;
}
.analyzing-thumbs {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 18px 0 4px;
  flex-wrap: wrap;
}
.analyzing-thumbs img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.analyzing-notes {
  text-align: left;
  margin-top: 16px;
}
.card-pending {
  border-color: rgba(20, 184, 166, 0.35);
  background: var(--primary-soft);
}
.pending-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.badge-pending {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid rgba(20, 184, 166, 0.35);
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}
.btn-ghost:hover, .btn-ghost:focus-visible {
  border-color: var(--muted);
  color: var(--text);
}

/* Wider tablets / desktop */
@media (min-width: 600px) {
  .app-shell { padding-bottom: calc(40px + var(--safe-bottom)); }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .stat-tile.primary { grid-column: span 4; }
}

@media (min-width: 768px) {
  .app-shell {
    max-width: min(1400px, 100%);
    padding-left: 12px;
    padding-right: 12px;
  }
  .main { padding: 20px 24px; }
  .topbar-inner { padding-left: 24px; padding-right: 24px; }
  .fab { right: 24px; }
}

/* Form inputs */
.input, .textarea {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 1rem;
  color: var(--text);
}
.input:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.45;
  font-family: inherit;
}

/* Photo / text / product mode toggle */
.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px;
}
.mode-toggle.mode-toggle-3 {
  grid-template-columns: 1fr 1fr 1fr;
}
.mode-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 11px;
  padding: 12px 10px;
  font-weight: 650;
  cursor: pointer;
  font-size: 0.92rem;
}
.mode-toggle-3 .mode-btn {
  padding: 11px 4px;
  font-size: 0.84rem;
}
.mode-btn.active {
  background: linear-gradient(135deg, var(--primary), #0ea5e9);
  color: var(--btn-text);
}
.mode-panel { margin-top: 4px; }

/* Text meal placeholders */
.thumb-text, .meal-photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--thumb-text-gradient-start), var(--thumb-text-gradient-end));
  font-size: 1.2rem;
  gap: 2px;
}
.meal-photo-placeholder { min-height: 72px; }
.text-hero { margin: -16px -16px 16px; }
.text-meal-banner {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 20px 16px;
  background: linear-gradient(160deg, var(--text-meal-gradient-start), var(--bg-card));
  border-bottom: 1px solid var(--border);
}
.text-meal-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--primary-soft);
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.text-meal-quote {
  margin: 4px 0 0;
  line-height: 1.45;
  font-size: 0.98rem;
}

/* Trends chart */
.range-pills {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
  scrollbar-width: none;
}
.range-pills::-webkit-scrollbar { display: none; }
.range-pill {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 0.85rem;
  font-weight: 650;
  color: var(--muted);
}
.range-pill.active {
  background: var(--primary-soft);
  border-color: rgba(20, 184, 166, 0.45);
  color: var(--primary);
}
.health-tabs {
  margin-bottom: 10px;
}
.bar-chart-wide {
  min-width: max(100%, calc(var(--n) * 28px));
}
.bar-chart-wide .bar-col {
  min-width: 22px;
}
.trends-stats {
  margin-bottom: 14px;
}
.trends-stats .stat-tile.primary { grid-column: auto; }
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px 10px;
  overflow: hidden;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 0 6px 12px;
  font-size: 0.75rem;
  color: var(--muted);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}
.swatch.deficit { background: var(--good); }
.swatch.excess { background: var(--bad); }
.swatch.goal-line {
  height: 2px;
  width: 16px;
  background: #fbbf24;
  border-radius: 1px;
  position: relative;
  top: -1px;
}
.chart-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
.bar-chart {
  --chart-h: 220px;
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: var(--chart-h);
  min-width: max(100%, calc(var(--n) * 36px));
  padding: 28px 4px 40px;
  border-top: 1px solid transparent;
}
.goal-line {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(28px + var(--goal-pct));
  border-top: 2px dashed rgba(251, 191, 36, 0.85);
  z-index: 2;
  pointer-events: none;
}
.goal-label {
  position: absolute;
  right: 4px;
  bottom: calc(30px + var(--goal-pct));
  transform: translateY(50%);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--warn);
  background: var(--goal-label-bg);
  padding: 1px 5px;
  border-radius: 4px;
  z-index: 3;
  pointer-events: none;
}
.bar-col {
  flex: 1 1 0;
  min-width: 28px;
  max-width: 48px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  position: relative;
  text-decoration: none;
}
.bar-col.empty { pointer-events: none; opacity: 0.45; }
.bar {
  width: 100%;
  min-height: 2px;
  border-radius: 6px 6px 3px 3px;
  transition: height 0.25s ease;
}
.bar.deficit {
  background: linear-gradient(180deg, var(--bar-deficit-start), var(--bar-deficit-end));
  box-shadow: 0 0 12px rgba(52, 211, 153, 0.25);
}
.bar.excess {
  background: linear-gradient(180deg, var(--bar-excess-start), var(--bar-excess-end));
  box-shadow: 0 0 12px rgba(248, 113, 113, 0.25);
}
.bar.none {
  background: var(--bar-none-bg);
  min-height: 3px;
  height: 3px !important;
}
.bar-val {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 4px;
  white-space: nowrap;
  min-height: 0.9em;
}
.bar-x {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.62rem;
  color: var(--muted);
  white-space: nowrap;
  padding-top: 4px;
  text-align: center;
  line-height: 1.15;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.bar-dow {
  font-weight: 800;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
}
.bar-col.weekend .bar-x,
.bar-col.weekend .bar-dow {
  color: #c084fc;
}
.bar.weekend {
  background: linear-gradient(180deg, #c4b5fd, #7c3aed);
  box-shadow: 0 0 12px rgba(167, 139, 250, 0.3);
}
[data-theme="light"] .bar-col.weekend .bar-x,
[data-theme="light"] .bar-col.weekend .bar-dow {
  color: #7c3aed;
}
.line-chart {
  --chart-h: 220px;
  min-width: max(100%, calc(var(--n) * 48px));
  padding: 18px 4px 16px;
}
.line-plot {
  position: relative;
  height: var(--chart-h);
  margin-left: 42px;
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.line-axis {
  position: absolute;
  left: -42px;
  top: 0;
  bottom: 0;
  width: 40px;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--muted);
  pointer-events: none;
}
.line-tick {
  position: absolute;
  right: 4px;
  transform: translateY(50%);
  line-height: 1;
}
.line-grid {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid rgba(148, 163, 184, 0.22);
  pointer-events: none;
}
.line-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.line-svg polyline {
  stroke: var(--good);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.line-dot {
  position: absolute;
  width: 8px;
  height: 8px;
  margin-left: -4px;
  margin-bottom: -4px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 2px var(--bg-card);
  z-index: 2;
}
.line-val {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
}
.line-dot.label-below .line-val {
  bottom: auto;
  top: 10px;
}
.line-dot.weekend { background: #a78bfa; }
.line-xs {
  display: flex;
  margin-left: 42px;
  min-height: 36px;
}
.line-x {
  flex: 1 1 0;
  min-width: 28px;
  text-align: center;
  font-size: 0.62rem;
  color: var(--muted);
  line-height: 1.15;
  padding-top: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.line-x.empty { opacity: 0.45; }
.line-x.weekend,
.line-x.weekend .bar-dow { color: #c084fc; }
[data-theme="light"] .line-x.weekend,
[data-theme="light"] .line-x.weekend .bar-dow { color: #7c3aed; }

.chart-footnote { margin-top: 14px; }
.chart-empty { margin: 8px; border: none; }

/* Edit form */
.num-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.action-row { margin-top: 20px; }
.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.92rem;
  line-height: 1.35;
  cursor: pointer;
}
.check-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--primary);
}
.card-check {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.photo-picker-sm { min-height: 140px; }
.photo-picker-sm .photo-placeholder { min-height: 140px; }
.photo-picker-sm .photo-placeholder-compact { min-height: 72px; }
.photo-picker-sm .photo-preview { min-height: 140px; max-height: 220px; }
.btn-secondary {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-sm {
  padding: 8px 12px;
  font-size: 0.85rem;
  border-radius: 10px;
  min-height: 36px;
}

/* Profile switcher (topbar) */
.topbar-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.profile-switcher {
  position: relative;
  margin-left: auto;
}
.topbar-meta-row .profile-switcher {
  margin-left: 0;
}
.profile-pill {
  cursor: pointer;
  gap: 4px;
  background: var(--primary-soft);
  border-color: rgba(20, 184, 166, 0.35);
  color: var(--primary);
  font-weight: 650;
  max-width: 160px;
}
.profile-pill-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 90px;
}
.profile-pill-caret {
  font-size: 0.7rem;
  opacity: 0.8;
}
.profile-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 180px;
  max-width: min(280px, 80vw);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.profile-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.92rem;
  font-weight: 550;
}
.profile-menu-item:hover,
.profile-menu-item:focus-visible {
  background: var(--primary-soft);
  color: var(--primary);
}
.profile-menu-item.is-current {
  background: rgba(20, 184, 166, 0.12);
  color: var(--primary);
}
.profile-menu-manage {
  margin-top: 4px;
  border-top: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.85rem;
}

/* Profiles page */
.profile-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.profile-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  flex-wrap: wrap;
}
.profile-card.is-active {
  border-color: rgba(20, 184, 166, 0.5);
  box-shadow: 0 0 0 1px rgba(20, 184, 166, 0.15);
}
.profile-card-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}
.profile-avatar {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #0ea5e9);
  color: var(--btn-text);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.profile-info { min-width: 0; }
.profile-name {
  font-weight: 700;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.profile-active-tag {
  font-size: 0.7rem;
  padding: 2px 8px;
}
.profile-card-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* Profile create / edit form */
.profile-form .field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.input-with-unit {
  display: flex;
  align-items: stretch;
  gap: 0;
}
.input-with-unit .input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  flex: 1;
  min-width: 0;
}
.input-unit {
  display: grid;
  place-items: center;
  padding: 0 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 12px 12px 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 650;
}
.profile-goals-preview {
  margin: 4px 0 8px;
  padding: 14px;
}
.profile-goals-preview h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
}
.profile-form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.profile-form .field { margin-bottom: 4px; }

@media (max-width: 380px) {
  .profile-form .field-row {
    grid-template-columns: 1fr;
  }
}

/* Cholesterol / substitutions on meal detail */
.cholesterol-card h3,
.sugar-sources-card h3 { margin: 0 0 8px; }
.cholesterol-card p { margin: 0 0 12px; line-height: 1.5; }
.sugar-sources-card { border-color: rgba(251, 191, 36, 0.35); }
.sugar-g-pill {
  background: rgba(251, 191, 36, 0.15);
  border-color: rgba(251, 191, 36, 0.35);
  color: var(--warn);
  font-weight: 700;
  font-size: 0.72rem;
}
.sub-list-head {
  margin: 4px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 650;
}
.substitution-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.substitution-item {
  background: var(--macro-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.sub-item-name {
  font-weight: 700;
  margin-bottom: 2px;
}
.sub-instead {
  margin-top: 8px;
  font-size: 0.92rem;
  line-height: 1.4;
}
.sub-instead-label {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--primary-soft);
  color: var(--primary);
  vertical-align: middle;
}

/* Product library */
.product-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.product-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  transition: border-color 0.15s, transform 0.15s;
}
.product-card:active { transform: scale(0.99); }
.product-card.is-pending {
  border-color: rgba(251, 191, 36, 0.4);
}
.product-card.is-error {
  border-color: rgba(248, 113, 113, 0.4);
}
.product-thumb {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
}
.product-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.product-thumb-placeholder {
  font-size: 1.4rem;
  opacity: 0.7;
}
.product-body { flex: 1; min-width: 0; }
.product-name {
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}
.product-macros strong { color: var(--text); }
.product-label-preview {
  display: block;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  max-height: 220px;
  background: var(--bg);
}
.product-label-preview img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  background: #fff;
}
.danger-zone {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.add-form .field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 380px) {
  .add-form .field-row {
    grid-template-columns: 1fr;
  }
}

/* Profile tools (bowel log / documents entry points) */
.tool-card-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tool-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.tool-card:hover,
.tool-card:focus-visible {
  border-color: rgba(20, 184, 166, 0.45);
  background: rgba(20, 184, 166, 0.06);
}
.tool-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}
.tool-card-body { min-width: 0; flex: 1; }
.tool-card-title {
  font-weight: 700;
  font-size: 1.02rem;
  margin-bottom: 2px;
}

/* Bowel movement log */
.bowel-form fieldset.field {
  min-width: 0;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 12px;
  /* Keep typical fieldset padding/margin; only soften chrome */
  padding: 0.5em 0.85em 0.85em;
  margin: 0.65em 0 0;
}
.bowel-form fieldset.field > legend.field-label {
  padding: 0 0.4em;
  margin-bottom: 0;
}
.bowel-bristol-legend {
  display: block;
  margin-top: 4px;
  font-size: 0.85rem;
}
.bowel-bristol-legend ul {
  margin: 4px 0 0;
  padding-left: 1.1rem;
  columns: 2;
  column-gap: 12px;
  list-style: none;
  padding-left: 0;
}
.bowel-bristol-legend li {
  margin: 0 0 2px;
  break-inside: avoid;
  line-height: 1.3;
}

/* Shared subtle card chrome for Bristol + tag options */
.bowel-option-card {
  --bowel-option-border: rgba(148, 163, 184, 0.16);
  --bowel-option-border-hover: rgba(148, 163, 184, 0.28);
  border: 1px solid var(--bowel-option-border);
  border-radius: 12px;
  background: rgba(22, 32, 51, 0.65);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  box-sizing: border-box;
}
.bowel-option-card:hover {
  border-color: var(--bowel-option-border-hover);
}
.bowel-option-card:has(input:checked) {
  border-color: rgba(20, 184, 166, 0.45);
  background: rgba(20, 184, 166, 0.1);
  box-shadow: 0 0 0 1px rgba(20, 184, 166, 0.12);
}
.bowel-option-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

/* Bristol: compact number squares — 4 per row, 2 rows (0–7) */
.icon-grid-bristol {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 8px;
}
.icon-grid-bristol .icon-option {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  aspect-ratio: 1;
  min-height: 44px;
}
.icon-grid-bristol .icon-face-num {
  font-size: 1.2rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  color: var(--text, #e2e8f0);
  line-height: 1;
}
.icon-grid-bristol .icon-option-none:has(input:checked) {
  border-color: rgba(148, 163, 184, 0.35);
  background: rgba(148, 163, 184, 0.1);
  box-shadow: 0 0 0 1px rgba(148, 163, 184, 0.1);
}
.icon-grid-bristol .icon-option-none .icon-face-num {
  color: var(--muted, #94a3b8);
}

/* Urgency / gas / pain: 2 per row, large touch targets */
.scale-rows {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.scale-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  min-width: 0;
  padding: 12px 12px;
}
.scale-row-num {
  flex-shrink: 0;
  width: 1.85rem;
  height: 1.85rem;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid rgba(148, 163, 184, 0.14);
  font-weight: 750;
  font-size: 0.98rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.scale-row:has(input:checked) .scale-row-num {
  border-color: rgba(20, 184, 166, 0.4);
  background: rgba(20, 184, 166, 0.16);
  color: #5eead4;
}
.scale-row-label {
  flex: 1;
  min-width: 0;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.25;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

@media (max-width: 380px) {
  .bowel-bristol-legend ul {
    columns: 1;
  }
}

.bowel-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bowel-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-decoration: none;
  color: inherit;
}
.bowel-card:hover,
.bowel-card:focus-visible {
  border-color: rgba(20, 184, 166, 0.4);
}
.bowel-card-main {
  min-width: 0;
  flex: 1;
}
.bowel-date {
  font-weight: 700;
  font-size: 0.98rem;
}
.bowel-notes {
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bowel-card-rating {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}
.bowel-stars {
  font-size: 0.95rem;
  letter-spacing: 1px;
  line-height: 1;
}
.bowel-stars .on { color: #fbbf24; }
.bowel-stars .off { color: var(--border); }
.bowel-none-badge {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--muted, #94a3b8);
  line-height: 1;
}
.bowel-card-none {
  opacity: 0.92;
}
.bowel-rating-caption {
  max-width: 120px;
  text-align: right;
  line-height: 1.25;
}

/* Health documents library */
.doc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.doc-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.doc-card-main {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  text-decoration: none;
  color: inherit;
}
.doc-card-main:hover,
.doc-card-main:focus-visible {
  background: rgba(20, 184, 166, 0.06);
}
.doc-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.doc-card-body {
  min-width: 0;
  flex: 1;
}
.doc-title {
  font-weight: 700;
  font-size: 0.98rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-notes {
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-card-actions {
  display: flex;
  gap: 6px;
  padding: 0 12px 12px;
  flex-wrap: wrap;
}
.btn-sm {
  padding: 6px 10px;
  font-size: 0.85rem;
}

/* Medicine courses */
.med-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.med-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-decoration: none;
  color: inherit;
}
.med-card:hover,
.med-card:focus-visible {
  border-color: rgba(20, 184, 166, 0.4);
}
.med-card-active {
  border-color: rgba(20, 184, 166, 0.35);
  background: rgba(20, 184, 166, 0.05);
}
.med-card-main {
  min-width: 0;
  flex: 1;
}
.med-name {
  font-weight: 700;
  font-size: 0.98rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.med-notes {
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.med-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--muted, #94a3b8);
}
.med-badge-active,
.med-badge-ongoing {
  color: #14b8a6;
  border-color: rgba(20, 184, 166, 0.4);
  background: rgba(20, 184, 166, 0.12);
}

/* Gastrointestinal triggers card */
.gastro-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.gastro-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
  font-weight: 600;
}

.gastro-card .muted.small {
  margin: 0 0 10px;
  color: var(--muted);
}

.gastro-triggers-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.gastro-trigger-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.gastro-trigger-name {
  font-size: 0.9rem;
  color: var(--text);
}

.gastro-level-pill {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid;
}

/* Trigger level colors */
.gastro-level-none {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--muted);
}

.gastro-level-trace {
  background: rgba(251, 191, 36, 0.15);
  border-color: rgba(251, 191, 36, 0.4);
  color: var(--warn);
}

.gastro-level-low {
  background: rgba(251, 191, 36, 0.2);
  border-color: rgba(251, 191, 36, 0.5);
  color: var(--warn);
}

.gastro-level-medium {
  background: rgba(248, 113, 113, 0.15);
  border-color: rgba(248, 113, 113, 0.4);
  color: var(--bad);
}

.gastro-level-high {
  background: rgba(248, 113, 113, 0.2);
  border-color: rgba(248, 113, 113, 0.5);
  color: var(--bad);
}
