:root {
  --bg: #e8eaed;
  --surface: #fbfbfc;
  --surface-2: #f1f3f5;
  --ink: #1e2430;
  --muted: #5c6675;
  --line: #d2d6dc;
  --accent: #40558a;
  --accent-soft: #dfe4f0;

  --m-3: #7d4a63;
  --m-2: #96617a;
  --m-1: #ab8494;
  --m0:  #8b8b93;
  --m1:  #6f9490;
  --m2:  #4d8b84;
  --m3:  #2c7f74;

  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;

  --r: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1c2027;
    --surface-2: #232830;
    --ink: #e5e8ee;
    --muted: #929aa8;
    --line: #2c323b;
    --accent: #8ba3d4;
    --accent-soft: #262f42;

    --m-3: #a4677f;
    --m-2: #b07f94;
    --m-1: #b799a5;
    --m0:  #8f939c;
    --m1:  #79a49f;
    --m2:  #5ba79e;
    --m3:  #45a396;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior-y: contain;
}

body {
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  max-width: 640px;
  margin: 0 auto;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; }

header.top {
  padding: 22px 18px 8px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
header.top h1 { margin: 0; font-size: 1.45rem; }
header.top .date { color: var(--muted); font-size: 0.86rem; font-variant-numeric: tabular-nums; }

main { padding: 0 14px; }

.panel { display: none; }
.panel.active { display: block; }

.block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
  margin-bottom: 14px;
}

.block > h2 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}
.block > .hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.82rem;
}

.field { margin-top: 18px; }
.field:first-of-type { margin-top: 0; }
.field > label {
  display: block;
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 8px;
}

/* Escala de ánimo */
.scale { display: flex; gap: 6px; }
.scale button {
  flex: 1;
  aspect-ratio: 1 / 1;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 50%;
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  transition: transform .12s ease;
}
.scale button[data-on="1"] {
  border-color: transparent;
  color: #fff;
  transform: scale(1.06);
}
.scale button[data-v="-3"][data-on="1"] { background: var(--m-3); }
.scale button[data-v="-2"][data-on="1"] { background: var(--m-2); }
.scale button[data-v="-1"][data-on="1"] { background: var(--m-1); }
.scale button[data-v="0"][data-on="1"]  { background: var(--m0); }
.scale button[data-v="1"][data-on="1"]  { background: var(--m1); }
.scale button[data-v="2"][data-on="1"]  { background: var(--m2); }
.scale button[data-v="3"][data-on="1"]  { background: var(--m3); }

.scale-ends {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--muted);
  margin-top: 6px;
}

/* Contador */
.counter { display: flex; align-items: center; gap: 14px; }
.counter button {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}
.counter .val {
  font-family: var(--serif);
  font-size: 1.6rem;
  min-width: 2.2ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.counter .unit { color: var(--muted); font-size: 0.84rem; }

/* Sí / No */
.choice { display: flex; gap: 8px; }
.choice button {
  flex: 1;
  padding: 11px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}
.choice button[data-on="1"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--ink);
  font-weight: 600;
}

textarea, input[type="text"], input[type="number"], input[type="date"], select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
}
textarea { resize: vertical; min-height: 62px; }

button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  display: inline-block;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.full { display: block; width: 100%; text-align: center; }
.btn.small { padding: 7px 11px; font-size: 0.85rem; }

.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

