/* App-Shell-Grid + Main + Topbar-Slot + Mobile-Drawer-Chrome + geteilte States.
   Geometrie 1:1 Cascade (content/crm shell.md); Reset/Body kommen aus dashboard-signatures.css. */
#appMain {
  display: none;
  min-height: 100vh;
  width: 100%;
  position: relative;
  z-index: 1;
}
#appMain.active {
  display: grid;
  grid-template-columns: var(--sb-w) 1fr;
}
html[data-sidebar='collapsed'] #appMain.active {
  grid-template-columns: var(--sb-w-collapsed) 1fr;
}

.main {
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar-wrap {
  position: sticky;
  top: 0;
  z-index: 20;
}
.main-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

/* Mobile-Open + Backdrop */
.mobile-open {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top, 0px));
  left: 14px;
  z-index: 999;
  width: 38px;
  height: 38px;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--t-bright);
  cursor: pointer;
}
.mobile-open svg {
  width: 18px;
  height: 18px;
}
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1050;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
html[data-sidebar='open'] .sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}

/* Shared button (vh-btn) */
.vh-btn {
  appearance: none;
  background: var(--accent-soft-bg);
  color: var(--accent);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-md);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.vh-btn:hover {
  background: color-mix(in oklab, var(--accent) 16%, transparent);
  border-color: var(--accent);
}

/* Spinner */
.vh-spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: vhSpin 0.8s linear infinite;
}
@keyframes vhSpin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .vh-spinner {
    animation-duration: 2s;
  }
}

/* Geteilte UI-States */
.vh-state {
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--t-muted);
  font-size: 14px;
  text-align: center;
}
.vh-state-ico {
  width: 30px;
  height: 30px;
  opacity: 0.7;
}
.vh-state-error {
  color: var(--danger);
}
.vh-state-msg {
  color: var(--t-secondary);
  max-width: 420px;
}

/* Boot-States (vor der Shell) */
.dash-boot-state {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--t-muted);
  font-size: 13px;
}
.dash-boot-error {
  color: var(--t-secondary);
}
.dbe-ico {
  width: 30px;
  height: 30px;
  color: var(--danger);
}
.dbe-msg {
  font-size: 14px;
}

/* Phase-1-View-Platzhalter */
.dash-stub {
  min-height: calc(100vh - var(--topbar-h) - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.dash-stub-card {
  text-align: center;
  max-width: 480px;
  padding: 40px 36px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  background: var(--bg-elev-1);
  box-shadow: var(--shadow-md);
}
.dash-stub-card h1 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.3px;
  margin-bottom: 10px;
}
.dash-stub-tag {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-pill);
  padding: 2px 8px;
  vertical-align: middle;
}
.dash-stub-card p {
  color: var(--t-secondary);
  font-size: 14px;
  line-height: 1.6;
}

/* Auto-Collapse (Desktop ≤1100 & ≥721) */
@media (max-width: 1100px) and (min-width: 721px) {
  #appMain.active {
    grid-template-columns: var(--sb-w-collapsed) 1fr;
  }
  .sidebar .nav-section,
  .sidebar .nav-item span:not(.nav-icon),
  .sidebar .brand-name,
  .sidebar .user-info,
  .sidebar .sb-settings span {
    display: none;
  }
  .sidebar .nav-item {
    justify-content: center;
    padding: 10px;
  }
}

/* Mobile (≤720) */
@media (max-width: 720px) {
  #appMain.active {
    grid-template-columns: 1fr !important;
    /* Stacking-Context von #appMain (z-index:1) aufheben: sonst ist die Sidebar (z-1100, IN #appMain)
       global unter dem Backdrop (z-1050, Geschwister) gefangen → Backdrop fängt alle Taps/Scrolls ab. */
    z-index: auto;
  }
  .main-scroll {
    padding: 18px 16px;
  }
  .mobile-open {
    display: flex;
  }
  html[data-sidebar='open'] .mobile-open {
    display: none;
  }
}
