/**
 * Sidebar Icon-Bar & Tabs System
 * Google Maps Style: Vertikale Icon-Leiste links, Content-Panel rechts
 */

/* ============================================
   ICON SIDEBAR (Google Maps Style)
   ============================================ */
:root {
    --iconbar-width: 48px;
}

.sidebar-iconbar {
    position: fixed;
    top: var(--header-height, 48px);
    left: 0;
    bottom: 0;
    width: var(--iconbar-width);
    background: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 6px;
    z-index: 1600;
    border-right: 1px solid #e0e0e0;
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.06);
    pointer-events: auto;
    /* Viele Module in kleinem Fenster: Die Leiste scrollt (Mausrad, Leiste unsichtbar), sonst wären die
       unteren Module nicht erreichbar (17.11.2026, vorher overflow: hidden). */
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: none;
}

/* Scrollbar fuer Icon-Bar */
.sidebar-iconbar::-webkit-scrollbar {
    width: 0;
}

/* Fußzeile: liegt fixiert über der Seite (z-index 1600). Iconleiste und Seitenleiste reichen bis an den
   Fensterrand und lassen unten ihre Höhe frei — sonst läge das Ende jedes Reiters dahinter (17.11.2026).
   --footer-height misst 2d/index.php (ResizeObserver, auch bei umbrechender Fußzeile); ohne Fußzeile 0.
   Mobil ist die Fußzeile ausgeblendet, die Leisten regelt dort mobile-sheet.css. */
body:not(.mobile-layout) .sidebar-iconbar,
body:not(.mobile-layout) .sidebar {
    padding-bottom: var(--footer-height, 0px);
}

/* Icon-Bar Buttons */
.iconbar-btn {
    width: 40px;
    min-height: 40px;
    margin: 2px 0;
    padding: 6px 0 4px 0;
    background: transparent;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    transition: all 0.2s ease;
    color: var(--text-muted, #5f6368);
    position: relative;
}

.iconbar-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-primary, #333);
}

.iconbar-btn.active {
    color: var(--primary-color, #8B0000);
    background: rgba(var(--primary-color-rgb, 139, 0, 0), 0.1);
}

.iconbar-btn i {
    font-size: 18px;
    line-height: 1;
}

/* Icon-Bar Label (klein, unter dem Icon) */
.iconbar-label {
    font-size: 9px;
    font-weight: 500;
    line-height: 1.1;
    max-width: 44px;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

/* ============================================
   LEGACY TAB NAVIGATION (ausgeblendet wenn Iconbar aktiv)
   ============================================ */
.sidebar-tabs {
    display: flex;
    background: var(--bg-light, #f5f5f5);
    border-bottom: 1px solid var(--border-color, #ddd);
    flex-shrink: 0;
}

.sidebar-tab {
    flex: 1;
    padding: 8px 2px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted, #666);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    white-space: nowrap;
    overflow: hidden;
    min-width: 0;
}

.sidebar-tab:hover {
    color: var(--text-primary, #333);
    background: rgba(0, 0, 0, 0.03);
}

.sidebar-tab.active {
    color: var(--primary-color, #8B0000);
    border-bottom-color: var(--primary-color, #8B0000);
    background: #fff;
}

.sidebar-tab i {
    font-size: 13px;
    flex-shrink: 0;
}

.sidebar-tab span {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   TAB CONTENT
   ============================================ */
.sidebar-tab-content {
    display: none;
    flex: 1;
    flex-direction: column;
    /* Reicht der Inhalt eines Moduls über den Reiter hinaus, scrollt der Reiter selbst (17.11.2026).
       Vorher „overflow: hidden": Module ohne eigenen Scrollbereich (Flächenanalyse, Eigentümerabfrage,
       Meldung, ALKIS-Buch, Plansuche) wurden unten abgeschnitten. Module mit eigenem Scrollbereich
       (height: 100 % + innere Liste) laufen nicht über und bleiben unberührt. Prüfung: Ablauf „seitenleiste". */
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 0; /* Wichtig fuer Flex-Overflow */
}

.sidebar-tab-content.active {
    display: flex;
}

/* Layer Tab - behaelt bestehende Struktur */
#tab-layers {
    flex: 1;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

#tab-layers.active {
    display: flex;
}

#tab-layers .layer-search-container {
    flex-shrink: 0;
}

#tab-layers .sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
    padding-bottom: 100px;
}

/* Flurstuecksuche Tab */
#tab-alkis {
    flex: 1;
    overflow: hidden;
}

#tab-alkis #alkis-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

#tab-alkis #alkis-panel.visible {
    display: flex;
}

#tab-alkis .alkis-search-form {
    flex-shrink: 0;
    overflow-y: auto;
    max-height: 50%;
}

#tab-alkis #alkis-results {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

#tab-alkis #alkis-results-list {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 50px;
}

/* Weinlagen Tab */
/* Kein eigenes overflow: Die Kern-Regel (.sidebar-tab-content, scrollt) gilt auch hier. Vorher „visible“ für das
   Ausklappmenü der Suche — es bleibt per max-width in der Seitenleiste; mit „visible“ ragte ein überlaufendes
   Formular unten aus der Seitenleiste und war nicht erreichbar (17.11.2026). */
#tab-weinlagen {
    flex: 1;
}

