/* whatelse?
   Dirección: «el ticket de la compra». El ticket es el único adorno; el resto es papel y tinta.
   - Una sola familia para la interfaz (Bricolage Grotesque) y una mono solo en el ticket (Martian Mono).
   - Listas como listas: una superficie por sección, filas separadas por una línea fina, sin sombras.
   - Precios siempre alineados a la derecha con cifras tabulares.
   - Oscuro por defecto; el claro se activa con data-theme="light" (lo pone prefs.js).
   - Radios con jerarquía: 16px paneles, 10px controles, redondo solo en casillas, avatares y chips. */

:root {
  color-scheme: dark;
  --bg: #111613;
  --surface: #182019;
  --surface-2: #1f2821;
  --line: #29332c;
  --line-strong: #37433a;
  --ink: #e8ede7;
  --muted: #a0ada3;
  --faint: #748178;
  --green: #4cc285;
  --green-hover: #63d196;
  --green-ink: #07160e;
  --green-soft: #1a3325;
  --green-text: #7fd8a5;
  --tomato: #f07a62;
  --tomato-soft: #3a211b;
  --paper: #fffdf6;
  --paper-ink: #24221e;
  --paper-faint: #7a766c;
  --font: 'Bricolage Grotesque', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Martian Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --tabbar-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom);
  --r-panel: 16px;
  --r-control: 10px;
}

/* Tema claro, si se elige en el perfil (el oscuro es el de siempre) */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f4f0;
  --surface: #ffffff;
  --surface-2: #eef1ec;
  --line: #dde3db;
  --line-strong: #c9d1c7;
  --ink: #16201b;
  --muted: #5d6a62;
  --faint: #8a968e;
  --green: #1e6b45;
  --green-hover: #175637;
  --green-ink: #ffffff;
  --green-soft: #e2efe7;
  --green-text: #1a5e3d;
  --tomato: #d4452b;
  --tomato-soft: #fbe6e1;
}


* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 16px/1.5 var(--font); font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2.5px solid var(--green); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.shell-nav { display: contents; }
.summary, .desktop-only, .sample-wrap { display: none; }

/* ---------- Estructura (móvil) ---------- */
.app { max-width: 640px; margin: 0 auto; min-height: 100dvh; }
.content { padding: 0 16px calc(var(--tabbar-h) + 104px + var(--safe-bottom)); }

.appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 800; font-stretch: 85%; font-size: 18px; letter-spacing: -.2px; }
.brand-mark { width: 34px; height: 34px; border-radius: var(--r-control); display: block; flex: none; }
@media (max-width: 1023px) { .appbar:has(.group-switcher:not([hidden])) .brand-name { display: none; } }
.group-switcher { flex: 1; min-width: 0; display: grid; justify-items: start; gap: 2px; border: 0; background: none; padding: 2px 0; text-align: left; border-radius: var(--r-control); }
.group-name { display: flex; align-items: center; gap: 2px; max-width: 100%; font-size: 18px; font-weight: 800; font-stretch: 85%; letter-spacing: -.2px; line-height: 1.2; }
.group-name > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-name svg { width: 18px; height: 18px; color: var(--muted); }
.group-members { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); max-width: 100%; }
.avatars { display: flex; }
.avatar { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; border: 2px solid var(--bg); margin-left: -6px; flex: none; line-height: 1; }
.avatars .avatar:first-child { margin-left: 0; }
.avatar.lg { width: 36px; height: 36px; font-size: 15px; border: 0; margin: 0; }
.avatar.xs { width: 16px; height: 16px; font-size: 9px; border: 0; margin: 0; }
.icon-button { width: 40px; height: 40px; border-radius: var(--r-control); border: 1px solid var(--line); background: var(--surface); color: var(--ink); display: grid; place-items: center; flex: none; }
.icon-button:hover { border-color: var(--line-strong); }
.icon-button.small { width: 34px; height: 34px; }
.icon-button.small svg { width: 16px; height: 16px; }

