:root {
  /* Layout: mapa a pantalla completa; barra superior flotante; panel Explorar a la izquierda; ficha a la derecha; vistas en hoja lateral (móvil: hojas inferiores + barra de navegación) */
  --bg: #eef1f5;
  --glass: rgba(255, 255, 255, .84);
  --solid: #ffffff;
  --ink: #0e1620;
  --muted: #5b6676;
  --faint: #8a94a3;
  --line: rgba(14, 22, 32, .10);
  --line-2: rgba(14, 22, 32, .16);
  --soft: rgba(14, 22, 32, .045);
  --soft-2: rgba(14, 22, 32, .075);
  --accent: #e3061c;
  --accent-ink: #ffffff;
  --accent-soft: rgba(227, 6, 28, .09);
  --good: #2463b0;
  --bad: #c23a2f;
  --warn: #a86400;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgba(14, 22, 32, .06), 0 8px 28px rgba(14, 22, 32, .10);
  --shadow-lg: 0 2px 6px rgba(14, 22, 32, .08), 0 18px 50px rgba(14, 22, 32, .16);
  --font-display: "Archivo", "Helvetica Neue", Arial, system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --r: 16px; --r-sm: 11px; --r-xs: 8px;
  --g: 14px;
  --top-h: 60px;
  --panel-w: 344px;
  --card-w: 396px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0e13; --glass: rgba(15, 21, 29, .84); --solid: #121a24; --ink: #e8edf3; --muted: #9aa5b4; --faint: #6f7a89;
    --line: rgba(255, 255, 255, .09); --line-2: rgba(255, 255, 255, .15); --soft: rgba(255, 255, 255, .05); --soft-2: rgba(255, 255, 255, .085);
    --accent: #ff3347; --accent-ink: #ffffff; --accent-soft: rgba(255, 51, 71, .14); --good: #6fa8ff; --bad: #ff7d6e; --warn: #f0b04a; --focus: #7fb0ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .45); --shadow-lg: 0 2px 8px rgba(0, 0, 0, .35), 0 20px 60px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0e13; --glass: rgba(15, 21, 29, .84); --solid: #121a24; --ink: #e8edf3; --muted: #9aa5b4; --faint: #6f7a89;
  --line: rgba(255, 255, 255, .09); --line-2: rgba(255, 255, 255, .15); --soft: rgba(255, 255, 255, .05); --soft-2: rgba(255, 255, 255, .085);
  --accent: #ff3347; --accent-ink: #ffffff; --accent-soft: rgba(255, 51, 71, .14); --good: #6fa8ff; --bad: #ff7d6e; --warn: #f0b04a; --focus: #7fb0ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .45); --shadow-lg: 0 2px 8px rgba(0, 0, 0, .35), 0 20px 60px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 400 14.5px/1.5 var(--font-body); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; overflow: hidden; overscroll-behavior: none; touch-action: manipulation; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; letter-spacing: -.01em; margin: 0; text-wrap: balance; }
a { color: var(--good); text-underline-offset: 2px; }
.num, td, .kpi b, .mono { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.sm { width: 16px; height: 16px; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.tiny { font-size: 12px; color: var(--muted); }

#app { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; background: var(--bg); }
.glass { background: var(--glass); -webkit-backdrop-filter: blur(18px) saturate(160%); backdrop-filter: blur(18px) saturate(160%); border: 1px solid var(--line); box-shadow: var(--shadow); }
.glass-solid { background: var(--solid); border: 1px solid var(--line); box-shadow: var(--shadow-lg); }
@supports not ((backdrop-filter: blur(2px)) or (-webkit-backdrop-filter: blur(2px))) { .glass { background: var(--solid); } }

/* ---------------- buttons & inputs ---------------- */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 40px; height: 40px; padding: 0 10px; border-radius: 12px; border: 1px solid transparent; background: transparent; color: var(--ink); }
.icon-btn:hover { background: var(--soft-2); }
.icon-btn.sm { min-width: 34px; height: 34px; padding: 0 8px; border-radius: 10px; }
.icon-btn.txt span { font: 600 12.5px/1 var(--font-mono); letter-spacing: .04em; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 0 14px; border-radius: 11px; border: 1px solid var(--line-2); background: var(--solid); color: var(--ink); font-weight: 500; font-size: 14px; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--ink); color: var(--solid); border-color: var(--ink); }
.btn.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.block { width: 100%; }
.btn.small { min-height: 32px; padding: 0 11px; font-size: 13px; border-radius: 9px; }
select, input[type="number"], input[type="search"], input[type="text"] {
  min-height: 38px; padding: 0 12px; border-radius: 11px; border: 1px solid var(--line-2); background: var(--solid); color: var(--ink); width: 100%; font-size: 14px;
}
select { -webkit-appearance: none; appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a94a3' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6.5 9.5 5.5 5.5 5.5-5.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }
input[type="checkbox"] { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; flex: none; }
label.field { display: grid; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); background: var(--solid); border-radius: 999px; padding: 5px 11px; font-size: 13px; line-height: 1.2; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--solid); border-color: var(--ink); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; background: var(--soft); border: 1px solid var(--line); white-space: nowrap; }
.pill.good { color: var(--good); background: rgba(36, 99, 176, .08); border-color: rgba(36, 99, 176, .22); }
.pill.bad { color: var(--bad); background: rgba(194, 58, 47, .08); border-color: rgba(194, 58, 47, .22); }
.pill.est { color: var(--warn); background: rgba(168, 100, 0, .08); border-color: rgba(168, 100, 0, .22); }
.badge { font: 600 11.5px/1 var(--font-mono); letter-spacing: .04em; border: 1px solid var(--line-2); border-radius: 6px; padding: 4px 6px; color: var(--muted); }
.info { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--faint); color: var(--faint); font: 700 10px/1 var(--font-body); text-decoration: none; margin-left: 5px; vertical-align: 1px; cursor: help; }

