/* v2 */
/* ── Variables ─────────────────────────────────────────── */
:root {
  --bg:      #f8fafc;
  --bg2:     #ffffff;
  --border:  #e2e8f0;
  --text:    #0f172a;
  --text2:   #64748b;
  --primary: #16a34a;
  --primary-dim: #dcfce7;
  --danger:  #ef4444;
  --nav-h:   62px;
  --hdr-h:   52px;
  --radius:  14px;

  --meal-desayuno: #f59e0b;
  --meal-almuerzo: #fb923c;
  --meal-comida:   #f97316;
  --meal-merienda: #a78bfa;
  --meal-cena:     #3b82f6;
  --meal-snack:    #6b7280;
}

[data-dark] {
  --bg:     #0f172a;
  --bg2:    #1e293b;
  --border: #334155;
  --text:   #f1f5f9;
  --text2:  #94a3b8;
  --primary-dim: #14532d;
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
input, textarea { font: inherit; color: inherit; background: none; border: none; outline: none; }

/* ── App shell ─────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 500px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

.view {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
.view.hidden { display: none; }

/* ── Header ────────────────────────────────────────────── */
.hdr {
  display: flex;
  align-items: center;
  height: var(--hdr-h);
  padding: 0 4px;
  background: var(--primary);
  color: #fff;
  flex-shrink: 0;
  gap: 2px;
}
.hdr-title {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 15px;
  text-transform: capitalize;
  padding: 0 4px;
}
.hdr-btn {
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.9;
}
.hdr-btn:active { background: rgba(255,255,255,0.15); }
.hdr-btn:disabled { opacity: 0.3; pointer-events: none; }

/* ── Scroll area ───────────────────────────────────────── */
.scroll-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 12px 10px;
}

/* ── Bottom nav ────────────────────────────────────────── */
#bottom-nav {
  display: flex;
  align-items: center;
  height: var(--nav-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding: 0 4px;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--text2);
  height: 100%;
  border-radius: 10px;
  transition: color 0.15s;
}
.nav-btn .ni { font-size: 20px; }
.nav-btn.active { color: var(--primary); font-weight: 600; }
.nav-btn:active { background: var(--border); }

#fab {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(22,163,74,0.4);
  flex-shrink: 0;
  margin: 0 6px;
  transition: transform 0.1s;
}
#fab:active { transform: scale(0.93); }

/* ── Summary bar ───────────────────────────────────────── */
.summary-bar {
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text2);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 28px;
}

/* ── Meal groups ───────────────────────────────────────── */
.meal-group {
  background: var(--bg2);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}
.meal-group-hdr {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.meal-group-hdr:active { background: var(--border); }
.meal-label {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
}
.meal-kcal {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-dim);
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}
.meal-chevron {
  font-size: 12px;
  color: var(--text2);
  flex-shrink: 0;
  margin-right: 2px;
}
.meal-count {
  font-size: 11px;
  color: var(--text2);
  background: var(--border);
  border-radius: 20px;
  padding: 1px 7px;
  white-space: nowrap;
}
.btn-add-meal {
  font-size: 22px;
  color: var(--primary);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.btn-add-meal:active { background: var(--primary-dim); }
.btn-save-recipe {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: #d97706;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}
.btn-save-recipe:active {
  background: rgba(245, 158, 11, .14);
}

.entry-empty {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text2);
}

/* ── Entry items ───────────────────────────────────────── */
.entry-list { list-style: none; }
.entry-item {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  position: relative;
}
.entry-item:first-child { border-top: none; }

.entry-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.entry-text {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  word-break: break-word;
}
.entry-time {
  font-size: 11px;
  color: var(--text2);
  flex-shrink: 0;
}
.entry-note {
  font-size: 12px;
  color: var(--text2);
  margin-top: 2px;
  font-style: italic;
}
.entry-ctx {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.ctx-tag {
  font-size: 11px;
  background: var(--border);
  border-radius: 20px;
  padding: 1px 7px;
  color: var(--text2);
}
.entry-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}
.entry-action-btn {
  font-size: 16px;
  padding: 3px 6px;
  border-radius: 6px;
  opacity: 0.5;
}
.entry-action-btn:active { opacity: 1; background: var(--border); }
.entry-photo-thumb {
  margin-top: 6px;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--border);
}
.entry-photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ── Week strip ────────────────────────────────────────── */
.week-strip {
  display: flex;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.week-day {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 2px;
  border-radius: 0;
}
.wd-name {
  font-size: 10px;
  text-transform: capitalize;
  color: var(--text2);
}
.wd-num {
  font-size: 16px;
  font-weight: 500;
}
.wd-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--primary);
  opacity: 0;
}
.week-day.has-entries .wd-dot { opacity: 1; }
.week-day.selected { background: var(--primary-dim); }
.week-day.selected .wd-name,
.week-day.selected .wd-num { color: var(--primary); font-weight: 700; }
.week-day.is-today .wd-num { color: var(--primary); }

