/* Bitácora RESET — sobria, texto grande y contraste alto (se lee bien a los 50 sin gafas) */
:root {
  --bg: #f6f3ec;
  --card: #ffffff;
  --ink: #17211f;
  --muted: #55625f;
  --line: #d9d4c7;
  --brand: #0f3d3a;
  --brand-ink: #ffffff;
  --accent: #b45309;
  --on: #0f766e;
  --on-soft: #cfe7e3;
  --off: #e8d9b8;
  --warn: #9a3412;
  --warn-bg: #fdeede;
  --ok-bg: #e3f1ee;
  --focus: #1d4ed8;
  --radius: 14px;
  --tab-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1514;
    --card: #162120;
    --ink: #eef2f0;
    --muted: #a3b2ae;
    --line: #2b3b39;
    --brand: #2dd4bf;
    --brand-ink: #062a27;
    --accent: #f59e0b;
    --on: #2dd4bf;
    --on-soft: #1b4a45;
    --off: #5a4a28;
    --warn: #fdba74;
    --warn-bg: #3a2412;
    --ok-bg: #123631;
    --focus: #93c5fd;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 18px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
body.no-tabs { padding-bottom: 0; }
h1 { font-size: 1.55rem; margin: 0 0 .25rem; line-height: 1.2; }
h2 { font-size: 1.2rem; margin: 1.6rem 0 .6rem; }
h3 { font-size: 1.02rem; margin: 0; }
p { margin: .5rem 0; }
a { color: var(--on); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.hidden { display: none !important; }

.wrap { max-width: 600px; margin: 0 auto; padding: calc(16px + env(safe-area-inset-top)) 16px 24px; }
.wrap.wide { max-width: 1100px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 12px 0;
}
.card.warn { background: var(--warn-bg); border-color: var(--warn); color: var(--ink); }
.card.ok { background: var(--ok-bg); }

/* botones */
button, .btn {
  font: inherit; font-weight: 600; min-height: 48px; padding: 10px 18px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; text-decoration: none;
}
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-danger { border-color: var(--warn); color: var(--warn); }
.btn-block { width: 100%; }
.btn-small { min-height: 40px; padding: 6px 12px; font-size: .92rem; }
.btn-link { border: 0; background: none; min-height: 40px; color: var(--on); text-decoration: underline; padding: 6px 4px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }

/* formularios */
label { display: block; font-weight: 600; margin: 14px 0 6px; }
input[type=text], input[type=email], input[type=date], input[type=number], select, textarea {
  font: inherit; width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--card); color: var(--ink);
}
textarea { min-height: 84px; resize: vertical; }
.code-input { font-size: 1.8rem; letter-spacing: .25em; text-align: center; text-transform: uppercase; font-weight: 700; }
.err { color: var(--warn); font-weight: 600; margin: 10px 0; min-height: 1.2em; }
.check { display: flex; gap: 12px; align-items: flex-start; font-weight: 500; margin: 14px 0; }
.check input { width: 26px; height: 26px; flex: none; margin-top: 2px; accent-color: var(--on); }

/* acceso */
.hero { text-align: center; padding-top: 6vh; }
.hero img { width: 84px; height: 84px; border-radius: 20px; }
.tagline { color: var(--muted); }

/* barra inferior */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line); display: flex;
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .78rem; font-weight: 600;
}
.tabbar a svg { width: 26px; height: 26px; }
.tabbar a[aria-current=page] { color: var(--on); }

/* cabecera de día */
.daybar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.daybar .title { text-align: center; flex: 1; }
.daybar .title b { display: block; font-size: 1.15rem; }
.daybar .title b::first-letter { text-transform: uppercase; }
.iconbtn { min-width: 48px; padding: 0; }
.weekpill { display: inline-block; background: var(--ok-bg); border-radius: 999px; padding: 2px 12px; font-size: .85rem; font-weight: 600; }

.seg { display: flex; border: 2px solid var(--line); border-radius: 14px; overflow: hidden; margin: 12px 0; background: var(--card); }
.seg button { flex: 1; border: 0; border-radius: 0; background: transparent; min-height: 52px; }
.seg button[aria-selected=true] { background: var(--brand); color: var(--brand-ink); }
.seg .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--on); display: inline-block; }

