/* Herramienta de patio para el celular. Lista de matrices como fichas apiladas; cada matriz abre su ficha con la
   historia (relevamientos y reparaciones) y los formularios salen en una hoja desde abajo.
   Tono hormigón con acento madera de encofrado; estados con color semántico + texto.
   Sin estilos en línea: la CSP no permite 'unsafe-inline'. */
:root {
  --bg: #f1f2ef; --panel: #e6e8e3; --card: #ffffff; --ink: #1d2124; --ink-2: #4a5157; --muted: #6c747a;
  --rule: #cfd3cf; --accent: #9a6418; --accent-ink: #ffffff;
  --ok: #2c6aa8; --warn: #9a6a00; --bad: #b8481a; --off: #6c747a;
  --ok-bg: #e3ecf6; --warn-bg: #f6edd8; --bad-bg: #f7e4da; --off-bg: #e6e8e3;
  --rec: #c0341d; --rec-ink: #ffffff;
  --shadow: 0 1px 2px rgba(20, 24, 26, .08);
  --f-display: "Archivo", "Arial Narrow", Arial, sans-serif;
  --f-body: "Source Sans 3", "Segoe UI", Arial, sans-serif;
  --f-data: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #1a1c1d; --panel: #24282a; --card: #2b2f32; --ink: #e8eae7; --ink-2: #c3c8c4; --muted: #9aa19c;
  --rule: #3a3f42; --accent: #d39a4a; --accent-ink: #1a1c1d;
  --ok: #6aa5e6; --warn: #d9a93a; --bad: #ec8257; --off: #9aa19c;
  --ok-bg: #1f2c3a; --warn-bg: #352c17; --bad-bg: #3a241b; --off-bg: #2b2f32;
  --rec: #ec6a4f; --rec-ink: #1a1c1d;
  --shadow: none; color-scheme: dark } }
