:root {
  --bg: #f4f6f7;
  --card: #ffffff;
  --ink: #16242b;
  --muted: #4d5d65;
  --line: #e1e7ea;
  --field: #7b8b93; /* kant på felt og knapper, min. 3:1 */
  --brand: #0e6e8a;
  --brand-ink: #ffffff;
  --brand-soft: #e2f1f5;
  --ok: #16703d;
  --ok-soft: #e3f4ea;
  --bad: #b0321f;
  --bad-soft: #fbe9e7;
  --wait: #8a5a0f;
  --wait-soft: #fdf3e1;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 36, 43, .06), 0 2px 8px rgba(16, 36, 43, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1719;
    --card: #182327;
    --ink: #e7eef0;
    --muted: #93a4ab;
    --line: #273439;
    --field: #6b7f88;
    --brand: #3aa7c6;
    --brand-ink: #06232c;
    --brand-soft: #16343d;
    --ok: #4cc47f;
    --ok-soft: #173325;
    --bad: #ef7f72;
    --bad-soft: #3a1f1c;
    --wait: #e6b35a;
    --wait-soft: #3a2f18;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html {
  background: var(--bg); /* samme farge som body, så man ikke ser hvitt blitz ved overscroll på iPhone */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, .choice, .chip, .item.click, tr.click {
  touch-action: manipulation; /* unngår 300ms-forsinkelse og utilsiktet dobbelttrykk-zoom på iPhone */
  -webkit-touch-callout: none; /* unngår at et langt trykk åpner en meny på knapper */
  -webkit-user-select: none; user-select: none; /* unngår at raske trykk markerer +/- som tekst */
}
.btn:active, .choice:active, .chip:active, .item.click:active, tr.click:active, .stepper button:active {
  transform: scale(0.97); /* synlig tilbakemelding på trykk, siden tap-highlight er skrudd av */
}

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--brand); color: var(--brand-ink);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.who { font-size: .9rem; opacity: .9; }

main { max-width: 720px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left)); }
.loading { color: var(--muted); text-align: center; padding: 40px 0; }

h2 { font-size: 1.15rem; margin: 22px 0 10px; }
h2:first-child { margin-top: 4px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}

label { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0 6px; }
label:first-child { margin-top: 0; }
input, select, textarea {
  width: 100%; padding: 12px; border-radius: 10px;
  border: 1px solid var(--field); background: var(--bg);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
textarea { min-height: 70px; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 10px 18px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--brand); color: var(--brand-ink); font-weight: 650;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--brand-soft); color: var(--brand); }
.btn.plain { background: transparent; color: var(--brand); padding: 8px 10px; min-height: 0; }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.ok { background: var(--ok); color: var(--card); }
.btn.sm { min-height: 44px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1 1 150px; min-width: 0; }
.actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.actions .btn { flex: 1; }

/* Produktvalg */
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.choice {
  position: relative; border: 2px solid var(--field); background: var(--bg); border-radius: 12px; padding: 14px 12px;
  text-align: left; cursor: pointer; min-height: 64px; hyphens: auto;
}
.choice b { display: block; }
.choice span { font-size: .85rem; color: var(--muted); }
.choice.on { border-color: var(--brand); border-width: 3px; padding: 13px 11px; background: var(--brand-soft); }
.choice.on::after { content: "✓"; position: absolute; bottom: 8px; right: 8px; width: 22px; height: 22px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); font-size: .8rem; font-weight: 800; display: grid; place-items: center; }

/* Teller */
.stepper { display: flex; align-items: center; gap: 0; border: 1px solid var(--field); border-radius: 12px; overflow: hidden; width: max-content; background: var(--bg); }
.stepper button { width: 52px; height: 50px; border: 0; background: transparent; font-size: 1.5rem; cursor: pointer; color: var(--brand); }
.stepper button:active { background: var(--brand-soft); }
.stepper input { width: 64px; text-align: center; border: 0; border-radius: 0; font-size: 1.25rem; font-weight: 700; padding: 0; background: transparent; }
.stepper input:focus { outline: none; }
.stepper.sm button { width: 44px; height: 44px; font-size: 1.25rem; }
.stepper.sm input { width: 44px; font-size: 1.1rem; }