/* ---------------- top bar ---------------- */
.topbar { position: absolute; z-index: 20; top: calc(var(--g) + var(--sat)); left: calc(var(--g) + var(--sal)); right: calc(var(--g) + var(--sar)); height: var(--top-h); border-radius: var(--r); display: flex; align-items: center; gap: 10px; padding: 0 10px 0 12px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; min-width: 0; flex: none; }
.logo svg { width: 34px; height: 34px; display: block; }
.logo rect { fill: var(--accent); } .logo path { fill: #fff; }
.wm { display: grid; line-height: 1.05; min-width: 0; }
.wm b { font: 700 19px/1 var(--font-display); letter-spacing: -.02em; }
.wm small { color: var(--muted); font-size: 11.5px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.mainnav { display: flex; gap: 2px; margin: 0 auto; background: var(--soft); border-radius: 12px; padding: 3px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.mainnav::-webkit-scrollbar { display: none; }
.mainnav button { display: inline-flex; align-items: center; gap: 7px; border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; color: var(--muted); font-weight: 500; font-size: 13.5px; white-space: nowrap; }
.mainnav button .ic { width: 17px; height: 17px; }
.mainnav button:hover { color: var(--ink); }
.mainnav button[aria-current="true"] { background: var(--solid); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.tb-right { display: flex; align-items: center; gap: 4px; flex: none; }
.search { position: relative; display: flex; align-items: center; }
.search > .ic { position: absolute; left: 11px; color: var(--faint); pointer-events: none; width: 17px; height: 17px; }
.search input { width: 280px; padding-left: 34px; border-radius: 11px; background: var(--soft); border-color: transparent; }
.search input:focus { background: var(--solid); border-color: var(--line-2); }
.sugg { position: absolute; top: calc(100% + 6px); right: 0; width: max(100%, 320px); border-radius: 14px; max-height: 60vh; overflow: auto; z-index: 40; display: none; padding: 6px; }
.sugg button { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 9px; }
.sugg button:hover, .sugg button.on { background: var(--soft-2); }
.sugg small { color: var(--muted); font-size: 12px; text-align: right; }
#searchBtn { display: none; }
.dd { position: relative; }
.dd-menu { position: absolute; right: 0; top: calc(100% + 6px); border-radius: 14px; padding: 6px; display: none; min-width: 170px; z-index: 40; }
.dd.open .dd-menu { display: grid; }
.dd-menu button { border: 0; background: transparent; text-align: left; padding: 9px 12px; border-radius: 9px; display: flex; justify-content: space-between; gap: 12px; }
.dd-menu button:hover { background: var(--soft-2); }
.dd-menu button[aria-selected="true"] { font-weight: 600; }
.dd-menu small { font-family: var(--font-mono); color: var(--muted); }
.show-sm { display: none !important; }

/* ---------------- panels ---------------- */
.panel { position: absolute; z-index: 10; top: calc(var(--top-h) + var(--g) * 2 + var(--sat)); bottom: calc(var(--g) + var(--sab)); border-radius: var(--r); display: flex; flex-direction: column; overflow: hidden; transition: transform .3s cubic-bezier(.2,.8,.2,1), opacity .2s; }
.explore { left: calc(var(--g) + var(--sal)); width: var(--panel-w); }
.card { right: calc(var(--g) + var(--sar)); width: var(--card-w); }
#app:not(.explore-open) .explore { transform: translateX(calc(-100% - var(--g) * 2)); opacity: 0; pointer-events: none; }
#app:not(.card-open) .card { transform: translateX(calc(100% + var(--g) * 2)); opacity: 0; pointer-events: none; }
.phead { display: flex; align-items: center; gap: 8px; padding: 12px 10px 10px 16px; border-bottom: 1px solid var(--line); flex: none; }
.phead h2 { font-size: 16px; flex: 1; }
.grab { display: none; }
.pbody { overflow-y: auto; overflow-x: hidden; padding: 6px 0 14px; flex: 1; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.explore-tab { position: absolute; z-index: 9; left: calc(var(--g) + var(--sal)); top: calc(var(--top-h) + var(--g) * 2 + var(--sat)); height: 42px; border-radius: 12px; display: none; align-items: center; gap: 8px; padding: 0 14px; font-weight: 600; font-size: 14px; color: var(--ink); }
#app:not(.explore-open) .explore-tab { display: inline-flex; }
.metric-pill { display: none; }

/* sections inside panels */
.sec { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sec:last-child { border-bottom: 0; }
.sec > h3, .sech { font: 700 12px/1.2 var(--font-display); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
details.acc { border-bottom: 1px solid var(--line); }
details.acc > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 13px 16px; cursor: pointer; font-weight: 600; font-size: 14.5px; user-select: none; }
details.acc > summary::-webkit-details-marker { display: none; }
details.acc > summary .ic.chev { margin-left: auto; transition: transform .2s; color: var(--faint); width: 18px; height: 18px; }
details.acc[open] > summary .ic.chev { transform: rotate(180deg); }
details.acc > summary .sic { width: 30px; height: 30px; border-radius: 9px; background: var(--soft); display: grid; place-items: center; color: var(--muted); flex: none; }
details.acc > summary .sic .ic { width: 17px; height: 17px; }
details.acc > summary small { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; margin-top: 1px; }
details.acc > .accb { padding: 0 16px 14px; display: grid; gap: 10px; }

.mgroup { display: grid; gap: 2px; }
.mgroup + .mgroup { margin-top: 10px; }
.mgroup > span { font: 600 11px/1.3 var(--font-display); text-transform: uppercase; letter-spacing: .09em; color: var(--faint); padding: 0 4px 4px; }
.mopt { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; padding: 8px 10px; border-radius: 10px; text-align: left; font-size: 14px; color: var(--ink); }
.mopt:hover { background: var(--soft-2); }
.mopt .sw { width: 22px; height: 8px; border-radius: 4px; flex: none; opacity: .35; background: linear-gradient(90deg, #2f6db3, #ebe5d8, #cf543f); }
.mopt[aria-pressed="true"] { background: var(--accent-soft); font-weight: 600; }
.mopt[aria-pressed="true"] .sw { opacity: 1; }
.mopt small { margin-left: auto; color: var(--faint); font-size: 11.5px; }

.check { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; font-size: 14px; }
.cond { display: grid; grid-template-columns: minmax(0, 1fr) 58px 84px 30px; gap: 6px; align-items: center; }
.cond select, .cond input { min-height: 36px; font-size: 13.5px; padding-left: 9px; }
.cond select { padding-right: 26px; background-position: right 6px center; }
.x { border: 0; background: transparent; color: var(--faint); width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.x:hover { background: var(--soft-2); color: var(--ink); }

.list { display: grid; gap: 2px; }
.li { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 8px; border-radius: 10px; cursor: pointer; border: 0; background: transparent; width: 100%; text-align: left; color: var(--ink); }
.li:hover { background: var(--soft-2); }
.li .r { font: 600 12px/1 var(--font-mono); color: var(--faint); text-align: center; }
.li b { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .v { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 13.5px; }
.li .sub { color: var(--muted); font-size: 12px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { display: block; height: 6px; border-radius: 3px; background: var(--soft-2); overflow: hidden; margin-top: 5px; }
.bar > i { display: block; height: 100%; border-radius: 3px; }

/* ---------------- card ---------------- */
.chead { padding: 16px 16px 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; flex: none; position: relative; }
.chead .top { display: flex; align-items: center; gap: 8px; }
.chead .top .sp { flex: 1; }
.chead h2 { font-size: 27px; line-height: 1.05; letter-spacing: -.02em; }
.chead .sub { color: var(--muted); font-size: 13px; }
.flagdot { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); display: inline-block; }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.kpi { background: var(--soft); border: 1px solid var(--line); border-radius: 13px; padding: 10px 12px; display: grid; gap: 1px; min-width: 0; position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--kc, transparent); }
.kpi span { font-size: 12px; color: var(--muted); display: flex; align-items: center; }
.kpi b { font: 600 19px/1.25 var(--font-display); letter-spacing: -.01em; overflow-wrap: anywhere; }
.kpi em { font-style: normal; font-size: 11.5px; color: var(--faint); }
.ins { display: grid; gap: 6px; }
.insi { display: grid; grid-template-columns: 18px 1fr; gap: 8px; font-size: 13.5px; line-height: 1.4; align-items: start; }
.insi .ic { width: 16px; height: 16px; margin-top: 2px; }
.insi.good .ic { color: var(--good); } .insi.bad .ic { color: var(--bad); } .insi.neu .ic { color: var(--muted); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 7px 14px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; }
.hb { display: grid; gap: 8px; }
.hbr { display: grid; grid-template-columns: minmax(90px, 1fr) 1.4fr 58px; gap: 10px; align-items: center; font-size: 13px; }
.hbr .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbr .trk { position: relative; height: 10px; background: var(--soft-2); border-radius: 5px; }
.hbr .trk i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; }
.hbr .trk s { position: absolute; top: -3px; bottom: -3px; width: 2px; border-radius: 1px; background: var(--ink); opacity: .45; }
.hbr .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
ul.notes { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 13.5px; color: var(--ink); }
.note { font-size: 12.5px; color: var(--muted); background: var(--soft); border-radius: 10px; padding: 9px 11px; margin: 0; }
.peek-more { display: none; }

/* ---------------- map controls ---------------- */
.mapctl { position: absolute; z-index: 12; top: calc(var(--top-h) + var(--g) * 2 + var(--sat)); right: calc(var(--g) + var(--sar)); display: grid; gap: 8px; transition: right .3s cubic-bezier(.2,.8,.2,1); }
#app.card-open .mapctl { right: calc(var(--card-w) + var(--g) * 2 + var(--sar)); }
.ctlgroup { display: grid; border-radius: 13px; overflow: hidden; }
.ctl { width: 42px; height: 40px; display: grid; place-items: center; border: 0; background: transparent; color: var(--ink); }
.ctl + .ctl { border-top: 1px solid var(--line); }
.ctl:hover { background: var(--soft-2); }
.ctl[aria-pressed="true"] { color: var(--accent); }
.ctl.txt { font: 700 12.5px/1 var(--font-mono); letter-spacing: .03em; }
.ctl:disabled { opacity: .35; cursor: default; }
.pop { position: absolute; right: calc(100% + 8px); bottom: 0; width: 230px; border-radius: 13px; padding: 10px 12px; display: grid; gap: 6px; font-size: 12.5px; color: var(--muted); }
.pop .row { flex-wrap: nowrap; } .pop output { font: 600 12.5px var(--font-mono); color: var(--ink); min-width: 38px; text-align: right; }

/* ---------------- legend ---------------- */
.legend { position: absolute; z-index: 11; bottom: calc(var(--g) + var(--sab)); left: calc(var(--g) + var(--sal)); width: 330px; border-radius: 14px; padding: 10px 13px 11px; display: grid; gap: 6px; transition: left .3s cubic-bezier(.2,.8,.2,1); }
#app.explore-open .legend { left: calc(var(--panel-w) + var(--g) * 2 + var(--sal)); }
.legend .lt { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 600; font-size: 13px; }
.legend .lt span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .grad { height: 10px; border-radius: 5px; }
.legend .ends { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; gap: 8px; }
.legend .ends b { font-weight: 600; color: var(--ink); }
.legend .cats { display: flex; flex-wrap: wrap; gap: 5px 12px; font-size: 12px; }
.legend .cats span { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* ---------------- sheet (views) ---------------- */
.sheet { position: absolute; z-index: 30; top: calc(var(--top-h) + var(--g) * 2 + var(--sat)); right: calc(var(--g) + var(--sar)); bottom: calc(var(--g) + var(--sab)); width: min(1040px, calc(100vw - var(--g) * 2)); border-radius: var(--r); display: flex; flex-direction: column; overflow: hidden; animation: sheetIn .28s cubic-bezier(.2,.8,.2,1); }
@keyframes sheetIn { from { transform: translateY(10px); opacity: .0; } to { transform: none; opacity: 1; } }
.shead { display: flex; align-items: center; gap: 10px; padding: 14px 14px 12px 20px; border-bottom: 1px solid var(--line); flex: none; }
.shead h2 { font-size: 20px; flex: 1; }
.sbody { overflow: auto; flex: 1; padding: 16px 20px 24px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sintro { max-width: 70ch; color: var(--muted); margin: 0 0 14px; }
.tablewrap { overflow: auto; border: 1px solid var(--line); border-radius: 13px; max-height: calc(100% - 50px); }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; text-align: right; }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--solid); z-index: 1; border-right: 1px solid var(--line); }
thead th { position: sticky; top: 0; background: var(--solid); z-index: 2; font: 600 12px/1.2 var(--font-body); color: var(--muted); cursor: pointer; user-select: none; }
thead th:first-child { z-index: 3; }
thead th.on { color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--soft); }
tbody tr:hover td:first-child { background: var(--solid); }
tbody tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
tbody tr.dim td { opacity: .4; }
td .cell { display: inline-flex; align-items: center; gap: 6px; justify-content: flex-end; }
td .cell i { width: 7px; height: 7px; border-radius: 2px; display: inline-block; }
.nd { color: var(--faint); }
.grid2 { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 22px; align-items: start; }
.cmpsel { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.cmpgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.cmpcard { border: 1px solid var(--line); border-radius: 15px; padding: 14px; display: grid; gap: 9px; background: var(--soft); align-content: start; }
.cmpcard h3 { font-size: 19px; }
.cmpm { display: grid; gap: 3px; font-size: 13px; }
.cmpm .row { flex-wrap: nowrap; justify-content: space-between; }
.cmpm .row span:first-child { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmpm .best { color: var(--good); font-weight: 700; }
.prof { display: flex; flex-wrap: wrap; gap: 6px; }
.slider { display: grid; grid-template-columns: minmax(0, 1fr) 120px 22px; align-items: center; gap: 10px; font-size: 13.5px; }
.slider output { text-align: right; font: 600 12.5px var(--font-mono); color: var(--muted); }
.tiles2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.prose { max-width: 760px; display: grid; gap: 4px; }
.prose details.acc { border: 1px solid var(--line); border-radius: 13px; margin-bottom: 8px; background: var(--soft); }
.prose details.acc > summary { padding: 13px 16px; }
.prose .accb { padding-top: 0; }
.srcs { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 6px 18px; font-size: 13px; }

/* ---------------- tooltip, toast, fallback ---------------- */
#tip { position: absolute; z-index: 50; pointer-events: none; background: var(--solid); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 9px 12px; font-size: 13px; display: none; min-width: 170px; max-width: 260px; }
#tip b { font: 700 15px/1.2 var(--font-display); }
#tip .tv { font: 600 18px/1.3 var(--font-display); margin-top: 3px; }
.toast { position: absolute; z-index: 60; left: 50%; bottom: calc(var(--g) * 2 + var(--sab) + 60px); transform: translate(-50%, 20px); border-radius: 12px; padding: 10px 14px; font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; max-width: min(92vw, 520px); text-align: center; }
.toast.on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast input { margin-top: 8px; font-family: var(--font-mono); font-size: 12px; }
.fallback { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; z-index: 1; }
.fallback .box { max-width: 420px; text-align: center; display: grid; gap: 12px; }
.scrim { position: absolute; inset: 0; z-index: 25; background: rgba(5, 10, 16, .32); }
.menu-sheet { position: absolute; z-index: 45; right: calc(var(--g) + var(--sar)); top: calc(var(--top-h) + var(--g) + var(--sat) + 6px); width: 270px; border-radius: 16px; padding: 8px; display: grid; gap: 2px; }
.menu-sheet button { display: flex; align-items: center; gap: 12px; border: 0; background: transparent; padding: 11px 12px; border-radius: 10px; text-align: left; font-size: 14.5px; width: 100%; color: var(--ink); }
.menu-sheet button:hover { background: var(--soft-2); }
.menu-sheet hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.bottomnav { display: none; }

.maplibregl-ctrl-attrib { font-size: 10.5px; border-radius: 8px 0 0 0; }
.maplibregl-ctrl-bottom-right { right: calc(var(--sar)); bottom: var(--sab); }
#app.card-open .maplibregl-ctrl-bottom-right { right: calc(var(--card-w) + var(--g) * 2 + var(--sar)); }
.maplibregl-ctrl-attrib.maplibregl-compact { background: var(--glass); color: var(--muted); }
.maplibregl-ctrl-attrib a { color: var(--muted); }
.maplibregl-ctrl-scale { background: var(--glass); color: var(--muted); border-color: var(--muted); font-size: 10.5px; }
.maplibregl-popup-content { background: var(--solid) !important; color: var(--ink); border-radius: 12px !important; box-shadow: var(--shadow-lg) !important; padding: 10px 13px !important; font: 13px/1.45 var(--font-body); }
.maplibregl-popup-tip { border-top-color: var(--solid) !important; border-bottom-color: var(--solid) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 18px; padding: 0 7px; }

/* ================= tablet ================= */
@media (max-width: 1360px) { .wm small { display: none; } .search input { width: 220px; } }
@media (max-width: 1240px) {
  :root { --panel-w: 320px; --card-w: 368px; }
  .wm small { display: none; }
  .search input { width: 200px; }
  .mainnav button { padding: 7px 10px; }
}
@media (max-width: 1080px) {
  .mainnav button .lbl { display: none; }
  .mainnav button { padding: 8px 11px; }
  .legend { width: 290px; }
}
@media (max-width: 960px) {
  :root { --card-w: 344px; }
  #app.explore-open.card-open .legend { left: calc(var(--g) + var(--sal)); bottom: calc(var(--g) + var(--sab)); }
}

/* ================= phone & small tablet ================= */
@media (max-width: 760px), (max-height: 520px) and (max-width: 1000px) {
  :root { --g: 10px; --top-h: 56px; --nav-h: 62px; }
  body { font-size: 15px; }
  .topbar { top: 0; left: 0; right: 0; height: calc(var(--top-h) + var(--sat)); padding: var(--sat) calc(6px + var(--sar)) 0 calc(12px + var(--sal)); border-radius: 0; border-width: 0 0 1px; }
  .mainnav { display: none; }
  .hide-sm { display: none !important; }
  .show-sm { display: inline-flex !important; }
  .wm b { font-size: 18px; }
  .brand { margin-right: auto; }
  .search { position: absolute; left: 8px; right: 8px; top: calc(var(--sat) + 8px); display: none; z-index: 41; }
  .search.open { display: flex; }
  .search input { width: 100%; height: 40px; background: var(--solid); border-color: var(--line-2); }
  .sugg { width: 100%; }
  #searchBtn { display: inline-flex; }
  .metric-pill { position: absolute; z-index: 13; display: inline-flex; align-items: center; gap: 8px; left: calc(10px + var(--sal)); top: calc(var(--top-h) + var(--sat) + 10px); max-width: calc(100vw - 80px - var(--sal) - var(--sar)); height: 42px; padding: 0 12px; border-radius: 12px; font-weight: 600; font-size: 14px; color: var(--ink); }
  .metric-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .explore-tab { display: none !important; }
  .panel { top: auto; left: 0 !important; right: 0 !important; width: auto !important; bottom: calc(var(--nav-h) + var(--sab)); border-radius: 20px 20px 0 0; border-bottom: 0; max-height: calc(100% - var(--top-h) - var(--sat) - var(--nav-h) - var(--sab) - 24px); transform: none; }
  .grab { display: block; position: absolute; left: 50%; top: 6px; width: 38px; height: 4px; border-radius: 2px; background: var(--line-2); transform: translateX(-50%); }
  .phead { position: relative; padding-top: 16px; }
  #app:not(.explore-open) .explore, #app:not(.card-open) .card { transform: translateY(calc(100% + 80px)); opacity: 1; }
  .explore { height: min(76vh, 640px); }
  .card { height: min(80vh, 720px); }
  .card.peek { height: 248px; }
  .card.peek .cbody { overflow: hidden; }
  .card.peek .peek-more { display: flex; position: absolute; left: 0; right: 0; bottom: 0; height: 64px; align-items: flex-end; justify-content: center; padding-bottom: 10px; background: linear-gradient(180deg, transparent, var(--solid) 60%); }
  .chead { padding-top: 18px; }
  .chead h2 { font-size: 23px; }
  .mapctl { top: calc(var(--top-h) + var(--sat) + 10px); right: calc(10px + var(--sar)) !important; gap: 6px; }
  .zoomgrp { display: none; }
  .ctl { width: 42px; height: 40px; }
  .pop { right: calc(100% + 6px); bottom: auto; top: 0; }
  .legend { left: calc(10px + var(--sal)) !important; right: calc(10px + var(--sar)); width: auto; bottom: calc(var(--nav-h) + var(--sab) + 10px) !important; padding: 8px 11px 9px; }
  .legend .lt { font-size: 12.5px; }
  #app.explore-open .legend, #app.card-open .legend, #app.sheet-open .legend { opacity: 0; pointer-events: none; }
  .sheet { top: calc(var(--top-h) + var(--sat)); left: 0; right: 0; width: auto; bottom: calc(var(--nav-h) + var(--sab)); border-radius: 0; border-width: 0; }
  .shead { padding: 10px 10px 10px 8px; }
  .shead h2 { font-size: 18px; }
  .sbody { padding: 14px 14px 26px; }
  .bottomnav { position: absolute; z-index: 35; display: grid; grid-template-columns: repeat(5, 1fr); left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + var(--sab)); padding: 0 var(--sar) var(--sab) var(--sal); border-radius: 0; border-width: 1px 0 0; }
  .bottomnav button { border: 0; background: transparent; display: grid; place-items: center; align-content: center; gap: 3px; font-size: 11px; color: var(--muted); padding: 6px 2px; }
  .bottomnav button .ic { width: 22px; height: 22px; }
  .bottomnav button[aria-current="true"] { color: var(--accent); font-weight: 600; }
  .bottomnav button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
  .menu-sheet { top: calc(var(--top-h) + var(--sat) + 6px); right: calc(8px + var(--sar)); width: min(300px, calc(100vw - 16px)); }
  .toast { bottom: calc(var(--nav-h) + var(--sab) + 70px); }
  .maplibregl-ctrl-bottom-right { bottom: calc(var(--nav-h) + var(--sab)); }
  #app.card-open .maplibregl-ctrl-bottom-right { right: 0; }
  .maplibregl-ctrl-scale { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .cmpsel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .slider { grid-template-columns: minmax(0, 1fr) 110px 20px; }
  .tablewrap { max-height: none; }
  #tip { display: none !important; }
}
@media (max-height: 520px) and (max-width: 1000px) {
  :root { --nav-h: 52px; }
  .bottomnav button span { display: none; }
  .card.peek { height: 180px; }
  .explore, .card { height: calc(100% - var(--top-h) - var(--sat) - var(--nav-h) - var(--sab) - 12px); }
}
@media (min-width: 1001px) and (max-height: 640px), (min-width: 761px) and (min-height: 521px) and (max-height: 640px) {
  :root { --top-h: 54px; --g: 10px; }
  .ctl { height: 36px; }
}
@media (hover: none) { #tip { display: none !important; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
@media print { .topbar, .mapctl, .bottomnav, .legend { display: none; } }

/* ---------------- additions ---------------- */
.seg { display: flex; flex-wrap: wrap; gap: 4px; background: var(--soft); border-radius: 12px; padding: 3px; }
.seg button { flex: 1 1 auto; border: 0; background: transparent; border-radius: 9px; padding: 7px 10px; font-size: 13px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.seg button:hover { color: var(--ink); }
.seg button[aria-selected="true"], .seg button[aria-checked="true"] { background: var(--solid); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.hl { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-radius: 13px; background: var(--soft); border: 1px solid var(--line); border-left: 5px solid var(--kc); }
.hl > div { display: grid; min-width: 0; }
.hl span { font-size: 12.5px; color: var(--muted); }
.hl b { font: 700 24px/1.15 var(--font-display); letter-spacing: -.015em; }
.hl .pill { flex: none; }
.cbody { flex: 1; }
.card .sec .sech:first-child { margin-top: 0; }
.legend { cursor: default; }
.legend .tiny .btn { min-height: 26px; padding: 0 9px; font-size: 12px; }
.legend .tiny { gap: 8px; margin-top: 2px; }
.legend .tiny span { display: inline-flex; align-items: center; gap: 6px; }
.mopt .sw { background: linear-gradient(90deg, #2f6db3, #ebe5d8, #cf543f); }
.li .r .ic, .li .r .dot { margin: 0 auto; display: block; }
.kv dd .dot { vertical-align: 0; }
.cmpm .bar { height: 4px; }
.sheet table td b { font-weight: 600; }
details.acc > summary > span:not(.sic) { min-width: 0; }
details.acc > summary small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast { z-index: 70; }
@media (min-width: 761px) and (max-width: 1080px) and (min-height: 521px), (min-width: 1001px) and (max-width: 1080px) {
  #searchBtn { display: inline-flex; }
  .search { position: absolute; right: 10px; top: calc(100% + 8px); display: none; z-index: 41; width: 320px; }
  .search.open { display: flex; }
  .search input { width: 100%; background: var(--solid); border-color: var(--line-2); box-shadow: var(--shadow-lg); height: 42px; }
}
@media (min-width: 761px) and (max-width: 860px) and (min-height: 521px) {
  .mainnav button { padding: 8px 9px; }
  .brand .wm b { font-size: 17px; }
}
@media (max-width: 760px), (max-height: 520px) and (max-width: 1000px) {
  .seg button { padding: 8px 10px; font-size: 13.5px; }
  .hl b { font-size: 22px; }
  .card.peek .sec + .sec, .card.peek details { display: none; }
  .chead .top .btn.small span { display: none; }
}
@media (max-width: 380px) {
  .wm b { font-size: 16.5px; }
  .chead .top .btn.small { padding: 0 8px; }
  .kpi b { font-size: 16.5px; }
  .bottomnav button { font-size: 10.5px; }
}

#northIc { transition: transform .1s linear; }

#calcRes th, #calcRes td { padding: 8px 8px; font-size: 12.5px; }

@media (max-width: 760px), (max-height: 520px) and (max-width: 1000px) {
  .panel { z-index: 15; }
  #app.card-full .mapctl, #app.explore-open .mapctl { visibility: hidden; }
  #app.sheet-open .metric-pill, #app.explore-open .metric-pill { visibility: hidden; }
}
@media (max-width: 760px) and (max-height: 740px), (max-height: 520px) and (max-width: 1000px) { #cRotL, #cRotR { display: none; } }
.kpi b small.u, .hl b small.u { font: 500 12px/1 var(--font-body); color: var(--muted); letter-spacing: 0; white-space: nowrap; }

/* landscape phones: side panels instead of bottom sheets */
@media (max-height: 520px) and (max-width: 1000px) {
  .panel { top: calc(var(--top-h) + var(--sat)) !important; bottom: calc(var(--nav-h) + var(--sab)) !important; left: 0 !important; right: auto !important; width: min(400px, 56vw) !important; height: auto !important; max-height: none !important; border-radius: 0 18px 0 0; border-width: 0 1px 0 0; padding-left: var(--sal); }
  #app:not(.explore-open) .explore, #app:not(.card-open) .card { transform: translateX(calc(-100% - 24px)); }
  .card.peek { height: auto !important; }
  .card.peek .cbody { overflow-y: auto; }
  .card.peek .peek-more { display: none; }
  .card.peek .sec + .sec { display: block; }
  .card.peek details { display: block; }
  .grab { display: none !important; }
  .phead, .chead { padding-top: 12px; }
  #app.card-open .metric-pill, #app.explore-open .metric-pill { visibility: hidden; }
  .mapctl { grid-auto-flow: column; align-items: start; top: calc(var(--top-h) + var(--sat) + 8px); }
  .ctl { height: 36px; width: 40px; }
  #app.card-full .mapctl, #app.explore-open .mapctl { visibility: visible; }
  .legend { left: auto !important; right: calc(10px + var(--sar)); width: 290px; bottom: calc(var(--nav-h) + var(--sab) + 8px) !important; }
  #app.explore-open .legend, #app.card-open .legend { opacity: 1; pointer-events: auto; }
  .toast { bottom: calc(var(--nav-h) + var(--sab) + 16px); }
}
.topbar.tb-c1 .wm small { display: none; }
.topbar.tb-c1 .search input { width: 190px; }
.topbar.tb-c2 .mainnav button .lbl { display: none; }
.topbar.tb-c2 .mainnav button { padding: 8px 11px; }
.mainnav { flex: 0 1 auto; }
