:root {
  --bg: #f4f6f8;
  --ink: #112129;
  --panel: #ffffff;
  --edge: #d3dce2;
  --accent: #1f6e8c;
}

body.dark {
  --bg: #0f1418;
  --ink: #d7e2ea;
  --panel: #182028;
  --edge: #2d3a45;
  --accent: #5da6c8;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background: radial-gradient(80vw 60vh at 0% 0%, #d8e9f0 0%, var(--bg) 60%);
}
body.dark { background: radial-gradient(80vw 60vh at 0% 0%, #1a2a33 0%, var(--bg) 60%); }

.topbar {
  padding: 1rem 1.2rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid var(--edge);
  background-color: #eaf1f6;
  background-image: linear-gradient(135deg, #eef4f8 0%, #dfeaf2 100%);
  backdrop-filter: blur(6px);
  position: relative;
}
body.dark .topbar {
  background-color: #202c35;
  background-image: linear-gradient(135deg, #243643 0%, #1e2c36 100%);
}
.topbar > div { text-align: center; }
.topbar h1 { margin: 0; font-size: 1.3rem; }
.topbar p { margin: .3rem 0 0; font-size: .9rem; }
.topbar-left-actions {
  position: absolute;
  left: 1.2rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: .45rem;
}
.topbar-action {
  position: absolute;
  right: 1.2rem;
  top: 50%;
  transform: translateY(-50%);
  border: 1px solid var(--edge);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  min-width: 5.8rem;
  height: 2.1rem;
  cursor: pointer;
  font-size: .86rem;
  font-weight: 600;
}
.topbar-action.secondary {
  position: static;
  transform: none;
  min-width: auto;
  padding: 0 .65rem;
}

.board-wrap {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.board {
  position: relative;
  overflow: auto;
  min-height: 0;
  height: 100%;
  width: 100%;
  background-image: linear-gradient(to right, rgba(127,145,158,.16) 1px, transparent 1px), linear-gradient(to bottom, rgba(127,145,158,.16) 1px, transparent 1px);
  background-size: 24px 24px;
}

.links {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
}

.node {
  position: absolute;
  width: 320px;
  min-height: 160px;
  border: 1px solid var(--edge);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 12px 30px rgba(17,33,41,.07);
  z-index: 10;
}
.node[data-kind="spg"] { width: 384px; }

.node-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--edge);
  padding: .65rem .75rem;
}
.node-head h3 { margin: 0; font-size: .95rem; }
.node-head-actions { display: flex; align-items: center; gap: .4rem; position: relative; }
.node-mini-btn {
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-size: .82rem;
  line-height: 1;
  padding: 0;
}
.node-add-btn {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

.node-body { padding: .6rem; min-height: 90px; }

.person, .membership {
  border: 1px solid #b8c8d5;
  border-radius: 10px;
  padding: .35rem .45rem;
  margin: 0 0 .35rem;
  font-size: .8rem;
  background: color-mix(in oklab, var(--panel) 90%, #dce7f0 10%);
}
.person {
  font-family: "Space Grotesk", sans-serif;
  cursor: grab;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.person.selected { border-color: var(--accent); }
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid #9bb2c3;
  object-fit: cover;
  flex: 0 0 30px;
}
.avatar-sm {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
}
.person-name {
  font-size: .96rem;
  font-weight: 600;
}
.person-chip {
  display: flex;
  align-items: center;
  gap: .4rem;
}
.person-chip-name {
  font-size: .86rem;
  font-weight: 600;
}
.info-btn {
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 999px;
  padding: 0;
  font-weight: 700;
}

.dropzone {
  min-height: 70px;
  border: 2px dashed #bacbd7;
  border-radius: 10px;
  padding: .45rem;
  background: color-mix(in oklab, var(--panel) 94%, #dbe8f1 6%);
  margin-bottom: .9rem;
}
.dropzone > :last-child { margin-bottom: 0; }
.dropzone.collapsed {
  min-height: 0;
  padding-top: .3rem;
  padding-bottom: .3rem;
}
.dropzone.over { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in oklab, var(--accent) 30%, transparent); }
.dropzone.over::after {
  content: "Slipp her for å legge til";
  display: block;
  margin: .15rem 0 .3rem;
  font-size: .72rem;
  color: var(--accent);
  font-weight: 700;
}
.dropzone.reorder-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--accent) 28%, transparent);
}

.membership-row { display: flex; align-items: center; gap: .4rem; }
.row-label { flex: 1; min-width: 0; }

.ug-parent {
  font-weight: 700;
  background: #f7e7d3;
  border-color: #e2c39c;
}
.ug-child { margin-left: 1rem; }

.spg-site-header {
  font-weight: 700;
  background: #dcece4;
  border-color: #b8d4c4;
  cursor: grab;
}
.spg-library-header {
  font-weight: 700;
  background: #e8f2ec;
  border-color: #c7dccf;
}
.spg-parent {
  font-weight: 700;
  background: #f0f7f3;
  border-color: #d0e2d7;
}
.spg-group { margin-left: .9rem; margin-top: .55rem; margin-bottom: .55rem; }
.spg-direct-user { margin-left: 1rem; }
.spg-ug-list { margin-top: .65rem; padding-top: .45rem; border-top: 1px dashed var(--edge); }
.spg-child { margin-left: 1rem; }
.spg-sub-user { margin-left: 2rem; font-size: .74rem; }

.row-btn {
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font-size: .72rem;
  padding: .15rem .35rem;
  cursor: pointer;
}
.toggle-btn { min-width: 1.4rem; padding: 0 .3rem; font-weight: 700; }
.remove-btn { color: #a33; border-color: #d8b5b5; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(16, 29, 36, .35);
  display: grid;
  place-items: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-card {
  width: min(92vw, 430px);
  background: var(--panel);
  border-radius: 16px;
  border: 1px solid var(--edge);
  box-shadow: 0 12px 30px rgba(17,33,41,.2);
  padding: 1rem;
  display: grid;
  gap: .5rem;
}
.modal-card h3 { margin: 0 0 .2rem; }
.modal-card input, .modal-card select {
  font: inherit;
  border: 1px solid var(--edge);
  border-radius: 9px;
  padding: .5rem .6rem;
  background: color-mix(in oklab, var(--panel) 92%, #dce7f0 8%);
  color: var(--ink);
}
.modal-radio-group {
  display: flex;
  gap: .6rem;
}
.modal-radio {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .84rem;
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: .25rem .55rem;
  background: color-mix(in oklab, var(--panel) 92%, #dce7f0 8%);
}
.modal-radio input { margin: 0; }
.modal-check-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .45rem;
}
.modal-preview-label { margin: .2rem 0 0; font-size: .78rem; }
.modal-preview {
  margin: 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: .84rem;
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: .4rem .5rem;
  white-space: pre-line;
}
.modal-actions { display: flex; justify-content: end; gap: .45rem; margin-top: .2rem; }
.modal-create { background: var(--accent); color: #fff; border-color: var(--accent); }
.modal-delete { color: #8a2d2d; border-color: #d8b5b5; margin-right: auto; }
.modal-warning { font-size: .72rem; color: #8a2d2d; align-self: center; margin-right: auto; }

.spg-menu {
  position: fixed;
  z-index: 110;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(17,33,41,.2);
  padding: .45rem;
  display: grid;
  gap: .3rem;
}
.spg-menu.hidden { display: none; }
.spg-menu .row-btn {
  text-align: left;
  font-size: .9rem;
  padding: .5rem .7rem;
  min-width: 160px;
}
.site-add-btn {
  min-width: 1.4rem;
  padding: 0 .35rem;
  font-weight: 700;
}

body.dark .board {
  background-image: linear-gradient(to right, rgba(140,160,175,.10) 1px, transparent 1px), linear-gradient(to bottom, rgba(140,160,175,.10) 1px, transparent 1px);
}
body.dark .dropzone {
  border-color: #41505c;
}
body.dark .spg-ug-list {
  border-top-color: #41505c;
}
body.dark .ug-parent {
  background: #3a3123;
  border-color: #5a4b36;
}
body.dark .spg-site-header {
  background: #213229;
  border-color: #355040;
}
body.dark .spg-library-header {
  background: #27372f;
  border-color: #3c5647;
}
body.dark .spg-parent {
  background: #2a3a31;
  border-color: #435e4f;
}

.hidden { display: none; }
