/* Kartlegg – offentlige sider og innloggingsstatus: lasteskjerm, låste menyvalg, forside, vilkår og personvern.
 * Del av designsystemet i assets/css/. Bruker tokens, så lys/mørk modus og temaer virker.
 */

/* Mens Firebase sjekker en lagret innlogging, vises bare en rolig lasteindikator (ingen blinking mellom tilstander). */
.auth-loading {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 50vh;
  color: var(--muted);
  font-size: 15px;
}
:root[data-auth="checking"] .auth-loading {
  display: flex;
}
:root[data-auth="checking"] .main>.page,
:root[data-auth="checking"] .main>.footer {
  display: none !important;
}
.auth-loading-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: auth-spin .8s linear infinite;
}
@keyframes auth-spin {
  to { transform: rotate(360deg); }
}
@media(prefers-reduced-motion:reduce){
  .auth-loading-spinner { animation-duration: 2.4s; }
}

/* «Logg inn» i toppen for den som ikke er innlogget; profilknappen for den som er det. */
.header-login {
  display: none;
  flex: none;
  white-space: nowrap;
  align-items: center;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-on);
  font-size: 14px;
  font-weight: 750;
  text-decoration: none;
}
:root:is([data-auth="guest"],[data-auth="verify"],[data-auth="consent"]) .header-login {
  display: inline-flex;
}
:root:is([data-auth="guest"],[data-auth="verify"],[data-auth="consent"],[data-auth="checking"]) .header .profile-trigger {
  display: none !important;
}

/* Låste menyvalg (Ny vurdering og Kliniske verktøy er åpne for alle): hengelås ved siden av navnet. Et klikk åpner innloggingen med forklaring. */
:root:is([data-auth="guest"],[data-auth="verify"],[data-auth="consent"]) :is(.sidebar .nav,.mobile-primary-link):is([data-page="historikk"],[data-page="laer"],[data-page="simulering"],[data-page="profil"])::after {
  content: "";
  flex: none;
  width: 13px;
  height: 13px;
  margin-left: auto;
  background: currentColor;
  opacity: .6;
  -webkit-mask: 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.4' stroke-linecap='round'%3E%3Crect x='5' y='11' width='14' height='10' rx='2'/%3E%3Cpath d='M8 11V7a4 4 0 0 1 8 0v4'/%3E%3C/svg%3E") center/contain no-repeat;
  mask: 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.4' stroke-linecap='round'%3E%3Crect x='5' y='11' width='14' height='10' rx='2'/%3E%3Cpath d='M8 11V7a4 4 0 0 1 8 0v4'/%3E%3C/svg%3E") center/contain no-repeat;
}
:root:is([data-auth="guest"],[data-auth="verify"],[data-auth="consent"]) .mobile-primary-nav:not(.mobile-guest-nav) .mobile-primary-link::after {
  position: absolute;
  top: 7px;
  right: calc(50% - 20px);
  margin: 0;
}
.mobile-primary-link {
  position: relative;
}

/* Kontosiden: begrunnelse når man kom fra et låst menyvalg. */
.konto-reason {
  max-width: 440px;
  margin: 0 auto 14px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--accent-bg);
  color: var(--ink);
  font-size: 15px;
}
.konto-reason:empty {
  display: none;
}

/* ------------------------------------------------------------------
 * Offentlig forside
 * ------------------------------------------------------------------ */