/* ── Quick Add panel ───────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: opacity 0.2s;
}
.overlay.hidden { display: none; }
.overlay:not(.open) { opacity: 0; pointer-events: none; }
.overlay.open { opacity: 1; pointer-events: auto; }

#qa-panel {
  background: var(--bg2);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 500px;
  padding: 8px 14px 32px;
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.32,0.72,0,1);
  max-height: 92vh;
  overflow-y: auto;
}
.overlay.open #qa-panel { transform: translateY(0); }

.qa-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 12px;
}

/* Meal chips */
.meal-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.meal-chip {
  flex: 1 0 calc(33% - 6px);
  padding: 7px 2px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  background: var(--bg);
  border: 2px solid var(--border);
  color: var(--text2);
  transition: border-color 0.1s, background 0.1s;
}
.meal-chip.active {
  border-color: var(--mc, var(--primary));
  background: color-mix(in srgb, var(--mc, var(--primary)) 12%, transparent);
  color: var(--mc, var(--primary));
}

/* Input */
.qa-input-wrap {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 4px 12px;
  margin-bottom: 8px;
  transition: border-color 0.15s;
}
.qa-input-wrap:focus-within { border-color: var(--primary); }

#qa-text {
  width: 100%;
  font-size: 17px;
  padding: 8px 0;
  background: none;
  caret-color: var(--primary);
}
#qa-text::placeholder { color: var(--text2); }

.qa-suggest {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: -2px 0 8px;
}
.qa-suggest.hidden {
  display: none;
}
.qa-suggest-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 8px 10px;
  text-align: left;
}
.qa-suggest-main {
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qa-suggest-sub {
  font-size: 12px;
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 45%;
}
.qa-suggest-item:active {
  border-color: var(--primary);
  background: var(--primary-dim);
}

/* Recents / recipes */
.qa-recents,
.qa-recipes { margin-bottom: 8px; }
.recents-lbl {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
  margin-bottom: 6px;
}
.recents-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.recents-chips,
.recipe-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.recent-chip,
.recipe-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 11px;
  font-size: 13px;
  color: var(--text);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recipe-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 190px;
  border-color: rgba(245, 158, 11, .35);
}
.recipe-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
}
.recipe-chip small {
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: rgba(245, 158, 11, .16);
  color: #b45309;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
}
.recent-chip:active,
.recipe-chip:active { background: var(--primary-dim); border-color: var(--primary); }

