/* Schedia – designsystem
   Lager: tokens → bas → appskal → komponenter → schemarutnät → verktygsklasser.
   Alla färger är semantiska tokens; mörkt läge byter bara tokenvärden. */

/* ───────────────────────── Tokens ───────────────────────── */
:root {
  color-scheme: light;

  /* Yta och text */
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --surface-sunken: #edf1ef;
  --surface-hover: #f0f4f2;
  --border: #dce3e0;
  --border-strong: #c3cdc9;
  --border-input: #87958f;
  --text: #15232a;
  --text-2: #4a5a60;
  --text-3: #5f6e73;
  --text-inverse: #ffffff;

  /* Varumärke: gran */
  --primary: #1d5e55;
  --primary-hover: #174c45;
  --primary-active: #123d37;
  --primary-soft: #e3efec;
  --primary-soft-2: #cfe3de;
  --on-primary: #ffffff;
  --focus: #2563c9;

  /* Signalfärger: fyllnad (graf/ikon), mjuk bakgrund, text på mjuk bakgrund */
  --ok: #2b7a4b;      --ok-soft: #e4f2e9;      --ok-text: #1e5c37;
  --warn: #a15c00;    --warn-soft: #fcf0dc;    --warn-text: #7a4500;
  --danger: #b42318;  --danger-soft: #fbe7e5;  --danger-text: #8e1b12;
  --info: #2f5da8;    --info-soft: #e6edf8;    --info-text: #234a87;
  --neutral-soft: #edf1ef; --neutral-text: #3f4f55;
  --accent: #6247aa;  --accent-soft: #efeafa;  --accent-text: #4b3590;

  /* Passtyper (standard när passtypen saknar egen färg). Dämpade: används som 2 px list, aldrig som fyllning. */
  --shift-day: #b3802a;
  --shift-evening: #5d4f9c;
  --shift-night: #3b4f6b;
  --shift-default: #2f6f6a;

  /* Diagram */
  --chart-1: #1d5e55;
  --chart-2: #8fbfb5;
  --chart-target: #15232a;
  --chart-grid: #e3e8e6;

  /* Typografi */
  --font-sans: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --fs-xs: 0.75rem;     /* 12 */
  --fs-sm: 0.8125rem;   /* 13 */
  --fs-md: 0.875rem;    /* 14 – brödtext i appen */
  --fs-lg: 1rem;        /* 16 */
  --fs-xl: 1.25rem;     /* 20 */
  --fs-2xl: 1.5rem;     /* 24 */
  --fs-3xl: 2rem;       /* 32 */
  --lh-tight: 1.2;
  --lh-normal: 1.45;
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* Avstånd (4-pixelsrutnät) */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px;
  --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;

  /* Hörn: små element rundas mindre än stora */
  --r-xs: 3px; --r-sm: 4px; --r-md: 6px; --r-lg: 10px; --r-xl: 14px; --r-pill: 999px;

  /* Skuggor används för lager, inte dekoration */
  --sh-1: 0 1px 0 rgba(21, 35, 42, 0.04);
  --sh-2: 0 4px 12px rgba(21, 35, 42, 0.10), 0 1px 3px rgba(21, 35, 42, 0.08);
  --sh-3: 0 18px 48px rgba(21, 35, 42, 0.20), 0 2px 8px rgba(21, 35, 42, 0.10);
  --backdrop: rgba(15, 28, 32, 0.42);

  /* Rörelse */
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur-1: 120ms;
  --dur-2: 200ms;

  /* Layout */
  --sidebar-w: 244px;
  --rail-w: 80px;
  --topbar-h: 56px;
  --bottombar-h: 62px;
  --content-max: 1600px;
  --gutter: var(--s-6);
  --control-h: 36px;
  --control-h-sm: 30px;

  --z-sticky: 5;
  --z-nav: 40;
  --z-popover: 80;
  --z-toast: 100;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1719; --surface: #162124; --surface-2: #1b282b; --surface-sunken: #121c1e; --surface-hover: #1f2e31;
    --border: #2a3a3e; --border-strong: #3a4d52; --border-input: #6b8380;
    --text: #e6eeec; --text-2: #a9b8b6; --text-3: #8a9b99; --text-inverse: #0f1719;
    --primary: #5fb8a8; --primary-hover: #79c9ba; --primary-active: #93d6c9; --primary-soft: #1c3833; --primary-soft-2: #24483f; --on-primary: #08201c;
    --focus: #8ab4ff;
    --ok: #5cc489; --ok-soft: #173325; --ok-text: #8fdcae;
    --warn: #e3a44a; --warn-soft: #3a2a12; --warn-text: #f2c47e;
    --danger: #f07a6e; --danger-soft: #3d1a17; --danger-text: #f6a79e;
    --info: #7fa6ea; --info-soft: #182a45; --info-text: #a9c4f2;
    --neutral-soft: #223034; --neutral-text: #c4d0ce;
    --accent: #a993e6; --accent-soft: #2a2342; --accent-text: #c9bbf2;
    --shift-day: #d1a85a; --shift-evening: #9c8fd8; --shift-night: #8aa0c4; --shift-default: #6fb3ab;
    --chart-1: #5fb8a8; --chart-2: #2f6a60; --chart-target: #e6eeec; --chart-grid: #26363a;
    --sh-1: 0 1px 0 rgba(0, 0, 0, 0.2);
    --sh-2: 0 6px 16px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.4);
    --sh-3: 0 20px 56px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.4);
    --backdrop: rgba(3, 8, 10, 0.62);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1719; --surface: #162124; --surface-2: #1b282b; --surface-sunken: #121c1e; --surface-hover: #1f2e31;
  --border: #2a3a3e; --border-strong: #3a4d52; --border-input: #6b8380;
  --text: #e6eeec; --text-2: #a9b8b6; --text-3: #8a9b99; --text-inverse: #0f1719;
  --primary: #5fb8a8; --primary-hover: #79c9ba; --primary-active: #93d6c9; --primary-soft: #1c3833; --primary-soft-2: #24483f; --on-primary: #08201c;
  --focus: #8ab4ff;
  --ok: #5cc489; --ok-soft: #173325; --ok-text: #8fdcae;
  --warn: #e3a44a; --warn-soft: #3a2a12; --warn-text: #f2c47e;
  --danger: #f07a6e; --danger-soft: #3d1a17; --danger-text: #f6a79e;
  --info: #7fa6ea; --info-soft: #182a45; --info-text: #a9c4f2;
  --neutral-soft: #223034; --neutral-text: #c4d0ce;
  --accent: #a993e6; --accent-soft: #2a2342; --accent-text: #c9bbf2;
  --shift-day: #d1a85a; --shift-evening: #9c8fd8; --shift-night: #8aa0c4; --shift-default: #6fb3ab;
  --chart-1: #5fb8a8; --chart-2: #2f6a60; --chart-target: #e6eeec; --chart-grid: #26363a;
  --sh-1: 0 1px 0 rgba(0, 0, 0, 0.2);
  --sh-2: 0 6px 16px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.4);
  --sh-3: 0 20px 56px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.4);
  --backdrop: rgba(3, 8, 10, 0.62);
}

@media (max-width: 719px) {
  :root { --gutter: var(--s-4); --control-h: 40px; --control-h-sm: 34px; }
}

/* ───────────────────────── Bas ───────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html.has-modal { overflow: hidden; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-normal);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4, p, figure, blockquote, dl, dd { margin: 0; }
h1, h2, h3, h4 { line-height: var(--lh-tight); font-weight: var(--fw-semibold); text-wrap: balance; }
h1 { font-size: var(--fs-2xl); letter-spacing: -0.015em; }
h2 { font-size: var(--fs-lg); letter-spacing: -0.005em; }
h3 { font-size: var(--fs-md); }
p { text-wrap: pretty; }
a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
img, svg { display: block; max-width: 100%; }
svg.icon { flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
table { border-collapse: collapse; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s-4) 0; }
kbd {
  display: inline-block; min-width: 1.5em; padding: 1px 5px;
  font-family: var(--font-sans); font-size: var(--fs-xs); line-height: 1.4; text-align: center;
  color: var(--text-2); background: var(--surface); border: 1px solid var(--border-strong);
  border-bottom-width: 2px; border-radius: var(--r-sm);
}
mark { background: var(--warn-soft); color: inherit; border-radius: 2px; padding: 0 1px; }
::selection { background: var(--primary-soft-2); }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
[hidden] { display: none !important; }

.skip-link {
  position: absolute; left: var(--s-3); top: -100px; z-index: 1000;
  padding: var(--s-2) var(--s-4); border-radius: var(--r-md);
  background: var(--primary); color: var(--on-primary); font-weight: var(--fw-semibold); text-decoration: none;
}
.skip-link:focus { top: var(--s-3); }

/* ───────────────────────── Appskal ───────────────────────── */
.app {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-areas: "side top" "side main";
}

.sidebar {
  grid-area: side;
  position: sticky; top: 0;
  height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: var(--z-nav);
}
.brand {
  display: flex; align-items: center; justify-content: center; gap: var(--s-3);
  height: var(--topbar-h); padding: 0 var(--s-4);
  color: var(--text); text-decoration: none;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.brand:hover { color: var(--text); }
.sr-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.brand__mark { width: 30px; height: 30px; flex: none; }
.brand__word { height: 24px; width: 113px; flex: none; fill: currentColor; }
.brand__mark--rail { display: none; }
.brand__text { display: flex; flex-direction: column; min-width: 0; }
.brand__name { font-weight: var(--fw-bold); font-size: 15px; letter-spacing: -0.01em; line-height: 1.15; }
.brand__sub { font-size: var(--fs-xs); color: var(--text-3); line-height: 1.2; }

.nav { flex: 1; overflow-y: auto; padding: var(--s-3) var(--s-3) var(--s-4); }
.nav__group + .nav__group { margin-top: var(--s-4); }
.nav__heading {
  padding: 0 var(--s-3) var(--s-1);
  font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--text-3);
}
.nav__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav__link {
  position: relative;
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 38px; padding: 0 var(--s-3);
  border-radius: var(--r-md);
  color: var(--text-2); text-decoration: none; font-weight: var(--fw-medium);
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.nav__link:hover { background: var(--surface-hover); color: var(--text); }
.nav__link[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.nav__link[aria-current="page"]::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--primary);
}
.nav__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav__count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill);
  display: inline-grid; place-items: center;
  font-size: 11px; font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums;
  background: var(--warn-soft); color: var(--warn-text);
}

.sidebar__foot {
  flex: none; padding: var(--s-3) var(--s-4);
  border-top: 1px solid var(--border);
  font-size: var(--fs-xs); color: var(--text-3);
  display: flex; align-items: flex-start; gap: var(--s-2);
}
.sidebar__foot .icon { margin-top: 1px; }
.sidebar__foot.is-warning { color: var(--warn-text); }

