/* ============================================================
   LAYOUT — App shell, header, nav, content area
   ============================================================ */

#app-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: calc(100% + var(--safe-top));
  overflow: hidden;
}

/* ---- Header ---- */
.app-header {
  position: fixed;
  top: 0;
  top: var(--safe-top);
  left: 0; right: 0;
  height: var(--header-h);
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-3);
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.context-chip {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  background: rgba(255,255,255,.18);
  color: white;
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-3);
  font-size: 15px;
  font-weight: 600;
  flex: 1;
  max-width: calc(100% - 96px);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  touch-action: manipulation;
  transition: background .15s;
}
.context-chip:active { background: rgba(255,255,255,.28); }
.context-chip #context-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.context-chip .chevron-down { flex-shrink: 0; }

.btn-icon {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: white;
  transition: background .15s;
  flex-shrink: 0;
}
.btn-icon:active { background: rgba(255,255,255,.2); }

/* ---- Main Content ---- */
#app-root {
  position: fixed;
  top: calc(var(--header-h) + var(--safe-top));
  left: 0; right: 0;
  bottom: calc(var(--nav-h) + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  background: var(--color-bg);
}

/* When nav is hidden (setup wizard, etc.) */
#app-root.no-nav {
  bottom: 0;
}

/* ---- Bottom Navigation ---- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  z-index: 100;
  box-shadow: 0 -2px 8px rgba(0,0,0,.06);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--color-text-secondary);
  font-size: 11px;
  font-weight: 500;
  transition: color .15s;
  touch-action: manipulation;
  padding: var(--space-2) 0;
}
.nav-item:active { opacity: .7; }
.nav-item.active {
  color: var(--color-primary);
}
.nav-item svg { transition: transform .15s; }
.nav-item.active svg { transform: scale(1.1); }

/* ---- Page sections ---- */
.page {
  padding: var(--space-4);
  min-height: 100%;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: var(--space-4);
  color: var(--color-text);
}

.section {
  margin-bottom: var(--space-6);
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
  padding: 0 var(--space-1);
}

/* ---- Bottom Sheets ---- */
.bottom-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--color-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  z-index: 300;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 92vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.bottom-sheet.open {
  transform: translateY(0);
}

.sheet-handle {
  width: 36px; height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  margin: var(--space-3) auto var(--space-2);
  flex-shrink: 0;
}

.sheet-content {
  padding: 0 var(--space-4) calc(var(--space-4) + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.sheet-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: var(--space-4);
  color: var(--color-text);
}

/* ---- Overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  opacity: 0;
  transition: opacity .3s;
}
.overlay.visible { opacity: 1; }

/* ============================================================
   TABLET & LANDSCAPE — Responsive breakpoints
   Tablet landscape: ≥768px width → app shell zentriert auf 720px
   ============================================================ */

@media (min-width: 768px) {
  :root {
    --app-max-w: 720px;
    --app-offset: max(0px, calc((100vw - var(--app-max-w)) / 2));
  }

  /* Header: zentriert mit max-width */
  .app-header {
    left: var(--app-offset);
    right: var(--app-offset);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
  }

  /* Main content area: zentriert */
  #app-root {
    left: var(--app-offset);
    right: var(--app-offset);
  }

  /* Bottom nav: zentriert, max-width begrenzt */
  .bottom-nav {
    left: var(--app-offset);
    right: var(--app-offset);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -2px 12px rgba(0,0,0,.10);
  }

  /* Nav items: nicht zu breit spreizen */
  .nav-item {
    max-width: 120px;
  }

  /* Bottom sheets: zentriert, nicht zu hoch */
  .bottom-sheet {
    left: var(--app-offset);
    right: var(--app-offset);
    max-height: 80vh;
  }

  /* Mehr Luft auf breiten Screens */
  .page {
    padding: var(--space-5) var(--space-5);
  }

  /* Seiten-Hintergrund sichtbar machen */
  body {
    background: #e8e8e8;
  }
}

/* Querformat auf kleinen Geräten (z.B. Handy quer) */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --header-h: 44px;
    --nav-h: 48px;
  }

  .bottom-sheet {
    max-height: 85vh;
  }

  .nav-item {
    font-size: 10px;
    gap: 2px;
  }

  .nav-item svg {
    width: 18px;
    height: 18px;
  }
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + var(--space-4));
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: #323232;
  color: white;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: 14px;
  z-index: 500;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
