/* ---- Reset y base --------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f172a;            /* slate-900 */
  --surface: #1e293b;       /* slate-800 */
  --surface-2: #0f172a99;   /* slate-900 60% */
  --border: #334155;        /* slate-700 */
  --border-soft: #475569;   /* slate-600 */
  --text: #f1f5f9;          /* slate-100 */
  --text-dim: #cbd5e1;      /* slate-300 */
  --muted: #94a3b8;         /* slate-400 */
  --muted-2: #64748b;       /* slate-500 */
  --accent: #10b981;        /* emerald-500 */
  --accent-strong: #059669; /* emerald-600 */
  --accent-soft: #10b98126; /* emerald-500 15% */
  --accent-border: #10b98166;
  --accent-glow: #10b9814d;
  --danger: #f87171;

  --container-pad: 16px;
  --ease-ios: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

html, body {
  height: 100%;
  background:
    radial-gradient(1200px 600px at 50% -10%, #1e293b 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overscroll-behavior-y: contain;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

input {
  font: inherit;
  color: inherit;
}

.loading {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

/* ---- Layout --------------------------------------------------------- */
.container {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--container-pad) var(--container-pad) 128px;
  padding-top: max(var(--container-pad), env(safe-area-inset-top));
}

/* ---- App bar (header mínimo) ---------------------------------------- */
.app-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 40px;
  margin-bottom: 4px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  transition: background-color 0.15s, color 0.15s, transform 0.1s;
}

.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }

/* ---- Dots indicadores ----------------------------------------------- */
.dots {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 12px 0 18px;
  min-height: 36px;
}