.topbar {
  grid-area: top;
  position: sticky; top: 0; z-index: var(--z-nav);
  display: flex; align-items: center; gap: var(--s-3);
  height: var(--topbar-h); padding: 0 var(--gutter);
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__brand { display: none; align-items: center; gap: var(--s-2); min-width: 0; color: var(--text); text-decoration: none; }
.topbar__brand .brand__mark { width: 28px; height: 28px; }
.topbar__title { font-weight: var(--fw-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__spacer { flex: 1; }
.topbar__actions { display: flex; align-items: center; gap: var(--s-1); }

.search-trigger {
  display: flex; align-items: center; gap: var(--s-2);
  width: min(420px, 100%); height: var(--control-h); padding: 0 var(--s-2) 0 var(--s-3);
  background: var(--surface); color: var(--text-3);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  text-align: left;
  transition: border-color var(--dur-1) var(--ease);
}
.search-trigger:hover { border-color: var(--border-input); color: var(--text-2); }
.search-trigger__text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.session-btn {
  display: flex; align-items: center; gap: var(--s-2);
  height: 40px; padding: 0 var(--s-2) 0 var(--s-1); margin-left: var(--s-1);
  border: 1px solid transparent; border-radius: var(--r-pill);
  background: transparent; text-align: left;
}
.session-btn:hover { background: var(--surface-hover); border-color: var(--border); }
.session-btn__text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.session-btn__role { font-weight: var(--fw-semibold); font-size: var(--fs-sm); white-space: nowrap; }
.session-btn__ctx { font-size: var(--fs-xs); color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }

.main { grid-area: main; min-width: 0; outline: none; }
.view {
  width: 100%; max-width: var(--content-max); margin: 0 auto;
  padding: var(--s-6) var(--gutter) var(--s-12);
  display: flex; flex-direction: column; gap: var(--s-6);
}
.view-loading { padding: var(--s-6) var(--gutter); display: grid; gap: var(--s-4); max-width: var(--content-max); margin: 0 auto; }

.bottomnav { display: none; }

/* Ikonräls för surfplatta */
@media (min-width: 720px) and (max-width: 1099px) {
  .app { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  .brand { justify-content: center; padding: 0; }
  .brand__text { display: none; }
  .brand__word { display: none; }
  .brand__mark--rail { display: block; }
  .nav { padding: var(--s-3) var(--s-2); }
  .nav__heading { display: none; }
  .nav__group + .nav__group { margin-top: var(--s-2); padding-top: var(--s-2); border-top: 1px solid var(--border); }
  .nav__link { flex-direction: column; justify-content: center; gap: 3px; min-height: 56px; padding: var(--s-1); text-align: center; }
  .nav__label { font-size: 11px; line-height: 1.15; white-space: normal; flex: none; }
  .nav__link[aria-current="page"]::before { left: -8px; }
  .nav__count { position: absolute; top: 4px; right: 8px; min-width: 18px; height: 18px; font-size: 10px; padding: 0 5px; }
  .sidebar__foot { justify-content: center; padding: var(--s-3) var(--s-2); }
  .sidebar__foot-text { display: none; }
  .sidebar__foot-btn { justify-content: center; }
  .session-btn__ctx { max-width: 120px; }
}

/* Mobil: bottenmeny */
@media (max-width: 719px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
  .sidebar { display: none; }
  .topbar { padding: 0 var(--s-2) 0 var(--s-4); gap: var(--s-2); }
  .topbar__brand { display: flex; }
  .topbar__spacer { display: block; }
  .search-trigger { display: none; }
  .session-btn__text, .hide-mobile { display: none !important; }
  .view { padding: var(--s-4) var(--gutter) calc(var(--bottombar-h) + var(--s-8) + env(safe-area-inset-bottom)); gap: var(--s-4); }
  .bottomnav {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-nav);
    height: calc(var(--bottombar-h) + env(safe-area-inset-bottom));
    padding: 0 var(--s-1) env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(21, 35, 42, 0.05);
  }
  .bottomnav__item {
    position: relative; flex: 1; min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    padding: var(--s-1) 2px; border: 0; background: none;
    color: var(--text-3); text-decoration: none; font-size: 11px; font-weight: var(--fw-medium);
    border-radius: var(--r-md);
  }
  .bottomnav__item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bottomnav__item[aria-current="page"], .bottomnav__item.is-active { color: var(--primary); }
  .bottomnav__item[aria-current="page"]::after, .bottomnav__item.is-active::after {
    content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary);
  }
  .bottomnav__item .nav__count { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 17px; height: 17px; font-size: 10px; padding: 0 4px; }
}
@media (min-width: 720px) { .show-mobile { display: none !important; } }

.more-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--s-2); }
.more-list a {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 52px; padding: var(--s-3);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  color: var(--text); text-decoration: none; font-weight: var(--fw-medium);
}
.more-list a[aria-current="page"] { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

/* ───────────────────────── Sidhuvud och paneler ───────────────────────── */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }
.page-header__titles { min-width: 0; display: grid; gap: var(--s-1); }
.page-header__back { justify-self: start; margin-left: calc(var(--s-2) * -1); }
.page-header__title:focus-visible { outline-offset: 4px; }
.page-header__subtitle { color: var(--text-2); max-width: 72ch; }
.page-header__meta { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; margin-top: var(--s-1); }
.page-header__actions { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; }
@media (max-width: 719px) { h1 { font-size: var(--fs-xl); } .page-header { align-items: flex-start; } }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  min-width: 0;
  display: flex; flex-direction: column;
}
.panel__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap;
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}
.panel__titles { min-width: 0; }
.panel__title { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.panel__subtitle { font-size: var(--fs-sm); color: var(--text-3); margin-top: 1px; }
.panel__actions { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }
.panel__body { padding: var(--s-4); min-width: 0; flex: 1; }
.panel__body--flush { padding: 0; }
.panel__foot { padding: var(--s-3) var(--s-4); border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.panel--warning { border-color: color-mix(in oklab, var(--warn) 45%, var(--border)); }
.panel--danger { border-color: color-mix(in oklab, var(--danger) 45%, var(--border)); }
.panel--muted { background: var(--surface-2); box-shadow: none; }

.callout {
  display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-3) var(--s-4); border-radius: var(--r-md);
  background: var(--info-soft); color: var(--info-text);
}
.callout > .icon { margin-top: 1px; }
.callout__body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.callout__title { font-weight: var(--fw-semibold); }
.callout--success { background: var(--ok-soft); color: var(--ok-text); }
.callout--warning { background: var(--warn-soft); color: var(--warn-text); }
.callout--danger { background: var(--danger-soft); color: var(--danger-text); }
.callout--neutral { background: var(--neutral-soft); color: var(--neutral-text); }
.callout__actions { display: flex; gap: var(--s-2); flex-wrap: wrap; margin-top: var(--s-2); }

/* ───────────────────────── Knappar ───────────────────────── */
.btn {
  --btn-bg: var(--surface); --btn-fg: var(--text); --btn-bd: var(--border-strong); --btn-bg-hover: var(--surface-hover);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: var(--control-h); padding: 0 var(--s-4);
  border: 1px solid var(--btn-bd); border-radius: var(--r-md);
  background: var(--btn-bg); color: var(--btn-fg);
  font-size: var(--fs-md); font-weight: var(--fw-medium); line-height: 1;
  white-space: nowrap; text-decoration: none; user-select: none;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.btn:hover { background: var(--btn-bg-hover); color: var(--btn-fg); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
.btn--primary { --btn-bg: var(--primary); --btn-fg: var(--on-primary); --btn-bd: var(--primary); --btn-bg-hover: var(--primary-hover); }
.btn--primary:active { --btn-bg: var(--primary-active); }
.btn--secondary { --btn-bg: var(--surface); }
.btn--ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--text-2); --btn-bg-hover: var(--surface-hover); }
.btn--ghost:hover { --btn-fg: var(--text); }
.btn--danger { --btn-bg: var(--danger); --btn-fg: #fff; --btn-bd: var(--danger); --btn-bg-hover: color-mix(in oklab, var(--danger) 85%, #000); }
:root[data-theme="dark"] .btn--danger { --btn-fg: #2a0b08; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn--danger { --btn-fg: #2a0b08; } }
.btn--danger-ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--danger-text); --btn-bg-hover: var(--danger-soft); }
.btn--sm { height: var(--control-h-sm); padding: 0 var(--s-3); font-size: var(--fs-sm); gap: 6px; }
.btn--lg { height: 44px; padding: 0 var(--s-5); font-size: var(--fs-lg); }
.btn--icon { width: var(--control-h); padding: 0; }
.btn--icon.btn--sm { width: var(--control-h-sm); }
.btn--block { width: 100%; }
.btn[aria-pressed="true"] { --btn-bg: var(--primary-soft); --btn-bd: var(--primary); --btn-fg: var(--primary); }
.btn.is-busy { color: transparent !important; }
.btn.is-busy > * { visibility: hidden; }
.btn.is-busy::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px;
  border: 2px solid var(--btn-fg); border-right-color: transparent; border-radius: 50%;
  animation: sp-spin 0.7s linear infinite;
}
.btn-group { display: inline-flex; }
.btn-group > .btn:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }
.btn-group > .btn:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }

/* ───────────────────────── Badges, piller, status ───────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 7px; border-radius: var(--r-sm);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold); line-height: 1; white-space: nowrap;
  background: var(--neutral-soft); color: var(--neutral-text);
  font-variant-numeric: tabular-nums;
}
.badge--info { background: var(--info-soft); color: var(--info-text); }
.badge--success { background: var(--ok-soft); color: var(--ok-text); }
.badge--warning { background: var(--warn-soft); color: var(--warn-text); }
.badge--danger { background: var(--danger-soft); color: var(--danger-text); }
.badge--accent { background: var(--accent-soft); color: var(--accent-text); }
.badge--primary { background: var(--primary-soft); color: var(--primary); }
.badge--outline { background: transparent; box-shadow: inset 0 0 0 1px var(--border-strong); color: var(--text-2); }
.badge--sm { height: 18px; padding: 0 6px; font-size: 11px; }

.pill__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-2);
}
.status--success .icon { color: var(--ok); }
.status--warning .icon { color: var(--warn); }
.status--danger .icon { color: var(--danger); }
.status--info .icon { color: var(--info); }
.status--neutral .icon { color: var(--text-3); }

/* ───────────────────────── Formulär ───────────────────────── */
.form { display: grid; gap: var(--s-4); }
.form--2col { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--s-4); }
.form--2col > .field--full, .form--2col > .form__section, .form--2col > .form__actions, .form--2col > .callout { grid-column: 1 / -1; }
@media (max-width: 599px) { .form--2col { grid-template-columns: minmax(0, 1fr); } }
.form__section { display: grid; gap: 2px; padding-top: var(--s-2); }
.form__section:not(:first-child) { border-top: 1px solid var(--border); padding-top: var(--s-4); }
.form__section h3 { font-size: var(--fs-md); }
.form__section p { color: var(--text-3); font-size: var(--fs-sm); }
.form__actions { display: flex; gap: var(--s-2); justify-content: flex-end; flex-wrap: wrap; padding-top: var(--s-2); }

.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field > .stepper, .field > .segmented, .field > .swatches { justify-self: start; }
.field__label { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text); }
.field__req { color: var(--danger-text); margin-left: 2px; }
.field__hint { font-size: var(--fs-xs); color: var(--text-3); }
.field__error { font-size: var(--fs-xs); color: var(--danger-text); font-weight: var(--fw-medium); display: flex; gap: 4px; align-items: flex-start; }
.field__error .icon { margin-top: 1px; }
.field__control { position: relative; display: flex; align-items: stretch; min-width: 0; }
.field__affix {
  display: flex; align-items: center; padding: 0 var(--s-3);
  font-size: var(--fs-sm); color: var(--text-3); white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--border-input);
}
.field__affix--prefix { border-right: 0; border-radius: var(--r-md) 0 0 var(--r-md); }
.field__affix--suffix { border-left: 0; border-radius: 0 var(--r-md) var(--r-md) 0; }
.field__control:has(.field__affix--prefix) .input { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.field__control:has(.field__affix--suffix) .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.field--inline { grid-template-columns: auto 1fr; align-items: center; column-gap: var(--s-3); }
.field--hide-label > .field__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.input {
  width: 100%; min-width: 0; height: var(--control-h); padding: 0 var(--s-3);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-input); border-radius: var(--r-md);
  font-size: var(--fs-md);
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
.input::placeholder { color: var(--text-3); opacity: 1; }
.input:hover { border-color: var(--text-3); }
.input:focus-visible, .input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in oklab, var(--focus) 28%, transparent); }
.input:disabled { background: var(--surface-sunken); color: var(--text-3); cursor: not-allowed; }
.input[readonly] { background: var(--surface-2); }
.input--sm { height: var(--control-h-sm); font-size: var(--fs-sm); padding: 0 var(--s-2); }
.input--num { text-align: right; font-variant-numeric: tabular-nums; }
.field--invalid .input, .input[aria-invalid="true"] { border-color: var(--danger); }
.field--invalid .input:focus { box-shadow: 0 0 0 3px color-mix(in oklab, var(--danger) 25%, transparent); }
textarea.input { height: auto; min-height: 80px; padding: var(--s-2) var(--s-3); line-height: var(--lh-normal); resize: vertical; }
select.input {
  appearance: none; -webkit-appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235f6e73' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
input[type="date"].input, input[type="time"].input { font-variant-numeric: tabular-nums; }
input[type="date"].input::-webkit-calendar-picker-indicator, input[type="time"].input::-webkit-calendar-picker-indicator { opacity: 0.6; cursor: pointer; }
:root[data-theme="dark"] input[type="date"].input::-webkit-calendar-picker-indicator,
:root[data-theme="dark"] input[type="time"].input::-webkit-calendar-picker-indicator { filter: invert(1); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) input[type="date"].input::-webkit-calendar-picker-indicator,
  :root:not([data-theme="light"]) input[type="time"].input::-webkit-calendar-picker-indicator { filter: invert(1); }
}

