/* Paleta 2 (clara) */
:root {
  --bg: #F8FAFC; --card: #FFFFFF; --ink: #0F172A; --muted: #64748B; --line: #E2E8F0;
  --primary: #1E40AF; --primary-ink: #fff; --accent: #D97706;
  --c-sst: #DC2626; --c-tec: #1E40AF;
  --verde: #15803d; --verde-bg: #dcfce7; --amarillo: #92400e; --amarillo-bg: #fef3c7;
  --rojo: #DC2626; --rojo-bg: #fee2e2;
  --radius: 10px; --sombra: 0 1px 3px rgba(15,23,42,.08);
}
* { 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(--ink); }
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: #0F172A; border-bottom: 3px solid var(--accent); 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 { box-shadow: var(--sombra); 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: .5rem 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%; }
.activar > img { width: 56px; height: 56px; }
/* Solo en pantallas anchas (PC): se compacta la activación para que todo quepa sin deslizar. El celular no cambia. */
@media (min-width: 900px) {
  #view-activar { padding-top: .25rem; padding-bottom: .5rem; }
  .activar { margin-top: 0; padding: .75rem 1rem; }
  .activar > img { width: 48px; height: 48px; }
  .activar h2 { margin: .4rem 0; }
  .activar .muted { margin: .3rem 0 .6rem; }
  #view-activar .ayuda-activar { margin-top: .5rem; }
  #view-activar .ayuda-activar p { padding: .3rem 0; }
}
.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; }
/* Ayuda de la pantalla de activación: dentro de la tarjeta, mismo ancho y un solo color de enlace */
.ayuda-activar { border-top: 1px solid var(--line); margin: 1rem -1rem 0; padding: .25rem 1rem 0; text-align: center; font-size: .9rem; }
.ayuda-activar p { margin: 0; padding: .55rem 0; }
.ayuda-activar p + p { border-top: 1px solid var(--line); }
.ayuda-activar a, .enlace-legal a { color: var(--primary); font-weight: 600; text-decoration: none; }
.enlace-legal { margin-top: .5rem; }
.enlace-legal a { color: var(--muted); font-weight: 400; text-decoration: underline; }

