/* ============================================================================
   Kveo — delt designsystem
   ----------------------------------------------------------------------------
   Ei token-kjelde for ALLE flater: offentleg nettstad, admin, kundeportal
   og statussider. Surface-spesifikk CSS (style.css / admin.css) byggjer
   oppa denne fila og skal ALDRI definere eigne fargeverdiar.

   Alle farge-par er verifiserte mot WCAG:
     brodtekst      >= 7:1     (--ink,  --ink-2)
     sekundaertekst >= 4.5:1   (--muted, --faint)
     statusetikett  >= 4.5:1   (--ok/--warn/--danger/--info pa -soft)
     kontrollkant   >= 3:1     (--line-strong)
   Endrar du ein verdi: koyr valideringa pa nytt for du committar.
   ========================================================================= */

/* ---------------------------------------------------------------- 1. TOKENS */

:root {
  color-scheme: light;

  /* Flater — lys */
  --canvas:      #f5f4f0;
  --sunk:        #e9e8e1;
  --surface:     #ffffff;
  --surface-2:   #efeee9;
  --surface-3:   #e4e4db;

  /* Tekst — lys */
  --ink:         #1d1d1f;   /* Contrast verified by test/design-system.test.js. */
  --ink-2:       #353538;   /* Contrast verified by test/design-system.test.js. */
  --muted:       #5c5c63;   /* Contrast verified by test/design-system.test.js. */
  --faint:       #68686f;   /* Contrast verified by test/design-system.test.js. */

  /* Kantar — lys */
  --line:        #d7d7dc;   /* dekorativ skiljelinje */
  --line-strong: #86868d;   /* Contrast verified by test/design-system.test.js. */

  /* Merkevare — lys */
  --accent:       #252824;
  --accent-hover: #40463d;
  --accent-ink:   #30382e;
  --accent-soft:  #e9ede5;
  --accent-line:  #bdc8b6;
  --on-accent:    #ffffff;

  /* Status — lys. Bruk ALLTID saman med glyf + tekst, aldri farge aleine. */
  --ok:          #12664a;  --ok-soft:     #e2f0ea;  --ok-line:     #a6cebc;
  --warn:        #7d4f05;  --warn-soft:   #fbf0da;  --warn-line:   #e0c48a;
  --danger:      #992c2c;  --danger-soft: #fbe8e8;  --danger-line: #e6b8b8;
  --info:        #12508f;  --info-soft:   #e4eefa;  --info-line:   #a9c8e8;

  --shadow-sm: 0 1px 2px rgba(18, 22, 25, .06);
  --shadow-md: 0 16px 36px -22px rgba(18, 22, 25, .32);
  --shadow-lg: 0 30px 70px -34px rgba(18, 22, 25, .40);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark;
    --canvas:#101012; --sunk:#151517; --surface:#1c1c1e; --surface-2:#242427; --surface-3:#2d2d31;
    --ink:#f5f4f0; --ink-2:#d2d2d7; --muted:#adadb5; --faint:#a0a0a8;
    --line:#38383d; --line-strong:#767680;
    --accent:#e5ebdd; --accent-hover:#ffffff; --accent-ink:#d9e5cc;
    --accent-soft:#252c22; --accent-line:#58644e; --on-accent:#181d14;
    --ok:#6fdcae;  --ok-soft:#14261f;     --ok-line:#31604b;
    --warn:#e3b46a; --warn-soft:#2a2214;  --warn-line:#5c4a24;
    --danger:#f09292; --danger-soft:#2c1818; --danger-line:#5e3434;
    --info:#7fb2f5; --info-soft:#16202e;  --info-line:#33507a;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
    --shadow-md: 0 18px 42px -24px rgba(0,0,0,.80);
    --shadow-lg: 0 30px 70px -30px rgba(0,0,0,.90);
  }
}

