/* ───────────────────────────────────────────────────────────────────────────
   KontohjelpLookup — scoped under .kh.

   Local --kh-* tokens read the live conta.no Webflow Variables (declared on
   :root by the host site; they cross the code-island Shadow DOM boundary) with
   the production hex values as fallbacks, so the standalone Vite preview looks
   identical to the real page.
   ─────────────────────────────────────────────────────────────────────────── */
.kh {
  --kh-green-50: var(--brand--green-50, #f0f2f1);
  --kh-green-100: var(--brand--green-100, #c6f5d6);
  --kh-green-200: var(--brand--green-200, #a6edc2);
  --kh-green-300: var(--brand--green-300, #60e791);
  --kh-green-400: var(--brand--green-400, #009a44);
  --kh-green-500: var(--brand--green-500, #006c30);
  --kh-green-600: var(--brand--green-600, #003e1b);
  --kh-green-700: var(--brand--green-700, #04221a);
  --kh-white: var(--neutral--white, #ffffff);
  --kh-n50: var(--neutral--neutral-50, #d9e0dc);
  --kh-n200: var(--neutral--neutral-200, #bfccc5);
  --kh-n300: var(--neutral--neutral-300, #8f9994);
  --kh-n400: var(--neutral--neutral-400, #565c59);

  --kh-text: var(--text-color--text-primary, #04221a);
  --kh-text-secondary: var(--text-color--text-secondary, #565c59);
  --kh-border: var(--border-color--border-primary, #bfccc5);
  --kh-link: var(--link-color--link-primary, #009a44);
  --kh-surface: var(--background-color--background-primary, #ffffff);
  --kh-surface-2: var(--background-color--background-secondary, #f0f2f1);

  --kh-font-body: Arial, "Helvetica Neue", Helvetica, sans-serif;
  --kh-font-display: "Poppins", Arial, sans-serif;

  --kh-radius: 14px;
  --kh-radius-sm: 9px;
  --kh-ring: 0 0 0 3px color-mix(in srgb, var(--kh-green-400) 30%, transparent);
  --kh-shadow: 0 1px 2px rgba(4, 34, 26, 0.04), 0 8px 28px -16px rgba(4, 34, 26, 0.22);
  --kh-h: clamp(460px, 68vh, 720px);

  display: block;
  font-family: var(--kh-font-body);
  color: var(--kh-text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.kh *,
.kh *::before,
.kh *::after {
  box-sizing: border-box;
}

.kh__heading {
  font-family: var(--kh-font-display);
  font-weight: 600;
  font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
  line-height: 1.15;
  margin: 0 0 0.35rem;
  color: var(--kh-green-700);
}
.kh__subheading {
  margin: 0 0 1.25rem;
  color: var(--kh-text-secondary);
  max-width: 60ch;
}

/* ── two-pane shell ────────────────────────────────────────────────────────── */
.kh__panes {
  display: grid;
  grid-template-columns: minmax(290px, 380px) 1fr;
  height: var(--kh-h);
  background: var(--kh-surface);
  border: 1px solid var(--kh-border);
  border-radius: var(--kh-radius);
  box-shadow: var(--kh-shadow);
  overflow: hidden;
}
.kh__list-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0; /* let the grid/flex item shrink so children can ellipsis (mobile fix) */
  border-right: 1px solid var(--kh-border);
  background: var(--kh-surface);
}

/* ── search bar ────────────────────────────────────────────────────────────── */
.kh__searchbar {
  position: relative;
  display: flex;
  align-items: center;
  margin: 0.85rem 0.85rem 0.55rem;
}
.kh__search-icon {
  position: absolute;
  left: 0.8rem;
  display: inline-flex;
  color: var(--kh-n300);
  pointer-events: none;
}
.kh__search-icon.is-loading {
  color: var(--kh-green-400);
}
.kh__search-input {
  width: 100%;
  font: inherit;
  font-size: 0.975rem;
  color: var(--kh-text);
  padding: 0.7rem 2.3rem 0.7rem 2.5rem;
  background: var(--kh-surface-2);
  border: 1px solid transparent;
  border-radius: var(--kh-radius-sm);
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.kh__search-input::placeholder {
  color: var(--kh-n400); /* full opacity — clears AA contrast */
}
.kh__search-input:focus {
  background: var(--kh-surface);
  border-color: var(--kh-green-400);
  box-shadow: var(--kh-ring);
}
.kh__clear {
  position: absolute;
  right: 0.55rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--kh-n400);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.kh__clear:hover {
  background: var(--kh-n50);
  color: var(--kh-green-700);
}

/* spinner (AI thinking) */
.kh__spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--kh-green-400) 30%, transparent);
  border-top-color: var(--kh-green-400);
  animation: kh-spin 0.7s linear infinite;
  display: inline-block;
}
.kh__spinner--lg {
  width: 22px;
  height: 22px;
  border-width: 2.5px;
}
@keyframes kh-spin {
  to {
    transform: rotate(360deg);
  }
}

.kh__count {
  margin: 0;
  padding: 0 0.95rem 0.5rem;
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--kh-n400);
  border-bottom: 1px solid var(--kh-border);
  min-height: 1.6rem;
}
.kh__ai-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--kh-green-600);
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.78rem;
}

/* ── results list (internal scroll) ───────────────────────────────────────── */
.kh__results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.kh__list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.kh__group-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.4rem 0.95rem;
  background: color-mix(in srgb, var(--kh-green-50) 92%, var(--kh-white));
  border-bottom: 1px solid var(--kh-border);
}
.kh__group-num {
  font-family: var(--kh-font-display);
  font-weight: 600;
  font-size: 0.72rem;
  color: var(--kh-green-500);
  letter-spacing: 0.03em;
  min-width: 1.6em;
}
.kh__group-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--kh-n400);
}
.kh__group-items {
  list-style: none;
  margin: 0;
  padding: 0;
}
.kh__option {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.55rem 0.95rem;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s ease;
}
.kh__option:hover,
.kh__option.is-active {
  background: var(--kh-green-50);
}
.kh__option.is-selected {
  background: color-mix(in srgb, var(--kh-green-100) 55%, var(--kh-white));
  border-left-color: var(--kh-green-400);
}
.kh__option-num {
  flex: none;
  font-family: var(--kh-font-display);
  font-weight: 600;
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
  color: var(--kh-green-600);
  min-width: 2.6em;
}
.kh__option-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.kh__option-name {
  font-size: 0.9rem;
  color: var(--kh-text);
  line-height: 1.25;
}
.kh__option-desc {
  font-size: 0.78rem;
  color: var(--kh-n400);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.05rem;
}
.kh__noresults,
.kh__ai-loading {
  padding: 1.75rem 1rem;
  color: var(--kh-n400);
  text-align: center;
}
.kh__ai-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
}

/* ── AI results: a distinct hero best-match + the other suggestions ────────── */
.kh__list--ai {
  padding: 0.7rem 0.85rem 0.9rem;
}
.kh__hero {
  display: block;
  cursor: pointer;
  padding: 0.85rem 0.95rem 0.8rem;
  background: var(--kh-green-50);
  border: 1.5px solid var(--kh-green-400);
  border-radius: var(--kh-radius-sm);
  transition: background 0.12s ease, box-shadow 0.12s ease;
}
.kh__hero:hover,
.kh__hero.is-active {
  background: color-mix(in srgb, var(--kh-green-100) 55%, var(--kh-white));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--kh-green-400) 20%, transparent);
}
.kh__hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}
.kh__hero-label {
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--kh-green-600);
}
.kh__hero-main {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.kh__hero-num {
  flex: none;
  font-family: var(--kh-font-display);
  font-weight: 700;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: var(--kh-green-500);
  padding: 0.12rem 0.5rem;
  border-radius: 7px;
}
.kh__hero-name {
  font-family: var(--kh-font-display);
  font-weight: 600;
  font-size: 1.02rem;
  line-height: 1.2;
  color: var(--kh-green-700);
}
.kh__hero-desc {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0.45rem 0 0.55rem;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--kh-text-secondary);
}
.kh__hero-cta {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--kh-green-500);
}
.kh__others {
  display: block;
  margin-top: 0.9rem;
}
.kh__others-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: var(--kh-n400);
  padding: 0 0.1rem 0.35rem;
}
.kh__list--ai .kh__option {
  padding: 0.5rem 0.35rem;
  border-left: none;
  border-radius: 8px;
}

/* ── detail pane ───────────────────────────────────────────────────────────── */
.kh__detail-pane {
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.75rem 2rem 2rem;
}
.kh__back {
  display: none; /* desktop: list always visible */
  align-items: center;
  gap: 0.3rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--kh-green-500);
  background: none;
  border: none;
  padding: 0 0 0.75rem;
  cursor: pointer;
}
.kh__detail-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.4rem;
}
.kh__detail-num {
  font-family: var(--kh-font-display);
  font-weight: 700;
  font-size: 1.25rem;
  color: #fff;
  background: var(--kh-green-400);
  padding: 0.15rem 0.6rem;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.kh__detail-class {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: var(--kh-green-500);
}
.kh__detail-title {
  font-family: var(--kh-font-display);
  font-weight: 600;
  font-size: clamp(1.5rem, 1.2rem + 1.1vw, 1.9rem);
  line-height: 1.15;
  margin: 0 0 1.1rem;
  color: var(--kh-green-700);
  text-wrap: balance;
  outline: none;
}
.kh__detail-title:focus,
.kh__detail-title:focus-visible {
  outline: none; /* programmatic focus target for screen readers — no visible box */
}
.kh__detail-best {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--kh-green-600);
}

/* rich body */
.kh__prose {
  font-size: 1.02rem;
  line-height: 1.62;
  color: var(--kh-text);
  max-width: 68ch; /* keep readable line length on wide detail panes */
  text-wrap: pretty;
}
.kh__prose > :first-child { margin-top: 0; }
.kh__prose p { margin: 0 0 1rem; }
.kh__prose a {
  color: var(--kh-link);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  font-weight: 500;
}
.kh__prose a:hover { color: var(--kh-green-600); }
.kh__prose ul,
.kh__prose ol { margin: 0 0 1rem; padding-left: 1.3rem; }
.kh__prose li { margin-bottom: 0.35rem; }
.kh__prose h2,
.kh__prose h3,
.kh__prose h4 {
  font-family: var(--kh-font-display);
  color: var(--kh-green-700);
  line-height: 1.25;
  margin: 1.5rem 0 0.6rem;
}
.kh__prose h2 { font-size: 1.3rem; }
.kh__prose h3 { font-size: 1.12rem; }
.kh__prose table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 1rem;
  font-size: 0.92rem;
}
.kh__prose th,
.kh__prose td {
  border: 1px solid var(--kh-border);
  padding: 0.45rem 0.6rem;
  text-align: left;
}
.kh__prose th { background: var(--kh-green-50); font-weight: 600; }
.kh__prose img { max-width: 100%; height: auto; border-radius: 8px; }

.kh__detail-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  margin-top: 1.75rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--kh-border);
}
.kh__open-full {
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  font-size: 0.95rem;
  color: #fff;
  background: var(--kh-green-500); /* AA contrast on white text */
  text-decoration: none;
  padding: 0.55rem 1rem;
  border-radius: var(--kh-radius-sm);
  transition: background 0.12s ease;
}
.kh__open-full:hover { background: var(--kh-green-600); }
.kh__detail-error { color: var(--kh-n400); }
.kh__retry {
  font: inherit;
  color: var(--kh-link);
  background: none;
  border: none;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}

