:root {
  --bg: #fbfaf7;
  --fg: #1d1d1b;
  --muted: #5f5e58;
  --line: #e2dfd6;
  --card: #ffffff;
  --accent: #0b5d4b;
  --accent-fg: #ffffff;
  --warn: #9a3412;
  --high: #b91c1c;
  --mid: #c2410c;
  --low: #0f766e;
  --demo: #fde68a;
  --focus: #2563eb;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141412;
    --fg: #ecebe6;
    --muted: #a9a79f;
    --line: #34332e;
    --card: #1c1c19;
    --accent: #5fd0b3;
    --accent-fg: #0b1f1a;
    --warn: #fdba74;
    --high: #f87171;
    --mid: #fb923c;
    --low: #5eead4;
    --demo: #713f12;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141412;
  --fg: #ecebe6;
  --muted: #a9a79f;
  --line: #34332e;
  --card: #1c1c19;
  --accent: #5fd0b3;
  --accent-fg: #0b1f1a;
  --warn: #fdba74;
  --high: #f87171;
  --mid: #fb923c;
  --low: #5eead4;
  --demo: #713f12;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 1rem/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); }
a:focus-visible, summary:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.wrap { max-width: 1200px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 8px; background: var(--card); padding: 8px; z-index: 10; }

.demo-banner { background: var(--demo); padding-block: 8px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); text-align: center; font-size: 0.9rem; }
.site-header { border-bottom: 1px solid var(--line); background: var(--card); }
.header-inner { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; padding-top: 12px; padding-bottom: 12px; }
.logo { font-weight: 800; font-size: 1.25rem; text-decoration: none; color: var(--fg); letter-spacing: -0.01em; }
.logo span { color: var(--accent); }
.site-header nav { display: flex; gap: 16px; flex: 1; }
.site-header nav a { text-decoration: none; color: var(--fg); }
.site-header nav a:hover { color: var(--accent); }
.price-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; font-size: 0.875rem; }
.price-toggle a { padding: 6px 12px; text-decoration: none; color: var(--fg); }
.price-toggle a[aria-current="true"] { background: var(--accent); color: var(--accent-fg); }
.kpi-note { font-size: 0.85rem; color: var(--muted); padding-bottom: 8px; }

main { padding-top: 24px; padding-bottom: 48px; }
h1 { font-size: 2rem; line-height: 1.2; margin: 0 0 8px; letter-spacing: -0.02em; }
h2 { font-size: 1.35rem; margin: 32px 0 8px; }
h3 { font-size: 1.05rem; margin: 20px 0 6px; }
.lead { font-size: 1.1rem; color: var(--muted); margin-top: 0; max-width: 60ch; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.warn { color: var(--warn); }
.sub { display: block; font-size: 0.8rem; color: var(--muted); font-weight: 400; }
.empty { padding: 32px; background: var(--card); border: 1px dashed var(--line); border-radius: 8px; text-align: center; }

.hero { margin-bottom: 16px; }
.view-toggle { display: inline-flex; gap: 4px; margin: 8px 0 16px; border-bottom: 1px solid var(--line); }
.view-toggle a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; }
.view-toggle a[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }

.filters { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 16px; }
.filters label { display: flex; flex-direction: column; font-size: 0.8rem; color: var(--muted); gap: 2px; flex: 1 1 160px; }
.filters label.narrow { flex: 0 1 100px; }
.filters input, .filters select { font: inherit; font-size: 0.95rem; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); min-width: 0; }
.filters button { font: inherit; padding: 7px 16px; background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 6px; cursor: pointer; }
.filters .reset { padding: 7px 4px; font-size: 0.9rem; }

.table-caption { font-size: 0.85rem; color: var(--muted); margin: 0 0 6px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
table.list { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list thead th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); white-space: nowrap; background: var(--card); position: sticky; top: 0; }
table.list thead th a { color: inherit; text-decoration: none; }
table.list thead th[aria-sort] a { color: var(--fg); }
table.list tbody tr:last-child > * { border-bottom: 0; }
table.list tbody th { font-weight: 600; }
.num { text-align: right !important; white-space: nowrap; }
.missing { color: var(--muted); }

