*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 400 var(--fs-m)/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1 { font-size: var(--fs-xl); line-height: 1.2; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: var(--fs-l); line-height: 1.3; margin: 0 0 var(--space-3); font-weight: 600; }
h3 { font-size: var(--fs-m); margin: 0 0 var(--space-2); font-weight: 600; }
p { margin: 0 0 var(--space-3); }
a { color: var(--accent); text-underline-offset: 2px; }
.muted { color: var(--text-muted); } .dim { color: var(--text-dim); } .small { font-size: var(--fs-s); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.icon { flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Skall */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.shell[data-collapsed="true"] { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); }
.sidebar-inner { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: var(--space-1);
  padding: var(--space-4) var(--space-3); overflow-y: auto; }
.brand { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-1) var(--space-2) var(--space-4); font-weight: 700; }
.logo { width: 28px; height: 28px; color: var(--logo-1); fill: var(--logo-2); flex: none; }
.nav-link { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); border-radius: var(--radius-s);
  color: var(--text-muted); text-decoration: none; font-weight: 500; }
.nav-link:hover { background: var(--surface-hover); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); }
.nav-failed { font-size: var(--fs-s); color: var(--danger); padding: var(--space-2) var(--space-3); }
.shell[data-collapsed="true"] .nav-label, .shell[data-collapsed="true"] .brand-name { display: none; }
.collapse-btn { margin-top: auto; border: 0; background: none; font: inherit; cursor: pointer; width: 100%; text-align: left; }
.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; height: var(--topbar-h); display: flex; align-items: center; gap: var(--space-3);
  padding: 0 var(--space-5); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.week-picker { display: flex; align-items: center; gap: var(--space-1); }
.week-label { min-width: 170px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.topbar-spacer { flex: 1; }
.search-btn { justify-content: flex-start; min-width: 240px; color: var(--text-muted); }
.search-btn kbd { margin-left: auto; }
.content { padding: var(--space-5); max-width: 1280px; width: 100%; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); flex-wrap: wrap; }
.page-actions { display: flex; gap: var(--space-2); margin-left: auto; }
.bottomnav { display: none; }
.user-menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-m); box-shadow: var(--shadow-2); padding: var(--space-2); z-index: 20; }
.menu-pop[hidden] { display: none; }
.menu-item { display: flex; width: 100%; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border: 0; background: none;
  color: var(--text); border-radius: var(--radius-s); cursor: pointer; font: inherit; text-align: left; }
.menu-item:hover { background: var(--surface-hover); }
.menu-item[aria-pressed="true"] { color: var(--accent-text); font-weight: 600; }
.menu-check { display: inline-grid; width: 18px; height: 18px; }
.avatar { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-weight: 650; font-size: 13px; }

@media (max-width: 1023px) {
  .shell, .shell[data-collapsed="true"] { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar { padding: 0 var(--space-4); gap: var(--space-2); }
  .week-label { min-width: 0; font-size: var(--fs-s); }
  .topbar .search-btn { width: 36px; min-width: 0; padding: 0; justify-content: center; flex: none; }
  .user-menu { flex: none; }
  .user-menu > .btn { width: 36px; padding: 0; justify-content: center; }
  .week-picker .week-now { display: none; }
  .user-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .search-btn .search-text, .search-btn kbd { display: none; }
  .content { padding: var(--space-4) var(--space-4) calc(var(--bottomnav-h) + var(--space-5)); }
  .bottomnav { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    height: var(--bottomnav-h); 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; justify-content: center; gap: 2px;
    font: 500 11px var(--font); color: var(--text-muted); text-decoration: none; background: none; border: 0; cursor: pointer; }
  .bottomnav [aria-current="page"] { color: var(--accent); }
  h1 { font-size: var(--fs-l); }
}

/* Kort, knapper, skjema */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-l); box-shadow: var(--shadow-1); padding: var(--space-5); min-width: 0; }
.card + .card { margin-top: var(--space-4); }
.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.row { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; gap: var(--space-2); height: 36px; padding: 0 var(--space-4); border-radius: var(--radius-s);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: 500 var(--fs-m) var(--font); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { color: var(--danger); }
.btn-icon { width: 36px; padding: 0; justify-content: center; }
.btn-sm { height: 30px; padding: 0 var(--space-3); font-size: var(--fs-s); }
.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.field label { font-size: var(--fs-s); font-weight: 600; color: var(--text-muted); }
.input, .select, .textarea { width: 100%; min-width: 0; height: 36px; padding: 0 var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-s);
  background: var(--surface); color: var(--text); font: inherit; }
