/* ============================================================================
   Salgspartner E-læring — lyst "liquid glass"-tema (light mode)
   Portal-chrome bruker --brand (fast emerald). Innhold bruker --accent som
   kan overstyres per kurs via inline CSS-variabler på #main.
   ============================================================================ */
:root {
  /* Overflater (frostet, lyst glass) */
  --surface: rgba(255, 255, 255, 0.58);
  --surface-2: rgba(255, 255, 255, 0.78);
  --surface-hover: rgba(255, 255, 255, 0.92);
  --border: rgba(17, 24, 39, 0.08);
  --border-strong: rgba(17, 24, 39, 0.16);
  --highlight: inset 0 1px 0 rgba(255, 255, 255, 0.75);

  /* Tekst */
  --text: #161d27;
  --text-muted: #5a6573;
  --text-dim: #939ca8;

  /* Merkevare (portal-chrome, alltid emerald) */
  --brand: #059669;
  --brand-strong: #047857;
  --brand-soft: rgba(5, 150, 105, 0.12);

  /* Aksent (innhold — kan overstyres per kurs) */
  --accent: #059669;
  --accent-2: #10b981;
  --accent-soft: rgba(5, 150, 105, 0.12);

  --danger: #dc2626;
  --warn: #d97706;
  --ok: #059669;

  --radius: 18px;
  --radius-sm: 11px;
  --shadow: 0 12px 36px -10px rgba(20, 30, 48, 0.22);
  --shadow-soft: 0 6px 22px -8px rgba(20, 30, 48, 0.16);
  --sidebar-w: 266px;
}

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

html, body { height: 100%; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 720px at 88% -12%, rgba(16, 185, 129, 0.16), transparent 58%),
    radial-gradient(900px 620px at -12% 112%, rgba(99, 102, 241, 0.12), transparent 55%),
    radial-gradient(700px 500px at 50% 120%, rgba(236, 174, 64, 0.07), transparent 60%),
    linear-gradient(160deg, #f5f8fb, #e9eef4);
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent-soft); }

/* Glass-utility */
.glass {
  background: var(--surface);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft), var(--highlight);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(20, 30, 48, 0.16); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: rgba(20, 30, 48, 0.26); }

/* ───────────── Knapper ───────────── */
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 10px 18px; color: var(--text);
  background: var(--surface-2); transition: all .16s ease; display: inline-flex; align-items: center; gap: 9px;
  box-shadow: var(--highlight);
}
.btn:hover { background: var(--surface-hover); transform: translateY(-1px); box-shadow: var(--shadow-soft); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: default; transform: none; box-shadow: none; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; font-weight: 700;
  box-shadow: 0 8px 22px -8px var(--accent), inset 0 1px 0 rgba(255,255,255,0.25);
}
.btn-primary:hover { filter: brightness(1.05); box-shadow: 0 12px 28px -8px var(--accent); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-muted); box-shadow: none; }
.btn-sm { padding: 7px 14px; font-size: 13.5px; }
.btn-lg { padding: 14px 26px; font-size: 16px; }
.link-muted { background: none; border: none; color: var(--text-dim); cursor: pointer; font: inherit; font-size: 13px; padding: 0; text-align: left; }
.link-muted:hover { color: var(--accent); }

/* ───────────── Innlogging ───────────── */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.login-card { border-radius: 24px; padding: 46px 40px; width: 90%; max-width: 410px; text-align: center; box-shadow: var(--shadow), var(--highlight); position: relative; z-index: 2; }
.login-tagline { color: var(--text-muted); margin: 20px 0 28px; font-size: 15px; }
.login-card .brand { justify-content: center; }
.login-bg { position: absolute; inset: 0; z-index: 1;
  background: radial-gradient(620px 440px at 28% 18%, rgba(16,185,129,.20), transparent 60%),
              radial-gradient(520px 420px at 82% 92%, rgba(99,102,241,.16), transparent 60%); }

/* Merkevare */
.brand { display: flex; align-items: center; gap: 13px; }
.brand-logo { height: 38px; width: auto; flex: 0 0 auto; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: -.2px; }
.brand-sub { font-size: 12px; color: var(--text-muted); font-weight: 500; }

.ms-logo { display: inline-block; flex: 0 0 auto; }

