/* =============================================================================
   components.css — gjenbrukbare komponenter med fulle tilstander
   hover / focus / active / disabled / loading er definert for alt klikkbart.
========================================================================== */

/* ---------------------------------------------------------------------------
   APP-SKALL: topbar + footer
--------------------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.1) blur(10px);
  border-bottom: var(--hairline) solid var(--line);
}
.topbar__inner {
  height: 100%;
  display: flex; align-items: center; gap: var(--space-6);
  max-width: var(--shell-max); margin-inline: auto;
  padding-inline: var(--space-6);
}
.topbar__brand {
  display: flex; align-items: center; gap: var(--space-3);
  color: var(--ink); font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight); white-space: nowrap;
}
.topbar__brand:hover { text-decoration: none; }
.topbar__logo { height: 22px; width: auto; }
.topbar__nav { display: flex; gap: var(--space-2); margin-inline-start: var(--space-2); }
.topbar__link {
  color: var(--ink-muted); font-size: var(--text-sm); font-weight: var(--weight-medium);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm);
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.topbar__link:hover { color: var(--ink); background: var(--surface-hover); text-decoration: none; }
.topbar__link[aria-current="page"] { color: var(--ink); }
.topbar__spacer { flex: 1; }
.topbar__actions { display: flex; align-items: center; gap: var(--space-3); }

@media (max-width: 720px) {
  .topbar__nav, .topbar__search { display: none; }
  .topbar__inner { gap: var(--space-4); }
}

.footer {
  border-top: var(--hairline) solid var(--line);
  margin-top: var(--space-10);
  color: var(--ink-subtle); font-size: var(--text-xs);
}
.footer__inner {
  max-width: var(--shell-max); margin-inline: auto;
  padding: var(--space-6); display: flex; gap: var(--space-5);
  align-items: center; flex-wrap: wrap;
}

/* ---------------------------------------------------------------------------
   KNAPPER
--------------------------------------------------------------------------- */
.btn {
  --_bg: var(--surface);
  --_ink: var(--ink);
  --_line: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-3);
  height: var(--control-h); padding-inline: var(--space-5);
  font-size: var(--text-sm); font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  color: var(--_ink); background: var(--_bg);
  border: var(--hairline) solid var(--_line);
  border-radius: var(--radius-md);
  cursor: pointer; user-select: none; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: translateY(0.5px) scale(0.992); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); border-color: var(--focus); }
.btn[disabled], .btn[aria-disabled="true"] {
  cursor: not-allowed; opacity: 0.5; transform: none;
}

/* Primær — fylt med --action */
.btn--primary {
  --_bg: var(--action); --_ink: var(--on-action); --_line: var(--action);
}
.btn--primary:hover { background: var(--action-hover); border-color: var(--action-hover); }
.btn--primary:active { background: var(--action-active); border-color: var(--action-active); }

/* Aksent — fylt med --accent (sjeldnere, f.eks. «legg i kurv»-CTA i tema) */
.btn--accent {
  --_bg: var(--accent); --_ink: var(--on-accent); --_line: var(--accent);
}
.btn--accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* Stille — kun tekst, til sekundære valg */
.btn--ghost { --_bg: transparent; --_line: transparent; }
.btn--ghost:hover { background: var(--surface-hover); }

/* Fare */
.btn--danger { --_ink: var(--critical); --_line: var(--line-strong); }
.btn--danger:hover { background: var(--critical-weak); border-color: var(--critical); }

.btn--sm  { height: var(--control-h-sm); padding-inline: var(--space-4); font-size: var(--text-xs); }
.btn--lg  { height: var(--control-h-lg); padding-inline: var(--space-6); font-size: var(--text-md); }
.btn--block { width: 100%; }
.btn--icon { padding-inline: 0; width: var(--control-h); }
.btn .icon { width: 17px; height: 17px; flex: none; }

/* Loading-tilstand: spinner inn, tekst dempet, klikk blokkert */
.btn[data-loading="true"] { pointer-events: none; color: transparent; position: relative; }
.btn[data-loading="true"]::after {
  content: ""; position: absolute; width: 16px; height: 16px;
  border: 2px solid color-mix(in srgb, currentColor 30%, transparent);
  border-top-color: var(--on-action);
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
.btn--primary[data-loading="true"]::after,
.btn--accent[data-loading="true"]::after { border-top-color: var(--on-action); }
.btn:not(.btn--primary):not(.btn--accent)[data-loading="true"]::after { border-top-color: var(--ink); }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------------------
   FELT
--------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--space-3); }
.field__label {
  font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--ink);
  display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-4);
}
.field__hint { font-size: var(--text-xs); color: var(--ink-subtle); }
.field__optional { font-size: var(--text-xs); color: var(--ink-faint); font-weight: var(--weight-regular); }

