:root {
  --bg: #0f0f12;
  --surface: #18181e;
  --surface-2: #22222b;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f4f3f0;
  --text-muted: #9c9aa4;
  --accent: #c9a962;
  --accent-muted: rgba(201, 169, 98, 0.35);
  --danger: #e07a6e;
  --radius: 12px;
  --font: 'DM Sans', system-ui, -apple-system, sans-serif;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  padding: 1.25rem clamp(1rem, 4vw, 2rem) 6.5rem;
}

/* While a bottom sheet is open, keep the page from scrolling behind it.
   JS also sets body position:fixed + top offset (see meal-tracker-app) for iOS / touch. */
html.sheet-scroll-lock {
  overflow: hidden;
  overscroll-behavior: none;
}

html.sheet-scroll-lock body {
  overflow: hidden;
}

a {
  color: var(--accent);
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell {
  max-width: 560px;
  margin: 0 auto;
}

.brand {
  font-weight: 600;
  letter-spacing: -0.02em;
  font-size: 1.35rem;
  margin: 0;
}

.subtle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0.2rem 0 1.25rem;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

@media (max-width: 430px) {
  .day-nav-secondary [data-today] {
    padding: 0.45rem;
    min-width: 2.5rem;
    min-height: 2.5rem;
    gap: 0;
  }

  .day-nav-secondary [data-today] .btn-text {
    display: none;
  }
}

.day-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.day-nav-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.day-nav-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.day-limit-hint {
  margin: -0.55rem 0 0.85rem;
}

.date-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  color: var(--text);
}

.date-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.day-title-trigger {
  min-width: 0;
  max-width: 100%;
  padding: 0.45rem 0.65rem;
}

.day-title-trigger [data-date-title] {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: var(--surface-2);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-primary {
  background: linear-gradient(180deg, rgba(201, 169, 98, 0.22), rgba(201, 169, 98, 0.12));
  border-color: var(--accent-muted);
  color: var(--text);
}

.btn-primary:hover {
  background: linear-gradient(180deg, rgba(201, 169, 98, 0.35), rgba(201, 169, 98, 0.18));
}

.btn-ghost {
  background: transparent;
}

.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  display: block;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0.45rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
}

.btn-small.btn-icon {
  min-width: 2.25rem;
  min-height: 2.25rem;
  padding: 0.35rem;
}

.btn-small.btn-icon .icon {
  width: 1.1rem;
  height: 1.1rem;
}

.btn-with-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.btn-with-icon .btn-text {
  line-height: 1;
}