:root[data-theme="dark"] { color-scheme: dark;
  --canvas:#101012; --sunk:#151517; --surface:#1c1c1e; --surface-2:#242427; --surface-3:#2d2d31;
  --ink:#f5f4f0; --ink-2:#d2d2d7; --muted:#adadb5; --faint:#a0a0a8;
  --line:#38383d; --line-strong:#767680;
  --accent:#e5ebdd; --accent-hover:#ffffff; --accent-ink:#d9e5cc;
  --accent-soft:#252c22; --accent-line:#58644e; --on-accent:#181d14;
  --ok:#6fdcae;  --ok-soft:#14261f;     --ok-line:#31604b;
  --warn:#e3b46a; --warn-soft:#2a2214;  --warn-line:#5c4a24;
  --danger:#f09292; --danger-soft:#2c1818; --danger-line:#5e3434;
  --info:#7fb2f5; --info-soft:#16202e;  --info-line:#33507a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
  --shadow-md: 0 18px 42px -24px rgba(0,0,0,.80);
  --shadow-lg: 0 30px 70px -30px rgba(0,0,0,.90);
}

:root {
  /* System typography; the legacy serif alias uses the same sans family. */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-serif: var(--font);
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Typeskala — ingenting under 0.75rem (12px). */
  --t-micro: .75rem;    /* 12px — mikroetikett, ALLTID >=600 vekt */
  --t-xs:    .8125rem;  /* 13px — metadata, hjelpetekst */
  --t-sm:    .875rem;   /* 14px */
  --t-base:  1rem;      /* 16px — brodtekst */
  --t-lg:    1.125rem;  /* 18px — ingress */
  --t-xl:    1.375rem;  /* 22px */
  --t-2xl:   1.75rem;   /* 28px */
  --t-3xl:   2.25rem;   /* 36px */

  --lh-tight: 1.12;
  --lh-snug:  1.35;
  --lh-body:  1.6;

  /* Rom — 4px-basert */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;

  /* Form */
  --r-xs: 8px; --r-sm: 12px; --r-md: 20px; --r-lg: 28px; --r-pill: 999px;

  /* Kontrollhogder. Grovt peikeutstyr far >=44px. */
  --control-h:    40px;
  --control-h-sm: 34px;
  --tap-min:      44px;

  --ease: cubic-bezier(.2, .7, .3, 1);
  --dur:  .16s;

  --nav-h: 64px;
  --container: 1180px;
}

/* Grovt peikeutstyr (finger): heva alle treffflater til 44px. */
@media (pointer: coarse) {
  :root { --control-h: 44px; --control-h-sm: 44px; }
}

/* ----------------------------------------------------------------- 2. RESET */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--nav-h) + var(--s-6));
  background: var(--canvas);
}

body {
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--t-base);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
img, svg, video { display: block; max-width: 100%; }
ul { list-style: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
table { border-collapse: collapse; width: 100%; }
::selection { background: var(--accent-soft); color: var(--accent-ink); }

/* ------------------------------------------------- 3. TILGJENGE (a11y-kjerne) */

/* Synleg fokus pa ALT som kan fokuserast. Aldri outline:none utan erstatning. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--r-xs);
}

/* Hopp-til-innhald. Kvar layout legg <a class="skip-link" href="#main"> fyrst. */
.skip-link {
  position: absolute;
  left: var(--s-4);
  top: calc(-1 * var(--tap-min) - var(--s-4));
  z-index: 999;
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-min);
  padding-inline: var(--s-4);
  border-radius: var(--r-pill);
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--t-sm);
  font-weight: 650;
  transition: top var(--dur) var(--ease);
}
.skip-link:focus-visible { top: var(--s-4); }

/* Berre for skjermlesar. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Mikroetikett. 12px er golvet, og alltid halvfeit for lesbarheit. */
.u-micro {
  font-family: var(--font-mono);
  font-size: var(--t-micro);
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  line-height: 1.4;
}

/* Redusert rorsle: sla av all ikkje-essensiell animasjon. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto !important; }
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* Auka kontrast: hard opp kantar og dempa tekst. */
@media (prefers-contrast: more) {
  :root { --line: var(--line-strong); --faint: var(--muted); }
}

/* -------------------------------------------------------- 4. LAYOUT-PRIMITIV */

.container {
  width: min(var(--container), calc(100% - 2 * var(--s-6)));
  margin-inline: auto;
}

.stack > * + * { margin-top: var(--s-4); }
.u-hide { display: none !important; }

/* Breitt innhald skal rulle i sin eigen boks, aldri sprengje sida. */
.scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

/* ------------------------------------------------------------ 5. KNAPPAR */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--control-h);
  padding-inline: var(--s-5);
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  font-size: var(--t-sm);
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              color var(--dur) var(--ease);
}

.btn-primary   { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink-2); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }

.btn-ghost     { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }

.btn-danger    { background: var(--danger); border-color: var(--danger); color: var(--surface); }

.btn-sm { min-height: var(--control-h-sm); padding-inline: var(--s-4); font-size: var(--t-xs); }

.btn:disabled, .btn[aria-disabled="true"] {
  background: var(--surface-3);
  border-color: var(--line);
  color: var(--faint);
  cursor: not-allowed;
}

/* ------------------------------------------------------------- 6. KORT */

.card {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  padding: var(--s-6);
}
.card-link { transition: border-color var(--dur) var(--ease); }
.card-link:hover { border-color: var(--line-strong); }

/* --------------------------------------------------------- 7. SKJEMAFELT */

.field { display: block; }

.field-label {
  display: block;
  margin-bottom: var(--s-2);
  color: var(--ink-2);
  font-size: var(--t-sm);
  font-weight: 600;
}

.field-hint { margin-top: var(--s-2); color: var(--muted); font-size: var(--t-xs); }
.field-error { margin-top: var(--s-2); color: var(--danger); font-size: var(--t-xs); font-weight: 600; }

.control {
  display: block;
  width: 100%;
  min-height: var(--control-h);
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--line-strong);   /* Contrast verified by test/design-system.test.js. */
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--t-base);               /* 16px hindrar zoom pa iOS */
  transition: border-color var(--dur) var(--ease);
}
.control::placeholder { color: var(--faint); }
.control:hover { border-color: var(--ink-2); }
.control[aria-invalid="true"] { border-color: var(--danger); }
textarea.control { min-height: 120px; resize: vertical; line-height: var(--lh-body); }

/* --------------------------------------------- 8. STATUS (farge + glyf + tekst) */

/* Status skal ALDRI berast av farge aleine — .status-dot gir form,
   og etiketten gir tekst. Sja HIG: "Convey information with more than
   color alone." */
.status {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-1) var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--t-micro);
  font-weight: 650;
  letter-spacing: .04em;
  white-space: nowrap;
}
.status-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: currentColor; }

.status-ok     { background: var(--ok-soft);     border-color: var(--ok-line);     color: var(--ok); }
.status-warn   { background: var(--warn-soft);   border-color: var(--warn-line);   color: var(--warn); }
.status-danger { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.status-info   { background: var(--info-soft);   border-color: var(--info-line);   color: var(--info); }

/* Ulik form per status, slik at dei skil seg utan farge. */
.status-warn   .status-dot { border-radius: 1px; transform: rotate(45deg); }
.status-danger .status-dot { border-radius: 1px; }
.status-info   .status-dot { background: none; border: 2px solid currentColor; }

/* --------------------------------------------------------------- 9. TABELL */

.table { font-size: var(--t-sm); }
.table th {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: var(--t-micro);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
}
.table td { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line); color: var(--ink-2); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }

/* -------------------------------------------------------------- 10. VARSEL */

.notice {
  display: flex;
  gap: var(--s-3);
  padding: var(--s-4);
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: var(--t-sm);
}
.notice-ok     { background: var(--ok-soft);     border-color: var(--ok-line);     border-left-color: var(--ok); }
.notice-warn   { background: var(--warn-soft);   border-color: var(--warn-line);   border-left-color: var(--warn); }
.notice-danger { background: var(--danger-soft); border-color: var(--danger-line); border-left-color: var(--danger); }
.notice-info   { background: var(--info-soft);   border-color: var(--info-line);   border-left-color: var(--info); }

/* -------------------------------------------------------- 11. TOM TILSTAND */

/* HIG: "Provide clear next steps on any blank screens." */
.empty {
  padding: var(--s-10) var(--s-6);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  text-align: center;
}
.empty h3 { color: var(--ink); font-size: var(--t-lg); font-weight: 650; }
.empty p  { margin-top: var(--s-2); color: var(--muted); font-size: var(--t-sm); }
.empty .btn { margin-top: var(--s-5); }

/* -------------------------------------------------------------- 12. AVATAR */

.avatar {
  display: inline-grid;
  place-items: center;
  width: 36px; height: 36px;
  flex: none;
  overflow: hidden;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: var(--t-xs);
  font-weight: 700;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 30px; height: 30px; font-size: var(--t-micro); }
.avatar-md { width: 44px; height: 44px; font-size: var(--t-sm); }
.avatar-xl { width: 72px; height: 72px; font-size: var(--t-xl); }