.input, .select, .textarea {
  height: var(--control-h);
  padding: 0 var(--space-4);
  background: var(--field-bg);
  color: var(--field-ink);
  border: var(--hairline) solid var(--field-line);
  border-radius: var(--field-radius);
  font-size: var(--text-md);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  width: 100%;
}
.textarea { height: auto; padding: var(--space-3) var(--space-4); line-height: var(--leading-base); resize: vertical; min-height: 96px; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-faint); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--focus); box-shadow: var(--focus-ring);
}
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--surface-sunk); color: var(--ink-faint); cursor: not-allowed;
}
/* Validering — aria-invalid driver stilen, ikke en egen klasse */
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] {
  border-color: var(--critical);
}
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--critical) 24%, transparent); }
.field__error {
  font-size: var(--text-xs); color: var(--critical-ink);
  display: flex; align-items: center; gap: var(--space-2);
}

/* Felt med prefiks/suffiks (f.eks. søk, valuta) */
.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-left: calc(var(--space-4) + 22px); }
.input-group__icon {
  position: absolute; left: var(--space-4); color: var(--ink-faint);
  width: 16px; height: 16px; pointer-events: none;
}

/* ---------------------------------------------------------------------------
   OTP — signatur-interaksjonen (kode-på-epost)
--------------------------------------------------------------------------- */
.otp { display: flex; gap: var(--space-3); }
.otp__digit {
  width: 52px; height: 60px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: var(--text-2xl); font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--surface);
  border: var(--hairline) solid var(--field-line);
  border-radius: var(--radius-md);
  caret-color: var(--accent);
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease);
}
.otp__digit:focus { outline: none; border-color: var(--focus); box-shadow: var(--focus-ring); }
.otp__digit[data-filled="true"] { border-color: var(--ink-faint); }
.otp[data-state="error"] .otp__digit { border-color: var(--critical); animation: shake 0.4s var(--ease); }
.otp[data-state="ok"] .otp__digit { border-color: var(--positive); }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-4px); } 40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); } 80% { transform: translateX(3px); }
}
@media (max-width: 420px) {
  .otp { gap: var(--space-2); }
  .otp__digit { width: 44px; height: 54px; font-size: var(--text-xl); }
}

/* ---------------------------------------------------------------------------
   ANTALL-STEPPER
--------------------------------------------------------------------------- */
.stepper {
  display: inline-flex; align-items: center;
  border: var(--hairline) solid var(--line-strong);
  border-radius: var(--radius-md); background: var(--surface);
  height: var(--control-h-sm); overflow: hidden;
}
.stepper__btn {
  width: 32px; height: 100%; border: 0; background: transparent;
  color: var(--ink-muted); cursor: pointer; font-size: var(--text-lg); line-height: 1;
  display: grid; place-items: center;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.stepper__btn:hover { background: var(--surface-hover); color: var(--ink); }
.stepper__btn:active { background: var(--accent-weak); }
.stepper__btn:disabled { color: var(--ink-faint); cursor: not-allowed; background: transparent; }
.stepper__input {
  width: 44px; height: 100%; border: 0; text-align: center;
  background: transparent; font-variant-numeric: tabular-nums;
  font-size: var(--text-sm); font-weight: var(--weight-medium);
  border-inline: var(--hairline) solid var(--line);
  -moz-appearance: textfield;
}
.stepper__input::-webkit-outer-spin-button,
.stepper__input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper__input:focus { outline: none; box-shadow: inset var(--focus-ring); }

/* ---------------------------------------------------------------------------
   BADGE / STATUS-PILL
--------------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-2);
  height: 22px; padding-inline: var(--space-3);
  font-size: var(--text-2xs); font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  border-radius: var(--radius-pill);
  background: var(--surface-sunk); color: var(--ink-muted);
  border: var(--hairline) solid var(--line);
  white-space: nowrap;
}
.badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: 0.9; flex: none;
}
.badge--positive { background: var(--positive-weak); color: var(--positive-ink); border-color: transparent; }
.badge--warning  { background: var(--warning-weak);  color: var(--warning-ink);  border-color: transparent; }
.badge--critical { background: var(--critical-weak); color: var(--critical-ink); border-color: transparent; }
.badge--neutral::before { display: none; }

/* ---------------------------------------------------------------------------
   KORT / PANEL
--------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: var(--hairline) solid var(--line);
  border-radius: var(--radius-lg);
}
.card__pad { padding: var(--space-6); }
.panel {
  background: var(--surface);
  border: var(--hairline) solid var(--line);
  border-radius: var(--radius-lg);
}
.panel__head {
  padding: var(--space-5) var(--space-6);
  border-bottom: var(--hairline) solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
}
.panel__title { font-size: var(--text-md); font-weight: var(--weight-semibold); }
.panel__body { padding: var(--space-6); }

/* ---------------------------------------------------------------------------
   TABELL — hårfine rader, høyrestilte tabular tall
--------------------------------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table thead th {
  text-align: left; padding: var(--space-3) var(--space-4);
  font-size: var(--text-2xs); font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps); text-transform: uppercase;
  color: var(--ink-subtle);
  border-bottom: var(--hairline) solid var(--line-strong);
  white-space: nowrap;
}
.table tbody td {
  padding: var(--space-4);
  border-bottom: var(--hairline) solid var(--line);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--dur-fast) var(--ease); }
.table--rows tbody tr:hover { background: var(--surface-hover); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }

/* ---------------------------------------------------------------------------
   PRIS — ledger-stilen (signatur)
--------------------------------------------------------------------------- */
.price {
  font-variant-numeric: tabular-nums; font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight); white-space: nowrap;
}
.price__unit { font-size: var(--text-xs); font-weight: var(--weight-regular); color: var(--ink-subtle); }
.price--lg { font-size: var(--text-xl); }
.price--strike { color: var(--ink-faint); font-weight: var(--weight-regular); text-decoration: line-through; }

