:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #5b6577;
  --border: #e2e7ef;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);

  --good: #15803d;
  --good-bg: #dcfce7;
  --bad: #c8102e;
  --bad-bg: #fde2e4;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --neutral: #475569;
  --neutral-bg: #e2e8f0;

  --accent: #00205b;
  --radius: 18px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120;
    --surface: #131c2e;
    --text: #e8edf5;
    --muted: #9aa6b8;
    --border: #22304a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
    --good: #4ade80;
    --good-bg: rgba(74, 222, 128, .14);
    --bad: #fb7185;
    --bad-bg: rgba(251, 113, 133, .15);
    --warn: #fbbf24;
    --warn-bg: rgba(251, 191, 36, .14);
    --neutral: #a5b4c8;
    --neutral-bg: rgba(165, 180, 200, .14);
    --accent: #7ea6ff;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}

.wrap {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}
@media (min-width: 720px) { .wrap { padding: 0 32px; } }

/* Header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 24px 0;
  margin-bottom: 28px;
}
.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
}
.brand { display: flex; align-items: center; gap: 16px; }
.brand h1 { margin: 0; font-size: clamp(1.6rem, 4vw, 2.2rem); font-weight: 800; letter-spacing: -.02em; }
.subtitle { margin: 0; color: var(--muted); }
.updated { margin: 0; color: var(--muted); font-size: .9rem; }

/* Norsk flagg i CSS */
.flag {
  flex: none;
  width: 56px; height: 40px;
  border-radius: 6px;
  background:
    linear-gradient(to right, transparent 16px, #00205b 16px, #00205b 24px, transparent 24px),
    linear-gradient(to bottom, transparent 16px, #00205b 16px, #00205b 24px, transparent 24px),
    linear-gradient(to right, transparent 13px, #fff 13px, #fff 27px, transparent 27px),
    linear-gradient(to bottom, transparent 13px, #fff 13px, #fff 27px, transparent 27px),
    #ba0c2f;
  box-shadow: 0 0 0 1px rgba(0,0,0,.08);
}

/* Search */
.toolbar { display: flex; gap: 12px; margin-bottom: 20px; }
.search { position: relative; flex: 1 1 auto; min-width: 0; }

/* Årstall-dropdown */
.year-select { position: relative; flex: none; }
.year-select::after {
  content: "";
  position: absolute; right: 20px; top: 50%;
  width: 8px; height: 8px;
  border-right: 2.4px solid var(--muted);
  border-bottom: 2.4px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.year-select select {
  appearance: none;
  -webkit-appearance: none;
  height: 100%;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 14px 46px 14px 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.year-select select:hover { border-color: var(--accent); }
.year-select select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
@media (max-width: 480px) {
  .year-select select { padding-left: 14px; padding-right: 38px; }
  .year-select::after { right: 16px; }
}
.search-icon {
  position: absolute; left: 18px; top: 50%;
  width: 22px; height: 22px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.search input {
  width: 100%;
  font: inherit;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 14px 20px 14px 52px;
  box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Summary */
.summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
@media (min-width: 720px) {
  .summary { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }
}
.summary-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  /* knapp-reset */
  font: inherit;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.summary-item:hover { border-color: currentColor; transform: translateY(-1px); }
.summary-item:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.summary-item[aria-pressed="true"] {
  border-color: currentColor;
  box-shadow: 0 0 0 2px currentColor, var(--shadow);
}
.summary-item[data-status=""] { color: var(--accent); }
.summary-item[data-status=""] .summary-count { color: var(--text); }
@media (prefers-reduced-motion: reduce) { .summary-item:hover { transform: none; } }
.summary-item .icon { width: 48px; height: 48px; }
.summary-count { font-size: 1.9rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.summary-label { color: var(--muted); font-size: .9rem; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.chip {
  font: inherit;
  font-weight: 600;
  font-size: .9rem;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.chip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Grid of cards */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
  gap: 20px;
  margin-bottom: 48px;
}

.card {
  --tone: var(--neutral);
  --tone-bg: var(--neutral-bg);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 22px 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  container-type: inline-size;
  animation: rise .35s ease both;
}
.card::before {
  content: "";
  position: absolute; inset: 0 0 auto 0;
  height: 6px;
  background: var(--tone);
}
.card.good { --tone: var(--good); --tone-bg: var(--good-bg); }
.card.bad  { --tone: var(--bad);  --tone-bg: var(--bad-bg); }
.card.warning { --tone: var(--warn); --tone-bg: var(--warn-bg); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .card { animation: none; } }
.grid.no-anim .card { animation: none; }

.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.category {
  display: inline-block;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 4px;
}
.card h2 { margin: 0; font-size: 1.15rem; font-weight: 700; line-height: 1.3; }

.status-badge {
  flex: none;
  display: grid;
  place-items: center;
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--tone-bg);
  color: var(--tone);
}
.status-badge .icon { width: 40px; height: 40px; }

.value-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.value {
  /* Skalerer med kortets bredde slik at verdi + enhet alltid får plass på én linje */
  font-size: clamp(1.4rem, 11.5cqi, 2.9rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.03em;
  color: var(--tone);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.value .unit { font-size: .55em; font-weight: 600; letter-spacing: 0; color: var(--muted); margin-left: 10px; white-space: nowrap; }
.value-full { color: var(--muted); font-size: .85rem; margin-top: 6px; font-variant-numeric: tabular-nums; }

.trend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 8px;
  border-radius: 999px;
  background: var(--tone-bg);
  color: var(--tone);
  font-weight: 700;
  font-size: .9rem;
}
.trend .icon { width: 26px; height: 26px; }

.description { margin: 0; color: var(--muted); font-size: .95rem; }

.target {
  font-size: .9rem;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
}
.target strong { font-variant-numeric: tabular-nums; }

.card-footer {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: .85rem;
  color: var(--muted);
}
.card-footer a { color: var(--accent); font-weight: 600; text-decoration: none; }
.card-footer a:hover { text-decoration: underline; }
.card-actions { display: inline-flex; align-items: center; gap: 16px; }

.share {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.share .icon { width: 16px; height: 16px; }
.share:hover .share-label { text-decoration: underline; }
.share:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.share.copied { color: var(--good); }

/* Melding når et delt kort vises */
.shared-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 20px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}
.shared-notice[hidden] { display: none; }
.shared-notice strong { color: var(--text); }
.shared-clear {
  font: inherit;
  font-weight: 600;
  font-size: .9rem;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--surface);
  cursor: pointer;
}
.shared-clear:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.icon { display: block; }

.loading, .error {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
}
.error { color: var(--bad); background: var(--bad-bg); border-radius: var(--radius); }

.site-footer { color: var(--muted); font-size: .85rem; padding: 0 0 32px; }
.site-footer code { font-size: .85em; }
.site-footer .wrap { display: flex; flex-direction: column; gap: 6px; }
.site-footer p { margin: 0; }
.site-footer a { color: var(--accent); font-weight: 600; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* Forklaring av status */
.method {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
  font-size: .95rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.method h2 { margin: 0; font-size: 1.15rem; font-weight: 700; color: var(--text); }
.method strong { color: var(--text); }
.method-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 12px;
}
.method-list li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg);
}
.method-list .icon { flex: none; width: 32px; height: 32px; }
.method-list strong { display: block; margin-bottom: 2px; }
.method-list .good .icon { color: var(--good); }
.method-list .warning .icon { color: var(--warn); }
.method-list .bad .icon { color: var(--bad); }
.method-list .neutral .icon { color: var(--neutral); }