/* ---- Bitácora360: vistas y motor de formularios ---- */
.grow { flex: 1; }
.seccion-titulo { font-size: 1.25rem; font-weight: 800; letter-spacing: .01em; color: var(--primary); margin: 1.25rem 0 .6rem; padding-left: .6rem; border-left: 5px solid var(--accent); line-height: 1.2; }
.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); padding: 1.4rem 1.5rem; gap: 1.5rem; font-size: 1.1rem; }
.item.obra strong { font-size: 1.35rem; }
.item.obra .small { font-size: .95rem; }
.item.obra .etiquetas { display: grid; grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); gap: .6rem; margin-top: .8rem; }
/* Cada módulo es un botón táctil (mín. 48 px de alto), redondeado pero amplio */
.item.obra .pill.mod { display: flex; align-items: center; justify-content: center; gap: .35rem; min-height: 3rem; padding: .5rem .9rem; border-radius: 14px; font-size: 1rem; text-align: center; line-height: 1.15; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform .08s, filter .08s; }
.item.obra .pill.mod:active { transform: scale(.96); filter: brightness(.9); }
@media (max-width: 560px) {
  .item.obra { flex-direction: column; gap: .6rem; padding: 1.1rem 1rem; }
  .item.obra .right { flex-direction: row; align-items: center; justify-content: space-between; width: 100%; }
  .item.obra .etiquetas { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
#lista-obras { gap: 1rem; }
.etiquetas { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }
.obra-cab h2 { margin: 0 0 .4rem; font-size: 1.5rem; font-weight: 800; line-height: 1.2; color: var(--primary); }
.obra-cab .datos-obra { font-size: 1rem; }
.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: grid; grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); gap: .6rem; }
/* Submenú: mismos botones táctiles que las píldoras de la obra, con el color de su módulo */
.botones .btn { min-height: 3rem; padding: .5rem .9rem; border-radius: 14px; font-size: 1rem; text-align: center; line-height: 1.15; -webkit-tap-highlight-color: transparent; transition: transform .08s, filter .08s; }
.botones .btn:active:not(:disabled) { transform: scale(.96); filter: brightness(.9); }
.modulo[data-modulo=sst] .btn.primary { background: var(--c-sst); border-color: var(--c-sst); }
.modulo[data-modulo=avance] .btn.primary { background: var(--verde); border-color: var(--verde); }
.modulo[data-modulo=calidad] .btn.primary { background: #7C3AED; border-color: #7C3AED; }
.modulo[data-modulo=vecindad] .btn.primary { background: #0F766E; border-color: #0F766E; }
@media (max-width: 560px) { .botones { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
#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; }

/* Aviso para instalar la app en el equipo */
.instalar { display: flex; gap: .75rem; align-items: flex-start; border-color: var(--primary); }
.instalar img { flex: none; border-radius: 10px; }
.instalar .txt { flex: 1; min-width: 0; }
.instalar .txt p { margin: .15rem 0 .5rem; }
.instalar ol { margin: .25rem 0 .5rem; padding-left: 1.2rem; }
.instalar .acciones { display: flex; flex-wrap: wrap; gap: .5rem; }
.instalar .cerrar { flex: none; margin: -.35rem -.5rem 0 0; }

/* Color por módulo: SST ámbar, técnico/inspección azul, bitácora naranja */
.modulo { border-left: 5px solid var(--accent); }
.modulo[data-modulo=sst] { border-left-color: var(--c-sst); }
.modulo[data-modulo=sst] .btn.primary { background: var(--c-sst); border-color: var(--c-sst); }
.modulo[data-modulo=sismo], .modulo[data-modulo=vecindad], .modulo[data-modulo=calidad], .modulo[data-modulo=interventoria] { border-left-color: var(--c-tec); }
.modulo[data-modulo=sismo] .btn.primary, .modulo[data-modulo=vecindad] .btn.primary, .modulo[data-modulo=calidad] .btn.primary, .modulo[data-modulo=interventoria] .btn.primary { background: var(--c-tec); border-color: var(--c-tec); }
.modulo h3 { color: var(--ink); }
.modulo { box-shadow: var(--sombra); }

/* Modo oscuro (paleta 1) */
:root[data-theme=dark] {
  color-scheme: dark;
  --bg: #1E222D; --card: #2A2F3D; --ink: #FFFFFF; --muted: #9CA3AF; --line: #3B4152;
  --primary: #F26522; --accent: #F26522; --c-sst: #D97706; --c-tec: #2563EB;
  --verde: #1f9d55; --verde-bg: #143524; --amarillo: #E0A96D; --amarillo-bg: #3a3110;
  --rojo: #e04848; --rojo-bg: #3d1616; --sombra: none;
}
:root[data-theme=dark] .topbar { background: #14171F; }
.tema-btn { background: none; border: 0; cursor: pointer; font-size: 1.2rem; line-height: 1; color: #fff; padding: .25rem .5rem; }

/* Razón social con protagonismo */
.topbar.marca-empresa #title { font-size: 1.5rem; line-height: 1.1; font-weight: 800; letter-spacing: .01em; }
.bienvenida { border-left: 6px solid var(--accent); padding: .25rem 0 .25rem 1rem; margin: .25rem 0 1rem; }
.bienvenida p { margin: 0; color: var(--muted); }
.bienvenida h1 { margin: 0 0 .15rem; font-size: clamp(1.7rem, 6.5vw, 2.5rem); line-height: 1.1; color: var(--ink); letter-spacing: .01em; overflow-wrap: anywhere; text-transform: capitalize; }
.bienvenida .obras-n { font-weight: 600; color: var(--accent); }

/* Barra: logo, marca y flecha de regresar */
.logo-barra { flex: none; border-radius: 8px; background: #fff; padding: 2px; }
.back-btn { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; border-radius: 10px; background: rgba(255,255,255,.16); color: #fff; cursor: pointer; }
.back-btn:hover, .back-btn:active { background: var(--accent); }
.back-btn[hidden] { display: none; }
.topbar .title strong { font-size: 1.25rem; }
.bienvenida .rol-n { font-weight: 600; color: var(--ink); }
.bienvenida .rol-n:empty { display: none; }
.datos-obra { margin: 0 0 .5rem; color: var(--ink); font-size: .95rem; }
.usuario-activo { margin: 0; display: inline-block; padding: .25rem .7rem; border-radius: 99px; font-size: .85rem; background: color-mix(in srgb, var(--accent) 14%, transparent); border: 1px solid var(--accent); color: var(--ink); }

/* Módulos activos de cada obra */
.pill.mod { color: #fff; background: var(--c-tec); font-weight: 700; box-shadow: 0 2px 5px rgba(15,23,42,.18); }
.pill.mod[data-modulo=sst] { background: var(--c-sst); }
.pill.mod[data-modulo=bitacora] { background: var(--accent); }
.pill.mod[data-modulo=avance] { background: var(--verde); }
.pill.mod[data-modulo=calidad] { background: #7C3AED; }
.pill.mod[data-modulo=vecindad] { background: #0F766E; }
.modulo h3 { margin: 0 0 .7rem; }
.modulo h3 .pill.mod { display: flex; align-items: center; gap: .5rem; width: 100%; box-sizing: border-box; font-size: 1.2rem; font-weight: 800; letter-spacing: .01em; padding: .65rem 1rem; border-radius: 14px; }
.botones .btn { font-size: 1.05rem; font-weight: 700; }

/* Atajos de obra, filtros, dictado */
.accesos { display: flex; flex-direction: column; gap: .5rem; margin: .75rem 0; }
.accesos .btn { justify-content: flex-start; text-align: left; }
.accesos .btn.continuar { background: var(--amarillo-bg); border-color: #f2c200; color: var(--amarillo); }
.alerta-obra { margin-top: .35rem; font-size: .85rem; font-weight: 700; color: var(--amarillo); }
.notice.warn { background: var(--amarillo-bg); color: var(--amarillo); border-color: #f2c200; }
.filtros input[type=search] { flex: 1 1 14rem; margin-top: 0; }
.filtros select { flex: 0 1 12rem; margin-top: 0; }
.con-dictado { position: relative; }
.btn.dictar { min-height: 36px; margin-top: .3rem; padding: .2rem .7rem; font-size: .85rem; }
.btn.dictar.grabando { background: var(--rojo); color: #fff; border-color: var(--rojo); }

/* Usuario en primer plano en el inicio */
.usuario-card { display: flex; align-items: center; gap: .9rem; }
.usuario-card .avatar { flex: none; width: 3.6rem; height: 3.6rem; border-radius: 50%; display: grid; place-items: center; font-size: 1.8rem; font-weight: 800; color: #fff; background: var(--accent); box-shadow: 0 2px 6px rgba(15,23,42,.25); }
.usuario-datos { min-width: 0; }
.bienvenida .rol-n { display: inline-block; margin-top: .15rem; padding: .15rem .7rem; border-radius: 99px; background: color-mix(in srgb, var(--accent) 16%, transparent); border: 1px solid var(--accent); font-size: .85rem; }
.bienvenida .empresa-n { margin-top: .6rem; font-size: 1rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.usuario-activo .nombre-u { font-size: 1.05rem; }
