:root {
  --bg: #f6f3ec; --card: #fffdf8; --card2: #f0ece1; --ink: #1f2a24; --muted: #66726a; --line: #e2dccd;
  --accent: #2f6b4f; --accent-ink: #fff; --accent-soft: #dcebe2;
  --p0: #1f7a8c; --p1: #d9624a;
  --ok: #2f6b4f; --warn: #b7791f; --bad: #b3402f;
  --shadow: 0 1px 2px rgba(31,42,36,.06), 0 4px 14px rgba(31,42,36,.06);
  --r: 16px; --nav-h: 64px;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131815; --card: #1b221e; --card2: #232c27; --ink: #e9f0ea; --muted: #94a399; --line: #2c3731;
    --accent: #6fbf94; --accent-ink: #0d1a13; --accent-soft: #1f3328;
    --p0: #4fb3c5; --p1: #f08a72; --ok: #6fbf94; --warn: #e0b04f; --bad: #ef7d6a;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-size: 16px; line-height: 1.4; min-height: 100dvh; overscroll-behavior-y: none; }
body.modal-open { overflow: hidden; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; line-height: 1.2; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .5rem; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { text-align: center; padding: 30vh 1rem 0; color: var(--muted); }

/* ---- Layout ---- */
.shell { max-width: 720px; margin: 0 auto; padding: calc(var(--sat) + 10px) 14px calc(var(--nav-h) + var(--sab) + 24px); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.topbar h1 { font-size: 1.25rem; }
.sync-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); margin-right: 6px; }
.sync-dot.off { background: var(--warn); } .sync-dot.pend { background: var(--p1); }
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center; background: var(--card); border-top: 1px solid var(--line); padding-bottom: var(--sab); }
.nav-inner { display: flex; width: 100%; max-width: 720px; }
.nav button { flex: 1; min-height: var(--nav-h); border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .7rem; color: var(--muted); cursor: pointer; }
.nav button .ico { font-size: 1.35rem; line-height: 1; }
.nav button.active { color: var(--accent); font-weight: 700; }
.nav button.active .ico { transform: translateY(-1px); }

/* ---- Tarjetas y texto ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .tiny { font-size: .75rem; }
.row { display: flex; align-items: center; gap: 8px; } .row.wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; } .between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 2px 8px; font-weight: 700; }

/* ---- Botones ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.btn.block { display: flex; width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn { width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; font-size: 1.1rem; cursor: pointer; color: var(--muted); }
.icon-btn:active { background: var(--card2); }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 6px 4px; cursor: pointer; }

/* ---- Chips ---- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { --c: var(--accent); min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--card); font-weight: 600; font-size: .92rem; cursor: pointer; white-space: nowrap; }
.chip.active { background: var(--c); border-color: var(--c); color: #fff; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; background: color-mix(in srgb, var(--c, var(--muted)) 16%, transparent); color: var(--c, var(--muted)); border: 1px solid color-mix(in srgb, var(--c, var(--muted)) 35%, transparent); white-space: nowrap; }
.pill.ok { --c: var(--ok); } .pill.over { --c: var(--bad); } .pill.part { --c: var(--warn); }
.seg { display: flex; background: var(--card2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 38px; border: 0; background: transparent; border-radius: 10px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.seg button.active.p { color: var(--c); }

/* ---- Formularios ---- */
.field { display: block; margin-bottom: 12px; }
.field-label { display: block; font-size: .82rem; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.hint { display: block; font-size: .78rem; color: var(--muted); margin-top: 3px; }
input[type=text], input[type=number], input[type=password], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); outline: none; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; } .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