.public-page {
  display: grid;
  gap: 40px;
  max-width: 1080px;
}
.public-page[hidden] {
  display: none;
}
.public-hero {
  display: grid;
  gap: 28px;
  align-items: center;
  padding-top: 8px;
}
@media(min-width:900px){
  .public-hero {
    grid-template-columns: minmax(0,1.25fr) minmax(0,.75fr);
    gap: 48px;
    padding-top: 24px;
  }
}
.public-hero h1 {
  margin: 0 0 14px;
  font-size: clamp(30px,4.4vw,46px);
  line-height: 1.1;
  letter-spacing: -.035em;
  max-width: 18ch;
}
.public-lede {
  margin: 0 0 22px;
  font-size: clamp(16px,1.6vw,19px);
  line-height: 1.55;
  color: var(--muted);
  max-width: 52ch;
}
.public-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.public-actions .public-cta {
  min-width: 0;
  min-height: 50px;
  padding: 0 22px;
  text-decoration: none;
}
@media(max-width:520px){
  .public-actions .public-cta {
    flex: 1 1 100%;
  }
}
.public-note {
  margin: 12px 0 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted);
}
.public-note a {
  color: var(--ui-action);
  font-weight: 700;
}
.public-feature-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  vertical-align: middle;
}
/* Forhåndsvisninger: illustrasjoner av funksjonene, ikke de faktiske verktøyene. */
.preview-card {
  max-width: 320px;
  margin: 0 auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: var(--ui-shadow-raised);
}
.preview-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
}
.preview-chip {
  padding: 3px 10px;
  border-radius: 99px;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.preview-score {
  margin: 10px 0 0;
  font-size: 56px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.04em;
}
.preview-status {
  margin: 6px 0 16px;
  color: var(--muted);
  font-weight: 600;
}
.preview-meter {
  display: grid;
  grid-template-columns: 1fr 4fr 2fr 2fr;
  gap: 3px;
  height: 10px;
}
.preview-meter span {
  border-radius: 4px;
}
.preview-meter span:nth-child(1) { background: #2f8a63; }
.preview-meter span:nth-child(2) { background: #6cc49a; }
.preview-meter span:nth-child(3) { background: #f0b43c; box-shadow: 0 0 0 2px var(--paper),0 0 0 4px var(--ink); }
.preview-meter span:nth-child(4) { background: #e2575c; }
.preview-meter-labels {
  display: grid;
  grid-template-columns: 1fr 4fr 2fr 2fr;
  gap: 3px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}
.public-section h2,
.public-disclaimer h2 {
  margin: 0 0 16px;
  font-size: clamp(22px,2.4vw,28px);
  letter-spacing: -.02em;
}
.public-features {
  display: grid;
  gap: 14px;
}
@media(min-width:700px){
  .public-features {
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 18px;
  }
}
.public-feature {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
}
.public-feature h3 {
  margin: 6px 0 0;
  font-size: 18px;
}
.public-feature p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}
.public-feature-preview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 64px;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg);
}
.preview-tools span,
.preview-steps span {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  font-size: 13px;
  font-weight: 700;
}
.preview-steps span:first-child {
  border-color: var(--accent);
  background: var(--accent-bg);
  color: var(--accent);
}
.preview-quote p {
  margin: 0;
  padding: 8px 12px;
  border-radius: 12px 12px 12px 4px;
  background: var(--paper);
  border: 1px solid var(--line);
  font-size: 14px;
  font-style: italic;
}
.preview-trend svg {
  width: 100%;
  max-width: 220px;
  height: 44px;
}
.preview-trend polyline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.public-split {
  display: grid;
  gap: 18px;
}
@media(min-width:900px){
  .public-split {
    grid-template-columns: minmax(0,1.1fr) minmax(0,.9fr);
    gap: 28px;
    align-items: start;
  }
}
.public-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.public-list li {
  position: relative;
  padding-left: 26px;
  line-height: 1.55;
}
.public-list li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: .55em;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}
.public-disclaimer {
  padding: 20px;
  border: 1px solid var(--accent-border,var(--line));
  border-radius: 18px;
  background: var(--accent-bg);
}
.public-disclaimer h2 {
  font-size: 19px;
  margin-bottom: 8px;
}
.public-disclaimer p {
  margin: 0 0 8px;
  line-height: 1.55;
}
.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
}

/* ------------------------------------------------------------------
 * Bruksvilkår og personvernerklæring
 * ------------------------------------------------------------------ */
.legal-doc {
  max-width: 720px;
  padding: clamp(18px,4vw,36px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  line-height: 1.6;
}
.legal-doc h1 {
  margin: 4px 0 2px;
  font-size: clamp(26px,3.4vw,34px);
  letter-spacing: -.025em;
}
.legal-doc h2 {
  margin: 26px 0 6px;
  font-size: 18px;
}
.legal-doc p,
.legal-doc li {
  color: var(--ink);
}
.legal-doc ul {
  padding-left: 20px;
}
.legal-doc li+li {
  margin-top: 6px;
}
.legal-meta {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}
.legal-draft {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--accent-bg);
  font-size: 14px;
}
@media(max-width:770px){
  .header-login {
    min-height: 40px;
    padding: 0 12px;
    font-size: 13px;
  }
}
/* På de smaleste telefonene er det ikke plass til både «Logg inn» og tema-knappen i toppen. */
@media(max-width:400px){
  :root:is([data-auth="guest"],[data-auth="verify"],[data-auth="consent"]) .header .theme-switch {
    display: none;
  }
}
/* Mobil: toppen har en fast 44 px-kolonne til tema-knappen. Med «Logg inn» trengs plass til innholdet. */
@media(max-width:770px){
  :root:is([data-auth="guest"],[data-auth="verify"],[data-auth="consent"]) .header {
    grid-template-columns: minmax(0,1fr) auto 44px !important;
  }
  :root:is([data-auth="guest"],[data-auth="verify"],[data-auth="consent"]) .header-right {
    width: auto !important;
    gap: 8px;
  }
}

