/* ==========================================================================
   1. FARB-THEMES
   ========================================================================== */
:root {
  --theme-primary: #0044cc;
  --theme-primary-hover: #003399;
  --theme-bg-active: #eef4ff;
}
body.theme-blue {
  --theme-primary: #0044cc;
  --theme-primary-hover: #003399;
  --theme-bg-active: #eef4ff;
}
body.theme-green {
  --theme-primary: #28a745;
  --theme-primary-hover: #1e7e34;
  --theme-bg-active: #e8f5e9;
}

/* ==========================================================================
   2. LAYOUT BASIS (SYMMETRIE-FIX)
   ========================================================================== */
html {
  scroll-behavior: smooth;
  /* FIX: Reserviert Platz für den Scrollbalken, damit das Layout perfekt mittig bleibt */
  scrollbar-gutter: stable; 
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  font-family: Arial, sans-serif;
  background-color: #ffffff;
  min-height: 100vh;
  overflow-x: hidden; 
  width: 100%;
}

.app-container {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: center;
  gap: 0;
  flex: 1 0 auto;
  width: 100%;
  /* FIX: Padding links/rechts angleichen */
  padding-right: 20px; 
  box-sizing: border-box;
}

.main-content {
  flex: 1;
  margin-top: 0px;      
  margin-bottom: 99px;
  max-width: 850px;        
  order: 1;                
  box-sizing: border-box;
  /* FIX: Symmetrischer Abstand innerhalb des Textes */
}

.main-content h2 {
  scroll-margin-top: 140px; 
}

.mobile-only { display: none; }

/* ==========================================================================
   3. DESKTOP NAVIGATION (STICKY SIDEBAR)
   ========================================================================== */
.sidebar-nav {
  width: 320px;
  position: -webkit-sticky;
  position: sticky;
  top: 30px;       
  display: flex;
  flex-direction: column;  
  order: 2;                
  flex-shrink: 0;
  max-height: calc(100vh - 190px); 
  /* DEIN WERT: margin-left: 40px beibehalten */
}

.btn-back {
  display: inline-block;
  width: 284px;
  padding: 12px 18px;
  margin-bottom: 20px;
  background-color: var(--theme-primary); 
  color: #fff;
  text-decoration: none;
  border-radius: 6px;
  font-weight: bold;
  transition: background 0.3s;
}

.btn-back:hover { background-color: var(--theme-primary-hover); }

.desktop-toc-box {
  background: #f8f9fa;
  padding: 20px 20px 30px 20px;
  box-sizing: border-box;
  border: 1px solid #e2e8f0; 
  border-radius: 12px;     
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05); 
  display: flex;
  flex-direction: column;
  overflow: hidden;        
  flex: 1;                 
}

.nav-title {
  margin-top: 0;           
  margin-bottom: 15px;
  font-size: 1.2rem;
  color: #333;
  border-bottom: 2px solid #ddd; 
  padding-bottom: 10px;
  flex-shrink: 0;         
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;        
  flex: 1;                 
}

.toc-list::-webkit-scrollbar { width: 0; }
.toc-list { scrollbar-width: none; }

.toc-list li { margin-bottom: 12px; }

.toc-list a {
  padding: 8px 12px;
  border-left: 4px solid transparent;
  transition: all 0.2s ease;
  display: block;
  text-decoration: none;
  color: #555;
}

.toc-list a.is-h3 {
  padding-left: 25px;
  font-size: 0.85rem;
  color: #777;
}

.toc-list a.active {
  background-color: var(--theme-bg-active);
  border-left: 4px solid var(--theme-primary);
  color: var(--theme-primary) !important;
  font-weight: bold;
}

/* ==========================================================================
   4. SCROLL BUTTON & LEGAL NAV (AUTO-HIDE AUF DESKTOP & MOBILE)
   ========================================================================== */
button.scroll-btn {
  position: fixed;
  bottom: 70px;
  right: 30px;
  background-color: var(--theme-primary); 
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 55px;
  height: 55px;
  font-size: 24px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: background 0.3s, transform 0.2s;
}

.legal-nav {
  display: flex;
  gap: 20px;
  margin-bottom: 0px;
  flex-wrap: wrap;
  
  /* Klebt jetzt ganz oben am Rand (0px), damit kein Spalt mehr entsteht */
  position: sticky;
  top: 0; 
  z-index: 900;
  
  /* Der Hintergrund deckt nun alles ab */
  background-color: rgba(255, 255, 255, 0.95);
  
  /* Wir nutzen Padding (Innenabstand) statt Margin (Außenabstand), 
     damit der weiße Hintergrund die volle Fläche ausfüllt. 
     Werte: oben 15px, rechts 15px, unten 10px, links 30px */
  padding: 30px 0px 20px 30px;
  margin-left: 0; 
  
  transition: transform 0.3s ease-in-out, opacity 0.3s;
}

.legal-nav.nav-hidden {
  transform: translateY(-160%);
  opacity: 0;
  pointer-events: none;
}

.legal-nav a {
  padding: 10px 14px;
  text-decoration: none;
  border: 1px solid #ddd;
  border-radius: 6px;
  color: #555;
  background: white;
  transition: all 0.2s;
}

.legal-nav a.active {
  background: var(--theme-primary);
  color: #fff;
  border-color: var(--theme-primary);
}

/* ==========================================================================
   5. MOBILE (< 900px)
   ========================================================================== */
@media (max-width: 900px) {
  .app-container { flex-direction: column; padding: 0;}
  .main-content { order: 2; max-width: 100%; padding: 0; margin-top: 0; }
  .desktop-only { display: none !important; }
  .mobile-only { display: flex !important; }
  
  .legal-nav {
    gap: 10px;
    top: 65px; 
    padding: 10px;
    margin: 0;
  }

  .sidebar-nav {
    width: 100%;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 999;
    background: #f8f9fa;
    border-bottom: 1px solid #ddd; 
    margin: 0;
    order: 1; 
  }

  .mobile-top-bar {
    width: 100%;
    display: flex;
    align-items: center;
    padding: 10px;
    box-sizing: border-box;
  }

  .btn-back-mobile {
    background-color: var(--theme-primary); 
    color: #fff !important;
    -webkit-text-fill-color: #fff !important;
    text-decoration: none;
    font-size: 1.4rem;
    width: 44px;
    height: 44px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .mobile-dropdown {
    flex-grow: 1;
    height: 44px; 
    margin-left: 10px;
    padding-left: 10px;
    padding-right: 30px;
    font-size: 16px; 
    font-weight: bold;
    color: #333 !important;
    -webkit-text-fill-color: #333 !important;
    border: 1px solid #ccc;
    border-radius: 6px;
    background-color: #fff;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
    background-size: 14px;
  }
}