/* ---- Stepper ---- */
.stepper { display: inline-flex; align-items: center; background: var(--card2); border-radius: 12px; }
.step-btn { width: 42px; height: 42px; border: 0; background: transparent; font-size: 1.4rem; font-weight: 700; color: var(--accent); cursor: pointer; border-radius: 12px; }
.step-btn:active { background: var(--accent-soft); }
.stepper-val { min-width: 44px; text-align: center; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---- Progreso ---- */
.bar { height: 8px; border-radius: 99px; background: var(--card2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--c, var(--accent)); transition: width .25s; }
.bar.over > i { background: var(--bad); }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.cat-cell { background: var(--card2); border-radius: 12px; padding: 8px 10px; }
.cat-cell .n { font-weight: 800; font-variant-numeric: tabular-nums; } .cat-cell .l { font-size: .75rem; color: var(--muted); font-weight: 700; }
.cat-cell .bar { margin-top: 6px; height: 6px; }

/* ---- Comidas ---- */
.meal-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.meal-head h3 { font-size: 1.05rem; } .meal-time { color: var(--muted); font-size: .85rem; }
.entry { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px dashed var(--line); }
.entry .name { font-weight: 600; } .entry.done .name { text-decoration: line-through; color: var(--muted); }
.entry input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.list-item:first-child { border-top: 0; }
.menu-line { display: flex; gap: 8px; align-items: center; padding: 6px 0; font-size: .92rem; }
details > summary { cursor: pointer; font-weight: 600; color: var(--accent); padding: 6px 0; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸ "; } details[open] > summary::before { content: "▾ "; }
.person-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); display: inline-block; }
.datebar { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 10px 0; }
.datebar .date-btn { flex: 1; text-align: center; font-weight: 800; position: relative; min-height: 44px; display: flex; align-items: center; justify-content: center; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.datebar .date-btn input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.weekday { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; }
.weekday .dn { width: 54px; font-weight: 800; } .weekday.today .dn { color: var(--accent); }

/* ---- Vacíos / dropzone ---- */
.empty { text-align: center; padding: 28px 16px; color: var(--muted); } .empty-icon { font-size: 2.4rem; margin-bottom: 6px; } .empty h3 { color: var(--ink); margin-bottom: 4px; }
.drop { border: 2px dashed var(--line); border-radius: var(--r); padding: 26px 16px; text-align: center; background: var(--card); }
.warn-box { background: color-mix(in srgb, var(--warn) 14%, var(--card)); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); border-radius: 12px; padding: 10px 12px; font-size: .9rem; margin-bottom: 10px; }
.info-box { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; font-size: .9rem; margin-bottom: 10px; }
.result { background: var(--accent-soft); border-radius: var(--r); padding: 14px; }
.result .big { font-size: 1.35rem; font-weight: 800; }
.preview { width: 100%; max-height: 240px; object-fit: contain; border-radius: 12px; background: #000; }
pre.raw { white-space: pre-wrap; font-size: .8rem; background: var(--card2); padding: 10px; border-radius: 10px; max-height: 220px; overflow: auto; }

/* ---- Hojas modales ---- */
#layer { position: relative; z-index: 50; }
.sheet-wrap { position: fixed; inset: 0; display: flex; align-items: flex-end; justify-content: center; opacity: 0; transition: opacity .15s; }
.sheet-wrap.open { opacity: 1; } .sheet-wrap.closing { opacity: 0; }
.backdrop { position: absolute; inset: 0; background: rgba(10,16,12,.5); }
.sheet { position: relative; width: 100%; max-width: 720px; max-height: 92dvh; background: var(--bg); border-radius: 22px 22px 0 0; display: flex; flex-direction: column; transform: translateY(14px); transition: transform .18s; box-shadow: 0 -10px 40px rgba(0,0,0,.25); }
.sheet-wrap.open .sheet { transform: none; }
.sheet.full { height: 92dvh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 8px 8px 18px; border-bottom: 1px solid var(--line); }
.sheet-body { padding: 14px 16px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet-foot { display: flex; gap: 8px; padding: 10px 16px calc(10px + var(--sab)); border-top: 1px solid var(--line); background: var(--bg); }
.sheet-foot .btn { flex: 1; }
.confirm-msg { font-size: 1.05rem; padding: 6px 0 10px; }
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--sab) + 16px); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; opacity: 0; transition: .2s; z-index: 80; max-width: 90vw; font-weight: 600; pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.progress-wrap { padding: 24px 6px; text-align: center; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 12px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Autenticación ---- */
.auth { max-width: 420px; margin: 0 auto; padding: calc(var(--sat) + 40px) 18px 40px; }
.auth h1 { font-size: 1.8rem; margin-bottom: 4px; }
.logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 14px; }

@media (min-width: 760px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 22px; max-height: 86dvh; } .sheet.full { height: 86dvh; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
