/* ---------- Tokens ---------- */

:root {
  --bg: #F6F5F1;
  --surface: #FFFFFF;
  --ink: #1C1B18;
  --ink-2: #6E6A62;
  --ink-3: #A9A59C;
  --line: rgba(28, 27, 24, .08);
  --line-strong: rgba(28, 27, 24, .14);
  --press: rgba(28, 27, 24, .05);
  --press-strong: rgba(28, 27, 24, .07);
  --accent: #2D7A5F;
  --on-accent: #FFFFFF;
  --danger: #C23B2E;
  --scrim: rgba(20, 19, 17, .28);
  --toast-action: #9AD9BD;
  --shadow: 0 1px 2px rgba(28, 27, 24, .04), 0 6px 20px rgba(28, 27, 24, .07);
  --shadow-sheet: 0 -8px 40px rgba(28, 27, 24, .12);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --gutter: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1E1D1B;
    --ink: #F1EFEA;
    --ink-2: #9C988F;
    --ink-3: #625E57;
    --line: rgba(241, 239, 234, .08);
    --line-strong: rgba(241, 239, 234, .16);
    --press: rgba(241, 239, 234, .06);
    --press-strong: rgba(241, 239, 234, .09);
    --accent: #4FA383;
    --on-accent: #0F1F18;
    --danger: #E0645A;
    --scrim: rgba(0, 0, 0, .5);
    --toast-action: #2D7A5F;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .35);
    --shadow-sheet: 0 -8px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  /* scrollIntoView deja la tarea nueva por encima del campo fijo de abajo */
  scroll-padding-bottom: calc(100px + var(--safe-bottom));
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input { font: inherit; color: inherit; }

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 10px; }

[hidden] { display: none !important; }

svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
svg.solid { fill: currentColor; stroke: none; }

.i { display: inline-grid; place-items: center; flex: none; }

/* ---------- Estructura ---------- */

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 max(var(--gutter), env(safe-area-inset-right)) calc(128px + var(--safe-bottom)) max(var(--gutter), env(safe-area-inset-left));
}

.screen[data-enter="forward"] .page { animation: in-forward .32s var(--ease); }
.screen[data-enter="back"] .page { animation: in-back .32s var(--ease); }
.screen[data-enter] .dock { animation: fade .32s var(--ease); }

@keyframes in-forward { from { opacity: 0; transform: translate3d(28px, 0, 0); } }
@keyframes in-back { from { opacity: 0; transform: translate3d(-20px, 0, 0); } }
@keyframes fade { from { opacity: 0; } }

.title {
  margin: 0;
  font-size: 34px;
  line-height: 1.12;
  font-weight: 700;
  letter-spacing: -.025em;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

/* Barra fija de abajo: acción principal / campo para agregar */
.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 18px max(var(--gutter), env(safe-area-inset-right)) calc(14px + var(--safe-bottom)) max(var(--gutter), env(safe-area-inset-left));
  background: linear-gradient(to bottom, transparent, var(--bg) 45%);
  pointer-events: none;
}
.dock > * { pointer-events: auto; max-width: 600px; margin: 0 auto; }

/* ---------- Botones ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 54px;
  padding: 0 24px;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.005em;
  transition: transform .12s var(--ease), opacity .15s, background-color .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .28; transform: none; cursor: default; }
.btn.wide { display: flex; width: 100%; }
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.secondary { background: var(--press-strong); color: var(--ink); }
.btn.danger { background: var(--danger); color: #fff; }
.btn svg { width: 20px; height: 20px; stroke-width: 2.4; }

.icon-btn {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  transition: background-color .15s;
}
.icon-btn:active { background: var(--press-strong); }

/* ---------- Inicio ---------- */

.home-head { padding: calc(var(--safe-top) + 40px) 0 10px; }

.groups { list-style: none; margin: 10px 0 0; padding: 0; }

.group {
  position: relative;
  width: 100%;
  min-height: 78px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
  text-align: left;
}
.groups li + li .group::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: var(--line);
}
.group::after {
  content: "";
  position: absolute;
  inset: 3px -12px;
  border-radius: 14px;
  background: var(--press);
  opacity: 0;
  transition: opacity .18s;
}
.group:active::after { opacity: 1; }

.group-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.group-name { font-size: 19px; font-weight: 600; letter-spacing: -.012em; line-height: 1.3; overflow-wrap: anywhere; }
.group-meta { font-size: 14.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.group .i { color: var(--ink-3); margin-right: -4px; }
.group .i svg { width: 20px; height: 20px; }

/* ---------- Estados vacíos ---------- */

.empty { padding: 12vh 0 0; }
.empty-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 22px;
  border-radius: 13px;
  background: var(--accent);
  color: var(--on-accent);
}
.empty-mark svg { width: 26px; height: 26px; stroke-width: 2.6; }
.empty-mark .tick { stroke-dashoffset: 0; }
.empty-title { margin: 0 0 6px; font-size: 22px; font-weight: 650; letter-spacing: -.018em; }
.empty-text { margin: 0 0 28px; color: var(--ink-2); max-width: 30ch; }
.list-empty { padding-top: 8vh; cursor: text; }

