:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1c2733;
  --muted: #6b7a8c;
  --accent: #e11d48;
  --accent-soft: #fde7ec;
  --danger: #dc2626;
  --border: #e3e8ee;
  --shadow: 0 1px 3px rgba(20, 35, 50, .08);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c;
    --card: #1a222b;
    --text: #e8edf2;
    --muted: #8b9aab;
    --accent: #fb7185;
    --accent-soft: #3b1721;
    --border: #2a3542;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
}

body {
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

/* ----- Cabecera ----- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 6px;
}
.topbar h1 { margin: 0; font-size: 1.35rem; }
.icon-btn {
  background: none;
  border: none;
  font-size: 1.35rem;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
}
.icon-btn:active { background: var(--border); }

/* ----- Pestañas de personas ----- */
.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 16px 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px 7px 9px;
  font-size: .92rem;
  cursor: pointer;
  white-space: nowrap;
}
.tab .ava {
  width: 24px; height: 24px; line-height: 24px;
  text-align: center; border-radius: 50%; font-size: .95rem;
  background: var(--bg);
}
.tab.active { color: #fff; }
.tab.active .ava { background: rgba(255, 255, 255, .25); }
.tab .count {
  background: rgba(127, 127, 127, .18);
  border-radius: 999px;
  font-size: .75rem;
  padding: 1px 7px;
}
.tab.active .count { background: rgba(255, 255, 255, .25); }
.tab.me-tab { font-weight: 600; }

/* ----- Cabecera de la lista (contexto + compartir) ----- */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 18px 10px;
}
.list-header #listHeaderText { font-size: .9rem; color: var(--muted); font-weight: 600; }
.chip-btn {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--accent);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
}

/* ----- Lista ----- */
.list { padding: 0 16px; }

.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 4px 8px;
  font-size: .85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}

.gift-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  cursor: pointer;
}
.gift-item .emoji {
  flex: 0 0 38px; width: 38px; height: 38px; line-height: 38px;
  text-align: center; font-size: 20px;
  background: var(--accent-soft); border-radius: 11px;
}
.gift-item .body { flex: 1; min-width: 0; }
.gift-item .name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gift-item .meta { display: block; font-size: .78rem; color: var(--muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gift-item .price {
  flex: 0 0 auto; font-size: .8rem; color: var(--muted);
  background: var(--bg); border-radius: 8px; padding: 3px 8px; white-space: nowrap;
}
.gift-item.gifted { opacity: .58; }
.gift-item.gifted .name { text-decoration: line-through; }
.gift-item.reserved { border-color: rgba(245, 158, 11, .5); }
.gift-item .tag {
  flex: 0 0 auto; font-size: 1.1rem;
}

.empty {
  text-align: center;
  color: var(--muted);
  margin: 56px 20px;
  line-height: 1.6;
}
.empty .big { font-size: 3rem; display: block; margin-bottom: 8px; }

/* ----- Barra inferior: añadir ----- */
.addbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 640px;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--border);
}
.btn-add-big {
  width: 100%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: 12px;
  padding: 15px;
  cursor: pointer;
}
.btn-add-big:active { filter: brightness(.95); }

/* ----- Aviso sin conexión ----- */
.offline {
  position: fixed;
  bottom: calc(94px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  font-size: .85rem;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}

/* ----- Modales ----- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 20, .55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
@media (min-width: 480px) { .overlay { align-items: center; } }
.modal {
  background: var(--card);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 480px) { .modal { border-radius: 18px; } }
.modal h2 { margin: 0 0 10px; font-size: 1.15rem; }
.modal h3 { margin: 18px 0 8px; font-size: .95rem; }
.modal section { border-top: 1px solid var(--border); }
.modal section:first-of-type { border-top: none; }
.modal label { display: block; margin: 12px 0 4px; font-size: .88rem; color: var(--muted); }
.modal input[type="text"],
.modal input[type="url"],
.modal input[type="password"],
.modal textarea,
.modal select {
  display: block;
  width: 100%;
  margin-top: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: 12px;
  font-size: .98rem;
  font-family: inherit;
}
.modal textarea { resize: vertical; }
.modal .row { display: flex; gap: 8px; margin: 8px 0; align-items: center; }
.modal .row input, .modal .row select { flex: 1; margin-top: 0; }
.modal .row .btn { flex: 0 0 auto; }
.modal-actions { display: flex; gap: 8px; margin-top: 18px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: .88rem; }
.small { font-size: .78rem; }
.center { text-align: center; }
.modal label small { color: var(--muted); font-weight: 400; }

.btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 16px;
  font-size: .92rem;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: none; border-color: var(--danger); color: var(--danger); }
.btn.full { width: 100%; display: block; text-align: center; text-decoration: none; margin-top: 10px; }
.big-touch { padding: 15px; font-size: 1.02rem; }

/* ----- Ficha de regalo ----- */
.detail-price { font-weight: 600; color: var(--accent); margin: 2px 0 6px; }
.detail-desc { white-space: pre-wrap; color: var(--text); margin: 6px 0; }

/* ----- Acceso ----- */
.modal.auth { max-width: 380px; }
.auth-logo {
  font-size: 3rem;
  text-align: center;
  background: var(--accent-soft);
  width: 84px; height: 84px; line-height: 84px;
  border-radius: 24px;
  margin: 4px auto 10px;
}
.auth-title { text-align: center; margin: 0; }
.sep { color: var(--muted); margin: 14px 0; position: relative; }
.full { width: 100%; }
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: .95rem;
  cursor: pointer;
  padding: 8px;
  text-decoration: underline;
}
.form-error {
  background: rgba(220, 38, 38, .12);
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 10px 0;
  font-size: .88rem;
}

