:root {
  --bg: #f4f6f9; --card: #fff; --ink: #1b2430; --muted: #5d6b7a; --line: #d9e0e8;
  --primary: #1f3b5c; --primary-ink: #fff; --accent: #e85d04;
  --verde: #1f9d55; --verde-bg: #dff5e7; --amarillo: #b98900; --amarillo-bg: #fff4c2;
  --rojo: #c62828; --rojo-bg: #fde0e0;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d; --card: #1a212b; --ink: #e6ebf1; --muted: #9aa7b5; --line: #2c3643;
    --primary: #5b8cc4; --verde-bg: #143524; --amarillo-bg: #3a3110; --rojo-bg: #3d1616;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: 110px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h2 { font-size: 1.1rem; margin: 0 0 .75rem; color: var(--primary); }
h3 { font-size: 1rem; margin: 0; }
h4 { font-size: .95rem; margin: 1rem 0 .5rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.spacer { flex: 1; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1rem; padding-top: calc(.6rem + env(safe-area-inset-top));
  background: #1f3b5c; color: #fff;
}
.topbar .title { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar .title small { opacity: .8; font-size: .75rem; }
.topbar .icon-btn { color: #fff; font-size: 1.4rem; }
.net { font-size: .75rem; padding: .15rem .5rem; border-radius: 99px; white-space: nowrap; }
.net.on { background: var(--verde); }
.net.off { background: var(--rojo); }

.view { max-width: 900px; margin: 0 auto; padding: 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .5rem 0; }
.toolbar.sticky {
  position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0;
  border-top: 1px solid var(--line); margin: 0;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 44px; padding: .5rem 1rem; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--rojo); border-color: var(--rojo); }
.icon-btn { background: none; border: 0; cursor: pointer; font-size: 1.1rem; color: var(--muted); padding: .25rem .5rem; }

label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: .6rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: .25rem; padding: .6rem .7rem; min-height: 44px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: inherit;
}
textarea { resize: vertical; }
input[type=checkbox], input[type=radio] { display: inline-block; width: 1.2rem; height: 1.2rem; min-height: 0; margin: 0; accent-color: var(--accent); vertical-align: middle; }
fieldset { border: 0; padding: 0; margin: .5rem 0 .8rem; }
legend { font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: .35rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0 1rem; }
.grid .wide { grid-column: 1 / -1; }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chips label, .checks label {
  display: inline-flex; align-items: center; gap: .4rem; margin: 0; padding: .45rem .7rem;
  border: 1px solid var(--line); border-radius: 99px; color: var(--ink); font-weight: 500; cursor: pointer;
}
.checks { display: grid; gap: .4rem; }
.checks label { border-radius: 8px; }
.chips label:has(:checked), .checks label:has(:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

.steps {
  position: sticky; top: 58px; z-index: 5; display: flex; gap: .25rem; overflow-x: auto;
  background: var(--bg); padding: .4rem 0; margin: -1rem 0 .5rem; scrollbar-width: none;
}
.steps a { white-space: nowrap; padding: .35rem .7rem; border-radius: 99px; background: var(--card); border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-size: .85rem; }
.ficha { margin: .25rem 0 .75rem; }

.pill { display: inline-block; font-size: .75rem; font-weight: 700; padding: .15rem .55rem; border-radius: 99px; background: var(--line); color: var(--ink); }
.pill.borrador { background: var(--line); }
.pill.pendiente { background: var(--amarillo-bg); color: var(--amarillo); }
.pill.enviado { background: var(--verde-bg); color: var(--verde); }
.pill.verde { background: var(--verde); color: #fff; }
.pill.amarillo { background: #f2c200; color: #222; }
.pill.rojo { background: var(--rojo); color: #fff; }

.notice { padding: .7rem 1rem; border-radius: 8px; margin: .5rem 0; background: var(--card); border: 1px solid var(--line); }
.notice.ok { background: var(--verde-bg); border-color: var(--verde); }
.notice.warn { background: var(--amarillo-bg); border-color: var(--amarillo); }
.notice.error { background: var(--rojo-bg); border-color: var(--rojo); }

.summary { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: center; margin: .75rem 0; font-size: .9rem; }
.dot { display: inline-block; width: .8rem; height: .8rem; border-radius: 50%; margin-right: -.6rem; }
.dot.verde { background: var(--verde); } .dot.amarillo { background: #f2c200; } .dot.rojo { background: var(--rojo); }

.cards { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; }
.item {
  display: flex; justify-content: space-between; gap: 1rem; padding: .8rem 1rem; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--line); border-radius: var(--radius);
}
.item.verde { border-left-color: var(--verde); } .item.amarillo { border-left-color: #f2c200; } .item.rojo { border-left-color: var(--rojo); }
.item .right { display: flex; flex-direction: column; align-items: flex-end; gap: .4rem; }
.link { font-size: .85rem; color: var(--primary); }

.bloque { border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem; margin-bottom: 1rem; background: var(--bg); }
.bloque > header { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.bloque > header h3 { flex: 1; }

.matriz { display: grid; gap: 2px; font-size: .85rem; }
.mfila { display: grid; grid-template-columns: 1fr repeat(var(--cols), minmax(3.2rem, 3.8rem)); align-items: center; gap: 2px; background: var(--card); padding: .35rem .5rem; border-radius: 6px; }
.mfila.head { background: none; font-weight: 700; text-align: center; color: var(--muted); font-size: .72rem; }
.mfila > span:first-child small { display: block; color: var(--muted); font-size: .75rem; font-weight: 400; }
.mfila label { margin: 0; display: flex; justify-content: center; align-items: center; height: 100%; cursor: pointer; }
.mfila label i { display: none; }
.mfila label:has(:checked) { border-radius: 6px; background: color-mix(in srgb, var(--accent) 15%, transparent); }
@media (max-width: 560px) {
  .mfila { grid-template-columns: repeat(var(--cols), 1fr); }
  .mfila > span:first-child { grid-column: 1 / -1; }
  .mfila.head { display: none; }
  .mfila label { flex-direction: column; gap: 2px; padding: .25rem 0; }
  .mfila label i { display: block; font-style: normal; font-size: .68rem; color: var(--muted); text-align: center; }
}

.dictamen { display: grid; gap: .5rem; margin-bottom: 1rem; }
.dictamen label { display: flex; gap: .7rem; align-items: center; padding: .7rem .9rem; border-radius: 8px; margin: 0; color: var(--ink); font-weight: 400; cursor: pointer; border: 2px solid transparent; }
.dictamen label.verde { background: var(--verde-bg); } .dictamen label.amarillo { background: var(--amarillo-bg); } .dictamen label.rojo { background: var(--rojo-bg); }
.dictamen label:has(:checked) { border-color: var(--ink); }
.dictamen.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.dictamen.compact label { justify-content: center; font-weight: 700; padding: .6rem .3rem; gap: .35rem; }
.hint { background: var(--bg); padding: .6rem .8rem; border-radius: 8px; font-size: .9rem; }

.table-like .row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.table-like .row > span { min-width: 190px; font-weight: 600; }

.fotos { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .5rem; margin-bottom: .5rem; }
.fotos figure { position: relative; margin: 0; }
.fotos img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 6px; display: block; }
.fotos figure .icon-btn { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.6); color: #fff; border-radius: 50%; width: 28px; height: 28px; padding: 0; }
.fotos .caption { min-height: 36px; padding: .3rem .5rem; font-size: .8rem; }
.btn.file { margin: 0; color: var(--ink); }

.gps { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; }
canvas.firma { width: 100%; max-width: 600px; aspect-ratio: 3/1; border: 1px dashed var(--muted); border-radius: 8px; background: #fff; touch-action: none; display: block; }

.btn:disabled { opacity: .5; cursor: not-allowed; }
.error { color: var(--rojo); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0 0 .5rem; }
.kv dt { color: var(--muted); font-weight: 600; font-size: .85rem; }
.kv dd { margin: 0; }
@media (max-width: 480px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: .4rem; } }
.activar { max-width: 420px; margin: 8vh auto 0; text-align: center; }
.activar form { text-align: left; }
.activar #act-pin { font: 700 1.4rem/1 ui-monospace, Consolas, monospace; letter-spacing: .15em; text-align: center; text-transform: uppercase; }
.activar .btn { width: 100%; }
.small { font-size: .8rem; }
input[readonly] { background: transparent; border-style: dashed; color: var(--muted); }
.enlace-portal { margin-top: 1.25rem; }
.enlace-portal a { color: var(--primary); font-weight: 600; }

/* ---- Bitácora360: vistas y motor de formularios ---- */
.grow { flex: 1; }
.seccion-titulo { font-size: 1rem; color: var(--primary); margin: 1rem 0 .5rem; }
.toolbar .seccion-titulo { margin: 0; }
.campo { margin-bottom: .75rem; min-width: 0; }
.campo.completo { grid-column: 1 / -1; }
.campo[hidden] { display: none !important; }
.lbl { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: .25rem; }
.req { color: var(--rojo); }
.ayuda { display: block; margin: -.1rem 0 .35rem; font-size: .78rem; }
.campo > input, .campo > select, .campo > textarea { margin-top: 0; }
.grupo-titulo { font-size: .95rem; margin: .25rem 0 .5rem; }
.info { background: var(--bg); border-left: 3px solid var(--primary); padding: .5rem .75rem; border-radius: 6px; margin: 0; }
.foto-falta { aspect-ratio: 4/3; display: flex; align-items: center; justify-content: center; background: var(--bg); border: 1px dashed var(--line); border-radius: 6px; font-size: .8rem; color: var(--muted); }
.item.obra { border-left-color: var(--primary); }
.etiquetas { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }
.obra-cab h2 { margin-bottom: .25rem; }
.nuevos { display: grid; gap: .75rem; }
.modulo { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem; }
.modulo h3 { font-size: .9rem; margin: 0 0 .5rem; color: var(--muted); }
.botones { display: flex; flex-wrap: wrap; gap: .5rem; }
#filtro-plantilla { width: auto; max-width: 60%; }
.error.small { font-size: .8rem; margin-top: .25rem; }
.totales { font-weight: 600; color: var(--primary); margin: .25rem 0 .5rem; }

/* Registros sellados: solo lectura */
.solo-lectura > section:not(.revision) button, .solo-lectura > section:not(.revision) label.btn { display: none !important; }
.solo-lectura > section:not(.revision) canvas { pointer-events: none; }
.solo-lectura input:disabled, .solo-lectura select:disabled, .solo-lectura textarea:disabled { opacity: 1; color: var(--ink); background: transparent; }

/* Revisión por invitados */
.revision { border: 2px solid var(--primary); }
.firmas-rev { padding-left: 1.1rem; margin: 0 0 .75rem; display: grid; gap: .4rem; }