.check { display: inline-flex; align-items: flex-start; gap: var(--s-2); cursor: pointer; font-size: var(--fs-md); }
.check__text { display: grid; gap: 1px; }
.check__desc { font-size: var(--fs-xs); color: var(--text-3); }
.check input[type="checkbox"], .check input[type="radio"] {
  width: 18px; height: 18px; margin: 1px 0 0; flex: none; accent-color: var(--primary); cursor: pointer;
}

.switch { display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; }
.switch input {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none;
  position: relative; width: 38px; height: 22px; border-radius: var(--r-pill);
  background: var(--border-input); cursor: pointer;
  transition: background var(--dur-2) var(--ease);
}
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform var(--dur-2) var(--ease);
}
.switch input:checked { background: var(--primary); }
.switch input:checked::after { transform: translateX(16px); background: var(--surface); }
.switch input:disabled { opacity: 0.5; cursor: not-allowed; }
.switch input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch__text { display: grid; gap: 1px; }

/* Segmenterad kontroll */
.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-sunken); border-radius: var(--r-md);
  border: 1px solid var(--border);
  max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.segmented__opt {
  display: inline-flex; align-items: center; gap: 6px;
  height: calc(var(--control-h) - 8px); padding: 0 var(--s-3);
  border: 0; border-radius: var(--r-sm); background: transparent;
  color: var(--text-2); font-size: var(--fs-sm); font-weight: var(--fw-medium); white-space: nowrap;
}
.segmented__opt:hover { color: var(--text); }
.segmented__opt[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--sh-2); }
.segmented--sm .segmented__opt { height: calc(var(--control-h-sm) - 8px); padding: 0 var(--s-2); font-size: var(--fs-xs); }

/* Valkort (radio med beskrivning) */
.choices { display: grid; gap: var(--s-2); }
.choices--row { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.choice {
  position: relative; display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-3); border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  background: var(--surface); cursor: pointer;
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.choice:hover { border-color: var(--border-input); }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.choice:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice__icon { width: 32px; height: 32px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--surface-sunken); color: var(--text-2); flex: none; }
.choice:has(input:checked) .choice__icon { background: var(--primary); color: var(--on-primary); }
.choice__text { display: grid; gap: 2px; min-width: 0; }
.choice__label { font-weight: var(--fw-semibold); }
.choice__desc { font-size: var(--fs-sm); color: var(--text-2); }
.choice__check { margin-left: auto; color: var(--primary); opacity: 0; flex: none; }
.choice:has(input:checked) .choice__check { opacity: 1; }

/* Stegräknare för tal */
.stepper { display: inline-flex; align-items: stretch; height: var(--control-h); border: 1px solid var(--border-input); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
.stepper:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in oklab, var(--focus) 28%, transparent); }
.stepper__btn { width: 32px; border: 0; background: var(--surface-2); color: var(--text-2); display: grid; place-items: center; flex: none; }
.stepper__btn:hover { background: var(--surface-hover); color: var(--text); }
.stepper__btn:disabled { opacity: 0.35; }
.stepper__input { width: 3.5em; min-width: 0; border: 0; background: transparent; text-align: center; font-variant-numeric: tabular-nums; font-weight: var(--fw-semibold); }
.stepper__input:focus { outline: none; }
.stepper--sm { height: var(--control-h-sm); }
.stepper--sm .stepper__btn { width: 26px; }
.stepper--sm .stepper__input { width: 2.6em; font-size: var(--fs-sm); }

/* Taggar */
.tags {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  min-height: var(--control-h); padding: 4px 6px;
  border: 1px solid var(--border-input); border-radius: var(--r-md); background: var(--surface);
  cursor: text;
}
.tags:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in oklab, var(--focus) 28%, transparent); }
.tag {
  display: inline-flex; align-items: center; gap: 2px; height: 24px; padding: 0 2px 0 8px;
  border-radius: var(--r-sm); background: var(--primary-soft); color: var(--primary);
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
}
.tag button { width: 20px; height: 20px; display: grid; place-items: center; border: 0; background: transparent; color: inherit; border-radius: var(--r-xs); }
.tag button:hover { background: var(--primary-soft-2); }
.tags__input { flex: 1; min-width: 100px; height: 26px; border: 0; background: transparent; padding: 0 4px; }
.tags__input:focus { outline: none; }

/* Färgväljare */
.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border-strong); background: var(--sw); padding: 0;
  display: grid; place-items: center; color: #fff;
}
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--text); }
.swatch .icon { opacity: 0; }
.swatch[aria-checked="true"] .icon { opacity: 1; }
.swatch-custom { position: relative; display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-2); }
.swatch-custom input[type="color"] { width: 32px; height: 28px; padding: 0; border: 1px solid var(--border-input); border-radius: var(--r-sm); background: none; cursor: pointer; }

/* Inline-redigering */
.inline-edit { display: inline-flex; max-width: 100%; min-width: 0; vertical-align: middle; }
.inline-edit__display {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  min-height: 28px; padding: 2px 6px; margin: -2px -6px;
  border: 1px dashed transparent; border-radius: var(--r-sm);
  background: transparent; text-align: inherit; color: inherit; font: inherit;
}
.inline-edit__display:hover { border-color: var(--border-input); background: var(--surface); }
.inline-edit__display .icon { color: var(--text-3); opacity: 0; transition: opacity var(--dur-1); }
.inline-edit__display:hover .icon, .inline-edit__display:focus-visible .icon { opacity: 1; }
.inline-edit__value { white-space: nowrap; }
.inline-edit__empty { color: var(--text-3); }
.inline-edit__form { display: inline-flex; gap: 4px; align-items: center; position: relative; min-width: 0; }
.inline-edit__form .input { height: 30px; font-size: var(--fs-sm); padding: 0 var(--s-2); min-width: 72px; }
.inline-edit__error {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 3; white-space: nowrap;
  padding: 4px 8px; border-radius: var(--r-sm); font-size: var(--fs-xs); font-weight: var(--fw-medium);
  background: var(--danger); color: #fff;
}
.inline-edit.is-saving { opacity: 0.6; }

/* Matris (t.ex. bemanningsbehov) */
.matrix-wrap { overflow-x: auto; }
.matrix { width: auto; min-width: min(100%, 480px); border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.matrix th, .matrix td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: center; white-space: nowrap; }
.matrix thead th { font-weight: var(--fw-medium); color: var(--text-3); font-size: var(--fs-xs); }
.matrix thead tr:first-child th { color: var(--text-2); font-size: var(--fs-sm); font-weight: var(--fw-semibold); }
.matrix .matrix__group-start { border-left: 1px solid var(--border); }
.matrix .matrix__corner { text-align: left; }
.matrix tbody th { text-align: left; font-weight: var(--fw-medium); }
.matrix__rowsub { display: block; color: var(--text-3); font-size: var(--fs-xs); font-weight: var(--fw-regular); }
.matrix__input {
  width: 48px; height: 30px; padding: 0 6px; text-align: center;
  border: 1px solid var(--border-input); border-radius: var(--r-sm); background: var(--surface);
  font-variant-numeric: tabular-nums; font-weight: var(--fw-semibold);
}
.matrix__input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in oklab, var(--focus) 28%, transparent); }
.matrix__input.is-zero { color: var(--text-3); font-weight: var(--fw-regular); }
.matrix tfoot td, .matrix tfoot th { font-weight: var(--fw-semibold); color: var(--text-2); border-bottom: 0; }

/* ───────────────────────── Tabell ───────────────────────── */
.table-wrap { overflow-x: auto; min-width: 0; }
.table-wrap--sticky { overflow: auto; max-height: var(--table-max-h, 70vh); }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-md); }
.tbl caption { text-align: left; padding: 0 0 var(--s-2); font-weight: var(--fw-semibold); }
.tbl th, .tbl td { padding: 0 var(--s-3); height: 44px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.tbl thead th {
  height: 38px; background: var(--surface-2);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-3);
  white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.tbl th:first-child, .tbl td:first-child { padding-left: var(--s-4); }
.tbl th:last-child, .tbl td:last-child { padding-right: var(--s-4); }
.tbl tbody tr { transition: background var(--dur-1) var(--ease); }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tr.is-clickable { cursor: pointer; }
.tbl tr.is-clickable:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.tbl tr.is-selected { background: var(--primary-soft); }
.tbl .is-end { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .is-center { text-align: center; }
.tbl .is-nowrap { white-space: nowrap; }
.tbl .is-shrink { width: 1%; white-space: nowrap; }
.tbl--dense th, .tbl--dense td { height: 36px; }
.tbl--dense thead th { height: 32px; }
.tbl__sort {
  display: inline-flex; align-items: center; gap: 4px; margin: 0 -4px; padding: 2px 4px;
  border: 0; background: none; color: inherit; font: inherit; border-radius: var(--r-xs);
}
.tbl__sort:hover { color: var(--text); }
.tbl__sort .icon { opacity: 0.35; }
th[aria-sort] .tbl__sort .icon { opacity: 1; }
.tbl__cellmain { font-weight: var(--fw-medium); }
.tbl__cellsub { display: block; font-size: var(--fs-xs); color: var(--text-3); }
@media (max-width: 719px) { .tbl .hide-sm { display: none; } }
@media (max-width: 1099px) { .tbl .hide-md { display: none; } }

/* ───────────────────────── Tomtillstånd, laddning ───────────────────────── */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s-2);
  padding: var(--s-10) var(--s-6);
  color: var(--text-2);
}
.empty__icon {
  width: 52px; height: 52px; border-radius: var(--r-xl); display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); margin-bottom: var(--s-2);
}
.empty--warning .empty__icon { background: var(--warn-soft); color: var(--warn-text); }
.empty--danger .empty__icon { background: var(--danger-soft); color: var(--danger-text); }
.empty__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); color: var(--text); margin: 0; line-height: 1.3; }
h1.empty__title { font-size: var(--fs-xl); }
h1.empty__title:focus { outline: none; }
.empty__text { max-width: 52ch; }
.empty__actions { display: flex; gap: var(--s-2); flex-wrap: wrap; justify-content: center; margin-top: var(--s-3); }
.empty--compact { padding: var(--s-6) var(--s-4); }
.empty--compact .empty__icon { width: 40px; height: 40px; border-radius: var(--r-lg); }
.empty--compact .empty__title { font-size: var(--fs-md); }
.empty details { margin-top: var(--s-3); max-width: 60ch; text-align: left; font-size: var(--fs-xs); color: var(--text-3); }
.empty details pre { white-space: pre-wrap; word-break: break-word; font-family: var(--font-mono); background: var(--surface-sunken); padding: var(--s-2) var(--s-3); border-radius: var(--r-md); margin: var(--s-2) 0 0; }

