:root {
  --bg: #f4f7f9;
  --surface: #ffffff;
  --surface-2: #eef3f6;
  --ink: #0f2733;
  --ink-2: #47606d;
  --ink-3: #7b909b;
  --line: #dbe4e9;
  --accent: #0b6a94;
  --accent-ink: #085475;
  --accent-soft: #e3f1f7;
  --bar: #1c7fa9;
  --bar-muted: #b9d3df;
  --vessel: #0b6a94;
  --station: #a2541b;
  --station-soft: #fbeee3;
  --shadow: 0 1px 2px rgba(15, 39, 51, .06), 0 4px 16px rgba(15, 39, 51, .05);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1a22;
    --surface: #13252f;
    --surface-2: #1a303c;
    --ink: #e8f0f4;
    --ink-2: #a9bcc6;
    --ink-3: #78909c;
    --line: #25404d;
    --accent: #5db9e0;
    --accent-ink: #8fd0ee;
    --accent-soft: #173646;
    --bar: #4aa9d2;
    --bar-muted: #2b4c5c;
    --vessel: #5db9e0;
    --station: #e9a56f;
    --station-soft: #3a2a1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
main { flex: 1; padding-top: 24px; padding-bottom: 48px; outline: none; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }

/* topplinje */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { display: flex; align-items: center; gap: 16px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--ink); flex-shrink: 0; }
.brand:hover { text-decoration: none; }
.brand svg { width: 28px; height: 28px; }
.brand svg rect { fill: var(--accent); }
.brand svg path { fill: var(--surface); }

