/* ===========================================================================
   Messebok – utseende
   Mobil først. Lys og mørk modus. Store trykkflater, høy kontrast slik at
   skjermen er lesbar i en opplyst messehall.
   =========================================================================== */

:root {
  --bg: #eef1f8;
  --surface: #ffffff;
  --surface-2: #f4f6fc;
  --border: #e3e7f2;
  --text: #101529;
  --text-dim: #616d8a;
  --text-faint: #8b95ad;

  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --brand-soft: #eceafe;
  --brand-ink: #ffffff;
  --grad: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #9333ea 100%);

  --teal: #0d9488;
  --teal-soft: #dcf5f1;
  --amber: #c2680a;
  --amber-soft: #fdf0dc;
  --rose: #d61f4b;
  --rose-soft: #fde7ec;

  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 12px -6px rgba(16, 24, 40, .12);
  --shadow-md: 0 2px 4px rgba(16, 24, 40, .05), 0 16px 32px -18px rgba(16, 24, 40, .28);
  --shadow-fab: 0 10px 26px -8px rgba(79, 70, 229, .65);

  --topbar-h: 62px;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0d16;
    --surface: #151a28;
    --surface-2: #1c2233;
    --border: #262d41;
    --text: #e9edf8;
    --text-dim: #9aa4bd;
    --text-faint: #78829b;

    --brand: #7c73f5;
    --brand-2: #a855f7;
    --brand-soft: #221f45;
    --brand-ink: #ffffff;
    --grad: linear-gradient(135deg, #3730a3 0%, #5b21b6 55%, #6b21a8 100%);

    --teal: #2dd4bf;
    --teal-soft: #10312e;
    --amber: #fbbf24;
    --amber-soft: #33240c;
    --rose: #fb7185;
    --rose-soft: #3a1220;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 12px 28px -16px rgba(0, 0, 0, .8);
    --shadow-fab: 0 10px 26px -8px rgba(124, 115, 245, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Må stå her: display-reglene under er mer spesifikke enn nettleserens
   standardregel for [hidden], og ville ellers vist skjulte elementer. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Topplinje ---------- */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  min-height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--grad);
  color: #fff;
  box-shadow: 0 6px 20px -12px rgba(24, 16, 80, .8);
  z-index: 40;
}
#topbar .titles { flex: 1; min-width: 0; padding: 8px 0; }
#topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#topbar p {
  margin: 1px 0 0;
  font-size: 12.5px;
  color: rgba(255, 255, 255, .78);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#topbar .status { display: flex; gap: 6px; }

.icon-btn {
  border: none;
  background: none;
  color: #fff;
  font-size: 32px;
  line-height: 1;
  width: 34px;
  height: 44px;
  cursor: pointer;
}
.avatar {
  width: 36px; height: 36px;
  flex: 0 0 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(255, 255, 255, .16);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
}

/* ---------- Fanelinje ---------- */
#tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 40;
}
.tab {
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}
.tab-ico {
  font-size: 17px;
  line-height: 1;
  width: 46px;
  padding: 5px 0;
  border-radius: 999px;
  transition: background .15s ease;
}
.tab.active { color: var(--brand); }
.tab.active .tab-ico { background: var(--brand-soft); }

/* ---------- Sidestruktur ---------- */
#app {
  padding: calc(var(--topbar-h) + env(safe-area-inset-top) + 14px) 14px
           calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 90px) 14px;
  max-width: 780px;
  margin: 0 auto;
}
#app.no-chrome { padding-top: 26px; padding-bottom: 26px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 22px 2px 10px;
}
.section-head:first-child { margin-top: 4px; }
.section-head h2 {
  margin: 0;
  font-size: 12px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 700;
}

/* ---------- Kort ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 15px;
  margin-bottom: 11px;
}
.card.tappable { cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
.card.tappable:active { transform: scale(.985); box-shadow: var(--shadow-md); }
.card h3 { margin: 0 0 2px; font-size: 16.5px; font-weight: 700; letter-spacing: -.01em; }
.card .meta { margin: 0; color: var(--text-dim); font-size: 13.5px; }
.card .row { display: flex; align-items: center; gap: 12px; }
.card .row > .grow { flex: 1; min-width: 0; }
.chev { color: var(--text-faint); font-size: 24px; line-height: 1; }

/* Fargeflate med initialer for leverandører */
.mono {
  flex: 0 0 44px;
  width: 44px; height: 44px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .02em;
}