.spinner { display: inline-flex; align-items: center; gap: var(--s-2); color: var(--text-3); font-size: var(--fs-sm); }
.spinner::before {
  content: ""; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--primary);
  animation: sp-spin 0.8s linear infinite;
}
.skeleton { display: grid; gap: var(--s-2); }
.skeleton__line {
  height: 12px; border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-sunken) 0%, var(--surface-hover) 50%, var(--surface-sunken) 100%);
  background-size: 200% 100%; animation: sp-shimmer 1.4s ease-in-out infinite;
}
.skeleton__block { height: 120px; border-radius: var(--r-lg); background: var(--surface-sunken); animation: sp-pulse 1.6s ease-in-out infinite; }

/* ───────────────────────── Flikar ───────────────────────── */
.tabs__list {
  display: flex; gap: var(--s-1); border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.tabs__list::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  height: 40px; padding: 0 var(--s-3); margin-bottom: -1px;
  border: 0; border-bottom: 2px solid transparent; background: none;
  color: var(--text-2); font-weight: var(--fw-medium); white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.tab:focus-visible { outline-offset: -2px; }
.tab__count { font-size: 11px; font-weight: var(--fw-semibold); padding: 1px 6px; border-radius: var(--r-pill); background: var(--neutral-soft); color: var(--neutral-text); }
.tab[aria-selected="true"] .tab__count { background: var(--primary-soft); color: var(--primary); }
.tabs__panel { padding-top: var(--s-4); }
.tabs__panel:focus-visible { outline-offset: 4px; }
.tabs--pill .tabs__list { border: 0; gap: 2px; background: var(--surface-sunken); padding: 3px; border-radius: var(--r-md); display: inline-flex; max-width: 100%; }
.tabs--pill .tab { height: 30px; border: 0; margin: 0; border-radius: var(--r-sm); font-size: var(--fs-sm); }
.tabs--pill .tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--sh-2); }

