:root {
  --bg: #0e1626;
  --panel: #16243b;
  --panel-2: #1e3050;
  --line: #2b4267;
  --text: #eaf1fb;
  --muted: #8ea3c0;
  --accent: #e2483d;
  --gold: #f5b73d;
  --green: #4cc38a;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: .2px; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6rem; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Oppstart ---------- */
.boot {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--muted);
}
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Innlogging ---------- */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
}
.login-logo { width: 60px; height: 60px; object-fit: contain; margin: 0 auto 8px; }
.login-card h1 { text-align: center; }
.login-card > p { text-align: center; margin-bottom: 14px; }
.login-card .btn { margin-top: 16px; }

/* ---------- Toppfelt ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar-logo { width: 34px; height: 34px; object-fit: contain; }
.spacer { flex: 1; }
.who { color: var(--muted); font-size: .88rem; }

.tabs {
  position: sticky;
  top: 59px;
  z-index: 39;
  display: flex;
  gap: 6px;
  padding: 10px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab {
  flex: 0 0 auto;
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab:hover { background: var(--panel); color: var(--text); }
.tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.wrap { max-width: 1400px; margin: 0 auto; padding: 22px 20px 60px; }
.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.view-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Kort ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.card-flush { padding: 0; overflow: hidden; }
.card > h3 { margin-bottom: 14px; }
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.two-col > .card { margin-bottom: 18px; }

/* ---------- Statistikk ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}
.stat .val { font-size: 1.75rem; font-weight: 800; line-height: 1.1; }
.stat .lab { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.stat.is-gold .val { color: var(--gold); }
.stat.is-green .val { color: var(--green); }
.stat.is-accent .val { color: var(--accent); }

/* ---------- Lister ---------- */
.list { display: flex; flex-direction: column; gap: 2px; }
.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 6px;
  border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: 0; }
.list-row img {
  width: 38px; height: 38px;
  object-fit: contain;
  background: var(--panel-2);
  border-radius: 9px;
  padding: 3px;
  flex: 0 0 auto;
}
.list-row .grow { flex: 1; min-width: 0; }
.list-row .name { font-weight: 600; }
.list-row .sub { color: var(--muted); font-size: .8rem; }
.list-row .count { font-weight: 700; color: var(--gold); white-space: nowrap; }
.rank {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  background: var(--panel-2);
  border-radius: 8px;
  font-weight: 700;
  font-size: .8rem;
  flex: 0 0 auto;
}

