:root {
  --fondo: #f4f5f7;
  --panel: #ffffff;
  --texto: #1d2129;
  --sutil: #6b7280;
  --borde: #e2e5ea;
  --acento: #0e7490;
  --nuevo: #2fb344;
  --eliminado: #e5484d;
  --modificado: #f5a524;
  --igual: #9aa0a6;
  --sindatos: #6e7278;
  --sel: #22d3ee;
  --sube: #2563eb;
  --baja: #c026d3;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex; font: 13px/1.4 "Segoe UI", system-ui, sans-serif;
  color: var(--texto); background: var(--fondo); overflow: hidden;
}
h1 { font-size: 16px; margin: 0; }
h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--sutil); margin: 0 0 8px; }
.sutil { color: var(--sutil); font-weight: normal; }

#lateral {
  width: 340px; flex: none; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--borde); overflow-y: auto;
}
#lateral section.crece { min-height: 320px; }
.chico { font-size: 11px; }

/* Selector de vista (botones segmentados) */
.seg { display: flex; border: 1px solid var(--borde); border-radius: 7px; overflow: hidden; }
.seg label { flex: 1; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 6px 4px; font-size: 12px; border-right: 1px solid var(--borde); }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--acento); color: #fff; font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--acento); outline-offset: -2px; }
.seg-cambios { margin-top: 8px; }
#vista-avance { margin-top: 8px; }
#vista-avance select { width: 100%; }
.escala { display: flex; align-items: center; gap: 6px; margin: 8px 0 4px; font-size: 11px; color: var(--sutil); }
.escala i { flex: 1; height: 10px; border-radius: 5px; background: linear-gradient(90deg, #c8ccd2, #f5d76e 50%, #2fb344); }
.escala .sin-dato { width: 12px; height: 10px; border-radius: 3px; background: rgb(92, 98, 108); margin-left: 6px; }
section.apagada { opacity: .45; pointer-events: none; }

/* Disciplina: fichas seleccionables + interruptor de selección múltiple */
.disc-cab { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.disc-cab h2 { margin: 0; }
.interruptor { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--sutil); cursor: pointer; user-select: none; }
.interruptor input { position: absolute; opacity: 0; pointer-events: none; }
.interruptor .pista { width: 28px; height: 16px; border-radius: 8px; background: #cfd4da; position: relative; transition: background .15s; flex: none; }
.interruptor .pista::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.interruptor input:checked + .pista { background: var(--acento); }
.interruptor input:checked + .pista::after { transform: translateX(12px); }
.interruptor input:focus-visible + .pista { outline: 2px solid var(--acento); outline-offset: 2px; }

.fichas { display: flex; flex-wrap: wrap; gap: 6px; }
.ficha-d {
  display: flex; align-items: center; gap: 6px; max-width: 100%; padding: 5px 9px; flex: 1 1 auto;
  border: 1px solid var(--borde); border-radius: 8px; background: #fff; cursor: pointer;
  font: inherit; font-size: 12px; text-align: left; color: var(--sutil); transition: all .12s;
}
.ficha-d:hover { border-color: var(--acento); }
.ficha-d .color { width: 10px; height: 10px; border-radius: 3px; flex: none; opacity: .35; }
.ficha-d .nom { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ficha-d b { font-weight: 600; font-size: 11px; font-variant-numeric: tabular-nums; }
.ficha-d.activa { background: #e9f6f9; border-color: var(--acento); color: var(--texto); }
.ficha-d.activa .color { opacity: 1; }
.ficha-d:focus-visible { outline: 2px solid var(--acento); outline-offset: 1px; }
.disc-pie { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.disc-pie button { padding: 2px 8px; font-size: 11px; }
.disc-pie span { margin-left: auto; text-align: right; }

/* Metrado */
.sub-h2 { margin-top: 14px !important; }
#acumulado table { width: 100%; border-collapse: collapse; font-size: 12px; }
#acumulado th, #acumulado td { padding: 3px 4px; border-bottom: 1px solid var(--borde); text-align: right; white-space: nowrap; }
#acumulado th:first-child, #acumulado td:first-child { text-align: left; white-space: normal; }
#acumulado th { color: var(--sutil); font-weight: 600; }
#acumulado tr.total td { font-weight: 700; }
#acumulado tr.pie td { color: var(--sutil); }
#acumulado tr.pct td { font-weight: 700; color: var(--acento); border-bottom: 0; }
#acumulado .cero { color: #c3c7cd; }
#metrado table { width: 100%; border-collapse: collapse; font-size: 12px; }
#metrado th, #metrado td { padding: 3px 4px; border-bottom: 1px solid var(--borde); text-align: right; white-space: nowrap; }
#metrado th:first-child, #metrado td:first-child { text-align: left; white-space: normal; }
#metrado th { color: var(--sutil); font-weight: 600; cursor: pointer; }
#metrado th:first-child { cursor: default; }
#metrado th:hover:not(:first-child) { color: var(--acento); }
#metrado tr.total td { font-weight: 700; border-bottom: 0; }
#metrado .cero { color: #c3c7cd; }

/* Alertas */
.alerta-tit { color: #b42318 !important; }
#alertas { max-height: 150px; overflow: auto; }
.alerta { padding: 4px; border-bottom: 1px solid var(--borde); cursor: pointer; font-size: 12px; }
.alerta:hover { background: #fdecea; }
.alerta b { display: block; }
.alerta small { color: var(--sutil); }
.caja-alerta { background: #fdecea; border: 1px solid #f5b5ae; color: #8a1c12; border-radius: 6px; padding: 6px 8px; margin: 8px 0; }

/* TAG en la ficha */
.tag { font-family: Consolas, monospace; font-size: 13px; font-weight: 600; }
.copiar { padding: 1px 7px; font-size: 11px; margin-left: 6px; }
#aviso-copia {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  background: #1d2129; color: #fff; padding: 5px 12px; border-radius: 6px; font-size: 12px;
}
#aviso-copia[hidden] { display: none; }
#lateral header { padding: 14px 16px 10px; border-bottom: 1px solid var(--borde); }
#aviso { margin-top: 8px; font-size: 11px; background: #fff6e5; border: 1px solid #f7d58a; border-radius: 6px; padding: 5px 7px; }
#lateral section { padding: 12px 16px; border-bottom: 1px solid var(--borde); }
#lateral section.crece { flex: 1; display: flex; flex-direction: column; min-height: 0; border-bottom: 0; }

label.estado { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; }
label.estado b { margin-left: auto; font-variant-numeric: tabular-nums; }
.punto { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }
.punto.nuevo { background: var(--nuevo); }
.punto.eliminado { background: var(--eliminado); }
.punto.modificado { background: var(--modificado); }
.punto.igual { background: var(--igual); }
.fila { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.fila span { color: var(--sutil); }
select, input[type=search] {
  font: inherit; padding: 4px 6px; border: 1px solid var(--borde); border-radius: 6px; background: #fff;
}
input[type=search] { width: 100%; }

#areas { max-height: 150px; overflow: auto; }
.zona { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.zona label { flex: 1; display: flex; gap: 6px; align-items: center; cursor: pointer; min-width: 0; }
.zona label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zona small { color: var(--sutil); white-space: nowrap; }
.zona small.hay { color: var(--modificado); font-weight: 600; }
.zona button { padding: 1px 6px; font-size: 11px; }

#avance { max-height: 210px; overflow: auto; }
.prop { display: flex; align-items: center; gap: 6px; padding: 3px 4px; border-radius: 4px; cursor: pointer; }
.prop:hover { background: #f0f7f9; }
.prop.activo { background: #dff6fb; }
.prop.vacio { color: var(--sutil); cursor: default; }
.prop.vacio:hover { background: none; }
.prop span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prop b { font-variant-numeric: tabular-nums; font-size: 12px; white-space: nowrap; }
.prop b.sube { color: var(--sube); }
.prop b.baja { color: var(--baja); }
.punto.sube { background: var(--sube); }
.punto.baja { background: var(--baja); }
.leyenda[hidden] { display: none; }
#n-excluidos { font-size: 11px; margin: -4px 0 6px; }
.leyenda { display: flex; align-items: center; gap: 12px; margin-top: 6px; font-size: 12px; }
.leyenda span { display: flex; align-items: center; gap: 4px; }
.leyenda button { margin-left: auto; padding: 2px 8px; font-size: 11px; }
.av { color: var(--texto); font-weight: 600; }

#lista { flex: 1; overflow: auto; margin-top: 8px; border-top: 1px solid var(--borde); }
.item { display: flex; gap: 8px; align-items: flex-start; padding: 6px 4px; border-bottom: 1px solid var(--borde); cursor: pointer; }
.item:hover { background: #f0f7f9; }
.item.activo { background: #dff6fb; }
.item .punto { margin-top: 3px; }
.item div { min-width: 0; }
.item .nom { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .det { color: var(--sutil); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mas { padding: 8px 4px; color: var(--sutil); }

button {
  font: inherit; padding: 5px 10px; border: 1px solid var(--borde); border-radius: 6px;
  background: #fff; color: var(--texto); cursor: pointer;
}
button:hover { border-color: var(--acento); color: var(--acento); }

#escena { flex: 1; position: relative; min-width: 0; }
#lienzo { width: 100%; height: 100%; display: block; background: linear-gradient(#3a4049, #22262c); touch-action: none; }
#barra { position: absolute; top: 12px; left: 12px; display: flex; gap: 6px; }
#barra button { background: rgba(255,255,255,.92); }
#ayuda {
  position: absolute; bottom: 10px; left: 12px; color: #d6dae0; font-size: 11px;
  background: rgba(0,0,0,.35); padding: 3px 8px; border-radius: 4px; pointer-events: none;
}
#carga {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px;
  align-items: center; justify-content: center; background: rgba(34,38,44,.85); color: #fff;
}
#carga[hidden] { display: none; }
.barra-prog { width: 260px; height: 6px; background: rgba(255,255,255,.2); border-radius: 3px; overflow: hidden; }
#carga-prog { height: 100%; width: 0; background: var(--sel); }
#carga-txt { max-width: min(640px, 90vw); text-align: center; white-space: pre-wrap; }
#carga-log {
  margin: 6px 0 0; width: min(640px, 90vw); max-height: 40vh; overflow: auto; padding: 8px 10px;
  font: 11px/1.45 ui-monospace, Consolas, monospace; color: #c9ced6; white-space: pre-wrap;
  background: rgba(0,0,0,.3); border-radius: 6px;
}
#carga-log[hidden] { display: none; }
#carga.con-error .barra-prog { display: none; }
#carga.con-error #carga-txt { color: #ffb4b6; }

#ficha {
  width: 380px; flex: none; background: var(--panel); border-left: 1px solid var(--borde);
  overflow: auto; position: relative; padding: 16px;
}
#cerrar-ficha { position: absolute; top: 8px; right: 8px; border: 0; font-size: 20px; line-height: 1; padding: 2px 8px; }
.insignia { display: inline-block; padding: 2px 8px; border-radius: 10px; color: #fff; font-size: 11px; font-weight: 600; }
.insignia.nuevo { background: var(--nuevo); }
.insignia.eliminado { background: var(--eliminado); }
.insignia.modificado { background: var(--modificado); color: #3b2a00; }
.insignia.igual { background: var(--igual); }
#ficha h3 { margin: 8px 0 4px; font-size: 15px; word-break: break-word; padding-right: 24px; }
#ficha dl { display: grid; grid-template-columns: 90px 1fr; gap: 3px 10px; margin: 10px 0; }
#ficha dt { color: var(--sutil); }
#ficha dd { margin: 0; word-break: break-all; }
#ficha h4 { margin: 16px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--sutil); }
#ficha table { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; }
#ficha td, #ficha th { border-bottom: 1px solid var(--borde); padding: 4px; text-align: left; vertical-align: top; word-break: break-word; }
#ficha th { color: var(--sutil); font-weight: 600; }
.resumen { margin: 10px 0 4px; background: #f0f7f9; border: 1px solid #bfe3ec; border-radius: 6px; padding: 8px 10px; }
.resumen-tit { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--acento); margin-bottom: 4px; }
.resumen ul { margin: 0; padding-left: 18px; }
.resumen li { margin: 2px 0; word-break: break-word; }
.resumen .sube { color: var(--sube); font-weight: 600; }
.resumen .baja { color: var(--baja); font-weight: 600; }
tr.cambio td { background: #fff6e5; font-weight: 600; }
#avance-ficha table td:nth-child(2), #avance-ficha table td:nth-child(3),
#avance-ficha table th:nth-child(2), #avance-ficha table th:nth-child(3) { width: 70px; text-align: right; }
td.antes { color: #b42318; }
td.ahora { color: #027a48; }
.geo { background: #fff6e5; border: 1px solid #f7d58a; border-radius: 6px; padding: 6px 8px; }
details { margin-top: 6px; }
summary { cursor: pointer; font-weight: 600; padding: 3px 0; }

/* Comparar semanas (arriba del todo): Desde / Hasta */
#sec-semanas { background: #f0f7f9; }
.semanas { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.semanas label { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.semanas label span { font-size: 11px; color: var(--sutil); }
.semanas select { width: 100%; min-width: 0; }
#sem-nota { margin-top: 6px; }
#sem-nota:empty { display: none; }
#sem-nota.mal { color: #b42318; }
.sem-pie { display: flex; gap: 6px; margin-top: 8px; }
.boton-link {
  font-size: 11px; padding: 2px 8px; border: 1px solid var(--borde); border-radius: 6px; background: #fff;
  color: var(--texto); text-decoration: none;
}
.boton-link:hover { border-color: var(--acento); color: var(--acento); }
.cargando-par { opacity: .55; pointer-events: none; }
.punto.sindatos { background: var(--sindatos); }
.insignia.sindatos { background: var(--sindatos); }
.sin-geo { font-size: 10px; color: var(--sutil); border: 1px solid var(--borde); border-radius: 4px; padding: 0 4px; margin-left: 4px; }
#aviso a { color: inherit; }
td.dif { background: #fff6e5; font-weight: 600; }

/* Publicar para el equipo (solo en tu PC) */
#b-publicar {
  margin-top: 10px; width: 100%; background: var(--acento); border-color: var(--acento); color: #fff; font-weight: 600;
}
#b-publicar:hover { filter: brightness(1.1); color: #fff; }
#b-publicar:disabled, #b-actualizar:disabled { opacity: .6; cursor: progress; }
#b-actualizar { margin-top: 10px; width: 100%; font-weight: 600; }
#publicar-msg { margin-top: 6px; font-size: 12px; }
#publicar-msg.mal { color: #b42318; }

/* Celular y pantallas angostas: el panel se despliega encima del modelo y la ficha sale abajo */
#b-panel { display: none; }
@media (max-width: 800px) {
  #lateral {
    position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: min(88vw, 360px);
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: 0 0 24px rgba(0,0,0,.35);
  }
  body.panel-abierto #lateral { transform: none; }
  #b-panel { display: inline-block; font-weight: 600; }
  #barra { right: 12px; flex-wrap: wrap; }
  #ayuda { display: none; }
  #ficha {
    position: fixed; z-index: 15; left: 0; right: 0; bottom: 0; width: auto; max-height: 55vh;
    border-left: 0; border-top: 1px solid var(--borde); border-radius: 12px 12px 0 0;
    box-shadow: 0 -6px 24px rgba(0,0,0,.25);
  }
}

/* Leyenda de la vista «% avance»: un degradado por partida */
.ley-partida { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 8px; margin: 5px 0; font-size: 11px; }
.ley-partida span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ley-partida i { height: 10px; border-radius: 5px; }
.ley-pie { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 11px; color: var(--sutil); }
.ley-pie b { width: 12px; height: 10px; border-radius: 3px; }
.ley-pie b + span { margin-right: 8px; }
#leyenda-avance { margin: 8px 0 6px; }

/* Subida automática a Cloudflare (solo en tu PC) */
#nube { margin-top: 8px; font-size: 12px; }
#nube summary { cursor: pointer; color: var(--sutil); }
#nube-estado.ok { color: #15803d; font-weight: 600; }
#nube-form { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
#nube-form p { margin: 0; }
#nube-form label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--sutil); }
#nube-form input { font: inherit; font-size: 12px; padding: 4px 6px; border: 1px solid var(--borde); border-radius: 6px; color: var(--texto); }
#nube-msg.mal, .pub-error { color: #b42318; }
#nube-msg.ok { color: #15803d; }
.pub-ok { color: #15803d; font-weight: 600; }

/* Revisión de datos (solo en tu PC) */
#revision details { border-bottom: 1px solid var(--borde); padding: 4px 0; font-size: 12px; }
#revision summary { cursor: pointer; list-style: none; display: flex; gap: 6px; align-items: baseline; }
#revision summary::-webkit-details-marker { display: none; }
#revision .nivel { flex: none; font-size: 10px; font-weight: 700; border-radius: 4px; padding: 0 5px; color: #fff; }
#revision .nivel.error { background: #c62828; }
#revision .nivel.aviso { background: #d97706; }
#revision .nivel.info { background: #9aa0a6; }
#revision .det { margin: 4px 0 2px; color: var(--sutil); }
#revision ul { margin: 2px 0 0; padding-left: 16px; font-family: Consolas, monospace; font-size: 11px; }
#rev-resumen .err { color: #c62828; font-weight: 600; }
#rev-caja > summary { cursor: pointer; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
#rev-caja > summary h2 { margin: 0; display: inline; }
#rev-caja[open] > summary { margin-bottom: 6px; }
