/* ============================================================
   SOLARDESK MODERN LAYER (v1, 26.05.2026)
   Browser-natives 2026er Frontend-Vokabular:
   1. View Transitions API (Page-Morph)
   2. Scroll-Driven Animations (KPI, Card-Reveal)
   3. @property + color-mix() Foundation (Multi-Tenant)
   4. Density-Modi (Compact / Comfortable / Spacious)
   5. Skeleton-Loading mit Shimmer
   6. Popover-API Styling
   7. Toast-Undo Pattern
   ============================================================ */

/* ──────────────────────────────────────────────────────────
   1. @property: animierbare Custom-Properties
   Browser kann jetzt zwischen Hex-Werten und Hue smooth
   interpolieren, weil er den Typ kennt.
   ────────────────────────────────────────────────────────── */
@property --m-accent-hue {
  syntax: '<number>';
  inherits: true;
  initial-value: 125;
}
@property --m-accent-chroma {
  syntax: '<number>';
  inherits: true;
  initial-value: 0.19;
}
@property --m-glow-radius {
  syntax: '<length>';
  inherits: false;
  initial-value: 0px;
}
@property --m-card-tilt {
  syntax: '<angle>';
  inherits: false;
  initial-value: 0deg;
}

/* ──────────────────────────────────────────────────────────
   2. Multi-Tenant-Token-Foundation via color-mix()
   Ein Hex pro Tenant, der Rest wird abgeleitet.
   Default: Sonnenexpert Lime (var(--green,#6E8E22))
   ────────────────────────────────────────────────────────── */
:root {
  --m-brand: oklch(78% var(--m-accent-chroma) var(--m-accent-hue));
  --m-brand-soft:   color-mix(in oklch, var(--m-brand) 14%, transparent);
  --m-brand-border: color-mix(in oklch, var(--m-brand) 38%, transparent);
  --m-brand-glow:   color-mix(in oklch, var(--m-brand) 42%, transparent);
  --m-brand-hover:  color-mix(in oklch, var(--m-brand) 12%, white);
  --m-brand-active: color-mix(in oklch, var(--m-brand) 18%, black);
  --m-brand-text-on: oklch(15% 0.005 var(--m-accent-hue));

  /* Surface-Stufen aus einem Lightness-Anker abgeleitet */
  --m-surface-l: 22%;
  --m-surface-c: 0.015;
  --m-surface-h: 245;
  --m-surface-0: oklch(calc(var(--m-surface-l) - 5%) var(--m-surface-c) var(--m-surface-h));
  --m-surface-1: oklch(var(--m-surface-l) var(--m-surface-c) var(--m-surface-h));
  --m-surface-2: oklch(calc(var(--m-surface-l) + 5%) var(--m-surface-c) var(--m-surface-h));
  --m-surface-3: oklch(calc(var(--m-surface-l) + 10%) var(--m-surface-c) var(--m-surface-h));
}

/* ──────────────────────────────────────────────────────────
   3. View Transitions API
   Smooth Page-Wechsel ohne SPA. Aktiviert via meta-Tag in HTML.
   ────────────────────────────────────────────────────────── */
@view-transition {
  navigation: auto;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 280ms;
  animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
}

::view-transition-old(root) {
  animation-name: m-fade-out-up;
}
::view-transition-new(root) {
  animation-name: m-fade-in-down;
}

@keyframes m-fade-out-up {
  to { opacity: 0; transform: translateY(-8px); }
}
@keyframes m-fade-in-down {
  from { opacity: 0; transform: translateY(8px); }
}

/* Shared-Element-Transitionen: Topbar bleibt persistent */
body.premium-dark .topbar { view-transition-name: m-topbar; }
body.premium-dark .sidebar { view-transition-name: m-sidebar; }
body.premium-dark [data-view-transition="page"] { view-transition-name: m-page; }

/* W2 (11.06.2026): Sidebar + Topbar bleiben beim Seitenwechsel STATISCH
   (kein Crossfade-Flackern). Konsolidiert aus view-transitions.css,
   die seither nur noch ein Stub ist: diese Datei ist die einzige
   Autorität für View-Transitions. */
::view-transition-old(m-topbar),
::view-transition-new(m-topbar),
::view-transition-old(m-sidebar),
::view-transition-new(m-sidebar) {
  animation: none;
  mix-blend-mode: normal;
}

::view-transition-old(m-topbar),
::view-transition-new(m-topbar),
::view-transition-old(m-sidebar),
::view-transition-new(m-sidebar) {
  animation-duration: 0ms;
}

/* ──────────────────────────────────────────────────────────
   4. Scroll-Driven Animations
   KPI-Cards faden + slidefen bei Viewport-Eintritt.
   Pures CSS, kein IntersectionObserver mehr.
   ────────────────────────────────────────────────────────── */
