:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --ink: #1f1d1a;
  --muted: #6f6a62;
  --line: #e6e0d6;
  --accent: #2f6b4f;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe8;
  --late: #b4432c;
  --late-soft: #f8e6e0;
  --emilio: #3563a0;
  --miriam: #b8573c;
  --ambos: #7a6f60;
  --radius: 14px;
  --bar: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --card: #1f1d1a;
    --ink: #f1ede6;
    --muted: #a39d93;
    --line: #34302b;
    --accent: #6fb58f;
    --accent-ink: #0f1a14;
    --accent-soft: #1f3228;
    --late: #ec8a73;
    --late-soft: #3a211b;
    --emilio: #8cb2e6;
    --miriam: #ee9d84;
    --ambos: #b9ad9c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.loading { padding: 40px 16px; color: var(--muted); text-align: center; }

/* ---------- cabecera ---------- */
.top {
  padding: calc(env(safe-area-inset-top) + 14px) 16px 8px;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  max-width: 640px; margin: 0 auto;
}
.top .brand { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); }
.top h1 { margin: 2px 0 0; font-size: 26px; line-height: 1.15; font-weight: 700; letter-spacing: -.01em; }
.me-btn {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0;
  color: #fff; font-weight: 700; font-size: 16px;
}
.me-btn.emilio { background: var(--emilio); }
.me-btn.miriam { background: var(--miriam); }
@media (prefers-color-scheme: dark) { .me-btn, .who button .av { color: #151412; } }

main.view {
  max-width: 640px; margin: 0 auto;
  padding: 4px 16px calc(var(--bar) + env(safe-area-inset-bottom) + 90px);
}

/* ---------- marcador ---------- */
.score {
  width: 100%; display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin: 6px 0 14px; text-align: left;
}
.score .label { font-size: 13px; color: var(--muted); flex: 1; }
.score .n { font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; gap: 6px; }

/* ---------- filtros ---------- */
.seg { display: inline-flex; background: var(--line); border-radius: 10px; padding: 2px; margin-bottom: 6px; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- listas ---------- */
h2.group {
  font-size: 13px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase;
  color: var(--muted); margin: 20px 4px 8px;
}
h2.group.late { color: var(--late); }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 58px; }
.row + .row { border-top: 1px solid var(--line); }
.row .body { flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 0; }
.row .title { font-weight: 550; overflow-wrap: anywhere; }
.row .meta { font-size: 13px; color: var(--muted); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.row .meta .late { color: var(--late); font-weight: 600; }
.row.done .title { text-decoration: line-through; color: var(--muted); font-weight: 400; }
.row.future { opacity: .55; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; margin-right: 5px; vertical-align: 1px; }
.dot.emilio { background: var(--emilio); }
.dot.miriam { background: var(--miriam); }
.dot.ambos { background: var(--ambos); }

.check {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--line); background: transparent; padding: 0;
  display: grid; place-items: center; transition: background .12s, border-color .12s;
}
.check.late { border-color: var(--late); }
.check svg { width: 16px; height: 16px; opacity: 0; }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on svg { opacity: 1; stroke: var(--accent-ink); }
.check:active { transform: scale(.94); }
.check[disabled] { visibility: hidden; }

.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }

.quick { display: flex; gap: 8px; margin: 8px 0 4px; }
.quick input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 14px; font-size: 16px; }
.quick button { border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 600; border-radius: 12px; padding: 0 16px; }

