:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1d1f1b;
  --muted: #6c6f66;
  --line: #e6e2d8;
  --soft: #efece4;
  --accent: #2f6b4f;
  --accent-ink: #ffffff;
  --kcal: #2f6b4f;
  --protein: #c2553b;
  --carbs: #d69a2d;
  --fat: #4b78a8;
  --fiber: #7a8f3a;
  --danger: #b33a3a;
  --over: #b8482f;
  --shadow: 0 1px 2px rgba(30, 30, 20, 0.06), 0 4px 16px rgba(30, 30, 20, 0.05);
  --radius: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151613;
    --card: #1f211d;
    --ink: #eeeee8;
    --muted: #9b9e93;
    --line: #30332c;
    --soft: #272a24;
    --accent: #6fbf94;
    --accent-ink: #10231a;
    --kcal: #6fbf94;
    --protein: #e98a6f;
    --carbs: #e8bb5e;
    --fat: #82abd8;
    --fiber: #a9bd63;
    --danger: #e57373;
    --over: #f08a6b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  min-height: 100vh;
  padding: env(safe-area-inset-top) 0 calc(76px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }

.wrap { max-width: 560px; margin: 0 auto; padding: 12px 16px 24px; }

/* Encabezado */
.top { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; }
.top h1 { font-size: 22px; margin: 0; flex: 1; letter-spacing: -0.01em; }
.people { display: flex; background: var(--soft); border-radius: 999px; padding: 3px; }
.people button {
  border: 0; background: none; padding: 6px 12px; border-radius: 999px; font-size: 14px; color: var(--muted);
}
.people button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

.daynav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.daynav .label { font-weight: 600; text-transform: capitalize; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--soft);
  display: grid; place-items: center; font-size: 20px; color: var(--ink);
}
.icon-btn:disabled { opacity: 0.35; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; }

/* Resumen calorías */
.hero { display: flex; gap: 16px; align-items: center; }
.ring { position: relative; width: 132px; height: 132px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .big { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.05; }
.ring .small { font-size: 12px; color: var(--muted); }
.hero-side { flex: 1; min-width: 0; display: grid; gap: 6px; font-size: 14px; }
.hero-side .row { display: flex; justify-content: space-between; gap: 8px; }
.hero-side .row span:first-child { color: var(--muted); }

.macros { display: grid; gap: 10px; margin-top: 14px; }
.macro .head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; }
.macro .head b { font-weight: 600; }
.macro .head span { color: var(--muted); }
.bar { height: 8px; border-radius: 99px; background: var(--soft); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; }
.macro.over .head span { color: var(--over); }

/* Comidas */
.meal { padding: 4px 0; }
.meal + .meal { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 12px; }
.meal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.meal-head b { text-transform: capitalize; }
.meal-head span { color: var(--muted); font-size: 14px; }
.entry {
  display: flex; width: 100%; align-items: center; gap: 10px; text-align: left; border: 0; background: none;
  padding: 8px 0; border-radius: 10px;
}
.entry .name { flex: 1; min-width: 0; }
.entry .name div:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .sub { font-size: 12px; color: var(--muted); }
.entry .kc { font-weight: 600; font-size: 15px; }
.empty { color: var(--muted); font-size: 14px; padding: 4px 0; }
.meal-add { border: 0; background: none; color: var(--accent); font-size: 14px; padding: 6px 0; font-weight: 600; }

.dots { display: inline-flex; gap: 8px; }
.dot::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 3px; vertical-align: 1px; }
.dot.p::before { background: var(--protein); }
.dot.c::before { background: var(--carbs); }
.dot.g::before { background: var(--fat); }

/* Botón flotante */
.fab {
  position: fixed; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 5;
  border: 0; border-radius: 999px; background: var(--accent); color: var(--accent-ink);
  padding: 14px 20px; font-weight: 700; font-size: 16px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

/* Barra inferior */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  flex: 1; max-width: 160px; border: 0; background: none; color: var(--muted); padding: 6px 0;
  display: grid; justify-items: center; gap: 2px; font-size: 12px;
}
.tabs button svg { width: 24px; height: 24px; }
.tabs button.on { color: var(--accent); font-weight: 600; }

