:root {
  /* NorPulse: marineblå → magenta (fra logoen på norpulse.no) */
  --bg: #F4F5FA;
  --surface: #FFFFFF;
  --surface-2: #F8F9FC;
  --text: #1E2560;
  --mid: #424A7A;
  --muted: #7C82A3;
  --border: #DCDFEC;
  --navy: #2C3C8D;
  --brand: #2C3C8D;
  --brand-tint: #ECEEF8;
  --accent: #DC1584;
  --gradient: linear-gradient(90deg, #2C3C8D 0%, #722C8C 50%, #DC1584 100%);
  --accent-ink: #FFFFFF;
  --ok: #2E7D4F;
  --warn: #B7791F;
  --danger: #C0392B;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(19,40,74,.06), 0 4px 16px rgba(19,40,74,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1130;
    --surface: #161A40;
    --surface-2: #1B2050;
    --text: #E9EAF5;
    --mid: #B9BEDD;
    --muted: #8187AE;
    --border: #2A3066;
    --navy: #161A40;
    --brand: #8E9BF0;
    --brand-tint: #232A63;
    --accent: #F0479F;
    --ok: #4CAF7A;
    --warn: #E0A84A;
    --danger: #E06A5C;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ── Layout ── */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  background: var(--surface); color: var(--text); padding: 20px 12px; border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
}
.brand { display: flex; flex-direction: column; gap: 2px; padding: 4px 10px 18px; }
.brand .logo { height: 44px; width: auto; align-self: flex-start; }
.brand small { display: block; font-weight: 600; color: var(--muted); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; padding-left: 2px; }
.brand::after { content: ""; display: block; height: 3px; border-radius: 3px; background: var(--gradient); margin-top: 12px; }
@media (prefers-color-scheme: dark) { .brand .logo { background: #fff; border-radius: 8px; padding: 4px 8px; height: 40px; } }
.side a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  text-decoration: none; color: var(--mid); font-size: 14px;
}
.side a:hover { background: var(--surface-2); color: var(--text); }
.side a.active { background: var(--brand-tint); color: var(--brand); font-weight: 600; }
.side .sep { height: 1px; background: var(--border); margin: 10px 8px; }
.side .grow { flex: 1; }
.side .who { font-size: 13px; color: #9FB2C6; padding: 8px 12px; }
.ico { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

main { padding: 28px 32px 48px; max-width: 1100px; width: 100%; }
.topbar { display: none; }
.bottomnav { display: none; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 20;
    background: var(--surface); color: var(--text); padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
    border-bottom: 1px solid var(--border); box-shadow: 0 2px 0 0 transparent;
  }
  .topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--gradient); }
  .topbar .logo { height: 22px; width: auto; }
  .topbar .title { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar button { background: none; border: 0; color: var(--text); padding: 6px; border-radius: 8px; display: flex; }
  main { padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }
  .bottomnav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottomnav a, .bottomnav button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px;
    font-size: 11px; color: var(--muted); text-decoration: none; background: none; border: 0;
  }
  .bottomnav .active { color: var(--accent); }
  .bottomnav .ico { width: 22px; height: 22px; }
}

/* ── Typografi ── */
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.page-head > div:first-child { flex: 1; min-width: 0; }
@media (max-width: 820px) {
  .page-head h1 { display: none; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .btns > .btn { flex: 1; }
}
.shell > div { min-width: 0; }
main { min-width: 0; }

/* ── Komponenter ── */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.grid { display: grid; gap: 12px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; display: block; }
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.stat .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 820px) { .two { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; text-decoration: none; min-height: 40px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--mid); margin-bottom: 4px; font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
  min-height: 42px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=number] { font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.searchbar { display: flex; gap: 8px; margin-bottom: 14px; }
.searchbar input { flex: 1; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--surface-2); }
td.r, th.r { text-align: right; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; text-decoration: none; }
a.row:hover, button.row:hover { background: var(--surface-2); }
button.row { width: 100%; text-align: left; background: none; border: 0; cursor: pointer; }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .end { text-align: right; flex: none; }
.qty { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 17px; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); color: var(--mid); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.badge.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.badge.accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }

.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.notice { border-left: 3px solid var(--accent); background: var(--surface-2); padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: 14px; }