/* Nøkkeltall */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
@media (min-width: 560px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .k { font-size: .8rem; color: var(--muted); }
.stat .v { font-size: 1.45rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.stat.hero { grid-column: 1 / -1; background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.stat.hero .k { color: inherit; opacity: .85; }
.stat.hero .v { font-size: 2rem; }
.stat.hero .sub { font-size: .85rem; opacity: .9; }

/* Lister */
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; gap: 10px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; padding-top: 0; }
.item:last-child { padding-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 650; }
.item .meta { font-size: .85rem; color: var(--muted); }
.item.click { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

.pill { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.pill.wait { background: var(--wait-soft); color: var(--wait); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--brand-soft); color: var(--brand); }
.pill.off { background: var(--line); color: var(--muted); }
.pill.paid { background: var(--ink); color: var(--card); }

.pending .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.pending .ctrl { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }

.bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; display: flex; margin-top: 8px; }
.bar i { display: block; height: 100%; }
.bar .b-ok { background: var(--ok); }
.bar .b-bad { background: var(--bad); }
.bar .b-wait { background: var(--wait); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: .8rem; color: var(--muted); }
.legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--c); }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 8px 6px; border-top: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-size: .78rem; color: var(--muted); font-weight: 600; border-top: 0; }
td.num, th.num { text-align: right; }
.scroll { overflow-x: auto; }

.monthnav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.monthnav b { font-size: 1.05rem; }
.monthnav .btn { min-width: 46px; min-height: 44px; }

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

/* Faner */
.tabs button.on span { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 2px; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.tabs button {
  flex: 1; border: 0; background: transparent; padding: 8px 4px 10px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .75rem; color: var(--muted);
}
.tabs button svg { width: 24px; height: 24px; }
.tabs button.on { color: var(--brand); font-weight: 700; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--card); width: 100%; max-width: 560px; overflow: auto; overscroll-behavior: contain;
  max-height: 92vh; max-height: 90dvh; /* dvh tar hensyn til Safaris adressefelt - 92vh gjør ikke det */
  border-radius: 18px 18px 0 0;
  padding: 20px max(16px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
@media (min-width: 600px) { .modal { align-items: center; } .sheet { border-radius: 18px; } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 40;
  bottom: calc(88px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600;
  max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}
.toast.err { background: var(--bad); color: #fff; }

.login { max-width: 380px; margin: 8vh auto 0; }
.login h1 { font-size: 1.4rem; margin: 0 0 4px; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 500; margin-top: 12px; }
.check input { width: 20px; height: 20px; }

/* Frakoblet og køvarsel */
.offline {
  position: sticky; top: calc(50px + env(safe-area-inset-top)); z-index: 9;
  background: var(--wait-soft); color: var(--wait); border-bottom: 1px solid var(--wait);
  text-align: center; font-weight: 650; font-size: .9rem; padding: 6px 16px;
}
.notice { background: var(--wait-soft); color: var(--wait); border-color: var(--wait); font-weight: 600; }

.install-banner {
  position: sticky; top: calc(50px + env(safe-area-inset-top)); z-index: 9;
  display: flex; align-items: center; gap: 10px;
  background: var(--brand-soft); color: var(--brand); border-bottom: 1px solid var(--brand);
  font-weight: 600; font-size: .9rem; padding: 8px 12px 8px max(12px, env(safe-area-inset-left));
}
.install-banner span { flex: 1; min-width: 0; }
.install-banner button#installBannerClose {
  background: transparent; border: 0; color: inherit; font-size: 1.1rem; padding: 6px 4px; min-height: 32px; opacity: .7;
}

/* Filterknapper */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip {
  border: 1px solid var(--field); background: var(--card); color: var(--ink);
  border-radius: 99px; padding: 7px 12px; font-size: .88rem; cursor: pointer; min-height: 44px;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 700; }

/* Dag- og månedsvisning */
.prodrow { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.prodrow:first-of-type { border-top: 0; }
.prodrow .grow { flex: 1 1 140px; min-width: 0; }
/* iOS zoomer siden når et felt under 16px får fokus - hold denne på 1rem selv om den er liten */
.datepick { width: auto; min-height: 44px; padding: 5px 8px; font-size: 1rem; margin-top: 4px; }
.item.current { background: var(--brand-soft); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
tr.click { cursor: pointer; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.compare .k { font-size: .8rem; color: var(--muted); }
.compare .v { font-size: 1.35rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.verdict { margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; font-weight: 650; }
.verdict.good { background: var(--ok-soft); color: var(--ok); }
.verdict.bad { background: var(--bad-soft); color: var(--bad); }
.stat.hero .row .pill { flex: none; }