/* Context */
.qa-context {
  display: none;
  flex-direction: column;
  gap: 10px;
  padding: 10px 0 2px;
  border-top: 1px solid var(--border);
  margin-bottom: 8px;
}
.qa-context.open { display: flex; }
.ctx-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ctx-lbl { font-size: 13px; color: var(--text2); min-width: 90px; }
.rating-grp { display: flex; gap: 5px; }
.rating-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  background: var(--bg);
  border: 2px solid var(--border);
  color: var(--text2);
}
.rating-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.ctx-checks { gap: 14px; }
.ctx-checks label { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.ctx-checks input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); }
.ctx-notes-input {
  width: 100%;
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.ctx-notes-input::placeholder { color: var(--text2); }

/* QA actions */
.qa-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}
.btn-ghost {
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--bg);
  font-size: 13px;
  color: var(--text2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.btn-ghost:active { background: var(--border); }
.btn-primary {
  flex: 1;
  padding: 13px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  transition: opacity 0.1s;
}
.btn-primary:disabled { opacity: 0.35; }
.btn-primary:active { opacity: 0.85; }
.btn-ghost.has-photo { color: var(--primary); border-color: var(--primary); }

/* ── Summary / Export ──────────────────────────────────── */
.summary-container { padding: 12px; }
.summary-week-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.summary-week-hdr h2 { font-size: 16px; font-weight: 700; }
.summary-day {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.summary-day-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.summary-day-lbl { font-weight: 600; font-size: 14px; text-transform: capitalize; }
.summary-day-count { font-size: 12px; color: var(--text2); }
.summary-meal-badges { display: flex; flex-wrap: wrap; gap: 5px; }
.sm-badge {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 600;
}
.plan-box {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}
.plan-box-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.plan-box-hdr h3 {
  font-size: 15px;
  font-weight: 700;
}
.plan-meta {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 10px;
}
.plan-clear-btn {
  padding: 6px 10px;
  font-size: 12px;
}
.plan-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 8px;
}
.plan-day {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  background: var(--bg);
}
.plan-day.is-today {
  border-color: var(--primary);
}
.plan-day-title {
  font-size: 12px;
  color: var(--text2);
  font-weight: 700;
  text-transform: capitalize;
  margin-bottom: 6px;
}
.plan-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.plan-row:last-child {
  margin-bottom: 0;
}
.plan-meal {
  width: 24px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  flex-shrink: 0;
}
.plan-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  background: var(--bg2);
  color: var(--text);
}
.plan-input:focus {
  outline: none;
  border-color: var(--primary);
}

