:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #eef2ee;
  --text: #1c2620;
  --muted: #69766e;
  --line: #dfe5df;
  --accent: #1f8a5b;
  --accent-ink: #ffffff;
  --accent-soft: #dcf0e5;
  --urgent: #d0402b;
  --urgent-soft: #fbe3de;
  --warn: #c98a12;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 14px rgb(0 0 0 / .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101713; --surface: #18221c; --surface-2: #213028; --text: #e7efe9; --muted: #93a39a;
    --line: #2b3a31; --accent: #3fbf84; --accent-ink: #08130d; --accent-soft: #1d3a2b;
    --urgent: #ff7a63; --urgent-soft: #45231d; --warn: #e2a93a;
    --shadow: 0 1px 2px rgb(0 0 0 / .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101713; --surface: #18221c; --surface-2: #213028; --text: #e7efe9; --muted: #93a39a;
  --line: #2b3a31; --accent: #3fbf84; --accent-ink: #08130d; --accent-soft: #1d3a2b;
  --urgent: #ff7a63; --urgent-soft: #45231d; --warn: #e2a93a;
  --shadow: 0 1px 2px rgb(0 0 0 / .4); color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
#app { max-width: 640px; margin: 0 auto; padding: 0 16px 96px; }
.splash { display: grid; place-items: center; height: 80dvh; font-size: 64px; opacity: .5; }

/* Cabecera */
.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  margin: 0 -16px; padding: 10px 16px 8px; display: flex; align-items: center; gap: 8px;
}
.top h1 { font-size: 22px; margin: 0; flex: 1; min-width: 0; }
.top h1 button { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }
.top h1 span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top h1 small { font-size: 14px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; transition: background .3s; }
.dot.pending { background: var(--warn); }
.dot.offline { background: var(--muted); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent;
  display: grid; place-items: center; font-size: 22px; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }

/* Buscador / añadir */
.add { position: relative; margin: 2px 0 14px; }
.add input {
  width: 100%; height: 50px; border-radius: var(--radius); border: 1.5px solid var(--line);
  background: var(--surface); padding: 0 16px 0 44px; font-size: 17px; outline: none; box-shadow: var(--shadow);
}
.add input:focus { border-color: var(--accent); }
.add::before { content: "＋"; position: absolute; left: 16px; top: 13px; font-size: 19px; color: var(--accent); font-weight: 700; }
.sugs {
  list-style: none; margin: 6px 0 0; padding: 6px; position: absolute; left: 0; right: 0; z-index: 6;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: 60dvh; overflow: auto;
}
.sugs li { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; cursor: pointer; }
.sugs li.sel, .sugs li:active { background: var(--surface-2); }
.sugs .ico { font-size: 20px; width: 26px; text-align: center; }
.sugs .tag { margin-left: auto; font-size: 12px; color: var(--muted); }

/* Secciones */
section.cat { margin-bottom: 14px; }
section.cat h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  margin: 0 4px 6px; display: flex; gap: 6px; align-items: center; font-weight: 600;
}
ul.items { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item {
  position: relative; overflow: hidden; border-top: 1px solid var(--line);
  cursor: pointer; user-select: none; touch-action: pan-y;
}
.item .row {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 6px 10px 14px; min-height: 56px;
  background: var(--surface); transition: opacity .25s;
}
.item:first-child { border-top: 0; }
.item:active .row { background: var(--surface-2); }
.item.swiping .row { background: var(--surface); }
.swipe-bg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: flex-end; padding: 0 20px;
  background: color-mix(in srgb, var(--urgent) 70%, var(--surface)); color: #fff; font-weight: 700; font-size: 15px;
  transition: background .15s;
}
.item.to-right .swipe-bg { justify-content: flex-start; }
.item.armed .swipe-bg { background: var(--urgent); }
.item:not(.swiping) .swipe-bg { visibility: hidden; }
.item .ico { font-size: 24px; width: 30px; text-align: center; flex: none; }
.item .txt { flex: 1; min-width: 0; }
.item .txt b { font-weight: 550; display: block; overflow-wrap: anywhere; }
.item .txt small { color: var(--muted); display: block; overflow-wrap: anywhere; }
.item.urgent .txt b { color: var(--urgent); }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--urgent-soft); color: var(--urgent); flex: none; }
.who {
  width: 24px; height: 24px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #fff;
}
.item .icon-btn { color: var(--muted); font-size: 20px; flex: none; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px 24px; }
.empty .big { font-size: 48px; display: block; margin-bottom: 6px; }

/* Recientes */
.recent h2 { justify-content: space-between; }
.recent h2 button { all: unset; cursor: pointer; color: var(--accent); text-transform: none; letter-spacing: 0; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 7px 12px 7px 9px;
  display: inline-flex; align-items: center; gap: 6px; font-size: 15px;
}
.chip:active { background: var(--accent-soft); }
.chips.editing .chip { border-color: var(--urgent); }
.chips.editing .chip::after { content: "✕"; color: var(--urgent); font-size: 12px; margin-left: 2px; }
.more { all: unset; cursor: pointer; color: var(--accent); font-size: 14px; padding: 8px 4px; }

/* Botones y formularios */
.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600; background: var(--accent); color: var(--accent-ink);
  min-height: 46px;
}
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--urgent); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; }
label.field { display: block; margin: 0 0 14px; }
label.field span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 5px; }
.field input, .field select {
  width: 100%; height: 48px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface);
  padding: 0 14px; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; }
