/* Advania – Vernerunde. Mobil først, kun lyst tema. */
:root {
  color-scheme: light;
  --text: #30302F;
  --muted: #6B6970;
  --purple: #471267;
  --purple-700: #3a0e55;
  --purple-50: #F3ECF7;
  --magenta: #BF007E;
  --orange: #EB5A28;
  --orange-50: #FDEEE8;
  --blue: #0088A7;
  --green: #5F8F3D;
  --green-50: #EEF4E9;
  --amber: #C98A00;
  --bg: #F7F6F8;
  --card: #FFFFFF;
  --line: #E4E1E8;
  --line-strong: #CFCAD6;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(48, 48, 47, .06), 0 2px 8px rgba(71, 18, 103, .05);
  --focus: 0 0 0 3px #fff, 0 0 0 5px var(--blue);
  --tap: 48px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.2; margin: 0; color: var(--text); }
h1 { font-size: 1.45rem; font-weight: 750; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; font-weight: 700; }
p { margin: 0; }
a { color: var(--purple); }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--focus); }

.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* ---------- Topplinje ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; border-radius: 8px; min-height: 44px; }
.brand-logo { display: block; height: 30px; width: auto; }
.brand-app {
  color: var(--purple); font-weight: 650; font-size: .95rem;
  padding-left: 10px; border-left: 1px solid var(--line-strong);
}
.progress { height: 4px; background: var(--purple-50); }
.progress-bar {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--purple), var(--magenta));
  transition: width .3s ease;
}

.save-status {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .8125rem; font-weight: 600; color: var(--muted);
  padding: 6px 10px; border-radius: 999px; background: var(--bg);
  white-space: nowrap;
}
.save-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); flex: none; }
.save-status[data-state="saving"] .dot { background: var(--blue); animation: pulse 1s ease-in-out infinite; }
.save-status[data-state="saved"] { color: var(--green); background: var(--green-50); }
.save-status[data-state="saved"] .dot { background: var(--green); }
.save-status[data-state="offline"] { color: #A93A12; background: var(--orange-50); }
.save-status[data-state="offline"] .dot { background: var(--orange); }
.save-status[data-state="error"] { color: #A93A12; background: var(--orange-50); }
.save-status[data-state="error"] .dot { background: var(--orange); }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- Layout ---------- */
.wrap { max-width: 760px; margin: 0 auto; padding: 16px 12px 40px; }
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--line);
  padding: 18px 16px; margin-bottom: 14px;
}
.card-title { margin-bottom: 10px; }
.footer { text-align: center; color: var(--muted); font-size: .8125rem; padding: 0 16px 32px; }
.loading { text-align: center; color: var(--muted); padding: 48px 0; }
.empty { color: var(--muted); font-size: .9375rem; padding: 6px 0 12px; }

.hero { padding: 10px 4px 18px; }
.hero h1 { font-size: 1.7rem; color: var(--purple); margin-bottom: 8px; }
.hero p { color: var(--muted); max-width: 52ch; }

@media (min-width: 640px) {
  .wrap { padding: 24px 20px 48px; }
  .card { padding: 22px 22px; }
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
}