/* loading skeleton */
.kh__skeleton {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-top: 0.5rem;
}
.kh__skeleton span {
  height: 0.85rem;
  border-radius: 5px;
  background: linear-gradient(
    90deg,
    var(--kh-surface-2) 0%,
    color-mix(in srgb, var(--kh-green-100) 40%, var(--kh-surface-2)) 50%,
    var(--kh-surface-2) 100%
  );
  background-size: 200% 100%;
  animation: kh-shimmer 1.2s ease-in-out infinite;
}
.kh__skeleton--short { width: 55%; }
@keyframes kh-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── empty state ───────────────────────────────────────────────────────────── */
.kh__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 0.6rem;
  color: var(--kh-text-secondary);
}
.kh__empty-arrow {
  font-size: 1.6rem;
  color: var(--kh-green-300);
}
.kh__empty-hint {
  margin: 0;
  max-width: 32ch;
  text-align: center;
}

/* ── "Mest søkt på" example chips ──────────────────────────────────────────── */
.kh__examples {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.4rem 0.6rem;
  margin-top: 1rem;
}
.kh__examples-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--kh-text-secondary);
}
.kh__examples-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.kh__example-chip {
  font: inherit;
  font-size: 0.82rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--kh-border);
  background: var(--kh-surface);
  color: var(--kh-green-700);
  cursor: pointer;
  transition: all 0.12s ease;
}
.kh__example-chip:hover {
  border-color: var(--kh-green-400);
  background: var(--kh-green-50);
}

