/* ===============================
   PERMIT SYSTEM – FÆLLES DESIGN
   =============================== */

:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #e2e6ec;
  --text: #16202e;
  --text-2: #4f5b6b;
  --muted: #7a8596;
  --brand: #2f5a8f;
  --brand-hover: #244a77;
  --brand-soft: #e6eef8;
  --sidebar: #16263d;
  --sidebar-text: #c6d1e0;
  --sidebar-active: #2a4466;
  --danger: #c43c3c;
  --success: #1f8a4c;
  --series-1: #2a78d6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --sidebar-w: 232px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f141b;
    --surface: #171e28;
    --surface-2: #1d2532;
    --border: #2a3444;
    --text: #e8edf3;
    --text-2: #b4bfcd;
    --muted: #8793a3;
    --brand: #4f86c9;
    --brand-hover: #6597d4;
    --brand-soft: #1f3048;
    --sidebar: #0b1017;
    --sidebar-text: #aab6c6;
    --sidebar-active: #1f3048;
    --series-1: #3987e5;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--brand); }

/* ===============================
   LAYOUT
   =============================== */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 24px;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .2px;
}

.brand img {
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 12px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-weight: 500;
}

.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; }

.nav svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-foot {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-foot a { color: var(--sidebar-text); text-decoration: none; }
.sidebar-foot a:hover { color: #fff; }

.main {
  flex: 1;
  min-width: 0;
  padding: 28px 32px 48px;
}

.container { max-width: 1120px; margin: 0 auto; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.page-head h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.2px;
}

.page-head p { margin: 4px 0 0; color: var(--text-2); }

/* mobil topbar */
.topbar { display: none; }

@media (max-width: 860px) {
  .app { flex-direction: column; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }

  body.nav-open .sidebar { transform: none; }

  body.nav-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .4);
    z-index: 150;
  }

  .topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--sidebar);
    color: #fff;
    font-weight: 700;
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .topbar button {
    background: none;
    border: 0;
    color: #fff;
    padding: 4px;
    cursor: pointer;
  }

  .main { padding: 20px 16px 40px; }
}

/* ===============================
   KORT
   =============================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card + .card { margin-top: 16px; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.card-head .hint { color: var(--muted); font-size: 12px; }

.section-title {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
}

/* ===============================
   FORMULAR
   =============================== */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.grid-3 { grid-template-columns: repeat(3, 1fr); }

.full { grid-column: 1 / -1; }

@media (max-width: 700px) {
  .grid, .grid-3 { grid-template-columns: 1fr; }
}

.field label,
label.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color .15s, box-shadow .15s;
}

input[readonly] { background: var(--surface-2); color: var(--text-2); }

textarea { min-height: 84px; resize: vertical; }

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.input-group {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.input-group > :first-child { flex: 1; min-width: 0; }

/* ===============================
   KNAPPER
   =============================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover { background: var(--surface-2); }

.btn-icon { padding: 9px 11px; }

.btn svg { width: 16px; height: 16px; }

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 20px;
}

/* ===============================
   DIVERSE
   =============================== */
.info-box {
  min-height: 80px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  white-space: pre-wrap;
  color: var(--text-2);
}

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

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--brand-soft);
  color: var(--brand);
}

.progress {
  height: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress > div {
  height: 100%;
  width: 0%;
  background: var(--brand);
  transition: width .2s;
}

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
}

/* ===============================
   BILLEDGALLERI + VIEWER
   =============================== */
#imageContainer {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

#imageContainer img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  cursor: zoom-in;
  background: var(--surface-2);
  transition: transform .15s, box-shadow .15s;
}

#imageContainer img:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .15);
}

img { image-orientation: from-image; }

#viewer {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, .96);
  display: none;
  align-items: center;
  justify-content: center;
  touch-action: none;
  z-index: 9999;
}

#viewer img {
  max-width: 95%;
  max-height: 95%;
  cursor: grab;
  transition: transform .1s ease;
}

#closeViewer {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #fff;
  background: rgba(255, 255, 255, .12);
  border-radius: 50%;
  cursor: pointer;
  z-index: 1000;
}

#closeViewer:hover { background: rgba(255, 255, 255, .22); }

#prevBtn, #nextBtn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 32px;
  color: #fff;
  opacity: .7;
  cursor: pointer;
  padding: 12px;
}

#prevBtn:hover, #nextBtn:hover { opacity: 1; }
#prevBtn { left: 10px; }
#nextBtn { right: 10px; }

/* TomSelect tilpasning */
.ts-wrapper { width: 100%; }

.ts-wrapper .ts-control {
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  background: var(--surface) !important;
  color: var(--text);
  box-shadow: none !important;
}

.ts-dropdown {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  font-size: 14px;
}

.ts-dropdown .active { background: var(--brand-soft); color: var(--text); }