/* ───────────────────────── Nyckeltal och diagram ───────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--s-4); }
.kpi {
  display: grid; gap: var(--s-1); align-content: start;
  padding: var(--s-4); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-1);
  min-width: 0;
}
.kpi__label { font-size: var(--fs-sm); color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.kpi__row { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-3); }
.kpi__value { font-size: 1.75rem; font-weight: var(--fw-semibold); letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi__unit { font-size: var(--fs-md); font-weight: var(--fw-medium); color: var(--text-3); margin-left: 3px; letter-spacing: 0; }
.kpi__foot { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; font-size: var(--fs-xs); color: var(--text-3); }
.kpi__delta { font-weight: var(--fw-semibold); }
.kpi__delta--success { color: var(--ok-text); }
.kpi__delta--warning { color: var(--warn-text); }
.kpi__delta--danger { color: var(--danger-text); }

.ring { display: inline-grid; justify-items: center; gap: var(--s-2); text-align: center; }
.ring__svg { position: relative; display: grid; place-items: center; }
.ring__svg svg { transform: rotate(-90deg); }
.ring__track { stroke: var(--surface-sunken); }
.ring__bar { stroke: var(--ring-color, var(--primary)); transition: stroke-dashoffset 600ms var(--ease); }
.ring__center { position: absolute; inset: 0; display: grid; place-content: center; line-height: 1.1; }
.ring__value { font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.ring__sub { font-size: 11px; color: var(--text-3); }
.ring__sub--outside { display: block; margin-top: 2px; }
.ring__label { font-size: var(--fs-sm); color: var(--text-2); max-width: 16ch; }
.ring--success { --ring-color: var(--ok); }
.ring--warning { --ring-color: var(--warn); }
.ring--danger { --ring-color: var(--danger); }
.ring--info { --ring-color: var(--info); }

.meter { display: grid; gap: 4px; min-width: 0; }
.meter__head { display: flex; justify-content: space-between; gap: var(--s-2); font-size: var(--fs-xs); color: var(--text-2); }
.meter__value { font-variant-numeric: tabular-nums; font-weight: var(--fw-semibold); color: var(--text); }
.meter__track { position: relative; height: 8px; border-radius: var(--r-pill); background: var(--surface-sunken); overflow: visible; }
.meter__fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: var(--r-pill); background: var(--meter-color, var(--primary)); max-width: 100%; transition: width 400ms var(--ease); }
.meter__target { position: absolute; top: -3px; bottom: -3px; width: 2px; border-radius: 1px; background: var(--chart-target); transform: translateX(-1px); }
.meter--success { --meter-color: var(--ok); }
.meter--warning { --meter-color: var(--warn); }
.meter--danger { --meter-color: var(--danger); }
.meter--info { --meter-color: var(--info); }
.meter--sm .meter__track { height: 5px; }

.chart { display: grid; gap: var(--s-2); min-width: 0; }
.chart__plot { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s-2); }
.chart__axis { display: flex; flex-direction: column; justify-content: space-between; font-size: 11px; color: var(--text-3); text-align: right; font-variant-numeric: tabular-nums; min-width: 2ch; }
.chart__area { position: relative; min-width: 0; }
.chart__svg { display: block; width: 100%; overflow: visible; }
.chart__grid { stroke: var(--chart-grid); }
.chart__bar { fill: var(--chart-1); }
.chart__bar--success { fill: var(--ok); }
.chart__bar--warning { fill: var(--warn); }
.chart__bar--danger { fill: var(--danger); }
.chart__bar--info { fill: var(--info); }
.chart__bar--muted { fill: var(--chart-2); }
.chart__target { stroke: var(--chart-target); stroke-width: 2; }
.chart__labels { display: grid; font-size: 11px; color: var(--text-3); text-align: center; font-variant-numeric: tabular-nums; }
.chart__labels span { overflow: hidden; text-overflow: clip; white-space: nowrap; padding: 0 1px; }
.chart { container-type: inline-size; }
@container (max-width: 560px) { .chart__labels.is-dense:not(.is-weekly) span:nth-child(even) { visibility: hidden; } }
@container (max-width: 600px) {
  .chart__labels.is-weekly span:not(.is-tick) { visibility: hidden; }
  .chart__labels.is-weekly span.is-tick { overflow: visible; text-align: left; padding-left: 0; }
}
.chart__labels span.is-weekend { color: var(--text-2); font-weight: var(--fw-semibold); }
.chart__values { position: absolute; inset: 0; display: grid; pointer-events: none; }
.chart__values span { align-self: end; text-align: center; font-size: 10px; font-weight: var(--fw-semibold); color: var(--text-2); font-variant-numeric: tabular-nums; }
.chart__legend { display: flex; gap: var(--s-4); flex-wrap: wrap; font-size: var(--fs-xs); color: var(--text-2); }
.chart__legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart__key { width: 10px; height: 10px; border-radius: 2px; background: var(--chart-1); }
.chart__key--target { height: 2px; width: 14px; border-radius: 1px; background: var(--chart-target); }
.chart__tip {
  position: absolute; z-index: 4; pointer-events: none; transform: translate(-50%, calc(-100% - 8px));
  padding: 4px 8px; border-radius: var(--r-sm); background: var(--text); color: var(--text-inverse);
  font-size: var(--fs-xs); white-space: nowrap; box-shadow: var(--sh-2);
}

.spark { overflow: visible; }
.spark__line { fill: none; stroke: var(--spark-color, var(--primary)); stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.spark__area { fill: var(--spark-color, var(--primary)); opacity: 0.12; }
.spark__dot { fill: var(--spark-color, var(--primary)); stroke: var(--surface); stroke-width: 1.5; }
.spark--success { --spark-color: var(--ok); }
.spark--warning { --spark-color: var(--warn); }
.spark--danger { --spark-color: var(--danger); }

.coverage {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  min-width: 34px; height: 20px; padding: 0 2px;
  font-size: var(--fs-xs); font-weight: var(--fw-medium); font-variant-numeric: tabular-nums;
  background: transparent; color: var(--text-2);
}
.coverage::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); flex: none; }
.coverage .icon { display: none; }
.coverage--under { color: var(--danger-text); font-weight: var(--fw-semibold); }
.coverage--under::before { background: var(--danger); }
.coverage--over { color: var(--info-text); }
.coverage--over::before { background: var(--info); }
.coverage--none { color: var(--text-3); font-weight: var(--fw-regular); }
.coverage--none::before { content: none; }

/* ───────────────────────── Avatar ───────────────────────── */
.avatar {
  --av: var(--primary);
  width: var(--av-size, 32px); height: var(--av-size, 32px); border-radius: 50%; flex: none;
  display: inline-grid; place-items: center;
  background: color-mix(in oklab, var(--av) 18%, var(--surface)); color: color-mix(in oklab, var(--av) 80%, var(--text));
  font-size: calc(var(--av-size, 32px) * 0.38); font-weight: var(--fw-semibold); letter-spacing: 0.01em;
  user-select: none;
}
.person { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.person__text { display: grid; min-width: 0; line-height: 1.25; }
.person__name { font-weight: var(--fw-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person__sub { font-size: var(--fs-xs); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ───────────────────────── Passchip ─────────────────────────
   Dämpad: neutral yta, passfärgen syns bara som 2 px vänsterlist och svag ton i koden.
   --chip-strong blandas mot textfärgen så att även starka egna färger tonas ned (mörkt läge: ljusare list). */
.chip {
  --chip: var(--shift-default);
  --chip-strong: color-mix(in oklab, var(--chip) 75%, var(--text));
  --chip-bg: color-mix(in oklab, var(--chip) 4%, var(--surface-2));
  --chip-line: color-mix(in oklab, var(--border) 70%, transparent);
  position: relative;
  display: inline-flex; flex-direction: column; justify-content: center; gap: 3px;
  min-width: 0; max-width: 100%;
  padding: 3px 5px 3px 7px;
  border: 1px solid var(--chip-line); border-left-width: 0; border-radius: var(--r-xs);
  background: var(--chip-bg);
  box-shadow: inset 2px 0 0 var(--chip-strong);
  color: var(--text);
  font-size: var(--fs-xs); line-height: 1.15; text-align: left;
  font-variant-numeric: tabular-nums;
  user-select: none;
}
:root[data-theme="dark"] .chip { --chip-strong: color-mix(in oklab, var(--chip) 70%, var(--text)); --chip-bg: color-mix(in oklab, var(--chip) 3%, var(--surface-2)); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chip { --chip-strong: color-mix(in oklab, var(--chip) 70%, var(--text)); --chip-bg: color-mix(in oklab, var(--chip) 3%, var(--surface-2)); }
}
button.chip { font: inherit; font-size: var(--fs-xs); cursor: pointer; }
button.chip:hover { background: color-mix(in oklab, var(--chip) 9%, var(--surface-2)); }
.chip__top { display: flex; align-items: baseline; gap: 5px; min-width: 0; }
.chip:has(> .chip__flags) .chip__top { padding-right: 11px; }
.chip__code { font-weight: var(--fw-semibold); letter-spacing: 0.01em; flex: none; color: color-mix(in oklab, var(--chip-strong) 45%, var(--text)); }
.chip__label { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; font-weight: var(--fw-regular); }
.chip__time { color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; margin-left: auto; }
.chip__flags { position: absolute; top: 2px; right: 3px; display: flex; gap: 2px; line-height: 1; }
.chip__flag {
  width: 10px; height: 10px; display: grid; place-items: center;
  background: none; color: var(--text-3);
}
.chip__flag .icon { width: 10px; height: 10px; }
.chip__flag--danger { color: var(--danger-text); }
.chip__flag--warning { color: var(--warn-text); }
.chip__flag--wish { color: var(--accent-text); }
.chip__flag--sub { font-size: 9.5px; font-weight: var(--fw-semibold); letter-spacing: 0; }
.chip__day { position: relative; height: 2px; border-radius: 1px; background: color-mix(in oklab, var(--border) 70%, transparent); }
.chip__seg { position: absolute; top: 0; bottom: 0; border-radius: 1px; background: color-mix(in oklab, var(--chip-strong) 75%, transparent); }
.chip--lg { padding: 5px 9px 6px 11px; font-size: var(--fs-sm); gap: 4px; border-radius: var(--r-sm); }
.chip--lg .chip__day { height: 3px; }
.chip--block { width: 100%; }
.tbl .chip, .legend .chip { min-width: 48px; } /* fristående chip i listor: dygnsstapeln behöver bredd för att läsas */
.chip--open {
  background: transparent;
  border: 1px dashed color-mix(in oklab, var(--danger) 55%, var(--border)); box-shadow: none; color: var(--danger-text);
}
.chip--open .chip__code { color: var(--danger-text); }
.chip--open .chip__label { color: var(--danger-text); }
.chip--open .chip__seg { background: color-mix(in oklab, var(--danger) 45%, transparent); }
.chip--conflict { border-color: var(--danger); }
.chip--warning { border-color: color-mix(in oklab, var(--warn) 70%, var(--border)); }
.chip--draft { opacity: 0.72; border-style: dashed; border-color: var(--border-input); }
.chip--wish { border-color: color-mix(in oklab, var(--accent) 55%, var(--border)); }
.chip--muted { opacity: 0.55; }
.chip--ghost {
  position: fixed; z-index: 1000; pointer-events: none; margin: 0;
  box-shadow: inset 2px 0 0 var(--chip-strong), var(--sh-2);
  transform: translate(-50%, -60%);
}

/* Passpalett (snabbmålning) */
.palette { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.palette__label { font-size: var(--fs-sm); color: var(--text-2); margin-right: var(--s-1); }
.palette__btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px 0 6px;
  border: 1px solid var(--border-strong); border-radius: var(--r-md); background: var(--surface);
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
}
.palette__btn:hover { background: var(--surface-hover); }
.palette__btn[aria-pressed="true"] { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); background: var(--surface-2); }
.palette__sw { width: 20px; height: 20px; border-radius: var(--r-xs); display: grid; place-items: center; font-size: 11px; font-weight: var(--fw-semibold); background: var(--surface-2); box-shadow: inset 2px 0 0 color-mix(in oklab, var(--sw) 85%, var(--text)), inset 0 0 0 1px color-mix(in oklab, var(--border) 70%, transparent); color: color-mix(in oklab, var(--sw) 45%, var(--text)); }
.palette__time { color: var(--text-3); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }

/* Passväljare i popover */
.picker { display: grid; gap: 2px; padding: var(--s-1); min-width: 240px; max-height: min(420px, 70vh); overflow-y: auto; }
.picker__title { padding: var(--s-2) var(--s-2) var(--s-1); font-size: var(--fs-xs); color: var(--text-3); font-weight: var(--fw-medium); }
.picker__opt {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: var(--s-2);
  min-height: 40px; padding: var(--s-1) var(--s-2); border: 0; border-radius: var(--r-md);
  background: transparent; text-align: left;
}
.picker__opt:hover, .picker__opt:focus-visible { background: var(--surface-hover); outline: none; }
.picker__opt:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.picker__opt[aria-selected="true"] { background: var(--primary-soft); }
.picker__name { display: grid; line-height: 1.2; min-width: 0; }
.picker__name span:first-child { font-weight: var(--fw-medium); }
.picker__name span + span { font-size: var(--fs-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }
.picker__sep { height: 1px; background: var(--border); margin: var(--s-1) 0; }
.picker__opt--danger { color: var(--danger-text); }
.picker__ico { width: 28px; display: grid; place-items: center; }

/* ───────────────────────── Schemarutnät ─────────────────────────
   Tät och dämpad: tunna linjer, tabulära siffror, tydlig veckostart, helg som svag neutral ton. */
.sched {
  position: relative; min-width: 0;
  --sched-line: color-mix(in oklab, var(--border) 70%, transparent);
  --sched-line-strong: var(--border-strong);
  --sched-weekend: color-mix(in oklab, var(--surface-sunken) 45%, var(--surface));
}
.sched__scroll {
  overflow: auto; max-height: var(--sched-max-h, calc(100dvh - var(--topbar-h) - 180px)); min-height: 200px;
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface);
  overscroll-behavior: contain;
}
.sched__table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.sched__table th, .sched__table td { border-bottom: 1px solid var(--sched-line); border-right: 1px solid var(--sched-line); padding: 0; }
.sched__table thead th {
  position: sticky; top: 0; z-index: 3; background: var(--surface);
  height: 38px; min-width: var(--sched-col, 54px); font-weight: var(--fw-medium);
}
.sched__table thead .sched__days th { top: 24px; border-bottom-color: var(--border); }
.sched__table thead .sched__weeks th {
  height: 24px; padding: 0 8px; white-space: nowrap; text-align: left;
  font-size: 10.5px; font-weight: var(--fw-semibold); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3);
}
.sched__table thead .sched__weeks .sched__corner, .sched__table thead .sched__weeks .sched__sum { height: 62px; border-bottom-color: var(--border); }
.sched__daybtn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; width: 100%; height: 100%; padding: 3px 2px; border: 0; background: none; color: inherit; font: inherit; }
button.sched__daybtn:hover { background: var(--surface-hover); }
.sched__dow { font-size: 11px; color: var(--text-3); text-transform: lowercase; line-height: 1.1; }
.sched__dom { font-size: var(--fs-sm); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; line-height: 1.25; padding: 0 2px; }
.sched__table thead th.is-weekend { background: var(--sched-weekend); }
.sched__table thead th.is-weekend .sched__dom { color: var(--text-2); }
.sched__table thead th.is-today .sched__dow { color: var(--primary); }
.sched__table thead th.is-today .sched__dom { color: var(--primary); box-shadow: inset 0 -2px 0 var(--primary); }
/* Veckostart: starkare linje mellan veckor (på cellen före, så att linjen blir en och inte dubbel) */
.sched__table :is(th, td):has(+ .is-week-start) { border-right-color: var(--sched-line-strong); }
.sched__corner, .sched__rowhead {
  position: sticky; left: 0; z-index: 2; background: var(--surface);
  text-align: left; min-width: var(--sched-rowhead, 196px); max-width: var(--sched-rowhead, 196px);
  box-shadow: 1px 0 0 var(--sched-line);
}
.sched__table thead .sched__corner {
  z-index: 4; padding: 0 var(--s-3); background: var(--surface);
  font-size: 10.5px; font-weight: var(--fw-semibold); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3);
}
.sched__rowhead { padding: 3px var(--s-3) !important; font-weight: var(--fw-regular); }
.sched__rowbtn { display: block; width: 100%; padding: 0; border: 0; background: none; text-align: left; color: inherit; font: inherit; border-radius: var(--r-xs); }
.sched__rowlabel { display: block; font-size: var(--fs-sm); font-weight: var(--fw-medium); line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched__rowsub { display: block; font-size: 11px; line-height: 1.25; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.sched__rowmeta { margin-top: 2px; }
button.sched__rowbtn:hover .sched__rowlabel { color: var(--primary); text-decoration: underline; text-underline-offset: 2px; }
.sched__group th {
  position: sticky; left: 0; z-index: 1; text-align: left; height: 26px; padding: 0 var(--s-3) !important;
  background: var(--surface-2); border-bottom-color: var(--border);
  font-size: 10.5px; font-weight: var(--fw-semibold); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-2);
}
/* Gruppnamnet följer med vid vågrät rullning (cellen spänner hela tabellen och kan inte själv vara klistrad) */
.sched__grouplabel { position: sticky; left: var(--s-3); display: inline-block; }
.sched__cell {
  height: var(--sched-row, 40px); min-width: var(--sched-col, 54px); vertical-align: middle;
  padding: 3px !important; position: relative; background: var(--surface);
}
.sched__cellin { display: flex; flex-direction: column; gap: 2px; justify-content: center; min-height: 100%; }
.sched__cell.is-weekend { background: var(--sched-weekend); }
.sched__cell.is-today { background: color-mix(in oklab, var(--primary) 4%, var(--surface)); }
.sched__cell.is-absent { background: var(--surface-sunken); }
.sched__cell.is-blocked { background: repeating-linear-gradient(135deg, color-mix(in oklab, var(--text) 7%, transparent) 0 1px, transparent 1px 6px), var(--surface-2); }
.sched__cell.is-off { background: var(--surface-sunken); }
.sched__cell.is-wish { box-shadow: inset 0 -2px 0 color-mix(in oklab, var(--accent) 45%, transparent); }
.sched__cell.is-conflict { box-shadow: inset 0 0 0 1px var(--danger); }
.sched__cell.is-gap { background: repeating-linear-gradient(135deg, color-mix(in oklab, var(--text) 8%, transparent) 0 1px, transparent 1px 6px), var(--surface); }
.sched__mark { display: block; text-align: center; font-size: 11px; color: var(--text-3); font-weight: var(--fw-medium); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched__cell.is-blocked .sched__mark { color: var(--text-2); }
.sched__cell.is-wish .sched__mark { color: var(--accent-text); font-weight: var(--fw-regular); }
.sched__cell.is-gap .sched__mark { color: var(--warn-text); font-weight: var(--fw-semibold); }
.sched__cell .chip { width: 100%; }
.sched__cell:focus { outline: none; }
.sched__cell:focus-visible, .sched__cell.is-focus { outline: 2px solid var(--focus); outline-offset: -2px; z-index: 1; border-radius: 0; }
.sched--editable .sched__cell { cursor: pointer; }
.sched--editable .sched__cell.is-empty:hover::after {
  content: "+"; position: absolute; inset: 3px; display: grid; place-items: center;
  border: 1px dashed var(--border-input); border-radius: var(--r-xs); color: var(--text-3); font-size: 14px; font-weight: var(--fw-regular);
}
.sched--painting .sched__cell { cursor: crosshair; }
.sched--painting .sched__cell.is-empty:hover::after { content: none; }
.sched--painting .sched__table { user-select: none; }
.sched__cell.is-painting { background: color-mix(in oklab, var(--paint, var(--primary)) 12%, var(--surface)); box-shadow: inset 0 0 0 2px var(--paint, var(--primary)); }
.sched__cell.is-drop-target { background: var(--primary-soft); box-shadow: inset 0 0 0 2px var(--primary); }
.sched__cell.is-moving-source .chip { opacity: 0.4; }
.sched--dragging, .sched--dragging * { cursor: grabbing !important; }
.sched__table tbody tr:hover .sched__rowhead { background: var(--surface-2); }
.sched__sum { padding: 0 var(--s-3) !important; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; font-size: var(--fs-xs); line-height: 1.3; min-width: 92px; background: var(--surface-2); position: sticky; right: 0; z-index: 2; box-shadow: -1px 0 0 var(--border); }
.sched__sum .fw-medium { font-weight: var(--fw-semibold); }
.sched__sum--inner { right: 128px; min-width: 96px; }
.sched__sum--last { min-width: 128px; width: 128px; max-width: 128px; right: 0; }
.sched__table thead .sched__weeks th.sched__sum { white-space: normal; line-height: 1.3; } /* rubriken bryts så att sista kolumnen håller 128 px och inte täcker 'Mot mål' (måste slå veckoradens th-nowrap) */
.sched .is-dimmed { opacity: .14; filter: grayscale(.6); }
.sched__table thead .sched__sum { z-index: 4; background: var(--surface-2); }
.sched__table tfoot th, .sched__table tfoot td { position: sticky; bottom: 0; z-index: 2; background: var(--surface-2); height: 32px; text-align: center; border-top: 1px solid var(--border); }
.sched__table tfoot tr + tr th, .sched__table tfoot tr + tr td { border-top: 0; }
.sched__table tfoot .sched__corner {
  z-index: 4; text-align: left; padding: 0 var(--s-3);
  font-size: 10.5px; font-weight: var(--fw-semibold); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-2);
}
.sched__table tfoot .sched__sum { z-index: 4; }
.sched--compact { --sched-col: 42px; --sched-row: 34px; --sched-rowhead: 160px; }
.sched--compact .chip { padding: 2px 3px 2px 6px; gap: 2px; }
.sched--compact .chip__label, .sched--compact .chip__time { display: none; }
.sched__hint { margin-top: var(--s-2); font-size: var(--fs-xs); color: var(--text-3); display: flex; gap: var(--s-3); flex-wrap: wrap; }
@media (max-width: 719px) { .sched { --sched-rowhead: 128px; --sched-col: 46px; } }

.legend { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); font-size: var(--fs-xs); color: var(--text-2); align-items: center; }
.legend__item { display: inline-flex; align-items: center; gap: 6px; }
.legend__sw { width: 14px; height: 14px; border-radius: var(--r-xs); flex: none; border: 1px solid var(--border-strong); }

