/* assets/css/common.css — felles layout + ALLE komponenter (jf. _utviklingsspesifikasjon.md § 6).
   Bruker KUN tokens fra tokens.css. Oxblood (--c-accent) er eneste fargeaksent, gull kun hårstrek. */

/* ===== Base / typografi ===== */
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  font-weight: 400;
  line-height: 1.65;
  color: var(--c-text);
  background: var(--c-bg);
  font-feature-settings: "ss01","ss02";
}
h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: var(--c-text);
}
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }
p { margin: 0 0 var(--s-3); }
a.lenke, .lenke { color: var(--c-accent); text-decoration: underline; text-underline-offset: 2px; }
a.lenke:hover { color: var(--c-accent-soft); }
strong, b { font-weight: 600; }
code, .mono { font-family: var(--font-mono); font-size: 0.92em; }
small { font-size: var(--fs-xs); color: var(--c-text-light); }
::selection { background: var(--c-accent); color: var(--c-bg); }

/* ===== Ikoner (inline SVG sprite via <svg class="icon"><use href="...#id"/>) ===== */
.icon { width: 18px; height: 18px; display: inline-block; vertical-align: middle; fill: none;
  stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon--sm { width: 14px; height: 14px; }
.icon--lg { width: 22px; height: 22px; }
.icon--xl { width: 32px; height: 32px; }

/* ===== App-shell layout ===== */
.app-shell { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 56px 1fr;
  grid-template-areas: "sidebar topbar" "sidebar content"; height: 100vh; }
.app-shell.is-collapsed { grid-template-columns: 60px 1fr; }

.sidebar { grid-area: sidebar; background: var(--c-surface); border-right: 1px solid var(--c-border);
  display: flex; flex-direction: column; overflow: hidden; }
.sidebar__brand { display: flex; align-items: center; gap: var(--s-2); height: 56px; padding: 0 var(--s-4);
  border-bottom: 1px solid var(--c-border-soft); }
.sidebar__brand .logo-mark { width: 28px; height: 28px; border-radius: var(--r-sm); flex: none; }
.sidebar__brand .brand-name { font-family: var(--font-serif); font-size: var(--fs-lg); font-weight: 500; white-space: nowrap; }
.app-shell.is-collapsed .brand-name, .app-shell.is-collapsed .nav-link__label { display: none; }
.sidebar__nav { flex: 1; overflow-y: auto; padding: var(--s-3) var(--s-2); }
.sidebar__section { margin: var(--s-4) 0 var(--s-1); padding: 0 var(--s-3); }
.nav-link { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md); color: var(--c-text-muted); font-size: var(--fs-md); cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast); width: 100%; text-align: left; }
.nav-link:hover { background: var(--c-surface-alt); color: var(--c-text); }
.nav-link.is-active { background: var(--c-accent-bg); color: var(--c-accent); font-weight: 500; }
.nav-link.is-active .icon { stroke: var(--c-accent); }

.topbar { grid-area: topbar; background: var(--c-surface); border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 var(--s-5); gap: var(--s-4); }
.topbar__left { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.topbar__right { display: flex; align-items: center; gap: var(--s-3); }
.iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px;
  border-radius: var(--r-md); color: var(--c-text-muted); transition: background var(--t-fast); position: relative; }
.iconbtn:hover { background: var(--c-surface-alt); color: var(--c-text); }
.user-chip { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-1) var(--s-2);
  border-radius: var(--r-md); cursor: pointer; }
.user-chip:hover { background: var(--c-surface-alt); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--c-accent); color: var(--c-bg);
  display: inline-flex; align-items: center; justify-content: center; font-size: var(--fs-sm); font-weight: 600; flex: none; }

.content { grid-area: content; overflow-y: auto; }
#module-root { max-width: 1280px; margin: 0 auto; padding: var(--s-6); }
.two-col { display: grid; grid-template-columns: 1fr 320px; gap: var(--s-6); align-items: start; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }

/* ===== Editorialt særpreg ===== */
.overline, .eyebrow { font-family: var(--font-sans); text-transform: uppercase; letter-spacing: 0.14em;
  font-size: var(--fs-xs); font-weight: 600; color: var(--c-accent); }
.rule-gold { height: 1px; background: var(--c-gold); border: 0; opacity: 0.55; margin: var(--s-3) 0; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4);
  margin-bottom: var(--s-5); padding-bottom: var(--s-3); border-bottom: 1px solid var(--c-border); }
.page-header__main { min-width: 0; }
.page-title { font-family: var(--font-serif); font-size: var(--fs-4xl); font-weight: 500;
  letter-spacing: -0.015em; line-height: 1.1; color: var(--c-text); }
.page-title--accent { color: var(--c-accent); }
.page-subtitle { color: var(--c-text-light); font-size: var(--fs-md); margin-top: var(--s-1); }

/* ===== Knapper ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  font-family: var(--font-sans); font-size: var(--fs-md); font-weight: 500; line-height: 1;
  padding: var(--s-3) var(--s-4); border-radius: var(--r-md); border: 1px solid transparent;
  cursor: pointer; transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), opacity var(--t-fast);
  white-space: nowrap; user-select: none; }
.btn:disabled, .btn.is-disabled { opacity: 0.5; cursor: not-allowed; }
.btn .icon { width: 16px; height: 16px; }
.btn--primary { background: var(--c-accent); color: var(--c-bg); }
.btn--primary:hover:not(:disabled) { background: var(--c-accent-soft); }
.btn--secondary { background: var(--c-surface); color: var(--c-text); border-color: var(--c-border); }
.btn--secondary:hover:not(:disabled) { background: var(--c-surface-alt); border-color: var(--c-text-light); }
.btn--ghost { background: transparent; color: var(--c-text-muted); }
.btn--ghost:hover:not(:disabled) { background: var(--c-surface-alt); color: var(--c-text); }
.btn--danger { background: var(--c-danger); color: var(--c-bg); }
.btn--danger:hover:not(:disabled) { background: #94403b; }
.btn--sm { padding: var(--s-2) var(--s-3); font-size: var(--fs-sm); }
.btn--lg { padding: var(--s-4) var(--s-6); font-size: var(--fs-lg); }
.btn--block { width: 100%; }

/* ===== Skjema ===== */
.field-group { margin-bottom: var(--s-4); }
.field-group > label { display: block; font-size: var(--fs-sm); font-weight: 500; color: var(--c-text-muted);
  margin-bottom: var(--s-2); }
.field-hint { font-size: var(--fs-xs); color: var(--c-text-light); margin-top: var(--s-1); }
.input, .select, .textarea {
  width: 100%; font-family: var(--font-sans); font-size: var(--fs-md); color: var(--c-text);
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md);
  padding: var(--s-3) var(--s-3); transition: border-color var(--t-fast), box-shadow var(--t-fast); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-accent-bg); }
.input::placeholder, .textarea::placeholder { color: var(--c-text-light); }
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237B716A' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right var(--s-3) center; padding-right: var(--s-6); }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--c-danger); }
.field-error { display: block; color: var(--c-danger); font-size: var(--fs-xs); margin-top: var(--s-1); min-height: 1em; }

/* ===== Egendefinert dropdown (assets/js/select.js) — lik på tvers av nettlesere =====
   Den native <select class="select"> beholdes som skjult modell (sr-only, men «synlig» for
   Playwright/skjermleser). Knappen speiler .select-utseendet; panelet portaleres til <body>. */
.km-select { position: relative; display: inline-block; width: 100%; vertical-align: middle; }
.km-select__native {
  position: absolute !important; width: 1px; height: 1px; margin: 0; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); opacity: 0; pointer-events: none; }
.km-select__btn {
  display: flex; align-items: center; gap: var(--s-2); width: 100%; text-align: left; cursor: pointer;
  font-family: var(--font-sans); font-size: var(--fs-md); color: var(--c-text);
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md);
  padding: var(--s-3) var(--s-3); transition: border-color var(--t-fast), box-shadow var(--t-fast); }