.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 8px 0 16px; }
.page-head h1 { margin: 0; font-size: 36px; line-height: 1; font-weight: 800; font-stretch: 78%; letter-spacing: -.6px; }
.page-head p { margin: 0; font-size: 14px; color: var(--muted); text-align: right; }
.page-head p:empty { display: none; }

/* ---------- Controles ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); padding: 20px; }
.card-title { margin: 0; font-size: 21px; font-weight: 700; font-stretch: 88%; letter-spacing: -.2px; line-height: 1.2; }
.form-stack { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.field input, .field select, .inline-form input {
  width: 100%; height: 48px; padding: 0 14px; border-radius: var(--r-control);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-size: 16px; font-weight: 500; outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .inline-form input:focus { border-color: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 20%, transparent); }
.form-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; }
.button {
  min-height: 48px; padding: 0 18px; border-radius: var(--r-control); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font-size: 16px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
.button:hover { border-color: var(--ink); }
.button:active { transform: translateY(1px); }
.button.primary { background: var(--green); border-color: var(--green); color: var(--green-ink); }
.button.primary:hover { background: var(--green-hover); border-color: var(--green-hover); }
.button.ghost { background: transparent; }
.button.block { width: 100%; }
.button.small { min-height: 40px; padding: 0 14px; font-size: 15px; }
.button:disabled { opacity: .55; cursor: wait; }
.button svg { width: 18px; height: 18px; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.link-button { border: 0; background: none; padding: 4px 0; color: var(--green-text); font-weight: 700; font-size: 15px; text-align: left; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.hint { margin: 14px 2px 0; font-size: 14px; color: var(--faint); line-height: 1.5; max-width: 60ch; }
.status { color: var(--tomato); font-size: 14px; font-weight: 600; margin: 10px 2px 0; }
.status:empty { display: none; }
.error-text { color: var(--tomato); font-size: 15px; font-weight: 600; min-height: 20px; margin: 0; }
.section-label, .eyebrow { margin: 0 0 8px; font-size: 14px; font-weight: 700; color: var(--muted); }

/* ---------- Perfil, tema e idioma ---------- */
.quick-prefs { display: flex; gap: 6px; margin-left: auto; }
.quick-prefs .icon-button { font-size: 13px; font-weight: 800; }
body[data-view="app"] .quick-prefs { display: none; }
.profile-button { flex: none; display: flex; align-items: center; gap: 8px; border: 0; background: none; padding: 2px; border-radius: 999px; font-weight: 700; color: var(--ink); }
.profile-button .avatar { width: 36px; height: 36px; font-size: 15px; border: 0; margin: 0; }
.profile-head { grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; column-gap: 14px; }
.profile-head .avatar { width: 52px; height: 52px; font-size: 21px; border: 0; margin: 0; }
.profile-name { margin: 0; font-size: 21px; font-weight: 800; font-stretch: 85%; line-height: 1.2; overflow-wrap: anywhere; }
.profile-head .muted { margin: 2px 0 0; }
.list-rows { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden; }
.list-rows:empty { display: none; }
.list-row { width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 0; background: none; text-align: left; }
.list-rows li + li .list-row { border-top: 1px solid var(--line); }
.list-row:hover { background: var(--surface-2); }
.list-row b { display: block; font-weight: 700; }
.list-row small { color: var(--muted); font-size: 13px; }
.list-row .current { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--green-text); border: 1px solid var(--green); border-radius: 999px; padding: 2px 8px; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.segmented button { min-height: 40px; border: 0; border-radius: 9px; background: none; color: var(--muted); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.segmented button svg { width: 17px; height: 17px; }
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .15); }
.inline-details summary { cursor: pointer; font-weight: 700; color: var(--green-text); padding: 4px 0; }
.inline-details[open] summary { margin-bottom: 10px; }
.sheet-section h3 + .segmented { margin-top: -4px; }