/* Lasteskjerm — logo i midten, spinner-ring roterer rundt */
.loading-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.loader { position: relative; width: 92px; height: 92px; display: flex; align-items: center; justify-content: center; }
.loader::before { content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--brand); animation: spin .8s linear infinite; }
.loading-logo { height: 42px; width: auto; animation: logoPulse 1.6s ease-in-out infinite; }
@keyframes logoPulse { 0%, 100% { opacity: .6; } 50% { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────── App-layout ───────────── */
#app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); position: fixed; top: 0; bottom: 0; left: 0;
  display: flex; flex-direction: column; padding: 22px 16px; gap: 8px; z-index: 40;
  border-right: 1px solid var(--border); border-radius: 0;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 2px 4px 18px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; cursor: pointer; overflow: hidden; }
.sidebar-toggle { flex: 0 0 auto; width: 32px; height: 32px; border-radius: 9px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center; transition: all .14s; }
.sidebar-toggle:hover { background: var(--surface-hover); color: var(--text); }
.sidebar-toggle::before { content: "«"; font-size: 17px; line-height: 1; }

/* Kollapset sidemeny */
body.sidebar-collapsed { --sidebar-w: 78px; }
body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .sidenav-item .label,
body.sidebar-collapsed .user-meta { display: none; }
body.sidebar-collapsed .sidebar-top { flex-direction: column-reverse; gap: 12px; }
body.sidebar-collapsed .sidebar-brand { justify-content: center; }
body.sidebar-collapsed .sidenav-item { justify-content: center; padding: 11px; }
body.sidebar-collapsed .sidebar-user { justify-content: center; }
body.sidebar-collapsed .sidebar-toggle::before { content: "»"; }
body.sidebar-collapsed .brand-logo { height: 34px; }
.sidenav { display: flex; flex-direction: column; gap: 4px; }
.sidenav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 13px; border-radius: 11px; cursor: pointer;
  background: transparent; border: none; color: var(--text-muted); font: inherit; font-weight: 600; font-size: 14.5px;
  width: 100%; text-align: left; transition: all .14s;
}
.sidenav-item:hover { background: var(--surface-2); color: var(--text); }
.sidenav-item.active { background: var(--brand-soft); color: var(--brand); }
.sidenav-sub { display: flex; flex-direction: column; gap: 2px; margin: 2px 0 4px 17px; padding-left: 12px; border-left: 1px solid var(--border); }
.sidenav-subitem { font-size: 13.5px; padding: 8px 12px; font-weight: 500; }
body.sidebar-collapsed .sidenav-sub { display: none; }
.ico { width: 18px; height: 18px; flex: 0 0 auto; opacity: .9;
  background: currentColor; -webkit-mask: var(--m) center/contain no-repeat; mask: var(--m) center/contain no-repeat; }
.ico-home { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 9.5 12 3l9 6.5V21H3z'/%3E%3C/svg%3E"); }
.ico-admin { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='8' r='3.2'/%3E%3Cpath d='M4 20c0-3.5 3.6-6 8-6s8 2.5 8 6'/%3E%3C/svg%3E"); }

.sidebar-extra { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.side-section { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-dim); padding: 14px 13px 6px; font-weight: 700; }
.side-module { display: flex; align-items: center; gap: 10px; padding: 9px 13px; border-radius: 10px; cursor: pointer;
  background: transparent; border: none; color: var(--text-muted); font: inherit; font-size: 13.5px; width: 100%; text-align: left; }
.side-module:hover { background: var(--surface-2); color: var(--text); }
.side-module.active { color: var(--accent); background: var(--accent-soft); }
.side-module .dot { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center; font-size: 11px; flex: 0 0 auto; }
.side-module.done .dot { background: var(--accent); border-color: var(--accent); color: #fff; }

.sidebar-user { margin-top: auto; display: flex; align-items: center; gap: 11px; padding: 12px 8px 4px; border-top: 1px solid var(--border); }
.avatar { width: 36px; height: 36px; border-radius: 10px; background: var(--brand-soft); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--brand); flex: 0 0 auto; }
.user-meta { display: flex; flex-direction: column; line-height: 1.25; overflow: hidden; }
.user-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { margin-left: var(--sidebar-w); flex: 1; padding: 40px 44px 90px; max-width: 1180px; transition: margin-left .2s ease; }

/* Kurs-layout: innhold + oversiktspanel til høyre */
.course-layout { display: flex; gap: 28px; align-items: flex-start; }
.course-content { flex: 1; min-width: 0; }
.course-aside { flex: 0 0 256px; position: sticky; top: 28px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-soft), var(--highlight);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); padding: 10px 8px 12px; }
.course-aside .side-section { padding-top: 8px; }
@media (max-width: 980px) {
  .course-layout { flex-direction: column; }
  .course-aside { position: static; width: 100%; flex: none; order: -1; }
}