/* Historial */
.day {
  display: grid;
  grid-template-columns: 62px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.day:last-child { border-bottom: none; }
.day .d { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.day .dots { display: flex; gap: 5px; }
.dot { width: 15px; height: 15px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); }
.day .meta { font-size: 0.76rem; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

/* Eventos */
.ev {
  display: flex;
  gap: 11px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  align-items: flex-start;
}
.ev:last-child { border-bottom: none; }
.ev .tick {
  width: 22px; height: 22px; flex: none;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 20px;
  text-align: center;
  color: var(--accent);
  padding: 0;
}
.ev .body { flex: 1; min-width: 0; }
.ev .t { font-size: 0.95rem; }
.ev[data-done="1"] .t { text-decoration: line-through; color: var(--muted); }
.ev .sub { font-size: 0.76rem; color: var(--muted); margin-top: 2px; }
.ev .del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 0 4px; }

.empty { color: var(--muted); font-size: 0.88rem; padding: 6px 0 2px; }

.saved {
  font-size: 0.76rem;
  color: var(--muted);
  opacity: 0;
  transition: opacity .2s;
}
.saved.on { opacity: 1; }

/* Nav */
nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
nav button {
  flex: 1;
  padding: 14px 4px;
  background: none;
  border: none;
  border-top: 2px solid transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.84rem;
  cursor: pointer;
}
nav button[aria-selected="true"] { color: var(--ink); border-top-color: var(--accent); font-weight: 600; }

.note { font-size: 0.78rem; color: var(--muted); line-height: 1.45; }

/* ---------- Informe ---------- */
#report { display: none; }
#report.on { display: block; }

.sheet {
  background: #fff;
  color: #16181d;
  padding: 20px;
  border-radius: var(--r);
  border: 1px solid var(--line);
}
.sheet h2 { font-size: 1.25rem; margin: 0; color: #16181d; }
.sheet .sub { font-size: 0.8rem; color: #565c66; margin: 3px 0 16px; }
.sheet h3 {
  font-size: 0.82rem;
  font-family: var(--sans);
  font-weight: 600;
  color: #565c66;
  margin: 18px 0 7px;
  padding-bottom: 4px;
  border-bottom: 1px solid #dcdee3;
}
.sheet table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.sheet td, .sheet th { padding: 4px 6px 4px 0; text-align: left; vertical-align: top; border-bottom: 1px solid #ebecef; }
.sheet th { color: #565c66; font-weight: 600; }
.stats { display: flex; flex-wrap: wrap; gap: 10px; }
.stat {
  flex: 1 1 84px;
  max-width: 160px;
  border: 1px solid #dcdee3;
  border-radius: 7px;
  padding: 8px 10px;
}
.stat .n { font-family: var(--serif); font-size: 1.3rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 0.68rem; color: #565c66; margin-top: 2px; }
.sheet .foot { font-size: 0.68rem; color: #6b7078; margin-top: 16px; }
.sheet ol { margin: 0; padding-left: 18px; font-size: 0.82rem; }
.sheet li { margin-bottom: 3px; }

@media print {
  @page { size: A4 portrait; margin: 12mm; }
  body { background: #fff; padding: 0; max-width: none; }
  header.top, nav, main, .no-print { display: none !important; }
  #report { display: block !important; }
  .sheet { border: none; padding: 0; border-radius: 0; }
  .sheet h3 { margin: 13px 0 5px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- etiquetas del día ---------- */
.tags { display: flex; flex-wrap: wrap; gap: 7px; }
.tags button {
  padding: 9px 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: 999px;
  font: inherit;
  font-size: 0.84rem;
  cursor: pointer;
}
.tags button[data-on="1"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  font-weight: 600;
}

/* ---------- guía ---------- */
.block.urgente { border-color: var(--accent); }
.tel {
  display: block;
  padding: 12px 14px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.92rem;
}
.tel b {
  font-family: var(--serif);
  font-size: 1.12rem;
  margin-right: 9px;
  font-variant-numeric: tabular-nums;
}

.pasos { margin: 0; padding-left: 20px; font-size: 0.93rem; }
.pasos li { margin-bottom: 10px; }

details {
  border-top: 1px solid var(--line);
  padding: 2px 0;
}
details:first-of-type { border-top: none; }
summary {
  padding: 12px 0;
  cursor: pointer;
  font-size: 0.94rem;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
summary::-webkit-details-marker { display: none; }
summary::after {
  content: "+";
  color: var(--accent);
  font-size: 1.15rem;
  line-height: 1;
  flex: none;
}
details[open] > summary::after { content: "\2212"; }
details > p {
  margin: 0 0 11px;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.55;
}
details > p:last-child { margin-bottom: 13px; }
details > p b { color: var(--ink); }

@media print {
  #p-guia { display: none !important; }
}