@supports (animation-timeline: view()) {
  body.premium-dark .widget,
  body.premium-dark .kpi-card,
  body.premium-dark .tracker-card,
  body.premium-dark .pj-card,
  body.premium-dark .kanban-card,
  body.premium-dark [data-reveal] {
    animation: m-reveal both;
    animation-timeline: view();
    animation-range: entry 0% entry 60%;
  }

  @keyframes m-reveal {
    from {
      opacity: 0;
      transform: translateY(14px) scale(0.985);
      filter: blur(2px);
    }
    to {
      opacity: 1;
      transform: translateY(0) scale(1);
      filter: blur(0);
    }
  }

  /* Counter-Cards bekommen einen Scale-Glow beim Scroll-Through */
  body.premium-dark [data-counter-card] {
    animation: m-counter-glow both;
    animation-timeline: view();
    animation-range: entry 20% cover 40%;
  }
  @keyframes m-counter-glow {
    from { --m-glow-radius: 0px; }
    to { --m-glow-radius: 24px; }
  }
}

/* ──────────────────────────────────────────────────────────
   5. Density-Modi (User-Preference)
   Toggle via Class auf <html>: density-compact, density-comfortable, density-spacious
   Default: comfortable
   ────────────────────────────────────────────────────────── */
:root {
  --m-density: 1;
  --m-density-pad: calc(1rem * var(--m-density));
  --m-density-gap: calc(0.75rem * var(--m-density));
  --m-density-radius: calc(12px * var(--m-density));
  --m-density-font: calc(1rem * var(--m-density));
}
html.density-compact    { --m-density: 0.82; }
html.density-comfortable { --m-density: 1; }
html.density-spacious   { --m-density: 1.18; }

body.premium-dark .widget,
body.premium-dark .kpi-card,
body.premium-dark .tracker-card,
body.premium-dark .pj-card {
  padding: var(--m-density-pad);
  gap: var(--m-density-gap);
  border-radius: var(--m-density-radius);
}

/* ──────────────────────────────────────────────────────────
   6. Skeleton-Loading mit Shimmer
   ────────────────────────────────────────────────────────── */