.btn-compact {
  padding: 0.35rem 0.55rem;
  font-size: 0.82rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.sheet-actions-single {
  justify-content: flex-end;
}

.btn-full {
  width: 100%;
  justify-content: center;
}

.username-onboarding-header {
  text-align: center;
  padding: 0.5rem 0 1.5rem;
}

.username-app-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  margin: 0 auto 0.75rem;
  display: block;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.username-app-name {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
  margin: 0 0 0.25rem;
}

.username-app-tagline {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0;
}

.recover-section {
  border-top: 1px solid var(--border);
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

[data-delete-id]:hover {
  color: var(--danger);
  border-color: rgba(224, 122, 110, 0.4);
}

.totals-bar {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.totals-metric {
  flex: 1;
  min-width: 0;
}

.totals-metric--compact .totals-metric-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.45rem;
  margin: 0 0 0.3rem;
  font-size: 0.82rem;
  flex-wrap: wrap;
}

.totals-metric-label {
  color: var(--text-muted);
  font-weight: 500;
  flex-shrink: 0;
}

.totals-metric-amount {
  text-align: right;
  min-width: 0;
}

.totals-metric-line strong {
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.totals-metric-suffix {
  margin: 0;
  font-size: 0.78rem;
}

/* Goal rings */
.totals-ring-group {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  flex-wrap: wrap;
}

.totals-ring-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.totals-ring-label {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.totals-ring-label .totals-metric-label {
  font-size: 0.75rem;
  margin: 0;
}

.totals-ring-label .totals-metric-amount {
  text-align: left;
  margin: 0;
}

.totals-ring-label .totals-metric-amount strong {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.totals-ring-label .totals-metric-suffix {
  font-size: 0.75rem;
}

.goal-ring {
  flex-shrink: 0;
  display: block;
  width: 48px;
  height: 48px;
}

.goal-ring-track {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 4;
}

.goal-ring-fill {
  fill: none;
  stroke-width: 4;
  stroke-dasharray: 0 113.097;
  transition: stroke-dasharray 0.35s ease;
}

.goal-ring-fill--cal {
  stroke: var(--accent);
}

.goal-ring-fill--cal.goal-ring-fill--warning {
  stroke: #f0a652;
}

.goal-ring-fill--cal.goal-ring-fill--danger {
  stroke: var(--danger);
}

.goal-ring-fill--protein {
  stroke: #5ba3f5;
}

.totals-target-status {
  margin: 0.35rem 0 0;
  font-size: 0.76rem;
}

/* Portion chips */
.portion-chips {
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
}

.portion-chips-label {
  margin: 0 0 0.35rem;
  font-size: 0.76rem;
}

.portion-chips-row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.portion-chip {
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
}

.portion-chip.is-active {
  background: var(--accent);
  color: var(--on-accent, #fff);
  border-color: var(--accent);
}

/* Recovery code banner */
.recovery-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.recovery-banner-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.recovery-banner-code {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--accent);
  flex: 1;
}

.recovery-banner-copy {
  font-size: 0.82rem;
  white-space: nowrap;
}

.recovery-banner-dismiss {
  margin-left: auto;
  flex-shrink: 0;
}

/* Recent meals in add-actions sheet */
.recent-meals-section {
  margin-bottom: 0.25rem;
}

.recent-meals-label {
  margin: 0 0 0.3rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.recent-meals-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.recent-meal-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  max-width: calc(50% - 0.2rem);
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.recent-meal-chip:active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}


@keyframes day-total-pulse {
  0% {
    color: var(--text);
    text-shadow: none;
  }
  35% {
    color: var(--accent);
    text-shadow: 0 0 16px rgba(201, 169, 98, 0.45);
  }
  100% {
    color: var(--text);
    text-shadow: none;
  }
}

.day-total-flash {
  animation: day-total-pulse 520ms ease-out;
}

.week-chart-card {
  padding: 0.65rem 0.85rem 0.55rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.week-chart-card-head {
  margin-bottom: 0.35rem;
}

.week-chart-head-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  gap: 0.25rem 0.65rem;
}

.week-chart-head-row .week-chart-sub {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.week-chart-toggle {
  display: inline-flex;
  gap: 0.3rem;
  margin-top: 0;
  margin-left: auto;
  flex: 0 0 auto;
}

.week-chart-toggle-btn.is-active {
  border-color: var(--accent-muted);
  background: rgba(201, 169, 98, 0.16);
}

.week-chart-heading {
  margin: 0 0 0.15rem;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.week-chart-sub {
  margin: 0;
  font-size: 0.78rem;
}

.week-chart-empty {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
}

.week-chart-metric {
  min-height: 90px;
}

.week-chart-metric svg {
  display: block;
  max-width: 100%;
}

.week-chart-card--empty .week-chart-metric svg rect {
  opacity: 0.18;
}

.entry-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  /* Keep the last row's actions clear of the floating FAB. */
  padding-bottom: calc(5.25rem + env(safe-area-inset-bottom, 0px));
}

.fab-add {
  position: fixed;
  right: clamp(1rem, 4vw, 2rem);
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  width: 56px;
  height: 56px;
  border-radius: 999px;
  border: 2px solid rgba(15, 15, 18, 0.92);
  background: var(--accent);
  color: #1a1408;
  font-size: 2rem;
  line-height: 1;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.45),
    0 2px 8px rgba(0, 0, 0, 0.25);
  z-index: 95;
}

.fab-add:hover {
  background: #d8b86f;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(24, 24, 30, 0.95);
  box-shadow: var(--shadow);
  z-index: 130;
}

.entry-card {
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

@keyframes entry-card-save-in {
  0% {
    transform: translateY(-8px);
    opacity: 0.7;
    border-color: rgba(201, 169, 98, 0.45);
  }
  100% {
    transform: translateY(0);
    opacity: 1;
    border-color: var(--border);
  }
}

.entry-card--new {
  animation: entry-card-save-in 140ms ease-out;
}

.entry-card-hit {
  width: 100%;
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.entry-card-hit:focus {
  outline: none;
}

.entry-card-hit:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.entry-card-hit-inner {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.entry-card:hover {
  border-color: rgba(201, 169, 98, 0.25);
}

.thumb {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: opacity 0.2s ease;
}

.thumb-lazy {
  /* Skeleton shimmer while remote image is being fetched / decoded */
  background: linear-gradient(
    90deg,
    var(--surface-2) 25%,
    var(--surface-3, #2e2e3a) 50%,
    var(--surface-2) 75%
  );
  background-size: 200% 100%;
  animation: thumb-shimmer 1.4s ease-in-out infinite;
}

@keyframes thumb-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.thumb-placeholder .icon {
  width: 1.35rem;
  height: 1.35rem;
  opacity: 0.55;
}

.entry-body {
  flex: 1;
  min-width: 0;
}

.entry-hit-kcal {
  flex-shrink: 0;
  text-align: right;
  padding-top: 0.05rem; /* optical alignment with label-line */
}

.badge {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.label-line {
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.4;
  word-break: break-word;
  color: var(--text);
}

.cals {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.cals-unit {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 0.15rem;
}

.entry-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.45rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.entry-footer-meta {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.entry-actions-row {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  flex-shrink: 0;
}

.btn-small {
  padding: 0.25rem 0.5rem;
  font-size: 0.82rem;
}

.entry-feedback {
  display: flex;
  gap: 0.1rem;
}

.feedback-thumb {
  opacity: 0.35;
  transition: opacity 0.15s, color 0.15s;
}

.feedback-thumb:active,
.feedback-thumb.is-active {
  opacity: 1;
}

.feedback-thumb--up.is-active {
  color: var(--accent);
}

.feedback-thumb--down.is-active {
  color: var(--danger, #e05c5c);
}

/* ── Confidence chip ─────────────────────────────── */
.confidence-chip {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.18rem 0.4rem;
  border-radius: 6px;
  border: 1px solid currentColor;
  background: transparent;
  cursor: pointer;
  line-height: 1;
}

.confidence-chip--low {
  color: #c47800;
  border-color: #c4780055;
  background: #c4780012;
}

.confidence-chip--medium {
  color: var(--text-muted);
  border-color: var(--border);
  background: var(--surface-2);
}

.confidence-chip--high {
  color: #2a9d5c;
  border-color: #2a9d5c55;
  background: #2a9d5c12;
}

.confidence-assumptions {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0.5rem 0 0;
  line-height: 1.5;
  word-break: break-word;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty-state p {
  margin: 0.35rem 0 0;
}

@keyframes sheet-backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes sheet-panel-in {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 120;
  padding: 1rem;
  animation: sheet-backdrop-in 0.18s ease-out;
}

.sheet:not(.hidden) {
  overscroll-behavior: contain;
}

.sheet-panel {
  position: relative;
  width: min(520px, 100%);
  max-height: min(90vh, 720px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.1rem;
  box-shadow: var(--shadow);
  animation: sheet-panel-in 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet-panel { animation: none; }
}

/* Required onboarding (first run / post-logout): fill the viewport so the
   app skeleton doesn't bleed through. Solid background shows immediately
   (no backdrop fade) so there's no flash; only the panel animates in. */
.sheet--fullscreen {
  background: var(--bg);
  padding: 0;
  animation: none;
}

.sheet--fullscreen .sheet-panel {
  width: 100%;
  max-width: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  border-radius: 0;
  border: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

@media (min-width: 640px) {
  .sheet--fullscreen {
    background: rgba(0, 0, 0, 0.6);
    padding: 1rem;
    animation: sheet-backdrop-in 0.18s ease-out;
  }
  .sheet--fullscreen .sheet-panel {
    width: min(480px, 100%);
    height: auto;
    max-height: 90vh;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: block;
  }
}

.add-actions-sheet {
  max-height: min(80vh, 540px);
  overflow-y: auto;
}

.add-actions-photo-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.add-action-photo-btn {
  flex-direction: column;
  gap: 0.35rem;
  padding: 1rem 0.5rem;
}

.add-action-photo-btn svg {
  width: 1.6rem;
  height: 1.6rem;
}

.add-actions-divider {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0 0.25rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.add-actions-divider::before,
.add-actions-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.settings-sheet {
  max-height: min(72vh, 440px);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.settings-header h3 {
  margin: 0;
}

.settings-done-btn {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  padding: 0.25rem 0.1rem;
}

.settings-block {
  padding: 0.7rem 0;
  border-top: 1px solid var(--border);
}

.settings-block:first-of-type {
  border-top: 0;
  padding-top: 0.2rem;
}

.settings-identity {
  margin: 0.3rem 0 0.35rem;
}

.recovery-code-inline {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.recovery-code-copy-btn {
  padding: 0.2rem;
  opacity: 0.5;
  color: var(--text);
  line-height: 0;
}

.recovery-code-copy-btn:hover,
.recovery-code-copy-btn:active {
  opacity: 1;
}

.recovery-code-copy-btn .icon {
  width: 1rem;
  height: 1rem;
}

.settings-recovery-label {
  margin: 0.5rem 0 0.15rem;
}

.recovery-code-tap-hint {
  font-style: italic;
  opacity: 0.65;
}

.settings-recovery-code {
  font-family: 'Courier New', monospace;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  margin: 0 0 0.6rem;
  cursor: pointer;
  display: inline-block;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  -webkit-tap-highlight-color: transparent;
}

.settings-recovery-code:active {
  background: var(--surface-3, var(--surface-2));
}

.settings-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.feedback-textarea {
  width: 100%;
  min-height: 6rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--color-border, #ddd);
  border-radius: 0.5rem;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  background: var(--color-surface, #fff);
  color: var(--color-text, #111);
}

.feedback-thanks {
  color: var(--color-success, green);
  font-size: 0.9rem;
  margin-top: 0.4rem;
}

.settings-targets-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.45rem 0.65rem;
  margin-top: 0.2rem;
}

.settings-target-field {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  min-width: 0;
}

.settings-target-field label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.settings-target-field input {
  width: 100%;
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.settings-block .settings-targets-row + .error-text {
  margin-top: 0.4rem;
}

@keyframes sheet-model-wait-pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

/* Model in flight: top bar + busy cursor; pseudos ignore pointer events so Save/Close still work. */
.sheet-panel.sheet-panel--model-wait {
  cursor: progress;
}

.sheet-panel.sheet-panel--model-wait::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 2;
  pointer-events: none;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--accent);
  animation: sheet-model-wait-pulse 0.85s ease-in-out infinite;
}

.sheet-panel.sheet-panel--model-wait::after {
  content: 'Working…';
  position: absolute;
  top: 0.45rem;
  left: 1.1rem;
  right: 1.1rem;
  z-index: 2;
  pointer-events: none;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.2;
}

@media (prefers-reduced-motion: reduce) {
  .sheet-panel.sheet-panel--model-wait::before {
    animation: none;
    opacity: 0.9;
  }
}

.sheet-panel h3 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.form-row label {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.form-row input,
.form-row select {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
}

/* One row: calories + protein inputs + Re-estimate / help. */
.form-row-nutrition-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  grid-template-rows: auto auto auto;
  gap: 0.35rem 0.5rem;
  align-items: end;
  margin-bottom: 0;
}

.form-row-nutrition-row .nutrition-field {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  min-width: 0;
}

.form-row-nutrition-row .nutrition-field label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.form-row-nutrition-row .nutrition-input {
  width: 100%;
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.form-row-nutrition-row .nutrition-field--cal {
  grid-column: 1;
  grid-row: 1;
}

.form-row-nutrition-row .nutrition-field--protein {
  grid-column: 2;
  grid-row: 1;
}

.form-row-nutrition-row .nutrition-actions {
  grid-column: 3;
  grid-row: 1;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding-bottom: 0.1rem;
  min-width: 0;
}

.form-row-nutrition-row .nutrition-est-hint {
  grid-column: 1 / -1;
  grid-row: 2;
  margin: 0.1rem 0 0;
}

.form-row-nutrition-row .nutrition-est-err {
  grid-column: 1 / -1;
  grid-row: 3;
  margin: 0;
}

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

  .form-row-nutrition-row .nutrition-field--cal {
    grid-column: 1;
    grid-row: 1;
  }

  .form-row-nutrition-row .nutrition-field--protein {
    grid-column: 2;
    grid-row: 1;
  }

  .form-row-nutrition-row .nutrition-actions {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
  }

  .form-row-nutrition-row .nutrition-est-hint {
    grid-row: 3;
  }

  .form-row-nutrition-row .nutrition-est-err {
    grid-row: 4;
  }
}

.reestimate-with-help {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.reestimate-with-help .btn-suggested {
  border-color: var(--accent-muted);
  background: linear-gradient(180deg, rgba(201, 169, 98, 0.28), rgba(201, 169, 98, 0.14));
}

.estimate-help-trigger {
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  font-weight: 600;
  line-height: 1;
}

.estimate-help-dialog {
  margin: auto;
  padding: 0;
  max-width: min(22rem, calc(100vw - 2rem));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.estimate-help-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.estimate-help-dialog-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
}

.estimate-help-dialog-body {
  font-size: 0.88rem;
  line-height: 1.45;
}

.estimate-help-list {
  margin: 0;
  padding-left: 1.15rem;
}

.estimate-help-list li + li {
  margin-top: 0.35rem;
}

.estimate-help-dialog-actions {
  margin: 0;
  display: flex;
  justify-content: flex-end;
}

.sheet-band--meal,
.sheet-band--numbers {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.sheet-band--numbers {
  margin-top: 0.45rem;
}

.sheet-band--meal .form-row:last-child {
  margin-bottom: 0;
}

.photo-vision-block {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-bottom: 0.85rem;
}

.photo-vision-block [data-retry-photo-estimate] {
  align-self: flex-start;
}

.photo-selected-images {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  overflow-x: auto;
  padding-bottom: 0.1rem;
}

.sheet-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.preview-img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.edit-media-band {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.edit-photo-picker-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.edit-images {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  overflow-x: auto;
  padding-bottom: 0.1rem;
}

.edit-image-chip {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  background: transparent;
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  overflow: hidden;
  position: relative;
}

.edit-image-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.edit-image-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 0.9rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.hint {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.error-text {
  color: var(--danger);
  font-size: 0.88rem;
}

/* ─── Onboarding card ─────────────────────────────────────────────────────── */

.onboarding-card {
  margin: 0.75rem 0 1rem;
  padding: 1rem 1rem 0.85rem;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.onboarding-card-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin: 0 0 0.3rem;
}

.onboarding-card .hint {
  margin: 0 0 0.65rem;
}

.onboarding-card-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ─── Wizard ──────────────────────────────────────────────────────────────── */

.settings-wizard-expander {
  margin-bottom: 0.6rem;
}

.settings-wizard-toggle {
  color: var(--accent);
  padding-left: 0;
  font-size: 0.85rem;
}

.settings-wizard-body {
  margin-top: 0.5rem;
}

.wizard-body {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.wizard-step {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.wizard-step-label {
  margin: 0;
  font-weight: 500;
}

.wizard-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.wizard-chip {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  font-size: 0.84rem;
  cursor: pointer;
  line-height: 1.3;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.wizard-chip.is-active,
.wizard-chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.wizard-chip:active {
  opacity: 0.8;
}

.wizard-weight-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.wizard-weight-input {
  flex: 1;
  min-width: 0;
}

.wizard-unit-chips {
  flex-wrap: nowrap;
}

.wizard-input {
  width: 100%;
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.9rem;
}

.wizard-calculate-btn {
  align-self: flex-start;
}

.wizard-result {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.75rem;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.wizard-result-label {
  margin: 0;
  font-weight: 500;
}

.wizard-result-note {
  margin: 0;
}

.wizard-save-btn {
  align-self: flex-start;
}

[data-wizard-error]:not(.hidden) {
  margin: 0;
}

@media (min-width: 640px) {
  .sheet {
    align-items: center;
  }

  .sheet-panel {
    border-radius: var(--radius);
  }
}
