:root {
  --bg: #eef5f2;
  --surface: #ffffff;
  --surface-2: #e6f0ec;
  --text: #16332d;
  --muted: #5a7770;
  --line: #d3e2dc;
  --line-strong: #a9c2ba;
  --accent: #23786b;
  --accent-soft: #d5ece6;
  --hero-a: #2f8f7f;
  --hero-b: #3d78b0;
  --on-accent: #ffffff;
  --danger: #b4443d;
  --shadow: 0 8px 28px rgba(22, 51, 45, 0.09);
  --radius: 22px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1716;
    --surface: #152523;
    --surface-2: #1b302d;
    --text: #e5f2ee;
    --muted: #8fb0a8;
    --line: #25403b;
    --line-strong: #3d635c;
    --accent: #5cc4ae;
    --accent-soft: #1d3a35;
    --hero-a: #1f6b5f;
    --hero-b: #2b5f8f;
    --on-accent: #0b1c19;
    --danger: #e58a83;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* sin zoom por doble toque */
  overflow-x: hidden;
  overscroll-behavior-x: none; /* sin arrastre lateral: se comporta como una app */
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
svg { display: block; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Contenedor */
#app { max-width: 640px; margin: 0 auto; padding: calc(16px + env(safe-area-inset-top)) 16px calc(104px + env(safe-area-inset-bottom)); }
#app[data-view="login"] { max-width: none; padding: 0; }
.boot-error { padding: 40px 16px; text-align: center; color: var(--muted); }

/* Cabecera */
.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.top h1 { font-size: 1.7rem; letter-spacing: -0.02em; }
.eyebrow { color: var(--muted); font-size: 0.85rem; }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: var(--surface); color: var(--muted); box-shadow: var(--shadow);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.on-hero { background: rgba(255, 255, 255, 0.18); color: #fff; box-shadow: none; }
.icon-btn.spacer { visibility: hidden; }

/* Resumen de la semana */
.hero {
  background: linear-gradient(135deg, var(--hero-a), var(--hero-b));
  color: #fff; border-radius: var(--radius); padding: 14px 14px 18px; box-shadow: var(--shadow);
}
.hero-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hero-title { text-align: center; }
.hero-title h2 { font-size: 1.15rem; }
.hero-title p { opacity: 0.85; font-size: 0.9rem; }
.hero-progress { margin-top: 12px; padding: 0 6px; }
.bar { height: 10px; border-radius: 99px; background: rgba(255, 255, 255, 0.25); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 99px; background: #fff; transition: width 0.4s ease; }
.hero-progress p { margin-top: 8px; font-size: 0.9rem; }

/* Tira de días (móvil) */
.strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 16px 0; }
.strip-day {
  display: grid; justify-items: center; gap: 2px; padding: 8px 0 10px; border: 0;
  border-radius: 16px; background: var(--surface); color: var(--muted);
}
.strip-day .letter { font-size: 0.75rem; font-weight: 600; }
.strip-day .num { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.strip-day .dot { width: 6px; height: 6px; border-radius: 50%; background: transparent; }
.strip-day.is-complete .dot { background: var(--accent); }
.strip-day.is-today .num { color: var(--accent); }
.strip-day.is-future { opacity: 0.65; }
.strip-day.is-selected { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow); opacity: 1; }
.strip-day.is-selected .num { color: var(--on-accent); }
.strip-day.is-selected.is-complete .dot { background: var(--on-accent); }

/* Días */
.day { display: none; background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.day.is-selected { display: block; }
.day.is-future { background: var(--surface-2); box-shadow: none; }
.day-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.day-head h2 { font-size: 1.2rem; }
.day-date { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; }
.pill { background: var(--accent-soft); color: var(--accent); border-radius: 99px; padding: 1px 10px; font-size: 0.75rem; font-weight: 700; }
.tasks { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 4px; }
.task { display: flex; align-items: center; gap: 2px; }
.task-body {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 6px 8px;
  background: none; border: 0; text-align: left; border-radius: 14px;
}
button.task-body:hover { background: var(--surface-2); }
.icon {
  display: inline-grid; place-items: center; width: 38px; height: 38px; flex: none;
  border-radius: 12px; background: var(--accent-soft); color: var(--accent);
}
.icon svg { width: 22px; height: 22px; }
.task-title { overflow-wrap: anywhere; }
.task.is-done .task-title { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.task.is-done .icon { opacity: 0.6; }
.empty { margin-top: 14px; color: var(--muted); font-size: 0.95rem; }

/* Check */
.check { position: relative; flex: none; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; background: transparent; }
.check::before {
  content: ""; position: absolute; inset: 7px; border-radius: 50%;
  border: 2px solid var(--line-strong); transition: background 0.2s, border-color 0.2s;
}
.check svg {
  position: relative; width: 18px; height: 18px; stroke: var(--on-accent); stroke-width: 3;
  stroke-dasharray: 24; stroke-dashoffset: 24; transition: stroke-dashoffset 0.25s ease 0.05s;
}
.check[aria-pressed="true"]::before { background: var(--accent); border-color: var(--accent); }
.check[aria-pressed="true"] svg { stroke-dashoffset: 0; }
.check:disabled { opacity: 0.35; cursor: default; }
.just-checked .check::before { animation: pop 0.35s ease; }

/* Anillo de progreso */
.ring { position: relative; display: inline-grid; place-items: center; }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 4; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; transition: stroke-dasharray 0.4s ease; }
.ring b { position: absolute; font-size: 0.68rem; font-weight: 700; }

/* Celebración */
.celebrate { margin-top: 10px; padding: 8px 12px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); font-weight: 700; animation: pop-in 0.4s ease; }
.day.is-celebrating { animation: glow 1.4s ease; }

/* Añadir */
.add-inline {
  display: none; align-items: center; justify-content: center; gap: 6px; width: 100%; margin-top: 12px;
  padding: 8px 12px; border: 1.5px dashed var(--line-strong); border-radius: 14px; background: none; color: var(--muted);
}
.add-inline svg { width: 18px; height: 18px; }
.add-inline:hover { color: var(--accent); border-color: var(--accent); }
.fab {
  position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border: 0; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--hero-a), var(--hero-b)); color: #fff; box-shadow: 0 10px 26px rgba(35, 120, 107, 0.4);
}
.fab svg { width: 28px; height: 28px; }
.fab:active { transform: scale(0.94); }

/* Aviso */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 14px; z-index: 10;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow); animation: fade-in 0.25s ease;
}

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 12px; padding: 28px 24px; border-radius: 28px; background: var(--surface); box-shadow: var(--shadow); }
.brand { display: grid; justify-items: center; gap: 6px; text-align: center; margin-bottom: 8px; }
.brand .mark { width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--hero-a), var(--hero-b)); }
.brand .mark .icon { width: 32px; height: 32px; background: none; color: inherit; }
.brand .mark .icon svg { width: 32px; height: 32px; }
.brand h1 { font-size: 1.6rem; }
.brand p { color: var(--muted); }
.field { display: grid; gap: 6px; font-size: 0.9rem; color: var(--muted); }
.input { width: 100%; font-size: 16px; /* menos de 16px hace que iOS amplíe la página al enfocar */ padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--line-strong); background: var(--bg); color: var(--text); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { min-height: 1.2em; color: var(--danger); font-size: 0.9rem; }
.btn { padding: 12px 18px; border-radius: 14px; border: 0; font-weight: 700; }
.btn-primary { background: linear-gradient(135deg, var(--hero-a), var(--hero-b)); color: #fff; }
.btn-ghost { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border: 1.5px solid currentColor; }

/* Hoja de tarea */
#sheet { width: 100%; max-width: 520px; margin: auto auto 0; padding: 0; border: 0; background: transparent; color: var(--text); overflow: visible; }
#sheet::backdrop { background: rgba(8, 20, 18, 0.5); backdrop-filter: blur(3px); }
.sheet-body {
  display: grid; gap: 16px; max-height: 92dvh; overflow: auto; background: var(--surface);
  border-radius: 26px 26px 0 0; padding: 22px 20px calc(20px + env(safe-area-inset-bottom)); animation: slide-up 0.25s ease;
}
.sheet-body h2 { font-size: 1.25rem; }
.hint { color: var(--muted); font-size: 0.85rem; }
.group-label { display: block; margin-bottom: 6px; font-size: 0.85rem; color: var(--muted); }
.chips { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.chip, .icon-choice { position: relative; }
.chip input, .icon-choice input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.chip .short { display: grid; place-items: center; height: 44px; border-radius: 14px; background: var(--surface-2); color: var(--muted); font-weight: 700; }
.chip:has(input:checked) .short { background: var(--accent); color: var(--on-accent); }
.chip:has(input:focus-visible), .icon-choice:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 14px; }
.icon-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.icon-choice { display: grid; place-items: center; height: 48px; border-radius: 14px; background: var(--surface-2); color: var(--muted); }
.icon-choice .icon { background: transparent; color: inherit; }
.icon-choice:has(input:checked) { background: var(--accent); color: var(--on-accent); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn-primary { flex: 1; }

@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.28); } 100% { transform: scale(1); } }
@keyframes pop-in { from { transform: scale(0.85); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes glow { 0%, 100% { box-shadow: var(--shadow); } 40% { box-shadow: 0 0 0 6px var(--accent-soft), var(--shadow); } }

/* Tablet y escritorio: los 7 días visibles */
@media (min-width: 640px) {
  #sheet { margin: auto; }
  .sheet-body { border-radius: 26px; }
}
@media (min-width: 760px) {
  #app { max-width: 2000px; padding-left: 32px; padding-right: 32px; }
  .strip, .fab { display: none; }
  .days { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 20px; align-items: start; }
  .day, .day.is-selected { display: block; }
  .add-inline { display: flex; }
}
@media (min-width: 1000px) {
  .days { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
/* Siete columnas solo cuando hay ancho para que los títulos respiren */
@media (min-width: 1700px) {
  .days { grid-template-columns: repeat(7, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