.m-skeleton {
  position: relative;
  overflow: hidden;
  background: linear-gradient(
    100deg,
    var(--m-surface-1) 30%,
    var(--m-surface-2) 50%,
    var(--m-surface-1) 70%
  );
  background-size: 200% 100%;
  animation: m-skeleton-shimmer 1.4s ease-in-out infinite;
  border-radius: 8px;
  color: transparent;
  user-select: none;
}
.m-skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    color-mix(in oklch, var(--m-brand) 8%, transparent) 50%,
    transparent 100%
  );
  animation: m-skeleton-sweep 2.4s ease-in-out infinite;
}
@keyframes m-skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: -100% 50%; }
}
@keyframes m-skeleton-sweep {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ──────────────────────────────────────────────────────────
   7. Popover-API Styling
   Native HTML <div popover> bekommt unsere Glass-DNA
   ────────────────────────────────────────────────────────── */
[popover] {
  background: var(--m-surface-1);
  border: 1px solid var(--m-brand-border);
  border-radius: 14px;
  padding: 12px;
  color: oklch(96% .005 245);
  box-shadow:
    0 1px 0 rgba(255,255,255,.04) inset,
    0 16px 40px -16px rgba(0,0,0,.6),
    0 0 0 1px var(--m-brand-soft);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  animation: m-popover-in 200ms cubic-bezier(.2,.8,.2,1);
}
[popover]::backdrop {
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: m-backdrop-in 200ms ease;
}
@keyframes m-popover-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes m-backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ──────────────────────────────────────────────────────────
   8. Toast-Undo Pattern
   ────────────────────────────────────────────────────────── */
.m-toast-stack {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.m-toast {
  pointer-events: auto;
  min-width: 280px;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--m-surface-2);
  border: 1px solid var(--m-brand-border);
  color: oklch(96% .005 245);
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow:
    0 10px 30px -8px rgba(0,0,0,.55),
    0 0 0 1px var(--m-brand-soft);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  animation: m-toast-in 240ms cubic-bezier(.2,.8,.2,1);
  position: relative;
  overflow: hidden;
}
.m-toast.leaving {
  animation: m-toast-out 200ms cubic-bezier(.4,0,1,1) both;
}
.m-toast-icon {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--m-brand-soft);
  color: var(--m-brand);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.m-toast-msg { flex: 1; font-size: 0.86rem; line-height: 1.35; }
.m-toast-undo {
  background: var(--m-brand-soft);
  color: var(--m-brand);
  border: 1px solid var(--m-brand-border);
  padding: 5px 11px;
  border-radius: 8px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 180ms;
}
.m-toast-undo:hover {
  background: color-mix(in oklch, var(--m-brand) 22%, transparent);
}
.m-toast-progress {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background: var(--m-brand);
  transform-origin: left;
  animation: m-toast-progress 5s linear forwards;
}
@keyframes m-toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes m-toast-out {
  to { opacity: 0; transform: translateX(40px); }
}
@keyframes m-toast-progress {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

/* ──────────────────────────────────────────────────────────
   9. Density-Toggle UI
   ────────────────────────────────────────────────────────── */
.m-density-toggle {
  display: inline-flex;
  background: var(--m-surface-1);
  border: 1px solid color-mix(in oklch, var(--m-brand) 14%, transparent);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.m-density-toggle button {
  background: transparent;
  border: none;
  color: oklch(75% .015 245);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.74rem;
  cursor: pointer;
  transition:transform 180ms cubic-bezier(.2,.8,.2,1), opacity 180ms cubic-bezier(.2,.8,.2,1), background-color 180ms cubic-bezier(.2,.8,.2,1), border-color 180ms cubic-bezier(.2,.8,.2,1), color 180ms cubic-bezier(.2,.8,.2,1), box-shadow 180ms cubic-bezier(.2,.8,.2,1), filter 180ms cubic-bezier(.2,.8,.2,1);
}
.m-density-toggle button[aria-pressed="true"] {
  background: var(--m-brand-soft);
  color: var(--m-brand);
}
.m-density-toggle button:hover:not([aria-pressed="true"]) {
  background: rgba(255,255,255,.05);
  color: oklch(96% 0 0);
}

/* ──────────────────────────────────────────────────────────
   10. Keyboard-Hint-Overlay
   ────────────────────────────────────────────────────────── */
.m-kbd {
  display: inline-flex;
  align-items: center;
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.10);
  color: oklch(85% .005 245);
  min-width: 18px;
  justify-content: center;
  line-height: 1.2;
}

#m-shortcuts-overlay {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 24px;
  padding: 18px;
  min-width: 460px;
  max-width: 90vw;
  font-size: 0.86rem;
}
#m-shortcuts-overlay h3 {
  grid-column: 1 / -1;
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 500;
  font-size: 1.05rem;
  margin-bottom: 4px;
  color: var(--m-brand);
}
#m-shortcuts-overlay .m-shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  color: oklch(85% .005 245);
}
#m-shortcuts-overlay .m-shortcut-keys {
  display: inline-flex; gap: 4px;
}

/* ──────────────────────────────────────────────────────────
   11. Command Palette Upgrade
   ────────────────────────────────────────────────────────── */
.m-cmdk-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9500;
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
  opacity: 0; pointer-events: none;
  transition: opacity 180ms;
}
.m-cmdk-backdrop.open {
  opacity: 1; pointer-events: auto;
}
.m-cmdk-panel {
  width: 100%;
  max-width: 640px;
  background: var(--m-surface-1);
  border: 1px solid color-mix(in oklch, var(--m-brand) 18%, transparent);
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 1px 0 rgba(255,255,255,.05) inset,
    0 30px 80px -10px rgba(0,0,0,.65),
    0 0 0 1px var(--m-brand-soft);
  transform: translateY(-8px) scale(0.98);
  transition: transform 200ms cubic-bezier(.2,.8,.2,1);
}
.m-cmdk-backdrop.open .m-cmdk-panel {
  transform: translateY(0) scale(1);
}
.m-cmdk-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: oklch(98% 0 0);
  font-size: 1.02rem;
  padding: 16px 20px;
  border-bottom: 1px solid var(--m-brand-soft);
  font-family: var(--body); /* Marken-Token statt literaler Schriftfamilie */
}
.m-cmdk-input::placeholder {
  color: oklch(60% .015 245);
}
.m-cmdk-results {
  max-height: 60vh;
  overflow-y: auto;
  padding: 6px;
}
.m-cmdk-group {
  padding: 8px 12px 4px;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: oklch(58% .015 245);
}
.m-cmdk-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 9px;
  cursor: pointer;
  color: oklch(92% 0 0);
  font-size: 0.9rem;
  transition: background 120ms;
}
.m-cmdk-item:hover,
.m-cmdk-item.selected {
  background: var(--m-brand-soft);
  color: var(--m-brand);
}
.m-cmdk-item-icon {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: rgba(255,255,255,.05);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem;
  flex-shrink: 0;
}
.m-cmdk-item-label { flex: 1; }
.m-cmdk-item-shortcut {
  font-family: 'Geist Mono', monospace;
  font-size: 0.72rem;
  color: oklch(58% .015 245);
}
.m-cmdk-empty {
  padding: 30px 20px;
  text-align: center;
  color: oklch(58% .015 245);
  font-size: 0.86rem;
}

