:root {
  --teal: #0f766e;
  --teal-d: #0b5d57;
  --teal-l: #d9efec;
  --bg: #f3f6f5;
  --card: #ffffff;
  --ink: #16211f;
  --muted: #5b6a67;
  --line: #dfe6e4;
  --danger: #b42318;
  --danger-l: #fde8e6;
  --ok: #067647;
  --warn: #b54708;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  overscroll-behavior-y: contain;
}
body.plain { background: var(--bg); }
body.lock { overflow: hidden; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.noscript { padding: 1rem; text-align: center; }

/* ---------- Estructura ---------- */
#app { max-width: 680px; margin: 0 auto; min-height: 100vh; padding: calc(var(--safe-t) + 14px) 14px calc(170px + var(--safe-b)); }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 2px 14px; }
.view-head .sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 2px rgba(15, 40, 36, .04); margin-bottom: 14px; }
.card > h2 { margin-bottom: 10px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 18px 2px 8px; }
.section-title h2 { font-size: 1.05rem; }
.card .section-title { margin-top: 0; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--teal);
  background: var(--teal); color: #fff; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-busy="true"] { opacity: .6; cursor: default; }
.btn.ghost { background: #fff; color: var(--teal-d); border-color: var(--line); }
.btn.soft { background: var(--teal-l); color: var(--teal-d); border-color: transparent; }
.btn.danger { background: #fff; color: var(--danger); border-color: #f1c4bf; }
.btn.block { display: flex; width: 100%; }
.btn.sm { min-height: 40px; padding: 0 14px; border-radius: 12px; font-size: .92rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row > .btn { flex: 1 1 140px; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: #fff; display: inline-grid; place-items: center; cursor: pointer; font-size: 1.2rem; }

/* ---------- Formularios ---------- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: .88rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field input, .field select, .field textarea, .input {
  width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid #c8d3d0; border-radius: 12px; background: #fff;
}
.field input:focus, .field select:focus, .input:focus, .field textarea:focus { outline: 3px solid rgba(15, 118, 110, .25); border-color: var(--teal); }
.err { color: var(--danger); background: var(--danger-l); padding: 10px 12px; border-radius: 12px; margin: 0 0 12px; font-weight: 600; }
.notice { background: var(--teal-l); color: var(--teal-d); padding: 10px 12px; border-radius: 12px; margin-bottom: 12px; }

/* ---------- Login / Setup ---------- */
.login { max-width: 420px; margin: 8vh auto 0; }
.login .logo { width: 84px; height: 84px; margin: 0 auto 14px; border-radius: 22px; }
.login h1 { text-align: center; margin-bottom: 4px; }
.login .lead { text-align: center; color: var(--muted); margin-bottom: 18px; }
.setup { max-width: 520px; margin: 0 auto; padding: 24px 14px 60px; }
.checks { list-style: none; padding: 0; margin: 0 0 16px; font-size: .92rem; }
.checks li { padding: 3px 0; }
.checks .ok { color: var(--ok); } .checks .bad { color: var(--danger); font-weight: 700; } .checks .warn { color: var(--warn); }

/* ---------- Estadísticas ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 14px 12px;
  cursor: pointer; box-shadow: 0 1px 2px rgba(15, 40, 36, .04);
}
.stat .n { font-size: 2.1rem; font-weight: 800; line-height: 1; color: var(--teal-d); letter-spacing: -.02em; }
.stat .t { font-weight: 700; margin-top: 6px; }
.stat .l { color: var(--muted); font-size: .82rem; }
.stat.active { border-color: var(--teal); outline: 2px solid rgba(15, 118, 110, .25); }
.stat.wide { grid-column: span 2; }

.chart { display: grid; grid-template-columns: repeat(12, 1fr); gap: 5px; align-items: end; height: 120px; margin-top: 8px; }
.chart .col { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 4px; background: none; border: 0; padding: 0; cursor: pointer; }
.chart .bar { width: 100%; min-height: 3px; background: #b7d9d4; border-radius: 6px 6px 3px 3px; }
.chart .col.cur .bar { background: var(--teal); }
.chart .col.sel .bar { background: var(--teal-d); }
.chart .v { font-size: .72rem; color: var(--muted); font-weight: 700; height: 14px; }
.chart-lbls { display: grid; grid-template-columns: repeat(12, 1fr); gap: 5px; text-align: center; font-size: .68rem; color: var(--muted); margin-top: 4px; }
.year-nav { display: flex; align-items: center; gap: 6px; }
.year-nav b { min-width: 3.4rem; text-align: center; }

/* ---------- Galería ---------- */
.day { margin: 14px 0 6px; display: flex; justify-content: space-between; align-items: baseline; }
.day b { font-size: .98rem; }
.day span { color: var(--muted); font-size: .85rem; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
@media (min-width: 520px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.thumb { position: relative; padding: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #e8eeec; aspect-ratio: 3 / 4; cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .tm { position: absolute; left: 4px; bottom: 4px; background: rgba(0, 0, 0, .62); color: #fff; font-size: .72rem; padding: 1px 7px; border-radius: 99px; font-weight: 600; }
.thumb .ck { position: absolute; right: 4px; top: 4px; background: var(--ok); color: #fff; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; font-weight: 800; }
.thumb .nt { position: absolute; right: 4px; bottom: 4px; background: rgba(255, 255, 255, .92); border-radius: 99px; font-size: .75rem; padding: 0 6px; }
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty .big { font-size: 2.6rem; }

.seg { display: flex; background: #e6edeb; border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; min-height: 42px; border: 0; background: transparent; border-radius: 10px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: #fff; color: var(--teal-d); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line); background: #fff; font-weight: 600; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--teal); color: #fff; border-color: var(--teal); }

/* ---------- Navegación inferior y botón flotante ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center;
  background: rgba(255, 255, 255, .96); border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
  backdrop-filter: blur(8px);
}
.nav-in { display: flex; width: 100%; max-width: 680px; }
.nav button { flex: 1; border: 0; background: none; padding: 9px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: .76rem; font-weight: 700; cursor: pointer; min-height: 58px; }
.nav button .ic { font-size: 1.35rem; line-height: 1; }
.nav button[aria-current="page"] { color: var(--teal-d); }
.fab {
  position: fixed; z-index: 21; right: max(16px, calc(50% - 340px + 16px)); bottom: calc(76px + var(--safe-b));
  min-height: 58px; padding: 0 22px; border-radius: 99px; border: 0; background: var(--teal); color: #fff; font-weight: 800; font-size: 1.05rem;
  box-shadow: 0 6px 18px rgba(15, 118, 110, .45); display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
}
.fab:active { transform: scale(.97); }
.link-btn { background: none; border: 0; color: var(--teal-d); text-decoration: underline; font-weight: 600; padding: 8px 2px; cursor: pointer; }

/* ---------- Visor ---------- */
.viewer { position: fixed; inset: 0; z-index: 50; background: #0d1412; color: #fff; display: flex; flex-direction: column; }
.viewer .vt { display: flex; align-items: center; gap: 10px; padding: calc(var(--safe-t) + 8px) 12px 8px; }
.viewer .vt .ttl { flex: 1; min-width: 0; }
.viewer .vt .ttl b { display: block; font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer .vt .ttl span { font-size: .8rem; color: #a8bbb7; }
.viewer .icon-btn { background: rgba(255, 255, 255, .12); border-color: transparent; color: #fff; }
.viewer .stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; touch-action: pan-y pinch-zoom; }
.viewer .stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .nv { position: absolute; top: 50%; transform: translateY(-50%); width: 46px; height: 64px; border: 0; border-radius: 12px; background: rgba(0, 0, 0, .4); color: #fff; font-size: 1.6rem; cursor: pointer; }
.viewer .nv.l { left: 6px; } .viewer .nv.r { right: 6px; }
.viewer .panel { background: #fff; color: var(--ink); border-radius: 20px 20px 0 0; padding: 14px 14px calc(14px + var(--safe-b)); max-height: 52vh; overflow: auto; }
.viewer .panel .row2 { display: grid; grid-template-columns: 1fr; gap: 8px; }
.sentline { display: inline-flex; gap: 6px; align-items: center; color: var(--ok); font-weight: 700; font-size: .88rem; margin-bottom: 8px; }

/* ---------- Hoja inferior (sheet) ---------- */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(8, 20, 18, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 680px; background: #fff; border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); max-height: 90vh; overflow: auto; }
.sheet h2 { margin-bottom: 12px; font-size: 1.2rem; }

/* ---------- Avisos ---------- */
#toasts { position: fixed; left: 0; right: 0; top: calc(var(--safe-t) + 10px); z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.toast { background: #17302c; color: #fff; padding: 12px 16px; border-radius: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); max-width: 520px; font-weight: 600; }
.toast.bad { background: var(--danger); }
.toast.good { background: var(--ok); }
.banner { background: #fff7e6; border: 1px solid #f5d79b; color: #7a4a00; padding: 12px 14px; border-radius: 14px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.progress { height: 8px; background: #dbe7e4; border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; background: var(--teal); width: 0; transition: width .2s; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .45); border-top-color: #fff; animation: spin .8s linear infinite; display: inline-block; }
.btn.ghost .spinner, .btn.soft .spinner { border-color: rgba(15, 118, 110, .25); border-top-color: var(--teal); }
@keyframes spin { to { transform: rotate(360deg); } }
.result { border: 1px solid #b6dfc9; background: #effaf4; border-radius: 14px; padding: 14px; margin-top: 14px; }
.result b { color: var(--ok); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.trash-item { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.trash-item img { width: 56px; height: 74px; object-fit: cover; border-radius: 8px; }
.trash-item .meta { flex: 1; min-width: 0; font-size: .9rem; }
.prevstrip { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 2px; }
.prevstrip img { height: 78px; width: 58px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); flex: none; }
.meter { height: 8px; background: #dbe7e4; border-radius: 99px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--teal); }

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

/* v1.1: búsqueda y seguridad */
.searchbar { display: flex; gap: 8px; margin: 14px 0 0; }
.searchbar .input { flex: 1; min-width: 0; }
.seclist { list-style: none; margin: 0; padding: 0; }
.seclist li { display: flex; flex-direction: column; padding: 8px 0; border-top: 1px solid var(--line); font-size: .9rem; }
.seclist li span { color: var(--muted); font-size: .82rem; }
.seclist li.bad b { color: #b42318; }
