/* ==========================================================================
   STYLES.CSS — theme tokens, layout, components
   ========================================================================== */

:root {
  --accent: #4f8cff;
  --accent-2: #34d19a;
  --danger: #e5484d;
  --warn: #e0a13b;
  --radius: 14px;
}

html[data-theme="dark"] {
  --bg: #0f1115;
  --bg-alt: #161922;
  --surface: #1b1f2a;
  --surface-2: #232838;
  --border: #2a3040;
  --text: #eef1f8;
  --text-muted: #9aa3b8;
  --brand-logo: url("logo/logo-black2.png");
  --shadow: 0 4px 20px rgba(0,0,0,0.35);
}

html[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-alt: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --border: #e1e5f0;
  --text: #1a1d29;
  --text-muted: #636b80;
  --brand-logo: url("logo/logo-white2.jpeg");
  --shadow: 0 4px 16px rgba(30,40,70,0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
h2 { font-size: 1.5rem; margin: 0 0 1rem; }
h3 { font-size: 1.05rem; margin: 0 0 0.75rem; }
.muted { color: var(--text-muted); }
.small { font-size: 0.82rem; }

/* ---------- App Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.brand { font-weight: 700; font-size: 1.15rem; margin-bottom: 1.5rem; display: flex; align-items: center; gap: 0.5rem; }
.brand-mark {
  display: block;
  width: 70px;
  height: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.nav-link {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 0.75rem; border-radius: 10px; margin-bottom: 0.25rem;
  color: var(--text-muted); font-weight: 500; font-size: 0.92rem;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--accent); color: #fff; }
.nav-icon, .bn-icon {
  width: 1.05rem; height: 1.05rem; font-size: 1.05rem; line-height: 1;
  flex-shrink: 0; display: inline-block;
}
.bn-link { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--text-muted); font-size: 0.68rem; padding: 0.25rem 0.4rem; border-radius: 8px; }
.bn-link.active { color: var(--accent); }

.account-status {
  position: relative; display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem;
  margin-top: 1.5rem; padding: 0.75rem 0.5rem 0;
  border-top: 1px solid var(--border); color: var(--text-muted);
}
.account-trigger {
  display: inline-flex; align-items: center; gap: 0.5rem; min-width: 0; max-width: 100%;
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 0.4rem 0.7rem 0.4rem 0.42rem;
  color: var(--text); cursor: pointer; transition: background .15s ease, border-color .15s ease;
}
.account-trigger:hover { border-color: var(--accent); background: color-mix(in srgb, var(--surface-2) 84%, var(--accent) 16%); }
.account-avatar {
  display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px;
  border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 0.72rem; font-weight: 700; flex-shrink: 0;
}
.account-email {
  max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 0.78rem; font-weight: 600; color: var(--text); flex: 1;
}
.account-menu {
  position: absolute; top: calc(100% + 0.4rem); right: 0; z-index: 60; min-width: 172px;
  padding: 0.45rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  box-shadow: var(--shadow); display: none; flex-direction: column; gap: 0.25rem;
}
.account-status.menu-open .account-menu { display: flex; }
.account-menu-item {
  width: 100%; display: flex; align-items: center; gap: 0.55rem;
  border: 0; background: transparent; color: var(--text); border-radius: 9px; padding: 0.55rem 0.65rem;
  text-align: left; font: inherit; font-weight: 600; cursor: pointer;
}
.account-menu-item:hover { background: var(--surface-2); }
.account-menu-item.danger { color: var(--danger); }
.menu-item-icon { font-size: 0.9rem; line-height: 1; }
.account-logout { flex: 0 0 auto; }
.topbar .account-status { margin: 0; padding: 0; border-top: 0; max-width: 60%; }

.main-content { flex: 1; min-width: 0; padding: 1.5rem 1.75rem 5rem; max-width: 980px; margin: 0 auto; width: 100%; }

.topbar { display: none; }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg-alt); border-top: 1px solid var(--border);
  padding: 0.4rem 0.25rem calc(0.4rem + env(safe-area-inset-bottom));
  z-index: 50;
}
.bn-inner { display: flex; justify-content: space-around; }
.bn-link { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--text-muted); font-size: 0.68rem; padding: 0.25rem 0.4rem; border-radius: 8px; }
.bn-link.active { color: var(--accent); }

/* ---------- Cards / Layout ---------- */
.view { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.info-card { border-left: 3px solid var(--accent); }
.callout { font-weight: 600; margin: 0 0 0.4rem; }
.warn { color: var(--warn); font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.75rem; margin-bottom: 1rem; }
.stat-grid .card { margin-bottom: 0; padding: 0.9rem 1rem; }
.stat-tile { min-width: 0; padding: 0.8rem 0.9rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.dashboard-stats-card .stat-tile:nth-child(1) { border-top: 3px solid var(--accent); }
.dashboard-stats-card .stat-tile:nth-child(2) { border-top: 3px solid var(--accent-2); }
.dashboard-stats-card .stat-tile:nth-child(3) { border-top: 3px solid var(--warn); }
.dashboard-stats-card .stat-tile:nth-child(4) { border-top: 3px solid #e87575; }
.stat-label { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; }

.today-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.6rem; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.5rem; }

/* ---------- Buttons ---------- */
.btn {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.5rem 0.9rem; font-size: 0.85rem; font-weight: 600;
  cursor: pointer; transition: transform .1s ease, background .15s ease;
}
.btn:hover { background: var(--border); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.78rem; }
.btn-icon { padding: 0.3rem 0.5rem; }
.file-btn { display: inline-flex; align-items: center; cursor: pointer; }

/* ---------- Forms ---------- */
label { display: block; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.7rem; }
input, select {
  display: block; width: 100%; margin-top: 0.3rem;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 0.5rem 0.6rem; font-size: 0.9rem;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.mini-input { width: 60px; display: inline-block; }
.mini-label { display: inline-flex; flex-direction: column; font-size: 0.7rem; margin-right: 0.4rem; }
.input-row { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; margin-bottom: 0.4rem; }
.settings-search-input {
  width: 100%;
  max-width: 260px;
  min-width: 140px;
  display: inline-block;
}

@media (max-width: 700px) {
  .settings-search-input {
    width: 100%;
    min-width: 140px;
    max-width: 240px;
    flex: 1 1 220px;
    font-size: 0.92rem;
    padding: 0.7rem 0.8rem;
  }

  .input-row {
    width: 100%;
  }
}
.workout-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; margin: 1rem 0; }
.workout-option { display: flex; align-items: center; gap: 0.5rem; margin: 0; padding: 0.65rem 0.75rem; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.workout-option input { width: auto; margin: 0; accent-color: var(--accent); }
.workout-option:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface-2)); }
.workout-actions { margin-top: 0.75rem; margin-bottom: 0; }
.workout-history { display: grid; gap: 0.5rem; }
.history-heading { margin-bottom: 0.35rem; }
.history-controls { display: flex; justify-content: flex-end; margin-bottom: 0.35rem; }
.history-controls select { width: auto; margin: 0; font-size: 0.78rem; padding: 0.35rem 0.55rem; }
.show-more-btn { width: 100%; margin-top: 0.75rem; border-style: dashed; }
.workout-history-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.65rem 0; border-top: 1px solid var(--border); }
.workout-history-row:first-child { border-top: none; }
.workout-history-main { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.workout-history-note { display: block; color: var(--text-muted); line-height: 1.35; word-break: break-word; }
.workout-tags { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.3rem; }
.workout-note-field { display: block; margin: 0.85rem 0 0.7rem; color: var(--text-muted); font-size: 0.8rem; }
.workout-note-input {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  margin-top: 0.35rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 0.7rem 0.8rem;
  font: inherit;
}
.calendar-head { margin-bottom: 0.9rem; }
.workout-gallery-card { margin-top: 1rem; }
.workout-gallery-panel { display: grid; gap: 0.7rem; }
.workout-gallery-panel.collapsed .workout-gallery-grid { display: none; }
.workout-gallery-toggle {
  width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  justify-content: flex-start;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface-2) 98%, transparent), color-mix(in srgb, var(--surface) 96%, transparent));
  border: 1px solid color-mix(in srgb, var(--border) 75%, transparent);
  cursor: pointer;
}
.workout-gallery-toggle .toggle-icon { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 8px; background: color-mix(in srgb, var(--accent) 14%, var(--surface)); font-size: 1.05rem; }
.workout-gallery-toggle .toggle-label { font-weight: 700; color: var(--text); }
.workout-gallery-toggle .toggle-count { color: var(--text-muted); font-size: 0.78rem; margin-left: auto; }
.workout-gallery-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.7rem; }
.workout-gallery-item {
  overflow: hidden; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); padding: 0; cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}