/* Emoji y color pickers */
.emoji-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.emoji-opt {
  width: 42px; height: 42px; font-size: 20px;
  border: 1px solid var(--border); background: var(--bg);
  border-radius: 11px; cursor: pointer;
}
.emoji-opt.selected { border-color: var(--accent); background: var(--accent-soft); }
.colors { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.color-swatch {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid transparent; cursor: pointer; padding: 0;
}
.color-swatch.selected { border-color: var(--text); }

/* Lista de personas para enlazar móvil */
.relink-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.relink-opt {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border); background: var(--bg);
  border-radius: 12px; padding: 12px; cursor: pointer; text-align: left; width: 100%;
  color: var(--text); font-size: 1rem;
}
.relink-opt .ava {
  width: 34px; height: 34px; line-height: 34px; text-align: center;
  border-radius: 50%; font-size: 1.1rem; background: var(--card);
}
.relink-opt.selected { border-color: var(--accent); background: var(--accent-soft); }

/* Chips de precio */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; }
.chip {
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 999px; padding: 7px 13px; font-size: .85rem; cursor: pointer;
}
.chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Compartir */
.share-box { margin: 12px 0; }
.share-box input {
  width: 100%; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 10px; padding: 12px; font-size: .85rem;
}

/* Foto del regalo */
.photo-field { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.photo-preview { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
.gift-item .thumb { flex: 0 0 38px; width: 38px; height: 38px; object-fit: cover; border-radius: 11px; }
.detail-photo { width: 100%; max-height: 280px; object-fit: cover; border-radius: 12px; margin: 6px 0 10px; display: block; }

/* Lista de familia (ajustes) */
.super-list { list-style: none; margin: 0 0 12px; padding: 0; }
.super-list li { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--border); }
.super-list .ava { width: 30px; height: 30px; line-height: 30px; text-align: center; border-radius: 50%; flex: 0 0 auto; }
.super-list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.super-list .pending { flex: 0 0 auto; font-size: .68rem; color: var(--muted); background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px; }
.super-list button { background: none; border: none; font-size: 1rem; cursor: pointer; padding: 4px; }

/* Campo de PIN (grande y centrado) */
.pin-input { text-align: center; letter-spacing: .55em; font-size: 1.35rem; padding-left: .55em; }
.pin-block { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 12px; }

/* Etiqueta en "elige tu nombre" (acceso) */
.relink-opt .tag { margin-left: auto; font-size: .7rem; color: var(--muted); background: var(--card); border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px; }
.relink-opt.claimed .tag { color: var(--accent); border-color: var(--accent); }

/* Selector de prioridad (modal de regalo) */
.prio-select { display: flex; gap: 8px; margin-top: 4px; }
.prio-select .prio-opt {
  flex: 1; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 10px; padding: 10px 6px; font-size: .85rem; cursor: pointer; white-space: nowrap;
}
.prio-select .prio-opt.sel { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* Prioridad en la tarjeta del regalo */
.gift-item.prio-high { border-color: rgba(225, 29, 72, .45); }
.gift-item.prio-high .name { font-weight: 700; }
.gift-item.prio-low { opacity: .7; }
.gift-item .name .prio { margin-right: 2px; }

/* ----- Gestos: deslizar para regalar/borrar ----- */
.item-wrap {
  position: relative;
  margin-bottom: 8px;
  border-radius: var(--radius);
  overflow: hidden;
}
.item-wrap .gift-item {
  position: relative;
  z-index: 1;
  margin-bottom: 0;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.gift-item.snapping { transition: transform .2s ease; }
.item-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 22px;
  font-weight: 600;
  font-size: .95rem;
  opacity: 0;
}
.item-bg-gift   { background: #16a34a; justify-content: flex-start; }       /* derecha → regalado */
.item-bg-delete { background: var(--danger); justify-content: flex-end; }   /* izquierda → borrar */
.item-wrap.dir-right .item-bg-gift   { opacity: 1; }
.item-wrap.dir-left  .item-bg-delete { opacity: 1; }
.item-wrap.will-act.dir-right .item-bg-gift   { background: #15803d; }
.item-wrap.will-act.dir-left  .item-bg-delete { background: #b91c1c; }

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(100px + env(safe-area-inset-bottom));
  z-index: 130;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 92%;
  background: #1f2937;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  font-size: .9rem;
}
.toast-action {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: #fb7185;
  font-weight: 700;
  font-size: .9rem;
  cursor: pointer;
  padding: 2px 4px;
}

.version {
  text-align: center;
  color: var(--muted);
  font-size: .72rem;
  letter-spacing: .02em;
  margin: 16px 0 2px;
  opacity: .7;
}

hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ===== Escritorio (>768px): filtros a la izquierda, regalos a la derecha ===== */
@media (min-width: 768px) {
  body { max-width: 1040px; padding-bottom: 24px; }

  .layout {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    padding: 0 16px;
  }

  /* Filtros (personas) como columna vertical fija */
  #tabs {
    flex: 0 0 250px;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    overflow: visible;
    padding: 0;
    position: sticky;
    top: 12px;
  }
  #tabs .tab { width: 100%; justify-content: flex-start; padding: 11px 14px; }
  #tabs .tab .count { margin-left: auto; }

  /* Columna de regalos */
  .content { flex: 1; min-width: 0; }
  .list { padding: 0; }
  .list-header { padding: 2px 2px 12px; }

  /* Barra de añadir: pegada abajo dentro de la columna derecha (ya no fija a pantalla completa) */
  .addbar {
    position: sticky;
    bottom: 0;
    left: auto;
    transform: none;
    width: auto;
    max-width: none;
    margin: 0;
    padding: 12px 0 4px;
    background: var(--bg);
    border-top: none;
  }
}

.hidden { display: none !important; }
