:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --fg: #12161c;
  --muted: #5d6673;
  --faint: #9aa3ae;
  --line: #e3e6ea;
  --grid: #eef0f3;
  --prof: #3f74b0;
  --prof-soft: #9dbbe0;
  --loss: #f08c2b;
  --loss-soft: #f8c48f;
  --accent: #3f74b0;
  --chip: #eef1f5;
  --chip-on: #12161c;
  --chip-on-fg: #ffffff;
  --tile-empty: #e9ecf0;
  --shadow: 0 1px 2px rgba(18, 22, 28, 0.06);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d1015;
  --card: #151a21;
  --fg: #eef1f5;
  --muted: #9aa4b2;
  --faint: #616b78;
  --line: #262d37;
  --grid: #1d232b;
  --prof: #6d9fd8;
  --prof-soft: #35567d;
  --loss: #f39a45;
  --loss-soft: #7a4a1d;
  --accent: #6d9fd8;
  --chip: #1d232b;
  --chip-on: #eef1f5;
  --chip-on-fg: #0d1015;
  --tile-empty: #1d232b;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body {
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
#app { max-width: 1440px; margin: 0 auto; padding: 20px 20px 28px; }

.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.kicker { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 2px 0 0; font-size: 26px; font-weight: 650; letter-spacing: -0.01em; }
h2 { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0.01em; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; min-height: 24px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border-radius: 999px;
  background: var(--chip); font-size: 12px; color: var(--fg); border: 0; cursor: pointer;
}
.pill b { font-weight: 600; }
.pill span { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; color: var(--muted); }
.pill:hover span { background: var(--line); color: var(--fg); }

.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.seg { display: inline-flex; background: var(--chip); border-radius: 999px; padding: 3px; }
.seg button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 12.5px; padding: 5px 11px;
  border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.seg button:hover { color: var(--fg); }
.seg button.on { background: var(--chip-on); color: var(--chip-on-fg); }
.reset {
  border: 1px solid var(--line); background: var(--card); color: var(--fg); font: inherit; font-size: 12.5px;
  padding: 6px 12px; border-radius: 999px; cursor: pointer;
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.kpis { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px 8px; box-shadow: var(--shadow); min-width: 0; }
.kpi .label { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .value { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .value.neg { color: var(--loss); }
.kpi svg { display: block; width: 100%; height: 30px; margin-top: 4px; overflow: visible; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.cardhead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.hint { margin: 6px 0 0; font-size: 11.5px; color: var(--faint); }

.mid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 12px; margin-top: 12px; }
#map { display: block; width: 100%; height: auto; }
#map .tile { cursor: pointer; transition: opacity 120ms; }
#map .tile rect { stroke: var(--card); stroke-width: 2; }
#map .tile.sel rect { stroke: var(--fg); stroke-width: 2.5; }
#map .tile.dim { opacity: 0.28; }
#map .tile text { font-size: 10.5px; font-weight: 600; pointer-events: none; text-anchor: middle; dominant-baseline: central; }
#map .country { font-size: 10px; fill: var(--faint); letter-spacing: 0.12em; text-transform: uppercase; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.legend .ramp { display: flex; height: 8px; width: 150px; border-radius: 2px; overflow: hidden; }
.legend .ramp i { flex: 1; }

#timeline { display: block; width: 100%; height: 230px; cursor: crosshair; touch-action: none; }
.range { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.keyrow { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.keyrow .sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-left: 8px; }
.keyrow .sw:first-child { margin-left: 0; }
.sw.prof { background: var(--prof); }
.sw.loss { background: var(--loss); }

.leaders { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--grid); }
.leaders h3 { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.lead {
  display: grid; grid-template-columns: 92px minmax(0, 1fr) 62px; align-items: center; gap: 8px; width: 100%;
  border: 0; background: transparent; color: var(--fg); font: inherit; font-size: 12.5px; padding: 4px 4px; border-radius: 6px;
  cursor: pointer; text-align: left;
}
.lead:hover { background: var(--chip); }
.lead.sel { box-shadow: inset 0 0 0 1.5px var(--fg); }
.lead .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead .bar { height: 10px; border-radius: 3px; }
.lead .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.lead.loss .bar { background: var(--loss); }
.lead.prof .bar { background: var(--prof); }

.multiples { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin-top: 12px; }
.row { display: grid; grid-template-columns: 112px minmax(0, 1fr); align-items: stretch; cursor: pointer; border-radius: 8px; }
.row + .row { border-top: 1px solid var(--grid); }
.row .name { padding: 10px 8px 0 4px; }
.row .name b { display: block; font-size: 13px; font-weight: 600; }
.row .name small { display: block; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 1px; }
.row svg { display: block; width: 100%; height: 96px; overflow: visible; }
.row.sel .name b { color: var(--accent); }
.row.dim { opacity: 0.35; }
.row:hover { background: color-mix(in srgb, var(--chip) 55%, transparent); }

svg text { fill: var(--muted); font-size: 10.5px; font-family: inherit; }
.axis line, .gridline { stroke: var(--grid); }
.cross { stroke: var(--fg); stroke-width: 1; opacity: 0.55; pointer-events: none; }
.brush { fill: var(--accent); opacity: 0.12; }
.brush-edge { stroke: var(--accent); stroke-width: 1.5; }
.outside { fill: var(--bg); opacity: 0.55; pointer-events: none; }

.tip {
  position: fixed; z-index: 10; pointer-events: none; background: var(--card); color: var(--fg); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 11px; font-size: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16); min-width: 170px;
}
.tip .t { font-weight: 600; margin-bottom: 4px; }
.tip .r { display: flex; justify-content: space-between; gap: 14px; font-variant-numeric: tabular-nums; }
.tip .r span:first-child { color: var(--muted); }

.foot { margin-top: 14px; font-size: 11.5px; color: var(--faint); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
.foot a { color: var(--muted); }
.loading { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); color: var(--muted); font-size: 14px; }
.loading[hidden] { display: none; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .mid, .multiples { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 620px) {
  #app { padding: 14px 16px 22px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row { grid-template-columns: 88px minmax(0, 1fr); }
  .leaders { grid-template-columns: minmax(0, 1fr); }
  .controls { width: 100%; }
}
