:root {
  --green: #16a34a;
  --green-dark: #15803d;
  --green-soft: #dcfce7;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f5f5f4;
  --text: #1c1917;
  --text-soft: #78716c;
  --border: #e7e5e4;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --radius: 16px;
  --tabbar-h: 68px;
  --topbar-h: 56px;
}

/* Dark por preferencia del sistema (modo Auto) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0a09;
    --surface: #1c1917;
    --surface-2: #292524;
    --text: #f5f5f4;
    --text-soft: #a8a29e;
    --border: #292524;
    --green-soft: #14361f;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}
/* Overrides manuales (ganan siempre) */
:root[data-theme="dark"] {
  --bg: #0c0a09;
  --surface: #1c1917;
  --surface-2: #292524;
  --text: #f5f5f4;
  --text-soft: #a8a29e;
  --border: #292524;
  --green-soft: #14361f;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}
:root[data-theme="light"] {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f5f5f4;
  --text: #1c1917;
  --text-soft: #78716c;
  --border: #e7e5e4;
  --green-soft: #dcfce7;
}

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

#app { min-height: 100%; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; gap: 8px;
  padding-left: 12px; padding-right: 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 19px; font-weight: 700; flex: 1; text-align: center; }
.icon-btn {
  border: none; background: none; color: var(--text); cursor: pointer;
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 10px;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn[hidden] { display: none; }

/* Punto verde "Thermomix" */
.tmx-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; vertical-align: middle; }
.back-btn { font-size: 30px; line-height: 1; }

/* Tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--surface);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-soft); font-size: 11px; font-weight: 600;
}
.tab.active { color: var(--green); }
.tab svg { width: 24px; height: 24px; }

main { padding: 16px; max-width: 640px; margin: 0 auto; }

/* Section headers */
.section-title { font-size: 22px; font-weight: 800; margin: 4px 0 4px; }
.section-sub { color: var(--text-soft); font-size: 14px; margin-bottom: 16px; }

/* Macro summary bar */
.macros-bar {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  background: var(--surface-2); border-radius: var(--radius); padding: 12px; margin-bottom: 18px;
}
.macro { text-align: center; }
.macro b { display: block; font-size: 17px; font-weight: 800; }
.macro span { font-size: 11px; color: var(--text-soft); text-transform: uppercase; letter-spacing: .03em; }
.macro.kcal b { color: var(--green); }

/* ===== WEEK VIEW: columnas deslizables ===== */
.week-scroll {
  display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch; padding: 4px 0 8px; margin: 0 -16px; padding-left: 16px; padding-right: 16px;
  scrollbar-width: none;
}
.week-scroll::-webkit-scrollbar { display: none; }
.day-col {
  flex: 0 0 84%; max-width: 360px; scroll-snap-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column;
}
.day-col.today { border-color: var(--green); border-width: 2px; }
.day-col-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.day-col-head .dcw { font-size: 13px; text-transform: capitalize; color: var(--text-soft); font-weight: 600; }
.day-col-head.today .dcw { color: var(--green); }
.day-col-head .dcn { font-size: 26px; font-weight: 800; }
.day-col-head .dckcal { text-align: right; font-size: 13px; color: var(--text-soft); font-weight: 700; }
.day-col-head .dckcal b { display: block; font-size: 17px; color: var(--green); }

.wk-meal {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 12px;
  margin-bottom: 8px; cursor: pointer; border-left: 4px solid var(--slot, var(--green));
  background: var(--surface-2);
}
.wk-meal:active { transform: scale(.99); }
.wk-check {
  width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--border); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; background: var(--surface);
}
.wk-check svg { width: 13px; height: 13px; color: #fff; }
.wk-meal.done .wk-check { background: var(--green); border-color: var(--green); }
.wk-info { flex: 1; min-width: 0; }
.wk-name { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wk-slot { font-size: 11px; color: var(--slot, var(--text-soft)); font-weight: 600; }
.wk-meal.done .wk-name { text-decoration: line-through; color: var(--text-soft); }
.wk-emoji { font-size: 18px; }
.swipe-hint { text-align: center; color: var(--text-soft); font-size: 12px; margin-top: 2px; }

/* ===== DAY VIEW ===== */
.slot-time { display: flex; align-items: center; gap: 8px; margin: 20px 2px 8px; }
.slot-time .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--slot, var(--green)); }
.slot-time b { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-soft); }
.slot-time .clock { margin-left: auto; font-size: 13px; color: var(--text-soft); font-weight: 600; }