/* Formularios */
label.field { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 12px;
  font-size: 16px; color: var(--ink); appearance: none; -webkit-appearance: none;
}
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
textarea.input { resize: none; min-height: 84px; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack { display: grid; gap: 12px; }
.btn {
  border: 0; border-radius: 14px; padding: 13px 16px; font-weight: 600; font-size: 16px; background: var(--soft); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: none; color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 4px 0; font-size: 15px; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.error { color: var(--danger); font-size: 14px; margin: 0; }

/* Login */
.auth { max-width: 380px; margin: 10vh auto 0; padding: 0 16px; }
.auth .logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 12px; }
.auth h1 { margin: 0 0 4px; font-size: 26px; }

/* Hoja inferior */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 10; animation: fade 0.15s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up 0.2s ease; max-width: 640px; margin: 0 auto;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 19px; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 12px; font-size: 14px;
  white-space: nowrap; text-transform: capitalize;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--soft); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: none; padding: 8px 6px; border-radius: 10px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

.photo-row { display: flex; gap: 8px; align-items: center; }
.thumb { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; }
.thumb-wrap { position: relative; }
.thumb-wrap button {
  position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%; border: 0;
  background: var(--ink); color: var(--bg); font-size: 14px; line-height: 1;
}

/* Ítems a agregar */
.items { display: grid; gap: 8px; }
.item { background: var(--card); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); }
.item-top { display: flex; gap: 8px; align-items: flex-start; }
.item-top input { flex: 1; border: 0; background: none; font-weight: 600; padding: 0; min-width: 0; font-size: 15px; }
.item-top input:focus { outline: none; text-decoration: underline; }
.item-x { border: 0; background: none; color: var(--muted); font-size: 20px; line-height: 1; padding: 0 2px; }
.item-mid { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty input { width: 76px; padding: 7px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); text-align: right; font-size: 16px; }
.qty span { color: var(--muted); font-size: 14px; }
.item-kc { margin-left: auto; font-weight: 700; }
.item-macros { font-size: 13px; color: var(--muted); margin-top: 4px; }
.conf { font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.conf.baja { color: var(--over); }
.note { font-size: 13px; color: var(--muted); margin-top: 6px; padding-left: 8px; border-left: 2px solid var(--carbs); }

.total-bar {
  position: sticky; bottom: calc(-20px - env(safe-area-inset-bottom)); background: var(--bg); padding: 12px 0 0; margin-top: 12px;
  border-top: 1px solid var(--line);
}
.total-line { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.total-line b { font-size: 20px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 10px; color: var(--muted); }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.fav { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.fav button.main { flex: 1; text-align: left; border: 0; background: none; padding: 0; min-width: 0; }
.fav .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Peso */
.weight-now { display: flex; align-items: baseline; gap: 6px; }
.weight-now b { font-size: 34px; letter-spacing: -0.02em; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--soft); border-radius: 12px; padding: 10px; }
.stat div:first-child { font-size: 12px; color: var(--muted); }
.stat div:last-child { font-weight: 700; margin-top: 2px; }
.chart { width: 100%; height: 190px; display: block; }
.chart text { font-size: 11px; fill: var(--muted); }
.wlist .row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.wlist .row:last-child { border-bottom: 0; }
.inline { display: flex; gap: 8px; }
.inline .input { flex: 1; }

.calc { display: grid; gap: 6px; font-size: 14px; }
.calc .row { display: flex; justify-content: space-between; }
.calc .row span:first-child { color: var(--muted); }
.calc .row.strong { font-weight: 700; font-size: 16px; }

#toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0;
  pointer-events: none; transition: 0.2s; z-index: 20; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 360px) {
  .ring { width: 112px; height: 112px; }
  .ring .big { font-size: 24px; }
}
