/* ===== Lista de la compra — estilos ===== */
:root {
  --green: #16a34a;
  --green-dark: #15803d;
  --green-light: #dcfce7;
  --bg: #f6f8f7;
  --surface: #ffffff;
  --text: #1a202c;
  --text-soft: #64748b;
  --border: #e5e7eb;
  --danger: #dc2626;
  --radius: 16px;
  --shadow: 0 4px 16px rgba(0,0,0,.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: none;
  min-height: 100dvh;
}

.screen { min-height: 100dvh; }
.hidden { display: none !important; }

/* ===== Pantalla "quien eres" ===== */
#screen-who {
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #f0fdf4 0%, var(--bg) 60%);
}
.who-wrap { width: 100%; max-width: 420px; text-align: center; }
.app-logo { font-size: 56px; line-height: 1; margin: 8px 0 4px; }
.app-title { font-size: 26px; margin: 6px 0 2px; color: var(--green-dark); }
.app-sub { color: var(--text-soft); margin: 4px 0 20px; font-size: 15px; }

.member-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
  margin-bottom: 16px;
}
.member-card {
  background: var(--surface); border: 2px solid transparent;
  border-radius: var(--radius); padding: 18px 10px 14px;
  box-shadow: var(--shadow); cursor: pointer; transition: transform .08s ease, border-color .15s ease;
  user-select: none;
}
.member-card:active { transform: scale(.96); }
.member-card.selected { border-color: var(--green); }
.avatar {
  width: 64px; height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 26px; font-weight: 700; margin: 0 auto 8px;
  box-shadow: inset 0 -3px 6px rgba(0,0,0,.18);
}
.member-card .mname { font-weight: 600; font-size: 15px; }

.btn-ghost {
  background: transparent; border: 1px dashed var(--text-soft);
  color: var(--text-soft); padding: 8px 16px; border-radius: 12px;
  font-size: 14px; cursor: pointer;
}
.btn-primary {
  background: var(--green); color: #fff; border: none; border-radius: 12px;
  padding: 10px 18px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-primary:active { transform: scale(.97); }

.add-member-form {
  display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap;
}
.add-member-form input[type="text"] {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 12px; font-size: 15px; width: 160px;
}
.add-member-form input[type="color"] { width: 44px; height: 40px; border: none; border-radius: 10px; padding: 2px; }

/* ===== Pantalla PIN ===== */
#screen-pin { display: flex; align-items: center; justify-content: center; padding: 24px; }
.pin-dots { display: flex; justify-content: center; gap: 16px; margin: 18px 0 6px; }
.pin-dots span {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--text-soft);
  transition: all .15s ease; background: transparent;
}
.pin-dots span.filled { background: var(--green); border-color: var(--green); transform: scale(1.15); }
.pin-error { color: var(--danger); font-size: 14px; margin: 6px 0 0; min-height: 20px; }
.pin-pad {
  display: grid; grid-template-columns: repeat(3, 76px); gap: 12px;
  justify-content: center; margin-top: 14px;
}
.pin-pad button {
  height: 64px; border-radius: 20px; border: none; background: var(--surface);
  box-shadow: var(--shadow); font-size: 24px; font-weight: 600; color: var(--text);
  cursor: pointer; user-select: none;
}
.pin-pad button:active { transform: scale(.93); background: var(--green-light); }
.pin-pad .pin-blank { background: transparent; box-shadow: none; cursor: default; }
.pin-pad .pin-blank:active { transform: none; background: transparent; }

/* ===== Topbar ===== */
#screen-list { display: flex; flex-direction: column; max-width: 640px; margin: 0 auto; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-titles h1 { font-size: 19px; margin: 0; color: var(--green-dark); }
.done-counter { font-size: 12.5px; color: var(--text-soft); }
.avatar-mini {
  width: 42px; height: 42px; border-radius: 50%; border: 2px solid var(--surface);
  color: #fff; font-weight: 700; font-size: 17px; cursor: pointer;
  box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.icon-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 50%;
  width: 42px; height: 42px; font-size: 19px; cursor: pointer; box-shadow: var(--shadow);
}
.icon-btn:active { transform: scale(.94); }

#connection-dot {
  position: fixed; top: 8px; right: 12px; z-index: 30;
  width: 10px; height: 10px; border-radius: 50%;
}
.conn-ok { background: var(--green); }
.conn-err { background: var(--danger); }
.conn-wait { background: #f59e0b; }

/* ===== Añadir ===== */
.list-main { padding: 4px 16px calc(90px + env(safe-area-inset-bottom)); }
.add-row { display: flex; gap: 10px; margin: 6px 0 8px; align-items: center; }
.add-row input {
  flex: 1; padding: 13px 16px; border: 1.5px solid var(--border); border-radius: 14px;
  font-size: 16px; background: var(--surface); color: var(--text); outline: none; min-width: 0;
}
.add-row input:focus { border-color: var(--green); }

.btn-mic {
  width: 50px; height: 50px; border-radius: 50%; border: none; flex: none;
  background: var(--surface); box-shadow: var(--shadow); font-size: 21px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform .1s ease;
}
.btn-mic:active { transform: scale(.92); }
.btn-mic.recording {
  background: var(--danger); animation: micPulse 1s ease infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .5); }
  50% { box-shadow: 0 0 0 12px rgba(220, 38, 38, 0); }
}
.btn-mic.unsupported { opacity: .55; }
.btn-primary.round {
  width: 50px; height: 50px; border-radius: 50%; font-size: 24px; line-height: 1;
  display: flex; align-items: center; justify-content: center; padding: 0; flex: none;
}

.suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-soft);
  padding: 5px 11px; border-radius: 999px; font-size: 13px; cursor: pointer;
  transition: all .12s ease;
}
.chip:active { background: var(--green-light); }
.chip:hover { border-color: var(--green); color: var(--green-dark); }

/* ===== Items ===== */
.items-list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-radius: var(--radius);
  padding: 11px 14px; box-shadow: var(--shadow);
  animation: pop .18s ease;
  cursor: pointer; user-select: none;
}
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(4px); } }
.item.done-anim { animation: doneOut .4s ease forwards; }
@keyframes doneOut { to { opacity: 0; transform: translateX(60px) scale(.9); } }
.item .check {
  width: 30px; height: 30px; border-radius: 10px; flex: none;
  border: 2px solid var(--border); display: flex; align-items: center; justify-content: center;
  font-size: 17px; color: transparent; transition: all .15s ease; background: var(--bg);
}
.item .check.checked { background: var(--green); border-color: var(--green); color: #fff; }
.item .item-body { flex: 1; min-width: 0; }
.item .item-text { font-size: 16.5px; font-weight: 500; word-break: break-word; }
.item .item-meta {
  font-size: 12px; color: var(--text-soft); margin-top: 2px;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.item .cat { opacity: .85; }
.item .added-dot {
  display: inline-flex; align-items: center; gap: 4px;
}
.mini-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.item .btn-del {
  background: none; border: none; color: var(--text-soft); font-size: 17px;
  cursor: pointer; padding: 6px; opacity: .7; flex: none;
}
.item .btn-del:active { color: var(--danger); opacity: 1; }

/* ===== Vacio ===== */
.empty-state { text-align: center; padding: 48px 0; color: var(--text-soft); }
.empty-emoji { font-size: 52px; margin-bottom: 8px; }

/* ===== Historial ===== */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 640px;
  border-radius: 20px 20px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 75dvh; display: flex; flex-direction: column;
  animation: sheetUp .22s ease;
}
@keyframes sheetUp { from { transform: translateY(100%); } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sheet-head h2 { margin: 0; font-size: 18px; color: var(--green-dark); }
.history-list { overflow-y: auto; }
.history-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 4px;
  border-bottom: 1px solid var(--border); font-size: 14.5px;
}
.history-item .strike { text-decoration: line-through; color: var(--text-soft); }
.history-item .htime { margin-left: auto; color: var(--text-soft); font-size: 12px; flex: none; }
.history-item .btn-undo {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  font-size: 15px; cursor: pointer; padding: 3px 7px; flex: none;
}
.history-empty { color: var(--text-soft); text-align: center; padding: 24px 0; font-size: 14px; }

/* ===== Ajustes ===== */
.settings-body { padding: 0 4px; }
.settings-body label { display: block; font-size: 13px; color: var(--text-soft); margin: 12px 0 4px; }
.settings-body input {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: 12px;
  font-size: 18px; letter-spacing: 6px; text-align: center; background: var(--bg); color: var(--text);
  outline: none;
}
.settings-body input:focus { border-color: var(--green); }
.settings-who { font-size: 15px; color: var(--text-soft); margin: 0 0 6px; }
.btn-primary.wide { width: 100%; margin-top: 16px; padding: 13px; }
.btn-danger-link {
  background: none; border: none; color: var(--danger); font-size: 14px; cursor: pointer;
  margin-top: 14px; width: 100%; padding: 6px; opacity: .85; text-decoration: underline;
}
.btn-danger-link:active { opacity: 1; }

/* ===== Pie (idioma) ===== */
.langbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 15;
  display: flex; justify-content: center; align-items: center; gap: 6px;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
}
.lang-btn { background: none; border: none; color: var(--text-soft); font-size: 12.5px; cursor: pointer; padding: 4px 6px; }
.lang-btn.active { color: var(--green); font-weight: 700; }
.lang-sep { color: var(--border); }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.25); white-space: nowrap;
  animation: toastIn .2s ease; max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } }

/* ===== Modo oscuro ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1410; --surface: #1a211c; --text: #e8ede9;
    --text-soft: #9aa8a0; --border: #2a342c;
    --green-light: #1c3a26;
    --shadow: 0 4px 16px rgba(0,0,0,.35);
  }
  #screen-who { background: linear-gradient(160deg, #122015 0%, var(--bg) 60%); }
  .app-title, .topbar-titles h1, .sheet-head h2 { color: #4ade80; }
  .add-row input { color: var(--text); }
  .item .check { background: var(--surface); }
}

/* Ajustes escritorio: centrar contenido */
@media (min-width: 641px) {
  .list-main { padding-left: 20px; padding-right: 20px; }
}