/* ---------------------------------------------------------------------------
   TOAST
--------------------------------------------------------------------------- */
.toast-region {
  position: fixed; bottom: var(--space-6); right: var(--space-6);
  z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--space-3);
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--space-4);
  min-width: 280px; max-width: 380px;
  padding: var(--space-4) var(--space-5);
  background: var(--paper-900); color: var(--paper-50);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  font-size: var(--text-sm); pointer-events: auto;
  animation: toast-in var(--dur-slow) var(--ease);
}
.toast[data-leaving="true"] { animation: toast-out var(--dur) var(--ease) forwards; }
.toast__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--positive); flex: none; }
.toast--critical .toast__dot { background: var(--critical); }
@keyframes toast-in  { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(0.98); } }

/* ---------------------------------------------------------------------------
   SKJELETT / LOADING
--------------------------------------------------------------------------- */
.skeleton {
  background: linear-gradient(100deg,
    var(--surface-sunk) 30%, var(--paper-200) 50%, var(--surface-sunk) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.skeleton--text { height: 0.7em; margin: 0.25em 0; }
.skeleton--line { height: 12px; }
.skeleton--block { height: 100%; width: 100%; }

/* ---------------------------------------------------------------------------
   TOM TILSTAND
--------------------------------------------------------------------------- */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: var(--space-4); padding: var(--space-9) var(--space-6);
  color: var(--ink-muted);
}
.empty__mark {
  width: 48px; height: 48px; border-radius: var(--radius-lg);
  display: grid; place-items: center;
  background: var(--surface-sunk); color: var(--ink-subtle);
  border: var(--hairline) solid var(--line);
}
.empty__title { font-size: var(--text-lg); font-weight: var(--weight-semibold); color: var(--ink); }
.empty__body { max-width: 38ch; font-size: var(--text-sm); }

/* ---------------------------------------------------------------------------
   FEILTILSTAND (inline, ikke modal)
--------------------------------------------------------------------------- */
.alert {
  display: flex; gap: var(--space-4); align-items: flex-start;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  border: var(--hairline) solid var(--line);
  background: var(--surface);
  font-size: var(--text-sm);
}
.alert__icon { flex: none; width: 18px; height: 18px; margin-top: 1px; }
.alert--critical { background: var(--critical-weak); border-color: transparent; color: var(--critical-ink); }
.alert--warning  { background: var(--warning-weak);  border-color: transparent; color: var(--warning-ink); }
.alert__title { font-weight: var(--weight-semibold); }

/* ---------------------------------------------------------------------------
   SEGMENT-KONTROLL (f.eks. visningsbytte rutenett/liste)
--------------------------------------------------------------------------- */
.segment {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--surface-sunk); border-radius: var(--radius-md);
  border: var(--hairline) solid var(--line);
}
.segment__btn {
  height: 28px; padding-inline: var(--space-3); border: 0; background: transparent;
  border-radius: var(--radius-sm); cursor: pointer; color: var(--ink-subtle);
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.segment__btn:hover { color: var(--ink); }
.segment__btn[aria-pressed="true"] {
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-xs);
}

/* ---------------------------------------------------------------------------
   AVATAR / KONTOMENY-TRIGGER
--------------------------------------------------------------------------- */
.avatar {
  width: 30px; height: 30px; border-radius: var(--radius-pill);
  background: var(--accent-weak); color: var(--accent-hover);
  display: grid; place-items: center;
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  border: var(--hairline) solid var(--line);
}

/* Liten lagervisning */
.stock { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: var(--ink-muted); }
.stock__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--positive); }
.stock--low  .stock__dot { background: var(--warning); }
.stock--out  .stock__dot { background: var(--critical); }
