/* hidden-attributtet skal alltid vinne over display-regler (.icon-btn m.fl.). */
[hidden] { display: none !important; }

:root {
  --bg: #f6f4ef;
  --surface: #fffdf8;
  --surface-2: #f0ebe0;
  --text: #1d1a13;
  --muted: #6c6657;
  --brand: #d86f2f;
  --brand-strong: #bb5620;
  --danger: #9e1f1f;
  --ring: rgba(216, 111, 47, 0.28);
  --shadow: 0 14px 35px rgba(30, 20, 5, 0.12);
  --border-soft: rgba(59, 42, 12, 0.08);
  --line: #ece4d2;
  --line-strong: #ddd2bd;
  --hover: #fbf5e7;
  --field-bg: #fffdf8;
  --th-bg: #f2ecdd;
  --th-text: #4f452e;
  --thumb-bg: #ddd8cc;
  --chip: #efe8d8;
  --chip-text: #3e3117;
  --chip-active: #d9c8a2;
  --chip-active-text: #2f250f;
  --danger-bg: #f7d7d7;
  --detail-row: #f4eedf;
  --icon: #54451f;
  --icon-active-bg: #ffffff;
  --icon-active-text: #2d220d;
  --top-btn-border: #dac9a6;
  --top-btn-active: #efe2c7;
  --track: #d9d3c7;
  --track-border: #c8bea9;
  --knob: #fffdf9;
  --knob-border: #cab892;
  --track-on: #d8a468;
  --track-on-border: #c68b4d;
  --glow-a: #fff0cc;
  --glow-b: #ffe2cc;
  --shape-a: #f2cf84;
  --shape-b: #e89f7b;
  --badge-bg: #fef3c7;
  --badge-text: #92400e;
}

body[data-theme="dark"] {
  --bg: #15191d;
  --surface: #1e2429;
  --surface-2: #2a323a;
  --text: #f2efe8;
  --muted: #bcb6aa;
  --brand: #d77f45;
  --brand-strong: #bf6a32;
  --ring: rgba(215, 127, 69, 0.32);
  --shadow: 0 16px 30px rgba(0, 0, 0, 0.35);
  --danger: #f08c8c;
  --border-soft: rgba(255, 255, 255, 0.07);
  --line: #2c343b;
  --line-strong: #3a444d;
  --hover: #252c33;
  --field-bg: #15191d;
  --th-bg: #252c33;
  --th-text: #d6d0c4;
  --thumb-bg: #2a323a;
  --chip: #2a323a;
  --chip-text: #e8e2d6;
  --chip-active: #3d4750;
  --chip-active-text: #ffffff;
  --danger-bg: #3d2224;
  --detail-row: #252c33;
  --icon: #d6d0c4;
  --icon-active-bg: #3d4750;
  --icon-active-text: #ffffff;
  --top-btn-border: #3a444d;
  --top-btn-active: #333d46;
  --track: #34414a;
  --track-border: #4f5f6b;
  --knob: #e8e2d6;
  --knob-border: #9a948a;
  --track-on: #bf6a32;
  --track-on-border: #d77f45;
  --glow-a: rgba(215, 127, 69, 0.10);
  --glow-b: rgba(215, 127, 69, 0.07);
  --shape-a: #5a4020;
  --shape-b: #5a2f1f;
  --badge-bg: #4a3a12;
  --badge-text: #fcd58a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 500px at 0% -5%, var(--glow-a) 0, transparent 55%),
    radial-gradient(900px 500px at 100% -5%, var(--glow-b) 0, transparent 60%), var(--bg);
  min-height: 100vh;
}

.bg-shape {
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  filter: blur(40px);
  opacity: 0.32;
}

.bg-shape-a {
  width: 300px;
  height: 300px;
  background: var(--shape-a);
  top: 35%;
  left: -120px;
}

.bg-shape-b {
  width: 380px;
  height: 380px;
  background: var(--shape-b);
  top: 8%;
  right: -150px;
}

.container,
.topbar {
  width: min(1200px, calc(100% - 2rem));
  margin: 0 auto;
}

.topbar {
  padding: 2rem 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.3rem);
}

.topbar p {
  margin: 0.3rem 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 0.5rem;
}

.top-icon-btn {
  width: 48px;
  height: 48px;
  background: var(--surface);
  border: 2px solid var(--top-btn-border);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.top-icon-btn.active {
  background: var(--top-btn-active);
}

.top-icon-btn svg {
  width: 20px;
  height: 20px;
  stroke-width: 1.9;
}

.search-panel {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1rem;
  margin: 0.75rem 0 1.2rem;
}

.filters {
  display: grid;
  grid-template-columns: 1fr;
  grid-auto-flow: column;
  grid-auto-columns: 240px; /* tema- og statusfilter vises bare når de har innhold */
  gap: 0.7rem;
}
.filters [hidden] { display: none; }

.search-panel input,
.search-panel select {
  width: 100%;
  border: 2px solid transparent;
  border-radius: 12px;
  font-size: 1rem;
  padding: 0.8rem 0.95rem;
  background: var(--surface-2);
  color: var(--text);
}

.search-panel input:focus,
.search-panel select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--ring);
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.9rem;
}

.section-head h2,
.section-head h3 {
  margin: 0;
}

.section-tools {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.toggle-btn {
  border: 0;
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.18rem 0.3rem 0.18rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text);
}

.toggle-label {
  font-weight: 700;
  font-size: 0.92rem;
}

.toggle-track {
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--track);
  border: 1px solid var(--track-border);
  display: inline-flex;
  align-items: center;
  padding: 2px;
  transition: background 0.2s ease;
}

.toggle-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--knob);
  border: 1px solid var(--knob-border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.toggle-btn.active .toggle-track {
  background: var(--track-on);
  border-color: var(--track-on-border);
}

.toggle-btn.active .toggle-thumb {
  transform: translateX(20px);
}

.view-toggle {
  display: inline-flex;
  gap: 0.35rem;
  padding: 0.2rem;
  border-radius: 10px;
  background: var(--chip);
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--icon);
  cursor: pointer;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
}

.icon-btn.active {
  background: var(--icon-active-bg);
  color: var(--icon-active-text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.meta {
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 1rem;
  padding-bottom: 2.5rem;
}

.card {
  background: var(--surface);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow);
  animation: rise 0.35s ease both;
}

.grid.list-view {
  display: block;
  padding-bottom: 1.5rem;
}

.list-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.list-table th,
.list-table td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 0.35rem 0.5rem;
  font-size: 0.86rem;
  vertical-align: middle;
}

.list-table tr:last-child td {
  border-bottom: 0;
}

.list-row {
  cursor: pointer;
}

.list-row:hover td {
  background: var(--hover);
}

.list-table th {
  background: var(--th-bg);
  color: var(--th-text);
  font-weight: 700;
  white-space: nowrap;
}

.sort-btn {
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.list-thumb {
  width: 22px;
  height: 30px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--line-strong);
  cursor: zoom-in;
}

.list-actions {
  white-space: nowrap;
}

.list-actions .btn-small {
  padding: 0.24rem 0.45rem;
  font-size: 0.74rem;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card-thumb {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: var(--thumb-bg);
  cursor: zoom-in;
}

.card-body {
  padding: 0.75rem;
}

.card-title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.25;
}