.status { font-size: 0.78rem; padding: 2px 8px; border-radius: 999px; background: var(--line); white-space: nowrap; }
.status-avbrutet { text-decoration: line-through; }
.idx { font-weight: 700; }
.idx-high { color: var(--high); }
.idx-mid { color: var(--mid); }
.idx-low { color: var(--low); }
.idx-warn { font-weight: 400; font-size: 0.75rem; color: var(--warn); }
.secondary-idx .idx { font-weight: 400; }
.warn-mark { color: var(--warn); }
.index-warning { border-left: 3px solid var(--warn); padding-left: 0.6rem; }
.pager { display: flex; gap: 16px; justify-content: center; margin: 16px 0; }

/* Källmarkeringar */
details.src { display: inline-block; position: relative; }
details.src > summary { list-style: none; cursor: pointer; color: var(--accent); font-size: 0.75rem; vertical-align: super; padding: 0 2px; }
details.src > summary::-webkit-details-marker { display: none; }
details.src.derived > summary { font-style: italic; vertical-align: baseline; font-size: 0.75rem; border-bottom: 1px dotted var(--accent); }
.src-pop { position: absolute; z-index: 5; left: 0; top: 1.6em; width: min(420px, 85vw); background: var(--card); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; box-shadow: 0 8px 24px rgb(0 0 0 / 0.15); text-align: left; white-space: normal; font-size: 0.85rem; font-weight: 400; }
td.num .src-pop { left: auto; right: 0; }
.src-pop p { margin: 0 0 6px; }
.src-title { font-weight: 600; }
.src-meta { color: var(--muted); }
.src-pop blockquote { margin: 6px 0; padding: 6px 10px; border-left: 3px solid var(--accent); background: var(--bg); font-style: italic; }
.src-pop ul { margin: 6px 0 0; padding-left: 18px; }
.src-pop .src-pop { position: static; box-shadow: none; width: auto; margin-top: 6px; }
.kind { font-size: 0.7rem; margin-left: 6px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); }
.kind-slutlig { border-color: var(--accent); color: var(--accent); }
.dev { font-weight: 700; white-space: nowrap; }
.dev-up { color: var(--high); }
.dev-down { color: var(--low); }
.dev-flat { color: var(--muted); }
.calc-tag { font-size: 0.7rem; font-style: italic; color: var(--muted); }
td.lead-col { font-weight: 600; }
table.list tfoot th, table.list tfoot td { border-top: 2px solid var(--line); font-weight: 600; }
tr.group-head th { background: var(--bg); font-weight: 600; text-align: left; }

/* Projekt */
.crumbs { font-size: 0.85rem; color: var(--muted); margin-bottom: 8px; }
.demo-tag { font-size: 0.8rem; vertical-align: middle; background: var(--demo); padding: 2px 8px; border-radius: 4px; margin-left: 8px; }
.facts { display: flex; flex-wrap: wrap; gap: 12px 32px; margin: 16px 0; }
.facts div { min-width: 120px; }
.facts dt { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.facts dd { margin: 2px 0 0; font-size: 1.15rem; font-weight: 600; }
table.kv { border-collapse: collapse; width: 100%; max-width: 720px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
table.kv th, table.kv td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.kv th { font-weight: 500; color: var(--muted); width: 45%; }
.derived-row th { font-style: italic; }
.alt-value td { font-size: 0.9rem; }
ol.timeline { list-style: none; padding: 0; border-left: 2px solid var(--line); margin-left: 6px; }
ol.timeline li { padding: 4px 0 12px 16px; position: relative; }
ol.timeline li::before { content: ""; position: absolute; left: -7px; top: 10px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); }
ol.timeline time { display: block; font-size: 0.8rem; color: var(--muted); }
ol.sources li { margin-bottom: 10px; }
ol.sources .src-links { margin: 2px 0 0; font-size: 0.9rem; }

.prose { max-width: none; } /* B58: lika bred som övriga sidor */
.prose code { background: var(--card); border: 1px solid var(--line); padding: 1px 6px; border-radius: 4px; font-size: 0.9em; }
.example { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; }

.site-footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 0.85rem; padding: 16px 0 32px; }

@media (max-width: 640px) {
  h1 { font-size: 1.5rem; }
  .site-header nav { order: 3; flex-basis: 100%; }
  table.kv { table-layout: fixed; }
  table.kv th { width: 42%; hyphens: auto; overflow-wrap: anywhere; }
  table.kv th, table.kv td { padding: 8px; }
  /* Källrutan som panel längst ner, så att den aldrig hamnar utanför skärmen */
  .src-pop, td.num .src-pop { position: fixed; left: 16px; right: 16px; top: auto; bottom: 16px; width: auto; max-height: 60vh; overflow-y: auto; z-index: 20; }
  .src-pop .src-pop { position: static; max-height: none; }
}

