/* Layout: one mobile-first column; each storage zone is a "shelf" with a thick plank rule under its label. */
:root {
  --bg: #f3f6f2;
  --surface: #ffffff;
  --sunk: #e8eee8;
  --ink: #1b2822;
  --muted: #5a6a61;
  --line: #d6dfd8;
  --accent: #2c6a4d;
  --accent-ink: #ffffff;
  --plank: #a8743f;
  --crit: #bf3b28;
  --crit-bg: #fbe7e3;
  --warn: #a8690f;
  --warn-bg: #fbf0dc;
  --ok: #2f7550;
  --ok-bg: #e2f1e8;
  --shadow: 0 10px 30px rgba(20, 40, 30, .14);
  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111714; --surface: #19211d; --sunk: #222c27; --ink: #e4ebe6; --muted: #98a79e; --line: #2c3832;
    --accent: #72c497; --accent-ink: #0d1a13; --plank: #c99256;
    --crit: #f2806b; --crit-bg: #3a1e19; --warn: #e6b456; --warn-bg: #3a2d15; --ok: #7fcb9d; --ok-bg: #1b3326;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 16px; line-height: 1.45; padding-top: env(safe-area-inset-top, 0px); }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.wrap { max-width: 780px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 0 120px; }

.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg); padding-block: 16px 0; }
.brand { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand h1 { margin: 0; font-family: var(--f-display); font-weight: 800; font-size: clamp(1.6rem, 5vw, 2.1rem); letter-spacing: -.02em; line-height: 1; text-wrap: balance; }
.brand h1 small { display: block; font-family: var(--f-body); font-weight: 400; font-size: .85rem; color: var(--muted); letter-spacing: 0; margin-top: 6px; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; font-size: .9rem; display: inline-flex; gap: 6px; align-items: center; }
.icon-btn:hover { border-color: var(--accent); }

.tabs { display: flex; gap: 4px; margin-top: 14px; background: var(--sunk); padding: 4px; border-radius: 12px; overflow-x: auto; scrollbar-width: none; }
.tab { flex: 1 0 auto; border: 0; background: transparent; padding: 10px 10px; border-radius: 9px; font-weight: 700; font-size: .95rem; color: var(--muted); display: flex; gap: 6px; justify-content: center; align-items: center; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.count { font-family: var(--f-mono); font-size: .72rem; background: var(--line); color: var(--ink); border-radius: 999px; padding: 1px 7px; }
.count.crit { background: var(--crit); color: var(--surface); }
.top::after { content: ""; display: block; height: 12px; background: linear-gradient(var(--bg), transparent); margin-bottom: -12px; position: relative; }

.notice { margin-top: 14px; padding: 10px 14px; border-radius: 10px; background: var(--warn-bg); color: var(--ink); font-size: .9rem; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

.view { margin-top: 18px; display: flex; flex-direction: column; gap: 18px; }

.alerts { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { border: 0; border-radius: 999px; padding: 6px 12px; font-size: .88rem; font-weight: 700; display: inline-flex; gap: 6px; align-items: center; }
.pill b { font-family: var(--f-mono); }
.pill.crit { background: var(--crit-bg); color: var(--crit); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.neutral { background: var(--sunk); color: var(--muted); }

.tools { display: flex; flex-direction: column; gap: 10px; }
.search { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 14px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 13px; font-size: .88rem; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.shelf h2 { margin: 0; font-family: var(--f-display); font-weight: 700; font-size: 1.15rem; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding-bottom: 6px; border-bottom: 5px solid var(--plank); border-radius: 0 0 2px 2px; }
.shelf h2 span { font-family: var(--f-mono); font-size: .78rem; font-weight: 500; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "main qty cart" "exp qty cart"; align-items: center; column-gap: 10px; row-gap: 4px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.row-main { grid-area: main; min-width: 0; text-align: left; border: 0; background: none; padding: 0; display: flex; flex-direction: column; }
.nm { font-weight: 700; font-size: 1.02rem; overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: .85rem; }
.exp-slot { grid-area: exp; min-width: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.qty { grid-area: qty; display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.qty button { border: 0; background: none; width: 34px; height: 34px; font-size: 1.1rem; font-weight: 700; }
.qty button:hover { color: var(--accent); }
.qty output { min-width: 3.4em; text-align: center; font-family: var(--f-mono); font-size: .85rem; font-variant-numeric: tabular-nums; }
.cart { grid-area: cart; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; width: 36px; height: 36px; display: grid; place-items: center; }
.cart:hover { border-color: var(--accent); color: var(--accent); }
.cart svg { width: 18px; height: 18px; }
.row.empty .nm { color: var(--muted); text-decoration: line-through; }
.row.empty .qty output { color: var(--crit); font-weight: 700; }

.badge { display: inline-flex; gap: 6px; align-items: center; font-family: var(--f-mono); font-size: .74rem; font-weight: 500; padding: 2px 8px; border-radius: 6px; background: var(--sunk); color: var(--muted); white-space: nowrap; }
.badge .t { font-weight: 700; letter-spacing: .04em; }
.badge.crit { background: var(--crit-bg); color: var(--crit); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }

.empty-state { text-align: center; padding: 40px 16px; border: 2px dashed var(--line); border-radius: 16px; color: var(--muted); }
.empty-state h3 { margin: 0 0 6px; font-family: var(--f-display); color: var(--ink); font-size: 1.2rem; }
.empty-state p { margin: 0 auto; max-width: 42ch; }

/* Caducidades */
.group h2 { margin: 0 0 4px; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.group h2::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--g, var(--line)); }
.g-crit { --g: var(--crit); } .g-warn { --g: var(--warn); } .g-ok { --g: var(--ok); }
.tl { list-style: none; margin: 0; padding: 0; }
.tl button { width: 100%; display: grid; grid-template-columns: 4.6em minmax(0, 1fr) auto; gap: 12px; align-items: center; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 10px 0; }
.tl .d { font-family: var(--f-mono); font-weight: 700; font-size: .95rem; line-height: 1.1; }
.tl .d small { display: block; font-weight: 500; font-size: .7rem; color: var(--muted); text-transform: uppercase; }
.tl .who { min-width: 0; }
.tl .who b { display: block; overflow-wrap: anywhere; }
.tl .who span { color: var(--muted); font-size: .85rem; }
.tl .rel { font-family: var(--f-mono); font-size: .8rem; color: var(--muted); white-space: nowrap; }
.tl .rel.crit { color: var(--crit); font-weight: 700; } .tl .rel.warn { color: var(--warn); font-weight: 700; }
.legend { font-size: .85rem; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 0; }
.legend b { color: var(--ink); }

/* Compra */
.shop-add { display: grid; grid-template-columns: minmax(0, 1fr) 5.5em auto; gap: 8px; }
.shop-add input { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 12px; min-width: 0; }
.btn { border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 12px; padding: 11px 16px; font-weight: 700; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--crit); color: var(--surface); }
.sub { margin: 0; font-family: var(--f-display); font-size: 1.05rem; font-weight: 700; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.sub span { font-family: var(--f-mono); font-size: .78rem; font-weight: 500; color: var(--muted); }
.srow { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.srow input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }
.srow label { min-width: 0; overflow-wrap: anywhere; }
.srow label small { display: block; color: var(--muted); font-size: .8rem; }
.srow.done label { color: var(--muted); text-decoration: line-through; }
.mini { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 5px 10px; font-size: .82rem; white-space: nowrap; }
.mini:hover { border-color: var(--accent); }
.mini:disabled { opacity: .6; cursor: default; }
.mini.to { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.x { border: 0; background: none; color: var(--muted); font-size: 1.3rem; line-height: 1; width: 30px; height: 30px; border-radius: 8px; }
.x:hover { color: var(--crit); background: var(--crit-bg); }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.suggest .chip::before { content: "+ "; color: var(--accent); font-weight: 700; }
.foot-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Recetas */
.rbar { display: flex; flex-direction: column; gap: 10px; }
.chips.wrap-chips { flex-wrap: wrap; overflow: visible; }
.rrow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.rrow input, .rrow select { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 12px; min-width: 0; }
.rstatus { color: var(--muted); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.rcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 12px; }
.rcard { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.rcard h3 { margin: 0; font-family: var(--f-display); font-size: 1.15rem; line-height: 1.2; text-wrap: balance; }
.rtags { display: flex; flex-wrap: wrap; gap: 6px; }
.rcard p { margin: 0; }
.rcard .uses, .rcard .miss { font-size: .9rem; }
.rcard .uses b, .rcard .miss b { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-right: 6px; }
.soon { color: var(--crit); font-weight: 700; }
.rcard details summary { cursor: pointer; font-weight: 700; color: var(--accent); }
.rcard ol, .rcard ul { margin: 6px 0 0; padding-left: 1.3em; }
.rcard li { margin-bottom: 4px; }
.racts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 4px; }

/* Botones flotantes */
.fabs { position: fixed; right: calc(16px + env(safe-area-inset-right, 0px)); bottom: calc(18px + env(safe-area-inset-bottom, 0px)); z-index: 6; display: flex; gap: 8px; align-items: center; }
.fab { border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 14px 22px; font-weight: 700; font-size: 1rem; box-shadow: var(--shadow); display: inline-flex; gap: 8px; align-items: center; }
.fab.alt { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.fab span { font-size: 1.3rem; line-height: 1; }

/* Hojas (formularios) */
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(10, 20, 15, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--surface); border-radius: 20px 20px 0 0; padding: 20px max(18px, env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px)); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
@media (min-width: 640px) { .backdrop { align-items: center; } .sheet { border-radius: 20px; } }
.sheet h2 { margin: 0; font-family: var(--f-display); font-size: 1.35rem; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.field input, .field select, .field textarea { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg label { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: .88rem; display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.seg label:has(input:checked) { border-color: var(--accent); background: var(--ok-bg); }
.seg input { accent-color: var(--accent); margin-top: 3px; }
.seg small { display: block; color: var(--muted); font-size: .76rem; }
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: space-between; align-items: center; }
.sheet-actions .r { display: flex; gap: 8px; margin-left: auto; }
.err { color: var(--crit); font-size: .88rem; margin: 0; }
.zlist { list-style: none; margin: 0; padding: 0; }
.zlist li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.zlist li small { color: var(--muted); font-family: var(--f-mono); font-size: .76rem; margin-left: 6px; }
.account { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 14px; border-radius: 12px; background: var(--sunk); }
.account span { min-width: 0; overflow-wrap: anywhere; }

.field textarea { resize: vertical; min-height: 7em; line-height: 1.5; }

/* Acceso */
.auth { min-height: 100vh; display: grid; place-items: center; padding-block: 24px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.auth-card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 14px; }
.auth-card h1 { margin: 0; font-family: var(--f-display); font-weight: 800; font-size: 2.2rem; letter-spacing: -.02em; line-height: 1; padding-bottom: 10px; border-bottom: 5px solid var(--plank); }
.auth-card form, .auth-card .box { display: flex; flex-direction: column; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--sunk); padding: 4px; border-radius: 10px; }
.auth-tabs button { border: 0; background: transparent; padding: 8px; border-radius: 7px; font-weight: 700; color: var(--muted); }
.auth-tabs button[aria-pressed="true"] { background: var(--surface); color: var(--ink); }
.link { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; font-size: .9rem; align-self: flex-start; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom, 0px)); z-index: 30; background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 14px; display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow); max-width: calc(100vw - 32px); font-size: .92rem; }
.toast button { border: 0; background: transparent; color: var(--accent); font-weight: 700; filter: brightness(1.25); white-space: nowrap; }

@media (max-width: 420px) {
  .grid2 { grid-template-columns: 1fr; }
  .shop-add { grid-template-columns: minmax(0, 1fr) 4.6em; }
  .shop-add .btn { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: up .22s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}