.check input { width: 22px; height: 22px; accent-color: var(--urgent); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.error { color: var(--urgent); font-size: 14px; min-height: 20px; margin: 4px 0 8px; }
.hint { color: var(--muted); font-size: 14px; }

/* Pantallas de acceso */
.auth { max-width: 380px; margin: 0 auto; padding-top: 12dvh; }
.auth .logo { font-size: 56px; }
.auth h1 { margin: 6px 0 4px; font-size: 26px; }
.auth p { color: var(--muted); margin: 0 0 22px; }
.code-input { letter-spacing: 8px; text-align: center; font-size: 26px !important; font-weight: 700; }

/* Hoja inferior */
dialog#sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px; max-height: 88dvh;
  background: var(--surface); color: var(--text); border-radius: 20px 20px 0 0;
}
dialog#sheet::backdrop { background: rgb(0 0 0 / .4); }
dialog#sheet[open] { animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.sheet-body { padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); }
.sheet-body h3 { margin: 0 0 14px; font-size: 19px; display: flex; align-items: center; gap: 8px; }
.sheet-body h4 { margin: 18px 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.menu { list-style: none; margin: 0; padding: 0; }
.menu li > button {
  all: unset; box-sizing: border-box; cursor: pointer; width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 12px 6px; border-radius: 10px; min-height: 46px;
}
.menu li > button:active { background: var(--surface-2); }
.menu .on { color: var(--accent); font-weight: 600; }
.menu .meta { margin-left: auto; color: var(--muted); font-size: 14px; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 9px; }
.seg button.on { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
.order li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.order li span.n { flex: 1; }
.order .icon-btn { width: 38px; height: 38px; font-size: 18px; }
.order .icon-btn:disabled { opacity: .25; }
.members { display: flex; flex-direction: column; gap: 8px; }
.members div { display: flex; align-items: center; gap: 10px; }
.share-box { display: flex; gap: 8px; margin-top: 8px; }
.share-box input { flex: 1; min-width: 0; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 10px; font-size: 13px; }

/* Aviso inferior */
#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 140%);
  background: #1c2620; color: #fff; border-radius: 12px; padding: 10px 10px 10px 16px; display: flex; gap: 12px; align-items: center;
  box-shadow: 0 6px 24px rgb(0 0 0 / .25); transition: transform .25s; z-index: 20; max-width: calc(100% - 32px); font-size: 15px;
}
#toast.show { transform: translate(-50%, 0); }
#toast button { border: 0; background: transparent; color: #7fe0b0; font-weight: 700; padding: 6px 8px; }
#toast:empty { display: none; }

/* Aviso de instalación */
.install {
  display: flex; align-items: center; gap: 12px; background: var(--accent-soft); border-radius: var(--radius);
  padding: 10px 6px 10px 12px; margin: 0 0 12px;
}
.install img { border-radius: 10px; flex: none; }
.install div { flex: 1; min-width: 0; }
.install b { display: block; }
.install small { display: block; color: var(--muted); font-size: 13px; }
.install .btn { min-height: 38px; padding: 8px 14px; }
.install .icon-btn { width: 32px; height: 32px; font-size: 15px; color: var(--muted); }
.steps { padding-left: 22px; margin: 0 0 14px; }
.steps li { margin: 0 0 10px; }
.kbd { display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 4px; border-radius: 6px; background: var(--surface-2); vertical-align: middle; color: var(--accent); }

/* Voy al súper */
.shopgo { margin: -4px 0 14px; }
.shopbar {
  display: flex; align-items: center; gap: 10px; margin: -4px 0 14px; padding: 10px 10px 10px 14px;
  border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--line);
}
.shopbar.me { background: var(--accent-soft); border-color: transparent; }
.shopbar > span { flex: 1; min-width: 0; }
.shopbar small { display: block; color: var(--muted); font-size: 13px; }
.shopbar .btn { min-height: 40px; padding: 8px 14px; flex: none; }

/* Historial */
dialog#sheet { overflow-y: auto; }
.logrow { display: flex; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 15px; align-items: baseline; }
.logrow time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; flex: none; width: 42px; }
.logrow .who { display: inline-grid; width: 20px; height: 20px; font-size: 11px; vertical-align: -3px; margin-right: 4px; }

/* Casilla de comprado */
.chk {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--muted) 55%, transparent); flex: none;
  display: grid; place-items: center; transition: background .2s, border-color .2s; margin-right: -2px;
}
.item:hover .chk { border-color: var(--accent); }
.item.done .chk { background: var(--accent); border-color: var(--accent); }
.item.done .chk::after {
  content: ""; width: 7px; height: 12px; border: solid var(--accent-ink); border-width: 0 2.5px 2.5px 0;
  transform: translate(0, -1px) rotate(45deg);
}
.item.done .txt b { text-decoration: line-through; color: var(--muted); font-weight: 450; }
.item.done .ico { opacity: .45; }
.item.done .who { opacity: .6; }
.item.moving .row { opacity: .35; }
.basket .item .row { background: var(--bg); }
.basket h2 { justify-content: space-between; }
.basket h2 button { all: unset; cursor: pointer; color: var(--accent); text-transform: none; letter-spacing: 0; font-size: 13px; }
.basket ul.items { box-shadow: none; border: 1px solid var(--line); background: transparent; }
