:root {
  --bg: #070c12; --bg2: #0c1219; --bg3: #121b26; --linea: #1d2b3a;
  --txt: #dbe6f1; --txt2: #8da2b8; --verde: #2f9e6e; --verde2: #8fe8c0;
  --azul: #3aa0ff; --ambar: #f4b942; --rojo: #ff6b6b;
  --top: 52px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--txt); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--azul); }
h1 { font-size: 22px; margin: 0 0 8px; }
h2 { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--txt2); margin: 18px 0 8px; font-weight: 600; }
h2:first-child { margin-top: 0; }
.hint { color: var(--txt2); font-size: 12.5px; margin: 6px 0; }
.nota { color: var(--txt2); font-weight: 400; letter-spacing: 0; text-transform: none; }

input, select, button { font: inherit; color: inherit; }
input[type=search], input[type=number], select {
  background: var(--bg3); border: 1px solid var(--linea); border-radius: 6px; padding: 7px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: 1px solid var(--azul); }
input[type=range] { width: 100%; accent-color: var(--verde); }
.btn, .buscar button {
  background: var(--verde); border: 0; border-radius: 6px; padding: 8px 14px; color: #fff; font-weight: 600;
  cursor: pointer; text-decoration: none; display: inline-block; white-space: nowrap;
}
.btn.sec { background: var(--bg3); border: 1px solid var(--linea); color: var(--txt); font-weight: 500; }
.btn:disabled { opacity: .4; cursor: default; }
.btn:hover:not(:disabled), .buscar button:hover { filter: brightness(1.15); }
.ico { background: none; border: 0; font-size: 20px; cursor: pointer; display: none; }

/* ---------- cabecera ---------- */
.top {
  height: var(--top); display: flex; align-items: center; gap: 14px; padding: 0 14px;
  background: var(--bg2); border-bottom: 1px solid var(--linea); position: sticky; top: 0; z-index: 1000;
}
.brand { font-size: 12px; letter-spacing: .14em; color: var(--txt2); white-space: nowrap; }
.brand b { color: var(--verde2); }
.actual { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 4px; }
.tabs button { background: none; border: 0; padding: 8px 12px; border-radius: 6px; cursor: pointer; color: var(--txt2); white-space: nowrap; }
.tabs button.on { background: var(--bg3); color: var(--txt); }

/* ---------- estructura ---------- */
.layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); height: calc(100vh - var(--top)); }
main { min-width: 0; min-height: 0; overflow: hidden; }
.tab { display: none; height: 100%; }
.tab.on { display: block; }