/* søk */
.search { position: relative; }
.search-compact { flex: 1; max-width: 420px; margin-left: auto; }
.search input {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px 9px 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%237b909b' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='9' cy='9' r='6'/%3E%3Cpath d='m14 14 4 4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
  background-size: 17px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.search-hero input { font-size: 18px; padding: 15px 16px 15px 48px; background-position: 16px center; background-size: 20px; border-radius: 14px; box-shadow: var(--shadow); }
.results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(15, 39, 51, .18);
  max-height: min(70vh, 560px); overflow-y: auto; z-index: 30; padding: 6px; text-align: left;
}
.results h3 { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); padding: 8px 10px 4px; }
.result { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink); }
.result:hover, .result.active { background: var(--accent-soft); text-decoration: none; }
.result-main { min-width: 0; flex: 1; }
.result-name { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-sub { display: block; font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-side { font-size: 12px; color: var(--ink-2); text-align: right; white-space: nowrap; }
.results-empty { padding: 14px 10px; color: var(--ink-2); }

.kind { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; }
.kind svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.kind-vessel { background: var(--accent-soft); color: var(--vessel); }
.kind-station { background: var(--station-soft); color: var(--station); }

/* forside */
.hero { text-align: center; padding: 36px 0 28px; }
.hero h1 { font-size: clamp(26px, 5vw, 40px); letter-spacing: -.02em; }
.hero p { color: var(--ink-2); max-width: 620px; margin: 12px auto 24px; font-size: 16px; }
.hero .search { max-width: 640px; margin: 0 auto; }
.hint { font-size: 13px; color: var(--ink-3); margin-top: 10px; }

/* kort og rutenett */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card > h2 { font-size: 16px; margin-bottom: 4px; }
.card > .sub { color: var(--ink-2); font-size: 13px; margin: 0 0 14px; }
.grid { display: grid; gap: 16px; margin-top: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 820px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 720px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.tile-label { font-size: 12px; color: var(--ink-2); }
.tile-value { font-size: 24px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-value small { font-size: 14px; font-weight: 500; color: var(--ink-2); }
.tile-note { font-size: 12px; color: var(--ink-3); }

/* profilside */
.crumb { font-size: 13px; margin-bottom: 14px; }
.profile-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 18px; }
.profile-head .kind { width: 48px; height: 48px; border-radius: 12px; }
.profile-head .kind svg { width: 28px; height: 28px; }
.profile-head h1 { font-size: clamp(22px, 4vw, 30px); letter-spacing: -.01em; overflow-wrap: anywhere; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2); margin-bottom: 2px; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 8px 0 0; padding: 0; list-style: none; color: var(--ink-2); font-size: 14px; }
.facts b { color: var(--ink); font-weight: 600; }
.notice { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; font-size: 13px; color: var(--ink-2); margin-top: 10px; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 28px 0 0; }
.section-head h2 { font-size: 18px; }
select, .btn {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 12px; cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; }
select:focus-visible, .btn:focus-visible, a:focus-visible, .ybar:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* søylediagram per år */
.chart { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 8px; }
.chart-y { display: flex; flex-direction: column; justify-content: space-between; height: 180px; font-size: 11px; color: var(--ink-3); text-align: right; font-variant-numeric: tabular-nums; }
.chart-y span { transform: translateY(-50%); }
.chart-y span:last-child { transform: translateY(50%); }
.chart-plot { position: relative; height: 180px; display: flex; align-items: flex-end; gap: 2px;
  background: linear-gradient(var(--line), var(--line)) 0 0 / 100% 1px no-repeat,
              linear-gradient(var(--line), var(--line)) 0 50% / 100% 1px no-repeat;
  border-bottom: 1px solid var(--ink-3); }
.ybar { flex: 1; min-width: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; padding: 0; border: 0; background: none; cursor: pointer; }
.ybar i { display: block; width: 100%; max-width: 28px; min-height: 1px; background: var(--bar); border-radius: 4px 4px 0 0; }
.chart.has-selection .ybar i { background: var(--bar-muted); }
.chart.has-selection .ybar.selected i { background: var(--bar); }
.ybar:hover i { filter: brightness(1.15); }
.chart-x { grid-column: 2; display: flex; gap: 2px; font-size: 11px; color: var(--ink-3); margin-top: 4px; font-variant-numeric: tabular-nums; }
.chart-x span { flex: 1; min-width: 0; text-align: center; white-space: nowrap; overflow: visible; }

/* vannrette søyler (arter) */
.hbars { display: grid; gap: 9px; }
.hbar-top { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.hbar-top span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-top .num { color: var(--ink-2); white-space: nowrap; }
.hbar-track { height: 8px; background: var(--surface-2); border-radius: 4px; margin-top: 3px; }
.hbar-fill { height: 100%; min-width: 2px; background: var(--bar); border-radius: 4px; }

/* tabeller */
.table-wrap { overflow-x: auto; margin: 0 -18px -18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th:first-child, td:first-child { padding-left: 18px; }
th:last-child, td:last-child { padding-right: 18px; }
tr:last-child > td { border-bottom: 0; }
th.r, td.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
.sub-line { display: block; font-size: 12px; color: var(--ink-3); }
tr.landing { cursor: pointer; }
tr.landing:hover > td { background: var(--surface-2); }
tr.landing.open > td { background: var(--surface-2); border-bottom-color: transparent; }
.chev { display: inline-block; width: 8px; height: 8px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(-45deg); transition: transform .15s; }
tr.open .chev { transform: rotate(45deg); }
.expand-btn { background: none; border: 0; padding: 4px 6px; cursor: pointer; }
tr.detail > td { background: var(--surface-2); padding: 4px 18px 16px; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 13px; color: var(--ink-2); margin-bottom: 10px; }
.detail-meta b { color: var(--ink); font-weight: 600; }
.detail table { background: var(--surface); border-radius: 8px; overflow: hidden; font-size: 13px; }
.detail th:first-child, .detail td:first-child { padding-left: 12px; }
.detail th:last-child, .detail td:last-child { padding-right: 12px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0 0; font-size: 13px; color: var(--ink-2); }
.pager div { display: flex; gap: 8px; }
.empty { padding: 28px 0; text-align: center; color: var(--ink-2); }
@media (max-width: 640px) { .hide-sm { display: none; } }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--ink); color: var(--bg);
  padding: 6px 10px; border-radius: 8px; font-size: 12px; line-height: 1.4; white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}
.tooltip b { display: block; font-size: 13px; }

.footer { color: var(--ink-3); font-size: 12px; padding-top: 16px; padding-bottom: 28px; border-top: 1px solid var(--line); }
.footer p { margin: 6px 0; max-width: 820px; }
.loading { padding: 60px 0; text-align: center; color: var(--ink-3); }

/* meny */
.topnav { display: flex; gap: 4px; }
.topnav a { color: var(--ink-2); font-weight: 600; padding: 6px 12px; border-radius: 8px; }
.topnav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.topnav a[aria-current] { background: var(--accent-soft); color: var(--accent-ink); }
@media (max-width: 520px) { .brand span { display: none; } }

/* kart */
.card-map { padding: 0; overflow: hidden; }
.map-box { height: 420px; background: var(--surface-2); }
.map-box-full { height: max(440px, calc(100vh - 290px)); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.map-page-head { margin-bottom: 14px; }
.map-page-head h1 { font-size: clamp(22px, 4vw, 30px); }
.map-page-head p { margin: 6px 0 0; }
.card-map #map-legend, .card-map .map-note { padding: 0 16px; }
.map-note { font-size: 13px; color: var(--ink-2); margin: 8px 0 14px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 12px; }
.legend-item {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 13px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px;
}
button.legend-item { cursor: pointer; }
button.legend-item:hover { background: var(--surface-2); }
button.legend-item[aria-pressed="false"] { color: var(--ink-3); background: var(--surface-2); }
button.legend-item[aria-pressed="false"] .legend-swatch { opacity: .25; }
.legend-static { border-style: dashed; }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.legend-svg { width: 14px; height: 14px; }
.legend-count { color: var(--ink-3); font-variant-numeric: tabular-nums; }

.leaflet-container { font: inherit; background: var(--surface-2); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--ink); box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; line-height: 1.5; }
.leaflet-container a.leaflet-popup-close-button { color: var(--ink-3); }
.leaflet-control-layers, .leaflet-bar a { background: var(--surface); color: var(--ink); }
.leaflet-control-layers-expanded { padding: 8px 12px; font-size: 13px; }
.leaflet-control-attribution { font-size: 11px; }
.pop { min-width: 180px; }
.pop-kicker { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); }
.pop-title { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.pop-comment { margin-top: 6px; padding: 6px 8px; background: var(--surface-2); border-radius: 6px; }
.pop-foot { margin-top: 6px; font-size: 11px; color: var(--ink-3); }
.pop-link { margin-top: 6px; font-weight: 600; }
.ship-icon { background: none; border: 0; }
.ship-icon svg { display: block; overflow: visible; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .35)); }
