:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #151826;
  --muted: #586074;
  --border: #e1e4ee;
  --primary: #4f46e5;
  --primary-ink: #ffffff;
  --ok: #0f7b4b;
  --ok-soft: #dcf5e8;
  --warn: #8a5100;
  --warn-soft: #fff3dc;
  --bad: #b42318;
  --bad-soft: #fde4e1;
  --radius: 18px;
  --shadow: 0 1px 2px rgb(16 24 40 / .05), 0 4px 14px rgb(16 24 40 / .04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1016;
    --surface: #171a23;
    --surface-2: #232733;
    --text: #eceef4;
    --muted: #a4aabb;
    --border: #2b3040;
    --primary: #8f8aff;
    --primary-ink: #0e1016;
    --ok: #5ad19a;
    --ok-soft: #15301f;
    --warn: #f5b955;
    --warn-soft: #34280f;
    --bad: #ff8b7b;
    --bad-soft: #3b1c19;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { line-height: 1.2; }
h3 { font-size: 16px; margin: 20px 0 0; }
a { color: var(--primary); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 10px; }
.view-title:focus, #view:focus { outline: none; }
.muted { color: var(--muted); }
.mt0 { margin-top: 0; }

/* ───── Estructura ───── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { flex: 1; min-width: 0; font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }
.pill.remote { background: var(--ok-soft); color: var(--ok); }
.pill:empty { display: none; }
#me-btn { border-radius: 50%; text-decoration: none; display: inline-flex; }
#view { max-width: 640px; margin: 0 auto; padding: 12px 16px calc(100px + env(safe-area-inset-bottom)); }
.loading-msg { text-align: center; color: var(--muted); margin-top: 30vh; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 62px; font-size: 12px; color: var(--muted); text-decoration: none; font-weight: 500;
}
.tabbar .ti { font-size: 22px; line-height: 1; filter: grayscale(.6); opacity: .8; }
.tabbar a[aria-current="page"] { color: var(--primary); font-weight: 700; }
.tabbar a[aria-current="page"] .ti { filter: none; opacity: 1; }
.tab-badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
body.loading .tabbar, body.loading .topbar > :not(.brand) { visibility: hidden; }
body.onboarding .topbar, body.onboarding .tabbar { display: none; }

/* ───── Cabeceras de vista ───── */
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.view-title { font-size: 26px; margin: 10px 0 4px; }
.sub { color: var(--muted); margin: 0 0 16px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 12px; }
.empty { color: var(--muted); margin: 4px 0; }
p.empty.card { padding: 24px 16px; text-align: center; }

/* ───── Tarjetas y listas ───── */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin: 0 0 12px; box-shadow: var(--shadow);
}
.card h2 { font-size: 17px; margin: 2px 0 8px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.card-head h2 { margin: 0; }
.warn-card { background: var(--warn-soft); border-color: transparent; }
.count { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }

.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 0; min-height: 56px; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.list.compact .row { min-height: 44px; padding: 4px 0; }
.grow { flex: 1; min-width: 0; }
.row small { display: block; color: var(--muted); font-size: 13px; }
.row.is-editing { background: var(--surface-2); border-radius: 12px; padding-left: 8px; padding-right: 8px; }
.row.is-done strong { text-decoration: line-through; color: var(--muted); }
.icon { font-size: 24px; width: 32px; text-align: center; flex: none; }
.slot-label { font-size: 12px; font-weight: 700; color: var(--muted); }
.slot-label.w { width: 82px; flex: none; font-size: 13px; }

/* ───── Botones ───── */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 650;
  text-decoration: none; white-space: nowrap; cursor: pointer; transition: transform .1s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.icon-btn {
  appearance: none; flex: none; display: inline-grid; place-items: center;
  width: 40px; height: 40px; border: 0; border-radius: 12px;
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 18px; cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }
.link-btn {
  appearance: none; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; padding: 4px 0;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions .btn.primary { flex: 1; }

/* ───── Inventario ───── */
.stepper { display: flex; align-items: center; gap: 4px; }
.qty { min-width: 54px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.qty small { display: inline; font-weight: 400; color: var(--muted); }
.search input { margin-top: 6px; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  font-size: 12px; font-weight: 650; background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.warn-card .badge.warn { background: var(--surface); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 12px; }
.chip {
  position: relative; display: inline-flex; align-items: center; min-height: 40px; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 550; cursor: pointer;
}
.chip[aria-pressed="true"], .chip.radio:has(input:checked) { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chip.radio input { position: absolute; opacity: 0; pointer-events: none; }
.chip.radio:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }
.chip.static { min-height: 0; padding: 4px 10px; cursor: default; background: var(--surface-2); border-color: transparent; }

/* ───── Compra ───── */
.quick-add { display: flex; gap: 8px; }
.quick-add input { flex: 1; }
.quick-add .btn { width: 52px; font-size: 22px; }
.check {
  appearance: none; display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 4px 0;
  border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.check .box {
  flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 9px;
  border: 2px solid var(--muted); color: var(--surface); font-weight: 800;
}
.is-done .check .box { background: var(--ok); border-color: var(--ok); }

/* ───── Avatares ───── */
.avatar {
  --c: #4f46e5; flex: none; display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 50%; background: var(--c); color: #fff; font-weight: 700; font-size: 15px;
}
.avatar.sm { width: 26px; height: 26px; font-size: 12px; }
.avatar.lg { width: 60px; height: 60px; font-size: 26px; }

/* ───── ¿Quién eres? ───── */
.profiles { list-style: none; margin: 0 0 16px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.profile {
  appearance: none; width: 100%; min-height: 132px; padding: 18px 10px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: inherit; font: inherit;
  box-shadow: var(--shadow); transition: transform .1s;
}
.profile:active { transform: scale(.97); }
.profile:hover { border-color: var(--primary); }
.profile strong { font-size: 17px; }
.profile small { color: var(--muted); font-size: 12px; }

/* ───── Menú ───── */
.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; font-weight: 650; }
.day.today { border-color: var(--primary); }
.slots { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.slot {
  appearance: none; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-height: 76px;
  padding: 10px 12px; border: 1px solid transparent; border-radius: 14px;
  background: var(--surface-2); color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.slot.empty-slot { background: transparent; border: 1.5px dashed var(--border); }
.cook { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 13px; color: var(--muted); }

/* ───── Limpieza ───── */

/* ───── Actividad ───── */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; }
.feed p { margin: 2px 0 0; }
.feed time { display: block; font-size: 12px; color: var(--muted); }

/* ───── Formularios ───── */
.form label, .form legend { display: block; margin: 14px 0 6px; padding: 0; font-size: 14px; font-weight: 650; }
.form label.chip { display: inline-flex; margin: 0; padding: 8px 14px; font-size: 14px; font-weight: 550; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px;
}
textarea { resize: vertical; }
fieldset { border: 0; margin: 0; padding: 0; }
fieldset .chips { margin-top: 0; }
.field-row { display: flex; gap: 8px; align-items: flex-end; }
.field-row input { flex: 1; }
.w-icon { width: 76px; flex: none; }
.w-icon input { text-align: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form label.check-label { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.check-label input { width: 22px; height: 22px; min-height: 0; accent-color: var(--primary); }
#scan-area video { width: 100%; max-height: 240px; border-radius: 14px; background: #000; object-fit: cover; }
.howto { margin: 8px 0 0; padding-left: 18px; }
.howto li { margin: 6px 0; }
.invite-code { margin: 4px 0 14px; font-size: 32px; font-weight: 800; letter-spacing: .15em; font-variant-numeric: tabular-nums; }

/* ───── Hoja inferior (dialog) ───── */
#sheet {
  width: 100%; max-width: 640px; max-height: 90dvh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 22px 22px 0 0; background: var(--surface); color: var(--text);
  box-shadow: 0 -10px 40px rgb(0 0 0 / .25);
}
#sheet[open] { animation: sheet-up .22s ease-out; }
#sheet::backdrop { background: rgb(10 12 20 / .5); }
.sheet-inner { padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h2 { margin: 0; font-size: 19px; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) { #sheet { margin: auto; border-radius: 22px; } }

/* ───── Avisos ───── */
#toasts {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 100;
  bottom: calc(76px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px; width: min(560px, calc(100% - 32px)); pointer-events: none;
}
.toast {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px;
  border-radius: 14px; background: var(--text); color: var(--bg); font-weight: 550;
  box-shadow: 0 8px 24px rgb(0 0 0 / .2); pointer-events: auto; animation: sheet-up .2s ease-out;
}
.toast .btn { background: transparent; color: inherit; border-color: currentColor; }

/* ───── Bienvenida ───── */
.onb { max-width: 480px; margin: 0 auto; padding-top: 20px; }
.onb-hero { text-align: center; margin-bottom: 18px; }
.onb-hero h1 { margin: 10px 0 4px; }
.onb .btn { width: 100%; margin-top: 16px; }
.onb h2 { margin-bottom: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