/* Linjeredigering (mottak/plukk/telling) */
.line { padding: 12px 16px; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; }
.line:last-child { border-bottom: 0; }
.line.done { background: color-mix(in srgb, var(--ok) 7%, transparent); }
.line .meta { font-size: 13px; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); font-size: 20px; cursor: pointer; line-height: 1; }
.stepper input { width: 70px; text-align: center; padding: 8px 4px; }
.line .extra { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.line .extra select { width: auto; min-height: 34px; padding: 4px 8px; font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-family: ui-monospace, Menlo, monospace; font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); }

.scanbar { display: flex; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); position: sticky; top: 0; z-index: 2; }
@media (max-width: 820px) { .scanbar { top: calc(env(safe-area-inset-top) + 52px); } }
.scanbar input { flex: 1; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(8,16,28,.5); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal header h2 { margin: 0; }
.modal .body { padding: 18px; }
.modal .foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
@media (max-width: 820px) {
  .modal-bg { padding: 0; align-items: flex-end; }
  .modal { max-width: none; border-radius: 16px 16px 0 0; max-height: 92vh; padding-bottom: env(safe-area-inset-bottom); }
}
video.scan { width: 100%; border-radius: 10px; background: #000; aspect-ratio: 4/3; object-fit: cover; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; transition: .2s;
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: calc(100vw - 32px); pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 14px;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }
@media (max-width: 820px) { #toast { bottom: calc(80px + env(safe-area-inset-bottom)); } }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login .brand { padding: 0 0 20px; }
.login .brand .logo { height: 44px; }

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

/* Varebilder */
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: contain; background: #fff; border: 1px solid var(--border); flex: none; }
.thumb.ph { display: grid; place-items: center; color: var(--muted); background: var(--surface-2); }
.thumb.ph .ico { width: 20px; height: 20px; }
.line .thumb { width: 40px; height: 40px; }
.line .who { display: flex; gap: 10px; align-items: center; min-width: 0; }
.product-hero { display: grid; grid-template-columns: 220px 1fr; gap: 16px; margin-bottom: 16px; }
.product-hero .img { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); aspect-ratio: 1; display: grid; place-items: center; overflow: hidden; }
.product-hero .img img { width: 100%; height: 100%; object-fit: contain; }
.product-hero .img .ico { width: 48px; height: 48px; color: var(--muted); }
@media (max-width: 820px) { .product-hero { grid-template-columns: 1fr; } .product-hero .img { max-height: 280px; aspect-ratio: auto; height: 240px; } }
.stat .value { color: var(--text); }
.btn.primary { background: var(--brand); border-color: var(--brand); }
@media (prefers-color-scheme: dark) { .btn.primary { background: #3B4BB0; border-color: #3B4BB0; } }

/* Varselkort */
.stat.alert.danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.stat.alert.danger .value { color: var(--danger); }
.stat.alert.warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); }
.stat.alert.warn .value { color: var(--warn); }
.tbl td { font-size: 14px; }
.tbl td.qty { font-size: 16px; }
@media (max-width: 820px) { .hide-sm { display: none; } .tbl th, .tbl td { padding: 8px 10px; } }
.print-only { display: none; }

/* ── Utskrift ── */
@media print {
  @page { size: A4; margin: 12mm; }
  :root { --bg: #fff; --surface: #fff; --surface-2: #fff; --text: #000; --mid: #222; --muted: #555; --border: #bbb; }
  body { background: #fff; font-size: 11pt; }
  .side, .topbar, .bottomnav, .scanbar, .no-print, #toast, .btns, .stepper button, .line .extra select, .line .extra .btn { display: none !important; }
  .print-only { display: block !important; }
  .shell { display: block; }
  main { padding: 0; max-width: none; }
  .page-head h1 { display: block !important; font-size: 18pt; }
  .card, .stat { box-shadow: none; break-inside: avoid; }
  .line { break-inside: avoid; }
  .stepper input { border: 0; background: none; font-weight: 700; width: auto; }
  .thumb { width: 32px; height: 32px; }
  a { text-decoration: none; }
  .hide-sm { display: table-cell !important; }
}
td.mono { white-space: nowrap; }