/* ──────────────────────────────────────────────────────────
   12. Anchor-Positioning Tooltips (Chrome 125+, Fallback ok)
   ────────────────────────────────────────────────────────── */
@supports (anchor-name: --x) {
  [data-tooltip] {
    anchor-name: var(--tooltip-anchor, --m-anchor);
    position: relative;
  }
  [data-tooltip]:hover::after,
  [data-tooltip]:focus-visible::after {
    content: attr(data-tooltip);
    position: fixed;
    position-anchor: var(--tooltip-anchor, --m-anchor);
    bottom: anchor(top);
    left: anchor(center);
    translate: -50% -8px;
    background: var(--m-surface-2);
    color: oklch(96% 0 0);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.74rem;
    white-space: nowrap;
    border: 1px solid var(--m-brand-soft);
    box-shadow: 0 8px 18px -8px rgba(0,0,0,.65);
    pointer-events: none;
    z-index: 100;
    animation: m-popover-in 160ms;
  }
}

/* ──────────────────────────────────────────────────────────
   13. text-wrap Balance + Pretty für Headlines/Body
   ────────────────────────────────────────────────────────── */
body.premium-dark h1,
body.premium-dark h2,
body.premium-dark .topbar-title,
body.premium-dark .section-title,
body.premium-dark .widget-title,
body.premium-dark .card-title { text-wrap: balance; }

body.premium-dark p,
body.premium-dark .card-meta,
body.premium-dark .tracker-card-path { text-wrap: pretty; }

/* ──────────────────────────────────────────────────────────
   14. Right-Click Context-Menu
   ────────────────────────────────────────────────────────── */
.m-ctx-menu {
  position: fixed;
  min-width: 200px;
  background: var(--m-surface-2);
  border: 1px solid var(--m-brand-border);
  border-radius: 10px;
  padding: 5px;
  z-index: 9200;
  box-shadow:
    0 1px 0 rgba(255,255,255,.05) inset,
    0 20px 50px -10px rgba(0,0,0,.6);
  animation: m-popover-in 160ms;
}
.m-ctx-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 11px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.85rem;
  color: oklch(92% 0 0);
  transition: background 120ms;
}
.m-ctx-item:hover {
  background: var(--m-brand-soft);
  color: var(--m-brand);
}
.m-ctx-separator {
  height: 1px;
  background: var(--m-brand-soft);
  margin: 4px 0;
}

/* ──────────────────────────────────────────────────────────
   15. Reduced-Motion Fallback
   ────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) { animation-duration: 0ms; }
  .m-toast, .m-cmdk-panel, [popover], .m-ctx-menu {
    animation: none;
  }
  body.premium-dark .widget,
  body.premium-dark .kpi-card,
  body.premium-dark .tracker-card {
    animation: none;
  }
}

/* ============================================================
   W1-05: Focus-Visible Glow-Ring im CI-Grün (systemweit)
   Ersetzt den blauen Chrome-Default-Fokusring durch einen
   markenkonformen Ring. Nur bei Tastatur-Fokus (:focus-visible),
   nicht bei Maus-Klick.
   ============================================================ */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent, var(--green,#6E8E22));
  outline-offset: 2px;
  border-radius: 6px;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent, var(--green,#6E8E22)) 22%, transparent);
}
/* Maus-Klicks zeigen keinen Ring (Standardverhalten erhalten) */
:where(a, button, input, select, textarea, summary, [tabindex]):focus:not(:focus-visible) {
  outline: none;
}

/* ============================================================
   W1-03: Gestaffelter Listeneintritt (.stagger-list/.stagger-item)
   Container bekommt .stagger-list, jedes Kind .stagger-item mit
   CSS-Variable --stagger-i (Index, per JS gesetzt). Maximal 20
   gestaffelte Items, danach ohne Verzögerung (Cap gegen lange
   Gesamtdauer auf grossen Listen).
   ============================================================ */
.stagger-list { --stagger-base: 40ms; }
.stagger-item {
  opacity: 0;
  transform: translateY(8px);
  animation: stagger-in 240ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: calc(min(var(--stagger-i, 0), 20) * var(--stagger-base));
  will-change: opacity, transform;
}
@keyframes stagger-in {
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .stagger-item {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

/* W2-02: Projekt-Hero-Morph (Liste zu Detail) etwas ruhiger als Default */
::view-transition-group(sd-projekt-hero) {
  animation-duration: 320ms;
  animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
}
#pd-name { view-transition-name: sd-projekt-hero; } /* W2-02: Morph-Ziel Projektliste zu Detail */