/* campos de registro */
.sys-title { font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 0 4px; font-weight: 700; }
.field { padding: 14px 0; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field .q { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.field .tag { font-weight: 600; font-size: .75rem; background: var(--warn-bg); color: var(--warn); padding: 1px 8px; border-radius: 999px; align-self: center; white-space: nowrap; }
.field .help { color: var(--muted); font-size: .88rem; margin: 2px 0 8px; }
.yn { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.yn button { min-height: 54px; font-size: 1.05rem; }
.yn button[aria-pressed=true].yes { background: var(--on); border-color: var(--on); color: var(--brand-ink); }
.yn button[aria-pressed=true].no  { background: var(--off); border-color: var(--off); color: var(--ink); }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 8px; }
.scale button { min-height: 52px; font-size: 1.15rem; padding: 0; }
.scale button[aria-pressed=true] { background: var(--on); border-color: var(--on); color: var(--brand-ink); }
.stepper { display: flex; gap: 8px; align-items: stretch; margin-top: 8px; }
.stepper button { min-width: 56px; font-size: 1.5rem; padding: 0; }
.stepper input { text-align: center; font-size: 1.3rem; font-weight: 700; flex: 1; min-width: 0; }
.savestate { text-align: center; color: var(--muted); font-size: .9rem; min-height: 1.4em; margin-top: 8px; }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 6px 0 2px; }
.progress i { display: block; height: 100%; background: var(--on); }

/* gráficos */
.chartcard h3 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.chartcard .big { font-size: 1.5rem; font-weight: 700; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .88rem; color: var(--muted); margin: 4px 0; }
.legend i { display: inline-block; width: 22px; height: 0; border-top: 3px solid; vertical-align: middle; margin-right: 6px; }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
svg.chart .grid { stroke: var(--line); stroke-width: 1; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.chips button { min-height: 40px; padding: 4px 14px; border-radius: 999px; }
.chips button[aria-pressed=true] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.stats { display: flex; gap: 18px; flex-wrap: wrap; margin: 6px 0; }
.stats b { font-size: 1.2rem; }

/* tira / cuadrícula de días (hecho, no hecho, sin registro) */
.daygrid { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 14px); grid-auto-columns: 14px; gap: 3px; margin-top: 8px; overflow-x: auto; padding-bottom: 4px; }
.cell { border-radius: 3px; border: 1px dashed var(--line); }
.cell.on { background: var(--on); border: 0; }
.cell.off { background: var(--off); border: 0; }
.cell.pad { border: 0; }
.keys { display: flex; gap: 14px; font-size: .82rem; color: var(--muted); flex-wrap: wrap; margin-top: 6px; }
.keys i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 5px; }

/* panel de administración */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover { background: var(--ok-bg); }
.strip { display: inline-flex; gap: 2px; }
.strip i { width: 9px; height: 22px; border-radius: 2px; background: transparent; border: 1px dashed var(--line); display: block; }
.alerts { color: var(--warn); font-size: .88rem; font-weight: 600; }
.badge { display: inline-block; border-radius: 999px; padding: 1px 10px; font-size: .78rem; font-weight: 700; background: var(--ok-bg); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.heat { border-collapse: separate; border-spacing: 2px; font-size: .78rem; }
.heat th { font-weight: 600; color: var(--muted); padding: 0 1px; text-align: center; }
.heat th.lbl, .heat td.lbl { text-align: left; position: sticky; left: 0; background: var(--card); padding-right: 10px; min-width: 150px; max-width: 190px; z-index: 1; font-size: .85rem; }
.heat td.c { width: 22px; height: 22px; min-width: 22px; border-radius: 4px; border: 1px dashed var(--line); }
.heat td.c.on { background: var(--on); border: 0; }
.heat td.c.off { background: var(--off); border: 0; }
.heat td.c.wk th { color: var(--accent); }
.heat .sep { border-left: 2px solid var(--muted); }
.scroll-x { overflow-x: auto; }
.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 120px; margin-top: 8px; }
.bars div { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: .8rem; }
.bars i { display: block; width: 100%; background: var(--on); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars span { margin-top: 4px; font-weight: 600; }
.note { padding: 8px 0; border-bottom: 1px solid var(--line); }
.note .meta { font-size: .8rem; color: var(--muted); font-weight: 600; }
.codebox { font-size: 2rem; font-weight: 800; letter-spacing: .2em; text-align: center; padding: 14px; background: var(--ok-bg); border-radius: 12px; margin: 10px 0; user-select: all; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px 16px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + 24px + env(safe-area-inset-bottom)); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; z-index: 30; max-width: 90vw; }

.privacy h3 { margin-top: 14px; }
.privacy p, .privacy li { font-size: .98rem; }
.privacy ul { padding-left: 1.2rem; margin: 4px 0; }

@media (min-width: 760px) {
  .tabbar { max-width: 600px; left: 50%; transform: translateX(-50%); border-radius: 16px 16px 0 0; border: 1px solid var(--line); }
}
@media print {
  .tabbar, .noprint, button, .toast { display: none !important; }
  body { background: #fff; color: #000; padding: 0; }
  .card { break-inside: avoid; border-color: #999; }
  .wrap.wide { max-width: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .progress i { transition: width .3s ease; }
}

/* añadidos */
.linkcard { display: block; color: inherit; text-decoration: none; }
.linkcard:hover { border-color: var(--on); }
.heat td.c { text-align: center; font-size: .68rem; }
.heat td.c.sep, .heat th.sep { border-left: 2px solid var(--muted); }

.chartgrid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.chartgrid .card { margin: 0; }
