/*
 * Grundlayout der App-Shell: Sidebar links (Domain-Navigation) +
 * Hauptbereich rechts. Jede Domain rendert ihren Inhalt in die
 * <section data-domain-view="..."> Container in index.html.
 */
.app-shell {
  display: flex;
  /* 100vh ist auf iOS zu hoch (Adressleiste), 100dvh korrigiert das;
     die vh-Zeile bleibt als Fallback für ältere Browser stehen. */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.app-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-tertiary);
  display: flex;
  flex-direction: column;
  padding: var(--space-4) var(--space-2);
  gap: var(--space-4);
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Schließen-Button und Backdrop gehören nur zur mobilen Drawer-Variante. */
.app-sidebar__close,
.app-sidebar-backdrop,
.app-topbar__menu {
  display: none;
}

.app-sidebar__footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.app-sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  color: var(--text-bright);
  font-weight: 700;
  font-size: var(--font-size-lg);
}

.app-sidebar__brand-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  background: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.app-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.app-nav__group {
  display: flex;
  flex-direction: column;
}

.app-nav__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  background: transparent;
  border: none;
  text-align: left;
  width: 100%;
  transition: background 0.1s ease, color 0.1s ease;
}

.app-nav__item:hover {
  background: var(--bg-modifier-hover);
  color: var(--text-normal);
}

.app-nav__item.is-active {
  background: var(--bg-primary);
  color: var(--text-bright);
}

.app-nav__item-icon {
  font-size: 16px;
}

.app-nav__item-label {
  flex: 1;
}

.app-nav__item-chevron {
  font-size: 12px;
  transition: transform 0.15s ease;
}

.app-nav__group.is-expanded .app-nav__item-chevron {
  transform: rotate(180deg);
}

/* Akkordeon: Höhe des Submenüs wird per Grid-Trick animiert (0fr <-> 1fr),
   damit kein fixer max-height-Wert nötig ist. */
.app-nav__submenu-wrapper {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.2s ease;
}

.app-nav__group.is-expanded .app-nav__submenu-wrapper {
  grid-template-rows: 1fr;
}

.app-nav__submenu {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-left: var(--space-4);
  overflow: hidden;
  min-height: 0;
}

.app-nav__subitem {
  display: flex;
  align-items: center;
  padding: 6px var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  background: transparent;
  border: none;
  text-align: left;
  width: 100%;
  font-size: 13px;
  transition: background 0.1s ease, color 0.1s ease;
}

.app-nav__subitem:hover {
  background: var(--bg-modifier-hover);
  color: var(--text-normal);
}

.app-nav__subitem.is-active {
  background: var(--bg-primary);
  color: var(--text-bright);
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  /* Ohne min-height: 0 behalten Flex-Items ihre Inhaltshöhe als
     Mindesthöhe. In der mobilen Spalten-Anordnung wächst .app-main
     dann über die Shell hinaus, statt .app-content scrollen zu lassen
     – die Liste wäre schlicht nicht scrollbar. */
  min-height: 0;
  background: var(--bg-primary);
}

.app-topbar {
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-elevation-low);
}

.app-topbar__title {
  font-weight: 700;
  color: var(--text-bright);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-5);
}

.domain-view {
  display: none;
  height: 100%;
}

.domain-view.is-active {
  display: flex;
  flex-direction: column;
}

.app-sidebar__theme-toggle {
  margin: 0 var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  text-align: left;
  transition: background 0.1s ease, color 0.1s ease;
}

.app-sidebar__theme-toggle:hover {
  background: var(--bg-modifier-hover);
  color: var(--text-normal);
}

/*
 * Mobile (<= 768px): Die Sidebar wird zur Off-Canvas-Drawer, die über
 * den ☰-Button in der Topbar ein-/ausgeblendet wird. Vorher war sie
 * eine horizontal scrollbare Leiste am oberen Rand – auf dem Handy
 * kostete das dauerhaft Höhe und war schwer treffsicher bedienbar.
 */
@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
    height: 100dvh;
    position: relative;
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(84vw, 300px);
    z-index: var(--z-drawer);
    flex-direction: column;
    gap: var(--space-4);
    padding: calc(var(--space-4) + env(safe-area-inset-top)) var(--space-2)
      calc(var(--space-4) + env(safe-area-inset-bottom));
    padding-left: calc(var(--space-2) + env(safe-area-inset-left));
    box-shadow: var(--shadow-elevation-high);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    will-change: transform;
  }

  .app-shell.is-drawer-open .app-sidebar {
    transform: translateX(0);
  }

  .app-sidebar__close {
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: flex-end;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 18px;
  }

  .app-sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: var(--z-drawer-backdrop);
    background: rgba(0, 0, 0, 0.6);
  }

  .app-sidebar-backdrop[hidden] {
    display: none;
  }

  .app-topbar {
    height: auto;
    min-height: 52px;
    padding: env(safe-area-inset-top) calc(var(--space-3) + env(safe-area-inset-right)) 0
      calc(var(--space-3) + env(safe-area-inset-left));
    position: relative;
    z-index: var(--z-topbar);
    background: var(--bg-primary);
  }

  .app-topbar__menu {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    margin-left: calc(-1 * var(--space-2));
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-normal);
    font-size: 20px;
  }

  /* Touch-Ziele in der Drawer-Navigation großzügiger machen */
  .app-nav__item {
    padding: var(--space-3);
  }

  .app-nav__subitem {
    padding: var(--space-3);
    font-size: var(--font-size-sm);
  }

  .app-content {
    padding: var(--space-3);
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
    padding-left: calc(var(--space-3) + env(safe-area-inset-left));
    padding-right: calc(var(--space-3) + env(safe-area-inset-right));
  }

  /* Auf dem Handy scrollt die gesamte Domain-Ansicht in .app-content,
     statt (wie am Desktop) Liste und Detail getrennt zu scrollen. */
  .domain-view,
  .domain-view.is-active {
    height: auto;
    min-height: 100%;
  }
}