/* Periodnavigering */
.period-nav { display: inline-flex; align-items: center; gap: var(--s-1); }
.period-nav__label { display: grid; min-width: 150px; padding: 0 var(--s-2); text-align: center; line-height: 1.2; }
.period-nav__main { font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.period-nav__sub { font-size: var(--fs-xs); color: var(--text-3); white-space: nowrap; }

/* ───────────────────────── Dialoger ───────────────────────── */
dialog.modal {
  padding: 0; border: 0; color: var(--text);
  background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--sh-3);
  width: min(calc(100vw - 32px), var(--modal-w, 560px));
  max-height: min(calc(100vh - 48px), calc(100dvh - 48px), 900px);
  display: flex; flex-direction: column; overflow-x: hidden; overflow-y: auto;
}
dialog.modal:not([open]) { display: none; }
dialog.modal::backdrop { background: var(--backdrop); }
.modal--sm { --modal-w: 480px; }
.modal--md { --modal-w: 680px; }
.modal--lg { --modal-w: 880px; }
.modal--xl { --modal-w: 1120px; }
.modal__head { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-5) var(--s-5) var(--s-3); flex: none; }
.modal__titles { flex: 1; min-width: 0; display: grid; gap: var(--s-1); }
.modal__title { font-size: var(--fs-xl); letter-spacing: -0.01em; }
.modal__desc { color: var(--text-2); }
.modal__head .btn { margin: -4px -6px 0 0; }
.modal__body { padding: var(--s-2) var(--s-5) var(--s-5); overflow-y: auto; flex: 1 1 auto; min-height: min(16rem, 40vh); }
.modal__foot {
  display: flex; justify-content: flex-end; gap: var(--s-2); flex-wrap: wrap; flex: none;
  padding: var(--s-3) var(--s-5); border-top: 1px solid var(--border); background: var(--surface-2);
  position: sticky; bottom: 0; z-index: 1;
}
.modal__foot .modal__foot-start { margin-right: auto; }
dialog.modal[open] { animation: sp-modal-in var(--dur-2) var(--ease); }
dialog.modal[open]::backdrop { animation: sp-fade-in var(--dur-2) var(--ease); }
dialog.modal.is-closing { animation: sp-modal-out 140ms var(--ease) forwards; }
dialog.modal.is-closing::backdrop { animation: sp-fade-out 140ms var(--ease) forwards; }

/* Låg fönsterhöjd: korta ner modalens fasta delar så att innehållet får plats */
@media (max-height: 720px) {
  dialog.modal { max-height: calc(100dvh - 16px); }
  .modal__head { padding: var(--s-3) var(--s-4) var(--s-1); }
  .modal__title { font-size: var(--fs-lg, 1.1rem); }
  .modal__desc { display: none; }
  .modal__body { padding: var(--s-2) var(--s-4) var(--s-3); }
  .modal__foot { padding: var(--s-2) var(--s-4); }
}

/* Mycket låg fönsterhöjd: hela dialogen scrollar i stället för att innehållet klipps bort */
@media (max-height: 520px) {
  dialog.modal:not(.cmdk) { overflow-y: auto; }
  dialog.modal:not(.cmdk) .modal__body { flex: none; overflow: visible; min-height: auto; }
  .wizard__steps { margin-bottom: var(--s-3); }
  .wizard__step { min-width: 0; }
}

dialog.modal--drawer {
  margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; border-radius: var(--r-xl) 0 0 var(--r-xl);
  width: min(100vw, var(--modal-w, 480px));
}
dialog.modal--drawer[open] { animation: sp-drawer-in var(--dur-2) var(--ease); }
dialog.modal--drawer.is-closing { animation: sp-drawer-out 140ms var(--ease) forwards; }

@media (max-width: 599px) {
  dialog.modal {
    width: 100vw; max-width: 100vw; margin: auto 0 0; max-height: calc(100dvh - 24px);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }
  dialog.modal[open] { animation: sp-sheet-in var(--dur-2) var(--ease); }
  dialog.modal.is-closing { animation: sp-sheet-out 140ms var(--ease) forwards; }
  dialog.modal--drawer { height: auto; max-height: calc(100dvh - 24px); border-radius: var(--r-xl) var(--r-xl) 0 0; margin: auto 0 0; }
  .modal__head { padding: var(--s-4) var(--s-4) var(--s-2); }
  .modal__body { padding: var(--s-2) var(--s-4) var(--s-4); }
  .modal__foot { padding: var(--s-3) var(--s-4) calc(var(--s-3) + env(safe-area-inset-bottom)); }
  .modal__foot .btn { flex: 1; }
}

/* Guide (wizard) */
.wizard__steps { display: flex; gap: var(--s-2); list-style: none; margin: 0 0 var(--s-5); padding: 0; overflow-x: auto; }
.wizard__step { flex: 1; min-width: 96px; display: grid; gap: 6px; font-size: var(--fs-xs); color: var(--text-3); }
.wizard__step::before { content: ""; height: 4px; border-radius: var(--r-pill); background: var(--surface-sunken); }
.wizard__step.is-done::before { background: var(--primary-soft-2); }
.wizard__step.is-current { color: var(--text); font-weight: var(--fw-semibold); }
.wizard__step.is-current::before { background: var(--primary); }
.wizard__intro { color: var(--text-2); margin-bottom: var(--s-4); }
.wizard__error { margin-bottom: var(--s-4); }

/* ───────────────────────── Popover, meny, toasts ───────────────────────── */
.popover {
  position: fixed; inset: auto; margin: 0; z-index: var(--z-popover);
  min-width: 180px; max-width: min(360px, calc(100vw - 16px));
  padding: 0; border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); color: var(--text); box-shadow: var(--sh-2);
  overflow: visible;
  animation: sp-pop-in var(--dur-1) var(--ease);
}
.popover:not(:popover-open):not(.is-open) { display: none; }
.popover__body { padding: var(--s-3); }
.menu { display: grid; padding: var(--s-1); gap: 1px; }
.menu__item {
  display: flex; align-items: center; gap: var(--s-2); min-height: 34px; padding: 0 var(--s-3) 0 var(--s-2);
  border: 0; border-radius: var(--r-sm); background: none; text-align: left; font-size: var(--fs-md); color: var(--text);
  white-space: nowrap;
}
.menu__item .icon { color: var(--text-3); }
.menu__item:hover, .menu__item:focus-visible { background: var(--surface-hover); outline: none; }
.menu__item:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.menu__item--danger, .menu__item--danger .icon { color: var(--danger-text); }
.menu__item:disabled { opacity: 0.45; }
.menu__check { margin-left: auto; color: var(--primary); }
.menu__sep { height: 1px; background: var(--border); margin: var(--s-1) 0; }
.menu__heading { padding: var(--s-2) var(--s-2) 2px; font-size: var(--fs-xs); color: var(--text-3); }

