:root {
  --navy: #12213f;
  --navy-2: #1b2f57;
  --navy-3: #2a4373;
  --lime: #a3e635;
  --lime-dark: #65a30d;
  --lime-soft: #ecfccb;
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #17213a;
  --muted: #5b6680;
  --line: #e2e7f0;
  --danger: #c2410c;
  --danger-soft: #fff1ea;
  --warn-soft: #fff8db;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(18, 33, 63, .06), 0 4px 14px rgba(18, 33, 63, .06);
  --nav-h: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
a { color: var(--navy-3); }
h1 { font-size: 1.6rem; margin: .2rem 0 .6rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
h3 { font-size: 1.02rem; margin: 0; }
code { background: #eef1f6; padding: 0 .3em; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.lead { font-size: 1.05rem; }
.ok-text { color: var(--lime-dark); font-weight: 600; }

/* ---------- Top og navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--navy); color: #fff; padding: .7rem 1.2rem;
}
.logo, .auth-logo { color: #fff; text-decoration: none; font-weight: 800; font-size: 1.3rem; letter-spacing: -.01em; white-space: nowrap; }
.logo b, .auth-logo b { color: var(--lime); }
.hex { color: var(--lime); }
.topbar-right { display: flex; align-items: center; gap: .9rem; min-width: 0; }
.org { color: #dfe6f5; text-decoration: none; display: flex; align-items: center; gap: .45rem; min-width: 0; }
.org-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 28vw; font-size: .92rem; }
.gear { font-size: 1.3rem; }
.org:hover .gear { color: var(--lime); }
.live { display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem; color: #c7d2ea; }
.live i { width: .55rem; height: .55rem; border-radius: 50%; background: #f59e0b; display: inline-block; }
.live.on i { background: var(--lime); box-shadow: 0 0 0 3px rgba(163, 230, 53, .25); }

.mainnav {
  position: sticky; top: 52px; z-index: 19;
  display: flex; gap: .25rem; background: var(--navy-2); padding: 0 1rem; overflow-x: auto;
}
.mainnav a {
  color: #d5ddef; text-decoration: none; padding: .75rem 1rem; border-bottom: 3px solid transparent;
  display: flex; align-items: center; gap: .45rem; white-space: nowrap; font-weight: 600;
}
.mainnav a:hover { color: #fff; }
.mainnav a.active { color: #fff; border-bottom-color: var(--lime); }
.mainnav .ico { color: var(--lime); }
.lbl-short { display: none; }

main { max-width: 1100px; margin: 0 auto; padding: 1.2rem 1.2rem 3rem; outline: none; }
.stale-note { background: var(--warn-soft); color: #6b4e00; text-align: center; padding: .5rem 1rem; font-size: .92rem; }

/* ---------- Kort, knapper, felter ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; border: 1px solid var(--line); }
a.card { display: block; color: inherit; text-decoration: none; transition: transform .08s, box-shadow .08s; }
a.card:hover { transform: translateY(-1px); box-shadow: 0 2px 4px rgba(18,33,63,.08), 0 8px 22px rgba(18,33,63,.1); }
.empty { text-align: center; padding: 2rem 1rem; }
.muted-card { opacity: .7; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.grid > .card { margin: 0; }
.stack > .card { margin-bottom: .75rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  border: 1px solid #cdd5e3; background: #fff; color: var(--navy); font: inherit; font-weight: 650;
  padding: .6rem 1rem; border-radius: 10px; cursor: pointer; text-decoration: none; min-height: 44px;
}
.btn:hover { border-color: var(--navy-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--lime); border-color: var(--lime); color: var(--navy); }
.btn.primary:hover { background: #b5f04f; border-color: var(--lime-dark); }
.btn.big { font-size: 1.05rem; padding: .75rem 1.25rem; }
.btn.small { min-height: 34px; padding: .3rem .7rem; font-size: .9rem; }
.btn.wide { width: 100%; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); border-color: #f3c6b2; }
.linkbtn { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; }

.back {
  background: none; border: 0; color: var(--navy-3); font: inherit; font-weight: 650; cursor: pointer;
  padding: .4rem 0; margin-bottom: .3rem; min-height: 40px;
}
.back:hover { color: var(--navy); text-decoration: underline; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .6rem; }
.page-head h1 { margin: 0; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .5rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .4rem 0 1rem; }
.page-head .actions { margin: 0; }

.badge { display: inline-block; font-size: .76rem; font-weight: 650; background: #eef2f8; color: var(--navy-3); border-radius: 999px; padding: .1rem .55rem; margin-top: .2rem; }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .7rem; }
.chip { font-size: .82rem; background: var(--lime-soft); color: #2f4a06; border-radius: 8px; padding: .2rem .5rem; }
.chip b { font-weight: 800; }
.chip.loaned { background: #e8edf7; color: var(--navy-3); }
.chip.empty, .chip.more { background: #f1f3f7; color: var(--muted); }

.form { display: grid; gap: .9rem; }
.form label, .filters label { display: grid; gap: .3rem; font-weight: 650; font-size: .92rem; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: #fff;
  border: 1px solid #cdd5e3; border-radius: 10px; padding: .6rem .75rem; min-height: 44px; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible, .back:focus-visible {
  outline: 3px solid rgba(163, 230, 53, .7); outline-offset: 1px; border-color: var(--lime-dark);
}
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.form-error { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: .6rem .8rem; margin: 0; font-weight: 600; }
.form-error[hidden] { display: none; }
.privacy { font-size: .85rem; color: #6b4e00; background: var(--warn-soft); border-radius: 10px; padding: .5rem .7rem; margin: -.3rem 0 0; }
.inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: .3rem 0; }
.inline-form input { flex: 1; min-width: 10rem; }
.inline-form label { display: flex; align-items: center; gap: .4rem; font-weight: 400; }
.inline-form label input { min-width: 0; }

.filters { display: grid; gap: .8rem; }
.filter-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .8rem; }
.search input { font-size: 1.05rem; }
.result-count { margin: -.3rem 0 .6rem; font-size: .9rem; }

.alert { display: block; border-radius: 12px; padding: .75rem 1rem; margin-bottom: 1rem; background: #eef2f8; color: var(--navy); text-decoration: none; font-weight: 600; }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: #6b4e00; font-weight: 400; }
.alert.warn p { margin: 0 0 .5rem; }
.note { background: #fff; border-left: 4px solid var(--lime); padding: .5rem .8rem; border-radius: 6px; }

/* ---------- Nøgletal ---------- */
.hero h1 { margin-bottom: 0; }
.hero p { margin-top: .2rem; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin: 1rem 0; }
.stats.small { grid-template-columns: repeat(3, 1fr); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.stat b { display: block; font-size: 2rem; line-height: 1.1; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .9rem; }
.stat.accent { background: var(--navy); border-color: var(--navy); }
.stat.accent b { color: var(--lime); }
.stat.accent span { color: #c7d2ea; }
.quick { display: flex; flex-wrap: wrap; gap: .7rem; margin-bottom: 1.4rem; }

/* ---------- Materialer og placeringer ---------- */
.mat-head { display: flex; justify-content: space-between; gap: .8rem; }
.mat-num { text-align: right; }
.mat-num b { display: block; font-size: 1.6rem; line-height: 1; color: var(--navy); font-variant-numeric: tabular-nums; }
.mat-num small { color: var(--muted); }
.loc-sum { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.loc-sum b { color: var(--navy); }
.loc-items { list-style: none; padding: 0; margin: 0; }
.loc-items li { display: flex; justify-content: space-between; gap: .6rem; padding: .4rem 0; border-top: 1px solid var(--line); }
.loc-items li:first-child { border-top: 0; }
.plain { list-style: none; padding: 0; margin: .4rem 0; }
.plain li { padding: .3rem 0; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .55rem .4rem; border-top: 1px solid var(--line); vertical-align: middle; }
.table thead th { border-top: 0; font-size: .82rem; color: var(--muted); font-weight: 650; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions a { margin-left: .6rem; }

/* ---------- Udlån ---------- */
.loan-card { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.loan-card.overdue { border-color: #f3c6b2; background: #fffaf7; border-left: 5px solid var(--danger); }
.loan-qty { margin: .2rem 0 .5rem; }
.loan-qty b { font-size: 1.2rem; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .3rem 1rem; margin: 0; }
.kv dt { font-size: .78rem; color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

/* ---------- Historik ---------- */
.events { list-style: none; padding: 0; margin: 0; }
.events.card { padding: .3rem 1.1rem; }
.event { padding: .7rem 0; border-top: 1px solid var(--line); }
.event:first-child { border-top: 0; }
.ev-top { display: flex; justify-content: space-between; gap: 1rem; font-size: .82rem; color: var(--muted); }
.ev-type { font-weight: 700; color: var(--navy-3); text-transform: uppercase; letter-spacing: .03em; }
.ev-udlaant .ev-type { color: #9a3412; }
.ev-fuld_retur .ev-type, .ev-delvis_retur .ev-type, .ev-oprettet .ev-type, .ev-tilfoejet .ev-type { color: var(--lime-dark); }
.ev-body { margin-top: .15rem; }
.ev-note { font-size: .88rem; color: var(--muted); margin-top: .1rem; }
.ev-actor { font-size: .78rem; color: var(--muted); margin-top: .1rem; }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--navy); padding: 1rem; }
.auth-card { background: #fff; border-radius: 18px; padding: 1.6rem; width: 100%; max-width: 420px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.auth-card .auth-logo { color: var(--navy); display: block; text-align: center; font-size: 1.6rem; margin-bottom: .8rem; }
.auth-foot { color: #8fa0c4; font-size: .8rem; }
.forgot { margin: 1rem 0 .5rem; }
.forgot summary { cursor: pointer; color: var(--navy-3); }
.forgot .form { margin-top: .7rem; }

.loading { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.loading.full { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.error-card { border-color: #f3c6b2; }

.toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translate(-50%, 150%); z-index: 50;
  background: var(--navy); color: #fff; padding: .75rem 1.1rem; border-radius: 12px; max-width: min(92vw, 520px);
  box-shadow: 0 8px 30px rgba(0,0,0,.25); transition: transform .2s; font-weight: 600; border-left: 5px solid var(--lime);
}
.toast.show { transform: translate(-50%, 0); }
.toast.error { border-left-color: #fb923c; }

details summary { cursor: pointer; font-weight: 600; }

/* ---------- Mobil ---------- */
@media (max-width: 720px) {
  :root { --nav-h: 62px; }
  h1 { font-size: 1.35rem; }
  main { padding: .9rem .85rem calc(var(--nav-h) + 2rem); }
  .topbar { padding: .6rem .85rem; }
  .logo { font-size: 1.15rem; }
  .org-name { display: none; }
  .mainnav {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: var(--nav-h);
    padding: 0 0 env(safe-area-inset-bottom); justify-content: space-around; gap: 0; background: var(--navy);
    box-shadow: 0 -2px 12px rgba(0,0,0,.2);
  }
  .mainnav a { flex: 1; flex-direction: column; gap: .1rem; padding: .45rem .2rem; font-size: .72rem; border-bottom: 0; border-top: 3px solid transparent; justify-content: center; }
  .mainnav a.active { border-top-color: var(--lime); border-bottom-color: transparent; }
  .mainnav .ico { font-size: 1.15rem; }
  .lbl-long { display: none; }
  .lbl-short { display: inline; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: .7rem; }
  .stats.small { grid-template-columns: repeat(3, 1fr); }
  .stat { padding: .75rem; }
  .stat b { font-size: 1.55rem; }
  .two { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .quick .btn { flex: 1 1 100%; }
  .page-head .add-material { width: 100%; }
  .loan-card { flex-direction: column; }
  .loan-card .btn { width: 100%; }
  .toast { bottom: calc(var(--nav-h) + .8rem); }
  .table th:nth-child(3), .table td:nth-child(3) { font-size: .9rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.inline-form input.days { width: 5.5em; flex: 0 0 auto; min-width: 0; }
.card { overflow-x: auto; }
@media (max-width: 720px) {
  .table th, .table td { padding: .5rem .25rem; font-size: .92rem; }
  .table thead th { font-size: .74rem; }
  .row-actions a { margin-left: .35rem; }
}
.modal-wrap { position: fixed; inset: 0; z-index: 60; background: rgba(13, 22, 44, .55); display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal { background: #fff; border-radius: 16px; padding: 1.3rem; max-width: 420px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal p { margin: 0 0 1.1rem; font-size: 1.05rem; }
.modal-actions { display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap; }
.demo-banner { background: var(--lime); color: var(--navy); text-align: center; font-size: .85rem; font-weight: 650; padding: .35rem .8rem; }
.demo-banner button { margin-left: .5rem; background: var(--navy); color: #fff; border: 0; border-radius: 8px; padding: .2rem .6rem; font: inherit; cursor: pointer; }
