/* ============================================================================
   Layout — Mobile-First (v11 — Rewrite)
   Base = Mobile, @media (min-width: 768px) = Desktop
   KEIN backdrop-filter, KEINE transparenten Overlays
   ============================================================================ */

/* --- App Shell --- */
.app {
  display: flex;
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
}

/* --- Sidebar (nur Desktop) --- */
.sidebar {
  display: none;
}

/* --- Main Content (Mobile-First) --- */
.main {
  flex: 1;
  padding: var(--space-4);
  padding-top: calc(56px + var(--space-4));
  padding-bottom: calc(var(--bottom-nav-height) + var(--space-4));
  overflow-x: hidden;
  max-width: 100vw;
  min-width: 0;
}

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

.page-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 800;
  letter-spacing: var(--tracking-tight);
  margin-bottom: var(--space-1);
}

.page-subtitle {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* --- KPI Bar --- */
.kpi-bar {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
  overflow-x: auto;
  padding: var(--space-2);
  scrollbar-width: none;
  background: var(--bg-surface);
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--border-subtle);
}
.kpi-bar::-webkit-scrollbar { display: none; }

/* KPI-Bar auf Dashboard ausblenden (Hero-KPIs uebernehmen) */
.main.dashboard-active .kpi-bar {
  display: none;
}

.kpi-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-lg);
  white-space: nowrap;
  min-width: fit-content;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: 700;
  font-feature-settings: 'tnum' on, 'lnum' on;
  color: var(--text-primary);
}

.kpi-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

/* --- Content Grid (Mobile: 1 Spalte) --- */
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

.grid-item-wide {
  grid-column: span 1;
}

.grid-item-full {
  grid-column: 1 / -1;
}

/* --- View Container --- */
.view {
  display: none;
  overflow-x: hidden;
  max-width: 100%;
}

.view.active {
  display: block;
  animation: fadeInUp var(--duration-slow) var(--ease-out);
}

/* --- Stagger-Container --- */
.stagger > * {
  opacity: 0;
  animation: fadeInUp 0.4s var(--ease-out) forwards;
}

.stagger > *:nth-child(1)  { animation-delay: 0ms; }
.stagger > *:nth-child(2)  { animation-delay: 40ms; }
.stagger > *:nth-child(3)  { animation-delay: 80ms; }
.stagger > *:nth-child(4)  { animation-delay: 120ms; }
.stagger > *:nth-child(5)  { animation-delay: 160ms; }
.stagger > *:nth-child(6)  { animation-delay: 200ms; }
.stagger > *:nth-child(n+7) { animation-delay: 200ms; }

/* --- Mobile Header --- */
.mobile-header {
  display: flex;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  z-index: var(--z-fixed);
  padding: 0 var(--space-4);
  align-items: center;
  justify-content: space-between;
}

.mobile-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.mobile-header-logo {
  width: 32px;
  height: 32px;
  border-radius: var(--border-radius-sm);
  background: var(--gradient-hero);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.mobile-header-title {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
}

.mobile-header-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.mobile-header-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--border-radius-md);
  background: none;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-fast) ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.mobile-header-btn:active {
  background: var(--bg-elevated);
  color: var(--accent-primary);
}

.mobile-header-btn svg {
  pointer-events: none;
}

/* --- Bottom Navigation --- */
.bottom-nav {
  display: block;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  z-index: var(--z-fixed);
}

.bottom-nav-items {
  display: flex;
  height: 100%;
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  transition: color var(--duration-fast) ease;
  min-height: 56px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item.active {
  color: var(--accent-primary);
  font-weight: 700;
}

.bottom-nav-item i {
  width: 24px;
  height: 24px;
}

/* --- Nav Item (Sidebar) --- */
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--border-radius-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-fast) ease;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  min-height: 44px;
  touch-action: manipulation;
}

.nav-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(240, 136, 62, 0.12);
  color: var(--accent-primary);
  font-weight: 600;
}

.nav-item.active::after {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-primary);
  margin-left: auto;
  box-shadow: 0 0 8px var(--accent-glow);
}

.nav-item i {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active i {
  opacity: 1;
}

.nav-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--space-2) var(--space-4);
}

.nav-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: var(--space-1) var(--space-5);
  opacity: 0.6;
}

.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: var(--bg-primary);
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 8px;
  min-width: 18px;
  text-align: center;
}

/* --- Toast Container (Mobile) --- */
.toast-container {
  top: auto;
  bottom: calc(var(--bottom-nav-height) + var(--space-3));
  right: var(--space-3);
  left: var(--space-3);
}

.toast {
  min-width: unset;
  width: 100%;
  max-width: 100%;
}

/* --- Section-Titles kleiner auf Mobile --- */
.section-title {
  font-size: var(--text-lg);
}

/* ============================================================================
   Desktop Layout (min-width: 768px)
   ============================================================================ */
