/* ==========================================================
   DER ASSISTENZDIENST — Design System
   ==========================================================

   Architecture
   ────────────
   Classless CSS — styling hooks are data attributes & semantic HTML.
   No .class selectors anywhere. Styles target elements, roles,
   aria attributes, and data-* attributes directly.

   Layers (cascade order, lowest → highest specificity):
     1. reset    — box model, list/link/button normalization
     2. base     — tokens, typography, buttons, forms, tables,
                   badges, skip link, avatars (shared by all views)
     3. app      — mobile shell (Assistent & Klient apps, ≤ 430 px)
     4. desktop  — desktop shell (Planer app, sidebar + main)

   CSS Features Used
   ─────────────────
   oklch()            perceptual color space for uniform lightness
   color-mix(in oklch) derived surface tints from semantic colors
   light-dark()       single-token dual-mode (respects color-scheme)
   CSS Nesting (&)    native nesting throughout
   @property          typed custom properties (--hue, --bar-h)
   @layer             explicit cascade ordering
   @starting-style    entry animations on badges, cards, sections…
   @keyframes         shared reusable animations (fade-up, pop-in…)
   @view-transition   styled cross-page slide+fade transitions
   view-transition-name  pinned header / bottom-nav across pages
   @container         component-level responsive layouts
   @supports          Display P3 wide-gamut enhancement
   scrollbar-*        thin scrollbars with custom color
   range media queries  (width <= 1024px) syntax
   font-size-adjust   consistent x-height across font stacks
   logical properties  inline-size, block-size, margin-block-start…
   dvh                dynamic viewport on mobile

   Data Attributes (Styling Hooks)
   ───────────────────────────────
   data-app="mobile|desktop"  root layout mode
   data-status="ok|warn|err|info"  status badge color
   data-border="ok|warn|err"  left-border accent on cards
   data-variant="primary|danger|ghost"  button/link variants
   data-size="lg"             large full-width button
   data-initials              circular avatar (content via textContent)
   data-layout="master-detail|calendar-panel|table-panel|
                kpi|charts|2col|card-grid"  layout patterns
   data-overflow              horizontal scroll wrapper for tables
   data-match                 marks matching compare-grid values
   data-other                 empty/placeholder calendar cells
   data-open                  sidebar open state (toggled via JS)
   data-backup                backup-assistant chip style

   Color Tokens — light-dark(LIGHT, DARK)
   ───────────────────────────────────────
   --bg              page background
   --surface         recessed surface (e.g. table headers, tabs bg)
   --surface-raised  elevated surface (cards, panels, inputs)
   --text            primary text
   --text-muted      secondary/label text
   --border          default border
   --border-strong   emphasized border (hover states)
   --primary         brand blue + derived --primary-surface
   --ok              success green + derived --ok-surface
   --warn            warning amber + derived --warn-surface
   --err             error red + derived --err-surface
   --sidebar-bg      dark sidebar background
   --sidebar-text    sidebar text (light on dark)

   Layout Tokens
   ─────────────
   --radius     .5rem    border radius
   --nav-h      3.5rem   mobile bottom nav height
   --sidebar-w  14rem    desktop sidebar width
   --header-h   3.25rem  top bar height
   --speed      150ms ease  transition timing

   ========================================================== */


:root { color-scheme: light dark; }

@layer reset, base, app, desktop;


@view-transition {
  navigation: auto;
}

/* ─── View Transition Styling ─────────────────────────────
   Overrides the default crossfade with an iOS-like slide+fade.
   Old page slides out to the left while fading; new page
   slides in from the right. Duration 250 ms, ease-out.
   Header and bottom nav are pinned (view-transition-name)
   so they persist across navigations without flashing.    */

::view-transition-old(root) {
  animation: 250ms ease-out both vt-slide-out;
}
::view-transition-new(root) {
  animation: 250ms ease-out both vt-slide-in;
}

@keyframes vt-slide-out {
  to { opacity: 0; transform: translateX(-8%); }
}
@keyframes vt-slide-in {
  from { opacity: 0; transform: translateX(8%); }
}

/* Pinned chrome — these elements stay in place during
   cross-page transitions instead of crossfading.          */
::view-transition-group(app-header),
::view-transition-group(bottom-nav) {
  animation-duration: 0s;
}

/* ─── Shared Keyframes ────────────────────────────────────
   Reusable animations referenced from Layers app & desktop.
   All subject to the prefers-reduced-motion guard below.  */