/* Bunnmeny på mobil: gjester får Start, NEWS2, Verktøy og Logg inn. */
.mobile-guest-nav {
  display: none !important;
}
@media(max-width:770px){
  :root:is([data-auth="guest"],[data-auth="verify"],[data-auth="consent"]) .mobile-primary-nav:not(.mobile-guest-nav) {
    display: none !important;
  }
  :root:is([data-auth="guest"],[data-auth="verify"],[data-auth="consent"]) .mobile-guest-nav {
    display: grid !important;
    grid-template-columns: repeat(4,minmax(0,1fr));
  }
  .mobile-guest-nav .mobile-primary-link {
    text-decoration: none;
  }
}


/* Gjester kan regne ut skårer, men ikke lagre målinger over tid. */
:root:is([data-auth="guest"],[data-auth="verify"],[data-auth="consent"]) :is(#saveMeasurement,#page-vurdering .meta-line small) {
  display: none !important;
}

/* Kilder og lisenser. */
.license-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}
.license-item {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  scroll-margin-top: 92px;
}
.license-item.is-target {
  border-color: var(--ui-action);
  box-shadow: 0 0 0 3px rgba(23,111,166,.18);
}
.license-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.license-head h3 {
  margin: 0;
  font-size: 17px;
}
.license-status {
  flex: none;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
}
.license-status-ok {
  background: #daf4e9;
  color: #075e4d;
}
.license-status-ask {
  background: #fff1d6;
  color: #7a4d00;
}
:root[data-theme=dark] .license-status-ok {
  background: #1d4a3f;
  color: #c9f3e4;
}
:root[data-theme=dark] .license-status-ask {
  background: #4f3d1c;
  color: #ffe2a8;
}
.license-item dl {
  display: grid;
  gap: 4px;
  margin: 10px 0 0;
}
.license-item dt {
  font-size: 13px;
  font-weight: 750;
  color: var(--muted);
}
.license-item dd {
  margin: 0 0 6px;
  line-height: 1.5;
}
.tool-card-license {
  justify-self: start;
  margin: 0 0 6px;
  padding: 0;
  min-height: 32px;
  border: 0;
  background: none;
  color: var(--ui-action);
  font-size: 13px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* «Kilde og lisens» står alltid til venstre i kortet, uansett kortets oppsett. */
#page-verktoy .tool-card .tool-card-license {
  align-self: flex-start;
  justify-self: start;
  margin-left: 0;
  margin-right: auto;
  text-align: left;
}
/* Bunnlenker: større trykkflate på mobil. */
@media(max-width:770px){
  .footer-links a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }
  .footer-links {
    gap: 0 18px;
  }
}
/* Øvingsforløp: «Ny måling» og «Slett» vises først når det finnes målinger (tomtilstanden har egne knapper). */
#page-historikk[data-forlop-empty="true"] .history-toolbar .actions-right {
  display: none;
}
/* Mobil: lenkeknapper i kortene får minst 44 px trykkflate. */
@media(max-width:770px){
  :is(.tool-card-license,.criteria-link,.tool-card-learn-link,.gcs-learn-link,.sim-reference,.v081-view-all) {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }
}
/* Kartlegg som app: melding når du er uten nett, og veiledning under Om Kartlegg. */
.offline-note {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--ui-nav-height, 72px) + 20px + env(safe-area-inset-bottom));
  z-index: 95;
  margin: 0 auto;
  max-width: 560px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #1f3347;
  color: #fff;
  font-size: 14px;
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
@media(min-width:771px){
  .offline-note {
    bottom: 20px;
  }
}
.install-app {
  padding: 20px 24px;
}
.install-app h2 {
  margin: 0 0 8px;
}
.install-app p {
  margin: 0 0 10px;
  color: var(--ink);
  line-height: 1.6;
}
.install-app-how {
  font-weight: 650;
}
.install-app [hidden] {
  display: none !important;
}