.export-box {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 10px;
}
.export-box h3 { font-size: 15px; margin-bottom: 12px; }
.export-range {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.export-range label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text2);
  flex: 1;
}
.export-range input[type=date] {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
.export-btns { display: flex; gap: 8px; }
.btn-secondary {
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.btn-secondary:active { background: var(--border); }

/* ── Water widget ──────────────────────────────────────── */
.water-widget {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 8px 14px 10px;
  flex-shrink: 0;
  transition: background 0.3s;
}
.water-widget.water-done { background: #f0fdf4; }
[data-dark] .water-widget.water-done { background: #14532d22; }
.water-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.water-icon { font-size: 18px; }
.water-label { font-size: 15px; font-weight: 700; color: #3b82f6; }
.water-goal  { font-size: 13px; color: var(--text2); }
.water-reset { margin-left: auto; font-size: 16px; color: var(--text2); padding: 2px 6px; }
.water-bar-wrap {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}
.water-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease, background 0.3s;
  width: 0%;
}
.water-btns {
  display: flex;
  gap: 6px;
}
.water-btn {
  flex: 1;
  padding: 6px 2px;
  border-radius: 8px;
  border: 1.5px solid #bfdbfe;
  background: #eff6ff;
  color: #2563eb;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}
[data-dark] .water-btn { background: #1e3a5f; border-color: #2563eb; color: #93c5fd; }
.water-btn:active { background: #bfdbfe; }

/* ── Campo cantidad ────────────────────────────────────── */
.qa-qty-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 0 2px;
}
#qa-qty {
  width: 90px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  text-align: center;
  transition: border-color 0.15s;
  -moz-appearance: textfield;
}
#qa-qty::-webkit-inner-spin-button,
#qa-qty::-webkit-outer-spin-button { -webkit-appearance: none; }
#qa-qty:focus { border-color: var(--primary); outline: none; }
#qa-qty::placeholder { color: var(--text2); }
.qa-unit-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text2);
}
.qa-unit-select {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 7px 8px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}
.qa-unit-select:focus { border-color: var(--primary); outline: none; }
.kcal-badge {
  flex: 1;
  text-align: right;
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  opacity: 0;
  transition: opacity 0.2s;
}
.kcal-badge.visible { opacity: 1; }
.qa-status-msg {
  min-height: 18px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text2);
}
.qa-status-msg.warn {
  color: #dc2626;
}
.qa-status-msg.allergen {
  color: #d97706;
  font-weight: 800;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Kcal preview (multi-alimento) ────────────────────── */
.kcal-preview {
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 8px;
  font-size: 13px;
}
.kcal-preview.has-content {
  border: 1px solid var(--border);
  background: var(--bg);
}
.kp-row {
  display: flex;
  align-items: center;
  padding: 5px 10px;
  gap: 6px;
  border-bottom: 1px solid var(--border);
}
.kp-row:last-of-type { border-bottom: none; }
.kp-food { flex: 1; font-weight: 500; color: var(--text); }
.kp-qty  { color: var(--text2); min-width: 50px; text-align: right; font-size: 12px; }
.kp-kcal { color: var(--primary); font-weight: 700; min-width: 65px; text-align: right; }
.kp-unknown .kp-food { color: var(--text2); font-style: italic; }
.kp-total {
  padding: 6px 10px;
  background: var(--primary-dim);
  color: var(--primary);
  font-size: 13px;
  border-top: 1px solid var(--border);
}

/* ── Entrada guardada: kcal + cantidad ─────────────────── */
.entry-sub-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
  flex-wrap: wrap;
}
.entry-qty {
  font-size: 12px;
  color: var(--text2);
}
.entry-kcal {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-dim);
  padding: 2px 8px;
  border-radius: 20px;
}
.btn-detail-toggle {
  font-size: 11px;
  color: var(--text2);
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.entry-items-detail {
  list-style: none;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 12px;
}
.entry-items-detail li {
  display: flex;
  align-items: center;
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  gap: 6px;
}
.entry-items-detail li:last-child { border-bottom: none; }
.ei-name { flex: 1; color: var(--text); }
.ei-qty  { color: var(--text2); }
.ei-kcal { color: var(--primary); font-weight: 600; min-width: 55px; text-align: right; }
.ei-unknown .ei-name { color: var(--text2); font-style: italic; }

/* ── Empty ─────────────────────────────────────────────── */
.empty-msg {
  text-align: center;
  color: var(--text2);
  padding: 40px 20px;
  font-size: 14px;
}

/* ── Dashboard ─────────────────────────────────────────── */
.dash-cards {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}
.dash-card {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  overflow: hidden;
  position: relative;
}
.dash-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.dash-card.kcal-card::before { background: var(--primary); }
.dash-card.water-card::before { background: #3b82f6; }

.dash-card-icon {
  font-size: 20px;
  margin-bottom: 6px;
  display: block;
}
.dash-card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
  margin-bottom: 4px;
}
.dash-value {
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 2px;
}
.dash-card.kcal-card  .dash-value { color: var(--primary); }
.dash-card.water-card .dash-value { color: #3b82f6; }
.dash-goal {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 10px;
}
.dash-bar-wrap {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.dash-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
  width: 0%;
}
.dash-bar.kcal  { background: var(--primary); }
.dash-bar.water { background: #3b82f6; }

.dash-streak {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 14px;
  color: #c2410c;
  margin-bottom: 12px;
  font-weight: 500;
}
.dash-streak.hidden { display: none; }
[data-dark] .dash-streak { background: #431407; border-color: #7c2d12; color: #fb923c; }

.dash-section { margin-bottom: 14px; }
.dash-section.hidden { display: none; }
.dash-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text2);
  font-weight: 700;
  margin-bottom: 8px;
}
.dash-quick-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.dash-quick-chip {
  background: var(--bg2);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dash-quick-chip:active { background: var(--primary-dim); border-color: var(--primary); color: var(--primary); }

/* ── Mini chart ─────────────────────────────────────────── */
.dash-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 120px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 12px 0;
}
.chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
}
.chart-kcal-lbl {
  font-size: 9px;
  color: var(--text2);
  height: 14px;
  display: flex;
  align-items: flex-end;
  white-space: nowrap;
  font-weight: 600;
}
.chart-col.is-today .chart-kcal-lbl { color: var(--primary); }
.chart-bar-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  padding: 0 1px;
}
.chart-bar-fill {
  width: 100%;
  background: var(--border);
  border-radius: 4px 4px 0 0;
  min-height: 4px;
  transition: height 0.5s ease;
}
.chart-col.is-today .chart-bar-fill { background: var(--primary); }
.chart-col:not(.is-today) .chart-bar-fill { opacity: 0.6; }
.chart-day-lbl {
  font-size: 10px;
  color: var(--text2);
  text-transform: capitalize;
  padding: 4px 0 8px;
  white-space: nowrap;
}
.chart-col.is-today .chart-day-lbl { color: var(--primary); font-weight: 700; }

/* ── Macros bars ─────────────────────────────────────────── */
#home-macros {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#home-macros.hidden { display: none; }
.macro-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.macro-lbl {
  font-size: 11px;
  font-weight: 800;
  color: var(--text2);
  width: 14px;
  flex-shrink: 0;
}
.macro-bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.macro-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
  min-width: 3px;
}
.macro-p { background: #3b82f6; }
.macro-c { background: #f59e0b; }
.macro-f { background: #ec4899; }
.macro-val {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  min-width: 34px;
  text-align: right;
}

.micro-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.micro-lbl {
  font-size: 11px;
  font-weight: 800;
  color: var(--text2);
  width: 44px;
  flex-shrink: 0;
}
.micro-bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.micro-bar {
  height: 100%;
  border-radius: 3px;
  min-width: 3px;
}
.micro-fi { background: #22c55e; }
.micro-na { background: #f97316; }
.micro-ca { background: #3b82f6; }
.micro-fe { background: #ef4444; }
.micro-val {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  min-width: 96px;
  text-align: right;
}

/* ── NOVA bar ────────────────────────────────────────────── */
#home-nova {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
}
#home-nova.hidden { display: none; }
.nova-bar-wrap {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}
.nova-seg { height: 100%; transition: width 0.5s ease; }
.nova-seg.nova-real  { background: #16a34a; }
.nova-seg.nova-proc  { background: #f59e0b; }
.nova-seg.nova-ultra { background: #ef4444; }
.nova-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text2);
  flex-wrap: wrap;
}
.nova-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.nova-dot.nova-real  { background: #16a34a; }
.nova-dot.nova-proc  { background: #f59e0b; }
.nova-dot.nova-ultra { background: #ef4444; }

/* ── Fasting widget ──────────────────────────────────────── */
.fasting-widget {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}
.fasting-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.fasting-icon  { font-size: 18px; }
.fasting-title { flex: 1; font-size: 13px; font-weight: 600; }
.fasting-target-sel select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
}
.btn-fasting-start {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  background: var(--primary-dim);
  color: var(--primary);
  font-size: 14px;
  font-weight: 700;
  border: 1.5px solid var(--primary);
}
.btn-fasting-start:active { background: var(--primary); color: #fff; }
.fasting-stop-btn {
  font-size: 14px;
  color: var(--text2);
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.fasting-active { border-color: var(--primary); }
.fasting-timer {
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 4px;
}
.fasting-phase {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
}
.fasting-bar-wrap {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}
.fasting-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 30s linear;
}
.fasting-meta { font-size: 11px; color: var(--text2); }

/* ── Weight widget ───────────────────────────────────────── */
.weight-widget {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}
.weight-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
}
.weight-latest {
  font-size: 18px;
  font-weight: 800;
  color: var(--primary);
}
.weight-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
#weight-input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  -moz-appearance: textfield;
}
#weight-input::-webkit-inner-spin-button,
#weight-input::-webkit-outer-spin-button { -webkit-appearance: none; appearance: none; }
#weight-input:focus { border-color: var(--primary); outline: none; }
.btn-weight-save {
  padding: 8px 16px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}
.btn-weight-save:active { opacity: 0.8; }

/* Weight sparkline */
.weight-sparkline {
  display: flex;
  gap: 2px;
  height: 48px;
  align-items: flex-end;
}
.spark-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
}
.spark-dot-wrap {
  flex: 1;
  width: 100%;
  position: relative;
}
.spark-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  position: absolute;
  left: 50%;
  transform: translate(-50%, 50%);
}
.spark-dot.filled { background: var(--primary); }
.spark-dot.empty  { background: var(--border); bottom: 0; position: static; margin: 0 auto; }
.spark-col.is-today .spark-dot.filled { background: #16a34a; width: 10px; height: 10px; }
.spark-lbl {
  font-size: 9px;
  color: var(--text2);
  text-transform: capitalize;
  padding-top: 4px;
}

/* ── Color score dots ────────────────────────────────────── */
.entry-cs {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-right: 2px;
  display: inline-block;
}
.cs-green  { background: #16a34a; }
.cs-yellow { background: #f59e0b; }
.cs-red    { background: #ef4444; }

/* entry macros + badges */
.entry-macros {
  font-size: 11px;
  color: var(--text2);
  background: var(--border);
  border-radius: 20px;
  padding: 1px 7px;
}
.entry-eco   { font-size: 13px; }
.entry-nova3 { font-size: 13px; }

/* ── Insights section (Summary view) ─────────────────────── */
.insights-section { margin-bottom: 16px; }
.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text2);
  font-weight: 700;
  margin-bottom: 8px;
}
.insight-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.insight-icon { font-size: 20px; flex-shrink: 0; }
.insight-body { font-size: 13px; color: var(--text); line-height: 1.4; }
.insight-body strong { color: var(--primary); }

/* ── Settings view ───────────────────────────────────────── */
.settings-section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.settings-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text2);
  font-weight: 700;
  margin-bottom: 12px;
}
.settings-hint {
  margin: -4px 0 12px;
  color: var(--text2);
  font-size: 13px;
  line-height: 1.35;
}
.allergen-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.allergen-chip {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  user-select: none;
  transition: border-color .15s, background .15s, color .15s;
}
.allergen-chip.active {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, .12);
  color: #b45309;
}
.allergen-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.allergen-icon {
  font-size: 17px;
  line-height: 1;
  flex-shrink: 0;
}
.allergen-label {
  font-size: 13px;
  font-weight: 800;
  min-width: 0;
}
.entry-allergen {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(245, 158, 11, .14);
  color: #b45309;
  font-size: 12px;
  margin-left: 4px;
  vertical-align: middle;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: none; }
.settings-row label {
  font-size: 14px;
  color: var(--text);
  flex: 1;
}
.settings-row input,
.settings-row select {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  width: 110px;
  text-align: right;
}
.settings-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 4px;
  text-align: initial;
  accent-color: var(--primary);
}
.settings-row select { text-align: left; width: 150px; }
.settings-row input:focus,
.settings-row select:focus { border-color: var(--primary); outline: none; }
.tdee-preview {
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--primary-dim);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text);
}
.tdee-preview strong { color: var(--primary); }

/* ── Challenges / Retos ──────────────────────────────────── */
.dash-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text2);
  font-weight: 700;
  margin-bottom: 8px;
}
.retos-badge {
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  border-radius: 20px;
  padding: 1px 7px;
  letter-spacing: 0;
  text-transform: none;
}

