:root {
  --series-e: #2a78d6;
  --series-i: #eb6834;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #15181d;
  --muted: #5d6470;
  --line: #e3e6eb;
  --chip: #eef0f3;
  --chip-active: #15181d;
  --chip-active-text: #ffffff;
  --gap: 2px;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --card: #171a20;
    --text: #eef0f3;
    --muted: #9aa1ad;
    --line: #2a2f38;
    --chip: #222730;
    --chip-active: #eef0f3;
    --chip-active-text: #0f1115;
    --series-e: #3987e5;
    --series-i: #d95926;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --card: #171a20; --text: #eef0f3; --muted: #9aa1ad;
  --line: #2a2f38; --chip: #222730; --chip-active: #eef0f3; --chip-active-text: #0f1115;
  --series-e: #3987e5; --series-i: #d95926;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1200px; margin: 0 auto; padding: 28px 16px 40px; }

.head { display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; }
h1 { font-size: clamp(24px, 4vw, 34px); letter-spacing: -0.02em; margin: 0 0 4px; }
.sub { margin: 0; color: var(--muted); max-width: 60ch; }

.seg { display: inline-flex; background: var(--chip); border-radius: 999px; padding: 4px; }
.seg button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  padding: 8px 20px; border-radius: 999px; cursor: pointer; transition: background .2s, color .2s;
}
.seg button[aria-selected="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toggle {
  display: inline-flex; align-items: center; gap: 10px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font: inherit; font-weight: 500; padding: 9px 16px 9px 10px; border-radius: 999px; cursor: pointer;
}
.toggle .knob {
  width: 34px; height: 20px; border-radius: 999px; background: var(--chip); position: relative; transition: background .2s;
}
.toggle .knob::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--muted); transition: transform .2s, background .2s;
}
.toggle[aria-pressed="true"] .knob { background: #e0762b; }
.toggle[aria-pressed="true"] .knob::after { transform: translateX(14px); background: #fff; }
.chip.sep { margin-left: 8px; }
.year { display: inline-flex; align-items: center; background: var(--chip); border-radius: 999px; padding: 4px; }
.year button {
  border: 0; background: transparent; color: var(--text); font: inherit; font-size: 18px; line-height: 1;
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
}
.year button:hover:not(:disabled) { background: var(--card); }
.year button:disabled { opacity: .3; cursor: default; }
.year select {
  appearance: none; -webkit-appearance: none; border: 0; background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; font-variant-numeric: tabular-nums; padding: 7px 14px; border-radius: 999px;
  cursor: pointer; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.12);
}

.countries { display: flex; gap: 12px; align-items: center; margin: 22px 0 16px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: 1 1 500px; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; background: var(--chip); color: var(--text); font: inherit; font-size: 14px; font-weight: 500;
  padding: 7px 13px; border-radius: 999px; cursor: pointer; transition: background .15s, color .15s;
}
.chip:hover { filter: brightness(0.96); }
.chip[aria-pressed="true"] { background: var(--chip-active); color: var(--chip-active-text); }
.search input {
  font: inherit; font-size: 14px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); width: 220px; max-width: 100%;
}

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.stat .k { color: var(--muted); font-size: 13px; }
.stat .v { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.stat .v.pos { color: #1f8f4e; }
.stat .v.neg { color: #c4413a; }

.map-card { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; }
.map { position: relative; width: 100%; height: clamp(420px, 62vh, 680px); overflow: hidden; border-radius: 10px; }
.tile {
  position: absolute; overflow: hidden; border-radius: 4px; cursor: pointer;
  transition: left .6s cubic-bezier(.2,.7,.2,1), top .6s cubic-bezier(.2,.7,.2,1),
              width .6s cubic-bezier(.2,.7,.2,1), height .6s cubic-bezier(.2,.7,.2,1), opacity .4s;
  padding: 7px 8px; display: flex; flex-direction: column; gap: 1px;
}
.tile:hover { filter: brightness(1.08); }
.tile .n {
  font-size: 13px; font-weight: 600; line-height: 1.2;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
}
.tile .p { font-size: 12px; opacity: .85; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.mid .n { -webkit-line-clamp: 2; }
.map.no-anim .tile { transition: none; }
.tile.big .n { font-size: 17px; }
.tile.big .p { font-size: 14px; }
.tile.small .n, .tile.small .p { display: none; }
.tile.mid .p { display: none; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 10; background: var(--text); color: var(--bg);
  padding: 9px 12px; border-radius: 10px; font-size: 13px; max-width: 260px; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.tooltip b { display: block; font-size: 14px; margin-bottom: 2px; }
.tooltip .g { opacity: .7; font-size: 12px; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 14px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend em { font-style: normal; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.trend-card {
  position: relative; margin-top: 22px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 18px 12px;
}
.trend-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.trend-head h2 { font-size: 18px; margin: 0 0 2px; letter-spacing: -0.01em; }
.trend-head .sub { font-size: 13px; }
.trend-legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); padding-top: 4px; }
.trend-legend span { display: inline-flex; align-items: center; gap: 7px; }
.key { width: 16px; height: 2px; border-radius: 2px; display: inline-block; }
.key.e { background: var(--series-e); }
.key.i { background: var(--series-i); }
.trend { margin-top: 10px; outline: none; border-radius: 8px; }
.trend:focus-visible { box-shadow: 0 0 0 2px var(--series-e); }
.trend svg { display: block; width: 100%; height: auto; overflow: visible; cursor: pointer; }
.trend .grid line { stroke: var(--line); shape-rendering: crispEdges; }
.trend .axis text { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.trend .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.trend .line.e { stroke: var(--series-e); }
.trend .line.i { stroke: var(--series-i); }
.trend .area.e { fill: var(--series-e); opacity: .1; }
.trend .area.i { fill: var(--series-i); opacity: .1; }
.trend .sel line { stroke: var(--text); opacity: .35; }
.trend .sel text { fill: var(--text); font-size: 12px; font-weight: 600; }
.trend .hover line { stroke: var(--muted); }
.trend .dot { stroke: var(--card); stroke-width: 2; }
.trend .dot.e { fill: var(--series-e); }
.trend .dot.i { fill: var(--series-i); }
.trend .end-label { fill: var(--text); font-size: 12px; font-weight: 600; }
#trend-tip .row { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
#trend-tip .row b { display: inline; font-size: 13px; margin: 0; }
#trend-tip .key { flex: none; }
.trend-table summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 8px 0 4px; }
.table-wrap { max-height: 320px; overflow: auto; }
.trend-table table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.trend-table th, .trend-table td { text-align: right; padding: 5px 10px; border-bottom: 1px solid var(--line); }
.trend-table th:first-child, .trend-table td:first-child { text-align: left; }
.trend-table th { color: var(--muted); font-weight: 500; position: sticky; top: 0; background: var(--card); }
.trend-table tr.current td { font-weight: 700; }

/* Vindu for én varegruppe */
.cat {
  border: 0; padding: 0; background: transparent; color: var(--text);
  width: min(920px, calc(100vw - 32px)); max-width: none; max-height: calc(100vh - 48px);
}
.cat::backdrop { background: rgba(10, 12, 16, .55); backdrop-filter: blur(2px); }
.cat[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.cat-inner {
  position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 20px 22px 18px; max-height: calc(100vh - 48px); overflow: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.cat.max { width: 100vw; height: 100vh; max-height: 100vh; margin: 0; }
.cat.max .cat-inner { border-radius: 0; min-height: 100vh; max-height: 100vh; padding: 24px max(24px, calc((100vw - 1400px) / 2)); }
.cat.loading .cat-inner { opacity: .6; }
.cat-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.cat-head h2 { margin: 2px 0 4px; font-size: 22px; letter-spacing: -0.01em; }
.cat-head .sub { font-size: 13px; }
.eyebrow { margin: 0; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.cat-actions { display: flex; gap: 6px; flex: none; }
.icon {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--card);
  color: var(--text); cursor: pointer; display: grid; place-items: center;
}
.icon:hover { background: var(--chip); }
.icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon[aria-pressed="true"] { background: var(--chip-active); color: var(--chip-active-text); }
.cat-stats { margin: 16px 0 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.cat-stats .k { display: flex; align-items: center; gap: 7px; }
.cat-stats .v { font-size: 18px; font-variant-numeric: normal; }
.cat-stats .d { font-size: 13px; font-weight: 600; margin-top: 2px; }
.cat-stats .d.pos { color: #1f8f4e; }
.cat-stats .d.neg { color: #c4413a; }
.cat-legend { padding: 0; margin-bottom: -4px; }
.trend.brush { margin-top: 4px; }
.trend.brush .bg { fill: var(--bg); }
.trend .line.thin { stroke-width: 1.5; opacity: .8; }
.trend.brush .selection { fill: var(--series-e); fill-opacity: .14; stroke: var(--series-e); stroke-opacity: .6; rx: 4; }
.trend.brush .handle { fill: transparent; cursor: ew-resize; }
.trend.brush .grip { fill: var(--text); stroke: var(--card); stroke-width: 2; pointer-events: none; }
.trend.brush .overlay { cursor: crosshair; }
.cat-hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.cat-hint b { color: var(--text); font-variant-numeric: tabular-nums; }
.link { border: 0; background: none; color: var(--series-e); font: inherit; cursor: pointer; padding: 0 0 0 6px; text-decoration: underline; }
.cat-items { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }
.cat-items h3 { margin: 0 0 2px; font-size: 16px; }
.cat-items .sub { font-size: 13px; }
.cat-items ul { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 12px; }
.cat-items li { display: grid; grid-template-columns: minmax(0, 1fr) 150px; grid-template-areas: "name val" "bar bar"; gap: 4px 12px; }
.cat-items .name { grid-area: name; font-size: 14px; }
.cat-items .code { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; margin-right: 8px; }
.cat-items .val { grid-area: val; text-align: right; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cat-items .bar { grid-area: bar; height: 10px; }
.cat-items .bar i { display: block; height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.cat-items .bar i.e { background: var(--series-e); }
.cat-items .bar i.i { background: var(--series-i); }
@media (max-width: 600px) {
  .cat { width: 100vw; max-height: 100vh; margin: auto 0 0; }
  .cat-inner { border-radius: 18px 18px 0 0; padding: 16px; max-height: 92vh; }
  .cat-items li { grid-template-columns: 1fr; grid-template-areas: "name" "bar" "val"; }
  .cat-items .val { text-align: left; }
}

.foot { margin-top: 26px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); padding-top: 14px; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

@media (max-width: 600px) {
  .wrap { padding-top: 20px; }
  .controls, .seg { width: 100%; }
  .toggle { flex: 1; justify-content: center; }
  .seg button { flex: 1; }
  .search, .search input { width: 100%; }
  .tile .n { font-size: 12px; }
  .stat:last-child { grid-column: 1 / -1; }
  .stat .v { font-size: 19px; }
}