/* Tallpanel på messekort */
.stats { display: flex; gap: 7px; margin-top: 10px; flex-wrap: wrap; }
.stat {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.stat b { color: var(--text); font-size: 14px; font-weight: 700; margin-right: 3px; }

.price {
  color: var(--teal);
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 46px 18px;
  font-size: 15px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty .big { display: block; font-size: 34px; margin-bottom: 10px; opacity: .85; }

/* ---------- Knapper ---------- */
button, input, select, textarea { font: inherit; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 15px;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
  transition: transform .12s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: var(--grad);
  border-color: transparent;
  color: var(--brand-ink);
  box-shadow: var(--shadow-fab);
}
.btn-danger { color: var(--rose); border-color: var(--border); }
.btn-block { display: flex; width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13.5px; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* Flytende hovedknapp */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  height: 54px;
  min-width: 54px;
  padding: 0 20px;
  border: none;
  border-radius: 18px;
  background: var(--grad);
  color: #fff;
  font-size: 15.5px;
  font-weight: 700;
  box-shadow: var(--shadow-fab);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  z-index: 35;
}
.fab:active { transform: scale(.96); }
.fab .plus { font-size: 22px; line-height: 1; margin-top: -2px; }

/* ---------- Merker ---------- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  white-space: nowrap;
}
.badge-cert { background: var(--teal-soft); border-color: transparent; color: var(--teal); }
.badge-warn { background: var(--amber-soft); border-color: transparent; color: var(--amber); }
.badge-offline { background: rgba(255, 255, 255, .2); border-color: rgba(255, 255, 255, .45); color: #fff; }
.badge-queue { background: rgba(255, 255, 255, .2); border-color: rgba(255, 255, 255, .45); color: #fff; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* ---------- Skjema ---------- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field input[type=text],
.field input[type=number],
.field input[type=email],
.field input[type=tel],
.field input[type=url],
.field input[type=password],
.field select,
.field textarea {
  width: 100%;
  padding: 12px 13px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color .15s ease, background .15s ease;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--surface);
}
.field textarea { min-height: 96px; resize: vertical; }
.field-row { display: flex; gap: 9px; }
.field-row > * { flex: 1; min-width: 0; }
.check {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 0;
  font-size: 15.5px;
  cursor: pointer;
}
.check input { width: 22px; height: 22px; accent-color: var(--brand); }
.hint { font-size: 12.5px; color: var(--text-faint); margin: 6px 0 0; }

.contact-row {
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 13px 13px 6px;
  margin-bottom: 11px;
  background: var(--surface-2);
}

/* ---------- Søk ---------- */
.searchbar { margin-bottom: 11px; }
.searchbar input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.searchbar input:focus { outline: none; border-color: var(--brand); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.filters select {
  flex: 1 1 46%;
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}
.chip {
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.chip.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }

/* ---------- Bilder og filer ---------- */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(98px, 1fr));
  gap: 9px;
  margin-top: 12px;
}
.thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 13px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .del {
  position: absolute;
  top: 5px; right: 5px;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(10, 12, 20, .65);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(3px);
}
.thumb .pend {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: rgba(10, 12, 20, .7);
  color: #fff;
  font-size: 10.5px;
  font-weight: 600;
  text-align: center;
  padding: 3px 0;
}
.filelist { list-style: none; margin: 12px 0 0; padding: 0; }
.filelist li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.filelist li:last-child { border-bottom: none; }
.filelist a { color: var(--brand); text-decoration: none; word-break: break-all; font-weight: 600; }
input[type=file] { display: none; }

/* ---------- Detaljrader ---------- */
.kv {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.kv:first-child { padding-top: 2px; }
.kv:last-child { border-bottom: none; padding-bottom: 2px; }
.kv .k { flex: 0 0 40%; color: var(--text-dim); font-size: 13.5px; }
.kv-block { display: block; }
.kv-block .k { display: block; margin-bottom: 2px; }
.kv-block .stats { margin-top: 6px; }
.kv .v { flex: 1; word-break: break-word; font-weight: 550; }
.kv a { color: var(--brand); text-decoration: none; font-weight: 600; }
.note { white-space: pre-wrap; word-break: break-word; font-weight: 400; }

/* ---------- Melding ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 84px);
  transform: translateX(-50%);
  background: #10152a;
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  z-index: 80;
  max-width: 90vw;
  text-align: center;
  box-shadow: var(--shadow-md);
}

/* ---------- Innlogging ---------- */
.login {
  min-height: 74vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 4px;
  padding: 0 8px;
}
.login .logo {
  width: 84px; height: 84px;
  border-radius: 26px;
  background: var(--grad);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: .02em;
  margin-bottom: 16px;
  box-shadow: var(--shadow-fab);
}
.login h2 { margin: 0; font-size: 25px; letter-spacing: -.02em; }
.login p { color: var(--text-dim); margin: 6px 0 22px; max-width: 34ch; }
.login code {
  background: var(--surface-2);
  border-radius: 6px;
  padding: 1px 5px;
  font-size: 13px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  text-align: left;
  box-shadow: var(--shadow-md);
}
.login-card .btn-row { justify-content: space-between; }
.login-card .btn-row .btn { flex: 1; }

/* ---------- Dialog ---------- */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 22, .55);
  backdrop-filter: blur(2px);
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal {
  background: var(--surface);
  width: 100%;
  max-width: 620px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 22px 22px 0 0;
  padding: 20px 16px calc(22px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-md);
}
.modal h2 { margin: 0 0 4px; font-size: 19px; letter-spacing: -.01em; }

.spinner {
  width: 24px; height: 24px;
  border: 2.5px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 48px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