.km-select__btn:hover { border-color: var(--c-border-soft); }
.km-select__btn:focus-visible, .km-select.is-open .km-select__btn {
  outline: none; border-color: var(--c-accent); box-shadow: 0 0 0 3px var(--c-accent-bg); }
.km-select__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.km-select__label--placeholder { color: var(--c-text-light); }
.km-select__chevron { display: inline-flex; color: var(--c-text-light); flex-shrink: 0;
  transition: transform var(--t-fast); }
.km-select.is-open .km-select__chevron { transform: rotate(180deg); }
.km-select.is-disabled { opacity: 0.6; }
.km-select.is-disabled .km-select__btn { cursor: not-allowed; background: var(--c-surface-alt); }

.km-select__panel {
  z-index: 1090; /* over modal (1000), under toast (1100) */
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg); padding: var(--s-1); overflow-y: auto;
  font-family: var(--font-sans); font-size: var(--fs-md); color: var(--c-text);
  animation: km-select-in var(--t-fast); }
@keyframes km-select-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.km-select__opt {
  padding: var(--s-2) var(--s-3); border-radius: var(--r-sm); cursor: pointer; line-height: 1.4;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.km-select__opt:hover, .km-select__opt.is-active { background: var(--c-surface-alt); }
.km-select__opt.is-selected { color: var(--c-accent); font-weight: 500; }
.km-select__opt.is-selected.is-active { background: var(--c-accent-bg); }
.km-select__opt.is-disabled { color: var(--c-text-light); cursor: default; }
.km-select__opt.is-disabled:hover { background: transparent; }
.input--money { font-family: var(--font-mono); text-align: right; }

.checkbox, .radio { display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer; font-size: var(--fs-md); }
.checkbox input, .radio input { width: 16px; height: 16px; accent-color: var(--c-accent); cursor: pointer; }
.field-row { display: flex; gap: var(--s-4); }
.field-row > .field-group { flex: 1; }

/* ===== Kort / paneler ===== */
.card, .panel { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg);
  padding: var(--s-5); }
.card { box-shadow: var(--shadow-sm); }
.panel { box-shadow: none; }
.card__header, .panel__header { display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3); margin-bottom: var(--s-4); }
.card__title, .panel__title { font-family: var(--font-serif); font-size: var(--fs-lg); font-weight: 500; }

/* ===== Stat-card (dashboard) ===== */
.stat-card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg);
  padding: var(--s-5); display: flex; flex-direction: column; gap: var(--s-2); }
.stat-card__label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--c-accent); font-weight: 600; }
.stat-card__value { font-family: var(--font-serif); font-size: var(--fs-4xl); font-weight: 500;
  line-height: 1; color: var(--c-text); font-variant-numeric: tabular-nums; }
.stat-card__meta { font-size: var(--fs-sm); color: var(--c-text-light); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--s-4); }

/* ===== Tabeller ===== */
.table-wrap { overflow-x: auto; border: 1px solid var(--c-border); border-radius: var(--r-lg); background: var(--c-surface); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
.table thead th { position: sticky; top: 0; z-index: 1; background: var(--c-surface-alt);
  text-align: left; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 600; color: var(--c-text-muted); padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--c-border); white-space: nowrap; }