.challenges-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.challenge-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px 8px;
  transition: border-color 0.2s;
}
.challenge-card.challenge-done {
  border-color: var(--primary);
  background: var(--primary-dim);
}
[data-dark] .challenge-card.challenge-done {
  background: #14532d22;
}
.challenge-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}
.challenge-icon {
  font-size: 20px;
  flex-shrink: 0;
  line-height: 1.2;
}
.challenge-info {
  flex: 1;
  min-width: 0;
}
.challenge-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}
.challenge-desc {
  font-size: 11px;
  color: var(--text2);
  line-height: 1.3;
}
.challenge-count {
  font-size: 12px;
  font-weight: 800;
  color: var(--text2);
  flex-shrink: 0;
  padding-top: 2px;
}
.challenge-count-done {
  color: var(--primary);
  font-size: 16px;
}
.challenge-bar-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.challenge-bar {
  height: 100%;
  border-radius: 2px;
  background: var(--text2);
  transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  min-width: 0;
}
.challenge-bar-done { background: var(--primary); }

/* ── Shopping list ─────────────────────────────────────── */
.shop-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

/* Home preview */
.shop-preview-empty {
  padding: 4px 0 8px;
}
.shop-preview-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 0 10px;
}
.shop-preview-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--card2);
  font-size: 13px;
  color: var(--text);
  border: 1px solid var(--border);
}
.shop-preview-more {
  font-size: 12px;
  color: var(--text2);
  padding: 4px 6px;
  align-self: center;
}
.shop-gen-btn {
  font-size: 13px;
  padding: 7px 12px;
}
.shop-view-btn {
  display: block;
  width: 100%;
  text-align: center;
  font-size: 13px;
  color: var(--primary);
  padding: 8px 0 2px;
  background: none;
  border: none;
  cursor: pointer;
  font-weight: 600;
}