/* ── focus visibility ──────────────────────────────────────────────────────── */
.kh button:focus-visible,
.kh a:focus-visible {
  outline: 2px solid var(--kh-green-400);
  outline-offset: 2px;
  border-radius: 4px;
}

/* visually-hidden SR status */
.kh__sr-status {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── responsive: stack + pane swap ─────────────────────────────────────────── */
@media (max-width: 860px) {
  .kh__panes {
    grid-template-columns: 1fr;
    height: auto;
  }
  .kh__list-pane { border-right: none; }
  .kh__results { max-height: 58vh; }
  .kh__detail-pane { display: none; max-height: none; padding: 1.25rem 1.25rem 1.75rem; }
  .kh--show-detail .kh__list-pane { display: none; }
  .kh--show-detail .kh__detail-pane { display: block; }
  .kh__back { display: inline-flex; }
  .kh__empty { height: auto; padding: 2.5rem 0; }

  /* touch targets ≥ 44px on phones */
  .kh__option { min-height: 48px; }
  .kh__back { min-height: 44px; padding-block: 0.65rem; }
  .kh__example-chip { padding: 0.55rem 0.9rem; }
  .kh__clear { width: 2.4rem; height: 2.4rem; }
}

/* ── reduced motion: kill shimmer, spinner, and all transitions ────────────── */
@media (prefers-reduced-motion: reduce) {
  .kh *,
  .kh *::before,
  .kh *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