/* ---------- Lista ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  height: calc(60px + var(--safe-top));
  margin: 0 calc(var(--gutter) * -1);
  padding: var(--safe-top) 8px 0;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.scrolled .bar { border-bottom-color: var(--line); }

.bar-title {
  flex: 1;
  min-width: 0;
  padding: 0 8px;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .2s, transform .2s var(--ease);
}
.show-bar-title .bar-title { opacity: 1; transform: none; }

.list-title { padding: 6px 0 14px; cursor: text; }

.tasks { list-style: none; margin: 0; padding: 0; }

.task {
  position: relative;
  display: flex;
  align-items: flex-start;
  min-height: 56px;
  padding: 4px 0;
}
.task + .task::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 40px;
  height: 1px;
  background: var(--line);
}

.check {
  flex: none;
  width: 48px;
  height: 48px;
  margin-left: -12px;
  display: grid;
  place-items: center;
}
.box {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink-3);
  border-radius: 8px;
  transition: background-color .18s, border-color .18s;
}
.box svg { width: 16px; height: 16px; stroke: var(--on-accent); stroke-width: 3; }
.tick { stroke-dasharray: 19; stroke-dashoffset: 19; transition: stroke-dashoffset .22s var(--ease) .04s; }

.done .box { background: var(--accent); border-color: var(--accent); }
.done .tick { stroke-dashoffset: 0; }
.pop .box { animation: pop .34s var(--ease); }
@keyframes pop { 35% { transform: scale(.8); } 70% { transform: scale(1.06); } }

.task-text {
  flex: 1;
  min-width: 0;
  margin-left: 4px;
  padding: 12px 0;
  overflow-wrap: anywhere;
  text-decoration: line-through;
  text-decoration-color: transparent;
  text-decoration-thickness: 1.5px;
  transition: color .22s, text-decoration-color .22s;
  outline: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.done .task-text { color: var(--ink-3); text-decoration-color: var(--ink-3); }
.editing .task-text {
  color: var(--ink);
  text-decoration-color: transparent;
  caret-color: var(--accent);
  -webkit-user-select: text;
  user-select: text;
}

.task-del {
  flex: none;
  width: 48px;
  height: 48px;
  margin-right: -12px;
  display: none;
  place-items: center;
  color: var(--danger);
}
.editing .task-del { display: grid; animation: fade .15s; }
.task-del svg { width: 22px; height: 22px; }

.task.is-new { animation: row-in .28s var(--ease); }
@keyframes row-in { from { opacity: 0; transform: translateY(6px); } }

.task.leaving {
  height: 0 !important;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  opacity: 0;
  transition: height .22s var(--ease), padding .22s var(--ease), opacity .14s;
}

/* Campo para agregar tareas */
.composer {
  display: flex;
  align-items: center;
  height: 58px;
  padding: 0 7px 0 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.composer-plus { width: 44px; display: grid; place-items: center; color: var(--accent); }
.composer-plus svg { stroke-width: 2.4; }
.composer-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 4px;
  border: 0;
  background: transparent;
  outline: none;
  font-size: 17px;
  caret-color: var(--accent);
}
.composer-input::placeholder { color: var(--accent); font-weight: 550; opacity: 1; }
.composer-input:focus::placeholder { color: var(--ink-3); font-weight: 400; }
.composer-add {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: var(--accent);
  color: var(--on-accent);
  opacity: 0;
  transform: scale(.85);
  pointer-events: none;
  transition: opacity .16s, transform .16s var(--ease);
}
.composer-add svg { width: 20px; height: 20px; stroke-width: 2.4; }
.has-text .composer-add { opacity: 1; transform: none; pointer-events: auto; }

/* ---------- Hoja inferior ---------- */

.sheet-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  opacity: 0;
  transition: opacity .24s;
}
.sheet {
  position: relative;
  width: 100%;
  max-width: 560px;
  padding: 8px var(--gutter) calc(18px + var(--safe-bottom));
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow-sheet);
  transform: translateY(100%);
  transition: transform .28s var(--ease);
}
.open .scrim { opacity: 1; }
.open .sheet { transform: none; }

.grabber {
  width: 36px;
  height: 4px;
  margin: 0 auto 14px;
  border-radius: 2px;
  background: var(--line-strong);
}

.sheet-title {
  display: block;
  margin: 4px 0 16px;
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -.018em;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.sheet-text { margin: -8px 0 24px; color: var(--ink-2); }
.sheet-caption {
  margin: 0 8px 6px;
  font-size: 14px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.field {
  width: 100%;
  height: 56px;
  margin-bottom: 14px;
  padding: 0 16px;
  border: 1.5px solid var(--line-strong);
  border-radius: 14px;
  background: var(--bg);
  outline: none;
  font-size: 17px;
  caret-color: var(--accent);
  transition: border-color .15s;
}
.field:focus { border-color: var(--accent); }
.field::placeholder { color: var(--ink-3); }

.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.menu-item {
  width: 100%;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 8px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 500;
  text-align: left;
  transition: background-color .15s;
}
.menu-item:active { background: var(--press-strong); }
.menu-item .i { color: var(--ink-2); }
.menu-item.danger, .menu-item.danger .i { color: var(--danger); }

/* ---------- Aviso ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + var(--safe-bottom));
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 2 * var(--gutter));
  min-height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--bg);
  font-size: 15px;
  white-space: nowrap;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity .18s, transform .18s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-action {
  height: 44px;
  margin-right: -10px;
  padding: 0 10px;
  color: var(--toast-action);
  font-weight: 650;
}

/* ---------- Movimiento reducido ---------- */

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