:root[data-theme="dark"] {
  --bg: #1a1c1d; --panel: #24282a; --card: #2b2f32; --ink: #e8eae7; --ink-2: #c3c8c4; --muted: #9aa19c;
  --rule: #3a3f42; --accent: #d39a4a; --accent-ink: #1a1c1d;
  --ok: #6aa5e6; --warn: #d9a93a; --bad: #ec8257; --off: #9aa19c;
  --ok-bg: #1f2c3a; --warn-bg: #352c17; --bad-bg: #3a241b; --off-bg: #2b2f32;
  --rec: #ec6a4f; --rec-ink: #1a1c1d;
  --shadow: none; 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.45 var(--f-body); overflow-x: hidden; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
.wrap { max-width: 860px; margin: 0 auto; padding-block: max(16px, env(safe-area-inset-top, 0px)) 96px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; gap: 16px; min-width: 0; }
h1, h2, h3 { font-family: var(--f-display); margin: 0; line-height: 1.15; text-wrap: balance; overflow-wrap: anywhere; }
h1 { font-size: 1.6rem; font-weight: 800; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0; }
.mono, .num { font-family: var(--f-data); font-variant-numeric: tabular-nums; }
.eyebrow { font: 500 .72rem/1.2 var(--f-data); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; }
.between { justify-content: space-between; }
.end { justify-content: flex-end; }
.top { align-items: flex-start; }
.stack { display: grid; gap: 10px; min-width: 0; }
.stack.tight { gap: 4px; }
.self-start { justify-self: start; }
.full { grid-column: 1 / -1; }
.normal { font-weight: 400; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center; text-decoration: none;
  border: 1px solid var(--rule); background: var(--card); color: var(--ink); border-radius: 8px; padding: 10px 14px; font-weight: 600; cursor: pointer; min-height: 44px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.danger.fill { background: var(--bad); color: var(--card); }
.btn.small { min-height: 44px; padding: 6px 12px; font-size: .92rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 20px; height: 20px; flex: none; }
.link { background: none; border: 0; padding: 10px 2px; min-height: 44px; color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link.quiet { color: var(--muted); }

/* Barra superior */
.barra { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.barra .quien { font-size: .92rem; color: var(--ink-2); min-width: 0; overflow-wrap: anywhere; }
.barra .quien b { color: var(--ink); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.tile { background: var(--panel); border-radius: 8px; padding: 12px; display: grid; gap: 2px; text-align: left; border: 1px solid transparent; cursor: pointer; min-height: 44px; }
.tile[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.tile b { font: 700 1.5rem/1 var(--f-display); font-variant-numeric: tabular-nums; }
.tile span { font-size: .85rem; color: var(--ink-2); }
@media (max-width: 420px) { .tiles { grid-template-columns: 1fr 1fr; } }

.filters { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
@media (max-width: 420px) { .filters { grid-template-columns: 1fr; } }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--rule); background: var(--card); border-radius: 8px; padding: 10px 12px; min-height: 44px; min-width: 0; }
textarea.input { min-height: 96px; resize: vertical; }
textarea.input.corta { min-height: 72px; }
label.field { display: grid; gap: 4px; font-size: .92rem; min-width: 0; }
label.field > span:first-child, .rotulo { font-weight: 600; color: var(--ink-2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

.group h3 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; padding-block: 6px; }
.group h3 .muted { font: 400 .8rem var(--f-data); }
.list { display: grid; gap: 8px; }
.card { background: var(--card); border: 1px solid var(--rule); border-radius: 10px; box-shadow: var(--shadow); min-width: 0; }
.mcard { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 8px 12px 8px 8px; width: 100%; text-align: left; cursor: pointer; color: inherit; text-decoration: none; }
.mcard:hover { border-color: var(--accent); }
.thumb { width: 64px; height: 64px; border-radius: 6px; background: var(--panel); object-fit: cover; display: grid; place-items: center; color: var(--muted); font: 500 .7rem var(--f-data); overflow: hidden; }
.mcard .who { min-width: 0; }
.mcard .code { font: 600 1rem var(--f-data); overflow-wrap: anywhere; }
.mcard .sub { font-size: .88rem; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 420px) { .mcard { grid-template-columns: 56px minmax(0, 1fr); } .mcard .thumb { width: 56px; height: 56px; } .mcard .chips { grid-column: 2; justify-content: flex-start; } }
.chips:empty { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 9px; font-size: .78rem; font-weight: 600; white-space: nowrap; border: 1px solid currentColor; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.c-ok { color: var(--ok); background: var(--ok-bg); }
.c-warn { color: var(--warn); background: var(--warn-bg); }
.c-bad { color: var(--bad); background: var(--bad-bg); }
.c-off { color: var(--off); background: var(--off-bg); }
@media (prefers-reduced-motion: no-preference) { .chip.vivo::before { animation: latido 1.2s ease-in-out infinite; } @keyframes latido { 50% { opacity: .25; } } }

.head { display: grid; gap: 6px; }
.titulo-matriz { font-size: 1.5rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; background: var(--card); border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; margin: 0; }
.facts div { background: var(--card); box-shadow: 0 0 0 .5px var(--rule); padding: 10px 12px; display: grid; gap: 2px; min-width: 0; }
.facts dt { font-size: .78rem; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }

.timeline { display: grid; gap: 10px; }
.entry { padding: 12px; display: grid; gap: 8px; }
.entry .meta { font-size: .85rem; color: var(--muted); }
.entry p { overflow-wrap: anywhere; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.photos.portada { grid-template-columns: minmax(0, 320px); }
.photos button { padding: 0; border: 0; background: var(--panel); border-radius: 6px; overflow: hidden; aspect-ratio: 1; cursor: zoom-in; max-width: 100%; }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.detail { display: grid; gap: 6px; border-top: 1px solid var(--rule); padding-top: 8px; }
.notice { border-left: 4px solid var(--accent); background: var(--panel); border-radius: 0 8px 8px 0; padding: 12px 14px; font-size: .95rem; display: grid; gap: 6px; }
.notice.bad { border-color: var(--bad); }
.notice.ok { border-color: var(--ok); }
.empty { padding: 24px 16px; text-align: center; color: var(--muted); background: var(--panel); border-radius: 10px; display: grid; gap: 6px; }
details.dictado-orig summary { cursor: pointer; color: var(--muted); font-size: .88rem; min-height: 32px; display: flex; align-items: center; }
details.dictado-orig p { font-size: .9rem; color: var(--ink-2); padding-top: 4px; white-space: pre-wrap; }
.titulo-sec { font-size: .95rem; }

/* Hoja de formularios */
.sheet-bg { position: fixed; inset: 0; background: rgba(10, 12, 13, .45); z-index: 40; display: grid; align-items: end; justify-items: center; }
.sheet { background: var(--bg); width: min(720px, 100%); max-height: calc(100% - 24px - env(safe-area-inset-top, 0px)); overflow-y: auto; overflow-x: hidden; border-radius: 14px 14px 0 0;
  padding-block: 16px calc(16px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; gap: 14px; overscroll-behavior: contain; }
.sheet > * { min-width: 0; }
fieldset.limpio { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.limpio legend { font-weight: 600; color: var(--ink-2); margin-bottom: 6px; padding: 0; }
.seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 6px; }
.seg label { border: 1px solid var(--rule); border-radius: 8px; padding: 10px; display: flex; gap: 8px; align-items: center; cursor: pointer; background: var(--card); min-height: 44px; }
.seg input { accent-color: var(--accent); width: 20px; height: 20px; flex: none; margin: 0; }
.seg label:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pending { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 6px; }
.pending:empty { display: none; }
.pending figure { margin: 0; position: relative; aspect-ratio: 1; border-radius: 6px; overflow: hidden; background: var(--panel); }
.pending img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pending .x { position: absolute; top: 2px; right: 2px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; font-weight: 700; font-size: 1.1rem; cursor: pointer; }
.pending .avance { position: absolute; inset: auto 0 0 0; height: 6px; background: rgba(0,0,0,.35); }
.pending .avance i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.pending figure.subida::after { content: "✓"; position: absolute; left: 6px; bottom: 8px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--ok); color: var(--card); font-weight: 700; font-size: .8rem; }
.pending figure.fallo { outline: 3px solid var(--bad); outline-offset: -3px; }
.dano { background: var(--panel); border-radius: 10px; padding: 12px; display: grid; gap: 8px; min-width: 0; }
.dano .pending figure { background: var(--card); }
.ia { background: var(--panel); border: 1px dashed var(--accent); border-radius: 10px; padding: 12px; display: grid; gap: 8px; min-width: 0; }
.dictar { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.dictar svg { width: 14px; height: 14px; flex: none; }
.check { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; min-height: 44px; padding-block: 8px; cursor: pointer; }
.check input { width: 24px; height: 24px; margin: 0; accent-color: var(--accent); }
.check.fuerte { font-weight: 600; }
.err { color: var(--bad); font-size: .9rem; font-weight: 600; }
.err:empty { display: none; }
.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.pie-hoja { position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom, 0px)); background: var(--bg); padding-block: 10px calc(10px + env(safe-area-inset-bottom, 0px)); margin-bottom: calc(-16px - env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--rule); display: grid; gap: 8px; }

/* Audio */
.audio { display: grid; gap: 6px; }
.audio-fila { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.audio-btn { min-height: 52px; padding-inline: 18px; font-size: 1.02rem; flex: 1 1 200px; max-width: 320px; }
.audio.grabando .audio-btn { background: var(--rec); border-color: var(--rec); color: var(--rec-ink); }
@media (prefers-reduced-motion: no-preference) { .audio.grabando .audio-btn svg { animation: latido 1s ease-in-out infinite; } }
.audio-estado { color: var(--ink-2); }
.audio-estado:empty { display: none; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 60; display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top, 0px)) 16px max(16px, env(safe-area-inset-bottom, 0px)); }
.lightbox img { max-width: 100%; max-height: 80vh; object-fit: contain; border-radius: 6px; }
.lightbox .cap { color: #eee; margin-top: 10px; text-align: center; max-width: 60ch; }
.lightbox .close { position: absolute; top: max(12px, env(safe-area-inset-top, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(16px, env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 70; font-weight: 600; max-width: calc(100% - 32px); }
@media (prefers-reduced-motion: no-preference) { .sheet { animation: up .18s ease-out; } @keyframes up { from { transform: translateY(24px); opacity: .6; } } }

/* Ingreso */
.ingreso { max-width: 440px; width: 100%; margin: 0 auto; display: grid; gap: 16px; }
.personas { display: grid; gap: 8px; }
.persona { min-height: 56px; justify-content: flex-start; font-size: 1.08rem; padding-inline: 16px; }
.persona .inicial { width: 32px; height: 32px; border-radius: 50%; background: var(--panel); color: var(--ink-2); display: grid; place-items: center; font: 700 .9rem var(--f-display); flex: none; }
.puntos { display: flex; justify-content: center; gap: 14px; min-height: 28px; padding-block: 6px; }
.puntos i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink-2); }
.puntos i.lleno { background: var(--ink); border-color: var(--ink); }
.teclado { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tecla { min-height: 64px; font: 600 1.6rem var(--f-data); border-radius: 12px; }
.tecla.chica { font: 600 1rem var(--f-body); }
.teclado .entrar { grid-column: 1 / -1; min-height: 56px; font-size: 1.1rem; }

/* Administración */
.usuarios { display: grid; gap: 8px; }
.usuario { padding: 12px; display: grid; gap: 8px; }
.usuario.inactivo { opacity: .7; }
.pin-grande { font: 600 2rem/1.1 var(--f-data); letter-spacing: .2em; padding: 12px; background: var(--card); border: 1px solid var(--rule); border-radius: 8px; text-align: center; }
.enlace-personal { font: .85rem var(--f-data); background: var(--card); border: 1px solid var(--rule); border-radius: 8px; padding: 8px 10px; overflow-wrap: anywhere; }