/* ---------------------------------------------------------------- admin (002) */
.logo .admin-tag { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; background: var(--fg); color: var(--bg); padding: 2px 6px; border-radius: 4px; vertical-align: middle; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.stat-row { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 12px; }
.stat-row li { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; min-width: 180px; }
.stat-row strong { font-size: 1.6rem; display: block; }
.stat-row a { text-decoration: none; color: var(--fg); }
body.admin .button, body.admin button { display: inline-block; font: inherit; padding: 7px 16px; background: var(--accent); color: var(--accent-fg); border: 1px solid var(--accent); border-radius: 6px; cursor: pointer; text-decoration: none; }
body.admin button.secondary { background: transparent; color: var(--accent); }
body.admin button.danger { background: transparent; color: var(--high); border-color: var(--high); font-size: 0.85rem; padding: 4px 10px; }
body.admin .small-button { font-size: 0.8rem; padding: 3px 8px; }
.notice { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); }
.notice.ok { border-color: var(--low); }
.notice.error { border-color: var(--high); }
.notice ul { margin: 6px 0 0; padding-left: 20px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 4px 16px 16px; margin-bottom: 16px; }
.panel h2 { margin-top: 12px; }
.admin-form { margin: 8px 0; }
.fields { display: flex; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 10px; }
.field { display: flex; flex-direction: column; gap: 2px; flex: 1 1 200px; min-width: 0; }
.field.small { flex: 0 1 140px; }
.field.wide { flex: 1 1 100%; }
.field.check { flex-direction: row; align-items: center; gap: 6px; flex-basis: 100%; }
.field label { font-size: 0.8rem; color: var(--muted); }
.field input, .field select, .field textarea { font: inherit; font-size: 0.95rem; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); min-width: 0; }
.field.check input { width: auto; }
.hint { font-size: 0.75rem; color: var(--muted); }
form.inline { display: inline; }
details.editor { border-top: 1px solid var(--line); padding: 8px 0; }
details.editor > summary { cursor: pointer; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.action { flex: 1 1 220px; }
.review-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.review-source { position: sticky; top: 8px; }
.viewer iframe { width: 100%; height: 80vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.viewer nav a[aria-current="true"] { font-weight: 700; }
.log { padding-left: 18px; font-size: 0.9rem; }
.log li { margin-bottom: 6px; }
.diff { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.diff pre { white-space: pre-wrap; word-break: break-word; font-size: 0.75rem; background: var(--bg); padding: 6px; border-radius: 6px; margin: 2px 0; }
.rs-publicerad { color: var(--low); }
.rs-avvisad { color: var(--high); }
@media (max-width: 900px) {
  .review-grid { grid-template-columns: 1fr; }
  .review-source { position: static; }
}
.admin-filters { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: flex-end; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 16px; }
.admin-filters .field { flex: 0 1 360px; }
.admin-filters .field.check { flex: 0 1 auto; padding-bottom: 8px; }

/* Ogranskad data (spec 006) – visas bara när SHOW_UNREVIEWED=1 */
.unreviewed-banner { background: var(--line); color: var(--fg); border-bottom: 2px solid var(--warn); }
.unreviewed-tag { color: var(--warn); font-weight: 600; }
.demo-tag.unreviewed-tag { background: var(--line); }
/* B19/B20: styckning */
.styckning-tag { color: var(--accent); font-weight: 400; }
.styckning-info { border-left: 3px solid var(--accent); padding-left: 0.6rem; }

/* B21: synlig anledning när ett index saknas (fungerar utan JS och i mobil) */
.idx-missing .why-label { white-space: normal; max-width: 12rem; margin-left: auto; }
details.why { font-size: 0.78rem; text-align: left; white-space: normal; }
details.why > summary { cursor: pointer; color: var(--accent); text-align: right; }
details.why[open] > p { margin: 4px 0 0; min-width: 14rem; max-width: 24rem; padding: 6px 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; color: var(--fg); }
/* B22: antaget prisår */
.assumed-tag { white-space: normal; max-width: 14rem; margin-left: auto; }
.assumed-note { font-size: 0.8rem; margin: 4px 0; }
/* B24: antal fastigheter */
.count .styckning-tag { white-space: normal; max-width: 12rem; margin-left: auto; }
.count .count-note { display: block; white-space: normal; max-width: 40rem; color: var(--warn); font-weight: 400; }
.counts-line .idx-missing, .counts-line .count { display: inline-block; vertical-align: top; }
