:root {
  --bg: #f5f6f8; --panel: #fff; --text: #1d2228; --muted: #6b7480; --line: #e2e5ea; --line2: #c9ced6;
  --accent: #c8102e; --accent-soft: #fdecee; --nav: #1d2228;
  --ok: #1b7f3b; --ok-soft: #e5f4ea; --ko: #b42318; --ko-soft: #fdecea;
  --warn: #9a6700; --warn-soft: #fff4d6; --na: #57606a; --na-soft: #eef0f2; --info: #1f5fad; --info-soft: #e8f0fb;
  --adv: #6f42c1; --adv-soft: #f1ebfb;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: inherit; }
a.link { color: var(--info); text-decoration: none; }
a.link:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 12px; margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
code { background: #eef0f2; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.mt { margin-top: 16px; } .mb { margin-bottom: 12px; }

/* cabecera */
.top { display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 48px; background: var(--nav); color: #fff; position: sticky; top: 0; z-index: 30; }
.top .brand { font-weight: 700; text-decoration: none; letter-spacing: .02em; white-space: nowrap; }
.top .brand span { color: #ff5a6e; }
.top .prog select { background: #2c333b; color: #fff; border: 1px solid #444c56; border-left: 4px solid var(--accent); padding: 4px 8px; font-size: 13px; }
.top .prog-nombre { font-size: 13px; color: #fff; border-left: 4px solid var(--accent); padding: 2px 8px; white-space: nowrap; }
.top nav { display: flex; gap: 2px; overflow-x: auto; }
.top nav a { color: #cfd5dc; text-decoration: none; padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.top nav a:hover, .top nav a.on { color: #fff; background: #2f363e; }
.top .user { margin-left: auto; display: flex; gap: 10px; align-items: center; color: #cfd5dc; font-size: 13px; white-space: nowrap; }
.top .user form { margin: 0; }
.top .user button { background: none; border: 1px solid #444c56; color: #cfd5dc; border-radius: 6px; padding: 3px 8px; cursor: pointer; font: inherit; }
.wrap { padding: 18px 20px 48px; max-width: 1600px; margin: 0 auto; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { text-decoration: none; } .crumbs a:hover { text-decoration: underline; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }

/* avisos */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 10px; border: 1px solid transparent; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--ko-soft); color: var(--ko); }
.flash.clave { background: var(--warn-soft); color: #6b4800; border-color: #f2d58a; font-weight: 600; }
.alerta { padding: 8px 12px; border-radius: 6px; background: var(--ko-soft); color: var(--ko); margin-bottom: 6px; font-size: 13px; }
.aviso { padding: 8px 12px; border-radius: 6px; background: var(--warn-soft); color: var(--warn); margin-bottom: 10px; font-size: 13px; }
.nota { padding: 8px 12px; border-radius: 6px; background: var(--info-soft); color: var(--info); margin-bottom: 10px; font-size: 13px; }

/* paneles, tablas */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.panel.p0 { padding: 0; overflow: hidden; }
.panel > h2:first-child { margin-top: 0; }
table.grid { width: 100%; border-collapse: collapse; background: var(--panel); }
table.grid th, table.grid td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.grid th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
table.grid th a { text-decoration: none; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover td { background: #fafbfc; }
tr[data-href] { cursor: pointer; }
.thumb { width: 84px; height: 63px; object-fit: cover; border-radius: 4px; background: #eee; display: block; }
.thumb.sm { width: 56px; height: 42px; }

.stats { display: flex; gap: 12px; flex-wrap: wrap; margin: 4px 0 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; min-width: 140px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.ok b { color: var(--ok); } .stat.warn b { color: var(--warn); } .stat.bad b { color: var(--ko); }

/* formularios */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], input[type=time], input[type=date], select, textarea {
  padding: 7px 9px; border: 1px solid var(--line2); border-radius: 6px; background: #fff; font: inherit; color: inherit; max-width: 100%; }
textarea { width: 100%; min-height: 64px; resize: vertical; }
textarea.code { font: 12px/1.4 ui-monospace, Consolas, monospace; min-height: 60vh; }
label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; font-weight: 600; }
label.chk { display: inline-flex; gap: 6px; align-items: center; margin-right: 12px; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 6px; border: 1px solid var(--line2); background: #fff; cursor: pointer; font: inherit; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: #9aa3ad; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--ko); border-color: #f1b5ae; }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn[disabled], .btn.disabled { opacity: .45; pointer-events: none; }
form.inline { display: inline; margin: 0; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-ok, .b-cumple, .b-completa { background: var(--ok-soft); color: var(--ok); }
.b-bad, .b-no_cumple, .b-error, .b-cancelado { background: var(--ko-soft); color: var(--ko); }
.b-warn, .b-pendiente, .b-avisos, .b-en_curso, .b-cancelando { background: var(--warn-soft); color: var(--warn); }
.b-sin, .b-en_cola { background: var(--na-soft); color: var(--na); }
.b-ejecutando, .b-info { background: var(--info-soft); color: var(--info); }
.b-adv { background: var(--adv-soft); color: var(--adv); }
.pctc { font-weight: 700; font-variant-numeric: tabular-nums; }
.pctc.ok { color: var(--ok); } .pctc.warn { color: var(--warn); } .pctc.bad { color: var(--ko); } .pctc.sin { color: var(--muted); }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; min-width: 70px; }
.bar i { display: block; height: 100%; background: var(--ok); }
.bar.ko i { background: var(--ko); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button, .tabs a { border: 0; background: none; padding: 8px 14px; font: inherit; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; text-decoration: none; }
.tabs .on { color: var(--text); border-color: var(--accent); font-weight: 600; }
.tab { display: none; } .tab.on { display: block; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.chip { background: #eef0f2; border-radius: 4px; padding: 1px 7px; font-size: 12px; text-decoration: none; }

/* ficha */
.ficha-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
dl.kv { display: grid; grid-template-columns: 44% 1fr; gap: 4px 10px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; word-break: break-word; }
.equip { columns: 2 260px; column-gap: 20px; font-size: 13px; margin: 0; padding-left: 18px; }
.equip li { break-inside: avoid; margin-bottom: 2px; }
details.eq { border-top: 1px solid var(--line); padding: 8px 0; }
details.eq summary { cursor: pointer; font-weight: 600; }

/* galería */
.gal { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.gal figure { margin: 0; position: relative; }
.gal img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 6px; cursor: zoom-in; display: block; background: #eee; }
.gal figcaption { font-size: 11px; color: var(--muted); padding: 2px 2px 0; }
.gal .mark-add img { outline: 3px solid var(--ok); } .gal .mark-del img { outline: 3px solid var(--ko); opacity: .7; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); display: none; z-index: 60; align-items: center; justify-content: center; }
.lightbox.on { display: flex; }
.lightbox img { max-width: 96vw; max-height: 92vh; }
.lightbox .cap { position: absolute; bottom: 12px; left: 0; right: 0; text-align: center; color: #fff; font-size: 13px; }
.lightbox button { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.12); color: #fff; border: 0; width: 48px; height: 72px; font-size: 30px; cursor: pointer; }
.lightbox .lb-prev { left: 8px; } .lightbox .lb-next { right: 8px; }

/* auditoría */
.aud-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; margin-bottom: 10px; flex-wrap: wrap; }
.resbar { display: grid; grid-template-columns: repeat(2, minmax(150px, 1fr)) auto; gap: 8px; align-items: stretch; position: sticky; top: 48px; z-index: 20; background: var(--bg); padding: 8px 0; }
.res-box { border-radius: 6px; padding: 6px 10px; text-align: center; font-weight: 700; background: var(--na-soft); color: var(--na); }
.res-box small { display: block; font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; opacity: .85; }
.res-box.cumple { background: var(--ok-soft); color: var(--ok); }
.res-box.no_cumple { background: var(--ko-soft); color: var(--ko); }
.res-box.pendiente { background: var(--warn-soft); color: var(--warn); }
.guardado { font-size: 12px; color: var(--muted); align-self: center; min-width: 120px; text-align: right; }
.pregunta { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; box-shadow: var(--shadow); }
.pregunta > header { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.pregunta > header h2 { margin: 0; font-size: 15px; }
.pregunta > header .pid { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.pregunta.completa > header { background: #fafdfb; }
.pregunta.con-no > header { background: #fffafa; }
.textos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px 14px; font-size: 12.5px; border-bottom: 1px solid var(--line); }
.textos div { padding: 6px 8px; border-radius: 6px; background: #f7f8fa; }
.textos b { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
.textos .n2 b { color: var(--adv); }
.unidades { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; padding: 12px 14px; }
.unidad { border: 1px solid var(--line); border-radius: 6px; padding: 6px; background: #fff; }
.unidad.tiene-no { border-color: #f1b5ae; background: #fffafa; }
.unidad img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 4px; cursor: zoom-in; display: block; background: #eee; }
.unidad .nofoto { width: 100%; aspect-ratio: 4/3; border-radius: 4px; background: repeating-linear-gradient(45deg, #f3f4f6, #f3f4f6 8px, #e9ebee 8px, #e9ebee 16px); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.unidad .cap { font-size: 11px; color: var(--muted); margin: 4px 0; min-height: 15px; }
.lv { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 4px; }
.lv > span { font-size: 11px; font-weight: 700; width: 64px; }
.lv.n2 > span { color: var(--adv); }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 4px 9px; font: inherit; font-size: 12px; cursor: pointer; border-left: 1px solid var(--line2); }
.seg button:first-child { border-left: 0; }
.seg button.on[data-v="si"] { background: var(--ok); color: #fff; }
.seg button.on[data-v="no"] { background: var(--ko); color: #fff; }
.seg button.on[data-v="na"] { background: var(--na); color: #fff; }
.seg.auto { box-shadow: 0 0 0 2px #dbe5ff; }
.motivo { display: none; margin-top: 6px; }
.unidad.tiene-no .motivo { display: block; }
.motivo select, .motivo input { width: 100%; font-size: 12px; padding: 4px 6px; margin-top: 3px; }
.ficha-mini { padding: 10px 14px; font-size: 13px; border-bottom: 1px solid var(--line); }
.ficha-mini dl.kv { grid-template-columns: 160px 1fr; }

/* consolidado / impresión */
.fallos { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.fallos figure { margin: 0; font-size: 11px; }
.fallos img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 4px; border: 2px solid var(--ko); }
.evol { display: flex; align-items: flex-end; gap: 10px; height: 140px; padding: 10px 4px 0; }
.evol .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 40px; }
.evol .bars { display: flex; gap: 3px; align-items: flex-end; height: 100px; }
.evol .bars i { display: block; width: 14px; border-radius: 3px 3px 0 0; background: var(--ok); }
.evol .bars i.n2 { background: var(--adv); }
.evol .col span { font-size: 11px; color: var(--muted); white-space: nowrap; }
.leyenda { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.leyenda i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.spark { display: flex; align-items: flex-end; gap: 2px; height: 28px; }
.spark i { display: block; width: 6px; background: #9fb3c8; border-radius: 1px; }
.log { font: 12px/1.45 ui-monospace, Consolas, monospace; background: #0f1419; color: #d6dde5; border-radius: 6px; padding: 10px; max-height: 60vh; overflow: auto; }
.log .error { color: #ff8a80; } .log .aviso { color: #ffd166; } .log .info { color: #b8c4d0; }

.login { max-width: 380px; margin: 9vh auto; }
.login .panel { padding: 22px; }

@media print {
  .top, .noprint, .filters { display: none !important; }
  body { background: #fff; }
  .wrap { padding: 0; max-width: none; }
  .panel { box-shadow: none; break-inside: avoid; }
  .fallos { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 760px) {
  .wrap { padding: 12px 12px 30px; }
  .top { padding: 0 10px; gap: 8px; }
  .top .user span { display: none; }
  .textos { grid-template-columns: 1fr; }
  .resbar { grid-template-columns: 1fr 1fr; }
  table.grid .hide-sm { display: none; }
}
