:root {
  --green: #1f4d3a;
  --green-2: #2f6b52;
  --red: #b3261e;
  --gold: #d9a441;
  --bg: #f6f3ee;
  --card: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6a66;
  --line: #e4dfd6;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* Cabecera */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--green); color: #fff;
}
.top h1 { flex: 1; margin: 0; font-size: 1.2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: #fff; font-size: 2rem; line-height: 1; padding: 0 8px 4px 0; }
.sync-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; background: #999; padding: 0; }
.sync-dot.ok { background: #5fd38d; }
.sync-dot.busy { background: var(--gold); }
.sync-dot.error { background: #ff6b6b; }

main { padding: 12px; max-width: 760px; margin: 0 auto; }

/* Barra inferior */
.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom button { background: none; border: 0; padding: 8px 0 10px; font-size: .75rem; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.bottom button span { font-size: 1.35rem; filter: grayscale(1); opacity: .7; }
.bottom button.active { color: var(--green); font-weight: 600; }
.bottom button.active span { filter: none; opacity: 1; }

.fab {
  position: fixed; right: 18px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 6;
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--red); color: #fff; font-size: 2rem; line-height: 1;
  box-shadow: 0 6px 16px rgba(0,0,0,.25);
}

/* Tarjetas y listas */
.card { background: var(--card); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-size: .85rem; }
.small { font-size: .8rem; }
.title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clickable { cursor: pointer; }
h2 { font-size: 1rem; margin: 18px 4px 8px; color: var(--green); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty b { display: block; font-size: 2.5rem; margin-bottom: 8px; }

.avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 1.1rem; }
.avatar.big { width: 84px; height: 84px; font-size: 1.8rem; }
.thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; flex: none; background: #efe9df; display: grid; place-items: center; font-size: 1.6rem; }

.bar { height: 8px; background: #ece6dc; border-radius: 4px; overflow: hidden; margin-top: 6px; }
.bar { display: flex; }
.bar > i { display: block; height: 100%; background: var(--green-2); }
.bar > i.ideas { background: repeating-linear-gradient(45deg, #c9d8cf 0 4px, #e6eee9 4px 8px); }
.bar.over > i { background: var(--red); }

.chip { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 3px 10px; font-size: .78rem; border: 1px solid var(--line); background: #fff; white-space: nowrap; }
button.chip { cursor: pointer; }
.chip.on { background: var(--green); border-color: var(--green); color: #fff; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; }
.st-idea { background: #fff7e0; border-color: #f0dca0; }
.st-pedido { background: #e8f0ff; border-color: #bcd0f5; }
.st-casa { background: #e6f5ec; border-color: #b4dcc3; }
.st-envuelto { background: #fde8e6; border-color: #f2bcb6; }
.st-entregado { background: #eee; border-color: #ddd; color: #777; }
.giver { background: #f3ecff; border-color: #d9c8f5; }

.search { width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; margin-bottom: 8px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: #fff; border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 1.25rem; }

.letters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.letters .thumb { width: 72px; height: 92px; cursor: pointer; }
.letter-text { width: 72px; height: 92px; border-radius: 10px; background: #fffbe9; border: 1px solid #efe2b0; font-size: .65rem; padding: 6px; overflow: hidden; flex: none; cursor: pointer; }

/* Botones */
.btn { border: 0; border-radius: 12px; padding: 11px 16px; background: var(--green); color: #fff; font-weight: 600; }
.btn.secondary { background: #fff; color: var(--green); border: 1px solid var(--green); }
.btn.danger { background: #fff; color: var(--red); border: 1px solid var(--red); }
.btn.small { padding: 7px 12px; font-size: .85rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-row .btn { flex: 1; }

/* Hoja de formulario */
dialog#sheet {
  border: 0; padding: 0; margin: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%;
  background: var(--bg);
}
dialog#sheet::backdrop { background: rgba(0,0,0,.4); }
@media (min-width: 700px) {
  dialog#sheet { margin: auto; max-width: 560px; height: auto; max-height: 90vh; border-radius: 18px; }
}
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 10px; padding: calc(12px + env(safe-area-inset-top)) 14px 12px; background: var(--green); color: #fff; }
.sheet-head h3 { flex: 1; margin: 0; font-size: 1.1rem; }
.sheet-head button { background: none; border: 0; color: #fff; font-weight: 600; font-size: 1rem; }
/* Margen abajo amplio para que los botones de navegación de Android no tapen los últimos botones */
.sheet-content { padding: 14px 14px calc(110px + env(safe-area-inset-bottom)); }

label.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 4px; }
.field input:not([type=checkbox]), .field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: #fff;
}
.field textarea { min-height: 70px; resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.check input { width: 22px; height: 22px; }

.photo-pick { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.photo-pick img, .photo-pick .ph { width: 96px; height: 96px; border-radius: 12px; object-fit: cover; background: #efe9df; display: grid; place-items: center; font-size: 2rem; }
.photo-pick.round img, .photo-pick.round .ph { border-radius: 50%; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg label { flex: 1; }
.seg input { display: none; }
.seg span { display: block; text-align: center; padding: 9px 6px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: .85rem; }
.seg input:checked + span { background: var(--green); color: #fff; border-color: var(--green); }

.link-row { display: flex; gap: 6px; margin-bottom: 6px; }
.link-row input { flex: 1; }
.link-row button { border: 1px solid var(--line); background: #fff; border-radius: 10px; width: 42px; }
a.link { display: block; color: var(--green-2); word-break: break-all; margin: 4px 0; }

.big-img { width: 100%; border-radius: 12px; }

/* Bloqueo */
dialog.lock-dialog, dialog.pin-dialog { border: 0; padding: 0; margin: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%; background: var(--bg); }
dialog.lock-dialog { background: var(--green); color: #fff; }
dialog.lock-dialog .muted { color: #d6e4dc; }
dialog.lock-dialog::backdrop { background: var(--green); }
.lock-box { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 80%; padding: 30px 20px; text-align: center; }
.lock-box h2 { color: inherit; font-size: 1.6rem; margin: 10px 0 4px; }
.lock-logo { width: 84px; height: 84px; border-radius: 20px; }
dialog.lock-dialog .link { color: #fff; text-decoration: underline; }
dialog.lock-dialog .btn { background: #fff; color: var(--green); }
.pin-dots { display: flex; gap: 14px; margin: 22px 0 8px; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; }
.pin-dots i.on { background: currentColor; }
.pin-dots.wrong { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pin-msg { min-height: 1.2em; margin-bottom: 10px; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 72px); gap: 14px; }
.pin-pad button { width: 72px; height: 72px; border-radius: 50%; border: 0; font-size: 1.6rem; background: rgba(255,255,255,.15); color: inherit; }
dialog.pin-dialog .pin-pad button { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
/* Al salir de la app, el contenido se difumina (para la vista de apps abiertas) */
body.privacy > main, body.privacy > header { filter: blur(18px); }

/* Selector de dibujos */
dialog.icon-dialog { border: 0; padding: 0; margin: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%; background: var(--bg); }
@media (min-width: 700px) { dialog.icon-dialog { margin: auto; max-width: 560px; height: auto; max-height: 90vh; border-radius: 18px; } }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.icon-cell { border: 0; border-radius: 14px; aspect-ratio: 1; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px; }
.icon-cell span { font-size: 2.3rem; line-height: 1; }
.icon-cell small { font-size: .68rem; font-weight: 600; text-align: center; line-height: 1.1; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + env(safe-area-inset-bottom)); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: 90vw; font-size: .9rem; }

.money-line { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.money-line:last-child { border-bottom: 0; }
/* El teclado del PIN siempre centrado */
#lockPad { display: flex; flex-direction: column; align-items: center; }
