:root {
  color-scheme: light dark;

  --fondo: #f7f2e6;
  --fondo-alto: #fffdf7;
  --superficie: #fffdf7;
  --borde: #e6dccb;
  --tinta: #241f18;
  --tenue: #7d6f5d;
  --verde: #2f6f4e;
  --verde-suave: #e4efe6;
  --naranja: #d96936;
  --sombra: 0 1px 2px rgba(60, 44, 24, 0.06), 0 8px 24px rgba(60, 44, 24, 0.06);

  --radio: 16px;
  --toque: 48px;
  --fuente: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #15120e;
    --fondo-alto: #1c1814;
    --superficie: #1f1a15;
    --borde: #332b23;
    --tinta: #f4ece0;
    --tenue: #a59684;
    --verde: #7fc79b;
    --verde-suave: #22332a;
    --naranja: #e8834f;
    --sombra: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--fondo);
  color: var(--tinta);
  font-family: var(--fuente);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  overscroll-behavior-y: none;
}

h1, h2, h3, p { margin: 0; }

button, input, select {
  font-family: inherit;
  font-size: 1rem;
  color: inherit;
}

button { cursor: pointer; }

[hidden] { display: none !important; }

.app {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
}

.pantalla { min-height: 100dvh; }

.centrada {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 28px 20px 40px;
  text-align: center;
}

.centrada h1 {
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.logo {
  font-size: 2.6rem;
  line-height: 1;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.08));
}

.tenue { color: var(--tenue); font-size: 0.95rem; line-height: 1.4; }

.tarjeta {
  width: 100%;
  max-width: 380px;
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--sombra);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
  margin-top: 8px;
}

.campo { display: flex; flex-direction: column; gap: 6px; }
.campo > span { font-size: 0.82rem; font-weight: 600; color: var(--tenue); letter-spacing: 0.01em; }

input, select {
  height: var(--toque);
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--borde);
  background: var(--fondo-alto);
  color: var(--tinta);
  font-size: 1rem;
  width: 100%;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus-visible, select:focus-visible {
  border-color: var(--verde);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--verde) 22%, transparent);
}

.ayuda { font-size: 0.8rem; color: var(--tenue); line-height: 1.45; }
.error {
  font-size: 0.85rem;
  color: #b23b2e;
  background: color-mix(in srgb, #b23b2e 10%, transparent);
  padding: 10px 12px;
  border-radius: 10px;
  line-height: 1.35;
}

.btn-principal {
  height: var(--toque);
  border: 0;
  border-radius: 12px;
  background: var(--verde);
  color: #fff;
  font-weight: 650;
  font-size: 1rem;
  width: 100%;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.btn-principal:active { transform: scale(0.985); filter: brightness(0.95); }

.btn-principal.ancho { max-width: 300px; margin-top: 6px; }

.btn-secundario {
  height: var(--toque);
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--borde);
  background: transparent;
  color: var(--tinta);
  font-weight: 600;
}

.peligro { color: #b23b2e; }

/* ---------- Lista ---------- */

.lista {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

.barra-top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: calc(16px + env(safe-area-inset-top)) 18px 12px;
  background: color-mix(in srgb, var(--fondo) 88%, transparent);
  backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid transparent;
}

.barra-texto h1 {
  font-size: 1.45rem;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.barra-texto p { margin-top: 3px; font-size: 0.85rem; }

.btn-icono {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--borde);
  background: var(--superficie);
  font-size: 1.25rem;
  line-height: 1;
  display: grid;
  place-items: center;
  color: var(--tenue);
}

.menu {
  position: absolute;
  top: calc(62px + env(safe-area-inset-top));
  right: 14px;
  z-index: 20;
  width: min(260px, calc(100vw - 28px));
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: 16px;
  box-shadow: var(--sombra);
  padding: 8px;
  display: flex;
  flex-direction: column;
}

.menu-yo {
  font-size: 0.8rem;
  color: var(--tenue);
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--borde);
  margin-bottom: 6px;
}

.menu button {
  height: 44px;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0 10px;
  border-radius: 10px;
  font-size: 0.95rem;
}

.menu button:active { background: var(--fondo); }

.miembros {
  display: flex;
  gap: 8px;
  padding: 0 18px 8px;
  flex-wrap: wrap;
}

.persona {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--tenue);
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: 999px;
  padding: 4px 10px 4px 4px;
}

.avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.68rem;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
}

.c-verde { background: #2f6f4e; }
.c-naranja { background: #d96936; }
.c-violeta { background: #7a5bd6; }
.c-celeste { background: #3c7fbf; }
.c-rosa { background: #c9538c; }
.c-amarillo { background: #b08519; }

.lista-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.grupo {
  padding: 6px 18px 0;
}

.grupo-titulo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 6px 6px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tenue);
}

.grupo-titulo .cuenta { font-weight: 600; opacity: 0.7; }

.item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: 14px;
  margin-bottom: 6px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
  overflow: hidden;
  animation: aparecer 0.18s ease;
}

@keyframes aparecer {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.check {
  flex: none;
  width: 52px;
  align-self: stretch;
  min-height: 56px;
  border: 0;
  background: transparent;
  display: grid;
  place-items: center;
}

.check .tick {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  border: 2px solid color-mix(in srgb, var(--tenue) 55%, transparent);
  display: grid;
  place-items: center;
  transition: all 0.15s ease;
  color: transparent;
  font-size: 0.9rem;
  font-weight: 800;
}

.check:active .tick { transform: scale(0.9); }

.item-txt {
  flex: 1;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 12px 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.item-nombre {
  font-size: 1.05rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.item-meta {
  font-size: 0.78rem;
  color: var(--tenue);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.punto { width: 7px; height: 7px; border-radius: 50%; flex: none; }

.btn-borrar {
  flex: none;
  width: 44px;
  align-self: stretch;
  border: 0;
  background: transparent;
  color: var(--tenue);
  font-size: 1.15rem;
  opacity: 0.55;
}

.item.comprado .item-nombre { text-decoration: line-through; color: var(--tenue); }
.item.comprado .check .tick {
  background: var(--verde);
  border-color: var(--verde);
  color: #fff;
}

.vacio {
  text-align: center;
  padding: 48px 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.vacio > div { font-size: 2rem; }

.sugerencias {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}

.chip {
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px dashed color-mix(in srgb, var(--tenue) 45%, transparent);
  background: var(--superficie);
  color: var(--tenue);
  font-size: 0.85rem;
  font-weight: 600;
}

.chip:active { background: var(--fondo-alto); color: var(--tinta); }

.comprados { padding: 8px 18px 0; }

.btn-plegable {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--borde);
  padding: 14px 6px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tenue);
}

.cuenta {
  min-width: 24px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--fondo-alto);
  border: 1px solid var(--borde);
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--tenue);
}

.comprados .lista-items { padding-top: 6px; }

/* ---------- Agregar ---------- */

.agregar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--fondo) 92%, transparent);
  backdrop-filter: blur(14px) saturate(1.2);
  border-top: 1px solid var(--borde);
  max-width: 640px;
  margin: 0 auto;
}

.agregar input {
  height: 52px;
  border-radius: 14px;
  font-size: 1.02rem;
  box-shadow: none;
}

.btn-mas {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  border: 0;
  background: var(--verde);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: transform 0.1s ease;
}

.btn-mas:active { transform: scale(0.94); }

/* ---------- Diálogo ---------- */

.dialogo {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(440px, calc(100vw - 24px));
  margin: auto;
}

.dialogo::backdrop {
  background: rgba(20, 14, 8, 0.45);
  backdrop-filter: blur(2px);
}

#form-item {
  background: var(--superficie);
  border-radius: 20px;
  padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  border: 1px solid var(--borde);
}

#form-item h2 { font-size: 1.15rem; }

.dialogo-botones { display: flex; gap: 10px; }
.dialogo-botones .btn-principal { flex: 1; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 14px;
  background: #2b2419;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.9rem;
  box-shadow: var(--sombra);
  max-width: min(90vw, 420px);
}

.toast button {
  border: 0;
  background: transparent;
  color: #ffd9a8;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 4px;
}

.aviso-offline {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #b08519;
  color: #fff;
  font-size: 0.8rem;
  text-align: center;
  padding: 8px 16px;
  line-height: 1.3;
}

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