/* ───────────── Typografi / felles ───────────── */
.page-title { font-size: 30px; font-weight: 800; letter-spacing: -.5px; margin-bottom: 6px; }
.page-sub { color: var(--text-muted); margin-bottom: 28px; font-size: 15px; }
.lead { font-size: 18px; color: var(--text-muted); margin-bottom: 22px; }
.muted { color: var(--text-muted); }
.error { color: var(--danger); }

/* ───────────── Kurskort ───────────── */
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 20px; }
.course-card { border-radius: var(--radius); padding: 24px; display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-soft), var(--highlight);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  transition: all .18s; position: relative; overflow: hidden; }
.course-card::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--c-accent, var(--accent)), var(--c-accent2, var(--accent-2))); }
.course-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.course-card h3 { font-size: 18px; font-weight: 700; }
.course-card .muted { font-size: 14px; flex: 1; }
.course-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.tag { font-size: 12px; font-weight: 600; padding: 4px 11px; border-radius: 20px; background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.tag-ok { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.tag-warn { background: rgba(217,119,6,.14); color: var(--warn); border-color: transparent; }

/* ───────────── Innholdsblokker ───────────── */
.block-heading { margin: 26px 0 8px; font-weight: 700; }
.block-p { margin: 14px 0; color: #2b333d; }
.block-html { margin: 16px 0; }
textarea.mono { font-family: ui-monospace, "Cascadia Code", "Consolas", monospace; font-size: 13px; }
.block-list { margin: 14px 0 14px 22px; color: #2b333d; }
.block-list li { margin: 6px 0; }
.block-table { width: 100%; border-collapse: collapse; margin: 18px 0; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); }
.block-table th, .block-table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.block-table th { background: var(--surface-2); font-weight: 600; }

.info-box { border-radius: var(--radius-sm); padding: 16px 18px; margin: 18px 0; border: 1px solid var(--border);
  border-left: 4px solid var(--iv, #6366f1); background: var(--surface); box-shadow: var(--highlight); }
.info-box-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.info-box-icon { width: 24px; height: 24px; flex: 0 0 auto; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 14px; font-weight: 800; color: #fff; background: var(--iv, #6366f1); }
.info-box-title { font-weight: 700; }
.info-box-body { color: #2b333d; }
/* Varianter (ny + bakoverkompatible) */
.info-box.info     { --iv: #6366f1; }
.info-box.positive, .info-box.success { --iv: var(--ok); }
.info-box.negative { --iv: var(--danger); }
.info-box.obs, .info-box.warning      { --iv: #f97316; }
.info-box.fact, .info-box.tip         { --iv: #eab308; }

/* ───────────── Framdrift ───────────── */
.progress-wrap { margin-bottom: 26px; }
.progress-bar { height: 8px; border-radius: 5px; background: rgba(20,30,48,.08); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 5px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .45s ease; }
.progress-text { font-size: 13px; color: var(--text-muted); margin-top: 8px; font-weight: 600; }

/* ───────────── Quiz ───────────── */
.quiz { border-radius: var(--radius); padding: 26px; margin: 30px 0; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-soft), var(--highlight); }
.quiz-title { font-size: 19px; font-weight: 700; margin-bottom: 18px; display: flex; align-items: center; gap: 10px; }
.quiz-title::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.question { margin: 20px 0; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.question:last-of-type { border-bottom: none; }
.question-text { font-weight: 600; margin-bottom: 14px; }
.options { display: flex; flex-direction: column; gap: 9px; margin-bottom: 14px; }
.option { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; transition: all .14s; }
.option:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.option input { accent-color: var(--accent); width: 17px; height: 17px; flex: 0 0 auto; cursor: pointer; }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
/* Visuell fasit-feedback etter at svaret er sjekket (vises bare når kurset tillater fasit) */
.option.opt-correct { border-color: var(--ok); background: var(--brand-soft); }
.option.opt-wrong { border-color: var(--danger); background: rgba(220,38,38,.10); }
.text-answer { width: 100%; min-height: 90px; padding: 13px; border-radius: var(--radius-sm); resize: vertical;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; margin-bottom: 14px; }
.text-answer:focus { outline: none; border-color: var(--accent); }
.feedback { display: none; margin-top: 12px; padding: 11px 15px; border-radius: var(--radius-sm); font-size: 14px; }
.feedback.show { display: block; }
.feedback.correct { background: var(--brand-soft); color: var(--ok); }
.feedback.wrong { background: rgba(220,38,38,.10); color: var(--danger); }
.nav-buttons { margin-top: 26px; display: flex; justify-content: flex-end; }
.nav-buttons.reveal { animation: fadeUp .35s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
/* Fremhev neste-knappen når den dukker opp (alle svar gitt) */
.nav-buttons.reveal .btn-primary { animation: nextPulse 1.8s ease-in-out infinite; }
.nav-buttons.reveal .btn-primary:hover { animation: none; }
@keyframes nextPulse {
  0%, 100% { box-shadow: 0 8px 22px -8px var(--accent), 0 0 0 0 var(--accent-soft); }
  50%      { box-shadow: 0 10px 28px -6px var(--accent), 0 0 0 6px var(--accent-soft); }
}

/* ───────────── Resultat ───────────── */
.result-screen { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 130px); }
.result-screen .result-card { margin: 0; }
.result-card { border-radius: 24px; padding: 50px; text-align: center; max-width: 500px; margin: 40px auto;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow), var(--highlight); }
.result-card.ok { border-top: 4px solid var(--ok); }
.result-card.warn { border-top: 4px solid var(--warn); }
.result-icon { font-size: 52px; }
.result-card h1 { margin: 12px 0; }
.result-score { font-size: 17px; color: var(--text-muted); margin: 8px 0 26px; }

/* ───────────── Admin ───────────── */
.tabs { display: flex; gap: 4px; margin-bottom: 24px; border-bottom: 1px solid var(--border); }
.tab { background: none; border: none; padding: 11px 18px; cursor: pointer; font: inherit; font-weight: 600;
  color: var(--text-muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.data-table { width: 100%; border-collapse: collapse; border-radius: var(--radius); overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-soft), var(--highlight); }
.data-table th, .data-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
.data-table th { background: var(--surface-2); font-weight: 600; color: var(--text-muted); }
.data-table tr:last-child td { border-bottom: none; }
.res-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.res-sortable:hover { color: var(--text); }
.res-pass { color: var(--ok); font-weight: 600; }
.res-fail { color: var(--danger); font-weight: 600; }
.res-filters { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 18px; align-items: flex-end; }
.res-filter { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-muted); font-weight: 600; }
.res-filter select, .res-filter input { padding: 8px 11px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; min-width: 160px; }
.res-filter select:focus, .res-filter input:focus { outline: none; border-color: var(--accent); }
.res-attempts { white-space: nowrap; }
.res-attempts .res-lock { margin-left: 8px; font-size: 11px; font-weight: 700; color: var(--danger);
  background: rgba(220,38,38,.10); padding: 2px 7px; border-radius: 999px; }
.res-attempts .res-grant { margin-left: 8px; font-size: 11px; font-weight: 700; color: var(--ok);
  background: var(--brand-soft); padding: 2px 7px; border-radius: 999px; }
.res-actions { white-space: nowrap; }
.res-actions .btn { margin-left: 8px; }
.res-summary { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.res-chip { font-size: 13px; font-weight: 600; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--border); }
.res-chip-lock { color: var(--danger); background: rgba(220,38,38,.08); }
.res-chip-grant { color: var(--ok); background: var(--brand-soft); }
.btn-grant { margin-left: 10px; }
.answer-card { border-radius: var(--radius-sm); padding: 16px 18px; margin: 12px 0; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--highlight); }
.answer-q { font-weight: 600; margin-bottom: 8px; }
.answer-a { padding: 8px 12px; border-radius: 8px; background: var(--surface-2); font-size: 14px; }
.answer-a.correct { background: var(--brand-soft); color: var(--ok); }
.answer-a.wrong { background: rgba(220,38,38,.10); color: var(--danger); }

/* ───────────── Kurs-bygger (admin) ───────────── */
.btn-danger { color: var(--danger); border-color: rgba(220,38,38,.3); }
.btn-danger:hover { background: rgba(220,38,38,.10); }
.builder-toolbar { display: flex; gap: 10px; margin-bottom: 18px; }
.builder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 18px; }
.builder-card { border-radius: var(--radius); padding: 20px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-soft), var(--highlight); position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 10px; }
.builder-card > .muted { flex: 1; }      /* beskrivelsen fyller, så tag + knapper havner på bunnlinje */
.builder-card .course-meta { margin-top: auto; }
.builder-card .builder-actions { margin-top: 0; }
.builder-card::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--c-accent, var(--accent)), var(--c-accent, var(--accent))); }
.builder-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.builder-actions { display: flex; align-items: center; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.save-msg { font-size: 13px; color: var(--text-muted); }

.builder-section { border-radius: var(--radius); padding: 22px; margin: 18px 0; background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-soft), var(--highlight); }
.builder-h { margin-bottom: 14px; }
.builder-module { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 18px; margin: 14px 0; background: var(--surface-2); }
.builder-sub { margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--border); }
.builder-item { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; margin: 10px 0; background: var(--surface); }
.builder-tag { font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 3px 10px; border-radius: 20px; }

/* Sammenleggbare seksjoner (accordion) i byggeren */
.builder-modules { margin-top: 8px; }
.acc { border: 1px solid var(--border); border-radius: var(--radius-sm); margin: 12px 0; background: var(--surface);
  box-shadow: var(--shadow-soft), var(--highlight); overflow: hidden; }
.acc-head { display: flex; align-items: center; gap: 12px; padding: 15px 18px; cursor: pointer; user-select: none; transition: background .12s; }
.acc-head:hover { background: var(--surface-2); }
.acc-title { font-weight: 700; flex: 1; font-size: 15px; }
.acc-actions { display: flex; gap: 8px; }
.acc-chevron::before { content: "›"; font-size: 20px; line-height: 1; color: var(--text-muted); display: inline-block; transition: transform .16s ease; }
.acc.open > .acc-head .acc-chevron::before { transform: rotate(90deg); }
.acc-body { display: none; padding: 4px 18px 18px; }
.acc.open > .acc-body { display: block; }
/* Modulnivå: tydeligere kort. Undernivå (Innhold/Spørsmål): lettere bakgrunn. */
.acc.acc-module { background: var(--surface); }
.acc.acc-module > .acc-head .acc-title { font-size: 16px; }
.acc.acc-sub { background: var(--surface-2); box-shadow: none; border-style: dashed; }
.acc.acc-sub > .acc-head { padding: 11px 14px; }
.acc.acc-sub > .acc-head .acc-title { font-size: 13.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; }

/* Segmentert "legg til"-kontroll: type-velger + knapp som ett element */
.add-group { display: inline-flex; align-items: stretch; margin: 6px 0 14px; }
.add-group-select { width: auto; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.add-group-btn { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; white-space: nowrap; }

/* "Legg til"-meny (utvides i flyten, så den aldri klippes av accordion) */
.addmenu { display: block; margin: 6px 0 12px; }
/* I verktøylinjen: absolutt dropdown (forstyrrer ikke layouten). Inne i accordion: in-flow (unngår klipping). */
.builder-toolbar { align-items: flex-start; }
.builder-toolbar .addmenu { margin: 0; position: relative; }
.builder-toolbar .addmenu-list { position: absolute; top: calc(100% + 6px); left: 0; z-index: 50; min-width: 230px; }
.builder-item.unsaved { box-shadow: inset 3px 0 0 var(--warn), var(--highlight); }
.addmenu-list { display: none; margin-top: 8px; max-width: 280px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-soft); padding: 6px; }
.addmenu-list.open { display: block; }
.addmenu-item { display: block; width: 100%; text-align: left; padding: 10px 12px; border: none; background: none;
  border-radius: 8px; cursor: pointer; font: inherit; color: var(--text); }
.addmenu-item:hover { background: var(--surface-2); }

/* Drag-and-drop sortering */
.sortable-list { display: flex; flex-direction: column; }
.item-head-left { display: flex; align-items: center; gap: 10px; }
.drag-handle { cursor: grab; color: var(--text-dim); font-size: 16px; line-height: 1; user-select: none; padding: 2px 4px; border-radius: 6px; }
.drag-handle:hover { background: var(--surface-2); color: var(--text-muted); }
.drag-handle:active { cursor: grabbing; }
.builder-item.dragging, .acc.dragging { opacity: .45; }

.form-row { margin: 12px 0; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.form-input { width: 100%; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: #fff; color: var(--text); font: inherit; }
.form-input:focus { outline: none; border-color: var(--accent); }
input[type="color"].form-input { height: 42px; padding: 4px; cursor: pointer; }
.form-hint { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.form-checkrow { display: flex; align-items: center; gap: 10px; margin: 12px 0; cursor: pointer; font-size: 14px; }
.form-check, .form-checkrow input { width: 18px; height: 18px; accent-color: var(--accent); }
.opts-wrap { margin: 12px 0; }
.opt-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.opt-row input[type="text"] { flex: 1; }
.opt-row .rich { flex: 1; }

/* Rik-tekst-felt (contenteditable) */
.rich { display: flex; flex-direction: column; }
.rich-tb { display: flex; gap: 4px; margin-bottom: 6px; flex-wrap: wrap; align-items: center; }
.rich-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.rich-sw { width: 22px; height: 24px; border-radius: 6px; border: 1px solid rgba(0,0,0,.18); cursor: pointer; padding: 0; }
.rich-sw:hover { transform: scale(1.08); }
.rich-tb-btn { width: 30px; height: 28px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; font-size: 13px; color: var(--text); font-family: Georgia, serif; }
.rich-tb-btn:nth-child(1) { font-weight: 800; }
.rich-tb-btn:nth-child(2) { text-decoration: underline; }
.rich-tb-btn:nth-child(3) { font-style: italic; }
.rich-tb-btn:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.rich-ed { min-height: 44px; cursor: text; overflow-wrap: anywhere; }
.rich-ed:focus { outline: none; border-color: var(--accent); }
.rich-ed.rich-single { min-height: 0; white-space: nowrap; overflow-x: auto; }
.rich-ed[data-placeholder]:empty::before { content: attr(data-placeholder); color: var(--text-dim); pointer-events: none; }
.opt-row input[type="radio"], .opt-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); flex: 0 0 auto; }

/* ───────────── Forhåndsvisning ───────────── */
.preview-overlay { position: fixed; inset: 0; z-index: 1050; display: flex; align-items: center; justify-content: center;
  background: rgba(20, 30, 48, 0.4); backdrop-filter: blur(3px); padding: 24px; }
.preview-modal { width: 100%; max-width: 880px; height: 92vh; display: flex; flex-direction: column;
  border-radius: 18px; overflow: hidden; background: linear-gradient(160deg, #f5f8fb, #e9eef4);
  border: 1px solid var(--border); box-shadow: var(--shadow); }
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; flex-wrap: wrap;
  background: rgba(255,255,255,.7); backdrop-filter: blur(20px); border-bottom: 1px solid var(--border); }
.preview-title { font-weight: 700; }
.preview-live { flex-basis: 100%; font-size: 12px; color: var(--brand); font-weight: 600; }
.preview-tools { display: flex; gap: 8px; }
.preview-body { flex: 1; overflow-y: auto; padding: 32px 36px 60px; }
/* Side ved side: dokk til høyre, la editoren være klikkbar til venstre */
.preview-overlay.side { background: transparent; backdrop-filter: none; justify-content: flex-end; padding: 0; pointer-events: none; }
.preview-overlay.side .preview-modal { pointer-events: auto; height: 100vh; max-width: 46vw; border-radius: 0;
  border-left: 1px solid var(--border-strong); box-shadow: -12px 0 40px -12px rgba(20,30,48,.3); }
@media (max-width: 720px) { .preview-overlay.side .preview-modal { max-width: 100vw; } }

/* ───────────── Modal / toast ───────────── */
.ui-overlay { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center;
  background: rgba(20, 30, 48, 0.32); backdrop-filter: blur(3px); opacity: 0; transition: opacity .18s ease; }
.ui-overlay.show { opacity: 1; }
.ui-dialog { border-radius: 18px; padding: 26px 26px 22px; width: 90%; max-width: 420px; box-shadow: var(--shadow), var(--highlight);
  transform: translateY(10px) scale(.98); transition: transform .18s ease; }
.ui-overlay.show .ui-dialog { transform: none; }
.ui-dialog h3 { font-size: 18px; font-weight: 700; }
.ui-dialog-msg { color: var(--text-muted); margin: 10px 0 22px; }
.ui-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

#ui-root { position: fixed; bottom: 24px; right: 24px; z-index: 1100; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.ui-overlay { /* overlays fyller skjermen uavhengig av #ui-root-posisjon */ position: fixed; }
.ui-toast { padding: 13px 18px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 14px; font-weight: 500; max-width: 360px;
  opacity: 0; transform: translateY(10px); transition: all .25s ease; backdrop-filter: blur(20px); }
.ui-toast.show { opacity: 1; transform: none; }
.ui-toast-error { border-left: 3px solid var(--danger); }
.ui-toast-warn { border-left: 3px solid var(--warn); }
.ui-toast-success { border-left: 3px solid var(--ok); }

/* ───────────── Claude-knapp + popup ───────────── */
.btn-claude { border-color: rgba(217,119,87,.45); color: #b85c3e; background: #fff;
  animation: claudePulse 2.4s ease-in-out infinite; }
.btn-claude:hover { background: #fbeee7; animation: none; }
.claude-logo { vertical-align: -3px; }
@keyframes claudePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(217,119,87,0); }
  50% { box-shadow: 0 0 0 5px rgba(217,119,87,.18); }
}
.answer-edited { font-size: 12px; color: var(--warn); font-weight: 500; }
.answer-correct { margin-top: 6px; font-size: 13px; color: var(--ok); }

/* ───────────── "Lag kurs med Claude"-popup ───────────── */
.claude-modal { width: 92%; max-width: 760px; max-height: 90vh; display: flex; flex-direction: column;
  border-radius: 18px; box-shadow: var(--shadow), var(--highlight); }
/* Claude-fargepalett i popupen (korall i stedet for portalens emerald) */
.claude-modal { --accent: #d97757; --accent-2: #c2613f; --accent-soft: rgba(217,119,87,.14); }
.claude-modal .btn-primary { background: linear-gradient(135deg, #d97757, #c2613f); color: #fff;
  box-shadow: 0 8px 22px -8px #d97757, inset 0 1px 0 rgba(255,255,255,.25); }
.claude-modal .btn-primary:hover { filter: brightness(1.05); }
.claude-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px;
  border-bottom: 1px solid var(--border); background: linear-gradient(180deg, #fbeee7, transparent); }
.claude-head h2 { font-size: 19px; }
.claude-body { overflow-y: auto; padding: 20px 22px 26px; }
.claude-steps { margin: 0 0 20px; padding-left: 22px; color: var(--text); line-height: 1.7; }
.claude-steps li { margin: 6px 0; }
.claude-sub { margin: 22px 0 10px; font-size: 15px; }
.claude-prompt-wrap { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: #fff; }
.claude-prompt-wrap > .btn { margin: 12px; }
.claude-prompt { margin: 0; padding: 16px 18px; background: #fbfcfd; max-height: 220px; overflow: auto;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; line-height: 1.65;
  white-space: pre-wrap; color: #2b333d; border-top: 1px solid var(--border); }
.claude-tip { display: flex; gap: 12px; align-items: center; padding: 12px 14px; margin: 4px 0 16px;
  border-radius: var(--radius-sm); background: #fbeee7; border: 1px solid rgba(217,119,87,.3); font-size: 13.5px; color: #6b4636; }
.claude-tip-icon { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 8px; background: #2b2622; color: #e8e2dc;
  display: flex; align-items: center; justify-content: center; }
.claude-file { margin-bottom: 12px; }
.claude-file input { color: var(--text-muted); font: inherit; font-size: 14px; }
.claude-file input::file-selector-button {
  font: inherit; font-weight: 600; cursor: pointer; margin-right: 12px;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text); transition: all .15s;
}
.claude-file input::file-selector-button:hover { background: var(--surface-hover); }
.claude-json { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.claude-result { margin-top: 16px; }
.claude-ok { padding: 12px 16px; border-radius: var(--radius-sm); background: var(--brand-soft); color: var(--ok); font-weight: 600; margin-bottom: 12px; }
.claude-errors { padding: 14px 16px; border-radius: var(--radius-sm); background: rgba(220,38,38,.08); border: 1px solid rgba(220,38,38,.25); }
.claude-err-title { font-weight: 700; color: var(--danger); margin-bottom: 8px; }
.claude-errors ul { margin: 0 0 12px 18px; color: var(--text); font-size: 14px; }
.claude-errors li { margin: 3px 0; }

/* ───────────── Responsiv ───────────── */
@media (max-width: 820px) {
  .sidebar { position: static; width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; }
  .sidebar-extra, .sidebar-user { display: none; }
  .sidenav { flex-direction: row; }
  .main { margin-left: 0; padding: 24px 18px 70px; }
  #app { flex-direction: column; }
}