/* Full shopping view */
.shop-add-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px 0;
}
.shop-add-row input {
  flex: 1;
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 15px;
}
.shop-add-row input:focus {
  outline: none;
  border-color: var(--primary);
}
.shop-add-btn {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  font-size: 22px;
  padding: 0;
  flex-shrink: 0;
}
.shop-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 4px;
}
.shop-share-btn {
  font-size: 16px;
  padding: 7px 10px;
}
.shop-empty-state {
  text-align: center;
  padding: 40px 24px;
  color: var(--text2);
}
.shop-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}
.shop-empty-sub {
  font-size: 13px;
  margin-top: 6px;
  color: var(--text2);
  opacity: .75;
}

/* Category groups */
.shop-cat-group {
  padding: 0 16px;
  margin-top: 16px;
}
.shop-cat-hdr {
  font-size: 12px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .5px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.shop-items {
  list-style: none;
  margin: 0;
  padding: 0;
}
.shop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.shop-item:last-child {
  border-bottom: none;
}
.shop-check {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color .15s, background .15s;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}
.shop-check:active {
  transform: scale(.9);
}
.shop-check-done {
  border-color: var(--primary);
  background: var(--primary);
}
.shop-check-circle {
  pointer-events: none;
}
.shop-item-text {
  flex: 1;
  font-size: 15px;
  color: var(--text);
}
.shop-item-done .shop-item-text {
  text-decoration: line-through;
  color: var(--text2);
  opacity: .7;
}
.shop-del {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text2);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: .5;
  flex-shrink: 0;
  transition: opacity .15s;
}
.shop-del:active {
  opacity: 1;
  background: var(--border);
}

/* Done section */
.shop-done-section {
  padding: 0 16px;
  margin-top: 20px;
}
.shop-done-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .5px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.shop-clear-btn {
  font-size: 12px;
  color: var(--primary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-weight: 600;
}
.shop-items-done .shop-item-text {
  text-decoration: line-through;
  color: var(--text2);
  opacity: .6;
}
