/* Bitácora RESET — sobria, texto grande y contraste alto (se lee bien a los 50 sin gafas) */
:root {
  /* Marca: negro del logo, crema cálida y el ámbar del amanecer del banner */
  --bg: #f8f2e6;
  --card: #fffcf5;
  --ink: #14120f;
  --muted: #5f584b;
  --line: #e0d7c3;
  --brand: #14120f;        /* botón principal y selección */
  --brand-ink: #f8f2e6;    /* texto sobre --brand y --on */
  --accent: #c26d06;       /* ámbar para gráficos y detalles */
  --accent-ink: #94560a;   /* ámbar legible como texto */
  --on: #14120f;           /* hecho / seleccionado */
  --on-soft: #efe4cc;
  --off: #d9c28f;          /* no hecho (arena) */
  --s1: #14120f;           /* serie 1 de los gráficos */
  --s2: #c26d06;           /* serie 2 de los gráficos */
  --warn: #9a3412;
  --warn-bg: #fdebd9;
  --ok-bg: #efe6d0;
  --focus: #1d4ed8;
  --radius: 14px;
  --tab-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0c0a;
    --card: #17150f;
    --ink: #f4ece1;
    --muted: #aaa192;
    --line: #2f2b22;
    --brand: #f4ece1;
    --brand-ink: #0d0c0a;
    --accent: #f0a43a;
    --accent-ink: #f0a43a;
    --on: #f4ece1;
    --on-soft: #2a261d;
    --off: #6b5a33;
    --s1: #f4ece1;
    --s2: #f0a43a;
    --warn: #fdba74;
    --warn-bg: #35210f;
    --ok-bg: #1e1b14;
    --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(--accent-ink); }
: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(--accent-ink); 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(--accent-ink); }

/* 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(--accent); }

/* 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; }

/* logo RESET: máscara con la marca; el color sigue al tema (tinta en claro, crema en oscuro) */
.logo { display: block; width: 120px; aspect-ratio: 692 / 546; margin: 0 auto 14px; background-color: var(--ink);
  -webkit-mask: url(../icons/mark.png) center / contain no-repeat; mask: url(../icons/mark.png) center / contain no-repeat; }
.logo.logo-sm { width: 64px; margin: 8px 0 14px; }

/* cabecera con el banner (en modo noche se sustituye por la marca sobre negro) */
.banner { position: relative; height: clamp(170px, 30vh, 250px); overflow: hidden; background: #f1e3c8; }
.banner.banner-sm { height: clamp(120px, 20vh, 170px); }
.banner img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 36%; display: block; }
.banner::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 38%; background: linear-gradient(to bottom, transparent, var(--bg)); }
.logo-night { display: none; }
.hero { padding-top: 6px; }
:root[data-mode=dark] .banner { display: none; }
:root[data-mode=dark] .logo-night { display: block; }
:root[data-mode=dark] .hero { padding-top: 6vh; }

/* Ajustes: plantillas de color */
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin: 12px 0; }
.theme-opt { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left; min-height: 0; padding: 10px 12px; border-radius: 14px; border: 2px solid var(--line); background: var(--card); color: var(--ink); }
.theme-opt[aria-checked=true] { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.theme-opt .sw { display: flex; width: 100%; height: 34px; border-radius: 9px; overflow: hidden; border: 1px solid rgba(128,128,128,.35); }
.theme-opt .sw i { flex: 1; display: block; }
.theme-opt b { font-size: 1rem; }
.theme-opt small { color: var(--muted); font-size: .8rem; line-height: 1.2; }

/* Panel: vistas */
.cardgrid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.tablescroll { overflow-x: auto; }
.tablecard { padding: 6px 10px; }
.thbtn { all: unset; cursor: pointer; font: inherit; text-transform: inherit; letter-spacing: inherit; color: inherit; padding: 6px 0; }
.thbtn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.table tr.clickable:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.sect { font-size: 1.15rem; margin: 22px 0 10px; }
.focuscard { border-left: 5px solid var(--warn); }
.okrows { padding: 4px 14px; }
.okrow { display: flex; align-items: center; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; flex-wrap: wrap; }
.okrow:last-child { border-bottom: 0; }
.okrow b { min-width: 130px; }
.okrow .small:last-child { margin-left: auto; font-weight: 700; }