.dot {
  position: relative;
  height: 36px;
  width: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.dot::after {
  content: "";
  display: block;
  height: 8px;
  width: 8px;
  border-radius: 999px;
  background: var(--border-soft);
  transition: width 0.32s var(--ease-ios), background-color 0.32s var(--ease-ios);
}

.dot.active::after {
  width: 26px;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.dot:hover::after { background: var(--muted); }
.dot.active:hover::after { background: var(--accent); }

/* ---- Viewport + track (carrusel horizontal) ------------------------- */
.swipe-viewport {
  margin: 0 calc(-1 * var(--container-pad));
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -ms-overflow-style: none;
  overscroll-behavior-x: contain;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.swipe-viewport::-webkit-scrollbar { display: none; }
.swipe-viewport.no-smooth { scroll-behavior: auto; }

.swipe-track {
  display: flex;
  align-items: flex-start;
}

.swipe-page {
  flex: 0 0 100%;
  scroll-snap-align: center;
  scroll-snap-stop: always;
  padding: 4px var(--container-pad) 8px;
}

/* ---- Place header (dentro de la página) ----------------------------- */
.place-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 4px 18px;
}

.place-icon-wrap {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(140deg, var(--accent-soft), transparent 70%);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  transition: background 0.4s var(--ease-ios), box-shadow 0.4s var(--ease-ios);
}

.place-icon-wrap .icon { width: 28px; height: 28px; }

.page-done .place-icon-wrap {
  background: linear-gradient(140deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  box-shadow: 0 0 0 6px var(--accent-glow);
}

.place-meta { min-width: 0; flex: 1; }

.place-name {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.place-date {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

/* ---- Progress ------------------------------------------------------- */
.progress {
  padding: 4px;
  margin-bottom: 18px;
}

.progress-bar {
  height: 6px;
  background: var(--surface);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
  border-radius: 999px;
  transition: width 480ms var(--ease-ios);
}

.progress-label {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.progress.all-done .progress-fill {
  background: linear-gradient(90deg, #34d399, var(--accent));
  box-shadow: 0 0 16px var(--accent-glow);
}

.progress.all-done .progress-label {
  color: #6ee7b7;
  font-weight: 600;
  animation: glow-pulse 2.4s ease-in-out infinite;
}

.progress.all-done .progress-label .icon { color: #6ee7b7; }

@keyframes glow-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ---- Lista de checks ------------------------------------------------ */
.checks {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.check {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: left;
  transition:
    transform 0.12s var(--ease-spring),
    background-color 0.25s var(--ease-ios),
    border-color 0.25s var(--ease-ios),
    box-shadow 0.25s var(--ease-ios);
}

.check:active {
  transform: scale(0.97);
}

.check.done {
  background: linear-gradient(135deg, var(--accent-soft), transparent 110%);
  border-color: var(--accent-border);
  box-shadow: 0 4px 18px -8px var(--accent-glow);
}

.check-icon {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 999px;
  border: 2px solid var(--border-soft);
  background: #0f172a66;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, border-color 0.2s;
}

.check.done .check-icon {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.check.done .check-icon svg { color: #fff; }
.check-icon svg { color: var(--text-dim); }

.check.just-toggled .check-icon svg {
  animation: pop-in 360ms var(--ease-spring);
}

.check.just-toggled {
  animation: card-flash 420ms var(--ease-ios);
}

@keyframes pop-in {
  0% { transform: scale(0.5); opacity: 0.4; }
  55% { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes card-flash {
  0% { transform: scale(1); }
  40% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

.check-body { flex: 1; min-width: 0; }

.check-label {
  font-size: 17px;
  line-height: 1.3;
  color: var(--text);
}

.check.done .check-label { color: #a7f3d0; }

.check-time {
  font-size: 13px;
  color: #34d39999;
  margin-top: 2px;
}

.page-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 16px;
  font-size: 14px;
}

/* ---- Reset día ------------------------------------------------------ */
.reset-btn {
  margin-top: 22px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  color: var(--muted);
  font-size: 14px;
  border-radius: 12px;
  transition: color 0.15s, background-color 0.15s;
}

.reset-btn:hover { color: var(--text); background: var(--surface); }

/* ---- Empty state ---------------------------------------------------- */
.empty-state {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
}

.empty-illustration {
  width: 96px;
  height: 96px;
  border-radius: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(140deg, var(--accent-soft), transparent 80%);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  margin-bottom: 4px;
  animation: gentle-float 4s ease-in-out infinite;
}

.empty-illustration .icon { width: 44px; height: 44px; }

@keyframes gentle-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.empty-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.empty-text {
  color: var(--text-dim);
  max-width: 320px;
  line-height: 1.5;
}

.empty-examples {
  color: var(--muted-2);
  font-size: 13px;
  max-width: 320px;
  margin-bottom: 12px;
}

/* ---- Modales -------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 40;
  animation: fade-in 200ms ease-out;
}

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
}

.modal {
  background: var(--surface);
  border-radius: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 85dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  animation: slide-up 280ms var(--ease-ios);
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slide-up {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  position: sticky;
  top: 0;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  z-index: 1;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.modal-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-panel,
.backup-panel {
  padding: 12px;
  background: var(--surface-2);
  border-radius: 12px;
}

.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.toggle-row input {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  margin-top: 2px;
  accent-color: var(--accent);
}

.toggle-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.toggle-title { font-weight: 500; }

.toggle-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.backup-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.secondary-btn {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 14px;
  transition: border-color 0.15s, color 0.15s, background-color 0.15s;
}

.secondary-btn:hover,
.secondary-btn:active {
  border-color: var(--accent-border);
  color: var(--text);
  background: var(--surface);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.modal-section-label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.modal-section-label strong {
  color: var(--text);
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
}

.section-spaced { margin-top: 14px; }

.modal-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 12px;
  transition: background-color 0.15s;
}

.modal-row:hover { background: #0f172acc; }

.modal-row-icon-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s, transform 0.1s;
}

.modal-row-icon-btn:hover { background: var(--border-soft); }
.modal-row-icon-btn:active { transform: scale(0.94); }
.modal-row-icon-btn.place svg { color: var(--accent); }
.modal-row-icon-btn.check svg { color: var(--text); }

.modal-row-main {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.modal-row-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-row-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.modal-row-label {
  flex: 1;
  font-size: 14px;
}

.danger-btn {
  padding: 8px;
  border-radius: 8px;
  color: var(--muted);
  transition: color 0.15s, background-color 0.15s;
}

.danger-btn:hover {
  color: var(--danger);
  background: #f871711a;
}

.modal-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  position: sticky;
  bottom: 0;
  background: var(--surface);
}

.modal-footer input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px; /* IMPORTANTE: 16px para evitar el zoom de iOS */
  outline: none;
  transition: border-color 0.15s, background-color 0.15s;
}

.modal-footer input:focus {
  border-color: var(--accent);
  background: var(--surface-2);
}

.primary-btn {
  padding: 10px 16px;
  background: var(--accent-strong);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  color: white;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.15s, transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 2px 8px -2px var(--accent-glow);
}

.primary-btn:hover {
  background: var(--accent);
  box-shadow: 0 4px 14px -4px var(--accent-glow);
}

.primary-btn:active { transform: scale(0.97); }

.primary-btn:disabled {
  background: var(--border);
  color: var(--muted-2);
  cursor: default;
  box-shadow: none;
}

.muted-row {
  text-align: center;
  color: var(--muted-2);
  font-size: 14px;
  padding: 16px 0;
}

/* ---- Bloque CP en edición de lugar ---------------------------------- */
.place-cp-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 12px;
  margin-bottom: 4px;
}

.cp-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 16px; /* 16px para evitar zoom en iOS */
  outline: none;
  transition: border-color 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cp-input:focus { border-color: var(--accent); }

.cp-help {
  font-size: 12px;
  color: var(--muted-2);
  line-height: 1.4;
}

/* ---- Icon picker grid ----------------------------------------------- */
.icon-picker-modal {
  max-height: 70dvh;
  z-index: 50;
}

.icon-picker-backdrop { z-index: 50; }

.icon-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  padding: 16px;
}

.icon-grid-item {
  aspect-ratio: 1;
  border-radius: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}

.icon-grid-item:hover {
  background: var(--surface);
  border-color: var(--accent-border);
}

.icon-grid-item:active { transform: scale(0.94); }
.icon-grid-item svg { color: var(--text); width: 24px; height: 24px; }

/* ---- Toast con deshacer --------------------------------------------- */
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 70;
  max-width: 448px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 14px;
  background: #e2e8f0;
  color: #0f172a;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  font-size: 14px;
  animation: toast-in 260ms var(--ease-spring);
}

@keyframes toast-in {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.toast-action {
  flex-shrink: 0;
  color: #047857;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background-color 0.15s;
}

.toast-action:hover { background: rgba(4, 120, 87, 0.1); }

/* ---- Iconos SVG inline ---------------------------------------------- */
.icon {
  display: inline-block;
  vertical-align: middle;
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-sm { width: 18px; height: 18px; }
.icon-lg { width: 28px; height: 28px; }

/* ---- Confetti (celebración al cerrar todo) -------------------------- */
.confetti-burst {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  width: 0;
  height: 0;
}

.confetti-piece {
  position: absolute;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  left: -4px;
  top: -6px;
  --dx: 0px;
  --dy: 0px;
  --rot: 0deg;
  transform: translate(0, 0) rotate(0deg) scale(0.4);
  opacity: 0;
  animation: confetti-fly 1500ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes confetti-fly {
  0%   { transform: translate(0, 0) rotate(0deg) scale(0.5); opacity: 0; }
  12%  { opacity: 1; }
  70%  { opacity: 1; }
  100% {
    transform: translate(var(--dx), calc(var(--dy) + 90px))
               rotate(var(--rot)) scale(1);
    opacity: 0;
  }
}

/* ---- Accesibilidad: respeta reduced-motion -------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .swipe-viewport { scroll-behavior: auto; }
}