.card-meta,
.card-theme {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.card-actions {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.65rem;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-small {
  padding: 0.43rem 0.62rem;
  font-size: 0.82rem;
}

.btn-primary {
  background: var(--brand);
  color: white;
}

.btn-primary:hover {
  background: var(--brand-strong);
}

.btn-ghost {
  background: var(--chip);
  color: var(--chip-text);
}

.btn-ghost.active {
  background: var(--chip-active);
  color: var(--chip-active-text);
}

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

.dialog {
  width: min(680px, calc(100% - 1.2rem));
  max-height: calc(100vh - 1.2rem);
  max-height: calc(100dvh - 1.2rem);
  border: none;
  border-radius: 16px;
  padding: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.dialog::backdrop {
  background: rgba(17, 11, 4, 0.34);
}

.dialog-content {
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--surface);
}

.dialog-content label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.dialog-content input,
.dialog-content textarea,
.dialog-content select {
  padding: 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  font-family: inherit;
}

.inline-field {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.inline-field > input {
  flex: 1 1 180px;
  min-width: 0;
}

.scan-container {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 4 / 3;
}

.scan-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scan-overlay {
  position: absolute;
  inset: 25% 8%;
  border: 2px solid rgba(255, 255, 255, 0.75);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.search-results {
  display: grid;
  gap: 0.5rem;
  max-height: 60vh;
  overflow-y: auto;
}

.search-result {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 0.7rem;
  padding: 0.6rem;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  align-items: center;
}

.search-result:hover {
  background: var(--hover);
}

.search-result img {
  width: 56px;
  height: 78px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--thumb-bg);
}

.search-result-meta {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
}

.search-result-meta strong {
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-meta .meta {
  font-size: 0.82rem;
}

.dialog-actions {
  margin-top: 0.3rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

.trash-list {
  display: grid;
  gap: 0.6rem;
}

.trash-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 0.7rem;
}

.trash-item p {
  margin: 0;
}

.detail-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 1rem;
}

.detail-image {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--thumb-bg);
}

.detail-meta {
  display: grid;
  gap: 0.4rem;
}

.detail-row {
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  background: var(--detail-row);
}

.row-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

@media (max-width: 800px) {
  .detail-layout {
    grid-template-columns: 1fr;
  }

  .filters {
    grid-template-columns: 1fr;
    grid-auto-flow: row;
  }
}

@media (max-width: 700px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }
}

@media (max-width: 600px) {
  .dialog {
    width: calc(100% - 0.6rem);
    max-height: calc(100vh - 0.6rem);
    max-height: calc(100dvh - 0.6rem);
    border-radius: 12px;
  }

  .dialog-content {
    padding: 0.85rem;
    gap: 0.55rem;
  }

  .dialog-content input,
  .dialog-content textarea,
  .dialog-content select {
    font-size: 16px;
  }

  .list-table {
    display: block;
    background: transparent;
    border: 0;
    box-shadow: none;
  }

  .list-table thead {
    display: none;
  }

  .list-table tbody {
    display: grid;
    gap: 0.5rem;
  }

  .list-table tr {
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr) auto;
    column-gap: 0.7rem;
    row-gap: 0.05rem;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    padding: 0.55rem 0.7rem;
    box-shadow: var(--shadow);
  }

  .list-table td {
    display: block;
    padding: 0;
    border: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.95rem;
  }

  .list-table td:nth-child(1) {
    grid-row: 1 / 4;
    grid-column: 1;
    align-self: center;
  }

  .list-table td:nth-child(2) {
    grid-row: 1;
    grid-column: 2;
    font-weight: 700;
    font-size: 1rem;
  }

  .list-table td:nth-child(3) {
    grid-row: 2;
    grid-column: 2;
    color: var(--muted);
    font-size: 0.85rem;
  }

  .list-table td:nth-child(4) {
    display: none;
  }

  .list-table td:nth-child(5) {
    grid-row: 3;
    grid-column: 2;
    color: var(--muted);
    font-size: 0.82rem;
    font-style: italic;
  }

  .list-table td:nth-child(6) {
    grid-row: 1 / 4;
    grid-column: 3;
    align-self: center;
  }

  .list-thumb {
    width: 42px;
    height: 58px;
  }

  .list-actions {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
  }

  .list-actions .btn-small {
    padding: 0.4rem 0.6rem;
    font-size: 0.82rem;
  }
}

/* ---------- samlinger, status og brukeradmin (2026-09-28) ---------- */
.collection-switch {
  margin-top: 0.4rem;
  max-width: 24rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.collection-switch[hidden] { display: none; }
.status-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--badge-text);
  vertical-align: middle;
}
.status-badge[hidden] { display: none; }
.load-more {
  display: block;
  margin: 1.5rem auto;
}
.detail-match {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(127, 127, 127, 0.25);
}
.candidate {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border-radius: 10px;
  background: rgba(127, 127, 127, 0.08);
}
.candidate-body {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}
.candidate-thumb {
  width: 64px;
  height: auto;
  border-radius: 4px;
}
.user-form {
  display: grid;
  gap: 0.6rem;
  margin: 1rem 0;
}
.user-form fieldset {
  border: 1px solid rgba(127, 127, 127, 0.3);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
}
.check,
.dialog-content label.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  color: var(--text);
}
.check input { width: auto; }
.row-actions { display: flex; gap: 0.4rem; }
.collection-list { margin: 0.25rem 0 0.75rem 1.1rem; }

/* Mobil: to kolonner, så en stor samling ikke blir én lang stripe av omslag. */
@media (max-width: 600px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
  }
}

.topbar .brand {
  margin: 0 0 0.15rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand-strong);
}

.invite-box {
  margin: 0.5rem 0 1rem;
  padding: 0.75rem;
  border-radius: 10px;
  background: rgba(216, 111, 47, 0.1);
}
.invite-box p { margin: 0 0 0.5rem; }
.invite-box input { flex: 1; min-width: 0; }

.toggle-label,
#resultCount { white-space: nowrap; }

/* Mobil: «Samling» på egen linje, verktøyene fordelt under. */
@media (max-width: 600px) {
  .section-head:has(.section-tools) {
    flex-wrap: wrap;
    gap: 0.6rem;
  }
  .section-tools {
    width: 100%;
    justify-content: space-between;
    gap: 0.4rem;
  }
  .section-tools .toggle-btn { padding-left: 0; }
  #resultCount { font-size: 0.85rem; }
}

/* Dialoger og skjemafelt: nettleserens standard er svart på hvitt, også i mørk modus. */
.dialog {
  background: var(--surface);
  color: var(--text);
}
.dialog-content input,
.dialog-content textarea,
.dialog-content select,
.row-form input {
  background: var(--field-bg);
  color: var(--text);
}
.dialog-content input::placeholder,
.search-panel input::placeholder { color: var(--muted); }
.list-table { color: var(--text); }
body { color-scheme: light; }
body[data-theme="dark"] { color-scheme: dark; }

/* Omslag i full størrelse. */
.image-viewer {
  width: 100vw;
  height: 100dvh;
  max-width: 100vw;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgba(0, 0, 0, 0.92);
  cursor: zoom-out;
}
.image-viewer[open] { display: grid; place-items: center; }
.image-viewer::backdrop { background: rgba(0, 0, 0, 0.92); }
.image-viewer img {
  width: 100%;
  height: 100dvh;
  object-fit: contain; /* små omslag (Google gir ofte ~130 px) skaleres opp til skjermen */
}
.detail-image { cursor: zoom-in; }

/* Mobil: dialogene fyller skjermen, og overskrift + Lukk ligger fast øverst mens man scroller. */
@media (max-width: 600px) {
  .dialog:not(.image-viewer) {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }
  .dialog:not(.image-viewer) .dialog-content {
    min-height: 100%;
    padding-top: 0;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    align-content: start;
  }
  .dialog-content > .section-head:first-child,
  .dialog-content > h3:first-of-type {
    position: sticky;
    top: 0;
    z-index: 2;
    margin: 0 -0.85rem;
    padding: calc(0.75rem + env(safe-area-inset-top)) 0.85rem 0.75rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
  }
}

/* =====================================================================
   Nytt oppsett 2026-09-30 (inspirert av ARK): appbar med søk og skanner,
   faner, forfatterkarusell, kort uten knapper, bokside med karuseller.
   ===================================================================== */
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.appbar {
  width: min(1200px, calc(100% - 2rem));
  margin: 0 auto;
  padding: calc(0.9rem + env(safe-area-inset-top)) 0 0.6rem;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.8rem 1rem;
}
.app-logo img { display: block; width: 44px; height: 44px; border-radius: 11px; }
.appbar-actions { justify-self: end; display: flex; gap: 0.4rem; }
.round-btn {
  position: relative;
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.round-btn:hover { background: var(--hover); }
.round-btn svg { width: 26px; height: 26px; }
.round-btn.on svg, .round-btn.fav.on svg { fill: var(--brand); stroke: var(--brand); }
.badge {
  position: absolute;
  right: 2px;
  bottom: 4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.7rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  background: var(--chip);
  color: var(--chip-text);
  font-size: 0.8rem;
  font-weight: 700;
}
.avatar.emoji { font-size: 1.25rem; background: transparent; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.1rem; }
.avatar-lg.emoji { font-size: 2.2rem; }

.searchbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0 0.4rem 0 0.9rem;
  height: 52px;
  border: 2px solid var(--brand);
  border-radius: 12px;
  background: var(--surface);
}
.searchbar:focus-within { box-shadow: 0 0 0 4px var(--ring); }
.searchbar-icon { width: 22px; height: 22px; color: var(--muted); flex: none; }
.searchbar input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
}
.searchbar input::placeholder { color: var(--muted); }
.searchbar-scan {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--brand);
  cursor: pointer;
}
.searchbar-scan:hover { background: var(--hover); }
.searchbar-scan svg { width: 28px; height: 28px; }

