:root {
  --bg: #f4f5f7; --panel: #ffffff; --panel2: #f9fafb; --line: #e5e7eb; --text: #111827; --muted: #6b7280;
  --accent: #f59e0b; --accent-ink: #92400e; --red: #dc2626; --green: #16a34a; --blue: #2563eb;
  --new: #16a34a; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  --r: 10px;
}
:root[data-theme="dark"] {
  --bg: #0d1117; --panel: #161b22; --panel2: #1c222b; --line: #2a313c; --text: #e6edf3; --muted: #8b949e;
  --accent-ink: #fbbf24; --shadow: 0 1px 2px rgba(0,0,0,.4);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --panel: #161b22; --panel2: #1c222b; --line: #2a313c; --text: #e6edf3; --muted: #8b949e;
    --accent-ink: #fbbf24; --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 Inter, system-ui, -apple-system, Segoe UI, sans-serif; background: var(--bg); color: var(--text); display: flex; flex-direction: column; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; cursor: pointer; }
.mini { font-size: 12px; font-weight: 500; }

/* top */
.top { position: relative; z-index: 2500; display: flex; align-items: center; gap: 20px; padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand b { display: block; font-size: 16px; letter-spacing: -.01em; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.kpis { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.kpi { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 12px; cursor: pointer; min-width: 92px; }
.kpi:hover { border-color: var(--accent); }
.kpi b { font-size: 18px; display: block; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi.new b { color: var(--new); }
.kpi.warn b { color: var(--red); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #111; }
.pill { font-size: 12px; color: var(--muted); padding: 4px 10px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); white-space: nowrap; }
.pill.run { color: var(--accent-ink); border-color: var(--accent); }
.pill.run::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 6px; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.menu { position: relative; }
.menu-pop { display: none; position: absolute; right: 0; top: 110%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); z-index: 2000; min-width: 260px; padding: 4px; }
.menu-pop.on { display: block; }
.menu-pop a { display: block; padding: 8px 10px; color: var(--text); border-radius: 6px; }
.menu-pop a:hover { background: var(--panel2); text-decoration: none; }
.menu-who { padding: 8px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-who small { color: var(--muted); }
[hidden] { display: none !important; }

/* innlogging */
.auth-page { align-items: center; justify-content: center; padding: 24px 16px; min-height: 100%; height: auto; }
.auth { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 28px 24px; }
.auth .brand { margin-bottom: 18px; }
.auth h2 { margin: 12px 0 4px; font-size: 20px; }
.auth .sub { color: var(--muted); margin: 0 0 14px; font-size: 13px; }
.auth .field { margin-bottom: 12px; }
.auth label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.auth input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); color: var(--text); font: inherit; }
.auth input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.auth .hint { margin: 4px 0 0; }
.auth .btn.primary { width: 100%; padding: 10px; margin-top: 6px; }
.auth .err { background: #fee2e2; color: #991b1b; padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.auth-switch { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.auth-switch button { flex: 1; border: 0; background: var(--panel2); padding: 8px; font-weight: 600; }
.auth-switch button[aria-pressed="true"] { background: var(--accent); color: #111; }

.tabs { display: flex; gap: 2px; padding: 0 18px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tabs .badge { margin-left: 6px; }

main { flex: 1; min-height: 0; }
.tab { display: none; height: 100%; }
.tab.on { display: flex; }
.tab.pad { padding: 18px; overflow: auto; display: none; }
.tab.pad.on { display: block; }

/* oversikt */
#tab-oversikt { display: none; }
#tab-oversikt.on { display: grid; grid-template-columns: 260px minmax(380px, 1fr) minmax(320px, 42%); min-height: 0; }
.filters { padding: 14px; border-right: 1px solid var(--line); overflow: auto; background: var(--panel); }
.filters input[type=search], .filters select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); color: var(--text); font: inherit; }
.fgroup { margin-top: 14px; }
.fgroup > label { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.fgroup.row { display: flex; flex-direction: column; gap: 6px; }
.chk { display: flex; gap: 6px; align-items: center; font-size: 13px; cursor: pointer; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.seg { display: flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--panel2); padding: 6px 4px; font-size: 12px; font-weight: 500; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #111; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 3px 9px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; user-select: none; }
.chip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.chip.on { border-color: var(--text); font-weight: 600; }
.chip small { color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); margin-top: 18px; }

.listwrap { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.listhead { display: flex; justify-content: space-between; padding: 10px 14px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); background: var(--panel); }
.list { overflow: auto; padding: 8px 12px 40px; flex: 1; }
.grp-h { position: sticky; top: -8px; z-index: 2; background: var(--bg); padding: 10px 2px 6px; font-weight: 700; font-size: 13px; display: flex; justify-content: space-between; }
.grp-h small { color: var(--muted); font-weight: 500; }
.grp-h.l1 { font-size: 15px; letter-spacing: -.01em; border-bottom: 2px solid var(--accent); margin-top: 6px; }
.grp-h.l2 { top: 22px; color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: .06em; }

.card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px 10px 56px; margin: 6px 0; cursor: pointer; box-shadow: var(--shadow); transition: border-color .1s; }
.card:hover, .card.hl { border-color: var(--accent); }
.card.seen-0::after { content: ""; position: absolute; left: -1px; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--new); }
.card.na { opacity: .55; }
.score { position: absolute; left: 10px; top: 10px; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; }
.s-hi { background: #dc2626; } .s-md { background: #f59e0b; color: #111; } .s-lo { background: #9ca3af; }
.card h4 { margin: 0 0 2px; font-size: 14px; font-weight: 600; line-height: 1.3; }
.card .meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.card .tags { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); white-space: nowrap; }
.tag.cat { color: #fff; border: 0; }
.badge { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 6px; border-radius: 4px; }
.b-new { background: var(--new); color: #fff; }
.b-open { background: #dbeafe; color: #1e40af; }
.b-early { background: #ede9fe; color: #5b21b6; }
.b-res { background: #e5e7eb; color: #374151; }
.b-exp { background: #fee2e2; color: #991b1b; }
.b-pipe { background: #fef3c7; color: #92400e; }
.dl-soon { color: var(--red); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

.mapwrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--panel2); }
.legend { position: absolute; right: 10px; bottom: 22px; z-index: 500; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 11px; box-shadow: var(--shadow); max-width: 220px; }
.legend div { display: flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.mk { border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 10px; }
.mk.approx { border-style: dashed; }
.leaflet-popup-content { font: 13px/1.4 Inter, system-ui, sans-serif; }
.marker-cluster div { font-weight: 700; }

/* drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.3); opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 3000; }
.drawer-bg.on { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--panel); z-index: 3001; transform: translateX(100%); transition: transform .2s ease; overflow: auto; box-shadow: -8px 0 30px rgba(0,0,0,.2); }
.drawer.on { transform: none; }
.d-head { position: sticky; top: 0; background: var(--panel); border-bottom: 1px solid var(--line); padding: 14px 20px; z-index: 5; }
.d-head h2 { margin: 6px 0 4px; font-size: 19px; line-height: 1.3; letter-spacing: -.01em; }
.d-close { position: absolute; right: 12px; top: 10px; border: 0; background: none; font-size: 22px; color: var(--muted); }
.d-body { padding: 16px 20px 60px; }
.d-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.d-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 12px 0; }
.d-grid div { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.d-grid span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.d-grid b { font-size: 14px; }
.sec { margin-top: 20px; }
.sec h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.people { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.person { border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 13px; }
.person b { display: block; }
.person .role { font-size: 11px; color: var(--muted); }
.why li { margin: 2px 0; }
.desc { white-space: pre-wrap; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th, table.t td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--panel2); position: sticky; top: 0; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--panel2); }
details.raw summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details.raw td:first-child { color: var(--muted); width: 40%; }
textarea { width: 100%; min-height: 80px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font: inherit; background: var(--panel2); color: var(--text); }
select.pipe { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font: inherit; }
.timeline { border-left: 2px solid var(--line); margin-left: 6px; padding-left: 14px; }
.timeline div { position: relative; margin-bottom: 8px; font-size: 13px; }
.timeline div::before { content: ""; position: absolute; left: -20px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }

/* andre faner */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.panel h2 { margin: 0 0 4px; font-size: 17px; }
.panel p.sub { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.two { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.kanban { display: grid; grid-template-columns: repeat(6, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; align-items: start; }
.col { background: var(--panel2); border: 1px solid var(--line); border-radius: var(--r); padding: 8px; min-height: 200px; }
.col h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; margin: 4px 4px 8px; display: flex; justify-content: space-between; }
.col.drop { outline: 2px dashed var(--accent); }
.col .card { padding-left: 12px; }
.col .card .score { position: static; width: auto; height: auto; display: inline-block; border-radius: 4px; padding: 0 5px; font-size: 11px; margin-right: 4px; }
.week h3 { margin: 18px 0 6px; font-size: 14px; }
.bar { height: 6px; border-radius: 3px; background: var(--accent); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(80px); background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; transition: transform .2s; z-index: 4000; font-size: 13px; }
.toast.on { transform: translateX(-50%); }

@media (max-width: 1100px) {
  #tab-oversikt.on { grid-template-columns: 1fr; grid-template-rows: auto 340px auto; overflow: auto; }
  .filters { border-right: 0; border-bottom: 1px solid var(--line); }
  .mapwrap { order: -1; height: 340px; }
  .listwrap { border-right: 0; }
  .list { overflow: visible; }
  .two { grid-template-columns: 1fr; }
  .legend { display: none; }
  body { height: auto; }
}
@media (max-width: 600px) {
  .top { padding: 10px 16px; gap: 10px; }
  .kpi { min-width: 70px; }
  .kanban { grid-template-columns: repeat(6, 80vw); }
}
