/* Atlas ZF1 — estética de atlas urbano: mapa dominante, franja editorial marginal */
:root {
  --paper: #f7f5f0;
  --paper-2: #efece5;
  --ink: #1b1b1a;
  --ink-2: #4a4843;
  --ink-3: #8a867d;
  --rule: #d9d5cb;
  --accent: #d6452b;          /* selección: tramo, nodo, predio */
  --accent-soft: rgba(214, 69, 43, .10);
  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --rail: clamp(300px, 23vw, 400px);
  --ctrl-h: 58px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper); color: var(--ink); font: 14px/1.5 var(--sans);
  display: grid; grid-template-columns: var(--rail) 1fr; overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
select { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------- carga */
#loading { position: fixed; inset: 0; z-index: 99; background: var(--paper); display: grid; place-items: center; transition: opacity .5s; }
#loading > div { display: flex; flex-direction: column; gap: 6px; align-items: center; }
#loading .ld-k { font: 600 11px var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); }
#loading #ld-msg { font: 400 22px var(--serif); }
#loading.done { opacity: 0; pointer-events: none; }

/* ---------------- franja narrativa */
#rail { height: 100vh; overflow-y: auto; border-right: 1px solid var(--rule); background: var(--paper); position: relative; scroll-behavior: smooth; }
.rail-head { padding: 34px 28px 10px 44px; }
.kick, .num, .lbl { font: 600 10.5px/1.3 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
h1 { font: 500 38px/1.02 var(--serif); margin: 10px 0 14px; letter-spacing: -.01em; }
h2 { font: 500 27px/1.1 var(--serif); margin: 8px 0 14px; letter-spacing: -.005em; }
h3 { font: 600 12px var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.thesis { font: 400 17px/1.45 var(--serif); color: var(--ink-2); margin: 0 0 14px; }
.hint { color: var(--ink-3); font-size: 12.5px; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

#dots { position: sticky; top: 0; float: left; width: 30px; margin-left: 6px; padding-top: 40vh; display: flex; flex-direction: column; gap: 9px; z-index: 2; height: 0; }
#dots button { width: 22px; height: 16px; border: 0; background: none; padding: 0; display: flex; align-items: center; gap: 4px; font: 600 9px var(--sans); color: var(--ink-3); }
#dots button::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--rule); flex: none; }
#dots button.on { color: var(--ink); }
#dots button.on::before { background: var(--accent); }

.scene { min-height: 92vh; padding: 28vh 28px 10vh 44px; }
.scene:first-child { padding-top: 14vh; }
.claim { font: 400 18.5px/1.42 var(--serif); margin: 0 0 16px; }
.body { color: var(--ink-2); margin: 0 0 14px; }
.body b { color: var(--ink); font-weight: 600; }
.note { color: var(--ink-3); font-size: 12.5px; border-left: 2px solid var(--rule); padding-left: 10px; margin: 14px 0; }
.note b { color: var(--ink-2); }
.nodelist { list-style: none; padding: 0; margin: 12px 0 18px; columns: 1; }
.nodelist li { display: flex; gap: 10px; align-items: baseline; padding: 3px 0; cursor: pointer; border-bottom: 1px dotted var(--rule); }
.nodelist li:hover { color: var(--accent); }
.nodelist .nn { font: 600 11px var(--sans); width: 18px; height: 18px; border-radius: 50%; background: var(--ink); color: #fff; display: inline-grid; place-items: center; flex: none; transform: translateY(3px); }
.pick { margin: 14px 0; }
blockquote.final { font: 500 22px/1.3 var(--serif); margin: 22px 0; padding: 0; }
.explore-btn { border: 1px solid var(--ink); background: var(--ink); color: var(--paper); padding: 11px 26px; font: 600 12px var(--sans); letter-spacing: .16em; text-transform: uppercase; }
.explore-btn:hover { background: var(--accent); border-color: var(--accent); }
.colophon { padding: 8vh 28px 16vh 44px; border-top: 1px solid var(--rule); font-size: 12.5px; color: var(--ink-2); }
.colophon dl { margin: 0; }
.colophon dt { font-weight: 600; color: var(--ink); margin-top: 10px; }
.colophon dd { margin: 2px 0 0; }

/* segmentados */
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--rule); background: #fff; }
.seg button { border: 0; background: none; padding: 6px 10px; font-size: 12.5px; color: var(--ink-2); border-right: 1px solid var(--rule); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ink); color: #fff; }
.seg.big { display: grid; grid-template-columns: 1fr 1fr; margin: 4px 0 10px; }
.seg.big button { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--rule); }
.seg.small button { padding: 4px 9px; font-size: 12px; }
.seg.xs button { padding: 2px 6px; font-size: 11px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0; }
.pair select { width: 100%; margin-top: 4px; padding: 5px; border: 1px solid var(--rule); background: #fff; }
.presets { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.presets button { text-align: left; background: none; border: 0; border-bottom: 1px dotted var(--rule); padding: 4px 0; color: var(--ink-2); font-size: 12.5px; }
.presets button:hover { color: var(--accent); }

#explore-panel { padding: 30px 26px 40px 44px; }
.xgroup { margin: 16px 0; display: flex; flex-direction: column; gap: 6px; }
.chk { font-size: 13px; color: var(--ink-2); display: flex; gap: 8px; align-items: center; }
#x-stats { border-top: 1px solid var(--rule); padding-top: 12px; margin-top: 16px; font-size: 12.5px; }
#x-stats table { width: 100%; border-collapse: collapse; }
#x-stats td { padding: 3px 0; border-bottom: 1px dotted var(--rule); }
#x-stats td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------- escenario */
#stage { position: relative; height: 100vh; overflow: hidden; background: #eeece6; }
#map { position: absolute; inset: 0; }
#ctrl {
  position: absolute; z-index: 5; top: 0; left: 0; right: 0; min-height: var(--ctrl-h);
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 16px; padding: 8px 16px 9px;
  background: rgba(247, 245, 240, .93); backdrop-filter: blur(6px); border-bottom: 1px solid var(--rule);
}
#ctrl .c { display: flex; flex-direction: column; gap: 3px; }
#ctrl .c > span { font: 600 9.5px var(--sans); letter-spacing: .11em; text-transform: uppercase; color: var(--ink-3); }
#ctrl select { border: 1px solid var(--rule); background: #fff; padding: 3px 4px; font-size: 12px; max-width: 170px; }
#ctrl .end { margin-left: auto; flex-direction: row; gap: 6px; }
#ctrl .ghost, #ctrl .solid { border: 1px solid var(--ink); padding: 5px 11px; font: 600 11px var(--sans); letter-spacing: .08em; text-transform: uppercase; background: transparent; }
#ctrl .solid { background: var(--ink); color: #fff; }
#ctrl .solid:hover { background: var(--accent); border-color: var(--accent); }
#ctrl-toggle { display: none; }
.echips { display: flex; gap: 2px; }
.echips button { border: 1px solid var(--rule); background: #fff; font: 600 10.5px var(--sans); padding: 2px 5px; display: flex; gap: 4px; align-items: center; }
.echips button i { width: 9px; height: 9px; display: inline-block; }
.echips button.off { opacity: .35; }
.echips button.off i { background: transparent !important; outline: 1px solid var(--ink-3); }

.card { position: absolute; z-index: 4; background: rgba(247, 245, 240, .94); border: 1px solid var(--rule); padding: 9px 11px; font-size: 11.5px; }
.card-h { display: flex; justify-content: space-between; font: 600 9.5px var(--sans); letter-spacing: .11em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 4px; }
#legend { left: 14px; bottom: 30px; max-width: 250px; }
#legend .lg-t { font: 600 9.5px var(--sans); letter-spacing: .11em; text-transform: uppercase; color: var(--ink-3); margin: 6px 0 4px; }
#legend .lg-t:first-child { margin-top: 0; }
#legend .row { display: flex; align-items: center; gap: 6px; line-height: 1.5; }
#legend .sw { width: 12px; height: 10px; flex: none; }
#legend .ramp { display: flex; height: 8px; margin: 2px 0; }
#legend .ramp i { flex: 1; }
#legend .ends { display: flex; justify-content: space-between; color: var(--ink-3); font-size: 10.5px; }
#legend .ln { width: 18px; height: 0; border-top: 3px solid var(--ink); flex: none; }
#legend .muted { color: var(--ink-3); font-size: 10.5px; }
#hist { right: 14px; top: calc(var(--ctrl-h) + 12px); width: 250px; }
#hist svg { width: 100%; height: 92px; display: block; }
#hist .bar { cursor: pointer; }
#hist .bar.off rect.b { fill: #e3e0d8 !important; }
.hist-foot { color: var(--ink-3); font-size: 10.5px; margin-top: 2px; }
#north { position: absolute; right: 14px; bottom: 34px; z-index: 3; opacity: .8; }
.maplibregl-ctrl-scale { background: rgba(247, 245, 240, .85) !important; border-color: var(--ink-2) !important; color: var(--ink-2) !important; font: 10px var(--sans) !important; }
.maplibregl-ctrl-attrib { font-size: 10px; background: rgba(247, 245, 240, .7) !important; }

/* panel inferior */
.sheet { position: absolute; z-index: 4; left: 0; right: 0; bottom: 0; max-height: 52vh; overflow-y: auto; background: rgba(247, 245, 240, .965); border-top: 1px solid var(--rule); padding: 10px 16px 12px; backdrop-filter: blur(4px); }
.sheet-h { display: flex; gap: 12px; align-items: baseline; margin-bottom: 4px; }
.sheet-h > span:first-child { font: 600 10.5px var(--sans); letter-spacing: .12em; text-transform: uppercase; }
.sheet-h .sub { color: var(--ink-3); font-size: 11.5px; }
#bottom-body { overflow-x: auto; }
#bottom-body svg { display: block; }
.prof text { font: 10.5px var(--sans); fill: var(--ink-2); }
.prof .rowlbl { font: 600 9.5px var(--sans); letter-spacing: .06em; text-transform: uppercase; fill: var(--ink-3); }
.prof .cellt { font: 500 10.5px var(--sans); fill: var(--ink); pointer-events: none; }
.prof .cellt.inv { fill: #fff; }
.prof .col-hl { fill: none; stroke: var(--accent); stroke-width: 2; pointer-events: none; }
.prof .cursor { stroke: var(--accent); stroke-width: 1; pointer-events: none; }

/* nodos: pequeños múltiplos */
.nodes-grid { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 12px; }
.ncell .kv span:first-child { overflow: hidden; text-overflow: ellipsis; }
.ncell { cursor: pointer; border-top: 3px solid transparent; padding-top: 4px; }
.ncell.on { border-top-color: var(--accent); }
.ncell canvas { width: 100%; aspect-ratio: 1; display: block; background: #fbfaf7; }
.ncell .nt { font: 600 11px/1.2 var(--sans); margin: 4px 0 2px; display: flex; gap: 5px; align-items: baseline; min-height: 28px; }
.ncell .nt b { font: 600 10px var(--sans); background: var(--ink); color: #fff; border-radius: 50%; width: 16px; height: 16px; display: inline-grid; place-items: center; flex: none; }
.ncell.on .nt b { background: var(--accent); }
.ncell .kv { display: flex; justify-content: space-between; gap: 4px; white-space: nowrap; font-size: 10.5px; color: var(--ink-2); border-bottom: 1px dotted var(--rule); font-variant-numeric: tabular-nums; }
.ncell .kv span:last-child { color: var(--ink); font-weight: 500; }
.stackbar { display: flex; height: 7px; margin: 4px 0 2px; }
.stackbar i { display: block; height: 100%; }

/* ficha de predio */
.drawer { position: absolute; z-index: 6; right: 0; top: var(--ctrl-h); bottom: 0; width: 330px; background: rgba(247, 245, 240, .98); border-left: 1px solid var(--rule); padding: 18px 20px 24px; overflow-y: auto; }
.drawer .x { position: absolute; right: 10px; top: 8px; border: 0; background: none; font-size: 22px; color: var(--ink-3); }
.ficha h4 { font: 600 10px var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); margin: 16px 0 4px; }
.ficha .clave { font: 500 20px/1.2 var(--serif); letter-spacing: .01em; word-break: break-all; }
.ficha table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ficha td { padding: 3px 0; border-bottom: 1px dotted var(--rule); vertical-align: top; }
.ficha td:first-child { color: var(--ink-3); width: 48%; }
.ficha td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.ficha .flag { margin: 12px 0 0; padding: 8px 10px; background: var(--accent-soft); border-left: 3px solid var(--accent); font-size: 12.5px; }
.ficha .cusbar { position: relative; height: 26px; margin: 8px 0 2px; background: #ecE9e2; }
.ficha .cusbar i { position: absolute; top: 0; bottom: 0; left: 0; }
.ficha .muted { color: var(--ink-3); font-size: 11.5px; }
.tag { display: inline-block; padding: 1px 6px; font: 600 10.5px var(--sans); color: #fff; }

/* comparador */
#compare { position: absolute; z-index: 4; left: 0; right: 0; top: var(--ctrl-h); bottom: 0; background: var(--paper); display: grid; grid-template-rows: 56% 44%; }
.cmp-maps { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; background: var(--rule); }
.cmp-col { position: relative; }
.cmp-map { position: absolute; inset: 0; }
.cmp-title { position: absolute; z-index: 3; left: 12px; top: 10px; background: rgba(247, 245, 240, .92); padding: 5px 9px; font: 500 16px var(--serif); display: flex; gap: 8px; align-items: center; }
.cmp-title b { font: 600 11px var(--sans); background: var(--ink); color: #fff; border-radius: 50%; width: 20px; height: 20px; display: inline-grid; place-items: center; }
.cmp-table { overflow-y: auto; padding: 10px 24px 16px; }
.bf { width: 100%; border-collapse: collapse; font-size: 12px; }
.bf td { padding: 3px 6px; border-bottom: 1px dotted var(--rule); font-variant-numeric: tabular-nums; }
.bf td.l { text-align: center; color: var(--ink-3); font: 600 9.5px var(--sans); letter-spacing: .08em; text-transform: uppercase; width: 190px; }
.bf td.a { text-align: right; width: 38%; }
.bf td.b { text-align: left; width: 38%; }
.bf .bw { display: inline-flex; align-items: center; gap: 6px; }
.bf td.a .bw { flex-direction: row-reverse; }
.bf .bb { display: inline-block; height: 9px; background: var(--ink-2); }
.bf tr.sec td { border-bottom: 1px solid var(--rule); padding-top: 10px; font: 600 10px var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--ink); text-align: center; }

/* síntesis */
#synth { position: absolute; z-index: 4; right: 0; top: var(--ctrl-h); bottom: 0; width: min(66%, 1000px); background: rgba(247, 245, 240, .97); border-left: 1px solid var(--rule); overflow-y: auto; padding: 16px 22px 30px; }
.syn-h { margin-bottom: 8px; }
.syn-h.second { margin-top: 22px; }
.syn-h .sub { color: var(--ink-3); font-size: 11.5px; }
.mx { width: 100%; border-collapse: collapse; font-size: 11.5px; table-layout: fixed; }
.mx tr.on td { background: var(--accent-soft); }
.mx-foot { margin-top: 8px; color: var(--ink-3); font-size: 11px; line-height: 1.45; }
.mx-foot b { color: var(--ink-2); }
.mx th { font: 600 9px var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--ink-2); vertical-align: bottom; }
.mx td { padding: 6px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.mx td.nd { font: 500 13px/1.2 var(--serif); }
.mx td.nd b { font: 600 10px var(--sans); background: var(--ink); color: #fff; border-radius: 50%; width: 16px; height: 16px; display: inline-grid; place-items: center; margin-right: 4px; }
.mx .v { font-variant-numeric: tabular-nums; }
.mx .d { color: var(--ink-3); font-size: 10.5px; }
.mx td.pend { color: var(--ink-3); text-align: center; background: repeating-linear-gradient(135deg, transparent 0 5px, rgba(0,0,0,.035) 5px 6px); }
.mx td.norm { border-left: 2px dashed var(--ink-3); color: var(--ink-3); font-style: italic; }
.mx .rd { display: inline-block; margin: 2px 3px 0 0; padding: 0 5px; border: 1px solid var(--rule); font-size: 10px; background: #fff; }
.quad text { font: 10.5px var(--sans); fill: var(--ink-2); }
.quad .ql { font: 600 9.5px var(--sans); letter-spacing: .06em; text-transform: uppercase; fill: var(--ink-3); }

#tip { position: absolute; z-index: 20; pointer-events: none; background: #1b1b1a; color: #f5f3ee; font-size: 11.5px; line-height: 1.45; padding: 7px 9px; max-width: 290px; display: none; }
#tip b { color: #fff; }
#tip .m { color: #b9b5ab; }

/* marcadores de nodo (HTML: no requieren glifos remotos) */
.nmk { width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: #fff; font: 600 11px/22px var(--sans); text-align: center; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); cursor: pointer; }
.nmk.on { background: var(--accent); transform: scale(1.18); }
.nmk.dim { opacity: .45; }
.clabel { font: 600 10px var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--ink); background: rgba(247,245,240,.85); padding: 1px 5px; white-space: nowrap; pointer-events: none; }
.szlabel { font: 500 12px var(--serif); color: var(--ink-3); pointer-events: none; }

/* modo exploración */
body.explore #story, body.explore #dots, body.explore .rail-head .hint { display: none; }
body.explore #explore-panel { display: block !important; }

/* ---------------- responsive */
@media (max-width: 900px) {
  html, body { height: auto; }
  body { display: block; overflow: visible; }
  #stage { position: fixed; top: 0; left: 0; right: 0; height: 56vh; z-index: 3; border-bottom: 1px solid var(--rule); }
  #rail { height: auto; overflow: visible; border-right: 0; padding-top: 56vh; }
  .scene { min-height: 62vh; padding: 6vh 16px 10vh; }
  .scene:first-child { padding-top: 6vh; }
  .rail-head { padding: 22px 16px 6px; }
  .colophon, #explore-panel { padding-left: 16px; padding-right: 16px; }
  #dots { display: none; }
  #ctrl { min-height: 40px; padding: 6px 10px; gap: 6px 10px; }
  #ctrl .c:not(.end) { display: none; }
  #ctrl.open .c { display: flex; }
  #ctrl .end { margin-left: 0; }
  #ctrl-toggle { display: inline-block; border: 1px solid var(--ink); background: #fff; padding: 4px 9px; font-size: 11px; margin-left: auto; }
  #legend, #hist, #north { display: none; }
  .sheet { max-height: 60%; }
  .nodes-grid { grid-template-columns: repeat(9, 120px); overflow-x: auto; }
  #synth { width: 100%; }
  .mx { table-layout: auto; min-width: 760px; }
  .drawer { width: 100%; }
  #compare { grid-template-rows: 50% 50%; }
  .bf td.l { width: 110px; }
}

/* ---- atlas vaciamiento y valor ---- */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 14px 0; }
.kpis div { border-top: 1px solid var(--rule); padding-top: 6px; }
.kpis b { display: block; font: 500 24px/1.1 var(--serif); }
.kpis span { font-size: 11.5px; color: var(--ink-3); }
.rules { font-size: 12px; color: var(--ink-2); margin: 10px 0; padding: 0; list-style: none; }
.rules li { display: flex; gap: 8px; padding: 4px 0; border-bottom: 1px dotted var(--rule); }
.rules i { width: 11px; height: 11px; flex: none; margin-top: 3px; }
.mxcell { cursor: pointer; }
.mxcell:hover rect { stroke: var(--accent); stroke-width: 2; }
.cmp2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.cmp2 .card2 { display: grid; grid-template-columns: 170px 1fr; gap: 12px; }
.cmp2 canvas { width: 170px; height: 170px; background: #fbfaf7; }
.cmp2 h4 { font: 500 18px var(--serif); margin: 0 0 4px; }
.cmp2 select { font-size: 12px; border: 1px solid var(--rule); background: #fff; padding: 2px 4px; }
.kv2 { display: flex; justify-content: space-between; font-size: 11.5px; border-bottom: 1px dotted var(--rule); padding: 2px 0; font-variant-numeric: tabular-nums; }
.kv2 span:first-child { color: var(--ink-3); }
.pricebar { position: relative; height: 12px; background: #efece6; margin: 2px 0 6px; }
.pricebar i { position: absolute; top: 2px; bottom: 2px; }
.pol { width: 100%; border-collapse: collapse; font-size: 12px; }
.pol th { text-align: left; font: 600 9.5px var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); border-bottom: 1px solid var(--ink-2); padding: 5px 6px; }
.pol td { border-bottom: 1px solid var(--rule); padding: 7px 6px; vertical-align: top; }
.pol td:first-child { font: 500 14px/1.2 var(--serif); white-space: nowrap; }
.pol .sw { display: inline-block; width: 10px; height: 10px; margin-right: 6px; }
.pol .d { color: var(--ink-3); font-size: 11px; }