.toast-region {
  position: fixed; inset: auto var(--s-4) var(--s-4) auto; margin: 0; padding: 0; border: 0; background: transparent;
  z-index: var(--z-toast); width: min(400px, calc(100vw - 32px)); overflow: visible;
  display: flex; flex-direction: column; gap: var(--s-2); pointer-events: none;
}
.toast-region:not(:popover-open):not(.is-open) { display: none; }
/* Mobil: överst under toppraden, så att aviseringen aldrig täcker formulär, knappar eller bottenmenyn. */
@media (max-width: 719px) { .toast-region { inset: calc(var(--topbar-h) + var(--s-2) + env(safe-area-inset-top)) var(--s-3) auto var(--s-3); width: auto; } }
.toast {
  pointer-events: auto;
  display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
  background: var(--text); color: var(--text-inverse);
  border-radius: var(--r-lg); box-shadow: var(--sh-3);
  animation: sp-toast-in var(--dur-2) var(--ease);
}
.toast.is-leaving { animation: sp-toast-out 160ms var(--ease) forwards; }
.toast > .icon { margin-top: 1px; }
.toast--success > .icon { color: #7fd6a3; }
.toast--warning > .icon { color: #f3c271; }
.toast--danger > .icon { color: #ff9c92; }
.toast--info > .icon { color: #9dbcf3; }
:root[data-theme="dark"] .toast--success > .icon { color: var(--ok); }
:root[data-theme="dark"] .toast--danger > .icon { color: #b42318; }
.toast__body { flex: 1; min-width: 0; display: grid; gap: 2px; padding-top: 1px; }
.toast__title { font-weight: var(--fw-semibold); }
.toast__msg { font-size: var(--fs-sm); opacity: 0.92; }
.toast__action {
  border: 0; background: none; color: inherit; font-weight: var(--fw-semibold); text-decoration: underline; text-underline-offset: 2px;
  padding: 2px 4px; border-radius: var(--r-sm); white-space: nowrap; align-self: center;
}
.toast__close { border: 0; background: none; color: inherit; opacity: 0.7; padding: 2px; border-radius: var(--r-sm); display: grid; place-items: center; }
.toast__close:hover { opacity: 1; }
.toast :focus-visible { outline-color: currentColor; }

/* Global sök */
dialog.modal.cmdk { --modal-w: 620px; margin-top: 12vh; max-height: 72vh; }
@media (max-width: 599px) { dialog.modal.cmdk { margin: 0; height: 100dvh; max-height: 100dvh; border-radius: 0; } }
.cmdk__bar { display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-4); border-bottom: 1px solid var(--border); flex: none; }
.cmdk__bar > .icon { color: var(--text-3); }
.cmdk__input { flex: 1; height: 56px; border: 0; background: transparent; font-size: var(--fs-lg); min-width: 0; }
.cmdk__input:focus { outline: none; }
.cmdk__list { overflow-y: auto; padding: var(--s-2); flex: 1; min-height: 0; list-style: none; margin: 0; }
.cmdk__group { padding: var(--s-3) var(--s-2) var(--s-1); font-size: var(--fs-xs); color: var(--text-3); font-weight: var(--fw-medium); }
.cmdk__opt { display: flex; align-items: center; gap: var(--s-3); min-height: 44px; padding: var(--s-1) var(--s-3); border-radius: var(--r-md); cursor: pointer; }
.cmdk__opt[aria-selected="true"] { background: var(--primary-soft); }
.cmdk__opt-ico { width: 32px; height: 32px; border-radius: var(--r-md); background: var(--surface-sunken); color: var(--text-2); display: grid; place-items: center; flex: none; }
.cmdk__opt[aria-selected="true"] .cmdk__opt-ico { background: var(--primary); color: var(--on-primary); }
.cmdk__opt-text { display: grid; min-width: 0; line-height: 1.25; flex: 1; }
.cmdk__opt-title { font-weight: var(--fw-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk__opt-sub { font-size: var(--fs-xs); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk__opt-hint { font-size: var(--fs-xs); color: var(--text-3); white-space: nowrap; }
.cmdk__foot { display: flex; gap: var(--s-4); flex-wrap: wrap; padding: var(--s-2) var(--s-4); border-top: 1px solid var(--border); background: var(--surface-2); font-size: var(--fs-xs); color: var(--text-3); flex: none; }
.cmdk__foot span { display: inline-flex; gap: 4px; align-items: center; }
.cmdk__empty { padding: var(--s-8) var(--s-4); text-align: center; color: var(--text-3); }

.shortcut-list { display: grid; grid-template-columns: auto 1fr; gap: var(--s-2) var(--s-4); align-items: center; font-size: var(--fs-sm); }
.shortcut-list dt { display: flex; gap: 4px; justify-content: flex-end; white-space: nowrap; }
.shortcut-list h3 { grid-column: 1 / -1; margin-top: var(--s-3); font-size: var(--fs-sm); }

.session-panel { display: grid; gap: var(--s-4); width: min(340px, calc(100vw - 32px)); padding: var(--s-4); }
.session-panel h2 { font-size: var(--fs-md); }

/* ───────────────────────── Verktygsklasser ───────────────────────── */
.stack { display: flex; flex-direction: column; gap: var(--s-4); min-width: 0; }
.stack-xs { display: flex; flex-direction: column; gap: var(--s-1); min-width: 0; }
.stack-sm { display: flex; flex-direction: column; gap: var(--s-2); min-width: 0; }
.stack-lg { display: flex; flex-direction: column; gap: var(--s-6); min-width: 0; }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); min-width: 0; }
.cluster-lg { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-4); min-width: 0; }
.split { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; min-width: 0; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-4); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--grid-min, 260px), 1fr)); gap: var(--s-4); }
.grid-main-side { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 360px); gap: var(--s-4); align-items: start; }
@media (max-width: 1099px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-main-side { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 719px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); } }
.span-all { grid-column: 1 / -1; }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.text-xs { font-size: var(--fs-xs); }
.text-sm { font-size: var(--fs-sm); }
.text-lg { font-size: var(--fs-lg); }
.fw-medium { font-weight: var(--fw-medium); }
.fw-semibold { font-weight: var(--fw-semibold); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.text-end { text-align: right; }
.text-success { color: var(--ok-text); }
.text-warning { color: var(--warn-text); }
.text-danger { color: var(--danger-text); }
.divider { height: 1px; background: var(--border); border: 0; margin: 0; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: var(--s-2) var(--s-4); font-size: var(--fs-sm); }
.dl dt { color: var(--text-3); }
.dl dd { font-weight: var(--fw-medium); min-width: 0; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-rows { list-style: none; margin: 0; padding: 0; }
.list-rows > li { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--border); min-width: 0; }
.list-rows > li:last-child { border-bottom: 0; }
.list-rows > li.stack, .list-rows > li.stack-xs, .list-rows > li.stack-sm, .list-rows > li.stack-lg { align-items: stretch; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ───────────────────────── Rörelse ───────────────────────── */
@keyframes sp-spin { to { transform: rotate(360deg); } }
@keyframes sp-shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
@keyframes sp-pulse { 50% { opacity: 0.55; } }
@keyframes sp-fade-in { from { opacity: 0; } }
@keyframes sp-fade-out { to { opacity: 0; } }
@keyframes sp-modal-in { from { opacity: 0; transform: translateY(8px) scale(0.985); } }
@keyframes sp-modal-out { to { opacity: 0; transform: translateY(4px) scale(0.99); } }
@keyframes sp-drawer-in { from { transform: translateX(24px); opacity: 0; } }
@keyframes sp-drawer-out { to { transform: translateX(24px); opacity: 0; } }
@keyframes sp-sheet-in { from { transform: translateY(32px); opacity: 0; } }
@keyframes sp-sheet-out { to { transform: translateY(32px); opacity: 0; } }
@keyframes sp-pop-in { from { opacity: 0; transform: translateY(-4px); } }
@keyframes sp-toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes sp-toast-out { to { opacity: 0; transform: translateX(16px); } }
@keyframes sp-flash { 0% { background: var(--primary-soft-2); } 100% { background: transparent; } }
.is-flash { animation: sp-flash 1.2s var(--ease); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .spinner::before, .btn.is-busy::after { animation-duration: 1.6s !important; animation-iteration-count: infinite !important; }
}

@media (forced-colors: active) {
  /* Högkontrastläge: systemfärger, synliga kanter där färg bar information. */
  .chip, .badge, .pill, .status, .btn, .input, .select, .textarea, .segmented, .tabs__tab[aria-selected="true"],
  .panel, .kpi, .callout, .toast, .modal, .popover, .menu, .cmdk__opt[aria-selected="true"], .choice, .lock-card { border: 1px solid CanvasText; }
  .nav__link[aria-current="page"], .bottomnav__item[aria-current="page"] { border: 2px solid Highlight; color: Highlight; }
  .btn--primary, .palette__btn[aria-pressed="true"], .segmented [aria-checked="true"], .segmented [aria-pressed="true"] { background: Highlight; color: HighlightText; border-color: Highlight; forced-color-adjust: none; }
  .switch__track, .check__box { border: 1px solid CanvasText; }
  .ring__bar, .meter__bar, .chart__bar, .spark path, .coverage__bar { forced-color-adjust: none; stroke: Highlight; background: Highlight; }
  .sched__cell.is-gap, .sched__cell.is-conflict { outline: 2px dashed Mark; outline-offset: -3px; }
  .sched__cell.is-painting, .sched__cell.is-drop-target { outline: 2px solid Highlight; outline-offset: -2px; }
  .chip__day, .chip__seg { forced-color-adjust: none; background: CanvasText; }
  .skeleton__line, .skeleton__block { background: GrayText; animation: none; }
  :focus-visible, .sched__cell:focus-visible { outline: 3px solid Highlight !important; outline-offset: 2px; }
  .sr-only { forced-color-adjust: auto; }
  .sched__sum, .sched__corner, .sched__rowhead, .sched__table thead th { background: Canvas !important; }
  .sched__sum { border-left: 2px solid CanvasText; }
  .sched__corner, .sched__rowhead { border-right: 2px solid CanvasText; }
}


/* Smala skärmar: ge dagarna plats – smalare radhuvud, summakolumnen scrollar med. */
@media (max-width: 599px) {
  .sched { --sched-rowhead: 104px; }
  .sched__rowhead { padding: 4px var(--s-2) !important; }
  .sched__rowhead .sched__rowname, .sched__rowhead > :first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
  /* Summakolumnerna ligger sist i tabellen och scrollar in under den klistrade namnkolumnen (104 px). Vid full
     scroll måste båda rymmas till höger om den: 2 × 92 px ≤ 360 − sidmarginaler − 104. Smal padding så att
     "136/138 h" och "timanställd" ändå får plats. */
  .sched__table .sched__sum, .sched__table .sched__sum--inner, .sched__table .sched__sum--last {
    position: static; right: auto; width: 92px; min-width: 92px; max-width: 92px; padding: 0 6px !important; box-shadow: none;
  }
  .sched__table thead .sched__sum { position: sticky; }
  .sched__table thead .sched__weeks th.sched__sum { white-space: normal; } /* "Totalt alla boenden" bryts på två rader (slår veckoradens nowrap) */
  .sched__table thead .sched__corner { padding: 0 var(--s-2); }
}
@media (max-width: 400px) {
  /* 360 px breda telefoner: namnkolumn 96 px och 2 × 88 px summor så att båda syns vid full scroll. */
  .sched { --sched-rowhead: 96px; }
  .sched__table .sched__sum, .sched__table .sched__sum--inner, .sched__table .sched__sum--last { width: 88px; min-width: 88px; max-width: 88px; padding: 0 5px !important; }
}

/* ───────── Applås (#lock-root, fylls av js/lock.js med ui.lockPanel) ───────── */
.lock-layer {
  position: fixed; inset: 0; z-index: 2147483000; display: grid; place-items: center;
  padding: max(var(--s-4), env(safe-area-inset-top)) var(--s-4) max(var(--s-4), env(safe-area-inset-bottom));
  background: var(--bg); overflow-y: auto;
}
.lock-layer[hidden] { display: none; }
.lock-layer:focus { outline: none; }
html.is-locked .app { visibility: hidden; }
html.is-locked .toast-region, html.is-locked .popover { display: none !important; }
html.is-locked, html.is-locked body { overflow: hidden; }
.lock-card {
  width: min(100%, 400px); display: grid; gap: var(--s-3); padding: var(--s-8) var(--s-6) var(--s-6);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-lg, 0 12px 32px rgb(0 0 0 / .12));
}
.lock-card__brand { display: flex; align-items: center; gap: var(--s-2); font-weight: var(--fw-semibold); color: var(--text-2); font-size: var(--fs-sm); }
.lock-card__brand svg { width: 24px; height: 24px; }
.lock-card__brand .brand__word { width: 100px; height: 21px; color: var(--text); }
.lock-card__icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft, var(--surface-2)); color: var(--primary); margin-top: var(--s-4); }
.lock-card__title { font-size: var(--fs-xl); line-height: 1.25; margin: 0; }
.lock-card__text { color: var(--text-2); margin: 0; }
.lock-card__body { display: grid; gap: var(--s-3); margin-top: var(--s-2); }
.lock-card__foot { display: flex; flex-wrap: wrap; gap: var(--s-2); justify-content: space-between; align-items: center; margin-top: var(--s-2); }
@media (max-width: 479px) { .lock-card { padding: var(--s-6) var(--s-4) var(--s-4); } }

/* Scrollbehållare blir innehållande block, så att .sr-only-element (position:absolute) klipps i stället för att ge sidscroll. */
.matrix-wrap, .table-wrap, .tabs__list, .segmented, .wizard__steps, .sched__scroll { position: relative; }


/* ───────── Laddläge i sidans form ───────── */
.page-skeleton { display: grid; gap: var(--s-6); }
.page-skeleton__head { display: grid; gap: var(--s-3); padding-top: var(--s-1); }
.skeleton__line--title { height: 26px; border-radius: var(--r-md); }
.skeleton__line--value { height: 24px; }
.page-skeleton__kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s-4); }
.page-skeleton__kpi, .page-skeleton__panel { display: grid; gap: var(--s-3); padding: var(--s-5); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); }
.page-skeleton__panel { gap: var(--s-4); min-height: 280px; align-content: start; }
.view-loading { animation: sp-fade-in 200ms ease-out both; animation-delay: 60ms; }

/* ───────── Mjuka vyövergångar (bara opacitet – flyttar inga sticky- eller fasta element) ───────── */
.view--enter { animation: sp-view-in 220ms cubic-bezier(.2, .7, .3, 1) both; }
@keyframes sp-view-in { from { opacity: 0; } }
.view--enter > * { animation: sp-view-rise 260ms cubic-bezier(.2, .7, .3, 1) both; }
.view--enter > :nth-child(2) { animation-delay: 30ms; }
.view--enter > :nth-child(3) { animation-delay: 60ms; }
.view--enter > :nth-child(n+4) { animation-delay: 90ms; }
@keyframes sp-view-rise { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) {
  .view--enter, .view--enter > *, .view-loading { animation: none !important; }
}

/* ───────── Välkomstguide ───────── */
.welcome-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-3); counter-reset: wstep; }
.welcome-steps__item { display: grid; grid-template-columns: auto 1fr; gap: var(--s-3); align-items: start; padding: var(--s-4); border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface-2); counter-increment: wstep; }
.welcome-steps__icon { position: relative; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.welcome-steps__icon::after { content: counter(wstep); position: absolute; right: -4px; bottom: -4px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--primary); color: var(--on-primary); font-size: 11px; font-weight: var(--fw-semibold); display: grid; place-items: center; box-shadow: 0 0 0 2px var(--surface-2); }
.welcome-steps__text { display: grid; gap: 2px; }
.welcome-steps__text strong { font-weight: var(--fw-semibold); }
.welcome-steps__text span { color: var(--text-2); }