.tabs {
  width: min(1200px, calc(100% - 2rem));
  margin: 0.4rem auto 0.4rem;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0.2rem 0 0.6rem;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.tab svg { width: 17px; height: 17px; }
.tab.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.tab-count { font-size: 0.75rem; opacity: 0.8; }

/* Hyller og karuseller */
.shelf { margin: 0.6rem 0 1.6rem; }
.shelf-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.shelf-title { margin: 0 0 0.8rem; font-size: 1.35rem; line-height: 1.2; }
.scroller {
  display: flex;
  gap: 0.9rem;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding-bottom: 0.6rem;
  scrollbar-width: thin;
}
.scroller > * { scroll-snap-align: start; flex: none; }
.author {
  width: 92px;
  display: grid;
  justify-items: center;
  gap: 0.25rem;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: center;
}
.author-photo {
  width: 84px;
  height: 84px;
  border-radius: 999px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--chip);
  color: var(--chip-text);
  font-weight: 700;
  font-size: 1.4rem;
}
.author-photo img { width: 100%; height: 100%; object-fit: cover; }
.author-name { font-weight: 700; font-size: 0.85rem; line-height: 1.2; }
.author .meta { font-size: 0.75rem; }

.mini {
  width: 132px;
  display: grid;
  gap: 0.15rem;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.mini-cover {
  height: 176px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  overflow: hidden;
  margin-bottom: 0.35rem;
}
.mini-cover img { max-width: 100%; max-height: 100%; object-fit: contain; }
.mini-author { font-size: 0.75rem; color: var(--muted); }
.mini-title, .row-title, .card-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.mini-title { font-weight: 700; font-size: 0.85rem; line-height: 1.25; }
.mini-meta { font-size: 0.75rem; color: var(--muted); }

/* Liste-hode */
.list-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin: 0.3rem 0 0.9rem; }
.list-title { margin: 0; font-size: 1.35rem; }
.list-tools { display: flex; align-items: center; gap: 0.5rem; }
.chip-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 38px;
  padding: 0 0.8rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.chip-btn svg { width: 18px; height: 18px; }
.dot { width: 8px; height: 8px; border-radius: 999px; background: var(--brand); }
.icon-btn svg { width: 20px; height: 20px; }

/* Kort (rutenett) – ingen knapper, hele kortet åpner boka */
.grid:not(.list-view) { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 1.1rem 0.9rem; }
.card { cursor: pointer; border-radius: 14px; box-shadow: none; animation: none; }
.card:focus-visible { outline: 3px solid var(--ring); }
.card-cover { position: relative; background: var(--thumb-bg); aspect-ratio: 3 / 4; display: grid; place-items: center; overflow: hidden; }
.card-cover .card-thumb { width: 100%; height: 100%; aspect-ratio: auto; object-fit: cover; cursor: pointer; }
.card-body { padding: 0.6rem 0.7rem 0.75rem; display: grid; gap: 0.1rem; }
.card-author { margin: 0; font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-title { margin: 0; font-size: 0.9rem; line-height: 1.25; font-weight: 700; }
.card-meta { margin: 0.15rem 0 0; font-size: 0.78rem; color: var(--muted); }
.card .card-status { position: absolute; left: 0.5rem; top: 0.6rem; }
.fav-btn {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--muted);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}
.fav-btn svg { width: 19px; height: 19px; }
.fav-btn.on { color: var(--brand); }
.fav-btn.on svg { fill: var(--brand); }

/* Liste */
.grid.list-view, .grid.list-view:not(#x) { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.8rem; }
.row {
  position: relative;
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 0.9rem;
  padding: 0.8rem 3rem 0.8rem 0.8rem;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  cursor: pointer;
}
.row:focus-visible { outline: 3px solid var(--ring); }
.row-thumb { width: 92px; height: 124px; object-fit: contain; background: var(--thumb-bg); border-radius: 8px; }
.row-body { min-width: 0; display: grid; align-content: start; gap: 0.2rem; }
.row-title { margin: 0; font-size: 1rem; line-height: 1.25; }
.row-author { margin: 0; color: var(--muted); font-size: 0.88rem; }
.row-meta { margin: 0; font-size: 0.82rem; font-weight: 600; }
.row-desc { margin: 0.3rem 0 0; font-size: 0.85rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.row .fav-btn { top: 0.6rem; right: 0.6rem; box-shadow: none; background: transparent; }
.empty { color: var(--muted); padding: 2rem 0; }

/* Ark (profil, filter): nedtrekk fra toppen til høyre på PC, fullskjerm på mobil */
.sheet {
  width: min(420px, calc(100% - 1.2rem));
  margin: 4.5rem 1rem auto auto;
  max-height: calc(100dvh - 6rem);
  border: 0;
  border-radius: 16px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: auto;
}
.sheet::backdrop { background: rgba(17, 11, 4, 0.25); }
.sheet-content { display: grid; gap: 1rem; padding: 1rem 1.1rem 1.3rem; }
.sheet-content label { display: grid; gap: 0.3rem; font-size: 0.9rem; color: var(--muted); }
.sheet-content select { padding: 0.6rem; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--field-bg); color: var(--text); font: inherit; }
.sheet-head { display: flex; align-items: center; gap: 0.8rem; }
.sheet-head > div { flex: 1; min-width: 0; }
.menu-group { display: grid; gap: 0.15rem; border-top: 1px solid var(--line); padding-top: 0.8rem; }
.menu-label { margin: 0 0 0.3rem; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.menu-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0.7rem 0.6rem;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover { background: var(--hover); }
.menu-item.selected { background: var(--chip); }
.menu-item.selected::after { content: "✓"; color: var(--brand); margin-left: 0.5rem; }
.menu-item.danger { color: var(--danger); }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.3rem; padding: 0.25rem; border-radius: 12px; background: var(--chip); }
.segmented button { padding: 0.55rem 0.3rem; border: 0; border-radius: 9px; background: transparent; color: var(--chip-text); font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 0.3rem; }
.emoji-grid .emoji { aspect-ratio: 1; border: 0; border-radius: 10px; background: transparent; font-size: 1.35rem; cursor: pointer; }
.emoji-grid .emoji:hover { background: var(--hover); }
.emoji-grid .emoji.selected { background: var(--chip-active); }

/* Boksiden: egen «side» over forsiden */
.page {
  width: min(760px, 100%);
  height: min(100dvh, 100%);
  max-width: 100%;
  max-height: 100dvh;
  margin: 0 auto;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--text);
  overflow: auto;
}
.page::backdrop { background: rgba(17, 11, 4, 0.45); }
.page-bar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 0.5rem;
  padding: calc(0.4rem + env(safe-area-inset-top)) 0.6rem 0.4rem;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.page-bar-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