@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
}
@keyframes pop-in {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes slide-up-number {
  from { opacity: 0; transform: translateY(8px); }
}
@keyframes fade-in {
  from { opacity: 0; }
}
@keyframes bar-grow {
  from { transform: scaleY(0); }
  to   { transform: scaleY(1); }
}

/* ─── Typed Custom Properties ─────────────────────────────── */

@property --hue {
  syntax: "<number>";
  inherits: true;
  initial-value: 250;
}
@property --bar-h {
  syntax: "<length-percentage>";
  inherits: false;
  initial-value: 0%;
}


/* ==========================================================
   LAYER: reset
   Box model, element normalization, scrollbar defaults.
   ========================================================== */

@layer reset {
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  html {
    font-size: 100%;
    -webkit-text-size-adjust: none;
    text-size-adjust: none;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: oklch(60% 0 0 / .35) transparent;
    scrollbar-gutter: stable;
    overscroll-behavior: contain;
    -webkit-tap-highlight-color: transparent;
  }

  img, svg { display: block; max-inline-size: 100%; }
  ul, ol { list-style: none; }
  a { color: inherit; text-decoration: none; }
  button { font: inherit; cursor: pointer; }
  input, select, textarea { font: inherit; }
}


/* ==========================================================
   LAYER: base
   Design tokens, typography, shared components.
   Everything here is available to both mobile and desktop.
   ========================================================== */

@layer base {

  /* ── Color Tokens ─────────────────────────────────────── */

  :root {
    /* Primitives — oklch(Lightness% Chroma Hue) */
    --bg:             light-dark(oklch(100% 0 0), oklch(7% .015 270));
    --surface:        light-dark(oklch(96% .005 270), oklch(12% .015 270));
    --surface-raised: light-dark(oklch(100% 0 0), oklch(14% .012 270));
    --text:           light-dark(oklch(8% 0 0), oklch(93% .005 270));
    --text-muted:     light-dark(oklch(30% .01 270), oklch(78% .01 270));
    --border:         light-dark(oklch(82% .005 270), oklch(25% .01 270));
    --border-strong:  light-dark(oklch(70% .01 270), oklch(45% .01 270));

    /* Semantic colors — each has a tinted surface via color-mix */
    --primary:        light-dark(oklch(35% .16 260), oklch(72% .12 250));
    --primary-surface:light-dark(
      color-mix(in oklch, oklch(35% .16 260) 8%, oklch(100% 0 0)),
      color-mix(in oklch, oklch(72% .12 250) 12%, oklch(7% .015 270))
    );

    --ok:             light-dark(oklch(32% .12 155), oklch(74% .17 155));
    --ok-surface:     light-dark(
      color-mix(in oklch, oklch(32% .12 155) 6%, white),
      color-mix(in oklch, oklch(74% .17 155) 12%, oklch(7% .015 270))
    );

    --warn:           light-dark(oklch(35% .12 75), oklch(84% .16 90));
    --warn-surface:   light-dark(
      color-mix(in oklch, oklch(35% .12 75) 8%, white),
      color-mix(in oklch, oklch(84% .16 90) 10%, oklch(7% .015 270))
    );

    --err:            light-dark(oklch(32% .16 25), oklch(78% .12 20));
    --err-surface:    light-dark(
      color-mix(in oklch, oklch(32% .16 25) 6%, white),
      color-mix(in oklch, oklch(78% .12 20) 10%, oklch(7% .015 270))
    );

    /* Layout */
    --radius:    .5rem;
    --nav-h:     3.5rem;
    --sidebar-w: 14rem;
    --header-h:  3.25rem;
    --speed:     150ms ease;

    /* Sidebar (dark bg, light text) */
    --sidebar-bg:   light-dark(oklch(14% .02 270), oklch(7% .015 270));
    --sidebar-text: light-dark(oklch(85% .005 270), oklch(72% .01 270));
  }

  /* ── Display P3 Wide-Gamut Override ───────────────────── */

  @supports (color: color(display-p3 0 0 0)) {
    :root {
      --primary: light-dark(color(display-p3 .08 .18 .58), color(display-p3 .42 .67 1));
      --ok:      light-dark(color(display-p3 .05 .30 .12), color(display-p3 .29 .87 .50));
      --warn:    light-dark(color(display-p3 .38 .22 .02), color(display-p3 .98 .80 .08));
      --err:     light-dark(color(display-p3 .42 .06 .06), color(display-p3 .99 .65 .65));
    }
  }

  /* ── Accessibility: High Contrast ─────────────────────── */

  @media (prefers-contrast: more) {
    :root {
      --bg: light-dark(#fff, #000);
      --surface: light-dark(#fff, #000);
      --surface-raised: light-dark(#fff, #000);
      --text: light-dark(#000, #fff);
      --text-muted: light-dark(oklch(8% 0 0), oklch(92% 0 0));
      --border: light-dark(#000, #fff);
    }
    input, select, textarea, button { border-width: 2px !important; }
  }

  /* ── Accessibility: Reduced Motion ────────────────────── */

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      transition-duration: .01ms !important;
      animation-duration:  .01ms !important;
    }
  }

  /* ── Typography ───────────────────────────────────────── */

  body {
    font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
    font-weight: 400;
    font-size-adjust: 0.5;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
  }

  h1 { font-size: 1.375rem; font-weight: 700; letter-spacing: -.01em; text-wrap: balance; }
  h2 { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
  h3 { font-size: .95rem; font-weight: 700; }
  p  { max-inline-size: 60ch; }
  small { font-size: .8rem; color: var(--text-muted); }
  strong { font-weight: 700; }

  /* SVG icon sizing — Lucide icons inside nav spans and buttons */
  span[aria-hidden] > svg { width: 1em; height: 1em; }
  button > svg { width: 1em; height: 1em; }

  :focus-visible {
    outline: 3px solid var(--primary); outline-offset: 4px;
    transition: outline-offset 150ms ease-out, outline-color 150ms ease-out;
  }
  :focus-visible:not(:active) { outline-offset: 2px; }
  a:hover { color: var(--primary); }

  /* ── Buttons ──────────────────────────────────────────── */
  /* Base: <button> or <a role="button">
     Variants via data-variant: primary | danger | ghost
     Sizes via data-size: lg                               */

  button, a[role="button"] {
    display: inline-flex; align-items: center; justify-content: center; gap: .25rem;
    border: 1.5px solid var(--border); background: var(--surface-raised);
    color: var(--text); padding: .5rem 1rem; border-radius: var(--radius);
    font-weight: 500; min-height: 2.5rem;
    transition: border-color var(--speed), background var(--speed), scale 80ms ease;
    touch-action: manipulation;

    &:hover { border-color: var(--border-strong); background: var(--surface); }
    &:active { scale: .97; }
  }

  [data-variant="primary"] {
    background: var(--primary) !important;
    color: light-dark(#fff, oklch(7% .015 270)) !important;
    border-color: transparent !important;
    font-weight: 600;

    &:hover { filter: brightness(1.1); }
    &:active { filter: brightness(1.25); }
  }

  [data-variant="danger"] {
    color: var(--err) !important; border-color: var(--err) !important; background: transparent !important;

    &:hover { background: var(--err-surface) !important; }
  }

  [data-variant="ghost"] {
    background: transparent !important; border-color: transparent !important;
    color: var(--text-muted) !important; padding: .5rem;
  }

  [data-size="lg"] {
    width: 100%; padding: .875rem; font-size: 1rem; font-weight: 700;
    min-height: 3rem; display: flex; justify-content: center; text-align: center;
  }

  a[data-variant], a[data-size] {
    display: inline-flex; align-items: center; justify-content: center;
    padding: .5rem 1rem; border-radius: var(--radius); min-height: 2.5rem; font-weight: 600;
  }

  /* ── Forms ────────────────────────────────────────────── */

  label { display: block; font-size: .875rem; font-weight: 600; margin-block-end: .25rem; }

  input:not([type="checkbox"]):not([type="radio"]),
  select, textarea {
    width: 100%; padding: .55rem .75rem;
    border: 1.5px solid var(--border); border-radius: var(--radius);
    background: var(--surface-raised); color: var(--text);
    transition: border-color var(--speed);

    &:focus { border-color: var(--primary); outline: 2px solid var(--primary); outline-offset: 2px; }
  }

  textarea { resize: vertical; min-block-size: 4.5rem; }
  fieldset { border: 1.5px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; }
  legend { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); padding: 0 .35rem; }

  /* ── Tables ───────────────────────────────────────────── */

  table { width: 100%; border-collapse: collapse; background: var(--surface-raised); }

  thead th {
    text-align: start; padding: .65rem 1rem; font-size: .75rem;
    text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-muted); background: var(--surface); border-block-end: 1.5px solid var(--border);
  }

  tbody {
    & tr {
      border-block-end: 1px solid var(--border);
      transition: background var(--speed);

      &:last-child { border-block-end: none; }
      &:hover { background: var(--surface); }
    }
    & td {
      padding: .65rem 1rem; font-size: .875rem;

      & strong { display: block; }
      & small { display: block; font-size: .75rem; color: var(--text-muted); margin-block-start: .1rem; }
    }
  }

  /* ── Definition Lists ─────────────────────────────────── */
  /* Used for key/value pairs in detail views.
     Rows reveal progressively via @starting-style.       */

  dl {
    font-size: .9rem;

    & > div {
      display: flex; justify-content: space-between; align-items: baseline;
      padding: .45rem 0; border-block-end: 1px solid var(--border);
      transition: opacity 200ms ease-out, transform 200ms ease-out;

      &:last-child { border-block-end: none; }
    }
  }
  @starting-style {
    dl > div { opacity: 0; transform: translateY(6px); }
  }
  dt { color: var(--text-muted); }
  dd { font-weight: 600; text-align: end; }

  /* ── Status Badges ────────────────────────────────────── */
  /* Pill-shaped labels: <span data-status="ok">Text</span>
     Entry animation via @starting-style                   */

  [data-status] {
    display: inline-flex; align-items: center;
    font-size: .75rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .06em; padding: .2rem .55rem; border-radius: 999px;
    transition: opacity var(--speed), scale var(--speed);
  }
  [data-status="ok"]   { background: var(--ok-surface);      color: var(--ok); }
  [data-status="warn"] { background: var(--warn-surface);     color: var(--warn); }
  [data-status="err"]  { background: var(--err-surface);      color: var(--err); }
  [data-status="info"] { background: var(--primary-surface);  color: var(--primary); }

  @starting-style {
    [data-status] { opacity: 0; scale: .92; }
  }

  /* ── Border Accents ───────────────────────────────────── */
  /* Left-border color stripe: <div data-border="ok">      */

  [data-border="ok"]   { border-inline-start: 4px solid var(--ok); }
  [data-border="warn"] { border-inline-start: 4px solid var(--warn); }
  [data-border="err"]  { border-inline-start: 4px solid var(--err); }

  /* ── Skip Link (a11y) ─────────────────────────────────── */

  body > a:first-child[href="#main"] {
    position: absolute; inset-inline-start: -9999px; top: 1rem;
    background: var(--primary); color: #fff;
    padding: .5rem 1rem; border-radius: var(--radius); font-weight: 600; z-index: 9999;

    &:focus { inset-inline-start: 1rem; }
  }

  /* ── Avatar Circle ────────────────────────────────────── */
  /* <span data-initials>AB</span>
     Pop-in entry via @starting-style.                     */

  [data-initials] {
    width: 2.75rem; height: 2.75rem; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .875rem;
    background: var(--primary-surface); color: var(--primary); border: 1.5px solid var(--primary);
    transition: scale 200ms ease-out, opacity 200ms ease-out;
  }

  @starting-style {
    [data-initials] { scale: .85; opacity: 0; }
  }

  [hidden] { display: none !important; }
}


/* ==========================================================
   LAYER: app — Mobile Shell (Assistent & Klient)
   Root: <body data-app="mobile">
   Structure: header → main → nav (bottom tabs)
   Max width 430 px, centered.
   ========================================================== */

@layer app {

  [data-app="mobile"] {
    max-inline-size: 430px; margin-inline: auto; min-block-size: 100dvh; position: relative;

    /* ── Sticky Top Header ────────────────────────────────
       Contains optional back-link, app icon, page title.
       <header><img …><h1>Title</h1></header>              */
    & > header {
      position: sticky; top: 0; z-index: 100;
      background: oklch(from var(--bg) l c h / .8);
      backdrop-filter: saturate(180%) blur(12px);
      -webkit-backdrop-filter: saturate(180%) blur(12px);
      border-block-end: 1px solid var(--border);
      padding: .625rem 1rem;
      display: flex; align-items: center; justify-content: space-between;
      min-block-size: var(--header-h); gap: .5rem;
      view-transition-name: app-header;

      & img {
        inline-size: 1.25rem; block-size: 1.25rem; border-radius: .15rem; flex-shrink: 0;
      }

      & > a:first-child {
        color: var(--primary); font-weight: 600; padding: .35rem;
        min-inline-size: 2.75rem; min-block-size: 2.75rem;
        display: inline-flex; align-items: center; border-radius: var(--radius);
      }
    }

    /* ── Main Content Area ────────────────────────────────
       Bottom padding accounts for fixed nav height.       */
    & > main {
      padding: 1rem; padding-block-end: calc(var(--nav-h) + 1.5rem);

      & > h2 { margin: 1.25rem 0 .75rem; }
    }

    /* ── Bottom Tab Navigation ────────────────────────────
       Fixed bar with 2–4 icon+label links.
       Active tab: aria-current="page"                     */
    & > nav:last-child {
      position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
      width: 100%; max-inline-size: 430px; block-size: var(--nav-h);
      background: oklch(from var(--bg) l c h / .8);
      backdrop-filter: saturate(180%) blur(12px);
      -webkit-backdrop-filter: saturate(180%) blur(12px);
      border-block-start: 1px solid var(--border);
      display: flex; z-index: 200;
      view-transition-name: bottom-nav;

      & a {
        flex: 1; display: flex; flex-direction: column; align-items: center;
        justify-content: center; gap: .15rem; min-block-size: 3rem;
        color: var(--text-muted); font-size: .7rem; font-weight: 500;
        transition: color var(--speed), scale 100ms ease;
        touch-action: manipulation;

        & span[aria-hidden] { font-size: 1.25rem; line-height: 1; transition: scale 100ms ease; }
        &:active span[aria-hidden] { scale: .85; }
      }
      & a[aria-current="page"] {
        color: var(--primary);

        /* Active indicator pill above the icon             */
        & span[aria-hidden] {
          position: relative;

          &::before {
            content: ""; position: absolute; top: -.35rem; left: 50%;
            inline-size: 1.25rem; block-size: 3px; border-radius: 999px;
            background: var(--primary); transform: translateX(-50%);
            animation: fade-up 200ms ease-out both;
          }
        }
        /* Subtle lift on the active icon                   */
        & span[aria-hidden] { transform: translateY(-1px); }
      }
    }

    /* ── Sub-Tabs (Heute/Morgen/Woche toggle) ─────────────
       iOS-like segmented control with smooth transitions
       on background and color for all links.              */
    & nav[aria-label="Zeitraum"],
    & [role="tablist"] {
      display: flex; gap: .2rem; margin-block-end: 1.25rem;
      background: var(--surface); border-radius: var(--radius); padding: .2rem;

      & a {
        flex: 1; padding: .5rem; border-radius: calc(var(--radius) - 2px);
        font-size: .875rem; font-weight: 500; color: var(--text-muted);
        text-align: center; min-block-size: 2.5rem;
        display: flex; align-items: center; justify-content: center;
        transition: background 200ms ease, color 200ms ease, font-weight 200ms ease;
      }
      & a[aria-current="page"] {
        background: var(--surface-raised); color: var(--primary); font-weight: 700;
        box-shadow: 0 1px 3px oklch(0% 0 0 / .06);
      }
    }

    /* ── Card Items ────────────────────────────────────────
       Linked cards: <article><a href><div><strong>…<small>…
       </div><span data-status>…</span></a></article>
       Staggered fade-up entry via nth-child delays.       */
    & main article {
      container-type: inline-size;
      background: var(--surface-raised); border: 1px solid var(--border);
      border-radius: var(--radius); margin-block-end: .625rem;
      transition: border-color var(--speed), scale 80ms ease;
      animation: fade-up 300ms ease-out both;

      &:nth-child(1)  { animation-delay: 0ms; }
      &:nth-child(2)  { animation-delay: 50ms; }
      &:nth-child(3)  { animation-delay: 100ms; }
      &:nth-child(4)  { animation-delay: 150ms; }
      &:nth-child(5)  { animation-delay: 200ms; }
      &:nth-child(n+6){ animation-delay: 250ms; }

      & > a {
        display: flex; align-items: center; gap: .75rem; padding: .875rem;
        min-block-size: 4rem; color: inherit;
        touch-action: manipulation;

        & > div { flex: 1; min-inline-size: 0; }
        & > div > strong { display: block; }
        & > div > small { display: block; margin-block-start: .15rem; }
      }
      &:hover { border-color: var(--primary); }
      &:active { scale: .98; }
    }

    /* ── Detail Sections ──────────────────────────────────
       Bordered card with heading: <section><h2>…<dl>…
       Entry animation via @starting-style (fade-up).      */
    & main > section {
      background: var(--surface-raised); border: 1px solid var(--border);
      border-radius: var(--radius); padding: 1rem; margin-block-end: .75rem;
      transition: opacity 250ms ease-out, transform 250ms ease-out;

      & > h2 { margin-block-end: .65rem; }
    }
    @starting-style {
      & main > section { opacity: 0; transform: translateY(8px); }
    }

    /* ── Status Screens (Success/Error/Pending) ─────────
       Spring-like pop-in on the large icon circle.        */
    & [role="status"] {
      display: flex; flex-direction: column; align-items: center; text-align: center;
      padding: 2.5rem 1.5rem 1rem;

      & > span:first-child {
        width: 4.5rem; height: 4.5rem; border-radius: 50%;
        display: flex; align-items: center; justify-content: center;
        font-size: 2rem; margin-block-end: 1.25rem;
        animation: pop-in 400ms cubic-bezier(.175, .885, .32, 1.275) both;
      }

      &[data-border="ok"] > span:first-child   { background: var(--ok-surface);   color: var(--ok); }
      &[data-border="warn"] > span:first-child  { background: var(--warn-surface); color: var(--warn); }
      &[data-border="err"] > span:first-child   { background: var(--err-surface);  color: var(--err); }

      & h2 {
        font-size: 1.125rem; text-transform: none; letter-spacing: normal;
        color: var(--text); margin-block-end: .5rem;
      }
      & p { color: var(--text-muted); margin-block-end: 2rem; }
    }

    /* ── Time List (Alle Zeiten) ──────────────────────────
       <ul role="list"><li><div><strong>…<small>…</div>
       <span data-status>…</span></li>
       Staggered fade-up entry on list items.              */
    & ul[role="list"] > li {
      display: flex; align-items: center; gap: .75rem;
      padding: .75rem; background: var(--surface-raised);
      border: 1px solid var(--border); border-radius: var(--radius);
      margin-block-end: .5rem; font-size: .9rem;
      animation: fade-up 300ms ease-out both;

      &:nth-child(1)  { animation-delay: 0ms; }
      &:nth-child(2)  { animation-delay: 50ms; }
      &:nth-child(3)  { animation-delay: 100ms; }
      &:nth-child(4)  { animation-delay: 150ms; }
      &:nth-child(5)  { animation-delay: 200ms; }
      &:nth-child(6)  { animation-delay: 250ms; }
      &:nth-child(7)  { animation-delay: 300ms; }
      &:nth-child(n+8){ animation-delay: 350ms; }

      & > div { flex: 1; }
      & small { display: block; font-size: .8rem; color: var(--text-muted); }
    }

    /* ── Profile Header ───────────────────────────────────
       Centered avatar + name: <header><span data-initials> */
    & main > header:first-child {
      display: flex; flex-direction: column; align-items: center;
      padding: 1.5rem 1rem; text-align: center; gap: .25rem;

      & [data-initials] {
        width: 4.5rem; height: 4.5rem; font-size: 1.5rem; margin-block-end: .5rem; border-width: 2.5px;
      }
    }

    /* ── Action Button Pairs (Bestätigen/Ablehnen) ─────── */
    & [role="group"][aria-label] {
      display: flex; gap: .75rem; margin-block-start: 1rem;

      & > * { flex: 1; }
      & > a {
        padding: .875rem; font-weight: 700; min-block-size: 3rem;
        border-radius: var(--radius); text-align: center;
        display: flex; align-items: center; justify-content: center; border: 1.5px solid transparent;
      }
      & > a[data-variant="ok"] {
        background: var(--ok); color: light-dark(#fff, oklch(7% .015 270));
      }
      & > a[data-variant="err"] {
        background: transparent; border-color: var(--err); color: var(--err);
      }
    }

    /* ── Compare Grid (Geplant vs. Erfasst) ───────────── */
    & [role="table"] {
      display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-block-end: .75rem;

      & > div {
        border-radius: var(--radius); padding: .65rem; text-align: center;

        & h3 { font-size: .6rem; margin-block-end: .2rem; }
        & strong { font-size: 1rem; display: block; }
      }
      & > div:first-child { background: var(--surface); }
      & > div:last-child  { background: var(--warn-surface); border: 1.5px solid var(--warn); }

      &[data-match] > div:last-child { background: var(--ok-surface); border-color: var(--ok); }
    }

    /* ── History Items (Klient Historie) ──────────────────
       <a role="listitem"><time><strong>DD</strong>Mon
       </time><div><strong>Name</strong><small>…</small>
       </div><span data-status>…</span></a>
       Staggered fade-up entry on history cards.           */
    & a[role="listitem"] {
      display: flex; align-items: center; gap: .75rem; padding: .875rem;
      background: var(--surface-raised); border: 1px solid var(--border);
      border-radius: var(--radius); margin-block-end: .5rem;
      transition: border-color var(--speed), scale 80ms ease;
      touch-action: manipulation;
      animation: fade-up 300ms ease-out both;

      &:nth-child(1)  { animation-delay: 0ms; }
      &:nth-child(2)  { animation-delay: 50ms; }
      &:nth-child(3)  { animation-delay: 100ms; }
      &:nth-child(4)  { animation-delay: 150ms; }
      &:nth-child(5)  { animation-delay: 200ms; }
      &:nth-child(n+6){ animation-delay: 250ms; }

      &:hover { border-color: var(--primary); }
      &:active { scale: .98; }

      & > div { flex: 1; min-inline-size: 0; }
      & > div > strong { display: block; }
      & > div > small { display: block; margin-block-start: .15rem; }

      & > time {
        width: 2.75rem; height: 3rem;
        background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
        display: flex; flex-direction: column; align-items: center; justify-content: center;
        flex-shrink: 0; font-size: .55rem; text-transform: uppercase; color: var(--text-muted);

        & strong { font-size: 1rem; color: var(--text); line-height: 1; }
      }
    }

    /* ── Spacing between consecutive action links ─────── */
    & main > section + button,
    & main > section + a[role="button"] { margin-block-start: 1.25rem; }
    & main > a + a,
    & main > button + a,
    & main > button + button { margin-block-start: .625rem; }
  }
}


/* ==========================================================
   LAYER: desktop — Planer Desktop Shell
   Root: <body data-app="desktop">
   Structure: aside (sidebar) + div > header + main
   Full viewport height, sidebar collapses ≤ 1024 px.
   ========================================================== */

@layer desktop {

  [data-app="desktop"] {
    display: flex; block-size: 100dvh; overflow: hidden;

    /* ── Sidebar ──────────────────────────────────────────
       Dark bg, logo header, nav groups (h2 + links),
       user footer. Collapses to off-canvas ≤ 1024 px.    */
    & > aside {
      inline-size: var(--sidebar-w); background: var(--sidebar-bg); color: var(--sidebar-text);
      display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto;
      scrollbar-width: thin; scrollbar-color: oklch(50% 0 0 / .3) transparent;

      & > header {
        padding: 1rem; border-block-end: 1px solid oklch(100% 0 0 / .06);
        display: flex; align-items: center; gap: .625rem;

        & img { width: 1.75rem; height: 1.75rem; border-radius: .25rem; }
        & div strong { display: block; color: #fff; font-size: .85rem; }
        & div small { color: var(--sidebar-text); }
      }

      & nav {
        padding: .5rem; flex: 1;

        & h2 { font-size: .65rem; color: oklch(70% .01 270); padding: .5rem .75rem .2rem; margin-block-start: .5rem; }
        & a {
          display: flex; align-items: center; gap: .65rem;
          padding: .55rem .75rem; border-radius: var(--radius);
          font-size: .85rem; color: var(--sidebar-text); min-block-size: 2.5rem;
          transition: background var(--speed), color var(--speed);

          & span { font-size: 1rem; inline-size: 1.25rem; text-align: center; flex-shrink: 0; }

          &:hover { background: oklch(100% 0 0 / .08); color: #fff; }
          &[aria-current="page"] {
            background: color-mix(in oklch, var(--primary) 20%, oklch(14% .02 270));
            color: oklch(78% .12 250); font-weight: 600;
          }
        }
      }

      & > footer {
        padding: .625rem .5rem; border-block-start: 1px solid oklch(100% 0 0 / .06);

        & > div {
          display: flex; align-items: center; gap: .625rem; padding: .5rem .75rem;
        }
        & [data-initials] {
          width: 2rem; height: 2rem; border-radius: 50%; border: none;
          background: var(--primary); color: #fff; font-size: .7rem; font-weight: 700;
        }
        & strong { font-size: .8rem; color: #fff; }
        & small { display: block; font-size: .75rem; color: var(--sidebar-text); }
      }
    }

    /* ── Main Area (right of sidebar) ─────────────────────
       Top bar (h1 + actions) → scrollable main content.  */
    & > div {
      flex: 1; display: flex; flex-direction: column; overflow: hidden;

      & > header {
        block-size: var(--header-h); background: var(--surface-raised);
        border-block-end: 1px solid var(--border);
        display: flex; align-items: center; justify-content: space-between;
        padding-inline: 1.5rem; flex-shrink: 0;

        & > nav { display: flex; align-items: center; gap: .5rem; }
      }

      & > main { flex: 1; overflow-y: auto; padding: 1.25rem 1.5rem; }
    }

    /* ── Horizontal Tabs ──────────────────────────────────
       <nav aria-label="Tabs"><a>…</a></nav>
       Used on pages with sub-views (Abrechnung, etc.)     */
    & nav[aria-label="Tabs"] {
      display: flex; border-block-end: 1px solid var(--border); margin-block-end: 1.25rem;

      & a {
        padding: .65rem 1.25rem; font-size: .85rem; font-weight: 500;
        color: var(--text-muted); border-block-end: 2px solid transparent;
        min-block-size: 2.5rem; display: flex; align-items: center;
        transition: color var(--speed);

        &[aria-current="page"] {
          color: var(--primary); border-block-end-color: var(--primary); font-weight: 700;
        }
      }
    }

    /* ── Master-Detail Layout ─────────────────────────────
       <div data-layout="master-detail">
         <nav> (left list with search) </nav>
         <section> (right detail panel) </section>
       </div>
       Used: Klientenliste, Klient-Stammdaten, etc.        */
    & [data-layout="master-detail"] {
      display: flex; gap: 1rem; block-size: calc(100dvh - var(--header-h) - 2.5rem);

      & > nav {
        inline-size: 16rem; flex-shrink: 0; background: var(--surface-raised);
        border: 1px solid var(--border); border-radius: var(--radius);
        display: flex; flex-direction: column; overflow: hidden;

        & > div:first-child { padding: .75rem; border-block-end: 1px solid var(--border); }
        & input[type="search"] { font-size: .85rem; }
        & ul { overflow-y: auto; flex: 1; }
        & li a {
          display: flex; justify-content: space-between; align-items: center;
          padding: .75rem 1rem; border-block-end: 1px solid var(--border);
          min-block-size: 3.5rem; transition: background var(--speed);

          &:hover { background: var(--surface); }
          &[aria-current="page"] {
            background: var(--primary-surface); border-inline-start: 3px solid var(--primary);
          }

          & > div { flex: 1; min-inline-size: 0; }
          & > div > strong { font-size: .875rem; display: block; }
          & > div > small { font-size: .75rem; display: block; color: var(--text-muted); margin-block-start: .1rem; }
          & strong { font-size: .875rem; display: block; }
          & small { font-size: .75rem; color: var(--text-muted); }
        }
      }

      & > section {
        flex: 1; background: var(--surface-raised); border: 1px solid var(--border);
        border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column;
        transition: opacity 250ms ease-out, transform 250ms ease-out;

        & > header {
          padding: .875rem 1.25rem; border-block-end: 1px solid var(--border);
          display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;
          block-size: auto; background: transparent;
        }
        & > div { padding: 1.25rem; overflow-y: auto; flex: 1; }
      }
    }
    @starting-style {
      [data-layout="master-detail"] > section { opacity: 0; transform: translateY(6px); }
    }

    /* ── Info Table (detail view key-value) ────────────── */
    & table.info {
      background: transparent;

      & th {
        text-align: start; padding: .4rem 1rem .4rem 0; color: var(--text-muted);
        font-weight: 400; inline-size: 40%; font-size: .875rem; border-block-end: 1px solid var(--border);
        background: transparent; text-transform: none; letter-spacing: normal;
      }
      & td {
        padding: .4rem 0; font-weight: 600; font-size: .875rem; border-block-end: 1px solid var(--border);
      }
      & tr:last-child th,
      & tr:last-child td { border-block-end: none; }
    }

    /* ── Calendar Grid ────────────────────────────────────
       <div role="grid"> with 7-column day cells.
       Each day: <a><strong>DD</strong><span data-status>
       <small>Backup: XX</small></a>
       Empty cells: <span data-other></span>
       Day cells fade+scale in via @starting-style.        */
    & [role="grid"] {
      display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px;

      & > small {
        text-align: center; font-size: .65rem; text-transform: uppercase;
        letter-spacing: .05em; padding: .35rem 0; font-weight: 700;
      }

      & > a {
        background: var(--surface-raised); border: 1px solid var(--border);
        border-radius: var(--radius); padding: .35rem; min-block-size: 4.5rem;
        display: flex; flex-direction: column;
        transition: border-color var(--speed), opacity 200ms ease-out, scale 200ms ease-out;
        font-size: .75rem;

        &:hover { border-color: var(--primary); }
        &[aria-current="date"] { border-color: var(--primary); background: var(--primary-surface); }

        & > strong { font-size: .75rem; margin-block-end: .2rem; }
        & > span {
          border-radius: 3px; padding: .1rem .25rem; font-size: .65rem; font-weight: 600;
        }
        & > small { font-size: .65rem; color: var(--text-muted); margin-block-start: auto; }
        & > [data-status="ok"]   { background: var(--ok-surface); color: var(--ok); }
        & > [data-status="warn"] { background: var(--warn-surface); color: var(--warn); }
        & > [data-status="info"] { background: var(--surface); color: var(--text-muted); border: 1px dashed var(--border); }
      }

      & > [data-other] {
        min-block-size: 4.5rem; border-radius: var(--radius);
        background: var(--surface); opacity: .15;
      }
    }
    @starting-style {
      [data-app="desktop"] [role="grid"] > a { opacity: 0; scale: .97; }
    }

    & [aria-label="Monatsnavigation"] {
      display: flex; align-items: center; justify-content: space-between; margin-block-end: 1rem;
    }

    /* ── Calendar + Side Panel ────────────────────────────
       <div data-layout="calendar-panel">
         <div> (calendar grid) </div>
         <aside> (shift detail panel) </aside>
       </div>                                              */
    & [data-layout="calendar-panel"] {
      display: flex; gap: 1rem;

      & > div:first-child { flex: 1; min-inline-size: 0; }

      & > aside {
        inline-size: 18rem; flex-shrink: 0; background: var(--surface-raised);
        border: 1px solid var(--border); border-radius: var(--radius);
        display: flex; flex-direction: column;
        color: var(--text); position: static; block-size: auto; transform: none; overflow: visible;

        & > header {
          padding: .875rem 1rem; border-block-end: 1px solid var(--border);
          display: flex; justify-content: space-between; align-items: center;
          block-size: auto; background: transparent;
        }
        & > div { padding: 1rem; flex: 1; }
      }
    }

    /* ── Helper Chips (Schicht-Panel) ─────────────────── */
    & [role="group"][aria-label*="Helfer"] {
      display: flex; flex-wrap: wrap; gap: .35rem; margin-block-start: .5rem;

      & button {
        padding: .35rem .75rem; border-radius: 999px; font-size: .8rem; font-weight: 600; min-block-size: 2.25rem;

        &[aria-pressed="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }
        &[data-backup] { background: var(--surface); border-color: var(--border-strong); color: var(--text-muted); }
      }
    }

    /* ── KPI Cards ────────────────────────────────────────
       <div data-layout="kpi"> with 4 metric cards.
       Collapses to 2-col via @container at 600 px.
       Metric numbers slide up into place on load.         */
    & [data-layout="kpi"] {
      container-type: inline-size;
      display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-block-end: 1.5rem;

      & > article {
        background: var(--surface-raised); border: 1px solid var(--border);
        border-radius: var(--radius); padding: 1rem;

        & > h2 { margin-block-end: .15rem; }
        & > strong {
          font-size: 1.5rem; display: block; margin: .15rem 0;
          animation: slide-up-number 350ms ease-out both;
        }
        & > small { display: block; }
      }
    }
    @container (max-width: 600px) {
      [data-layout="kpi"] { grid-template-columns: 1fr 1fr; }
    }

    /* ── Chart Cards ──────────────────────────────────────
       <div data-layout="charts"> with bar chart articles.
       Collapses to 1-col via @container at 600 px.       */
    & [data-layout="charts"] {
      container-type: inline-size;
      display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;

      & > article {
        background: var(--surface-raised); border: 1px solid var(--border);
        border-radius: var(--radius); padding: 1.25rem;

        & > h2 { margin-block-end: 1rem; }
      }
    }
    @container (max-width: 600px) {
      [data-layout="charts"] { grid-template-columns: 1fr; }
    }

    /* ── Bar Charts ───────────────────────────────────────
       <div role="img" aria-label="…">
         <div>
           <span>VALUE</span>                   (top label)
           <span style="block-size:60%;         (the bar)
                  background:var(--primary)">
           </span>
           <span>LABEL</span>                   (bottom label)
         </div> …
       </div>
       Bars grow upward on load via the registered
       --bar-h @property (animatable length-percentage).   */
    & [role="img"][aria-label] {
      display: flex; align-items: flex-end; gap: .75rem; block-size: 9rem;
      padding-block-end: .25rem; border-block-end: 1.5px solid var(--border);

      & > div {
        display: flex; flex-direction: column; align-items: center; flex: 1;
        block-size: 100%; justify-content: flex-end; gap: .15rem;

        & > span:first-child { font-size: .65rem; font-weight: 700; flex-shrink: 0; animation: fade-in 400ms ease-out both; }
        & > span:nth-child(2) {
          display: block;
          inline-size: 100%; border-radius: 3px 3px 0 0;
          transform-origin: bottom;
          animation: bar-grow 500ms ease-out both;
        }
        & > span:last-child { font-size: .65rem; color: var(--text-muted); flex-shrink: 0; }

        /* Stagger bars left-to-right                      */
        &:nth-child(1) > span:nth-child(2) { animation-delay: 0ms; }
        &:nth-child(2) > span:nth-child(2) { animation-delay: 60ms; }
        &:nth-child(3) > span:nth-child(2) { animation-delay: 120ms; }
        &:nth-child(4) > span:nth-child(2) { animation-delay: 180ms; }
        &:nth-child(5) > span:nth-child(2) { animation-delay: 240ms; }
        &:nth-child(6) > span:nth-child(2) { animation-delay: 300ms; }
        &:nth-child(n+7) > span:nth-child(2) { animation-delay: 360ms; }
      }
    }

    /* ── 2-Column Form Layout ─────────────────────────────
       <div data-layout="2col"><section>…</section> ×2
       Collapses to 1-col via @container at 500 px.       */
    & [data-layout="2col"] {
      container-type: inline-size;
      display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;

      & > section {
        background: var(--surface-raised); border: 1px solid var(--border);
        border-radius: var(--radius); padding: 1.25rem;

        & > h3 { margin-block-end: 1rem; }
        & > div + div { margin-block-start: .875rem; }
      }
    }
    @container (max-width: 500px) {
      [data-layout="2col"] { grid-template-columns: 1fr; }
    }

    /* ── Spacing: action buttons after layout blocks ───── */
    & > div > main > [data-layout] + button,
    & > div > main > [data-layout] + a[role="button"],
    & > div > main > table + button,
    & > div > main > table + a[role="button"],
    & > div > main > [data-overflow] + button,
    & > div > main > [data-overflow] + a[role="button"] { margin-block-start: 1.5rem; }
    & > div > main > button + button,
    & > div > main > button + a[role="button"],
    & > div > main > a[role="button"] + button,
    & > div > main > a[role="button"] + a[role="button"] { margin-inline-start: .5rem; }

    /* ── Filter Toolbar ───────────────────────────────────
       Inline row of label+input/select pairs + button.   */
    & [role="search"],
    & [aria-label="Filter"] {
      display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-block-end: 1rem;

      & label { font-size: .8rem; margin-block-end: 0; }
      & input, & select { width: auto; min-inline-size: 10rem; font-size: .85rem; }
    }

    /* ── Desktop List Items ───────────────────────────────
       <ul role="list"><li><div><strong>…<small>…</div>
       <div>actions</div></li>
       Used: Abrechnung Kostenträger list, etc.            */
    & [role="list"] > li {
      background: var(--surface-raised); border: 1px solid var(--border);
      border-radius: var(--radius); padding: .875rem 1.25rem;
      margin-block-end: .625rem; display: flex; justify-content: space-between;
      align-items: center; gap: .5rem;

      & > div:first-child { flex: 1; min-inline-size: 0; }
      & > div:first-child > strong { display: block; }
      & > div:first-child > small { display: block; margin-block-start: .15rem; }
      & > div:last-child { display: flex; align-items: center; gap: .5rem; }
    }

    /* ── Table Overflow Wrapper ────────────────────────── */
    & [data-overflow] {
      overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius);
    }

    /* ── Table + Side Panel Layout ────────────────────────
       <div data-layout="table-panel">
         <div> (table) </div>
         <aside> (row detail panel) </aside>
       </div>
       Used: Zeiten-Korrektur, etc.                        */
    & [data-layout="table-panel"] {
      display: flex; gap: 1.25rem; align-items: flex-start;

      & > div:first-child { flex: 1; min-inline-size: 0; }

      & > aside {
        inline-size: 22rem; flex-shrink: 0; background: var(--surface-raised);
        border: 1px solid var(--border); border-radius: var(--radius);
        display: flex; flex-direction: column;
        color: var(--text); position: static; block-size: auto; transform: none; overflow: visible;

        & > header {
          padding: .875rem 1rem; border-block-end: 1px solid var(--border);
          display: flex; justify-content: space-between; align-items: center;
          block-size: auto; background: transparent;
        }
        & > div {
          padding: 1rem; flex: 1; display: flex; flex-direction: column; gap: .75rem;
        }
        & > footer {
          padding: .875rem 1rem; border-block-start: 1px solid var(--border); display: flex; gap: .5rem;
        }
      }
    }

    /* ── Selected Table Row ────────────────────────────── */
    & tbody tr[aria-selected="true"] {
      border-inline-start: 3px solid var(--primary); background: var(--primary-surface);
    }

    /* ── Summary Footer Bar ───────────────────────────── */
    & [role="contentinfo"] {
      margin-block-start: 1.25rem; padding: .875rem 1.25rem;
      background: var(--surface); border: 1px solid var(--border);
      border-radius: var(--radius); font-weight: 600;
    }

    /* ── Card Grid (Assistenten-Liste) ────────────────────
       <div data-layout="card-grid">
         <a><span data-initials>AB</span>
         <div><strong>Name</strong><small>…</small></div>
         <span data-status>…</span></a> …
       </div>                                              */
    & [data-layout="card-grid"] {
      display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: .75rem;

      & > a {
        display: flex; align-items: center; gap: .75rem; padding: .875rem 1rem;
        background: var(--surface-raised); border: 1px solid var(--border);
        border-radius: var(--radius); transition: border-color var(--speed), scale 80ms ease;
        animation: fade-up 300ms ease-out both;

        &:nth-child(1)  { animation-delay: 0ms; }
        &:nth-child(2)  { animation-delay: 50ms; }
        &:nth-child(3)  { animation-delay: 100ms; }
        &:nth-child(4)  { animation-delay: 150ms; }
        &:nth-child(5)  { animation-delay: 200ms; }
        &:nth-child(n+6){ animation-delay: 250ms; }

        &:hover { border-color: var(--primary); }
        &:active { scale: .98; }

        & > div { flex: 1; min-inline-size: 0; }
        & > div > strong { display: block; }
        & > div > small { display: block; margin-block-start: .15rem; }
      }

      & [data-initials] {
        width: 2.5rem; height: 2.5rem; border-radius: 50%; border: none;
        background: var(--primary); color: #fff; font-size: .8rem; font-weight: 700;
      }
    }

    /* ── Responsive Sidebar Collapse ──────────────────────
       ≤ 1024 px: sidebar becomes fixed off-canvas overlay.
       Toggled via data-open attribute + hamburger button.
       Scrim overlay fades in behind the drawer.           */
    @media (width <= 1024px) {
      & > aside {
        position: fixed; top: 0; left: 0; block-size: 100dvh;
        transform: translateX(-100%); z-index: 300;
        transition: transform 200ms ease-out;

        &[data-open] { transform: translateX(0); }

        /* Dark scrim backdrop behind the open sidebar     */
        &[data-open]::after {
          content: ""; position: fixed; inset: 0;
          background: oklch(0% 0 0 / .35);
          z-index: -1;
          animation: 200ms ease-out both fade-in;
        }
      }
      & > div > header { padding-inline-start: 3.5rem; }
    }

    & > div > header > button[aria-label="Navigation"] {
      display: none; position: fixed; top: .35rem; left: .35rem; z-index: 500;
      background: var(--sidebar-bg); color: #fff; border: none;
      inline-size: 2.5rem; block-size: 2.5rem; border-radius: var(--radius); font-size: 1.15rem;
    }

    @media (width <= 1024px) {
      & > div > header > button[aria-label="Navigation"] { display: flex; }
    }
  }
}