/* ───────── Kommandopalett: kortkommandon och G-läge ───────── */
.cmdk__opt-keys { display: inline-flex; gap: 3px; margin-left: auto; flex: none; }
.cmdk__opt-keys + .cmdk__opt-hint { margin-left: var(--s-2); }
.cmdk__opt-keys kbd { min-width: 20px; text-align: center; }
html.is-goto .topbar::after {
  content: "Gå till … tryck O, E, S, P, V, R, I eller M"; position: fixed; left: 50%; bottom: calc(var(--s-6) + env(safe-area-inset-bottom)); transform: translateX(-50%);
  padding: var(--s-2) var(--s-4); border-radius: var(--r-md); background: var(--text); color: var(--bg); font-size: var(--fs-sm); box-shadow: var(--shadow-lg, 0 8px 24px rgb(0 0 0 / .2)); z-index: 60; pointer-events: none;
  animation: sp-fade-in 120ms ease-out;
}

/* ───────── Utskrift: A4 liggande, utan skal ───────── */
@page { size: A4 landscape; margin: 10mm 10mm 12mm; }
@media print {
  :root, :root[data-theme="dark"] {
    color-scheme: light;
    --bg: #fff; --surface: #fff; --surface-2: #f6f7f7; --surface-sunken: #f1f3f2; --surface-hover: #f1f3f2;
    --text: #000; --text-2: #222; --text-3: #444; --border: #bfc6c3; --border-strong: #8a948f;
  }
  html, body { background: #fff !important; font-size: 10pt; }
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; animation: none !important; transition: none !important; box-shadow: none !important; }
  .skip-link, .sidebar, .topbar, .bottomnav, .toast-region, .popover, dialog, .lock-layer,
  .page-header__actions, .period-nav button, .palette, .sched__hint, .btn, .tabs__list, .segmented,
  .field:has(select), [data-print="hide"], .no-print { display: none !important; }
  [data-print="show"] { display: revert !important; }
  .app { display: block; min-height: 0; }
  .main { display: block; }
  #main[data-print-meta]::before { content: attr(data-print-meta); display: block; font-size: 8pt; color: #444; margin-bottom: 4mm; padding-bottom: 2mm; border-bottom: 0.5pt solid #bfc6c3; }
  .view { padding: 0 !important; max-width: none; gap: 5mm; }
  .page-header h1 { font-size: 16pt; }
  .panel, .kpi, .callout { border: 0.5pt solid #bfc6c3; }
  .kpi, .callout, .ring, .panel:not(:has(.sched, .tbl, .chart)) { break-inside: avoid; }
  .grid-2, .grid-3, .grid-4, .grid-auto, .grid-main-side { gap: 4mm; }
  .grid-main-side { grid-template-columns: 1fr; }
  h1, h2, h3 { break-after: avoid; }
  /* Schemarutnät: hela bredden, inga klistrade kolumner, rubriker upprepas per sida. */
  .sched__scroll { max-height: none !important; overflow: visible !important; border: 0; }
  .sched__table { width: 100%; font-size: 7pt; table-layout: fixed; }
  .sched__table .sched__corner, .sched__table .sched__rowhead { width: 30mm; min-width: 0 !important; max-width: none !important; }
  .sched__table .sched__sum { width: 18mm; min-width: 0 !important; font-size: 6.5pt; padding: 0 1mm !important; }
  .sched__table td, .sched__table th { overflow: hidden; }
  .sched__daybtn { padding: 0 !important; }
  .sched__cell > * { max-width: 100%; }
  .sched__cell { font-size: 6.5pt; white-space: nowrap; text-overflow: clip; }
  .chip { min-width: 0 !important; width: auto; max-width: 100%; gap: 0; }
  .chip__time, .chip__flags { display: none !important; }
  .coverage, .sched__table tfoot td { font-size: 6.5pt; }
  .sched__table thead { display: table-header-group; }
  .sched__table tfoot { display: table-footer-group; }
  .sched__table th, .sched__table td { position: static !important; box-shadow: none !important; }
  .sched__table tr { break-inside: avoid; }
  .sched__table thead th { height: auto; min-width: 0; padding: 1mm 0.5mm; }
  .sched__cell { min-width: 0 !important; height: auto !important; padding: 0.5mm !important; border: 0.25pt solid #d5dad8; }
  .sched { --sched-col: 0; --sched-rowhead: 34mm; }
  .chip { min-height: 0; padding: 0.4mm 1mm; font-size: 7pt; border: 0.5pt solid currentColor; }
  .chip__day { display: none; }
  .tbl { font-size: 8.5pt; }
  .table-wrap, .matrix-wrap { overflow: visible !important; }
  .tbl tr { break-inside: avoid; }
  a[href]::after { content: none !important; }
}

/* Nyckeltal på smala skärmar: två per rad, ringar krymper i stället för att ta en hel rad var. */
@media (max-width: 599px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
  .kpi-grid > .ring { padding: var(--s-2) 0; min-width: 0; }
  .kpi-grid .ring__svg { width: 84px !important; height: 84px !important; }
  .kpi-grid .ring__svg > svg { width: 100%; height: 100%; }
  .kpi-grid .ring__value { font-size: 18px !important; }
  .kpi-grid .ring__center .ring__sub { font-size: 9px; }
  .kpi-grid .ring__label { font-size: var(--fs-xs); max-width: 100%; }
  .kpi-grid .kpi { padding: var(--s-3); min-width: 0; }
  .kpi-grid .kpi__value { font-size: var(--fs-xl); }
  .kpi-grid .kpi .spark { display: none; }
}

/* ───────── Nästa steg (vägledning) ───────── */
.next-step {
  position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s-4); align-items: start;
  padding: var(--s-5); border-radius: var(--r-lg); border: 1px solid var(--primary-soft-2);
  background: var(--primary-soft);
}
.next-step--neutral { background: var(--surface); border-color: var(--border); }
.next-step--success { background: var(--ok-soft); border-color: color-mix(in oklab, var(--ok) 30%, transparent); }
.next-step--warning { background: var(--warn-soft); border-color: color-mix(in oklab, var(--warn) 35%, transparent); }
.next-step__icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); }
.next-step--neutral .next-step__icon { background: var(--primary-soft); color: var(--primary); }
.next-step--success .next-step__icon { background: var(--ok); color: var(--surface); }
.next-step--warning .next-step__icon { background: var(--warn); color: #1d1500; }
.next-step__body { display: grid; gap: var(--s-2); min-width: 0; }
.next-step__eyebrow { margin: 0; font-size: var(--fs-xs); color: var(--text-2); font-weight: var(--fw-medium); }
.next-step__title { margin: 0; font-size: var(--fs-lg); line-height: 1.3; font-weight: var(--fw-semibold); padding-right: var(--s-8); }
.next-step__text { margin: 0; color: var(--text-2); max-width: 70ch; }
.next-step__actions { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-2); }
.next-step__close { position: absolute; top: var(--s-3); right: var(--s-3); }
.next-step__steps { list-style: none; margin: var(--s-1) 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); }
.next-step__dot { display: inline-flex; align-items: center; gap: var(--s-2); font-size: var(--fs-sm); color: var(--text-2); }
.next-step__num { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: var(--fw-semibold); border: 1.5px solid var(--border-input); color: var(--text-2); background: var(--surface); }
.next-step__dot.is-done .next-step__num { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.next-step__dot.is-current { color: var(--text); font-weight: var(--fw-semibold); }
.next-step__dot.is-current .next-step__num { border-color: var(--primary); color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft-2); }
@media (max-width: 479px) {
  .next-step { grid-template-columns: minmax(0, 1fr); padding: var(--s-4); }
  .next-step__icon { width: 36px; height: 36px; }
  .next-step__actions > .btn { flex: 1 1 100%; }
}

/* ───────── Förklaringsikon ───────── */
.help-tip {
  display: inline-grid; place-items: center; width: 24px; height: 24px; margin: -4px 0 -4px 2px; padding: 0; vertical-align: middle;
  border: 0; border-radius: 50%; background: transparent; color: var(--text-3); cursor: help;
}
.help-tip:hover, .help-tip[aria-expanded="true"] { color: var(--primary); background: var(--primary-soft); }
.help-tip:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
@media (pointer: coarse) { .help-tip { width: 32px; height: 32px; margin: -8px 0 -8px 0; } }
.popover--tip { max-width: min(320px, calc(100vw - 32px)); padding: var(--s-3) var(--s-4); font-size: var(--fs-sm); line-height: 1.5; color: var(--text); }
.help-tip__text { margin: 0; }
@media (forced-colors: active) { .help-tip { border: 1px solid CanvasText; } .next-step { border: 1px solid CanvasText; } }

/* ───────── Säkerhetspanel ───────── */
.sidebar__foot-btn { all: unset; box-sizing: border-box; display: flex; align-items: flex-start; gap: var(--s-2); width: 100%; padding: var(--s-2); border-radius: var(--r-md); cursor: pointer; color: inherit; font: inherit; }
.sidebar__foot-btn:hover { background: var(--surface-hover); color: var(--text); }
.sidebar__foot-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.safety-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-3); }
.safety-list > li { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s-3); align-items: start; padding: var(--s-3) var(--s-4); border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface-2); }
.safety-list__icon { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.safety-list__icon.is-warning { background: var(--warn-soft); color: var(--warn-text); }
.safety-list strong { display: block; font-weight: var(--fw-semibold); margin-bottom: 2px; }
.safety-list p { margin: 0; color: var(--text-2); }
.safety-list .btn { margin-top: var(--s-2); }
.sidebar__foot { padding: var(--s-2) var(--s-3); }
.sidebar__foot-text { display: grid; gap: 1px; min-width: 0; }
.sidebar__foot-title { font-weight: var(--fw-semibold); color: var(--text-2); font-size: var(--fs-sm); }
.sidebar__foot.is-warning .sidebar__foot-title { color: inherit; }
.sidebar__foot-btn .icon { margin-top: 2px; flex: none; }
@media (min-width: 720px) and (max-width: 1099px) {
  .sidebar__foot { padding: var(--s-2); }
  .sidebar__foot-text { display: none; }
  .sidebar__foot-btn { justify-content: center; align-items: center; min-height: 44px; }
  .sidebar__foot-btn .icon { margin-top: 0; }
}
@media (max-width: 719px) { .toast { animation-name: sp-toast-in-top; } }
@keyframes sp-toast-in-top { from { opacity: 0; transform: translateY(-8px); } }
.sidebar__foot.is-danger, .sidebar__foot.is-danger .sidebar__foot-title { color: var(--danger-text); }

/* Rapport över reparerad data */
.repair-list__wrap { max-height: min(40vh, 320px); overflow: auto; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); }
.repair-list__wrap:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.repair-list { margin: 0; padding: var(--s-2) var(--s-3) var(--s-2) calc(var(--s-3) + 1.1em); display: grid; gap: var(--s-1); font-size: var(--fs-sm); }
.repair-list li { overflow-wrap: anywhere; }

/* Pekskärmar: små knappar ska ändå vara minst 44 px höga (WCAG 2.5.8 / bekvämt tryck). */
@media (pointer: coarse) { .btn--sm { min-height: 44px; } }

/* Tabell som kort på smala skärmar (t.ex. Konton): varje rad blir ett kompakt kort med etiketter. */
@media (max-width: 599px) {
  .table--cards, .table--cards tbody, .table--cards tr, .table--cards td { display: block; width: 100%; }
  .table--cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table--cards tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius, 8px); padding: var(--s-3); margin-bottom: var(--s-3); }
  .table--cards td { border: 0 !important; padding: 2px 0 !important; display: flex; flex-wrap: wrap; gap: 2px var(--s-2); align-items: baseline; }
  .table--cards td[data-label]::before { content: attr(data-label); flex: 0 0 4.5rem; color: var(--text-3); font-size: var(--fs-xs); }
  .table--cards td.table__main { padding-bottom: var(--s-2) !important; }
  .table--cards td.table__actions { padding-top: var(--s-2) !important; }
}
