/* Statistikk-kalkulatoren (/statistikk-kalkulator/). Lastes etter v2.css.
   Regnekoden og HTML-en kommer fra den live sida via mockups/statistikk-kalkulator/lag_v2.py.
   Den live sida hadde all CSS i en <style> uten lag. Her er reglene for selve kalkulatoren skrevet om til v2
   og avgrenset med .stat-side. Toppmeny og bunn kommer fra v2.css.

   Fire forslag, valgt med forslag=1|2|3|4 (data-forslag på <html>):
   1 Oppgavearket   én rolig spalte i tre trinn: tallene, svarene, figuren
   2 Arbeidsbordet  dataene står fast til venstre på PC, svarene som store tall til høyre
   3 Figuren først  typevalg med eksempler, figuren øverst i svaret og tallene under som bildetekst
   4 Blandingen     Arbeidsbordet: sentralmål, spredningsmål, figur, tabell. Fliser stablet på PC, på linje på mobil. */

@layer seksjon {
  /* Diagramkoden leser --data, --text og --bg fra <html> når den tegner. Derfor står de her og ikke på body. */
  html[data-forslag] {
    --text: var(--ink);
    --subtext: var(--ink-2);
    --border: var(--line);
    --muted: var(--tint);
    --accent: var(--ink);
    --data: var(--pen);
    --data2: #c98a12;
    --radius: 18px;
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
    --stat-spalte: 680px;
  }
  html[data-forslag][data-theme="dark"] { --data2: #f2c14e;}

  .stat-side [hidden] { display: none !important;}
  .stat-side .calc-wrap { max-width: calc(var(--stat-spalte) + 48px); margin: 0 auto; padding: 0 24px 72px;}
  @media (max-width: 899px) { .stat-side .calc-wrap { padding: 0 16px 56px;} }
  @media (min-width: 900px) { .stat-side .calc-wrap { max-width: calc(var(--stat-spalte) + 80px); padding: 0 40px 80px;} }

  /* ---------- Topp ---------- */
  .stat-side .calc-hero { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 24px; padding: 40px 0 0;}
  .stat-side .calc-hero h1 { font-size: 44px; line-height: 1.04;}
  @media (min-width: 900px) {
    .stat-side .calc-hero { padding-top: 64px;}
    .stat-side .calc-hero h1 { font-size: 60px;}
  }
  .stat-side .calc-hero .btn-ghost { order: 2; padding: 0; border: 0; background: none; color: var(--link); font-size: 16px; text-decoration: underline; text-decoration-color: var(--pen); text-underline-offset: 0.22em;}
  .stat-side .calc-note { margin: 14px 0 32px; color: var(--ink-2); font-size: 16px; line-height: 1.5;}
  .stat-side .calc-note a { color: var(--link); text-decoration: underline; text-underline-offset: 0.18em;}

  /* ---------- Byggeklosser ---------- */
  .stat-side .stat-blokk { margin-bottom: 20px;}
  .stat-side .field-label { display: block; margin-bottom: 8px; color: var(--ink-2); font-size: 15px; font-weight: 600;}
  .stat-side .btn-ghost svg, .stat-side .stat-copy svg, .stat-side .stat-v-copy svg, .stat-side .steps-copy svg, .stat-side .ft-cellcopy svg { display: inline-block;}

  .stat-side .toggle-row { display: flex; flex-wrap: wrap; gap: 8px;}
  .stat-side .toggle-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 8px 16px;
    background: transparent; color: var(--ink-2);
    border: 1px solid var(--line); border-radius: 12px;
    font-size: 16px; line-height: 1.2; text-align: center;
    transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
  }
  .stat-side .toggle-btn:hover { color: var(--ink); border-color: var(--field-line);}
  .stat-side .toggle-btn.active { color: var(--heading); background: var(--boks); border-color: var(--boks-sterk); font-weight: 600;}
  .stat-side .mode-toggle-row { display: grid; grid-template-columns: 1fr 1fr;}
  @media (min-width: 640px) { .stat-side .mode-toggle-row { grid-template-columns: repeat(4, 1fr);} }
  .stat-side .type-eks, .stat-side .type-tekst { display: none;}

  .stat-side textarea, .stat-side input[type=text], .stat-side .ts-select {
    min-height: 52px; padding: 12px 15px;
    background: var(--field); color: var(--ink);
    border: 1px solid var(--field-line); border-radius: 14px;
    font: 400 18px/1.45 var(--mono);
  }
  .stat-side .ts-select { font-family: var(--sans); font-size: 17px;}
  .stat-side textarea { min-height: 104px; resize: vertical;}
  .stat-side textarea:focus, .stat-side input[type=text]:focus { border-color: var(--pen);}
  .stat-side textarea::placeholder, .stat-side input::placeholder { color: var(--ink-2); opacity: 0.6;}
  .stat-side .ts-row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 12px;}
  .stat-side .ts-field { flex: 1; min-width: 150px;}

  .stat-side .dtable { width: 100%; border-collapse: collapse; margin-bottom: 8px;}
  .stat-side .dtable th { padding: 0 8px 8px 2px; color: var(--ink-2); font-size: 15px; font-weight: 600; text-align: left;}
  .stat-side .dtable td { padding: 0 8px 8px 0;}
  .stat-side .dtable input[type=text] { min-height: 48px; padding: 10px 12px; font-size: 17px;}
  .stat-side .dtable th:last-child { width: 44px;}
  .stat-side .rowdel { width: 44px; height: 48px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink-2); font-size: 20px; line-height: 1;}
  .stat-side .rowdel:hover { color: var(--error); border-color: var(--error);}

  .stat-side .btn-ghost {
    display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 14px;
    background: transparent; color: var(--ink-2); border: 1px solid var(--line); border-radius: 12px;
    font-size: 15px; font-weight: 500; transition: color 0.2s ease, border-color 0.2s ease;
  }
  .stat-side .btn-ghost:hover { color: var(--ink); border-color: var(--field-line);}
  .stat-side .addrow { margin-top: 2px;}

  .stat-side .run-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 18px; margin-top: 4px;}
  .stat-side .btn-primary {
    display: inline-flex; align-items: center; justify-content: center; min-height: 52px; padding: 10px 28px;
    background: var(--cta); color: var(--cta-ink); border-radius: 15px;
    font-size: 18px; font-weight: 600; transition: transform 0.45s var(--ease);
  }
  .stat-side .btn-primary:hover { transform: translateY(-1px);}
  .stat-side .echo { flex: 1 1 260px; min-width: 0; min-height: 16px; color: var(--ink-2); font-size: 15px;}
  .stat-side .echo b { color: var(--ink);}
  .stat-side .echo-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; max-height: 124px; overflow-y: auto; padding: 2px;}
  .stat-side .echo-copy { min-height: 30px; padding: 2px 10px; font-size: 14px;}
  .stat-side .chips { display: inline-flex; flex-wrap: wrap; gap: 5px;}
  .stat-side .chip { display: inline-block; padding: 1px 9px; background: var(--tint); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; font: 14px/1.6 var(--mono);}
  .stat-side .err { min-height: 16px; margin-top: 10px; color: var(--error); font-size: 16px;}
  .stat-side .err:empty, .stat-side .echo:empty { min-height: 0; margin-top: 0;}

  /* Historikk */
  .stat-side .history-box { margin-bottom: 20px;}
  .stat-side .history-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px;}
  .stat-side .hist-list { display: grid; grid-template-columns: 1fr; gap: 6px; max-height: 176px; overflow-y: auto; align-content: start;}
  @media (min-width: 480px) { .stat-side .hist-list--wide, .stat-side .hist-list--narrow { grid-template-columns: 1fr 1fr;} }
  @media (min-width: 760px) { .stat-side .hist-list--wide { grid-template-columns: 1fr 1fr 1fr;} }
  .stat-side .hist-row { display: flex; align-items: center; gap: 6px; width: 100%; min-width: 0; min-height: 40px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 12px; text-align: left;}
  .stat-side .hist-row:hover { background: var(--tint);}
  .stat-side .hist-chips { flex: 1; display: flex; align-items: center; gap: 3px; min-width: 0; overflow: hidden; white-space: nowrap;}
  .stat-side .hist-chip { flex-shrink: 0; padding: 1px 5px; background: var(--field); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; font: 13px/1.5 var(--mono);}
  .stat-side .hist-chip b { font-weight: 600;}
  .stat-side .hist-ellipsis, .stat-side .hist-time { flex-shrink: 0; color: var(--ink-2); font-size: 13px;}
  .stat-side .hist-del { flex-shrink: 0; padding: 2px 4px; border-radius: 6px; color: var(--ink-2); font-size: 16px; line-height: 1;}
  .stat-side .hist-del:hover { background: var(--line); color: var(--ink);}

  /* Ikonknapper vises ved pekeren på PC og står alltid på berøringsskjerm (som før). */
  @media (hover: hover) {
    .stat-side .hist-del, .stat-side .stat-copy, .stat-side .stat-toggle, .stat-side .stat-del, .stat-side .stat-v-copy, .stat-side .echo-copy { opacity: 0;}
    .stat-side .hist-row:hover .hist-del, .stat-side .hist-del:focus,
    .stat-side .stat:hover .stat-copy, .stat-side .stat:hover .stat-toggle, .stat-side .stat-copy:focus, .stat-side .stat-toggle:focus,
    .stat-side .stat:hover .stat-del, .stat-side .stat-del:focus,
    .stat-side .stat:hover .stat-v-copy, .stat-side .stat-v-copy:focus,
    .stat-side .echo-row:hover .echo-copy, .stat-side .echo-copy:focus { opacity: 1;}
  }

  /* ---------- Svarene ---------- */
  .stat-side .results { margin-top: 28px;}
  .stat-side .results > div:first-child { margin-bottom: 8px !important;}
  .stat-side .group-title { margin: 32px 0 12px; color: var(--heading); font-size: 17px; font-weight: 600;}
  .stat-side .group-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 32px 0 12px;}
  .stat-side .group-row .group-title { margin: 0;}
  .stat-side .stat-group .group-row { margin: 0 0 8px;}
  .stat-side .stat-groups { display: grid; grid-template-columns: 1fr; gap: 28px;}

  .stat-side .stat-rows { border-top: 1px solid var(--line);}
  .stat-side .stat { position: relative; border-bottom: 1px solid var(--line);}
  .stat-side .stat-row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 10px 2px;}
  .stat-side .stat-k { flex: 0 0 auto; min-width: 128px; color: var(--ink-2); font-size: 16px;}
  .stat-side .stat-v { flex: 1; color: var(--ink); font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere;}
  .stat-side .stat-btns { display: flex; flex-shrink: 0; align-items: center; gap: 4px;}
  .stat-side .stat-copy, .stat-side .stat-toggle, .stat-side .stat-del {
    display: flex; align-items: center; justify-content: center; flex-shrink: 0; width: 36px; height: 36px;
    color: var(--ink-2); border: 1px solid var(--line); border-radius: 10px; font-size: 13px;
  }
  .stat-side .stat-copy:hover, .stat-side .stat-toggle:hover { color: var(--ink); border-color: var(--field-line);}
  /* Ikonknappene har .btn-ghost med 14 px luft på sidene; uten dette krympes ikonet til 2 px (max-width: 100% i v2.css). */
  .stat-side :is(.stat-copy, .stat-toggle, .stat-del, .steps-copy, .stat-v-copy, .echo-copy) { padding: 0;}
  .stat-side :is(.stat-copy, .steps-copy, .stat-v-copy, .echo-copy, .ft-cellcopy) svg { max-width: none; flex-shrink: 0;}
  .stat-side .stat-del:hover { color: var(--error); border-color: var(--error);}
  /* To svar i samme rad (σ og s): navnet får egen linje på smal skjerm */
  @media (max-width: 639px) {
    .stat-side .stat-row:has(.stat-v-copy) { flex-wrap: wrap;}
    .stat-side .stat-row:has(.stat-v-copy) .stat-k { flex-basis: 100%;}
  }
  .stat-side .stat-v-copy { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; margin-left: 2px; vertical-align: middle; color: var(--ink-2); border: 1px solid var(--line); border-radius: 7px;}
  .stat-side .stat .steps {
    position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 6;
    padding: 14px 16px; background: var(--surface); color: var(--ink);
    border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
    font: 14px/1.6 var(--mono); white-space: pre-wrap; word-break: break-word;
  }
  .stat-side .steps-copy { position: absolute; top: 8px; right: 8px; display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; background: var(--surface); color: var(--ink-2); border: 1px solid var(--line); border-radius: 9px;}
  .stat-side .steps-text { padding-right: 36px;}
  .stat-side #gridTallsys { display: grid; grid-template-columns: 1fr; gap: 0 16px; border-top: 1px solid var(--line);}
  @media (min-width: 640px) {
    .stat-side #gridTallsys { grid-template-columns: 1fr 1fr;}
    .stat-side #gridTallsys .stat--full { grid-column: 1 / -1;}
  }

  .stat-side .seg-toggle { display: inline-flex; overflow: hidden; vertical-align: middle; border: 1px solid var(--line); border-radius: 10px;}
  .stat-side .seg-opt { min-height: 36px; padding: 4px 10px; color: var(--ink-2); font-size: 14px;}
  .stat-side .seg-opt.active { background: var(--heading); color: var(--bg);}

  /* Frekvenstabellen */
  .stat-side .chart-box { overflow-x: auto; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);}
  /* Merknad under histogrammet når klassene er ulike brede */
  .stat-side .chart-note { margin: 10px 0 0; color: var(--ink-2); font-size: 15px; line-height: 1.5;}
  .stat-side .rtable { width: 100%; border-collapse: collapse; font-size: 16px; font-variant-numeric: tabular-nums;}
  .stat-side .rtable th, .stat-side .rtable td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--line);}
  .stat-side .rtable td { position: relative; white-space: nowrap;}
  .stat-side .rtable th { line-height: 1.25; white-space: normal;}
  .stat-side .rtable th:first-child, .stat-side .rtable td:first-child { text-align: left;}
  .stat-side .rtable thead th { color: var(--ink-2); font-size: 14px; font-weight: 600;}
  .stat-side .rtable tfoot td { font-weight: 600; border-top: 1px solid var(--ink-2); border-bottom: 0;}
  .stat-side .rtable tbody tr:last-child td { border-bottom: 0;}
  .stat-side .ft-cellcopy { display: none;}
  @media (hover: hover) {
    .stat-side .ft-cellcopy { position: absolute; top: 4px; right: 2px; display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; opacity: 0; background: var(--surface); color: var(--ink-2); border: 1px solid var(--line); border-radius: 6px;}
    .stat-side td:hover .ft-cellcopy, .stat-side .ft-cellcopy:focus { opacity: 1;}
  }

  /* Diagrammet. SVG-en har fast bredde fra regnekoden; den rulles inne i boksen hvis den er bredere. */
  .stat-side #chart svg { max-width: none; margin: 0 auto;}
  .stat-side #chart svg text { fill: var(--ink); font-family: var(--sans);}
  .stat-side #chartArea .btn-ghost { margin-top: 2px;}
  .stat-side #chartArea > div:last-child { margin-top: 12px !important;}
  .stat-side .trinn, .stat-side .tom-svar { display: none;}

  .stat-side .toast { position: fixed; left: 50%; bottom: 22px; z-index: 30; padding: 10px 18px; transform: translateX(-50%); opacity: 0; pointer-events: none; background: var(--cta); color: var(--cta-ink); border-radius: 12px; font-size: 16px; transition: opacity 0.2s ease;}
  .stat-side .toast.show { opacity: 1;}
  @media (max-width: 899px) { .stat-side .toast { bottom: 22px;} }

  /* ---------- Toppen på mobil: som verktøysidene (v2-verktoy, forslag A, Ruben 08.11) ----------
     R-ikon og navnet på verktøyet i stedet for logoen, ☰ Meny i toppen og ingen mobillinje nederst.
     lag_v2.py flytter Meny-knappen inn i toppen. Toppen følger scrollingen («Følger» i v2.css).
     Klassene er de samme som i verktoy.css og kan slås sammen med dem. */
  .stat-side .vt-left { display: flex; flex: none; align-items: center; gap: 8px; min-width: 0;}
  .stat-side :is(.vt-r, .vt-title) { display: none;}
  .stat-side .vt-title { color: var(--heading); font-weight: 600; white-space: nowrap;}
  @media (max-width: 899px) {
    .stat-side { padding-bottom: 0;} /* v2.css holder av plass til mobillinja */
    .stat-side .topbar .nav { min-height: 48px;}
    .stat-side .vt-title { display: block;}
    .stat-side .vt-left .logo-wordmark { display: none !important;}
    .stat-side .vt-r-lys { display: block; width: 32px; height: 32px;}
    [data-theme="dark"] .stat-side .vt-r-lys { display: none;}
    [data-theme="dark"] .stat-side .vt-r-mork { display: block; width: 32px; height: 32px;}
    .stat-side .topbar .meny-knapp { display: inline-flex; padding: 10px; margin-right: -6px; border: 0; border-radius: 14px; background: transparent; box-shadow: none; color: var(--ink);}
    .stat-side .topbar .meny-knapp > span:not(.meny-ikon) { display: none;}
    /* Menyen faller ned fra toppen (--vt-topp settes i statistikk.js) */
    .stat-side .burger-menu {
      top: calc(var(--vt-topp, 48px) + 6px); bottom: auto;
      max-height: calc(100dvh - var(--vt-topp, 48px) - 16px); overflow-y: auto;
      transform-origin: calc(100% - 24px) 0; transform: translateY(-14px) scale(0.98);}
    .stat-side .burger-menu.open { transform: none;}
  }
  /* Åpen meny: toppen (med ✕) ligger over dimmingen, og v2.css sin dimming av selve toppen
     (laget for Meny nederst) er av. Et trykk utenfor menyen treffer .nav-dim og lukker. */
  .stat-side .burger-menu { z-index: 60;}
  .stat-side .nav-dim { z-index: 55;}
  html.meny-apen body.stat-side .topbar,
  html.meny-apen[data-topp] body.stat-side .topbar { z-index: 56;}
  html.meny-apen[data-topp] body.stat-side .topbar::after { opacity: 0; pointer-events: none;}
  @media (max-width: 374px) { .stat-side .vt-title-hale { display: none;} }

  /* ---------- App-modus (åpnet fra app-ikonet, eller ?app) ----------
     Som verktøysidene (app-modus-oppskrift.md): ingen bunntekst og ingen strikk ved kanten.
     Klassen settes i <head> før siden tegnes. Kalkulatoren scroller som før; Meny ligger i toppen. */
  .vt-appmodus .stat-side footer.bunn { display: none;}
  .vt-appmodus .stat-side .calc-hero .btn-ghost { display: none;} /* appen virker uten nett, ingen grunn til å laste ned */
  .vt-appmodus .stat-side { padding-bottom: 0;}
  .vt-appmodus, .vt-appmodus .stat-side { overscroll-behavior: none;}

  /* ---------- «Legg på hjemskjermen» nederst i menyen (som verktoy.css) ---------- */
  .stat-side .vt-inst { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; margin-top: 4px; padding: 8px 16px;
    border-top: 1px solid var(--line); border-radius: 0 0 18px 18px; color: var(--ink); font-size: 17px; text-align: left;}
  .stat-side .vt-inst svg { width: 22px; height: 22px; flex: none; fill: none; stroke: var(--pen); stroke-width: 1.7; stroke-linecap: round;}
  .stat-side .vt-inst-guide { width: min(400px, calc(100vw - 32px)); padding: 22px 22px 18px; border: 1px solid var(--line); border-radius: 24px;
    background: var(--bg); color: var(--ink); box-shadow: var(--shadow-low), 0 24px 48px -16px rgba(30, 22, 14, 0.3);}
  .stat-side .vt-inst-guide::backdrop { background: rgba(30, 22, 14, 0.35);}
  .stat-side .vt-inst-guide h2 { margin: 0 0 8px; font-family: var(--serif); font-size: 26px; font-weight: 400; color: var(--heading);}
  .stat-side .vt-inst-guide p { margin: 0 0 14px; color: var(--ink-2); font-size: 15px; line-height: 1.5;}
  .stat-side .vt-inst-guide ol { margin: 0 0 18px; padding-left: 22px; display: grid; gap: 10px; font-size: 16px; line-height: 1.45;}
  .stat-side .vt-inst-guide form { display: flex; justify-content: flex-end;}
  .stat-side .vt-del { display: inline-block; width: 16px; height: 18px; vertical-align: -3px; background: no-repeat center / contain
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 18' fill='none' stroke='%23235580' stroke-width='1.5' stroke-linecap='round'%3E%3Cpath d='M5 6H3.5a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1V7a1 1 0 0 0-1-1H11M8 11V1.5M5 4.2 8 1.2l3 3'/%3E%3C/svg%3E");}

  @media (min-width: 900px) { .stat-side .topbar .meny-knapp { display: none;} }


  /* =====================================================================
     Forslag 1: Oppgavearket. Én spalte, tre trinn, svarene ført som på en prøve.
     ===================================================================== */
  [data-forslag="1"] .stat-side .trinn {
    display: flex; align-items: baseline; gap: 14px;
    margin: 0 0 18px; padding-top: 28px; border-top: 1px solid var(--line);
    font-size: 30px; line-height: 1.1;
  }
  [data-forslag="1"] .stat-side .trinn-nr { color: var(--pen); font-style: italic; font-size: 34px; min-width: 0.6em;}
  @media (min-width: 900px) {
    [data-forslag="1"] .stat-side .trinn { position: relative;}
    [data-forslag="1"] .stat-side .trinn-nr { position: absolute; right: calc(100% + 18px); font-size: 40px;}
  }
  [data-forslag="1"] .stat-side .trinn-svar { margin-top: 8px;}
  [data-forslag="1"] .stat-side .figur-tittel { display: none;}
  [data-forslag="1"] .stat-side .figur-blokk .trinn { margin-top: 40px;}

  /* Typevalget som faner med strek under */
  [data-forslag="1"] .stat-side .mode-toggle-row { display: flex; flex-wrap: wrap; gap: 0 22px; border-bottom: 1px solid var(--line);}
  [data-forslag="1"] .stat-side .mode-toggle-row .toggle-btn { min-height: 46px; padding: 8px 0; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none;}
  [data-forslag="1"] .stat-side .mode-toggle-row .toggle-btn.active { color: var(--heading); border-bottom-color: var(--pen); background: none;}
  [data-forslag="1"] .stat-side #chartToggle .toggle-btn { min-height: 40px; padding: 6px 14px; border-radius: 999px;}

  /* Svarene: navn til venstre, tallet til høyre, som en svarliste */
  [data-forslag="1"] .stat-side .stat-groups { gap: 24px;}
  [data-forslag="1"] .stat-side .stat-group .group-title { font-size: 16px; color: var(--ink-2); font-weight: 500;}
  [data-forslag="1"] .stat-side .stat-k { flex: 1 1 auto; color: var(--ink); font-size: 18px;}
  [data-forslag="1"] .stat-side .stat-v { flex: 0 1 auto; text-align: right; font-size: 21px;}
  [data-forslag="1"] .stat-side .stat-rows .stat:nth-child(even) { background: color-mix(in srgb, var(--tint) 55%, transparent);}
  [data-forslag="1"] .stat-side .chart-box { background: transparent;}
  /* «Kopier alt» står på linje med overskriften «Svarene» i stedet for over den */
  [data-forslag="1"] .stat-side .results { position: relative;}
  [data-forslag="1"] .stat-side .results:has(#mainResultSections:not([style*="none"])) > div:first-child { position: absolute; top: 30px; right: 0; margin: 0 !important;}
  [data-forslag="1"] .stat-side .results:has(#mainResultSections:not([style*="none"])) { margin-top: 36px;}


  /* =====================================================================
     Forslag 2: Arbeidsbordet. Dataene står fast til venstre, svarene som store tall.
     Forslag 4 bruker alt herfra og endrer bare rekkefølgen og diagrammet (se nederst).
     ===================================================================== */
  html:is([data-forslag="2"], [data-forslag="4"]) { --stat-spalte: 1056px;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .data-panel {
    padding: 22px 20px 20px; background: var(--surface);
    border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow-low);
  }
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .mode-toggle-row { gap: 4px; padding: 4px; background: var(--boks); border-radius: 14px; grid-template-columns: 1fr 1fr;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .mode-toggle-row .toggle-btn { min-height: 42px; padding: 6px 8px; border: 0; border-radius: 11px; font-size: 15px;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .mode-toggle-row .toggle-btn.active { background: var(--surface); color: var(--heading); box-shadow: 0 1px 3px rgba(40, 30, 20, 0.12);}
  :is([data-forslag="2"], [data-forslag="4"])[data-theme="dark"] .stat-side .mode-toggle-row .toggle-btn.active { background: var(--quiet); box-shadow: none;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .data-panel textarea, :is([data-forslag="2"], [data-forslag="4"]) .stat-side .data-panel input[type=text], :is([data-forslag="2"], [data-forslag="4"]) .stat-side .data-panel .ts-select { background: var(--bg);}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .run-row { flex-direction: column; align-items: stretch;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .btn-primary { width: 100%; min-height: 54px;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .echo { flex: 0 0 auto;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-blokk:last-of-type { margin-bottom: 16px;}

  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .tom-svar {
    min-height: 200px; align-content: center; padding: 40px 24px; color: var(--ink-2); text-align: center; font-size: 17px;
    border: 1.5px dashed var(--line); border-radius: 22px;
  }
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-bord:has(#results[style*="none"]) .tom-svar { display: block;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .svar-panel { margin-top: 28px;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .results { margin-top: 0;}

  /* Hovedtallene som fliser */
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-groups { gap: 22px;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows { position: relative; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; border: 0;}
  @media (min-width: 640px) { :is([data-forslag="2"], [data-forslag="4"]) .stat-side #gridCentral, :is([data-forslag="2"], [data-forslag="4"]) .stat-side #gridSpread { grid-template-columns: repeat(3, minmax(0, 1fr));} }
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows .stat { position: static; border: 0; background: var(--boks); border-radius: 16px;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows .stat-row { position: relative; flex-direction: column; align-items: flex-start; gap: 4px; min-height: 104px; padding: 14px 16px 16px;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows .stat-k { min-width: 0; font-size: 15px;}
  /* Knappene står oppe til høyre. På PC vises de over navnet ved pekeren; på berøringsskjerm står de alltid, så navnet flyttes ned. */
  @media (hover: none) { :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows .stat-k { margin-top: 30px;} }
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows .stat-v { flex: 0 0 auto; color: var(--heading); font: 400 34px/1.05 var(--serif); letter-spacing: -0.01em;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows .stat-v:has(.stat-v-copy) { font-size: 24px;}
  @media (min-width: 640px) {
    :is([data-forslag="2"], [data-forslag="4"]) .stat-side #gridSpread:has(.stat-v-copy) { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;}
    :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows .stat-v:has(.stat-v-copy) { white-space: nowrap;}
  }
  @media (max-width: 639px) { :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows .stat-v { font-size: 28px;} :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows .stat-v:has(.stat-v-copy) { font-size: 22px;} :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows .stat-k { padding-right: 0; margin-top: 30px;} :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows .stat:has(.stat-v-copy) { grid-column: 1 / -1;} }
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows .stat-btns { position: absolute; top: 8px; right: 8px;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows .stat-copy, :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows .stat-toggle { width: 32px; height: 32px; background: var(--boks); border-color: transparent;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-rows .stat .steps { top: calc(100% + 8px);}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side #gridTallsys .stat { border-radius: 16px;}

  @media (min-width: 1000px) {
    :is([data-forslag="2"], [data-forslag="4"]) .stat-side .stat-bord { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 40px; align-items: start;}
    :is([data-forslag="2"], [data-forslag="4"]) .stat-side .data-panel { position: sticky; top: 92px;}
    :is([data-forslag="2"], [data-forslag="4"]) .stat-side .svar-panel { margin-top: 0;}
    :is([data-forslag="2"], [data-forslag="4"]) .stat-side .calc-note { margin-bottom: 36px;}
  }


  /* =====================================================================
     Forslag 3: Figuren først. Typevalg med eksempler, figuren øverst i svaret.
     ===================================================================== */
  html[data-forslag="3"] { --stat-spalte: 860px;}
  [data-forslag="3"] .stat-side .mode-toggle-row { display: grid; grid-template-columns: 1fr; gap: 8px;}
  [data-forslag="3"] .stat-side .mode-toggle-row .toggle-btn:not(#modeTallsys) {
    display: grid; grid-template-columns: 1fr auto; grid-template-areas: "navn eks" "tekst eks"; align-items: center; justify-items: start;
    gap: 2px 16px; min-height: 64px; padding: 10px 16px; text-align: left;
    background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  }
  [data-forslag="3"] .stat-side .type-navn { grid-area: navn; color: var(--heading); font-size: 17px; font-weight: 600;}
  [data-forslag="3"] .stat-side .type-tekst { grid-area: tekst; display: block; color: var(--ink-2); font-size: 15px; font-weight: 400;}
  [data-forslag="3"] .stat-side .type-eks { grid-area: eks; display: inline-grid; grid-auto-flow: column; gap: 4px; font: 14px/1 var(--mono); color: var(--ink);}
  [data-forslag="3"] .stat-side .type-eks > span { padding: 5px 7px; background: var(--tint); border-radius: 6px;}
  [data-forslag="3"] .stat-side .type-eks--tab { grid-auto-flow: row; grid-template-columns: auto auto; gap: 0;}
  [data-forslag="3"] .stat-side .type-eks--tab > span { padding: 3px 8px; border-radius: 0; background: none; border-bottom: 1px solid var(--line);}
  [data-forslag="3"] .stat-side .type-eks--tab > span:nth-child(odd) { border-right: 1px solid var(--line);}
  [data-forslag="3"] .stat-side .type-eks--tab > span:nth-last-child(-n+2) { border-bottom: 0;}
  [data-forslag="3"] .stat-side .mode-toggle-row .toggle-btn.active:not(#modeTallsys) { background: var(--boks); border-color: var(--pen); box-shadow: inset 0 0 0 1px var(--pen);}
  [data-forslag="3"] .stat-side #modeTallsys { justify-self: start; min-height: 40px; padding: 4px 2px; border: 0; background: none; color: var(--link); font-size: 15px; text-decoration: underline; text-underline-offset: 0.2em; text-decoration-color: var(--pen);}
  [data-forslag="3"] .stat-side #modeTallsys.active { color: var(--heading); font-weight: 600;}
  @media (min-width: 640px) {
    [data-forslag="3"] .stat-side .mode-toggle-row { grid-template-columns: repeat(3, 1fr); gap: 10px;}
    [data-forslag="3"] .stat-side .mode-toggle-row .toggle-btn:not(#modeTallsys) { grid-template-columns: 1fr; grid-template-areas: "navn" "tekst" "eks"; align-content: start; gap: 4px; min-height: 0; padding: 14px 16px 16px;}
    [data-forslag="3"] .stat-side .type-eks { margin-top: 10px;}
    [data-forslag="3"] .stat-side #modeTallsys { grid-column: 1 / -1;}
  }

  /* Svaret: figuren øverst, tallene under som bildetekst, tabellen sist */
  [data-forslag="3"] .stat-side #mainResultSections { display: flex; flex-direction: column;}
  [data-forslag="3"] .stat-side .figur-blokk { order: 1;}
  [data-forslag="3"] .stat-side .stat-groups { order: 2;}
  [data-forslag="3"] .stat-side #freqTableGroup { order: 3;}
  [data-forslag="3"] .stat-side .figur-tittel { display: none;}
  [data-forslag="3"] .stat-side .figur-blokk { display: flex; flex-direction: column; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 22px 22px 0 0; border-bottom: 0;}
  [data-forslag="3"] .stat-side #chartArea { order: 1;}
  [data-forslag="3"] .stat-side #chartToggle { order: 2; margin: 14px 0 0 !important; gap: 6px;}
  [data-forslag="3"] .stat-side #chartToggle .toggle-btn { min-height: 40px; padding: 6px 14px; border-radius: 999px;}
  [data-forslag="3"] .stat-side #chartArea .chart-box { padding: 8px 0; border: 0; background: none;}
  [data-forslag="3"] .stat-side #chartArea > div:last-child { display: none;}
  [data-forslag="3"] .stat-side .figur-blokk:has(#chartArea[hidden]) #chartToggle { margin-top: 0 !important;}

  [data-forslag="3"] .stat-side .stat-groups { gap: 0; padding: 4px 18px 16px; background: var(--boks); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 22px 22px;}
  @media (min-width: 640px) { [data-forslag="3"] .stat-side .stat-groups { grid-template-columns: 1fr 1fr; gap: 0 28px;} }
  [data-forslag="3"] .stat-side .stat-group .group-row { margin: 12px 0 2px;}
  [data-forslag="3"] .stat-side .stat-group .group-title { color: var(--ink-2); font-size: 14px; font-weight: 600;}
  [data-forslag="3"] .stat-side .stat-rows { border: 0;}
  [data-forslag="3"] .stat-side .stat { border: 0;}
  [data-forslag="3"] .stat-side .stat-row { min-height: 40px; padding: 4px 0;}
  [data-forslag="3"] .stat-side .stat-k { min-width: 0; flex: 1 1 auto; color: var(--ink); font-size: 16px;}
  [data-forslag="3"] .stat-side .stat-v { flex: 0 1 auto; text-align: right; font-size: 18px;}
  [data-forslag="3"] .stat-side .stat-copy, [data-forslag="3"] .stat-side .stat-toggle { width: 32px; height: 32px; border-color: transparent;}
  [data-forslag="3"] .stat-side #freqTableGroup .group-row { margin-top: 36px;}

  /* Byggeklosser som bare forslag 4 viser */
  .stat-side .type-kort, .stat-side .stat-fot, .stat-side .chips-erstattet, .stat-side .fil-gruppe { display: none;}
  :is([data-forslag="2"], [data-forslag="4"]) .stat-side #gridTallsys { gap: 10px; border-top: 0;}


  /* =====================================================================
     Forslag 4: Blandingen. Arbeidsbordet med figuren rett etter tallene, før tabellen,
     på alle bredder (Ruben 8.11). Fliser stablet fra 640 px, på linje under.
     statistikk.js legger til ikoner, «Kopier bilde», sammenslåtte verdier, navn på
     tallsystemene og overskrift i utregningen (klassen v2-ekstra).
     Flisene: stablet (standard) eller navn og tall på linje (?fliser=linje, data-fliser).
     ===================================================================== */
  [data-forslag="4"] .stat-side #mainResultSections { display: flex; flex-direction: column; gap: 22px;}
  [data-forslag="4"] .stat-side .stat-groups { display: contents;}
  [data-forslag="4"] .stat-side .stat-group:first-child { order: 1;}
  [data-forslag="4"] .stat-side .stat-group:nth-child(2) { order: 2;}
  [data-forslag="4"] .stat-side .figur-blokk { order: 3;}
  [data-forslag="4"] .stat-side #freqTableGroup { order: 4;}
  [data-forslag="4"] .stat-side #freqTableGroup .group-row { margin-top: 10px;}

  /* Typevalget: fire på rad med korte navn på mobil, fulle navn ellers */
  @media (min-width: 640px) and (max-width: 999px) { [data-forslag="4"] .stat-side .mode-toggle-row { grid-template-columns: repeat(4, minmax(0, 1fr));} }
  @media (min-width: 380px) and (max-width: 639px) {
    [data-forslag="4"] .stat-side .mode-toggle-row { grid-template-columns: repeat(4, minmax(0, 1fr));}
    [data-forslag="4"] .stat-side .mode-toggle-row .toggle-btn { padding: 6px 2px; font-size: 14px;}
  }
  @media (max-width: 639px) {
    [data-forslag="4"] .stat-side .type-navn { display: none;}
    [data-forslag="4"] .stat-side .type-kort { display: inline;}
  }

  /* «Tolket som»: like verdier slått sammen, ikke noe eget rullefelt */
  [data-forslag="4"] .stat-side .echo-row { max-height: none; overflow: visible;}
  [data-forslag="4"] .stat-side .chip-n { color: var(--ink-2);}

  /* ---------- Flisene ---------- */
  /* .stat er usynlig i oppsettet, så utregningen (.steps) kan legge seg som en egen rad under flisene. */
  [data-forslag="4"] .stat-side .stat-rows { grid-auto-flow: row dense;}
  [data-forslag="4"] .stat-side .stat-rows .stat { display: contents;}
  [data-forslag="4"] .stat-side .stat-rows .stat-row { flex-wrap: nowrap; min-height: 112px; background: var(--boks); border-radius: 16px; cursor: pointer; transition: box-shadow 0.2s ease;}
  [data-forslag="4"] .stat-side .stat-rows .stat-row .stat-k { flex-basis: auto;}
  [data-forslag="4"] .stat-side .stat-rows .stat-row:hover { box-shadow: inset 0 0 0 1px var(--boks-sterk);}
  [data-forslag="4"] .stat-side .stat-rows .stat:has(> .steps:not([hidden])) > .stat-row { box-shadow: inset 0 0 0 2px var(--pen);}
  [data-forslag="4"] .stat-side .stat-rows .stat--full > .stat-row { grid-column: 1 / -1;}
  @media (min-width: 640px) { [data-forslag="4"] .stat-side #gridSpread:has(.stat-v-copy) { grid-template-columns: repeat(3, minmax(0, 1fr));} }

  [data-forslag="4"] .stat-side .stat-rows .stat-btns { display: contents;}
  [data-forslag="4"] .stat-side .stat-rows .stat-copy { position: absolute; top: 8px; right: 8px;}
  [data-forslag="4"] .stat-side .stat-rows .stat-del { position: absolute; top: 8px; right: 44px; width: 32px; height: 32px; background: var(--boks); border-color: transparent;}
  [data-forslag="4"] .stat-side .stat-rows .stat-toggle { position: absolute; right: 8px; bottom: 8px; opacity: 1; width: 30px; height: 30px; background: transparent; color: var(--ink-2); font-size: 16px;}
  [data-forslag="4"] .stat-side .stat-rows .stat:has(> .steps:not([hidden])) .stat-toggle { color: var(--pen);}

  /* σ og s over hverandre, så alle flisene kan være like brede */
  [data-forslag="4"] .stat-side .stat-rows .stat-v:has(.stat-v-copy) { display: flex; flex-direction: column; gap: 2px; font-size: 24px; white-space: nowrap;}
  [data-forslag="4"] .stat-side .dual-skille { display: none;}
  @media (max-width: 639px) { [data-forslag="4"] .stat-side .stat-rows .stat-v:has(.stat-v-copy) { font-size: 22px;} }

  /* Utregningen: et panel under raden med flisen du trykket på */
  [data-forslag="4"] .stat-side .stat-rows .stat .steps {
    position: relative; inset: auto; grid-column: 1 / -1; z-index: auto;
    padding: 16px 60px 18px 20px; background: var(--surface); color: var(--ink);
    border: 1px solid var(--line); border-radius: 16px; box-shadow: none;
    font: 16px/1.7 var(--sans); font-variant-numeric: tabular-nums;
  }
  [data-forslag="4"] .stat-side .steps-tittel { margin-bottom: 4px; color: var(--heading); font-weight: 600;}
  [data-forslag="4"] .stat-side .stat-rows .steps-text { padding-right: 0;}
  [data-forslag="4"] .stat-side .stat-rows .steps-copy { top: 12px; right: 12px; width: 36px; height: 36px;}

  /* Tallsystemer med navn på grunntallene */
  [data-forslag="4"] .stat-side .ts-original { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;}
  [data-forslag="4"] .stat-side .ts-navn { padding-right: 72px;}
  [data-forslag="4"] .stat-side .ts-navn b { color: var(--ink); font-weight: 600;}
  [data-forslag="4"] .stat-side .ts-gt { color: var(--ink-2); font-size: 13px; white-space: nowrap;}

  /* Navn og tall på linje: alltid på mobil (én flis per rad, leses som en liste),
     og på PC med ?fliser=linje (to i bredden). Tallsystemene beholder stablede fliser. */
  @media (max-width: 639px) {
    [data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread) .stat-row { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; padding: 12px 84px 12px 18px;}
    [data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread) .stat-k { flex: 1 1 auto; margin-top: 0; min-width: 0;}
    [data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread) .stat-v { flex: 0 0 auto; text-align: right; font-size: 28px;}
    [data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread) .stat-v:has(.stat-v-copy) { align-items: flex-end; font-size: 22px;}
    [data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread) .stat-copy { top: 50%; right: 44px; transform: translateY(-50%);}
    [data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread) .stat-toggle { top: 50%; bottom: auto; transform: translateY(-50%);}
    [data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread) { grid-template-columns: minmax(0, 1fr);}
  }
  @media (min-width: 640px) {
    [data-fliser="linje"][data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread) .stat-row { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; padding: 12px 84px 12px 18px;}
    [data-fliser="linje"][data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread) .stat-k { flex: 1 1 auto; margin-top: 0; min-width: 0;}
    [data-fliser="linje"][data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread) .stat-v { flex: 0 0 auto; text-align: right; font-size: 28px;}
    [data-fliser="linje"][data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread) .stat-v:has(.stat-v-copy) { align-items: flex-end; font-size: 22px;}
    [data-fliser="linje"][data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread) .stat-copy { top: 50%; right: 44px; transform: translateY(-50%);}
    [data-fliser="linje"][data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread) .stat-toggle { top: 50%; bottom: auto; transform: translateY(-50%);}
    [data-fliser="linje"][data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread, #gridSpread:has(.stat-v-copy)) { grid-template-columns: repeat(2, minmax(0, 1fr));}
  }

  /* Utregningen formatert av statistikk.js: navn for seg, regnestykket i tallskrift, svaret uthevet */
  [data-forslag="4"] .stat-side .stat-rows .steps-text { white-space: normal;}
  [data-forslag="4"] .stat-side .u-blokk + .u-blokk { margin-top: 14px;}
  [data-forslag="4"] .stat-side #gridSpread .steps-text:has(> .u-blokk:nth-child(2):last-child) { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 32px;}
  [data-forslag="4"] .stat-side #gridSpread .steps-text:has(> .u-blokk:nth-child(2):last-child) .u-blokk + .u-blokk { margin-top: 0;}
  [data-forslag="4"] .stat-side .u-linje { padding: 2px 0;}
  [data-forslag="4"] .stat-side .u-navn { margin-right: 2px; color: var(--ink-2); font-size: 15px;}
  [data-forslag="4"] .stat-side :is(.u-uttrykk, .u-svar) { font-family: var(--serif); font-size: 19px; line-height: 1.5;}
  [data-forslag="4"] .stat-side .u-svar { padding: 0 5px; color: var(--heading); font-weight: 600; background: color-mix(in srgb, var(--pen) 16%, transparent); border-radius: 6px; white-space: nowrap;}
  [data-forslag="4"] .stat-side .u-overskrift { color: var(--heading); font-weight: 600;}
  [data-forslag="4"] .stat-side .u-overskrift + .u-linje, [data-forslag="4"] .stat-side .u-blokk > .u-overskrift:not(:last-child) { margin-bottom: 2px;}
  [data-forslag="4"] .stat-side .u-merk { color: var(--ink-2); font-size: 14px; font-weight: 400;}
  [data-forslag="4"] .stat-side .u-deling { font: 15px/1.7 var(--mono); padding: 0;}

  /* σ og s: kopiknappene uten ramme, som i de andre flisene, og på samme sted når flisene står på linje */
  [data-forslag="4"] .stat-side .stat-rows .stat-v-copy { width: 30px; height: 30px; margin-left: 6px; border-color: transparent; vertical-align: -4px;}
  [data-forslag="4"] .stat-side .stat-rows .stat-v-copy:hover { background: var(--tint);}
  @media (max-width: 639px) { [data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread) .stat-row:has(.stat-v-copy) { padding-right: 44px;} }
  @media (min-width: 640px) { [data-fliser="linje"][data-forslag="4"] .stat-side :is(#gridCentral, #gridSpread) .stat-row:has(.stat-v-copy) { padding-right: 44px;} }

  /* «Tolket som»: kopiknappen har fast plass oppe til høyre; varsel om tusenskille */
  [data-forslag="4"] .stat-side .echo-row { position: relative; padding-right: 46px;}
  [data-forslag="4"] .stat-side .echo-row .echo-copy { position: absolute; top: 0; right: 0; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; min-height: 0; opacity: 1;}
  [data-forslag="4"] .stat-side .echo-copy svg { width: 16px; height: 16px;}
  [data-forslag="4"] .stat-side .tusen-varsel { margin: 10px 0 0; padding: 8px 12px; color: var(--ink); background: color-mix(in srgb, var(--error) 12%, transparent); border-radius: 10px; font-size: 15px; line-height: 1.45;}

  /* ---------- Figuren: verktøylinje over, boks med fast størrelse ---------- */
  [data-forslag="4"] .stat-side .figur-blokk { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 12px;}
  [data-forslag="4"] .stat-side .figur-tittel { grid-column: 1 / -1; margin: 0 0 8px;}
  [data-forslag="4"] .stat-side #chartToggle { grid-column: 1 / -1; grid-row: 2; margin: 0 !important; gap: 6px;}
  [data-forslag="4"] .stat-side #chartToggle .toggle-btn { min-height: 40px; padding: 6px 14px 6px 11px; border-radius: 999px;}
  [data-forslag="4"] .stat-side .diagram-ikon { display: inline-block; flex-shrink: 0;}
  [data-forslag="4"] .stat-side #chartArea { display: contents;}
  [data-forslag="4"] .stat-side #chartArea > .chart-box {
    --fig-h: 300px; grid-column: 1 / -1; grid-row: 3; box-sizing: content-box; height: var(--fig-h);
    display: flex; align-items: center; justify-content: center; margin-top: 12px; padding: 12px; overflow: auto;
  }
  [data-forslag="4"] .stat-side #chart { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%;}
  [data-forslag="4"] .stat-side #chart svg.passer { display: block; width: 100%; height: 100%;}
  [data-forslag="4"] .stat-side #chartArea > .chart-box.ruller { justify-content: flex-start; align-items: flex-start;}
  [data-forslag="4"] .stat-side .ruller #chart { display: block; width: auto; height: auto;}
  [data-forslag="4"] .stat-side #chartArea > div:last-child { grid-column: 1 / -1; grid-row: 3; justify-self: end; align-self: start; z-index: 1; display: flex; gap: 6px; margin: 22px 10px 0 0 !important;}
  [data-forslag="4"] .stat-side #chartArea > .chart-box { padding-top: 56px;}
  /* PNG og SVG: hver sin gruppe med «last ned» og «kopier» (bare ikoner, navnet står foran) */
  [data-forslag="4"] .stat-side .figur-gammel { display: none;}
  [data-forslag="4"] .stat-side .fil-gruppe { display: inline-flex; align-items: center; gap: 1px; height: 36px; padding: 0 3px 0 11px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; color: var(--ink-2); font-size: 13px; font-weight: 600; letter-spacing: 0.03em;}
  [data-forslag="4"] .stat-side .fil-navn { margin-right: 5px;}
  [data-forslag="4"] .stat-side .fil-knapp { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; color: var(--ink-2); border-radius: 8px; transition: background-color 0.2s ease, color 0.2s ease;}
  [data-forslag="4"] .stat-side .fil-knapp:hover { background: var(--tint); color: var(--ink);}
  [data-forslag="4"] .stat-side .fil-knapp::before { content: ""; width: 17px; height: 17px; background: currentColor; -webkit-mask: var(--ikon) no-repeat center / contain; mask: var(--ikon) no-repeat center / contain;}
  [data-forslag="4"] .stat-side .fil-last { --ikon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 4v11M7 10l5 5 5-5M5 20h14'/%3E%3C/svg%3E");}
  [data-forslag="4"] .stat-side .fil-kopier { --ikon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='11' height='11' rx='2'/%3E%3Cpath d='M5 15V6a2 2 0 0 1 2-2h9'/%3E%3C/svg%3E");}
  @media (max-width: 639px) {
    [data-forslag="4"] .stat-side #chartArea > .chart-box { --fig-h: 230px; padding: 10px;}
    [data-forslag="4"] .stat-side #chartArea > div:last-child { grid-row: 4; justify-self: start; margin: 10px 0 0 !important;}
    [data-forslag="4"] .stat-side #chartArea > .chart-box { padding-top: 10px;}
    [data-forslag="4"] .stat-side #chartToggle { gap: 4px;}
    [data-forslag="4"] .stat-side #chartToggle .toggle-btn { gap: 5px; min-height: 38px; padding: 5px 10px 5px 8px; font-size: 14px;}
    [data-forslag="4"] .stat-side #chartToggle .diagram-ikon { width: 16px; height: 16px;}
  }

  /* ---------- Frekvenstabellen: smal verdikolonne, formlene i mono ---------- */
  [data-forslag="4"] .stat-side .rtable th, [data-forslag="4"] .stat-side .rtable td { padding: 10px 10px;}
  [data-forslag="4"] .stat-side .rtable :is(th, td):first-child { width: 1%; white-space: nowrap;}
  [data-forslag="4"] .stat-side .rtable :is(th, td):nth-child(2) { width: 6.5em;}
  [data-forslag="4"] .stat-side .rtable tfoot td { white-space: normal;}
  [data-forslag="4"] .stat-side .rtable tfoot :is(.ft-formula, .ft-excel) { overflow-wrap: anywhere;}
  [data-forslag="4"] .stat-side .rtable tfoot td:nth-child(2) :is(.ft-formula, .ft-excel) { display: inline-block; min-width: 13ch;}
  [data-forslag="4"] .stat-side .rtable :is(.ft-formula, .ft-excel) { font: 14px/1.4 var(--mono);}
  /* PC: formlene får brytes der det trengs, så tabellen får plass uten sidelengs rulling */
  @media (min-width: 640px) {
    [data-forslag="4"] .stat-side .rtable td { white-space: normal;}
    [data-forslag="4"] .stat-side .rtable :is(.ft-formula, .ft-excel) { overflow-wrap: anywhere;}
  }
  /* Mobil: Svar, Utregning, Excel og kopier på én linje (kopier som ikon) */
  @media (max-width: 639px) {
    [data-forslag="4"] .stat-side #freqTableGroup .history-row { flex-wrap: nowrap; gap: 6px;}
    [data-forslag="4"] .stat-side #freqTableGroup .toggle-row { flex-wrap: nowrap; gap: 4px;}
    [data-forslag="4"] .stat-side #freqTableGroup .toggle-btn { min-height: 38px; padding: 5px 10px; font-size: 14px;}
    [data-forslag="4"] .stat-side #freqTableGroup .seg-opt { min-height: 36px; padding: 4px 8px;}
    [data-forslag="4"] .stat-side #copyFreqTable { flex-shrink: 0; justify-content: center; width: 40px; min-height: 40px; padding: 0; font-size: 0;}
    [data-forslag="4"] .stat-side #copyFreqTable svg { width: 17px; height: 17px; max-width: none;}
  }

  /* ---------- Under verktøyet ---------- */
  [data-forslag="4"] .stat-side > main .calc-note, [data-forslag="4"] .stat-side .calc-wrap > .calc-note { display: none;}
  [data-forslag="4"] .stat-side .calc-hero { margin-bottom: 32px;}
  [data-forslag="4"] .stat-side .stat-fot { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; margin-top: 64px; border-top: 1px solid var(--line); color: var(--ink-2); font-size: 15px; line-height: 1.55;}
  [data-forslag="4"] .stat-side .fot-kort { padding: 18px 0; border-bottom: 1px solid var(--line);}
  [data-forslag="4"] .stat-side .fot-tittel { margin: 0 0 4px; color: var(--heading); font: 600 16px/1.3 var(--sans);}
  [data-forslag="4"] .stat-side .stat-fot p { margin: 0;}
  @media (min-width: 900px) {
    [data-forslag="4"] .stat-side .stat-fot { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 32px; padding-top: 22px;}
    [data-forslag="4"] .stat-side .fot-kort { padding: 0; border-bottom: 0;}
  }
  [data-forslag="4"] .stat-side .stat-fot a, [data-forslag="4"] .stat-side .lenkeknapp { padding: 0; background: none; border: 0; color: var(--link); font: inherit; text-decoration: underline; text-decoration-color: var(--pen); text-underline-offset: 0.2em; cursor: pointer;}
}

/* v2.css gir .meny-knapp.open bakgrunn med !important. For !important vinner det tidligste laget,
   så denne ene regelen må ligge i laget gammel for å slå den. ✕ skal være flat som ☰ (som verktoy.css). */
@layer gammel {
  .stat-side .topbar .meny-knapp.open { background: transparent !important;}
}