.textarea { height: auto; min-height: 88px; padding: var(--space-2) var(--space-3); resize: vertical; line-height: 1.5; }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: var(--fs-s); }
.notice { display: flex; gap: var(--space-2); align-items: flex-start; padding: var(--space-3) var(--space-4); border-radius: var(--radius-m); font-size: var(--fs-s); }
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.notice-danger { background: var(--danger-soft); color: var(--danger); }
.notice-info { background: var(--info-soft); color: var(--info); }
kbd, .kbd { font: 500 11px var(--mono); padding: 1px 6px; border: 1px solid var(--border); border-radius: 4px; color: var(--text-muted); background: var(--surface-2); }

/* Piller: alltid tekst, ikke bare farge */
.pill { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 var(--space-2); border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--neutral-soft); color: var(--text-muted); }
.pill-ok { background: var(--ok-soft); color: var(--ok); } .pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); } .pill-info { background: var(--info-soft); color: var(--info); }
.pill[hidden] { display: none; }
.pill-accent { background: var(--accent-soft); color: var(--accent-text); }

/* Tabeller: tall høyrejustert med tabular-nums */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-m); }
.table th { text-align: left; font-size: var(--fs-s); font-weight: 600; color: var(--text-muted); padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); }
.table td { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.num, .table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .input.num { max-width: 96px; margin-left: auto; display: block; }

/* Tabs */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); margin-bottom: var(--space-4); overflow-x: auto; }
.tab { border: 0; background: none; padding: var(--space-2) var(--space-3); color: var(--text-muted); font: 500 var(--fs-m) var(--font);
  border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tab[aria-selected="true"], .tab[aria-current="page"] { color: var(--accent-text); border-bottom-color: var(--accent); }

/* Tom tilstand, skjelett, toast */
.empty-state { text-align: center; padding: var(--space-7) var(--space-4); color: var(--text-muted); }
.empty-state h3 { color: var(--text); }
.skeleton { display: grid; gap: var(--space-2); }
.skeleton span { display: block; height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--surface-hover), var(--surface-2));
  background-size: 200% 100%; animation: shimmer 1.2s infinite; }
.skeleton span:nth-child(3n) { width: 60%; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton span { animation: none; } }
.toast-region { position: fixed; right: var(--space-4); bottom: var(--space-4); display: grid; gap: var(--space-2); z-index: 50; }
@media (max-width: 1023px) { .toast-region { left: var(--space-4); bottom: calc(var(--bottomnav-h) + var(--space-3)); } }
.toast { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
  background: var(--text); color: var(--bg); border-radius: var(--radius-m); box-shadow: var(--shadow-2); font-size: var(--fs-s); }
.toast .btn { height: 28px; background: transparent; color: inherit; border-color: color-mix(in srgb, var(--bg) 40%, transparent); }

/* Kommandopalett */
.palette-backdrop { position: fixed; inset: 0; background: rgb(10 8 20 / 0.45); display: grid; justify-items: center; align-items: start; padding-top: 12vh; z-index: 60; }
.palette-backdrop[hidden] { display: none; }
.palette { width: min(560px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-l); box-shadow: var(--shadow-2); overflow: hidden; }
.palette input { width: 100%; border: 0; border-bottom: 1px solid var(--border); padding: var(--space-4); font: inherit; font-size: 16px; background: transparent; color: var(--text); outline: none; }
.palette ul { list-style: none; margin: 0; padding: var(--space-2); max-height: 50vh; overflow-y: auto; }
.palette:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.palette li { padding: var(--space-2) var(--space-3); border-radius: var(--radius-s); cursor: pointer; display: flex; justify-content: space-between; gap: var(--space-3); }
.palette li[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }

/* Fremdriftsring (Hjem) og kanban (outreach) */
.ring { display: grid; justify-items: center; gap: var(--space-2); text-align: center; }
.ring svg { width: 96px; height: 96px; }
.ring-track { stroke: var(--surface-2); } .ring-value { stroke: var(--accent); transition: stroke-dashoffset 0.4s; }
.ring-num { font-size: var(--fs-l); font-weight: 650; font-variant-numeric: tabular-nums; }
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(170px, 1fr); gap: var(--space-3); overflow-x: auto; padding-bottom: var(--space-2); }
.kanban-col { background: var(--surface-2); border-radius: var(--radius-l); padding: var(--space-3); min-height: 160px; }
.kanban-col[data-over="true"] { outline: 2px dashed var(--accent); }
.kanban-col h3 { display: flex; justify-content: space-between; font-size: var(--fs-s); color: var(--text-muted); }
.kanban-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m); padding: var(--space-3); margin-top: var(--space-2); cursor: grab; box-shadow: var(--shadow-1); }
.kanban-card:focus-visible { outline: 2px solid var(--focus); }
@media (max-width: 1023px) { .kanban { grid-auto-flow: row; grid-auto-columns: auto; } .kanban-col { min-height: 0; } }

/* Innlogging */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--space-4); }
.login-card { width: min(380px, 100%); }
.login-card .brand { padding: 0 0 var(--space-2); }
.login-card .logo { width: 32px; height: 32px; }
.login-card form { display: grid; gap: var(--space-4); }
a.tab { text-decoration: none; display: inline-block; }
.page-body > * + * { margin-top: var(--space-4); }
form.card .row { margin-top: var(--space-3); }
.card p.small { white-space: pre-wrap; }
.filter-bar { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.filter-bar .select { width: auto; min-width: 160px; }
@media (max-width: 1023px) { .filter-bar .select { flex: 1 1 100%; } }
.select-sm { height: 30px; font-size: var(--fs-s); }
.tnum { font-variant-numeric: tabular-nums; }

/* Metrics */
#trend { width: 100% !important; height: 260px !important; }
.chart-box { position: relative; height: 260px; }
.table tbody th[scope="rowgroup"] { padding-top: var(--space-4); color: var(--text); font-size: var(--fs-m); }
@media (max-width: 1023px) { .table .input.num { width: 64px; padding: 0 6px; } }
.src-inline { display: none; }
.src-sub { display: none; }
@media (max-width: 1023px) { .col-hide-m { display: none; } .src-sub { display: block; } }
@media (max-width: 1023px) { .col-src { display: none; } .src-inline { display: flex; margin-top: 2px; } }

/* Ukesmøte */
fieldset { border: 0; padding: 0; margin: var(--space-3) 0; min-width: 0; }
legend { padding: 0; margin-right: var(--space-2); }
.page-body section + section, .page-body .card + section, .page-body section + .card { margin-top: var(--space-4); }
.page-body .kanban > *, .page-body .cal-week > *, .page-body .cal-month > * { margin-top: 0; }
details.card summary { cursor: pointer; font-weight: 600; }
.tab-short { display: none; }
@media (max-width: 1023px) { .tab-long { display: none; } .tab-short { display: inline; } }

.cal-week { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: var(--space-2); }
.cal-item { display: block; width: 100%; text-align: left; font: inherit; color: inherit; }
.cal-month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--space-1); }
.cal-cell { min-height: 96px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-s); padding: var(--space-1); min-width: 0; }
.cal-cell .kanban-card { padding: var(--space-1) var(--space-2); }
@media (max-width: 1023px) {
  .cal-week { grid-template-columns: minmax(0, 1fr); }
  .cal-month { grid-template-columns: minmax(0, 1fr); }
  .cal-head, .cal-cell:empty { display: none; }
  .cal-cell { min-height: 0; }
}
.is-today { outline: 2px solid var(--accent); outline-offset: -2px; }

.widget-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.widget-list li { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.widget-stats { display: grid; grid-template-columns: 1fr auto; gap: var(--space-2) var(--space-4); margin: 0 0 var(--space-3); align-items: center; }
.widget-stats dd { margin: 0; text-align: right; }
.stat-num { font-size: var(--fs-l); font-weight: 650; }
.today-line { margin: calc(-1 * var(--space-4)) 0 var(--space-4); }
.stat-lead { font-size: var(--fs-l); font-weight: 600; margin: 0 0 var(--space-3); }
a.btn { text-decoration: none; }
@media (max-width: 1023px) {
  .rings-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ring svg { width: 64px; height: 64px; }
  .ring-num { font-size: var(--fs-m); }
}
.page-body .grid > .card.card, .page-body .grid > * + .card.card { margin-top: 0; }
.page-body .card + .grid { margin-top: var(--space-4); }

.widget-list a { color: var(--text); text-decoration: none; }
.widget-list a:hover, .widget-list a:focus-visible { text-decoration: underline; }