/* ---------- Stolpediagram ---------- */
.chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-height: 180px;
  padding-top: 10px;
  overflow-x: auto;
}
.bar-col {
  flex: 1 0 34px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.bar-val { font-size: .78rem; color: var(--gold); font-weight: 700; }
.bar {
  width: 100%;
  max-width: 46px;
  min-height: 4px;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, var(--accent), #96271f);
}
.bar-lab {
  font-size: .7rem;
  color: var(--muted);
  white-space: nowrap;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

/* ---------- Skjema ---------- */
label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  margin: 10px 0 4px;
}
input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(226, 72, 61, .18);
}
select { cursor: pointer; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
/* Uten dette presser datetime-feltenes egenbredde kolonnene ut av kortet. */
.row-2 > *, .row-3 > * { min-width: 0; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.form-actions.right { justify-content: flex-end; }
.form-error {
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(226, 72, 61, .15);
  border: 1px solid var(--accent);
  color: #ffc9c4;
  font-size: .87rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}
.field { min-width: 130px; }
.field label { margin-top: 0; }
.field-grow { flex: 1; min-width: 220px; }
.result-line {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: .88rem;
}

/* ---------- Knapper ---------- */
.btn {
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.18); }
.btn:disabled { opacity: .55; cursor: not-allowed; filter: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-gold { background: var(--gold); border-color: var(--gold); color: #2a1c00; }
.btn-green { background: var(--green); border-color: var(--green); color: #06301f; }
.btn-danger { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: .8rem; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---------- Tabeller ---------- */
.table-scroll { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .89rem;
}
.table th, .table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table th {
  color: var(--muted);
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .5px;
  white-space: nowrap;
}
.table tbody tr:hover { background: var(--panel-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .btn { margin-left: 6px; }
.table .empty { text-align: center; color: var(--muted); padding: 26px 12px; }
.sprite-cell img {
  width: 40px; height: 40px;
  object-fit: contain;
  background: var(--panel-2);
  border-radius: 9px;
  padding: 3px;
  display: block;
}
.strong { font-weight: 700; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 700;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  white-space: nowrap;
}
.pill-green { color: var(--green); border-color: rgba(76, 195, 138, .5); background: rgba(76, 195, 138, .12); }
.pill-gold { color: var(--gold); border-color: rgba(245, 183, 61, .5); background: rgba(245, 183, 61, .12); }
.pill-accent { color: #ffb3ad; border-color: rgba(226, 72, 61, .5); background: rgba(226, 72, 61, .14); }

/* ---------- Kart ---------- */
.event-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 18px;
  align-items: start;
}
.map { width: 100%; height: 520px; }
.map-hint {
  margin: 0;
  padding: 10px 16px;
  color: var(--muted);
  font-size: .82rem;
  border-top: 1px solid var(--line);
}
.maplibregl-popup-content {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
  font-size: .82rem;
  padding: 8px 12px;
}
.maplibregl-popup-tip { border-top-color: var(--panel-2) !important; border-bottom-color: var(--panel-2) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 16px; }
.pin {
  width: 20px; height: 20px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  background: var(--gold);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .5);
  cursor: pointer;
}
.pin.pin-new { background: var(--accent); width: 24px; height: 24px; }
.pin.pin-past { background: var(--muted); }

/* ---------- Soner ---------- */
.lead {
  margin: 0 0 16px;
  max-width: 76ch;
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.55;
}
.lead strong { color: var(--text); }
.draw-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.draw-status {
  color: var(--muted);
  font-size: .82rem;
  margin-left: auto;
  text-align: right;
}
/* Punktene i omrisset som tegnes. Rammen holder dem synlige mot lyst kart. */
.vertex {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid #12233c;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
  cursor: grab;
}
.vertex:active { cursor: grabbing; }
.field-help {
  margin: -6px 0 12px;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.45;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 4px 0 14px;
  font-weight: 500;
  cursor: pointer;
}
.check-row input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }
#zoneForm input[type="range"] {
  width: 100%;
  margin: 2px 0 8px;
  padding: 0;
  accent-color: var(--accent);
  background: none;
  border: 0;
}

/* ---------- Innstillinger ---------- */
.settings-list { display: flex; flex-direction: column; gap: 4px; }
.setting-row {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
}
.setting-row:last-child { border-bottom: 0; }
.setting-row .grow { flex: 1; min-width: 0; }
.setting-row .name { font-weight: 600; }
.setting-row .help { color: var(--muted); font-size: .84rem; margin-top: 3px; }
.setting-state { color: var(--muted); font-size: .8rem; font-weight: 700; margin-top: 3px; }
.setting-state.is-on { color: var(--green); }

/* Av/på-bryter. Selve avkryssingsboksen ligger skjult over bryteren. */
.switch {
  position: relative;
  flex: 0 0 auto;
  width: 56px;
  height: 30px;
  margin-top: 2px;
}
.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}
.switch .slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  transition: background .18s, border-color .18s;
}
.switch .slider::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .18s, background .18s;
}
.switch input:checked + .slider {
  background: rgba(76, 195, 138, .28);
  border-color: var(--green);
}
.switch input:checked + .slider::before {
  transform: translateX(26px);
  background: var(--green);
}
.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px rgba(226, 72, 61, .3); }
.switch input:disabled { cursor: progress; }
.switch input:disabled + .slider { opacity: .6; }

/* ---------- Toast ---------- */
.toasts {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  font-size: .89rem;
  animation: toast-in .18s ease-out;
}
.toast-error { border-color: var(--accent); background: #3a1a19; }
.toast-ok { border-color: var(--green); background: #123328; }
@keyframes toast-in { from { opacity: 0; transform: translateX(14px); } }

/* ---------- Dialog ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(6, 11, 20, .72);
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
}
.modal h3 { margin-bottom: 8px; }
.modal p { color: var(--muted); }
.modal-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Mobil ---------- */
@media (max-width: 800px) {
  .wrap { padding: 16px 12px 50px; }
  .topbar { padding: 10px 12px; }
  .topbar h1 { font-size: 1rem; }
  .who { display: none; }
  .tabs { top: 55px; padding: 8px 12px; }
  .two-col,
  .event-layout,
  .row-2,
  .row-3 { grid-template-columns: 1fr; }
  .map { height: 340px; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .modal-fields { grid-template-columns: 1fr; }
}