.workout-gallery-item:hover { transform: translateY(-1px); border-color: var(--accent); box-shadow: 0 10px 22px rgba(79, 140, 255, 0.1); }
.workout-gallery-item img { display: block; width: 100%; height: 180px; object-fit: cover; }
.workout-gallery-caption { padding: 0.45rem 0.6rem; font-size: 0.85rem; text-align: center; color: var(--text); }
.workout-gallery-lightbox {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgba(8, 12, 18, 0.8);
  backdrop-filter: blur(3px);
  padding: 1rem;
}
.workout-gallery-viewer {
  position: relative; width: min(92vw, 980px); max-height: 92vh;
  display: flex; align-items: center; justify-content: center;
  background: rgba(17, 20, 28, 0.9); border: 1px solid rgba(255,255,255,0.1); border-radius: 18px; padding: 0.75rem;
  box-shadow: 0 30px 80px rgba(0,0,0,0.38);
}
.workout-gallery-full-image {
  display: block; max-width: 100%; max-height: 88vh; width: auto; height: auto;
  border-radius: 12px; object-fit: contain; background: rgba(255,255,255,0.02);
}
.workout-gallery-close {
  position: absolute; top: 0.6rem; right: 0.6rem;
  background: rgba(17, 20, 28, 0.8); color: #fff; border-color: rgba(255,255,255,0.18);
  border-radius: 999px; padding: 0.45rem 0.7rem;
}
.calendar-weekdays, .workout-calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.35rem; }
.calendar-weekdays { margin-bottom: 0.35rem; }
.calendar-weekdays span { color: var(--text-muted); font-size: 0.68rem; font-weight: 700; text-align: center; text-transform: uppercase; }
.calendar-day { position: relative; aspect-ratio: 1; min-height: 38px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); cursor: pointer; font-weight: 600; }
.calendar-day:hover { border-color: var(--accent); }
.calendar-day.has-workout { background: color-mix(in srgb, var(--accent-2) 20%, var(--surface-2)); border-color: var(--accent-2); }
.calendar-day.has-workout::after { content: ""; position: absolute; bottom: 5px; left: 50%; width: 5px; height: 5px; border-radius: 50%; background: var(--accent-2); transform: translateX(-50%); }
.calendar-day.selected-day { outline: 2px solid var(--accent); outline-offset: 1px; }
.calendar-empty { min-height: 38px; }
.calendar-hint { margin: 0.8rem 0 0; }
.workout-stat-layout { display: grid; grid-template-columns: 150px 1fr; align-items: center; gap: 1.4rem; }
.workout-pie { width: 150px; height: 150px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); }
.workout-pie-hole { width: 92px; height: 92px; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 50%; background: var(--surface); }
.workout-pie-hole strong { font-size: 1.45rem; line-height: 1.1; }
.workout-pie-hole span { color: var(--text-muted); font-size: 0.72rem; }
.workout-legend { display: grid; gap: 0.55rem; }
.workout-legend-row { display: grid; grid-template-columns: 9px 1fr auto; align-items: center; gap: 0.5rem; font-size: 0.84rem; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; }
.workout-filters { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 0.75rem; }
.workout-filters label { margin: 0; }
.filter-apply-btn { margin-top: 0.75rem; }
.workout-week { display: grid; grid-template-columns: repeat(8, 1fr); gap: 0.45rem; align-items: end; margin: 1rem 0 0.5rem; }
.workout-week-day { display: grid; gap: 0.35rem; justify-items: center; color: var(--text-muted); font-size: 0.7rem; }
.workout-week-bar { height: 62px; width: 100%; display: flex; align-items: flex-end; background: var(--surface-2); border-radius: 7px; overflow: hidden; }
.workout-week-bar i { display: block; width: 100%; height: 16%; background: var(--border); }
.workout-week-day.active { color: var(--accent-2); font-weight: 700; }
.workout-week-day.active .workout-week-bar i { height: 72%; background: var(--accent-2); }
.dashboard-rings { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 1rem; padding: 0.75rem 0 1rem; }
.dashboard-glance-card { border-top: 3px solid var(--accent-2); background: linear-gradient(135deg, var(--surface), color-mix(in srgb, var(--surface) 84%, var(--accent-2) 16%)); }
.dashboard-section-head { align-items: flex-start; }
.dashboard-section-head p { margin: 0.15rem 0 0; }
.dashboard-stats-card { background: var(--bg-alt); }
.dashboard-goal-card { border: 1px solid color-mix(in srgb, var(--warn) 55%, var(--border)); background: linear-gradient(135deg, color-mix(in srgb, var(--surface) 88%, var(--warn) 12%), var(--surface)); }
.goal-kicker { color: var(--warn); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.dashboard-goal-title { color: var(--text); font-size: 1.1rem; margin-top: 0.25rem; }
.goal-target { display: flex; align-items: baseline; gap: 0.45rem; margin: 0.8rem 0; color: var(--warn); }
.goal-target strong { font-size: 2rem; line-height: 1; }
.goal-target span { color: var(--text-muted); font-size: 0.78rem; }
.dashboard-ring { display: grid; justify-items: center; gap: 0.4rem; }
.dashboard-ring::before { content: ""; grid-area: 1 / 1; width: 94px; height: 94px; border-radius: 50%; background: conic-gradient(from 0deg, var(--ring-color), color-mix(in srgb, var(--ring-color) 45%, white) 12%, var(--ring-color) 25%, var(--ring-color) var(--ring-progress), var(--surface-2) 0); animation: ring-spin 10s linear infinite, ring-pulse 3.2s ease-in-out infinite; }
.dashboard-ring-hole { z-index: 1; grid-area: 1 / 1; align-self: center; width: 68px; height: 68px; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 50%; background: var(--surface); }
.dashboard-ring-hole strong {
  max-width: 100%;
  color: var(--ring-color);
  font-size: 0.64rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
  white-space: normal;
  text-align: center;
  word-break: break-word;
  padding: 0 4px;
}
.dashboard-ring-hole span { color: var(--text-muted); font-size: 0.65rem; }
.dashboard-ring-label { color: var(--ring-color); font-size: 0.75rem; font-weight: 700; }
.ring-blue { --ring-color: var(--accent); }
.ring-green { --ring-color: var(--accent-2); }
.ring-gold { --ring-color: var(--warn); }
.ring-red { --ring-color: #e87575; }
.ring-purple { --ring-color: #b18ce6; }
.dashboard-links { display: flex; justify-content: center; gap: 0.5rem; }
@keyframes ring-spin { to { transform: rotate(360deg); } }
@keyframes ring-pulse { 0%, 100% { filter: drop-shadow(0 0 0 color-mix(in srgb, var(--ring-color) 0%, transparent)); } 50% { filter: drop-shadow(0 0 7px color-mix(in srgb, var(--ring-color) 48%, transparent)); } }
@media (max-width: 700px) {
  .totals-card {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    width: auto;
    transform: none;
    z-index: auto;
  }
  .meal-summary-grid {
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 0.45rem;
  }
  .meal-summary-card {
    min-height: 74px;
    padding: 0.5rem 0.55rem;
  }
  .meal-summary-name {
    font-size: 0.8rem;
  }
  .meal-summary-meta,
  .meal-summary-kcal {
    font-size: 0.66rem;
  }
  .go-top-btn {
    right: 0.8rem;
    bottom: calc(4.8rem + env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .dashboard-ring::before { animation: none; }
}

/* Hide native number-input spin buttons everywhere. We have our own +/- steppers
   next to quantity fields, and the native spinner box eats horizontal space —
   on a narrow input that's exactly what was clipping "100" down to "10". */
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* ---------- Nutrition ---------- */
.date-nav { display: flex; align-items: center; gap: 0.5rem; }
.date-nav-label { font-size: 0.85rem; font-weight: 600; min-width: 5.5rem; text-align: center; }
.totals-card {
  position: relative;
  top: auto;
  left: auto;
  transform: none;
  width: auto;
  z-index: auto;
  border-top: 3px solid var(--accent);
  background: linear-gradient(135deg, var(--surface), color-mix(in srgb, var(--surface) 84%, var(--accent-2) 16%));
  box-shadow: none;
}
.totals-card { transition: transform 0.2s ease, opacity 0.2s ease; }
.totals-card > .row-between { margin-bottom: 0.9rem; }
.totals-card > .row-between h3 { color: var(--accent-2); }
.calorie-summary { color: var(--accent); font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.calorie-summary div:last-child { color: var(--text-muted); font-size: 0.78rem; font-weight: 600; }
.calorie-summary.calorie-alert, .calorie-summary.calorie-alert div:last-child { color: var(--danger); }
.totals-card .pbar-wrap { padding: 0.35rem 0; }
.totals-card .pbar-labels { font-weight: 600; }
.totals-card .pbar-labels span:last-child { color: var(--metric-color, var(--text)); font-variant-numeric: tabular-nums; font-weight: 800; }
.totals-card .pbar-labels span:first-child { font-weight: 800; letter-spacing: 0.01em; }
.totals-card .pbar-calories { --metric-color: var(--accent); }
.totals-card .pbar-protein { --metric-color: var(--accent-2); }
.totals-card .pbar-carbs { --metric-color: #e8b04a; }
.totals-card .pbar-fat { --metric-color: #e87575; }
.totals-card .pbar-fiber { --metric-color: #b18ce6; }
.totals-card .pbar-calories .pbar-labels span:first-child { color: var(--accent); }
.totals-card .pbar-protein .pbar-labels span:first-child { color: var(--accent-2); }
.totals-card .pbar-carbs .pbar-labels span:first-child { color: #e8b04a; }
.totals-card .pbar-fat .pbar-labels span:first-child { color: #e87575; }
.totals-card .pbar-fiber .pbar-labels span:first-child { color: #b18ce6; }
.totals-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.85rem;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.totals-actions .btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.totals-card .pbar-fill { background: var(--metric-color, var(--accent-2)); box-shadow: 0 0 8px color-mix(in srgb, var(--metric-color, var(--accent-2)) 35%, transparent); transition: width .45s ease, background .2s ease; }
.totals-card .pbar-fill.over { background: var(--warn); }

.meal-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.55rem;
  margin: 1rem 0 0.75rem;
}
.meal-summary-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.12rem;
  width: 100%;
  min-height: 82px;
  padding: 0.6rem 0.7rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.meal-summary-card:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--surface-2) 84%, var(--accent) 16%);
}
.meal-summary-name {
  font-size: 0.95rem;
  line-height: 1.2;
}
.meal-summary-meta {
  display: inline-block;
  font-size: 0.68rem;
  line-height: 1.2;
}
.meal-summary-kcal {
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 700;
}
.meal-targeted {
  animation: meal-highlight 1.4s ease;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
@keyframes meal-highlight {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 25%, transparent); }
  30% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 18%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent); }
}

.go-top-btn {
  position: fixed;
  right: 1rem;
  bottom: 4.5rem;
  z-index: 60;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  box-shadow: var(--shadow);
  background: rgba(16, 18, 25, 0.92);
  backdrop-filter: blur(6px);
}
.go-top-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

html { scroll-padding-top: 90px; }

.meal-card .food-items { margin-bottom: 0.5rem; }
.meal-card-collapsed { opacity: 0.82; }
.meal-card-collapsed .meal-name-input { color: var(--text-muted); }
.meal-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.5rem; flex-wrap: wrap; }
.meal-name-group { display: flex; align-items: center; gap: 0.5rem; flex: 1 1 180px; min-width: 0; }
.meal-head-right { display: flex; align-items: center; gap: 0.4rem; flex: 0 0 auto; }
.meal-name-input { font-weight: 700; font-size: 1.02rem; border: none; background: transparent; padding: 0.1rem 0; margin: 0; flex: 1 1 160px; min-width: 0; }
.meal-name-input:focus { outline: 1px solid var(--border); border-radius: 6px; }
.meal-toggle { display: inline-flex; align-items: center; gap: 0.25rem; white-space: nowrap; flex-shrink: 0; }
.meal-time-input { width: auto; min-width: 6.4em; margin: 0; flex: 0 0 auto; }

.food-item { display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.food-item:first-child { border-top: none; }
.food-item-name { flex: 1 1 140px; font-size: 0.86rem; display: flex; align-items: center; gap: 0.4rem; }
.tag { font-size: 0.65rem; background: var(--surface-2); color: var(--text-muted); padding: 0.1rem 0.4rem; border-radius: 10px; white-space: nowrap; }
.in-qty {
  width: 4.2em; min-width: 52px; flex: 0 0 auto; margin-top: 0;
  padding: 0.4rem 0.3rem; text-align: center; font-variant-numeric: tabular-nums;
}
.qty-stepper { display: flex; align-items: center; gap: 0.35rem; flex: 0 0 auto; }
.step-btn {
  padding: 0; line-height: 1; width: 34px; height: 34px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center; font-size: 1rem;
}
.food-macros { font-size: 0.76rem; color: var(--text-muted); flex: 1 1 180px; }
.meal-subtotal { text-align: right; padding-top: 0.3rem; border-top: 1px dashed var(--border); margin-bottom: 0.6rem; }

.add-food-row { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.food-lib-list { margin-top: 0.4rem; }
.food-search { flex: 1 1 180px; margin-top: 0; }
.input-error { border-color: var(--danger) !important; }

.food-override-row { display: flex; align-items: flex-end; gap: 0.4rem; padding: 0.5rem 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.food-override-row:first-of-type { border-top: none; }
.settings-card-head { margin-bottom: 0.35rem; }
.settings-card-head h3 { color: var(--text); }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: .02em; }
.active-history-row { background: var(--surface-2); }

/* ---------- Charts ---------- */
.chart-wrap { margin-top: 0.5rem; }
.trend-chart { width: 100%; height: 90px; margin-top: 0.3rem; }
.trend-line { fill: none; stroke: var(--accent); stroke-width: 2; }
.trend-dot { fill: var(--accent-2); }
.progress-entry-card { border-left: 3px solid var(--accent); }
.today-weight-card { border: 1px solid color-mix(in srgb, var(--accent-2) 60%, var(--border)); border-top: 3px solid var(--accent-2); background: linear-gradient(135deg, var(--surface), color-mix(in srgb, var(--surface) 84%, var(--accent-2) 16%)); }
.progress-entry-head, .progress-panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.8rem; }
.progress-entry-head h3, .progress-panel-head h3 { margin: 0.15rem 0 0; }
.progress-kicker { color: var(--accent-2); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.progress-weight-input { border-color: color-mix(in srgb, var(--accent-2) 55%, var(--border)); background: color-mix(in srgb, var(--surface-2) 78%, var(--accent-2) 12%); font-size: 1.2rem; font-weight: 700; }
.today-weight-card .progress-weight-input { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-2) 12%, transparent); }
.progress-note-input { background: color-mix(in srgb, var(--surface-2) 92%, var(--accent) 8%); }
.progress-entry-actions { gap: 0.6rem; margin-top: 1rem; margin-bottom: 0; }
.progress-save-button { min-height: 42px; box-shadow: 0 5px 14px color-mix(in srgb, var(--accent) 24%, transparent); }
.progress-delete-button { min-height: 38px; background: transparent; }
.progress-trend-card { border-top: 3px solid var(--accent); }
.progress-history-card { border-top: 3px solid var(--warn); }

/* ---------- Pills / badges ---------- */
.pill { font-size: 0.72rem; font-weight: 700; padding: 0.2rem 0.6rem; border-radius: 20px; }
.pill-good { background: rgba(52, 209, 154, 0.15); color: var(--accent-2); }
.pill-warn { background: rgba(224, 161, 59, 0.15); color: var(--warn); }
.pill-neutral { background: var(--surface-2); color: var(--text-muted); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 12, 18, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem; z-index: 100; animation: fade .15s ease;
}
.modal-dialog {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto;
  padding: 1.2rem 1.3rem;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.modal-body label { margin-bottom: 0.65rem; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.75rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }

/* ---------- Toast ---------- */
#toast-host { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 0.4rem; align-items: center; pointer-events: none; }
.toast {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.55rem 1rem; font-size: 0.85rem; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(8px); transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
@media (max-width: 760px) { #toast-host { bottom: 5rem; } }

/* ---------- Onboarding wizard ---------- */
body.onboarding .sidebar,
body.onboarding .bottom-nav,
body.onboarding .topbar { display: none !important; }
body.onboarding .main-content { max-width: 560px; padding-top: clamp(1.5rem, 6vh, 4rem); }

body.login-screen .sidebar,
body.login-screen .bottom-nav,
body.login-screen .topbar { display: none !important; }
body.login-screen .account-status { display: none; }
body.login-screen .main-content { max-width: 460px; padding-top: clamp(2rem, 12vh, 7rem); }

.login-view { animation: fade .2s ease; display: flex; flex-direction: column; align-items: center; }
.login-brand {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin-bottom: 1.5rem;
}
.login-brand .brand-mark {
  width: 190px;
  height: auto;
  margin: 0 auto;
}
.login-card { text-align: center; width: 100%; }
.login-card h2 { margin-bottom: 0.4rem; }
.login-button { width: 100%; margin-top: 0.5rem; }

.access-request-box {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.6rem 0.8rem;
  margin: 0.6rem 0;
}
.access-request-identity { word-break: break-all; }
.access-denied-actions { flex-direction: column; align-items: stretch; }

.onboard-hero { text-align: center; margin-bottom: 1.25rem; }
.onboard-hero .brand { justify-content: center; margin-bottom: 0.75rem; }
.onboard-hero h2 { margin-bottom: 0.4rem; }

.onboard-progress { display: flex; gap: 0.4rem; justify-content: center; margin-bottom: 1rem; }
.onboard-progress span { width: 8px; height: 8px; border-radius: 50%; background: var(--border); display: block; }
.onboard-progress span.active { background: var(--accent); }

.target-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; margin: 1rem 0; }
.target-grid .card { margin-bottom: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .sidebar { display: none; }
  .bottom-nav { display: block; }
  .main-content {
    margin: 0 auto;
    max-width: 100%;
    width: 100%;
    padding: 1rem 1rem calc(5.5rem + env(safe-area-inset-bottom));
  }
  .topbar {
    display: flex; align-items: center; justify-content: flex-start;
    gap: 0.75rem;
    padding: calc(0.9rem + env(safe-area-inset-top)) 1rem 0.9rem;
    background: var(--bg-alt); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 40;
  }
  .topbar .brand { margin: 0; }
  .topbar .account-status { margin-left: auto; }

  /* iOS Safari zooms the whole page in on focus of any input under 16px —
     force every form control to 16px on small screens so typing doesn't
     yank the viewport around. */
  input, select { font-size: 16px; }

  /* Card padding/margins trimmed a bit so more content fits without feeling
     cramped, and touch targets get roomier since fingers, not cursors. */
  .card { padding: 1rem; margin-bottom: 0.85rem; }
  .btn { padding: 0.6rem 0.9rem; }
  .btn-icon { padding: 0.5rem 0.6rem; min-width: 40px; min-height: 40px; }

  /* Keep the daily totals section visible as a normal card while scrolling on mobile. */
  .totals-card {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    transform: none;
    opacity: 1;
    pointer-events: auto;
  }
  .totals-actions { margin-top: 0.7rem; }

  .meal-head { gap: 0.6rem; }
  .meal-name-group { width: 100%; }
  .meal-toggle { font-size: 0.72rem; padding: 0.35rem 0.5rem; }
  .go-top-btn {
    left: 50%;
    right: auto;
    bottom: calc(5.8rem + env(safe-area-inset-bottom));
    z-index: 70;
    transform: translateX(-50%);
  }
  .go-top-btn.visible {
    transform: translateX(-50%) translateY(0);
  }
  .progress-entry-actions { align-items: stretch; }
  .progress-save-button { flex: 1 1 100%; }
  .progress-delete-button { flex: 1 1 100%; }
  .dashboard-rings { gap: 0.5rem; }
  .dashboard-rings { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dashboard-glance-card { padding-top: 0.9rem; }
  .dashboard-section-head .pill { flex-shrink: 0; }
  .dashboard-ring::before { width: 78px; height: 78px; }
  .dashboard-ring-hole { width: 56px; height: 56px; }
  .dashboard-ring-hole strong { max-width: 54px; font-size: 0.58rem; }
  .workout-options { grid-template-columns: repeat(2, 1fr); }
  .workout-stat-layout { grid-template-columns: 1fr; justify-items: center; }
  .workout-legend { width: 100%; }
  .workout-filters { grid-template-columns: 1fr; gap: 0.25rem; }
  .settings-card-head { align-items: flex-start; }
  .settings-card-head h3 { max-width: 60%; }
  .meal-name-input { font-size: 1rem; flex-basis: 100%; }
  .meal-head-right { flex-basis: 100%; justify-content: space-between; }
  .meal-time-input { flex: 1 1 auto; }

  .food-item { gap: 0.5rem 0.6rem; }
  .food-item-name { flex-basis: 100%; order: 1; }
  .qty-stepper { order: 2; }
  .step-btn { width: 38px; height: 38px; }
  .food-macros { flex-basis: 100%; order: 3; }
  .food-item > .btn-icon { order: 4; margin-left: auto; }

  .add-food-row { flex-direction: column; align-items: stretch; }
  .add-food-row .food-search { flex-basis: auto; }
}

@media (max-width: 420px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 1.25rem; }
  .modal-grid { grid-template-columns: 1fr; }
  .target-grid { grid-template-columns: 1fr; }
  .workout-options { grid-template-columns: 1fr; }
  .workout-history-row { align-items: flex-start; flex-direction: column; gap: 0.45rem; }
  .workout-tags { justify-content: flex-start; }
  .stat-grid .card { padding: 0.75rem 0.8rem; }
}

@media (max-width: 760px) and (orientation: portrait) {
  /* Leave room for the iPhone home-indicator so action buttons at the
     bottom of a modal are never covered by it. */
  .modal-dialog { padding: 1.1rem 1.1rem calc(1.1rem + env(safe-area-inset-bottom)); }
}