.meal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; margin-bottom: 4px; display: flex; align-items: stretch;
  border-left: 5px solid var(--slot, var(--green));
}
.meal-main { flex: 1; display: flex; align-items: center; gap: 14px; padding: 14px 14px; cursor: pointer; min-width: 0; }
.meal-thumb {
  width: 54px; height: 54px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 30px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--slot, var(--green)) 22%, transparent), var(--surface-2));
}
.meal-title { flex: 1; min-width: 0; }
.meal-title b { font-size: 16px; font-weight: 700; display: block; }
.meal-title .tags { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.tag { font-size: 11px; color: var(--text-soft); display: inline-flex; align-items: center; gap: 3px; }
.tag svg { width: 12px; height: 12px; }
.tag.tmx { color: var(--green); font-weight: 700; }
.meal-kcal { text-align: right; font-weight: 800; color: var(--green); font-size: 15px; }
.meal-kcal small { display: block; color: var(--text-soft); font-weight: 600; font-size: 10px; }
.meal-check {
  border: none; background: none; padding: 0 14px; cursor: pointer; display: flex; align-items: center;
  border-left: 1px solid var(--border);
}
.meal-check .box {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center; background: var(--surface);
}
.meal-check .box svg { width: 16px; height: 16px; color: #fff; }
.meal-card.done .meal-check .box { background: var(--green); border-color: var(--green); }
.meal-card.done .meal-title b { text-decoration: line-through; color: var(--text-soft); }
.meal-card.done { opacity: .72; }

/* Suplementos callout */
.supp {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 10px;
}
.supp h3 { font-size: 14px; font-weight: 800; display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.supp h3 svg { width: 18px; height: 18px; color: var(--green); }
.supp-item { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.supp-item:first-of-type { border-top: none; }
.supp-item .si-ic { font-size: 20px; }
.supp-item b { font-size: 14px; }
.supp-item .si-dose { color: var(--green); font-weight: 700; font-size: 13px; }
.supp-item p { font-size: 13px; color: var(--text-soft); line-height: 1.45; margin-top: 2px; }

/* Recipe detail */
.recipe-hero {
  height: 170px; border-radius: var(--radius); margin-bottom: 16px;
  display: flex; align-items: center; justify-content: center; font-size: 78px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--slot, var(--green)) 25%, transparent), var(--surface-2));
}
.recipe-title { font-size: 26px; font-weight: 800; line-height: 1.15; margin-bottom: 10px; }
.recipe-meta { display: flex; gap: 18px; color: var(--text-soft); font-size: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.recipe-meta span b { color: var(--text); }
.pill {
  display: inline-block; background: var(--slot, var(--green)); color: #fff; font-weight: 700; font-size: 12px;
  padding: 4px 12px; border-radius: 20px; margin-bottom: 16px;
}
.block-title { font-size: 20px; font-weight: 800; margin: 24px 0 12px; }

.ing-row { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.ing-qty { font-weight: 700; min-width: 110px; }
.ing-name { flex: 1; }
.ing-note { color: var(--text-soft); font-size: 13px; display: block; }

/* Control de porciones */
.portion-ctrl {
  background: var(--surface-2); border-radius: var(--radius); padding: 6px 14px; margin-bottom: 16px;
}
.pc-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; }
.pc-row + .pc-row { border-top: 1px solid var(--border); }
.pc-label { font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 7px; }
.pc-label svg { width: 19px; height: 19px; color: var(--slot, var(--green)); flex-shrink: 0; }
.stepper { display: flex; align-items: center; gap: 4px; background: var(--surface); border-radius: 12px; padding: 4px; }
.stepper button {
  width: 38px; height: 38px; border: none; background: var(--surface-2); color: var(--slot, var(--green));
  font-size: 24px; font-weight: 700; border-radius: 9px; cursor: pointer; line-height: 1;
}
.stepper button:active { transform: scale(.94); }
.stepper span { min-width: 34px; text-align: center; font-size: 18px; font-weight: 800; }
.mult-chips { display: flex; gap: 6px; }
.mult-chips button {
  min-width: 44px; height: 38px; border: 1px solid var(--border); background: var(--surface); color: var(--text-soft);
  border-radius: 10px; font-size: 14px; font-weight: 700; cursor: pointer;
}
.mult-chips button.active {
  border-color: var(--slot, var(--green)); color: var(--slot, var(--green));
  background: color-mix(in srgb, var(--slot, var(--green)) 14%, transparent);
}
.macro-scale { text-align: center; font-size: 13px; font-weight: 700; color: var(--slot, var(--green)); margin: -8px 0 8px; }
.macro-scale:empty { display: none; }

/* Segmented control Normal / Thermomix */
.segmented {
  display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin: 8px 0 16px;
}
.segmented button {
  flex: 1; border: none; background: none; cursor: pointer; padding: 9px; border-radius: 9px;
  font-size: 14px; font-weight: 700; color: var(--text-soft);
}
.segmented button.active { background: var(--surface); color: var(--green); box-shadow: var(--shadow); }
.segmented button svg { width: 16px; height: 16px; vertical-align: -3px; margin-right: 3px; }

.step-row { display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.step-num {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%; background: var(--green-soft);
  color: var(--green); font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.step-txt { flex: 1; line-height: 1.5; padding-top: 2px; }
.step-txt strong { color: var(--green); }

/* Shopping list */
.shop-group { margin-bottom: 8px; }
.shop-group h3 {
  font-size: 15px; font-weight: 800; margin: 20px 0 6px; display: flex; align-items: center; gap: 8px;
}
.shop-group h3 svg { width: 20px; height: 20px; color: var(--green); }
.shop-group h3 .cnt { color: var(--text-soft); font-weight: 600; font-size: 13px; }
.shop-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.shop-check {
  width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--border); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; background: var(--surface);
}
.shop-check svg { width: 14px; height: 14px; color: #fff; }
.shop-item.done .shop-check { background: var(--green); border-color: var(--green); }
.shop-item.done .shop-name { text-decoration: line-through; color: var(--text-soft); }
.shop-name { flex: 1; }
.shop-qty { font-weight: 700; color: var(--green); }
.shop-item.done .shop-qty { color: var(--text-soft); }

.callout {
  background: var(--surface-2); border-left: 3px solid var(--green); border-radius: 10px;
  padding: 12px 14px; font-size: 14px; line-height: 1.5; margin: 8px 0 16px; color: var(--text-soft);
}
.callout b { color: var(--text); }

/* ===== Settings sheet ===== */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; display: flex; align-items: flex-end;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; margin: 0 auto;
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
  max-height: 85vh; overflow-y: auto;
}
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 8px auto 14px; }
.sheet h2 { font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.set-group { margin-top: 20px; }
.set-label { font-size: 13px; font-weight: 700; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.seg-row { display: flex; gap: 8px; }
.seg-row button {
  flex: 1; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 12px; border-radius: 12px; font-weight: 700; font-size: 14px; cursor: pointer;
}
.seg-row button.active { border-color: var(--green); color: var(--green); background: var(--green-soft); }
.seg-row button svg { width: 16px; height: 16px; vertical-align: -3px; margin-right: 4px; }
.set-btn {
  width: 100%; border: none; background: var(--green); color: #fff; padding: 14px; border-radius: 12px;
  font-weight: 700; font-size: 15px; cursor: pointer; margin-top: 8px;
}
.set-btn.secondary { background: var(--surface-2); color: var(--text); }
.set-note { font-size: 13px; color: var(--text-soft); line-height: 1.5; margin-top: 10px; }