.table tbody td { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--c-border-soft); vertical-align: middle; }
.table tbody tr:nth-child(even) { background: var(--c-surface-alt); }
.table tbody tr:hover { background: var(--c-accent-bg); }
.table tbody tr:last-child td { border-bottom: none; }
.table .num, .table th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .col-actions { text-align: right; white-space: nowrap; }
.table--clickable tbody tr { cursor: pointer; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable .icon { opacity: 0.4; }
th.sortable.is-sorted .icon { opacity: 1; stroke: var(--c-accent); }

/* ===== Badge / tag ===== */
.badge { display: inline-flex; align-items: center; gap: var(--s-1); font-size: var(--fs-xs); font-weight: 600;
  padding: 2px var(--s-2); border-radius: 999px; line-height: 1.5; white-space: nowrap; }
.badge--neutral { background: var(--c-surface-deep); color: var(--c-text-muted); }
.badge--success { background: #E4EDE6; color: var(--c-success); }
.badge--warning { background: #F6E9D6; color: var(--c-warning); }
.badge--danger  { background: var(--c-accent-bg); color: var(--c-danger); }
.badge--info    { background: var(--c-surface-deep); color: var(--c-info); }
.badge--accent  { background: var(--c-accent); color: var(--c-bg); }
.tag { display: inline-flex; align-items: center; gap: var(--s-1); font-size: var(--fs-sm);
  padding: 2px var(--s-2); border-radius: var(--r-sm); background: var(--c-surface-alt);
  border: 1px solid var(--c-border); color: var(--c-text-muted); }

/* ===== Tabs / breadcrumb / pagination ===== */
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--c-border); margin-bottom: var(--s-5); }
.tab { padding: var(--s-3) var(--s-4); font-size: var(--fs-md); color: var(--c-text-muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color var(--t-fast), border-color var(--t-fast); }
.tab:hover { color: var(--c-text); }
.tab.is-active { color: var(--c-accent); border-bottom-color: var(--c-accent); font-weight: 500; }

.breadcrumb { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-sm); color: var(--c-text-light); }
.breadcrumb a { cursor: pointer; }
.breadcrumb a:hover { color: var(--c-accent); }
.breadcrumb .icon { width: 14px; height: 14px; opacity: 0.6; }

.pagination { display: flex; align-items: center; gap: var(--s-2); justify-content: flex-end; margin-top: var(--s-4); }
.pagination__info { font-size: var(--fs-sm); color: var(--c-text-light); margin-right: auto; }
.page-btn { min-width: 34px; height: 34px; padding: 0 var(--s-2); border-radius: var(--r-md);
  border: 1px solid var(--c-border); background: var(--c-surface); color: var(--c-text-muted);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.page-btn:hover:not(:disabled) { background: var(--c-surface-alt); }
.page-btn.is-active { background: var(--c-accent); color: var(--c-bg); border-color: var(--c-accent); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Empty state / skeleton ===== */
.empty-state { text-align: center; padding: var(--s-8) var(--s-5); color: var(--c-text-light); }
.empty-state .icon { width: 40px; height: 40px; stroke-width: 1.25; opacity: 0.5; margin: 0 auto var(--s-3); }
.empty-state__title { font-family: var(--font-serif); font-size: var(--fs-xl); color: var(--c-text-muted); margin-bottom: var(--s-2); }
.skeleton-loader, .skeleton { background: linear-gradient(90deg, var(--c-surface-alt) 25%, var(--c-surface-deep) 50%, var(--c-surface-alt) 75%);
  background-size: 200% 100%; animation: km-shimmer 1.3s ease-in-out infinite; border-radius: var(--r-sm); height: 1em; }
@keyframes km-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ===== Alert / banner ===== */
.alert { display: flex; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-radius: var(--r-md);
  border: 1px solid var(--c-border); background: var(--c-surface-alt); font-size: var(--fs-md);
  align-items: flex-start; }
.alert .icon { flex: none; margin-top: 1px; }
.alert__body { min-width: 0; }
.alert__title { font-weight: 600; margin-bottom: 2px; }
.alert--info    { background: var(--c-surface-deep); border-color: var(--c-border); color: var(--c-info); }
.alert--success { background: #E9F1EB; border-color: #CBDCD0; color: var(--c-success); }
.alert--warning { background: #F8EEDD; border-color: #ECD9B8; color: var(--c-warning); }
.alert--danger  { background: var(--c-accent-bg); border-color: #E4C4BE; color: var(--c-danger); }
.banner { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-5);
  background: var(--c-accent); color: var(--c-bg); font-size: var(--fs-md); }
.banner--gold { background: var(--c-surface-deep); color: var(--c-text); border-bottom: 1px solid var(--c-gold); }

/* ===== Modal / dialog / overlay ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(26,22,20,0.45); display: flex;
  align-items: center; justify-content: center; padding: var(--s-5); z-index: 1000;
  opacity: 0; animation: km-fade var(--t-base) forwards; }
@keyframes km-fade { to { opacity: 1; } }
.modal { background: var(--c-surface); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
  border: 1px solid var(--c-border); }
.modal--wide { max-width: 860px; }
.modal__header { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--c-border-soft); }
.modal__title { font-family: var(--font-serif); font-size: var(--fs-xl); font-weight: 500; }
.modal__body { padding: var(--s-5); overflow-y: auto; }
.modal__footer { display: flex; justify-content: flex-end; gap: var(--s-3); padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--c-border-soft); background: var(--c-surface-alt); }
.dialog { max-width: 420px; }
.dialog__message { color: var(--c-text-muted); }

/* ===== Toast ===== */
.toast-stack { position: fixed; bottom: var(--s-5); right: var(--s-5); display: flex; flex-direction: column;
  gap: var(--s-2); z-index: 1100; }
.toast { display: flex; align-items: center; gap: var(--s-3); min-width: 260px; max-width: 380px;
  padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--c-surface);
  border: 1px solid var(--c-border); box-shadow: var(--shadow-md); font-size: var(--fs-md);
  animation: km-toast-in var(--t-base); }
@keyframes km-toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.toast--success { border-left: 3px solid var(--c-success); }
.toast--warning { border-left: 3px solid var(--c-warning); }
.toast--danger  { border-left: 3px solid var(--c-danger); }
.toast--info    { border-left: 3px solid var(--c-info); }
.toast.is-leaving { opacity: 0; transform: translateY(8px); transition: all var(--t-base); }

/* ===== kbd ===== */
.kbd { font-family: var(--font-mono); font-size: var(--fs-xs); padding: 1px var(--s-2);
  border: 1px solid var(--c-border); border-bottom-width: 2px; border-radius: var(--r-sm);
  background: var(--c-surface-alt); color: var(--c-text-muted); }

/* ===== Loader / spinner ===== */
.loader { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--c-border);
  border-top-color: var(--c-accent); border-radius: 50%; animation: km-spin 0.7s linear infinite; }
.loader--lg { width: 32px; height: 32px; border-width: 3px; }
@keyframes km-spin { to { transform: rotate(360deg); } }
.loader-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.6); z-index: 50; }

/* ===== Hjelpeklasser ===== */
.flex { display: flex; } .flex-col { flex-direction: column; } .items-center { align-items: center; }
.justify-between { justify-content: space-between; } .gap-1 { gap: var(--s-1); } .gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); } .gap-4 { gap: var(--s-4); } .flex-wrap { flex-wrap: wrap; }
.mt-2 { margin-top: var(--s-2); } .mt-3 { margin-top: var(--s-3); } .mt-4 { margin-top: var(--s-4); }
.mt-5 { margin-top: var(--s-5); } .mb-3 { margin-bottom: var(--s-3); } .mb-4 { margin-bottom: var(--s-4); }
.ml-auto { margin-left: auto; }
.text-muted { color: var(--c-text-muted); } .text-light { color: var(--c-text-light); }
.text-accent { color: var(--c-accent); } .text-danger { color: var(--c-danger); }
.text-success { color: var(--c-success); } .text-right { text-align: right; }
.text-sm { font-size: var(--fs-sm); } .text-xs { font-size: var(--fs-xs); }
.fw-500 { font-weight: 500; } .fw-600 { font-weight: 600; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.w-full { width: 100%; } .hidden { display: none !important; }
.divider { height: 1px; background: var(--c-border); border: 0; margin: var(--s-4) 0; }
.spacer { flex: 1; }