@media (min-width: 768px) {
  .sidebar {
    display: flex;
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    position: fixed;
    top: 0;
    left: 0;
    z-index: var(--z-fixed);
    flex-direction: column;
    transition: width var(--duration-normal) var(--ease-out);
  }

  .sidebar-header {
    padding: var(--space-5) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }

  .sidebar-logo {
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius-md);
    background: var(--gradient-hero);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    box-shadow: var(--shadow-glow);
  }

  .sidebar-title {
    font-family: var(--font-display);
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
  }

  .sidebar-subtitle {
    font-size: var(--text-xs);
    color: var(--text-muted);
    white-space: nowrap;
  }

  .sidebar-nav {
    flex: 1;
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    overflow-y: auto;
  }

  .sidebar-footer {
    padding: var(--space-4);
    border-top: 1px solid var(--border-subtle);
  }

  .sidebar-scan-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--border-radius-md);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--duration-fast) ease;
    min-height: 36px;
  }

  .sidebar-scan-btn:hover {
    background: var(--bg-base);
    color: var(--accent-primary);
    border-color: var(--border-accent);
  }

  /* Mobile Header + Bottom Nav ausblenden */
  .mobile-header {
    display: none;
  }

  .bottom-nav {
    display: none;
  }

  /* Main bekommt Sidebar-Margin */
  .main {
    margin-left: var(--sidebar-width);
    padding: var(--space-6);
    padding-top: var(--space-6);
    padding-bottom: var(--space-6);
    max-width: calc(var(--content-max-width) + var(--space-6) * 2);
  }

  .page-title {
    font-size: var(--text-2xl);
  }

  .page-subtitle {
    font-size: var(--text-sm);
  }

  .kpi-value {
    font-size: var(--text-xl);
  }

  .kpi-bar {
    gap: var(--space-4);
    padding: var(--space-3);
  }

  .kpi-item {
    padding: var(--space-3) var(--space-5);
  }

  /* Grid: 2 Spalten auf Tablet */
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-item-wide {
    grid-column: span 2;
  }

  /* Toast Position auf Desktop */
  .toast-container {
    top: var(--space-4);
    right: var(--space-4);
    left: auto;
    bottom: auto;
  }

  .toast {
    min-width: 280px;
    max-width: 420px;
    width: auto;
  }

  .section-title {
    font-size: var(--text-xl);
  }
}

/* --- Tablet Grid (768-1023px) --- */
@media (min-width: 768px) and (max-width: 1023px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* --- Desktop groesser: 3 Spalten --- */
@media (min-width: 1400px) {
  .grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* --- Theme Toggle (Sidebar) --- */
.theme-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--border-radius-md);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-fast) ease;
  min-height: 36px;
  margin-top: var(--space-2);
}

.theme-toggle:hover {
  background: var(--bg-base);
  color: var(--accent-primary);
  border-color: var(--border-accent);
}

/* Vereins-Modus Section (zwischen Nav und Footer) */
.sidebar-mode-section {
  display: none;
}

@media (min-width: 768px) {
  .sidebar-mode-section {
    display: block;
    padding: var(--space-3);
    border-top: 1px solid var(--border-subtle);
  }
}

/* Vereins-Modus Toggle */
.mode-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--border-radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration-fast) ease;
  min-height: 40px;
  border: 1px solid var(--accent-orange);
  background: rgba(240,136,62,0.12);
  color: var(--accent-orange);
  margin-top: 0;
}

.mode-toggle:hover {
  background: rgba(240,136,62,0.22);
}

.mode-toggle.mode-all {
  border-color: var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.mode-toggle.mode-all:hover {
  background: var(--bg-base);
  color: var(--text-primary);
}

/* --- Light Theme Layout Overrides --- */
[data-theme="light"] .sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
}

[data-theme="light"] .nav-item.active {
  background: rgba(212, 112, 42, 0.1);
}

[data-theme="light"] .kpi-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

[data-theme="light"] .bottom-nav {
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
}

[data-theme="light"] .mobile-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
}

/* ==================== MORE SHEET (Mobile Overflow-Nav) ==================== */
.more-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: var(--z-modal);
  display: none;
}
.more-sheet-backdrop.active {
  display: block;
}

.more-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  padding: var(--space-3) var(--space-4) calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform var(--duration-normal, 200ms) ease;
  z-index: calc(var(--z-modal) + 1);
  touch-action: manipulation;
}
.more-sheet.active {
  transform: translateY(0);
}

.more-sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border-subtle);
  border-radius: 2px;
  margin: 0 auto var(--space-3);
}

.more-sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-3);
}

.more-sheet-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.more-sheet-close {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg-elevated, rgba(255,255,255,0.05));
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  touch-action: manipulation;
}

.more-sheet-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin: var(--space-4) var(--space-2) var(--space-2);
  font-weight: 600;
}
.more-sheet-section-label:first-of-type {
  margin-top: var(--space-2);
}

.more-sheet-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: none;
  background: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  text-align: left;
  border-radius: 10px;
  cursor: pointer;
  min-height: 48px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.more-sheet-item:active {
  background: var(--bg-elevated, rgba(255,255,255,0.05));
}
.more-sheet-item i {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-muted);
}

/* Desktop: Sheet + Backdrop komplett ausblenden (Sidebar uebernimmt) */
@media (min-width: 768px) {
  .more-sheet,
  .more-sheet-backdrop {
    display: none !important;
  }
}