.lista { background: var(--bg2); border-right: 1px solid var(--linea); display: flex; flex-direction: column; min-height: 0; padding: 10px; gap: 8px; }
.condados { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.condados button { background: var(--bg3); border: 1px solid var(--linea); border-radius: 6px; padding: 6px 2px; cursor: pointer; font-size: 12px; color: var(--txt2); }
.condados button.on { border-color: var(--verde); color: var(--txt); }
.items { overflow-y: auto; flex: 1; min-height: 0; }
.items button { display: flex; justify-content: space-between; gap: 6px; width: 100%; text-align: left; background: none; border: 0; padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.items button:hover { background: var(--bg3); }
.items button.on { background: var(--verde); color: #fff; }
.items .tag { font-size: 10.5px; color: var(--txt2); border: 1px solid var(--linea); border-radius: 10px; padding: 0 7px; white-space: nowrap; align-self: center; }
.items button.on .tag { color: #fff; border-color: #ffffff66; }
.pie { font-size: 11.5px; color: var(--txt2); }

/* ---------- código ---------- */
#tab-codigo.on { display: flex; flex-direction: column; }
.barra { display: flex; gap: 8px; padding: 10px 14px 6px; flex-wrap: wrap; align-items: center; }
.barra select { width: auto; max-width: 260px; }
.buscar { display: flex; gap: 6px; flex: 1; min-width: 220px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 6px; }
.panel .chips { padding: 0; }
.chips button { background: var(--bg3); border: 1px solid var(--linea); border-radius: 14px; padding: 3px 11px; font-size: 12px; cursor: pointer; color: var(--txt2); }
.chips button:hover { color: var(--txt); border-color: var(--azul); }
.vigencia { padding: 0 14px 8px; font-size: 12px; color: var(--txt2); }
.codigo { display: grid; grid-template-columns: 330px minmax(0, 1fr); flex: 1; min-height: 0; border-top: 1px solid var(--linea); }
.toc { overflow: auto; padding: 8px; border-right: 1px solid var(--linea); font-size: 13px; }
.toc ul { list-style: none; margin: 0; padding-left: 14px; }
.toc > ul { padding-left: 0; }
.toc .n { display: flex; gap: 2px; align-items: flex-start; }
.toc .fl { width: 18px; flex: none; background: none; border: 0; color: var(--txt2); cursor: pointer; padding: 3px 0; }
.toc .tt { background: none; border: 0; text-align: left; padding: 3px 6px; border-radius: 5px; cursor: pointer; flex: 1; }
.toc .tt:hover { background: var(--bg3); }
.toc .tt.on { background: var(--bg3); color: var(--verde2); }
.contenido { overflow: auto; padding: 18px 26px 60px; min-width: 0; }
.contenido article { max-width: 900px; margin-bottom: 26px; scroll-margin-top: 12px; }
.contenido article h3 { font-size: 16px; color: var(--verde2); margin: 0 0 8px; }
.contenido article.foco h3 { color: var(--ambar); }
.contenido table { display: block; overflow-x: auto; border-collapse: collapse; margin: 10px 0; max-width: 100%; }
.contenido td, .contenido th { border: 1px solid var(--linea); padding: 4px 8px; vertical-align: top; }
.contenido img { max-width: 100%; background: #fff; }
.contenido p { margin: 6px 0; }
.contenido .incr, .contenido .hist, .contenido .historynote { color: var(--txt2); font-size: 12.5px; }
.navdoc { display: flex; justify-content: space-between; gap: 10px; max-width: 900px; margin-top: 20px; }
.bienvenida { max-width: 640px; margin: 6vh auto; }
.bienvenida li { margin: 6px 0; }
.resultado { display: block; width: 100%; text-align: left; background: var(--bg2); border: 1px solid var(--linea); border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; cursor: pointer; max-width: 900px; }
.resultado:hover { border-color: var(--azul); }
.resultado .ruta { font-size: 11.5px; color: var(--txt2); }
.resultado .tit { font-weight: 600; }
.resultado .frag { font-size: 12.5px; color: var(--txt2); }
.resultado em, .contenido em.hit { color: var(--ambar); font-style: normal; font-weight: 600; background: none; border: 0; padding: 0; display: inline; }

/* ---------- lote ---------- */
.lote, .masa { display: grid; grid-template-columns: minmax(0, 1fr) 380px; height: 100%; }
.masa { grid-template-columns: 340px minmax(0, 1fr); }
.mapa-wrap { position: relative; min-height: 0; }
#mapa { position: absolute; inset: 0; background: var(--bg2); }
.buscar.sobre { position: absolute; z-index: 500; top: 10px; left: 54px; right: 10px; max-width: 520px; }
.buscar.sobre input { background: var(--bg2); }
.panel { overflow-y: auto; padding: 14px; background: var(--bg2); border-left: 1px solid var(--linea); }
.masa .panel { border-left: 0; border-right: 1px solid var(--linea); }
.kv { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 3px 10px; font-size: 13px; }
.kv span:nth-child(odd) { color: var(--txt2); }
.kv span:nth-child(even) { overflow-wrap: anywhere; }
.zona { font-size: 20px; font-weight: 700; color: var(--ambar); }
#btnAMasa { width: 100%; margin-top: 12px; }
.fuente { display: block; padding: 8px 10px; border: 1px solid var(--linea); border-radius: 8px; margin-bottom: 6px; text-decoration: none; color: var(--txt); background: var(--bg3); }
.fuente:hover { border-color: var(--azul); }
.fuente small { display: block; color: var(--txt2); }
.grupo { font-size: 11.5px; color: var(--txt2); margin: 12px 0 5px; }

/* ---------- masa ---------- */
.sl { margin-bottom: 8px; }
.sl label { display: flex; justify-content: space-between; font-size: 13px; }
.sl b { color: var(--verde2); }
.fila2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.fila2 label { font-size: 12px; color: var(--txt2); display: flex; flex-direction: column; gap: 3px; }
.fila2 .btn { width: 100%; }
.controles > .btn { width: 100%; }
.vista { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow-y: auto; }
.lienzo { position: relative; flex: 1; min-height: 340px; }
#canvas3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.vbtns { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; }
.aviso { position: absolute; left: 10px; bottom: 10px; right: 10px; font-size: 12.5px; color: var(--ambar); pointer-events: none; }
.metricas { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 1px; background: var(--linea); border-top: 1px solid var(--linea); }
.metricas div { background: var(--bg2); padding: 9px 12px; }
.metricas small { display: block; color: var(--txt2); font-size: 11px; }
.metricas b { font-size: 16px; }
.metricas .ok b { color: var(--verde2); }
.metricas .mal b { color: var(--rojo); }
.tabla { padding: 8px 12px 14px; font-size: 12.5px; overflow-x: auto; }
.tabla table { border-collapse: collapse; width: 100%; }
.tabla td, .tabla th { padding: 4px 8px; border-bottom: 1px solid var(--linea); text-align: right; white-space: nowrap; }
.tabla th { color: var(--txt2); font-weight: 500; }
.tabla td:first-child, .tabla th:first-child { text-align: left; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--bg3); border: 1px solid var(--linea); padding: 9px 16px; border-radius: 8px; transition: transform .25s; z-index: 3000; max-width: 90vw; }
.toast.on { transform: translateX(-50%); }
.toast.mal { border-color: var(--rojo); }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--linea); border-top-color: var(--verde2); border-radius: 50%; animation: g .8s linear infinite; margin-right: 6px; vertical-align: -1px; }
@keyframes g { to { transform: rotate(360deg); } }

.leaflet-container { font: inherit; }
.leyenda { background: var(--bg2); color: var(--txt); border: 1px solid var(--linea); border-radius: 8px; padding: 8px 10px; font-size: 12px; max-width: 250px; }
.leyenda .ley-t { font-weight: 600; display: flex; gap: 6px; align-items: center; cursor: pointer; }
.leyenda .ley-items { max-height: 34vh; overflow-y: auto; margin: 4px 0; }
.leyenda .ley-items div { display: flex; gap: 6px; align-items: center; padding: 1px 0; white-space: nowrap; }
.leyenda i { width: 14px; height: 14px; border-radius: 3px; border: 1px solid #0006; flex: none; }
.leyenda small { color: var(--txt2); display: block; white-space: normal; }

@media (max-width: 1000px) {
  .ico { display: block; }
  .brand { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .lista { position: fixed; top: var(--top); bottom: 0; left: 0; width: 280px; z-index: 900; transform: translateX(-100%); transition: transform .2s; }
  .lista.abierta { transform: none; }
  .codigo { grid-template-columns: minmax(0, 1fr); grid-template-rows: 38vh minmax(0, 1fr); }
  .toc { border-right: 0; border-bottom: 1px solid var(--linea); }
  .lote, .masa { grid-template-columns: minmax(0, 1fr); height: auto; }
  .tab { overflow-y: auto; }
  .mapa-wrap { height: 55vh; }
  .lienzo { min-height: 55vh; }
  .panel { border: 0 !important; }
  .masa .vista { order: -1; overflow: visible; }
  .contenido { padding: 14px 16px 60px; }
}
