:root {
  --bg: #0b1426;
  --bg2: #101c34;
  --panel: #111d36;
  --panel2: #172646;
  --line: #243558;
  --text: #e8eefb;
  --muted: #9bacca;
  --accent: #2ec4b6;
  --export: #2ec4b6;
  --import: #f4a259;
  --neg: #ef6f5e;
  --nodata: #1a2740;
  --topbar-h: 56px;
  --footer-h: 28px;
  --panel-w: 440px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 700px at 50% 30%, #12213f 0%, var(--bg) 70%);
  color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.4;
  display: flex; flex-direction: column; overflow: hidden;
}
a { color: #7fd8ff; }
a:hover { color: #b5e9ff; }
:focus-visible { outline: 2px solid #7fd8ff; outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: #04121f; padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }

/* header */
.topbar {
  height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: rgba(11, 20, 38, .85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.logo { width: 26px; height: 26px; color: var(--accent); flex: none; }
.badge {
  font-size: 12px; padding: 3px 9px; border-radius: 999px; background: rgba(46, 196, 182, .14);
  color: #7ff0e3; border: 1px solid rgba(46, 196, 182, .45); white-space: nowrap;
}
.search { position: relative; margin-left: auto; width: 260px; }
.search input {
  width: 100%; height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--text); font: inherit; transition: border-color .15s, box-shadow .15s;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: #7fd8ff; box-shadow: 0 0 0 3px rgba(127, 216, 255, .2); }
#search-list {
  position: absolute; left: 0; right: 0; top: 42px; margin: 0; padding: 4px; list-style: none; max-height: 320px; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(0, 0, 0, .5); z-index: 40;
}
#search-list li { padding: 7px 10px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
#search-list li small { color: var(--muted); }
#search-list li[aria-selected="true"], #search-list li:hover { background: var(--panel2); }
.metrics { display: flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.metric {
  font: inherit; font-size: 13px; color: var(--muted); background: transparent; border: 0; padding: 6px 12px; border-radius: 7px;
  cursor: pointer; transition: background .15s, color .15s; white-space: nowrap;
}
.metric:hover { color: var(--text); }
.metric.active { background: var(--accent); color: #04121f; font-weight: 600; }

/* stage + map */
.stage { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#map:active { cursor: grabbing; }
.sphere { fill: #0d1a33; stroke: #20365f; }
.graticule { fill: none; stroke: #ffffff; stroke-opacity: .06; }
.country { stroke: #0b1426; stroke-linejoin: round; transition: fill .45s ease, opacity .2s; cursor: pointer; }
.country.nodata { fill: url(#hatch); cursor: default; }
.country:hover { stroke: #fff; stroke-opacity: .9; }
.country.selected { stroke: #fff; stroke-opacity: 1; }
.arc { fill: none; stroke-linecap: round; opacity: .85; pointer-events: none; }
.arc.export { stroke: var(--export); }
.arc.import { stroke: var(--import); }
.arc-dot { pointer-events: none; }
.arc-dot.export { fill: var(--export); }
.arc-dot.import { fill: var(--import); }
.origin-dot { fill: #fff; stroke: #0b1426; pointer-events: none; }

.tooltip {
  position: absolute; z-index: 15; pointer-events: none; background: rgba(8, 15, 30, .96); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 11px; font-size: 13px; box-shadow: 0 8px 24px rgba(0, 0, 0, .5); max-width: 260px;
}
.tooltip b { display: block; font-size: 14px; margin-bottom: 2px; }
.tooltip .row { display: flex; justify-content: space-between; gap: 14px; color: var(--muted); }
.tooltip .row span:last-child { color: var(--text); font-variant-numeric: tabular-nums; }
.tooltip .exp { color: var(--export) !important; } .tooltip .imp { color: var(--import) !important; }

.legend {
  position: absolute; left: 16px; bottom: 16px; width: 240px; padding: 10px 12px; z-index: 10;
  background: rgba(11, 20, 38, .85); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(6px); font-size: 12px;
}
.legend-title { color: var(--muted); margin-bottom: 6px; }
.legend-bar { height: 10px; border-radius: 5px; }
.legend-ticks span { white-space: nowrap; }
.legend-ticks { display: flex; justify-content: space-between; margin-top: 4px; color: var(--muted); font-variant-numeric: tabular-nums; }
.legend-nodata { margin-top: 8px; display: flex; align-items: center; gap: 6px; color: var(--muted); }
.swatch-nodata { width: 14px; height: 10px; border-radius: 3px; border: 1px solid var(--line);
  background: repeating-linear-gradient(45deg, #1a2740 0 3px, #2a3a5c 3px 4px); }

.zoom-ctl { position: absolute; left: 16px; top: 16px; display: flex; flex-direction: column; gap: 4px; z-index: 10; }
.zoom-ctl button {
  width: 34px; height: 34px; font-size: 18px; line-height: 1; color: var(--text); background: rgba(11, 20, 38, .85);
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer; transition: background .15s;
}
.zoom-ctl button:hover { background: var(--panel2); }

.overlay {
  position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(11, 20, 38, .88); transition: opacity .3s;
}
.overlay.hidden { opacity: 0; pointer-events: none; visibility: hidden; }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn { font: inherit; background: var(--accent); color: #04121f; border: 0; border-radius: 8px; padding: 8px 16px; font-weight: 600; cursor: pointer; }

.credits {
  height: var(--footer-h); flex: none; display: flex; align-items: center; justify-content: center; padding: 0 12px; font-size: 11.5px; color: var(--muted);
  border-top: 1px solid var(--line); background: rgba(11, 20, 38, .9); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; z-index: 20;
}

/* panel */
.panel {
  position: absolute; z-index: 25; top: 0; right: 0; bottom: 0; width: var(--panel-w); max-width: 100%;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: -12px 0 40px rgba(0, 0, 0, .45);
  transform: translateX(105%); transition: transform .35s cubic-bezier(.2, .8, .2, 1); overflow-y: auto; overscroll-behavior: contain;
}
.panel.open { transform: none; }
.panel-inner { padding: 18px 20px 28px; }
.p-head { display: flex; align-items: flex-start; gap: 10px; }
.p-head h2 { margin: 0; font-size: 24px; line-height: 1.15; }
.p-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.close {
  margin-left: auto; flex: none; width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg2);
  color: var(--text); font-size: 20px; line-height: 1; cursor: pointer;
}
.close:hover { background: var(--panel2); }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0 4px; }
.kpi { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; min-width: 0; }
.kpi .lbl { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.kpi .val { font-size: 21px; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; }
.kpi .meta { font-size: 11px; color: var(--muted); }
.kpi.exp .val { color: var(--export); } .kpi.imp .val { color: var(--import); }
.kpi.bal.pos .val { color: var(--export); } .kpi.bal.neg .val { color: var(--neg); }
.note { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.sec { margin-top: 22px; }
.sec h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); margin: 0 0 8px; display: flex; justify-content: space-between; gap: 8px; }
.sec h3 small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 13.5px; }
.bar-row .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .nm button { all: unset; cursor: pointer; color: #cfe9ff; text-decoration: underline dotted; text-underline-offset: 3px; }
.bar-row .nm button:hover { color: #fff; }
.bar-row .nm button:focus-visible { outline: 2px solid #7fd8ff; outline-offset: 2px; }
.bar-row .v { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.track { grid-column: 1 / -1; height: 6px; background: #0d1a33; border-radius: 3px; overflow: hidden; }
.fill { height: 100%; border-radius: 3px; width: 0; transition: width .6s cubic-bezier(.2, .8, .2, 1); }
.fill.export { background: var(--export); } .fill.import { background: var(--import); }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); }
.chip .n { color: var(--muted); font-size: 11px; margin-right: 4px; }
.chips.exp .chip { border-color: rgba(46, 196, 182, .4); } .chips.imp .chip { border-color: rgba(244, 162, 89, .4); }
.chips.res .chip { border-color: rgba(168, 139, 250, .4); }
.pg { display: grid; gap: 10px; }
.pg-row .name { font-size: 13.5px; margin-bottom: 3px; }
.pg-line { display: grid; grid-template-columns: 1fr 88px; align-items: center; gap: 8px; margin-bottom: 3px; }
.pg-line .v { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.legend-inline { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.dot.export { background: var(--export); } .dot.import { background: var(--import); }
.srcs { margin: 0; padding-left: 18px; font-size: 12.5px; word-break: break-all; }
.skeleton { height: 14px; border-radius: 6px; margin: 10px 0; background: linear-gradient(90deg, #172646, #20345c, #172646); background-size: 200% 100%; animation: sh 1.2s linear infinite; }
@keyframes sh { to { background-position: -200% 0; } }

@media (max-width: 1000px) {
  .brand h1 { font-size: 16px; }
  .metric { padding: 6px 8px; font-size: 12px; }
}
@media (max-width: 720px) {
  :root { --topbar-h: auto; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 10px; gap: 8px; }
  .badge { font-size: 11px; }
  .search { order: 3; width: 100%; margin-left: 0; }
  .metrics { margin-left: auto; }
  .legend { left: 8px; bottom: 8px; width: 190px; }
  .zoom-ctl { left: 8px; top: 8px; }
  .credits { white-space: normal; font-size: 10px; height: auto; padding: 4px 8px; text-align: center; }
  .panel {
    top: auto; left: 0; right: 0; width: 100%; height: 62%; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0; transform: translateY(105%);
  }
  .panel.open { transform: none; }
  .panel::before { content: ""; display: block; width: 44px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 0; position: sticky; top: 8px; }
  .kpi .val { font-size: 17px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
@media (max-width: 720px) { body.panel-open .legend { display: none; } }
@media (min-width: 721px) { body.panel-open .legend { left: 16px; } }

/* footer: single line; compact on small screens */
.footer, footer { display: block; text-align: center; line-height: var(--footer-h); }
@media (max-width: 720px) {
  footer { font-size: 10px; padding: 0 8px; }
  .legend { width: 190px; left: 10px; bottom: 10px; }
  footer { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