/* ---------- Skjemafelt ---------- */
.form { display: grid; gap: 2px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > label, .label { font-weight: 600; font-size: .9rem; }
input[type="text"], input[type="url"], input[type="date"], textarea {
  width: 100%; font: inherit; color: var(--text);
  background: #fff; border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 11px 12px; min-height: var(--tap);
  transition: border-color .15s, box-shadow .15s;
}
input[type="date"] { appearance: none; -webkit-appearance: none; }
textarea { resize: vertical; min-height: 76px; line-height: 1.4; }
input:focus, textarea:focus { outline: none; border-color: var(--purple); box-shadow: 0 0 0 3px rgba(71, 18, 103, .18); }
input::placeholder, textarea::placeholder { color: #9A97A0; }
.form-error { color: #A93A12; background: var(--orange-50); border-radius: 8px; padding: 10px 12px; font-size: .9rem; margin-bottom: 12px; }
.hint { color: var(--muted); font-size: .875rem; margin-top: 12px; }

/* ---------- Knapper ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 18px;
  font: inherit; font-weight: 650; text-decoration: none; cursor: pointer;
  border-radius: var(--radius-sm); border: 1.5px solid transparent;
  transition: background-color .15s, border-color .15s, color .15s, transform .05s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--purple); color: #fff; }
.btn-primary:hover { background: var(--purple-700); }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn-secondary { background: #fff; color: var(--purple); border-color: var(--purple); }
.btn-secondary:hover { background: var(--purple-50); }
.btn-ghost { background: transparent; color: var(--purple); padding: 8px 12px; min-height: 44px; }
.btn-ghost:hover { background: var(--purple-50); }
.btn-danger-ghost { background: transparent; color: #A93A12; padding: 8px 12px; min-height: 44px; }
.btn-danger-ghost:hover { background: var(--orange-50); }
.btn-block { width: 100%; }
.btn-sm { min-height: 40px; padding: 6px 12px; font-size: .875rem; }
.ico { width: 20px; height: 20px; flex: none; }
.icon-btn {
  flex: none; width: 44px; height: 44px; border: 0; background: transparent; cursor: pointer;
  font-size: 1.6rem; line-height: 1; color: inherit; border-radius: 8px;
}
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.actions .btn { white-space: nowrap; padding: 10px 8px; }

/* ---------- Banner ---------- */
.banner {
  display: flex; gap: 8px; align-items: flex-start;
  background: var(--purple); color: #fff; border-radius: var(--radius);
  padding: 14px 8px 14px 16px; margin-bottom: 14px; font-size: .9375rem;
}
.banner strong { display: block; margin-bottom: 2px; }
.banner .icon-btn { color: #fff; margin-top: -8px; }

/* ---------- Metadata ---------- */
.meta-head { margin-bottom: 14px; }
.meta-head h1 { color: var(--purple); }
.progress-text { color: var(--muted); font-size: .9rem; margin-top: 4px; }

/* ---------- Seksjoner ---------- */
.section { padding: 0; overflow: hidden; }
.section-toggle {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 16px; min-height: 64px; border: 0; background: transparent;
  font: inherit; color: inherit; text-align: left; cursor: pointer;
  border-radius: var(--radius);
}
.section-nr {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 750; font-size: .95rem;
  background: var(--purple-50); color: var(--purple);
}
.section.done .section-nr { background: var(--green); color: #fff; }
.section-titles { flex: 1; min-width: 0; }
.section-title { font-size: 1.02rem; font-weight: 700; display: block; }
.section-sub { font-weight: 400; font-size: .8125rem; color: var(--muted); display: block; }
.section-count {
  display: inline-block; margin-top: 6px; font-size: .8125rem; font-weight: 650; color: var(--muted);
  background: var(--bg); padding: 4px 9px; border-radius: 999px; white-space: nowrap;
}
.section.done .section-count { color: var(--green); background: var(--green-50); }
.section-count.warn { color: #A93A12; background: var(--orange-50); }
.chev { flex: none; width: 20px; height: 20px; color: var(--muted); transition: transform .2s; }
.section-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.section-body { border-top: 1px solid var(--line); }

.item { padding: 14px 16px 16px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item-text { font-weight: 550; margin-bottom: 10px; display: flex; gap: 8px; }
.item-nr { color: var(--muted); font-weight: 650; flex: none; min-width: 1.6em; }
.item.is-nei { background: linear-gradient(90deg, var(--orange) 0 3px, transparent 3px); }
.item.is-ja { background: linear-gradient(90deg, var(--green) 0 3px, transparent 3px); }

/* Segmenterte knapper */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0; border-radius: var(--radius-sm); }
.seg button {
  min-height: var(--tap); font: inherit; font-weight: 650; cursor: pointer;
  background: #fff; color: var(--text); border: 1.5px solid var(--line-strong);
  margin-left: -1.5px; position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  -webkit-tap-highlight-color: transparent;
}
.seg button:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.seg button:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.seg button:hover { background: var(--bg); }
.seg button:focus-visible { z-index: 2; }
.seg button[aria-pressed="true"] { z-index: 1; color: #fff; }
.seg button .check { width: 18px; height: 18px; display: none; }
.seg button[aria-pressed="true"] .check { display: block; }
.seg .opt-ja[aria-pressed="true"] { background: var(--green); border-color: var(--green); }
.seg .opt-nei[aria-pressed="true"] { background: var(--orange); border-color: var(--orange); }
.seg .risk-1[aria-pressed="true"] { background: var(--green); border-color: var(--green); }
.seg .risk-2[aria-pressed="true"] { background: var(--amber); border-color: var(--amber); }
.seg .risk-3[aria-pressed="true"] { background: #C2361A; border-color: #C2361A; }
.seg .risk-n { font-weight: 800; }
.seg .risk-l { font-weight: 500; font-size: .8125rem; }

.comment { margin-top: 12px; display: grid; gap: 6px; }
.comment label { font-size: .875rem; font-weight: 600; }
.comment.required label::after { content: " (påkrevd ved nei)"; color: #A93A12; font-weight: 600; }
.comment.required.missing textarea { border-color: var(--orange); background: #FFFBF9; }
.comment-warn { font-size: .8125rem; color: #A93A12; display: flex; gap: 6px; align-items: center; }
.item-tools { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 8px; margin-left: -10px; }

/* ---------- Handlingsplan ---------- */
.plan-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.plan-head .card-title { margin-bottom: 0; }
.badge { font-size: .8125rem; font-weight: 650; background: var(--purple-50); color: var(--purple); padding: 4px 10px; border-radius: 999px; }
.plan-card > .muted { margin: 4px 0 14px; }
.plan-rows { display: grid; gap: 12px; margin-bottom: 12px; }
.plan-row {
  border: 1.5px solid var(--line); border-radius: var(--radius); padding: 14px 14px 4px;
  background: #FCFBFD; scroll-margin-top: 90px;
}
.plan-row.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { border-color: var(--magenta); box-shadow: 0 0 0 3px rgba(191, 0, 126, .15); } }
.plan-row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.plan-row-title { font-weight: 750; color: var(--purple); }
.plan-row-head .btn-danger-ghost { margin-right: -8px; }
.plan-sign { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }

/* ---------- Mine vernerunder ---------- */
.round-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.round-list li { display: flex; align-items: stretch; gap: 4px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; }
.round-link {
  flex: 1; min-width: 0; display: grid; gap: 2px; padding: 12px 14px; min-height: 56px;
  text-decoration: none; color: var(--text); border-radius: var(--radius-sm);
}
.round-link:hover { background: var(--bg); }
.round-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.round-date { font-size: .8125rem; color: var(--muted); }
.round-list .icon-btn { width: 48px; height: auto; color: var(--muted); font-size: 1.3rem; }
.round-list .icon-btn:hover { color: #A93A12; }

.error-card { text-align: center; padding: 32px 18px; }
.error-card p { color: var(--muted); margin: 10px 0 18px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: #fff; padding: 12px 18px; border-radius: 999px;
  font-size: .9375rem; font-weight: 550; max-width: calc(100% - 32px); text-align: center;
  transition: opacity .2s, transform .2s; z-index: 50;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .brand-app { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Hvem er inne ---------- */
.presence { padding: 14px 16px; display: grid; gap: 10px; }
.presence-head { display: flex; align-items: center; gap: 8px; }
.presence-label { font-size: .9375rem; font-weight: 650; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); flex: none; }
.presence[data-live="true"] .live-dot { background: var(--green); box-shadow: 0 0 0 3px var(--green-50); }
.presence-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.presence-list:empty { display: none; }
.who { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 3px 10px 3px 3px;
  border-radius: 999px; background: var(--purple-50); color: var(--purple); font-size: .875rem; font-weight: 550; }
.who.me { background: var(--card); box-shadow: inset 0 0 0 1px var(--line-strong); color: var(--text); }
.who-av { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--purple); color: #fff; font-size: .6875rem; font-weight: 700; letter-spacing: .02em; }
.who.me .who-av { background: var(--magenta); }
.who-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.presence-name { margin: 0; }
.presence-name label { font-size: .8125rem; }

/* ---------- v2: faner, protokoll, kartlegginger ---------- */
.top-actions { margin: 0 0 12px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin: 0 0 14px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); position: sticky; top: 70px; z-index: 5; }
.tab { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; border-radius: var(--radius-sm);
  font-weight: 650; color: var(--muted); text-decoration: none; }
.tab[aria-current="page"] { background: var(--purple); color: #fff; }
.tab[aria-current="page"] .badge { background: rgba(255,255,255,.2); color: #fff; }
.view-heading { font-size: 1.15rem; margin: 22px 4px 10px; color: var(--purple); }
.ov-list { display: grid; }
.ov-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ov-row:last-child { border-bottom: 0; }
.ov-text { display: flex; gap: 6px; font-size: .9375rem; }
.seg-sm button { min-height: 40px; padding: 4px 12px; font-size: .875rem; }
.seg-sm { min-width: 150px; }
.ok-row { display: flex; align-items: center; gap: 12px; margin: 10px 0 12px; }
.ok-label { min-width: 26px; }
.seg-ok { min-width: 150px; }
.seg .opt-na[aria-pressed="true"] { background: var(--muted); border-color: var(--muted); }
.item-text.long { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.item-text.long.open { display: block; -webkit-line-clamp: unset; }
.more-btn { margin: 2px 0 4px -12px; }
.item .field { margin-bottom: 8px; }
.p-more { margin-top: 2px; }
.k-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.k-item { display: grid; gap: 2px; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  text-decoration: none; color: var(--text); min-height: 48px; }
.k-item:hover { background: var(--purple-50); }
.k-name { font-weight: 650; color: var(--purple); }
.k-meta { font-size: .8125rem; color: var(--muted); }
.k-nav { display: flex; justify-content: space-between; align-items: center; margin: 0 0 8px; }