/* ---------- Bienvenida e invitación ---------- */
.auth { display: grid; gap: 16px; padding-top: 12px; }
.auth-hero { padding: 20px 0 4px; }
.auth-hero h1 { margin: 0; font-size: 44px; line-height: .98; font-weight: 800; font-stretch: 75%; letter-spacing: -1px; max-width: 12ch; }
.auth-hero p { margin: 16px 0 0; max-width: 42ch; color: var(--muted); font-size: 17px; line-height: 1.55; }
.auth-hero .eyebrow { margin-bottom: 6px; font-size: 16px; }
.member-picks { display: flex; flex-wrap: wrap; gap: 8px; }
.member-picks:empty { display: none; }
.member-pick { min-height: 46px; padding: 0 16px 0 7px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); font-weight: 700; display: inline-flex; align-items: center; gap: 8px; }
.member-pick:hover { border-color: var(--green); background: var(--green-soft); }
.member-pick .avatar { width: 32px; height: 32px; font-size: 14px; border: 0; margin: 0; }

.notice { margin: 4px 0 14px; padding: 14px 16px; border-radius: var(--r-panel); background: var(--green-soft); display: grid; gap: 12px; }
.notice p { margin: 0; font-size: 15px; }

/* ---------- Añadir y buscar ---------- */
.composer { position: relative; background: var(--surface); border: 1.5px solid var(--line-strong); border-radius: var(--r-panel); padding: 6px; margin-bottom: 14px; transition: border-color .15s; }
.composer:focus-within { border-color: var(--green); }
.composer-main { display: flex; align-items: center; gap: 8px; padding-left: 10px; }
.composer-icon { color: var(--faint); }
.composer-main input { flex: 1; min-width: 0; height: 48px; border: 0; outline: 0; background: transparent; font-size: 18px; font-weight: 600; }
.composer-main input::placeholder { color: var(--faint); font-weight: 500; }
.composer-main input::-webkit-search-cancel-button { display: none; }
.add-button { width: 48px; height: 48px; border-radius: var(--r-control); border: 0; background: var(--green); color: var(--green-ink); display: grid; place-items: center; flex: none; }
.add-button:hover { background: var(--green-hover); }
.add-button:active { transform: scale(.95); }
.add-button:disabled { opacity: .6; }
.add-button svg { width: 22px; height: 22px; stroke-width: 2.4; }
.composer-options { display: none; gap: 8px; padding: 8px 4px 4px; }
.composer:focus-within .composer-options { display: flex; }
.composer-options select { height: 40px; min-width: 0; padding: 0 10px; border-radius: var(--r-control); border: 1px solid var(--line); background: var(--surface-2); font-size: 15px; font-weight: 600; outline: 0; }
.composer-options select:last-child { flex: 1; }
.stepper { display: flex; align-items: center; height: 40px; border-radius: var(--r-control); border: 1px solid var(--line); background: var(--surface-2); }
.stepper button { width: 36px; height: 100%; border: 0; background: none; font-size: 20px; color: var(--muted); }
.stepper input { width: 40px; border: 0; background: none; text-align: center; font-weight: 700; font-size: 16px; outline: 0; appearance: textfield; -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { appearance: none; margin: 0; }

.live-results { border-top: 1px solid var(--line); margin-top: 6px; padding: 8px 0 0; }
.live-head { display: flex; align-items: center; gap: 6px; margin: 0 8px 4px; }
.live-title { font-size: 14px; font-weight: 600; color: var(--muted); }
.live-store { height: 32px; padding: 0 8px; border-radius: var(--r-control); border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); font-size: 14px; font-weight: 700; outline: 0; }
.live-results ul { list-style: none; margin: 0; padding: 0; }
.live-item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 8px; border: 0; border-radius: var(--r-control); background: none; text-align: left; }
.live-item:hover, .live-item:focus-visible { background: var(--surface-2); }
.live-item .item-body { flex: 1; min-width: 0; }
.live-item .item-name { font-size: 15px; }
.live-price { font-weight: 800; font-size: 16px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.live-add { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; border: 1.5px solid var(--green); color: var(--green-text); flex: none; }
.live-add svg { width: 16px; height: 16px; stroke-width: 2.6; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 0; padding: 0; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 15px; font-weight: 600; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.chip:hover { border-color: var(--ink); }
.chip.active { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip .plus { color: var(--green-text); font-weight: 800; }
.usual { margin: 0 0 18px; }
.store-chips { margin-bottom: 12px; }

.filter { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: var(--r-control); border: 1px solid var(--line); background: var(--surface); color: var(--faint); margin: 0 0 8px; }
.filter svg { width: 17px; height: 17px; }
.filter input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; font-size: 16px; color: var(--ink); }

/* ---------- Listas ---------- */
.grouped-list { display: grid; gap: 20px; margin-top: 6px; }
.department-heading { margin: 0 2px 6px; font-size: 16px; font-weight: 700; font-stretch: 88%; display: flex; justify-content: space-between; align-items: baseline; }
.department-heading span:last-child { font-size: 14px; font-weight: 600; color: var(--faint); font-variant-numeric: tabular-nums; }
.item-list { list-style: none; margin: 0; padding: 0; }
.card-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden; margin-top: 8px; }
.card-list:empty { display: none; }
.grouped-list .card-list { margin-top: 0; }
.item { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; }
.item + .item { border-top: 1px solid var(--line); }
.item.removing { opacity: .3; }
.item-body { flex: 1; min-width: 0; }
.item-name { font-size: 16px; font-weight: 650; line-height: 1.3; color: var(--ink); overflow-wrap: anywhere; text-decoration: none; display: block; }
a.item-name:hover { text-decoration: underline; text-underline-offset: 2px; }
.item-meta { margin-top: 3px; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.person { display: inline-flex; align-items: center; gap: 5px; }
.item-side { display: grid; justify-items: end; gap: 6px; flex: none; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: contain; background: #fff; border: 1px solid var(--line); flex: none; }
.item > .check, .item > .thumb { margin-top: 1px; }
.check { width: 26px; height: 26px; margin-top: 2px; border-radius: 50%; border: 2px solid var(--line-strong); background: transparent; display: grid; place-items: center; color: transparent; flex: none; padding: 0; transition: border-color .15s, background .15s; }
.check svg { width: 15px; height: 15px; stroke-width: 3; }
.check:hover { border-color: var(--green); color: var(--green); }
.check:active { background: var(--green); border-color: var(--green); color: var(--green-ink); }
.price-button { border: 0; background: none; padding: 0; font-size: 16px; font-weight: 800; color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; }
.price-button.empty { font-size: 14px; font-weight: 600; color: var(--green-text); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.price-button small { display: block; font-size: 12px; font-weight: 500; color: var(--faint); }
.mini-stepper { display: inline-flex; align-items: center; border-radius: var(--r-control); border: 1px solid var(--line); }
.item-body > .mini-stepper { margin-top: 8px; }
.mini-stepper button { width: 34px; height: 32px; border: 0; background: none; font-size: 18px; color: var(--muted); display: grid; place-items: center; }
.mini-stepper button svg { width: 15px; height: 15px; }
.mini-stepper button:hover { color: var(--ink); }
.mini-stepper .qty { min-width: 36px; text-align: center; font-size: 14px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
#pantry-list .item, #catalog-list .item, #expense-list .item { align-items: center; }
.row-actions { display: flex; gap: 6px; align-items: center; }
.chip-button { min-height: 34px; padding: 0 12px; border-radius: var(--r-control); border: 1.5px solid var(--green); background: transparent; color: var(--green-text); font-size: 14px; font-weight: 700; white-space: nowrap; }
.chip-button:hover { background: var(--green-soft); }
.chip-button.in-list { background: var(--green); color: var(--green-ink); }
.price-tag { font-size: 17px; font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }
.store-badge { font-weight: 700; color: var(--ink); }
.no-results { padding: 20px; text-align: center; color: var(--muted); font-size: 15px; list-style: none; }
.catalog-list.loading, #catalog-list.loading { opacity: .5; }

.empty { padding: 36px 8px 12px; }
.empty-icon { display: none; }
.empty h3 { margin: 0 0 6px; font-size: 24px; font-weight: 800; font-stretch: 80%; letter-spacing: -.3px; }
.empty p { margin: 0; max-width: 40ch; color: var(--muted); font-size: 16px; }

/* ---------- El ticket ---------- */
.ticket {
  --zig: 14px;
  position: relative; background: var(--paper); color: var(--paper-ink);
  font-family: var(--mono); font-stretch: 80%; font-size: 13px; line-height: 1.55;
  padding: 22px 20px calc(22px + var(--zig));
  min-width: 0;
  /* Borde de abajo rasgado, como el papel térmico al cortarlo */
  -webkit-mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(var(--zig) * 2) 100%;
  mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / calc(var(--zig) * 2) 100%;
}
/* La sombra va en un envoltorio: si estuviera en el propio ticket, la máscara del borde rasgado la recortaría. */
.ticket-wrap { min-width: 0; filter: drop-shadow(0 1px 1px rgb(22 32 27 / .10)) drop-shadow(0 8px 16px rgb(22 32 27 / .10)); }
.ticket-head { display: grid; justify-items: center; gap: 1px; text-align: center; padding-bottom: 12px; margin-bottom: 10px; border-bottom: 1.5px dashed color-mix(in srgb, var(--paper-ink) 45%, transparent); text-transform: uppercase; letter-spacing: .5px; }
.ticket-head b { font-size: 15px; font-weight: 700; letter-spacing: 2px; }
.ticket-head span { color: var(--paper-faint); font-size: 12px; }
.ticket-lines { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; }
.ticket-lines li { display: flex; justify-content: space-between; gap: 12px; min-width: 0; }
.ticket-lines li > span { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-lines b { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ticket-lines li > b, .ticket-lines li > i { flex: none; }
.ticket-lines i { font-style: normal; color: var(--paper-faint); white-space: nowrap; }
.ticket-empty { color: var(--paper-faint); justify-content: center !important; padding: 6px 0; }
.ticket-subtotals { margin-top: 10px; padding-top: 10px; border-top: 1.5px dashed color-mix(in srgb, var(--paper-ink) 45%, transparent); color: var(--paper-faint); }
.ticket-subtotals b { color: var(--paper-ink); }
.ticket-total { display: flex; justify-content: space-between; align-items: baseline; margin-top: 12px; padding-top: 12px; border-top: 2px solid var(--paper-ink); text-transform: uppercase; }
.ticket-total span { font-size: 15px; font-weight: 700; letter-spacing: 2px; }
.ticket-total b { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.ticket-foot { margin: 12px 0 0; color: var(--paper-faint); font-size: 12px; text-align: center; }
/* Al añadir un producto con precio, su línea sale impresa */
.ticket-lines li.printed { animation: print .5s steps(6, end); }
@keyframes print { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

/* Punta del ticket (móvil): siempre a la vista sobre la navegación */
.total-wrap {
  position: fixed; z-index: 25; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  width: min(608px, calc(100% - 24px));
  filter: drop-shadow(0 -3px 10px rgb(22 32 27 / .14));
}
.total-bar {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(14px + 7px) 18px 12px; border: 0; text-align: left;
  background: var(--paper); color: var(--paper-ink); font-family: var(--mono); font-stretch: 80%;
  -webkit-mask: conic-gradient(from 135deg at top, #0000, #000 1deg 89deg, #0000 90deg) 50% / 14px 100%;
  mask: conic-gradient(from 135deg at top, #0000, #000 1deg 89deg, #0000 90deg) 50% / 14px 100%;
}
.total-main { display: flex; align-items: baseline; gap: 12px; }
.total-label { font-size: 13px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; }
.total-amount { font-size: 24px; font-weight: 700; letter-spacing: -.5px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.total-detail { font-size: 12px; color: var(--paper-faint); text-align: right; white-space: pre-line; }
.ticket-sheet .ticket { margin-bottom: 16px; }

/* ---------- Navegación inferior (móvil) ---------- */
.tabbar {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tab-button { position: relative; border: 0; background: none; display: grid; justify-items: center; align-content: center; gap: 2px; font-size: 12px; font-weight: 700; color: var(--faint); }
.tab-button.active { color: var(--ink); }
.tab-button.active::before { content: ''; position: absolute; top: -1px; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--green); }
.tab-icon { position: relative; display: grid; place-items: center; height: 26px; }
.tab-icon svg { width: 23px; height: 23px; }
.tab-button.active .tab-icon svg { stroke-width: 2.2; }
.tab-count { position: absolute; top: -5px; left: 15px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--tomato); color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; font-variant-numeric: tabular-nums; }
.tab-count[data-zero] { display: none; }

/* ---------- Gastos ---------- */
.balances { list-style: none; margin: 0 0 16px; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden; }
.balance { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; }
.balance + .balance { border-top: 1px solid var(--line); }
.balance-head { display: flex; align-items: center; gap: 10px; font-weight: 650; min-width: 0; }
.balance-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.balance-head .avatar { width: 30px; height: 30px; font-size: 13px; margin: 0; border: 0; }
.balance b { font-size: 17px; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.balance small { display: block; font-size: 12px; font-weight: 600; color: var(--faint); }
.balance.positive b { color: var(--green-text); }
.balance.negative b { color: var(--tomato); }
.settlements { display: grid; gap: 8px; margin-bottom: 16px; }
.settlements:empty { display: none; }
.settlement { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 10px 10px 16px; border-radius: var(--r-panel); border: 1.5px dashed var(--line-strong); font-weight: 650; }
.expense-form-box { padding: 0; margin: 0 0 4px; }
.expense-form-box summary { list-style: none; cursor: pointer; padding: 16px 18px; font-weight: 700; color: var(--green-text); display: flex; align-items: center; gap: 8px; }
.expense-form-box summary::-webkit-details-marker { display: none; }
.expense-form-box[open] summary { border-bottom: 1px solid var(--line); }
.expense-form-box form { padding: 16px 18px 18px; }
.participants { border: 0; margin: 0; padding: 0; }
.participants legend { padding: 0; margin-bottom: 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.participant { min-height: 40px; padding: 0 14px 0 10px; border-radius: 999px; border: 1px solid var(--line-strong); font-size: 15px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.participant:has(input:checked) { background: var(--green-soft); border-color: var(--green); }
.participant input { width: 18px; height: 18px; margin: 0; accent-color: var(--green); }
.expense-item .avatar { width: 36px; height: 36px; font-size: 15px; margin: 0; border: 0; }
.expense-item.transfer .item-name { color: var(--muted); font-weight: 600; }

/* ---------- Hojas (grupo y ticket) ---------- */
.sheet { width: min(100% - 24px, 520px); max-height: min(90dvh, 820px); padding: 0; border: 0; border-radius: 20px; background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / .25); }
.sheet::backdrop { background: rgb(10 15 12 / .45); }
.sheet[open] { animation: sheet-in .2s ease-out; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.sheet-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 10px; background: var(--surface); }
.sheet-head h2 { margin: 0; font-size: 24px; font-weight: 800; font-stretch: 80%; letter-spacing: -.3px; }
.sheet-section { padding: 14px 20px; display: grid; gap: 12px; }
.sheet-section + .sheet-section { border-top: 1px solid var(--line); }
.sheet-section:last-child { padding-bottom: 24px; }
.sheet-section h3 { margin: 0; font-size: 16px; font-weight: 700; }
.sheet-section .hint { margin: 0; }
.ticket-sheet { background: var(--bg); }
.ticket-sheet .sheet-head { background: var(--bg); }
.member-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.member-list li { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-weight: 650; }
.member-list li > span.name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--muted); }
.badge.me { border-color: var(--green); color: var(--green-text); }
.invite-link { margin: 0; padding: 12px 14px; border-radius: var(--r-control); background: var(--surface-2); font: 500 13px var(--mono); font-stretch: 85%; color: var(--muted); overflow-wrap: anywhere; user-select: all; }

/* ---------- Aviso flotante ---------- */
.toast {
  position: fixed; z-index: 50; left: 50%; bottom: calc(var(--tabbar-h) + 90px + var(--safe-bottom));
  transform: translate(-50%, 8px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 14px; max-width: calc(100% - 32px);
  padding: 12px 16px; border-radius: var(--r-control); background: var(--ink); color: var(--bg);
  font-size: 15px; font-weight: 600; box-shadow: 0 10px 30px rgb(0 0 0 / .2); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.actionable.show { pointer-events: auto; }
.toast-action { border: 0; background: none; color: var(--bg); font-weight: 800; font-size: 15px; padding: 4px 0; text-decoration: underline; text-underline-offset: 3px; }
body:not([data-view="app"]) .toast { bottom: calc(24px + var(--safe-bottom)); }
body:has(#total-bar[hidden]) .toast { bottom: calc(var(--tabbar-h) + 16px + var(--safe-bottom)); }

@media (max-width: 600px) {
  .sheet { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 20px 20px 0 0; max-height: 92dvh; padding-bottom: var(--safe-bottom); }
}

/* ---------- Tabletas ---------- */
@media (min-width: 700px) and (max-width: 1023px) {
  .app { max-width: 720px; }
  .content { padding-left: 24px; padding-right: 24px; }
  .tabbar { left: 50%; right: auto; transform: translateX(-50%); width: min(720px, 100%); border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; }
}

/* ---------- Ordenador ---------- */
@media (min-width: 1024px) {
  .app { max-width: none; }
  /* Bienvenida: a la izquierda el titular y los formularios; a la derecha un ticket de ejemplo */
  body:not([data-view="app"]) .appbar { position: static; max-width: 1160px; margin: 0 auto; padding: 32px 48px 0; background: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
  body:not([data-view="app"]) .content { max-width: 1160px; margin: 0 auto; padding: 24px 48px 72px; }
  .auth {
    grid-template-columns: minmax(0, 560px) minmax(0, 1fr);
    grid-template-areas: "hero sample" "create sample" "login sample" "invite sample" "error sample";
    column-gap: 72px; row-gap: 16px; align-items: start; padding-top: 24px;
  }
  #join { grid-template-areas: "hero ." "create ." "error ."; }
  .auth-hero { grid-area: hero; padding: 8px 0 12px; }
  .auth-hero h1 { font-size: 72px; line-height: .92; letter-spacing: -2px; }
  .auth-hero p { font-size: 19px; }
  #create-group-form, #join > .card { grid-area: create; }
  #welcome > .card:not(form) { grid-area: invite; }
  #login-form { grid-area: login; }
  .auth > .error-text { grid-area: error; }
  .sample-wrap { display: block; grid-area: sample; width: 340px; justify-self: center; margin-top: 40px; transform: rotate(-1.5deg); }

  /* App: barra lateral, lista y ticket */
  body[data-view="app"] .app { display: grid; grid-template-columns: 256px minmax(0, 1fr); max-width: none; }
  body[data-view="app"] .shell-nav {
    display: flex; flex-direction: column; gap: 24px;
    position: sticky; top: 0; height: 100dvh; padding: 24px 16px;
    border-right: 1px solid var(--line); overflow-y: auto;
  }
  body[data-view="app"] .appbar { position: static; display: grid; gap: 18px; padding: 0; background: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
  body[data-view="app"] .brand { padding: 0 8px; }
  body[data-view="app"] .appbar .brand-name { display: inline; }
  body[data-view="app"] .group-switcher { padding: 10px 8px; border-radius: var(--r-control); }
  body[data-view="app"] .group-switcher:hover { background: var(--surface-2); }
  body[data-view="app"] .group-name { font-size: 21px; }
  body[data-view="app"] #quick-invite { width: 100%; height: 44px; gap: 8px; font-weight: 700; font-size: 15px; display: flex; justify-content: center; }
  body[data-view="app"] #quick-invite[hidden] { display: none; }
  body[data-view="app"] .profile-button { order: 3; width: 100%; padding: 8px; border-radius: var(--r-control); justify-content: flex-start; }
  body[data-view="app"] .profile-button:hover { background: var(--surface-2); }
  body[data-view="app"] .appbar { grid-template-rows: auto auto auto; }
  body[data-view="app"] .shell-nav .profile-button { margin-top: auto; }
  .desktop-only { display: inline; }

  .tabbar { position: static; display: grid; grid-template-columns: none; gap: 2px; height: auto; padding: 0; background: none; border: 0; transform: none; width: auto; order: 2; }
  .tab-button { display: flex; align-items: center; justify-content: flex-start; gap: 12px; padding: 10px 12px; border-radius: var(--r-control); font-size: 16px; color: var(--muted); }
  .tab-button:hover { background: var(--surface-2); color: var(--ink); }
  .tab-button.active { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
  .tab-button.active::before { top: 10px; bottom: 10px; left: 0; right: auto; width: 3px; height: auto; border-radius: 0 3px 3px 0; }
  .tab-icon { display: contents; }
  .tab-count { position: static; order: 1; margin-left: auto; min-width: 0; height: auto; background: transparent; color: var(--faint); font-weight: 700; font-size: 14px; padding: 0; }
  .tab-button.active .tab-count { color: var(--ink); }

  body[data-view="app"] .content { padding: 40px 56px 72px; max-width: 1180px; width: 100%; }
  #app-content:not([hidden]) {
    display: grid; grid-template-columns: minmax(0, 1fr) 340px; column-gap: 48px;
    grid-template-areas: "notice notice" "head aside" "main aside"; grid-template-rows: auto auto 1fr; align-items: start;
  }
  #passkey-notice { grid-area: notice; display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 0 0 24px; }
  #passkey-notice[hidden] { display: none; }
  .page-head { grid-area: head; margin: 0 0 24px; }
  .page-head h1 { font-size: 60px; letter-spacing: -1.4px; }
  .page-head p { font-size: 16px; }
  #app-content > section { grid-area: main; min-width: 0; }

  .summary { grid-area: aside; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; position: sticky; top: 40px; align-self: start; min-width: 0; }
  .summary .ticket { max-height: calc(100dvh - 260px); overflow-x: hidden; overflow-y: auto; scrollbar-width: thin; }
  .summary-people { padding: 8px 4px 0; display: grid; gap: 12px; }
  .summary-people .section-label { margin: 0; }
  .summary-members { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
  .summary-members li { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
  .summary-members .avatar { width: 28px; height: 28px; font-size: 12px; margin: 0; border: 0; }
  .summary-members li > span:nth-child(2) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .total-wrap { display: none !important; }
  .toast, body:has(#total-bar[hidden]) .toast, body:not([data-view="app"]) .toast { bottom: 32px; }

  .composer-options { display: flex; }
  /* Con ancho de sobra, la cantidad va a la derecha del nombre en vez de debajo */
  .item-body:has(> .mini-stepper) { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 20px; align-items: center; }
  .item-body:has(> .mini-stepper) > .item-name, .item-body:has(> .mini-stepper) > .item-meta { grid-column: 1; }
  .item-body > .mini-stepper { grid-column: 2; grid-row: 1 / span 2; margin-top: 0; }
  .item { align-items: center; }
  .chips.scroll { margin: 0; padding: 0 0 2px; flex-wrap: wrap; }
  .sheet { width: 520px; }
}

@media (min-width: 1024px) and (max-width: 1239px) {
  body[data-view="app"] .app { grid-template-columns: 232px minmax(0, 1fr); }
  body[data-view="app"] .content { padding: 32px 32px 64px; }
  #app-content:not([hidden]) { grid-template-columns: minmax(0, 1fr) 300px; column-gap: 32px; }
}

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