/* minmax(0, 1fr): ellers gjør karusellene (lange flex-rader) hele siden bredere enn skjermen. */
.page-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.9rem; padding: 1rem 1rem calc(2rem + env(safe-area-inset-bottom)); }
.shelf, .scroller { min-width: 0; }
.page-loading { padding: 3rem 0; text-align: center; }
.book-hero { margin: 0; display: grid; justify-items: center; gap: 0.4rem; }
.book-hero img {
  max-width: min(100%, 420px);
  max-height: 62dvh;
  border-radius: 6px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
  cursor: zoom-in;
}
.book-hero.no-cover img { box-shadow: none; max-height: 40dvh; cursor: default; }
.title-card { padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.title-card h1 { margin: 0 0 0.35rem; font-size: 1.55rem; line-height: 1.2; }
.byline { margin: 0; color: var(--muted); }
.link { border: 0; padding: 0; background: none; color: var(--brand-strong); font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
body[data-theme="dark"] .link { color: var(--brand); }
.panel { padding: 1rem 1.1rem; border-radius: 14px; background: var(--surface); border: 1px solid var(--border-soft); }
.panel p { margin: 0; line-height: 1.55; }
.panel-title { margin: 0 0 0.6rem; font-size: 1.05rem; }
.desc-text { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.panel.expanded .desc-text { -webkit-line-clamp: unset; display: block; }
.desc-more { margin-top: 0.5rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.8rem 1rem; }
.fact { display: grid; gap: 0.1rem; }
.fact-wide { grid-column: 1 / -1; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.8rem; }
.fact-label { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.fact-value { font-weight: 600; }
.meter { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; }
.meter i { height: 8px; border-radius: 3px; background: var(--line-strong); }
.meter i.on { background: var(--brand); }
.awards { margin: 0; padding-left: 1.1rem; display: grid; gap: 0.3rem; }
.more-info summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; justify-content: space-between; }
.more-info summary::-webkit-details-marker { display: none; }
.more-info summary::after { content: "›"; transform: rotate(90deg); transition: transform 0.2s; color: var(--muted); }
.more-info[open] summary::after { transform: rotate(-90deg); }
.more-info[open] summary { margin-bottom: 0.6rem; }
.info-row { display: grid; grid-template-columns: 8.5rem 1fr; gap: 0.8rem; padding: 0.45rem 0; border-top: 1px solid var(--line); font-size: 0.9rem; }
.info-row span:first-child { color: var(--muted); }
.info-row span:last-child { overflow-wrap: anywhere; }
.page-actions { display: flex; justify-content: flex-end; gap: 0.6rem; padding-top: 0.5rem; }
.page .shelf { margin: 0.4rem 0 0.2rem; }
.page .shelf-title { font-size: 1.2rem; }

@media (max-width: 600px) {
  .appbar, .tabs { width: calc(100% - 1.6rem); }
  .grid:not(.list-view) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 0.7rem; }
  .sheet { width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  .sheet-content { padding-top: calc(1rem + env(safe-area-inset-top)); }
  .page { width: 100%; height: 100dvh; }
  .row { grid-template-columns: 76px 1fr; }
  .row-thumb { width: 76px; height: 104px; }
  .list-title { font-size: 1.2rem; }
  .shelf-title { font-size: 1.2rem; }
}
.row-body .status-badge { justify-self: start; }

.desc-source { margin-top: 0.6rem !important; font-size: 0.78rem; }
.subjects { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.subject { padding: 0.35rem 0.75rem; border-radius: 999px; border: 1px solid var(--line-strong); font-size: 0.82rem; font-weight: 600; color: var(--chip-text); background: var(--surface); }

.avatar-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.6rem; }
.file-btn { cursor: pointer; display: inline-flex; align-items: center; }
.gravatar-form { display: flex; gap: 0.5rem; }
.gravatar-form input { flex: 1; min-width: 0; padding: 0.55rem; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--field-bg); color: var(--text); font: inherit; }
.meta.small { font-size: 0.75rem; margin: 0.3rem 0 0.6rem; }

/* ---------- AI-forbedring av omslag ---------- */
.book-hero img { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
.menu-item [id="coverMenuHint"] { font-weight: 400; }
.enhance { width: min(980px, 100%); }
.enhance-wait { display: grid; justify-items: center; gap: 0.8rem; text-align: center; padding: 1rem 0 2rem; }
.enhance-lead { font-size: 1.2rem; font-weight: 700; margin: 0; }
.enhance-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; text-align: left; }
.enhance-steps li { display: flex; align-items: center; gap: 0.6rem; color: var(--muted); }
.enhance-steps li.done { color: var(--text); }
.enhance-steps li.done .spinner { animation: none; border-color: var(--brand); background: var(--brand); }
.enhance-steps li.failed .spinner { animation: none; border-color: var(--danger); }
.spinner { width: 16px; height: 16px; flex: none; border-radius: 999px; border: 2.5px solid var(--line-strong); border-top-color: var(--brand); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.enhance-warning { margin: 0; padding: 0.7rem 0.9rem; border-radius: 10px; background: var(--badge-bg); color: var(--badge-text); font-size: 0.9rem; font-weight: 600; }
.variants { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-top: 1rem; }
.variant { margin: 0; display: grid; gap: 0.6rem; align-content: start; padding: 0.8rem; border-radius: 14px; background: var(--surface); border: 1px solid var(--border-soft); }
.variant img { width: 100%; max-height: 60dvh; object-fit: contain; background: var(--thumb-bg); border-radius: 8px; }
.variant figcaption { display: grid; gap: 0.35rem; }
.check { font-size: 0.82rem; font-weight: 600; }
.check.ok { color: #2f7d32; }
.check.warn { color: var(--danger); }
body[data-theme="dark"] .check.ok { color: #7fcf86; }

/* Kokkemusen som baker mens AI-en jobber */
.chef { width: 220px; height: 200px; }
.chef .fur { fill: #b9b2a8; stroke: none; }
.chef .belly { fill: #e7e1d8; stroke: none; }
.chef .ear { fill: #efb3a8; stroke: none; }
.chef .eye { fill: #2b241c; stroke: none; }
.chef .glint { fill: #fff; stroke: none; }
.chef .nose { fill: #d9776a; stroke: none; }
.chef .whisker { stroke: #6f675d; stroke-width: 1.4; }
.chef .hat { fill: #fff; stroke: #d7cfc2; stroke-width: 1.5; }
.chef .hat-band { fill: #f3eee6; stroke: #d7cfc2; stroke-width: 1.5; }
.chef .tail { stroke: #b9b2a8; stroke-width: 6; }
.chef .arm { stroke: #b9b2a8; stroke-width: 9; }
.chef .bowl { fill: var(--brand); stroke: none; }
.chef .batter { fill: #f6e3b4; stroke: none; }
.chef .shadow { fill: rgba(0, 0, 0, 0.12); stroke: none; }
.chef .whisk-handle { stroke: #7a5a3a; stroke-width: 6; }
.chef .whisk-wire { stroke: #9aa3ab; stroke-width: 2.2; }
.chef .steam path { stroke: var(--muted); stroke-width: 3; opacity: 0; animation: steam 2.4s ease-in-out infinite; }
.chef .steam path:nth-child(2) { animation-delay: 0.8s; }
.chef .steam path:nth-child(3) { animation-delay: 1.6s; }
.chef .flour circle { fill: #f3ead6; stroke: none; animation: flour 1.6s ease-out infinite; }
.chef .flour circle:nth-child(2) { animation-delay: 0.5s; }
.chef .flour circle:nth-child(3) { animation-delay: 1s; }
.chef .whisk { transform-origin: 168px 118px; animation: whisk 0.5s ease-in-out infinite alternate; }
.chef .head { transform-origin: 78px 110px; animation: bob 1s ease-in-out infinite alternate; }
.chef .tail { transform-origin: 44px 150px; animation: wag 1.2s ease-in-out infinite alternate; }
@keyframes whisk { from { transform: rotate(-12deg); } to { transform: rotate(14deg); } }
@keyframes bob { from { transform: rotate(-3deg) translateY(0); } to { transform: rotate(3deg) translateY(2px); } }
@keyframes wag { from { transform: rotate(-8deg); } to { transform: rotate(10deg); } }
@keyframes steam { 0% { opacity: 0; transform: translateY(8px); } 40% { opacity: 0.8; } 100% { opacity: 0; transform: translateY(-14px); } }
@keyframes flour { 0% { opacity: 0.9; transform: translate(0, 0); } 100% { opacity: 0; transform: translate(6px, -18px); } }
@media (prefers-reduced-motion: reduce) { .chef * { animation: none !important; } }

/* ---------- Profilsiden (samme prinsipper som boksiden) ---------- */
.appbar .round-btn { width: 48px; height: 48px; }
.appbar .avatar { width: 38px; height: 38px; font-size: 0.9rem; }
.appbar .avatar.emoji { font-size: 1.5rem; }
.profile { width: min(640px, 100%); }
.profile-hero { display: grid; justify-items: center; gap: 0.3rem; text-align: center; padding: 0.6rem 0 0.2rem; }
.profile-hero h1 { margin: 0.4rem 0 0; font-size: 1.5rem; }
.profile-photo { position: relative; cursor: pointer; }
.avatar-xl { width: 112px; height: 112px; font-size: 2.2rem; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18); }
.avatar-xl.emoji { font-size: 4rem; background: var(--chip); }
.photo-edit { position: absolute; right: 2px; bottom: 2px; width: 34px; height: 34px; border-radius: 999px; display: grid; place-items: center; background: var(--brand); color: #fff; border: 3px solid var(--bg); }
.photo-edit svg { width: 17px; height: 17px; }
.collection-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.8rem; }
.collection-card { display: grid; gap: 0.5rem; padding: 0.55rem; border-radius: 14px; border: 2px solid var(--line); background: var(--bg); color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.collection-card:hover { border-color: var(--line-strong); }
.collection-card.selected { border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.mosaic { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; aspect-ratio: 1; border-radius: 9px; overflow: hidden; background: var(--thumb-bg); }
.mosaic img, .mosaic span { width: 100%; height: 100%; object-fit: cover; background: var(--chip); }
.cc-text { display: grid; gap: 0.1rem; }
.cc-name { font-weight: 700; font-size: 0.92rem; line-height: 1.25; }
.cc-selected { color: var(--brand-strong); }
body[data-theme="dark"] .cc-selected { color: var(--brand); }
.switch-row { display: flex !important; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.6rem 0; border-top: 1px solid var(--line); cursor: pointer; }
.switch-row > span { display: grid; gap: 0.15rem; }
.switch { appearance: none; width: 50px; height: 30px; flex: none; border-radius: 999px; background: var(--track); border: 1px solid var(--track-border); position: relative; cursor: pointer; transition: background 0.2s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 999px; background: var(--knob); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.2s; }
.switch:checked { background: var(--brand); border-color: var(--brand); }
.switch:checked::after { transform: translateX(20px); }
.emoji-label { margin-top: 0.8rem !important; }
.menu-panel { padding: 0.4rem; display: grid; }
.menu-panel .menu-item { padding: 0.85rem 0.7rem; }
.chev { color: var(--muted); font-size: 1.2rem; }

/* Liten popup-meny midt på skjermen (langt trykk / høyreklikk på omslaget). */
.popover-menu {
  width: min(320px, calc(100% - 2.5rem));
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.popover-menu::backdrop { background: rgba(17, 11, 4, 0.35); }
.popover-menu[open] { animation: pop-in 0.16s ease-out; }
@keyframes pop-in { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: none; } }
.popover-content { display: grid; padding: 0.5rem; }
.popover-title { margin: 0.4rem 0.7rem 0.3rem; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.popover-content .menu-item { padding: 0.85rem 0.7rem; justify-content: flex-start; gap: 0.3rem; flex-wrap: wrap; }
.popover-content .menu-item + .menu-item { border-top: 1px solid var(--line); border-radius: 0; }
.popover-content [data-cover="close"] { color: var(--muted); justify-content: center; }

/* ---------- Søkekryss, pluss-knapp og «legg til»-valg ---------- */
.searchbar-clear { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 999px; background: transparent; color: var(--muted); cursor: pointer; flex: none; }
.searchbar-clear svg { width: 22px; height: 22px; }
.searchbar input::-webkit-search-cancel-button { display: none; }
.fab {
  position: fixed;
  right: calc(1.1rem + env(safe-area-inset-right));
  bottom: calc(1.1rem + env(safe-area-inset-bottom));
  z-index: 20;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
  cursor: pointer;
}
.fab svg { width: 30px; height: 30px; stroke-width: 2.4; }
.fab:active { transform: scale(0.95); }
.add-sheet { width: min(380px, calc(100% - 2rem)); }
.add-option { display: grid; grid-template-columns: 44px 1fr; gap: 0.8rem; align-items: center; width: 100%; padding: 0.75rem 0.6rem; border: 0; border-radius: 12px; background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.add-option:hover { background: var(--hover); }
.add-option > span:nth-child(2) { display: grid; gap: 0.1rem; }
.add-option .meta { font-size: 0.8rem; }
.add-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand-strong); }
body[data-theme="dark"] .add-icon { color: var(--brand); }
.add-icon svg { width: 24px; height: 24px; }

/* ---------- Bokskjemaet som egen side ---------- */
.book-form-page { width: min(680px, 100%); }
.book-form-page form { display: contents; }
.page-footer {
  position: sticky;
  bottom: 0;
  z-index: 3;
  padding: 0.8rem 1rem calc(0.8rem + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  border-top: 1px solid var(--line);
}
.big-btn { width: 100%; padding: 0.95rem 1rem; font-size: 1rem; border-radius: 12px; display: flex; justify-content: center; align-items: center; cursor: pointer; }
.big-btn:disabled { opacity: 0.5; cursor: default; }
.form-status { margin: 0; padding: 0.75rem 0.9rem; border-radius: 12px; font-weight: 600; font-size: 0.92rem; line-height: 1.4; }
.form-status.ok { background: color-mix(in srgb, #2f7d32 14%, transparent); color: #235f26; }
body[data-theme="dark"] .form-status.ok { color: #9fe0a4; }
.form-status.warn { background: var(--badge-bg); color: var(--badge-text); }
.form-status.working { background: var(--chip); color: var(--chip-text); }
.form-cover { display: grid; grid-template-columns: 120px 1fr; gap: 1rem; align-items: center; }
.form-cover img { width: 120px; height: 160px; object-fit: cover; border-radius: 8px; background: var(--thumb-bg); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15); }
.form-cover-actions { display: grid; gap: 0.6rem; justify-items: start; }
.form-cover-actions .btn { cursor: pointer; }
.form-panel { display: grid; gap: 0.9rem; }
.field { display: grid; gap: 0.35rem; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.03em; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 0.75rem 0.8rem;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--field-bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.field input[type="range"] { padding: 0; border: 0; box-shadow: none; accent-color: var(--brand); background: transparent; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.inline-field { display: flex; gap: 0.4rem; align-items: stretch; }
.inline-field input { flex: 1; min-width: 0; }
.inline-field .btn { white-space: nowrap; }
.icon-only { display: grid; place-items: center; padding: 0 0.6rem; }
.icon-only svg { width: 20px; height: 20px; }
.advanced summary { cursor: pointer; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.advanced[open] summary { margin-bottom: 0.6rem; }

/* ---------- Batch: mange bøker på rad ---------- */
.batch { width: min(720px, 100%); }
.batch-intro p { margin: 0 0 0.9rem; }
.batch-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.batch-summary { margin: 0; font-weight: 600; }
.batch-list { display: grid; gap: 0.6rem; }
.batch-item { display: grid; grid-template-columns: 64px 1fr auto; gap: 0.8rem; align-items: center; padding: 0.6rem; border-radius: 12px; background: var(--surface); border: 1px solid var(--border-soft); }
.batch-item.added { opacity: 0.6; }
.batch-item img { width: 64px; height: 84px; object-fit: cover; border-radius: 6px; background: var(--thumb-bg); }
.batch-body { display: grid; gap: 0.15rem; min-width: 0; }
.batch-body strong { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.batch-body .link { justify-self: start; font-size: 0.85rem; margin-top: 0.2rem; }
.batch-status { justify-self: start; font-size: 0.72rem; font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 999px; background: var(--chip); color: var(--chip-text); }
.batch-status.ok { background: color-mix(in srgb, #2f7d32 16%, transparent); color: #235f26; }
body[data-theme="dark"] .batch-status.ok { color: #9fe0a4; }
.batch-status.warn { background: var(--badge-bg); color: var(--badge-text); }
.batch-status.busy { background: var(--chip); color: var(--chip-text); animation: pulse 1.2s ease-in-out infinite; }
.batch-status.muted { color: var(--muted); }
@keyframes pulse { 50% { opacity: 0.5; } }
@media (max-width: 600px) { .field-row { grid-template-columns: 1fr 1fr; } .form-cover { grid-template-columns: 96px 1fr; } .form-cover img { width: 96px; height: 128px; } }

.form-candidates { display: grid; gap: 0.4rem; }
.form-candidates .meta { margin: 0; }
.cand { display: grid; grid-template-columns: auto 1fr; gap: 0.8rem; align-items: center; padding: 0.7rem; border-radius: 12px; border: 1px dashed var(--line-strong); background: var(--surface); color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.cand img { width: 52px; height: 70px; object-fit: cover; border-radius: 5px; }
.cand > span { display: grid; gap: 0.15rem; }
.cand.selected { border: 2px solid var(--brand); }

.load-error { display: grid; gap: 0.6rem; justify-items: start; margin-top: 1rem; }

.photo-switch { border-top: 0 !important; padding: 0.2rem 0 !important; width: 100%; }
.form-cover-actions { width: 100%; }
@media (max-width: 600px) { .form-cover { grid-template-columns: 96px 1fr; align-items: start; } }

/* Bryter i filterarket: tekst til venstre, bryter til høyre (arket stabler ellers labels som grid). */
.sheet-content .filter-switch { display: flex !important; color: var(--text); font-size: 0.95rem; }
.sheet-content .filter-switch strong { font-weight: 600; }
.switch:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

/* ---------- Tøyinnbinding: bøker uten omslag ----------
   Stoff med vevstruktur, ryggfals til venstre, blindpreget ramme, påklistret papiretikett og
   årstall i gullpreg. Etiketten er et fysisk papir og har samme farge i lys og mørk modus. */
.binding {
  --cloth: #6e2a26; --gilt: #e2c98d;
  container-type: inline-size;
  position: relative; box-sizing: border-box; display: grid; place-items: center;
  width: 100%; height: 100%; padding: 12% 9% 16% 15%;
  border-radius: 2px 4px 4px 2px; overflow: hidden;
  background:
    linear-gradient(90deg, rgba(0,0,0,.34) 0, rgba(0,0,0,.12) 4.5%, rgba(255,255,255,.10) 6%, rgba(0,0,0,.06) 8%, transparent 12%),
    radial-gradient(120% 90% at 70% 20%, rgba(255,255,255,.09), transparent 60%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.045) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0,0,0,.07) 0 1px, transparent 1px 2px),
    var(--cloth);
  color: #2a2418; text-align: center; user-select: none;
}
.binding::before { content: ""; position: absolute; inset: 5% 6% 5% 12%; border: 1px solid rgba(255,255,255,.16); box-shadow: inset 0 0 0 3px rgba(0,0,0,.06); border-radius: 1px; pointer-events: none; }
.binding[data-cloth="oksblod"]     { --cloth: #6e2a26; }
.binding[data-cloth="flaskegronn"] { --cloth: #2f4a3a; }
.binding[data-cloth="marine"]      { --cloth: #26364f; }
.binding[data-cloth="sennep"]      { --cloth: #9c7a2c; --gilt: #3a2a0c; }
.binding[data-cloth="terrakotta"]  { --cloth: #9a4f2e; }
.binding[data-cloth="skifer"]      { --cloth: #4a5560; }
.binding[data-cloth="plomme"]      { --cloth: #523046; }
.binding[data-cloth="oliven"]      { --cloth: #5b5a2f; }
.binding-label {
  display: grid; gap: 0.35em; max-width: 100%; box-sizing: border-box;
  padding: 0.75em 0.7em; border-radius: 1.5px;
  background: linear-gradient(180deg, #f6eedc, #eee3c8);
  box-shadow: 0 1px 1.5px rgba(0,0,0,.35), 0 3px 8px rgba(0,0,0,.18), inset 0 0 0 1px rgba(90,60,20,.18), inset 0 0 0 3.5px #f3ead5, inset 0 0 0 4.5px rgba(90,60,20,.28);
}
.binding-title {
  font-weight: 800; font-size: clamp(0.62rem, 9.5cqi, 1.6rem); line-height: 1.12; letter-spacing: -0.005em;
  hyphens: auto; overflow-wrap: anywhere; text-wrap: balance;
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden;
}
.binding-author { font-size: clamp(0.6rem, 5.2cqi, 0.95rem); font-weight: 600; color: #5d513b; text-wrap: balance; }
.binding-year {
  position: absolute; left: 12%; right: 6%; bottom: 6%;
  font-size: clamp(0.55rem, 6.5cqi, 1rem); font-weight: 700; letter-spacing: 0.14em; color: var(--gilt);
  text-shadow: 0 -1px 0 rgba(0,0,0,.35), 0 1px 0 rgba(255,255,255,.12);
}
body[data-theme="dark"] .binding-label { filter: brightness(0.93); }
.card-cover .binding { cursor: pointer; }
.binding-mini { height: 100%; width: auto; aspect-ratio: 3 / 4; }
.binding-row { width: 100%; height: auto; aspect-ratio: 92 / 124; align-self: start; border-radius: 3px 6px 6px 3px; padding: 10% 8% 15% 14%; }
.binding-row .binding-title { -webkit-line-clamp: 4; }
.binding-hero { width: min(100%, 300px); height: auto; aspect-ratio: 3 / 4; box-shadow: 0 18px 40px rgba(0,0,0,.22); }
.binding-hero .binding-label { padding: 1.1em 1em; }
/* Små innbindinger (liste, hyller): mindre skrift og ingen orddeling – «Ham-lets» leses dårlig. */
.binding-row, .binding-mini { padding: 9% 7% 16% 13%; }
.binding-row .binding-label, .binding-mini .binding-label { padding: 0.45em 0.35em; }
.binding-row .binding-title, .binding-mini .binding-title { hyphens: manual; overflow-wrap: break-word; max-width: 100%; font-size: clamp(0.5rem, 9cqi, 0.78rem); -webkit-line-clamp: 4; }

/* ---------- Dialoger og meldinger (erstatter alert/confirm) ---------- */
.ask { width: min(440px, calc(100% - 2rem)); border: 0; border-radius: 16px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.ask::backdrop { background: rgba(17, 11, 4, 0.35); }
.ask-body { display: grid; gap: 0.9rem; padding: 1.4rem 1.3rem 1.2rem; margin: 0; }
.ask-body h2 { margin: 0; font-size: 1.2rem; line-height: 1.3; text-wrap: balance; }
.ask-text { margin: 0; color: var(--muted); line-height: 1.5; }
.ask-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; margin-top: 0.4rem; }
.ask-actions .btn { min-height: 44px; padding: 0.6rem 1rem; font: inherit; font-weight: 700; }
@media (max-width: 600px) { .ask-actions { flex-direction: column-reverse; } .ask-actions .btn { width: 100%; } }
.dup-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.dup-book { margin: 0; display: grid; gap: 0.45rem; align-content: start; }
.dup-cover { display: grid; place-items: center; height: 168px; border-radius: 10px; background: var(--thumb-bg); overflow: hidden; }
.dup-cover img { max-width: 100%; max-height: 100%; object-fit: contain; }
.dup-book figcaption { display: grid; gap: 0.1rem; font-size: 0.85rem; line-height: 1.3; }
.dup-book figcaption span { color: var(--muted); }
.dup-label { font-size: 0.75rem; font-weight: 700; color: var(--muted); }

.toasts { position: fixed; z-index: 2147483000; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(460px, calc(100% - 1.5rem)); display: grid; gap: 0.5rem; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 0.6rem; padding: 0.7rem 0.6rem 0.7rem 1rem; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); font-size: 0.95rem; line-height: 1.35; animation: toast-in 0.22s cubic-bezier(0.2, 0.8, 0.2, 1); }
.toast-error { background: var(--danger-bg); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }
.toast-text { flex: 1; min-width: 0; }
.toast-action { border: 0; background: transparent; color: inherit; font: inherit; font-weight: 800; text-decoration: underline; text-underline-offset: 3px; min-height: 40px; padding: 0 0.6rem; cursor: pointer; }
.toast-close { border: 0; background: transparent; color: inherit; opacity: 0.7; width: 36px; height: 36px; border-radius: 999px; cursor: pointer; font-size: 0.9rem; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity 0.18s, transform 0.18s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }
[aria-invalid="true"] { border-color: var(--danger) !important; box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 25%, transparent) !important; }

/* ---------- Polish: kontrast, fokus og trykkflater ---------- */
/* Hvit tekst på Kobberkjele (#d86f2f) ga 3,4:1. Fylte knapper bruker en dypere kobber (4,7:1);
   i mørk modus mørk tekst på lys kobber (5,8:1). --brand er fortsatt aksentfargen ellers. */
:root { --brand-fill: #bb5620; --brand-fill-hover: #a64b1a; --on-brand: #ffffff; }
body[data-theme="dark"] { --brand-fill: #d77f45; --brand-fill-hover: #e2915c; --on-brand: #1d1a13; }
.btn-primary { background: var(--brand-fill); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-fill-hover); }
.fab, .photo-edit { background: var(--brand-fill); color: var(--on-brand); }
.invite-box { background: color-mix(in srgb, var(--brand) 10%, transparent); }
:where(button, a, [role="button"], summary, .switch, .card, .row):focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn-primary:focus-visible, .fab:focus-visible { outline-color: var(--text); }
@media (pointer: coarse) {
  .icon-btn { width: 44px; height: 44px; }
  .chip-btn { height: 44px; }
  .fav-btn { width: 40px; height: 40px; }
  .segmented button { min-height: 44px; }
}

/* ---------- Les boka ---------- */
.read-panel { display: grid; gap: 0.7rem; }
.read-lead { margin: 0; line-height: 1.5; }
.read-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.read-actions .btn { min-height: 44px; display: inline-flex; align-items: center; text-decoration: none; font: inherit; font-weight: 700; padding: 0.55rem 1rem; }
.read-links { margin: 0; padding: 0; list-style: none; display: grid; gap: 0.35rem; }
.read-links a { color: var(--text); text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--brand) 60%, transparent); }
.read-toc summary { cursor: pointer; font-weight: 600; }
.read-toc p { margin: 0.5rem 0 0; color: var(--muted); line-height: 1.55; white-space: pre-line; }

.reader .reader-body { max-width: 46rem; margin: 0 auto; width: 100%; box-sizing: border-box; }
.reader-count { margin-left: auto; font-size: 0.85rem; white-space: nowrap; }
.reader-search { display: block; position: sticky; top: 0; z-index: 2; padding: 0.6rem 0; background: var(--bg); }
.reader-search input { width: 100%; box-sizing: border-box; font: inherit; font-size: 1rem; padding: 0.8rem 1rem; border-radius: 12px; border: 2px solid transparent; background: var(--surface-2); color: var(--text); }
.reader-search input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--ring); }
.reader-hits { display: grid; gap: 0.4rem; margin: 0.4rem 0 1rem; }
.reader-hit { display: grid; grid-template-columns: 3.5rem 1fr; gap: 0.6rem; text-align: left; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; font-size: 0.92rem; line-height: 1.45; padding: 0.6rem 0.75rem; cursor: pointer; }
.reader-hit:hover { background: var(--hover); }
.reader-hit-page { font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.reader-page { padding: 1.2rem 0; border-bottom: 1px solid var(--line); }
.reader-page-no { margin: 0 0 0.6rem; font-size: 0.8rem; font-weight: 700; color: var(--muted); letter-spacing: 0.04em; }
.reader-page p { margin: 0; font-size: 1.02rem; line-height: 1.7; overflow-wrap: anywhere; }
.reader mark, .text-hits mark { background: color-mix(in srgb, var(--brand) 28%, transparent); color: inherit; border-radius: 3px; padding: 0 0.1em; }
.reader-more { display: block; margin: 1.2rem auto 2rem; min-height: 44px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.text-hits { margin: 0 0 1.4rem; }
.text-hits-title { margin: 0 0 0.6rem; font-size: 1.1rem; display: flex; gap: 0.5rem; align-items: baseline; }
.text-hits-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 0.6rem; }
.text-hit { display: grid; grid-template-columns: 54px 1fr; gap: 0.75rem; align-items: start; text-align: left; padding: 0.6rem; border: 1px solid var(--border-soft); border-radius: 12px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.text-hit:hover { background: var(--hover); }
.text-hit.extra { display: none; }
.text-hits.all .text-hit.extra { display: grid; }
.text-hit-cover { width: 54px; height: 72px; display: grid; place-items: center; overflow: hidden; border-radius: 4px; background: var(--thumb-bg); }
.text-hit-cover img { width: 100%; height: 100%; object-fit: cover; }
.text-hit-body { display: grid; gap: 0.2rem; min-width: 0; font-size: 0.9rem; line-height: 1.4; }
.text-hit-snip { color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.text-hits-all { margin-top: 0.6rem; }

.reader .page-bar-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader .reader-count { flex: none; padding-right: 0.25rem; }

/* ---------- Den digitale boka ---------- */
.excerpt { margin: 0.2rem 0 0; display: grid; gap: 0.35rem; }
.excerpt blockquote { margin: 0; padding: 0.2rem 0 0.2rem 1rem; border-left: 1px solid var(--line-strong); font-size: 0.98rem; line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.excerpt-more { justify-self: start; }
.book-viewer { display: none; }
.book-viewer[open] { display: grid; grid-template-rows: auto auto 1fr auto; height: 100dvh; max-height: 100dvh; }
.bv-bar { gap: 0.5rem; }
.bv-bar .page-bar-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bv-mode button { min-height: 36px; padding: 0 0.8rem; }
.bv-mode[hidden] { display: none; }
.bv-search { padding: 0.6rem 1rem 0.4rem; border-bottom: 1px solid var(--line); max-height: 45dvh; overflow: auto; background: var(--bg); }
.bv-search input { width: 100%; box-sizing: border-box; font: inherit; font-size: 1rem; padding: 0.75rem 1rem; border-radius: 12px; border: 2px solid transparent; background: var(--surface-2); color: var(--text); }
.bv-search input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--ring); }
.bv-hits { display: grid; gap: 0.4rem; margin-top: 0.5rem; }
.bv-stage { overflow: auto; display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; align-content: start; gap: 1rem; padding: 1rem; background: var(--surface-2); }
.bv-stage.two { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.bv-page { margin: 0; width: 100%; max-width: 720px; display: grid; gap: 0.4rem; justify-items: center; }
.bv-page img { width: 100%; height: auto; max-height: calc(100dvh - 11rem); object-fit: contain; background: #fffdf8; border-radius: 3px; box-shadow: 0 10px 30px rgba(30, 20, 5, 0.18); }
.bv-text { box-sizing: border-box; width: 100%; min-height: 50dvh; padding: 1.6rem 1.5rem; background: var(--surface); border-radius: 6px; box-shadow: 0 10px 30px rgba(30, 20, 5, 0.12);
  font-size: 1.02rem; line-height: 1.7; overflow-wrap: anywhere; max-width: 40rem; }
.bv-loading { padding: 3rem 1rem; }
.bv-nav { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 0.6rem; padding: 0.6rem 1rem calc(0.6rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
.bv-nav .round-btn[disabled] { opacity: 0.35; cursor: default; }
.bv-slider { width: 100%; accent-color: var(--brand-fill); min-height: 44px; }
.bv-jump { display: flex; align-items: center; gap: 0.35rem; }
.bv-jump-input { width: 3.6rem; text-align: center; font: inherit; font-variant-numeric: tabular-nums; padding: 0.45rem 0.3rem; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--field-bg); color: var(--text); }
.bv-of { white-space: nowrap; font-variant-numeric: tabular-nums; }
.book-viewer mark { background: color-mix(in srgb, var(--brand) 30%, transparent); color: inherit; border-radius: 3px; padding: 0 0.1em; }
@media (max-width: 600px) {
  .bv-nav { grid-template-columns: auto 1fr auto; grid-template-areas: "prev jump next" "slider slider slider"; row-gap: 0.2rem; }
  .bv-nav [data-v="prev"] { grid-area: prev; } .bv-nav [data-v="next"] { grid-area: next; }
  .bv-jump { grid-area: jump; justify-self: center; } .bv-slider { grid-area: slider; }
  .bv-stage { padding: 0.6rem; }
  .bv-text { padding: 1.2rem 1.1rem; }
}

.book-viewer .bv-bar { display: flex; align-items: center; gap: 0.4rem; }
.book-viewer .bv-bar .round-btn { flex: none; }
.bv-mode { flex: none; display: inline-flex; }
.bv-mode button { font-size: 0.82rem; padding: 0 0.6rem; }
@media (max-width: 420px) { .bv-bar .page-bar-title { font-size: 0.95rem; } }
/* Leseren: tittelen deler plass med knappene (ikke sentrert oppå dem), og navigasjonen får plass på smal skjerm. */
.book-viewer .bv-bar .page-bar-title { position: static; transform: none; left: auto; right: auto; text-align: left; flex: 1 1 auto; min-width: 0; }
.bv-nav { grid-template-columns: auto minmax(0, 1fr) auto auto; }
.bv-slider { min-width: 0; }
@media (max-width: 600px) {
  .bv-nav { grid-template-columns: auto minmax(0, 1fr) auto; }
  .bv-mode button { padding: 0 0.5rem; font-size: 0.8rem; }
  .book-viewer .bv-bar .page-bar-title { font-size: 0.9rem; }
}
.book-viewer .bv-bar { padding-inline: 0.5rem 0.9rem; }
.book-viewer .bv-search { padding: 0.6rem 1rem 0.5rem; }
.book-viewer .bv-search input { margin: 0; }

a.menu-item { text-decoration: none; color: inherit; }

/* ---------- Brukeradministrasjon ---------- */
.ua { max-width: 52rem; margin: 0 auto; width: 100%; box-sizing: border-box; display: grid; gap: 1.6rem; padding-bottom: 3rem; }
.ua-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.ua-head h1 { margin: 0 0 0.3rem; font-size: 1.6rem; }
.ua-head p { margin: 0; max-width: 34rem; line-height: 1.5; }
.ua-head .btn { min-height: 44px; padding: 0.6rem 1.1rem; font: inherit; font-weight: 700; }
.ua-users { display: grid; gap: 0.7rem; }
.ua-user { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: 1rem; align-items: start; padding: 1rem 1.1rem; background: var(--surface); border: 1px solid var(--border-soft); border-radius: 14px; }
.ua-avatar { width: 48px; height: 48px; border-radius: 999px; display: grid; place-items: center; background: var(--chip); color: var(--chip-text); font-weight: 700; }
.ua-main p { margin: 0; }
.ua-name { font-size: 1.02rem; }
.ua-email { font-size: 0.88rem; overflow-wrap: anywhere; }
.ua-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.45rem 0 0.35rem !important; }
.ua-badge, .ua-status { display: inline-flex; align-items: center; border-radius: 999px; padding: 0.15rem 0.6rem; font-size: 0.78rem; font-weight: 600; }
.ua-badge { background: var(--chip); color: var(--chip-text); }
.ua-badge.role-admin { background: color-mix(in srgb, var(--brand) 18%, var(--surface)); }
.ua-status.s-ok { background: color-mix(in srgb, #2f7d32 14%, var(--surface)); color: color-mix(in srgb, #2f7d32 80%, var(--text)); }
.ua-status.s-wait { background: var(--badge-bg); color: var(--badge-text); }
.ua-status.s-bad { background: var(--danger-bg); color: var(--danger); }
.ua-access { font-size: 0.88rem; }
.ua-actions { display: flex; flex-direction: column; gap: 0.4rem; align-items: stretch; }
.ua-actions .btn { min-height: 38px; white-space: nowrap; }
.ua-collections h2 { margin: 0 0 0.6rem; font-size: 1.2rem; }
.ua-coll-list { list-style: none; margin: 0 0 0.8rem; padding: 0; display: grid; gap: 0.4rem; }
.ua-coll-list li { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: 0.7rem 0.9rem; background: var(--surface); border: 1px solid var(--border-soft); border-radius: 10px; }
.ua-coll-form { display: flex; gap: 0.5rem; }
.ua-coll-form input { flex: 1; min-width: 0; font: inherit; padding: 0.7rem 0.9rem; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--field-bg); color: var(--text); }
.ua-edit fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 0.45rem; }
.ua-edit legend { font-size: 0.9rem; color: var(--muted); margin-bottom: 0.35rem; padding: 0; }
.ua-edit input[type="email"], .ua-edit input:not([type]) { font: inherit; padding: 0.7rem 0.8rem; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--field-bg); color: var(--text); }
.ua-edit input:disabled { opacity: 0.7; }
.ua-role { display: flex !important; align-items: flex-start; gap: 0.7rem; padding: 0.7rem 0.8rem; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; color: var(--text) !important; }
.ua-role:has(input:checked) { border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.ua-role input { margin-top: 0.2rem; accent-color: var(--brand-fill); }
.ua-role > span { display: grid; gap: 0.1rem; }
.ua-checks { display: grid; gap: 0.35rem; }
.ua-check { display: flex !important; align-items: center; gap: 0.55rem; color: var(--text) !important; font-size: 0.95rem !important; }
.ua-check input { width: 18px; height: 18px; accent-color: var(--brand-fill); }
.ua-submit { min-height: 46px; font: inherit; font-weight: 700; }
.ua-link { width: 100%; box-sizing: border-box; font: inherit; font-size: 0.85rem; padding: 0.6rem; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--field-bg); color: var(--text); }
@media (max-width: 600px) {
  .ua-user { grid-template-columns: 40px minmax(0, 1fr); }
  .ua-avatar { width: 40px; height: 40px; }
  .ua-actions { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; }
}

/* Første samling */
.first-coll { display: none; }
.first-coll[open] { display: grid; place-items: center; height: 100dvh; max-height: 100dvh; }
.first-coll-inner { width: min(30rem, calc(100% - 2.5rem)); display: grid; gap: 1rem; justify-items: start; }
.first-coll-inner img { border-radius: 16px; }
.first-coll-inner h1 { margin: 0; font-size: 1.7rem; line-height: 1.2; text-wrap: balance; }
.first-coll-inner .lead { margin: 0; color: var(--muted); line-height: 1.55; }
.first-coll-inner form { display: grid; gap: 0.8rem; width: 100%; }
.first-coll-inner label { display: grid; gap: 0.35rem; color: var(--muted); font-size: 0.9rem; }
.first-coll-inner input { font: inherit; font-size: 1.05rem; padding: 0.8rem 0.9rem; border-radius: 12px; border: 2px solid transparent; background: var(--surface-2); color: var(--text); }
.first-coll-inner input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--ring); }
.first-coll-inner .btn { min-height: 48px; font: inherit; font-weight: 700; }

/* Leser: ingen knapper for å endre samlingen (serveren stopper det uansett). */
.role-leser .fab, .role-leser [data-action="edit"], .role-leser [data-action="delete"], .role-leser #menuAddBook,
.role-leser [data-action="accept"], .role-leser [data-action="reject"], .role-leser [data-cover="enhance"], .role-leser [data-cover="revert"] { display: none !important; }

/* Gjester på det offentlige nettstedet: ingen favoritter, profil eller strekkode (som kan legge til bøker). */
.role-gjest #profileBtn, .role-gjest #favoritesBtn, .role-gjest #scanSearchBtn, .role-gjest .fav-btn { display: none !important; }

/* Strekkoden (finn eller legg til bok) er bare for administratorer. */
.role-leser #scanSearchBtn { display: none !important; }

/* Favoritter (hjerter) finnes ikke på dette nettstedet – bare administratorer logger inn. */
.fav-btn, #favoritesBtn, #bookFavBtn { display: none !important; }

/* Den digitale boka: zoom og fullskjerm. */
.bv-zoombar { display: flex; align-items: center; gap: 0.15rem; flex: none; }
.bv-zoomlevel { font: inherit; font-size: 0.8rem; font-weight: 700; min-width: 3.6rem; padding: 0.35rem 0.4rem; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); cursor: pointer; }
.bv-stage { --bv-zoom: 1; }
.bv-stage.zoomed { justify-items: start; cursor: grab; }
.bv-stage.zoomed.dragging { cursor: grabbing; user-select: none; }
.bv-stage.zoomed .bv-page { max-width: none; width: calc(var(--bv-zoom) * min(720px, 100%)); }
.bv-stage.zoomed.two .bv-page { width: calc(var(--bv-zoom) * 100%); }
.bv-stage.zoomed .bv-page img { max-height: none; }
.bv-stage .bv-text { font-size: calc(1rem * var(--bv-zoom)); }
.bv-stage .bv-page img { touch-action: pan-x pan-y; -webkit-user-drag: none; }
.book-viewer.bv-fullscreen { width: 100vw; max-width: none; height: 100vh; max-height: none; border-radius: 0; }
.book-viewer.bv-fullscreen .bv-page img { max-height: calc(100vh - 8rem); }
.book-viewer.bv-fullscreen .bv-stage.zoomed .bv-page img { max-height: none; }
@media (max-width: 700px) { .bv-zoomlevel { display: none; } }

/* Filterarket: grupper med overskrift, chips for periode og språk, brytere for innhold. */
.filter-sheet .sheet-content { gap: 0.2rem; }
.fs-group { display: grid; gap: 0.6rem; padding: 0.9rem 0; border-top: 1px solid var(--line); }
.fs-group:first-of-type { border-top: 0; }
.fs-group h3 { margin: 0; font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.fs-select { width: 100%; }
.fs-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.fs-chip { font: inherit; font-size: 0.88rem; font-weight: 600; padding: 0.42rem 0.8rem; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); cursor: pointer; }
.fs-chip:hover { background: var(--hover); }
.fs-chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.fs-years { display: flex; align-items: end; gap: 0.6rem; }
.fs-years label { flex: 1; display: grid; gap: 0.25rem; font-size: 0.82rem; color: var(--muted); }
.fs-years input { font: inherit; padding: 0.5rem 0.65rem; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--field-bg); color: var(--text); width: 100%; }
.fs-years span { padding-bottom: 0.55rem; color: var(--muted); }
.filter-sheet .filter-switch .meta { display: block; font-weight: 400; font-size: 0.8rem; }
.fs-actions { display: flex; gap: 0.6rem; justify-content: space-between; padding: 0.9rem 0 0.2rem; background: var(--surface); border-top: 1px solid var(--line); }
.fs-actions .btn-primary { flex: 1; justify-content: center; }
