:root {
  --bg: #0e1217;
  --surface: #151a21;
  --surface-2: #1c232c;
  --line: #2a333e;
  --ink: #e8edf3;
  --ink-2: #aab4c0;
  --ink-3: #7b8794;
  --sea: #0f1d2b;
  --land-other: #1a1f26;
  --land-ua: #262e38;
  --oblast: #3a4552;
  --river: #2f6491;
  --red: #e0564b;
  --red-strong: #ff7468;
  --red-fill: rgba(224, 86, 75, 0.42);
  --red-2014: rgba(120, 22, 22, 0.55);
  --blue: #4b8fe2;
  --amber: #f2a93b;
  --grey-hatch: #c7cdd5;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
a { color: #8dbbf2; }
a:hover { color: #b8d5f7; }
button { font: inherit; color: inherit; }

/* Capçalera */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-mark rect { fill: var(--surface-2); }
.brand-mark .m-fill { fill: var(--red); opacity: .8; }
.brand-mark .m-line { fill: none; stroke: var(--red-strong); stroke-width: 2; stroke-linejoin: round; }
h1 { font-size: 17px; margin: 0; letter-spacing: .2px; }
.sub { margin: 0; color: var(--ink-2); font-size: 12.5px; }
.disclaimer { margin: 0; color: var(--ink-3); font-size: 12px; max-width: 420px; text-align: right; }

/* Disposició */
.layout { flex: 1; display: flex; min-height: 0; }
.map-wrap { position: relative; flex: 1; min-width: 0; overflow: hidden; background: var(--sea); touch-action: none; }
#map { display: block; width: 100%; height: 100%; cursor: grab; user-select: none; }
#map.dragging { cursor: grabbing; }
.panel {
  width: 400px; flex: none; border-left: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; min-height: 0;
}

/* Capes del mapa */
#sea { fill: var(--sea); }
.l-neighbors { fill: var(--land-other); stroke: #313a45; stroke-width: .8; }
.l-ukraine { fill: var(--land-ua); }
.l-ukraine-border { fill: none; stroke: #8e9aa8; stroke-width: 1.4; }
.l-oblasts path { fill: transparent; stroke: var(--oblast); stroke-width: .7; }
.l-oblasts path:hover { fill: rgba(255, 255, 255, .035); }
.l-lakes { fill: var(--sea); stroke: var(--river); stroke-width: .5; }
.l-rivers { fill: none; stroke: var(--river); stroke-width: .8; }
.l-rivers-main { fill: none; stroke: var(--river); stroke-width: 1.8; }
.l-occupied { fill: var(--red-fill); }
.l-occ2014 { fill: var(--red-2014); }
.l-grey { fill: url(#hatch-grey); }
.l-liberated path { fill: url(#hatch-blue); stroke: var(--blue); stroke-width: 1; stroke-dasharray: 3 2; }
.l-front { fill: none; stroke: var(--red-strong); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.l-line2022 { fill: none; stroke: #ffd2cc; stroke-width: 1.4; stroke-dasharray: 6 4; }
#world path { vector-effect: non-scaling-stroke; }
.hatch-bg-grey { fill: rgba(140, 150, 162, .14); }
.hatch-grey { stroke: var(--grey-hatch); stroke-width: 1.4; opacity: .55; }
.hatch-bg-blue { fill: rgba(75, 143, 226, .18); }
.hatch-blue { stroke: var(--blue); stroke-width: 1.6; opacity: .8; }
.hatch-bg-claim { fill: rgba(224, 86, 75, .25); }
.hatch-claim { stroke: var(--red); stroke-width: 2.2; }
.hidden-layer { display: none; }

/* Etiquetes (coordenades de pantalla) */
.lbl { font: 600 12px var(--font); fill: var(--ink); paint-order: stroke; stroke: rgba(10, 13, 17, .92); stroke-width: 3.5px; stroke-linejoin: round; pointer-events: none; }
.lbl.t1 { font-size: 13.5px; font-weight: 700; }
.lbl.t3 { font-size: 11px; font-weight: 500; fill: #d5dbe2; }
.lbl.foreign { fill: var(--ink-3); font-weight: 500; }
.lbl.country { font-size: 12px; letter-spacing: 3px; fill: #66717e; font-weight: 600; stroke-width: 2.5px; }
.lbl.country.big { font-size: 20px; letter-spacing: 8px; fill: rgba(232, 237, 243, .16); stroke: none; }
.lbl.sea { font-style: italic; font-weight: 400; fill: #3d6487; letter-spacing: 1.5px; stroke: none; }
.mk { cursor: pointer; }
.mk .hit { fill: transparent; }
.mk-ua { fill: #e8edf3; stroke: #0e1217; stroke-width: 1.5; }
.mk-ru { fill: var(--red-strong); stroke: #0e1217; stroke-width: 1.5; }
.mk-ct { fill: var(--amber); stroke: #0e1217; stroke-width: 1.5; }
.mk-foreign { fill: #59636f; stroke: #0e1217; stroke-width: 1; }
.mk-ring { fill: none; stroke: var(--amber); stroke-width: 1.5; opacity: .9; }
.mk:hover circle, .mk:hover rect, .mk:hover path { filter: brightness(1.25); }
.mk.sel .mk-ring { stroke: #fff; stroke-width: 2; }

/* Controls flotants */
.map-ui { position: absolute; inset: 0; pointer-events: none; }
.map-ui > * { pointer-events: auto; }
.zoom { position: absolute; top: 12px; left: 12px; display: flex; flex-direction: column; gap: 6px; }
.zoom button {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line);
  background: rgba(21, 26, 33, .92); font-size: 18px; cursor: pointer; line-height: 1;
}
.zoom button:hover { background: var(--surface-2); }
.zoom button:focus-visible, .tabs button:focus-visible, .chip:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.layers {
  position: absolute; top: 12px; right: 12px; background: rgba(21, 26, 33, .94);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; font-size: 12.5px; min-width: 210px;
}
.layers summary { cursor: pointer; font-weight: 600; color: var(--ink-2); }
.layers label { display: flex; gap: 8px; align-items: center; padding: 3px 0; cursor: pointer; }
.layers input { accent-color: var(--blue); }
.legend {
  position: absolute; left: 12px; bottom: 12px; background: rgba(21, 26, 33, .94);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; font-size: 12px; color: var(--ink-2);
  display: grid; gap: 4px;
}
.legend > div { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.sw { width: 18px; height: 11px; border-radius: 2px; display: inline-block; flex: none; }
.sw-occ { background: var(--red-fill); border: 1.5px solid var(--red-strong); }
.sw-2014 { background: #5e1d1d; }
.sw-grey { background: repeating-linear-gradient(45deg, rgba(199, 205, 213, .65) 0 1.5px, rgba(140, 150, 162, .18) 1.5px 5px); }
.sw-lib { background: repeating-linear-gradient(-45deg, rgba(75, 143, 226, .9) 0 1.5px, rgba(75, 143, 226, .2) 1.5px 5px); border: 1px dashed var(--blue); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 1.5px solid #0e1217; }
.d-ua { background: #e8edf3; }
.d-ru { background: var(--red-strong); }
.d-ct { background: var(--amber); transform: rotate(45deg); border-radius: 1px; width: 9px; height: 9px; }
.scale { position: absolute; right: 12px; bottom: 30px; font-size: 11px; color: var(--ink-2); text-align: right; }
#scalebar { height: 6px; border: 1.5px solid var(--ink-2); border-top: 0; margin-left: auto; }
.coords { position: absolute; right: 12px; bottom: 10px; font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.tip {
  position: absolute; pointer-events: none; background: rgba(12, 15, 20, .96); border: 1px solid var(--line);
  border-radius: 7px; padding: 5px 9px; font-size: 12.5px; white-space: nowrap; z-index: 5;
}
.card {
  position: absolute; z-index: 6; width: 330px; max-width: calc(100% - 24px); max-height: calc(100% - 24px); overflow: auto;
  background: rgba(17, 21, 27, .98); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, .45);
}
.card h3 { margin: 0 26px 4px 0; font-size: 16px; }
.card .x { position: absolute; top: 8px; right: 8px; border: 0; background: none; font-size: 18px; color: var(--ink-3); cursor: pointer; width: 28px; height: 28px; }
.card .x:hover { color: var(--ink); }
.card p { margin: 6px 0; color: var(--ink-2); }

/* Estat */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; }
.status.ua::before { background: #e8edf3; }
.status.ru::before { background: var(--red-strong); }
.status.contested::before { background: var(--amber); border-radius: 1px; transform: rotate(45deg); }
.claims { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.claims li { border-left: 3px solid var(--line); padding: 2px 0 2px 10px; }
.claims li.ua { border-color: var(--blue); }
.claims li.ru { border-color: var(--red); }
.claims li.ind { border-color: #9aa5b1; }
.claims .who { display: block; font-size: 11.5px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .4px; }

/* Panell */
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; overflow-x: auto; scrollbar-width: none; }
.tabs button {
  flex: 1 0 auto; padding: 11px 10px; white-space: nowrap; background: none; border: 0; border-bottom: 2px solid transparent; cursor: pointer;
  color: var(--ink-2); font-weight: 600; font-size: 13px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--red-strong); }
.tab { padding: 14px 16px 24px; overflow-y: auto; flex: 1; }
.tab h2 { font-size: 14px; margin: 22px 0 8px; color: var(--ink); }
.tab h2:first-child { margin-top: 4px; }
.lead { color: var(--ink-2); margin: 0 0 12px; font-size: 13px; }

.stats { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; }
.stat.wide { grid-column: 1 / -1; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.3px; }
.stat .v small { font-size: 13px; color: var(--ink-2); font-weight: 600; margin-left: 4px; }
.stat .k { color: var(--ink-2); font-size: 12px; }
.stat .ref { color: var(--ink-3); font-size: 11.5px; margin-top: 4px; }

.sector { padding: 10px 0; border-bottom: 1px solid var(--line); }
.sector:last-child { border-bottom: 0; }
.sector h3 { margin: 0 0 3px; font-size: 13px; display: flex; justify-content: space-between; gap: 8px; }
.sector h3 button { background: none; border: 0; color: #8dbbf2; cursor: pointer; font-size: 12px; padding: 0; white-space: nowrap; }
.sector p { margin: 0; color: var(--ink-2); font-size: 13px; }
.cite { color: var(--ink-3); font-size: 11.5px; }

.hot { display: block; width: 100%; text-align: left; background: var(--surface-2); border: 1px solid transparent; border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; cursor: pointer; }
.hot:hover { border-color: var(--line); }
.hot .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hot strong { font-size: 14px; }
.hot .n { color: var(--ink-3); font-size: 12px; margin-top: 4px; }

.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { border: 1px solid var(--line); background: none; border-radius: 99px; padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); border-color: #4a5664; }
.events { list-style: none; margin: 0; padding: 0; }
.events li { position: relative; padding: 0 0 14px 18px; border-left: 1px solid var(--line); margin-left: 4px; }
.events li::before { content: ""; position: absolute; left: -5px; top: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--surface); border: 2px solid #6b7785; }
.events time { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.events p { margin: 2px 0 4px; font-size: 13px; }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; border: 1px solid; white-space: nowrap; }
.badge.ua { color: #9cc3f3; border-color: rgba(75, 143, 226, .55); }
.badge.ru { color: #f3a39b; border-color: rgba(224, 86, 75, .55); }
.badge.ind { color: #c9d1da; border-color: #56616d; }
.badge.agg { color: var(--ink-3); border-color: var(--line); }
.src-name { font-weight: 600; font-size: 12px; color: var(--ink-2); margin-right: 6px; }

.source { background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.source .row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.source a { font-weight: 600; }
.source p { margin: 4px 0 0; color: var(--ink-2); font-size: 12.5px; }
.source .lean { color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.method { padding-left: 18px; color: var(--ink-2); font-size: 13px; }
.method li { margin-bottom: 6px; }

/* Gràfics */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis { stroke: #56616d; stroke-width: 1; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--ink-3); font-size: 10.5px; }
.chart .cat { fill: var(--ink-2); font-size: 12px; }
.chart .val { fill: var(--ink); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .bar-ru { fill: var(--red); }
.chart .bar-ua { fill: var(--blue); }
.chart .bar-claim { fill: url(#hatch-claim); stroke: var(--red); stroke-width: 1; }
.chart .bar-n { fill: #8d99a6; }
.chart .hitbar { fill: transparent; cursor: default; }
.chart .hitbar:hover + .hl, .chart .hl { pointer-events: none; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--ink-2); margin: 6px 0 2px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.chart-legend .k-ru { background: var(--red); }
.chart-legend .k-ua { background: var(--blue); }
.chart-legend .k-claim { background: repeating-linear-gradient(45deg, var(--red) 0 2px, rgba(224, 86, 75, .25) 2px 5px); }
.table-view { margin-top: 8px; font-size: 12.5px; color: var(--ink-2); }
.table-view summary { cursor: pointer; }
.table-view table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.table-view th, .table-view td { text-align: left; padding: 5px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table-view td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Mòbil */
@media (max-width: 900px) {
  .disclaimer { display: none; }
  .layout { flex-direction: column; }
  .map-wrap { flex: none; height: min(64vh, 115vw); min-height: 340px; }
  .panel { width: auto; border-left: 0; border-top: 1px solid var(--line); }
  .tab { overflow: visible; }
  .layers { min-width: 0; }
  .layers:not([open]) { padding: 6px 10px; }
  .legend { font-size: 11px; padding: 6px 9px; max-width: calc(100% - 24px); }
  .scale, .coords { display: none; }
}
@media (max-width: 520px) {
  .top { padding: 8px 16px; }
  .legend > div:nth-child(2), .legend > div:nth-child(4) { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
@media (forced-colors: active) {
  .l-front { stroke: CanvasText; }
  .l-occupied { fill: Mark; }
}