#tab-weinlagen #weinlagen-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: visible;
}

#tab-weinlagen #weinlagen-panel.visible {
    display: flex;
}

#tab-weinlagen .weinlagen-search-form {
    flex-shrink: 0;
    overflow: visible;
    max-height: 50%;
}

#tab-weinlagen #weinlagen-results {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

#tab-weinlagen #weinlagen-results-list {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 50px;
}

/* ============================================
   RESPONSIVE: DESKTOP (>= 769px)
   Iconbar als Flex-Child im main-content
   ============================================ */
@media (min-width: 769px) {
    .sidebar-iconbar {
        position: relative;
        top: auto;
        bottom: auto;
        left: auto;
        height: 100%;
        flex-shrink: 0;
        box-shadow: none;
    }

    /* Sidebar braucht kein left-Offset, da Iconbar Flex-Child ist */
    .sidebar.has-iconbar {
        left: auto;
    }

    .sidebar.has-iconbar.closed {
        transform: none;
        margin-left: calc(-1 * var(--sidebar-width, 320px));
    }
}

/* ============================================
   RESPONSIVE: TABLET (max 768px)
   Beide fixed, Sidebar neben Iconbar
   ============================================ */
@media (max-width: 768px) {
    .sidebar-iconbar {
        position: fixed !important;
        top: 50px !important;
        left: 0 !important;
        bottom: 0 !important;
        z-index: 1600 !important;
    }

    .sidebar.has-iconbar {
        left: var(--iconbar-width, 48px) !important;
        width: calc(300px - var(--iconbar-width, 48px)) !important;
    }

    .sidebar.has-iconbar.closed {
        transform: translateX(calc(-100% - var(--iconbar-width, 48px))) !important;
    }

    /* Layer-Suche immer sichtbar */
    #layer-search-container {
        display: block !important;
    }
}

/* ============================================
   RESPONSIVE: MOBILE (max 480px)
   Kleinere Iconbar, Labels ausblenden
   ============================================ */
@media (max-width: 480px) {
    :root {
        --iconbar-width: 42px;
    }

    .iconbar-btn {
        width: 36px;
        min-height: 36px;
    }

    .iconbar-btn i {
        font-size: 16px;
    }

    .iconbar-label {
        display: none;
    }

    .sidebar.has-iconbar {
        width: calc(85vw - var(--iconbar-width, 42px)) !important;
    }

    /* Legacy Tabs (falls noch verwendet) */
    .sidebar-tab {
        padding: 8px 4px;
        font-size: 10px;
    }

    .sidebar-tab span {
        display: none;
    }

    .sidebar-tab i {
        font-size: 15px;
    }
}