/* ---------- barra de abajo ---------- */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs .inner { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); height: var(--bar); }
nav.tabs button { border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 500; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
nav.tabs button svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav.tabs button.on { color: var(--accent); }
.fab {
  position: fixed; z-index: 11; right: max(16px, calc(50% - 304px));
  bottom: calc(var(--bar) + env(safe-area-inset-bottom) + 16px);
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
  display: grid; place-items: center;
}
.fab svg { width: 26px; height: 26px; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }

/* ---------- hoja (añadir / editar / ajustes) ---------- */
dialog#sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px;
  max-height: 92%; border-radius: 20px 20px 0 0;
  background: var(--bg); color: var(--ink);
}
dialog#sheet { overscroll-behavior: contain; }
dialog#sheet::backdrop { background: rgba(0,0,0,.35); }
@media (min-width: 700px) { dialog#sheet { margin: auto; border-radius: 20px; } }
.sheet { padding: 16px 16px calc(env(safe-area-inset-bottom) + 20px); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h3 { margin: 0; font-size: 19px; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 6px 2px; }
.field { margin-bottom: 14px; }
.field > label, .field > .lbl { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin: 0 2px 6px; }
.field input[type=text], .field input[type=date], .field input[type=time], .field input[type=number], .field input[type=password], .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 12px; font-size: 16px;
}
.field textarea { resize: vertical; min-height: 64px; }
/* Safari del iPhone: las fechas y horas salen estrechas y centradas si no */
.field input[type=date], .field input[type=time], .field > input[type=time] { -webkit-appearance: none; appearance: none; min-height: 46px; text-align: left; display: block; }
input::-webkit-date-and-time-value { text-align: left; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pills button { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 14px; font-size: 15px; display: inline-flex; align-items: center; gap: 6px; }
.pills button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input[type=number] { width: 80px; }
.inline select { flex: 1; }
.switch, .field > label.switch { display: flex; margin: 0; align-items: center; justify-content: space-between; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.switch span { font-weight: 550; color: var(--ink); font-size: 16px; }
.switch span small { display: block; color: var(--muted); font-size: 13px; font-weight: 400; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 14px; font-weight: 600; font-size: 16px; background: var(--accent); color: var(--accent-ink); text-align: center; text-decoration: none; }
.btn.ghost { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--late); border: 1px solid var(--line); }
.btn + .btn { margin-top: 8px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.actions .btn + .btn { margin-top: 0; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 2px 10px; }
.error { color: var(--late); font-size: 14px; margin: 8px 2px; min-height: 1em; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.card h4 { margin: 0 0 6px; font-size: 16px; }
.card p { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.card ol { margin: 0 0 12px; padding-left: 20px; font-size: 14px; }
.card ol li { margin-bottom: 4px; }

/* marcador */
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 70px 1fr 28px; align-items: center; gap: 10px; font-size: 15px; }
.bar { height: 12px; background: var(--line); border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 6px; }
.bar i.emilio { background: var(--emilio); }
.bar i.miriam { background: var(--miriam); }
.bar-row b { text-align: right; }
.hist { list-style: none; padding: 0; margin: 0; }
.hist li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.hist li:first-child { border-top: 0; }
.hist li span.t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.hist li time { color: var(--muted); font-size: 13px; }

/* aviso con deshacer */
#toast {
  position: fixed; left: 50%; transform: translate(-50%, 20px); z-index: 30;
  bottom: calc(var(--bar) + env(safe-area-inset-bottom) + 16px);
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 10px 10px 16px;
  display: flex; align-items: center; gap: 12px; font-size: 15px; width: max-content; max-width: calc(100% - 32px);
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { border: 0; background: none; color: var(--bg); font-weight: 700; text-decoration: underline; padding: 4px 6px; }

/* pantallas de entrada */
.gate-card { max-width: 400px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 56px) 16px 32px; }
.gate-card h1 { font-size: 32px; margin: 12px 0 4px; letter-spacing: -.01em; }
.gate-card > p { color: var(--muted); margin: 0 0 24px; }
.gate-card .logo { width: 64px; height: 64px; border-radius: 16px; }
.who { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.who button { border: 2px solid var(--line); background: var(--card); border-radius: 14px; padding: 16px 8px; font-weight: 600; font-size: 17px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.who button .av { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; }
.who button .av.emilio { background: var(--emilio); }
.who button .av.miriam { background: var(--miriam); }
.who button.on { border-color: var(--accent); background: var(--accent-soft); }
