/* Search Bar Card Container */
.sb-card {
    border: 2px solid #dae4f0; /* Leichter Pastell-Rahmen (Blau-Grau) */
    box-shadow: 0 4px 12px rgba(0,0,0,0.05); /* Leichter Schatten für Tiefe */
    transition: background-color 0.3s ease, box-shadow 0.3s ease; /* Nur visuelle Änderungen animieren, kein Layout! */
}

.search-wrapper {
    display: flex;
    align-items: center;
    width: 100%;
    background: transparent;
    min-height: 48px; /* Fix für CLS Desktop: Platz reservieren */
}

/* 1. Kategorie Button */
.sb-cat-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    background: transparent;
    border: none;
    border-right: 1px solid #eee; /* Leichterer Trenner innen */
    padding: 0 20px;
    color: #333;
    cursor: pointer;
    white-space: nowrap;
    height: 48px;
    transition: background 0.2s;
    border-radius: 6px 0 0 6px;
}

.sb-cat-btn:hover {
    background-color: #f8f9fa;
    color: var(--mz-one);
}

.sb-cat-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.2;
    text-align: left;
}

.sb-cat-label {
    font-size: 1rem;
    color: #333;
    font-weight: 700;
    line-height: 1.2;
}

.sb-cat-value {
    font-size: 0.75rem;
    font-weight: 400;
    color: #888;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
}

.sb-cat-icon {
    font-size: 1.2rem;
    color: #777;
}

/* 2. Typ Dropdown (Custom) */
.sb-type-dropdown {
    height: 48px;
    display: flex;
    align-items: center;
    border-right: 1px solid #eee; /* Leichterer Trenner innen */
}

.sb-type-btn {
    border: none;
    background: transparent;
    padding: 0 15px;
    font-size: 0.95rem;
    color: #555;
    cursor: pointer;
    height: 100%;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap; /* Verhindert Umbruch bei "Alle Typen" */
}

.sb-type-btn:hover {
    color: #000;
    background-color: #fcfcfc;
}

/* 3. Suchformular */
.sb-input-wrapper {
    flex: 1; /* Nimmt im Desktop den restlichen Platz ein */
    margin: 0 10px;
    position: relative; /* Für absolute Positionierung der Vorschläge */
}

.sb-input {
    border: 2px solid #cbd5e1; /* Kräftigerer Rahmen (Blue-Grey) */
    border-radius: 4px;
    outline: none;
    width: 100%;
    font-size: 1rem;
    height: 40px;
    background: #f8f9fa; /* Leichter Hintergrund für bessere Erkennbarkeit */
    padding: 0 35px 0 15px; /* Rechts Platz für das X */
    color: #333;
    margin: 0;
    transition: all 0.2s;
}

.sb-input:focus {
    background: #fff;
    border-color: var(--mz-two);
    box-shadow: 0 0 0 2px rgba(56, 75, 112, 0.1);
}

.sb-input::placeholder {
    color: #999;
}

/* Clear Button (X) */
.sb-clear-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: #999;
    font-size: 1.5rem;
    line-height: 1;
    display: none; /* Standardmäßig versteckt */
    padding: 0 5px;
}
.sb-clear-btn:hover { color: #333; }

/* Suggestions Dropdown */
.sb-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-top: none;
    z-index: 9999; /* Sehr hoch, damit es über allem liegt */
    display: none;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    border-radius: 0 0 6px 6px;
    max-height: 300px;
    overflow-y: auto;
}

.sb-suggestion-item {
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 1px solid #f9f9f9;
    font-size: 0.95rem;
}
.sb-suggestion-item:hover, .sb-suggestion-item.active {
    background-color: #f0f0f0;
}

/* History Header & Footer */
.sb-suggestion-header {
    padding: 8px 15px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #999;
    text-transform: uppercase;
    background-color: #f8f9fa;
    border-bottom: 1px solid #eee;
    cursor: default;
}

.sb-suggestion-footer {
    padding: 10px 15px;
    border-top: 1px solid #eee;
    background-color: #fff;
    text-align: center;
}

.sb-suggestion-footer a {
    color: var(--mz-two);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
}
.sb-suggestion-footer a:hover {
    text-decoration: underline;
}

/* NEU: Aktive Auswahl hervorheben */
.sb-suggestion-item.selected {
    background-color: #e8f0fe; /* Hellblau */
    color: #1a73e8; /* Blau */
    font-weight: 600;
}

/* 4. History Button */
.sb-history-btn {
    background-color: transparent;
    color: #999;
    border: none;
    padding: 0 10px;
    height: 40px;
    margin-right: 4px;
    cursor: pointer;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.sb-history-btn:hover {
    color: #333;
    background-color: #f0f0f0;
}

/* 5. View Toggles (Grid/List) */
.sb-view-toggle {
    display: flex;
    align-items: center;
    padding-left: 10px;
    margin-left: 5px;
    border-left: 1px solid #eee; /* Leichterer Trenner innen */
    height: 30px; /* Höhe des Trenners */
    gap: 5px;
}

.sb-view-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: #999;
    padding: 5px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.sb-view-btn .icon-grid,
.sb-view-btn .icon-list {
    display: none;
}

/* Wenn aktueller Modus LIST ist -> Zeige Grid-Icon (zum Umschalten) */
.sb-view-btn[data-view-mode="list"] .icon-grid { display: block; }

/* Wenn aktueller Modus GRID ist -> Zeige List-Icon (zum Umschalten) */
.sb-view-btn[data-view-mode="grid"] .icon-list { display: block; }

.sb-view-btn:hover {
    background-color: #f0f0f0;
    color: #666;
}

.sb-view-btn {
    height: 42px;
    width: 52px; /* Breiter */
    border: 1px solid #ccc; /* Kräftigerer Rahmen */
    background-color: #f8f9fa; /* Leichter Hintergrund für mehr "Body" */
    color: #333; /* Dunkleres Icon */
    justify-content: center;
}

/* CSP Helpers (statt Inline-Styles) */
.sb-history-icon {
    float: right;
}
.sb-history-meta {
    color: #999;
    margin-left: 5px;
}

/* History Modal Styles */
.btn-search-delete {
    background: none;
    border: none;
    color: #ccc;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 10px;
    margin-left: 10px;
}
.btn-search-delete:hover {
    color: var(--mz-one);
}

/* Sticky Search Container */
.sticky-search-container {
    position: -webkit-sticky; /* Safari */
    position: sticky;
    top: 0; /* Ganz oben andocken */
    z-index: 990; /* Unter dem Mobile Overlay (9999), aber über dem Content */
    padding-top: 10px; /* Abstand zum Rand, wenn sticky */
    padding-bottom: 10px; /* Abstand zum Content */
    background-color: transparent; /* Oder Hintergrundfarbe, falls nötig */
    margin-top: 0 !important; /* Überschreibt mt-3, damit es direkt andockt */
    transition: background-color 0.3s ease, box-shadow 0.3s ease; /* Nur visuelle Änderungen animieren */
}

/* Sticky State (wird per JS gesetzt) */
.sticky-search-container.is-sticky {
    background-color: #f0f8ff; /* AliceBlue - sehr helles Blau */
    box-shadow: 0 4px 10px rgba(0,0,0,0.05); /* Dezenter Schatten */
    border: 2px solid var(--mz-blue); /* Umlaufender Rahmen */
    /* border-top: none;  <-- ENTFERNT für Desktop, damit Höhe gleich bleibt */
    /* padding-top: 5px;  <-- ENTFERNT für Desktop */
    /* padding-bottom: 5px; <-- ENTFERNT für Desktop */
}

.sticky-search-container.is-sticky .sb-card {
    border: none; /* Rahmen weg im Sticky-Modus */
    box-shadow: none; /* Schatten übernimmt der Container */
    background: transparent;
}

/* User Tools in Sticky Searchbar */
.sb-user-tools {
    display: none; /* Standardmäßig versteckt */
    align-items: center;
    margin-left: 10px;
    padding-left: 10px;
    border-left: 1px solid #eee;
    height: 30px;
}

/* Mobile Optimierung */
@media (max-width: 799.9px) {
    .search-wrapper {
        flex-wrap: wrap;
        gap: 5px; /* Reduzierter Gap für mehr Platz */
        padding: 5px;
        align-content: flex-start;
    }

    /* Zeile 1: Kategorie & Typ */
    .sb-cat-btn {
        order: 1;
        border-right: none;
        background-color: #f1f3f4;
        border-radius: 6px;
        height: 42px;
        width: calc(50% - 2.5px); /* Exakt 50% minus halber Gap */
        flex: 0 0 auto;
        justify-content: center;
        padding: 0 10px;
    }

    .sb-cat-value {
        max-width: 100px;
        font-size: 0.75rem;
    }

    .sb-type-dropdown {
        order: 2;
        border-right: none;
        background-color: #f1f3f4;
        border-radius: 6px;
        height: 42px;
        width: calc(50% - 2.5px); /* Exakt 50% minus halber Gap */
        flex: 0 0 auto;
        justify-content: center;
    }

    /* Zeile 2: Suche, Button, Toggles */
    .sb-input-wrapper {
        order: 3;
        width: auto;
        min-width: 0; /* WICHTIG: Erlaubt dem Input zu schrumpfen */
        flex: 1 1 auto; /* Nimmt den restlichen Platz */
        margin: 0; /* Margin entfernen für mehr Platz */
    }

    .sb-input {
        height: 42px;
        border: 1px solid #eee;
        border-radius: 6px;
        background-color: #fff;
        margin: 0;
        padding-right: 25px; /* Weniger Padding rechts */
    }

    .sb-history-btn {
        order: 4;
        padding: 0;
        height: 42px;
        width: 40px; /* Etwas schmaler */
        justify-content: center;
        margin-right: 0;
        flex: 0 0 auto; /* Feste Breite */
    }

    .sb-view-toggle {
        order: 5;
        display: flex;
        border-left: none;
        padding-left: 0;
        margin-left: 0;
        height: 42px;
        gap: 0;
        flex: 0 0 auto; /* Feste Breite */
    }

    .sb-view-btn {
        height: 42px;
        width: 40px; /* Etwas schmaler */
        border: 1px solid #eee;
        justify-content: center;
    }
}

/* Extra Small Devices (iPhone SE etc.) */
@media (max-width: 370px) {
    .sb-history-btn, .sb-view-btn {
        width: 36px; /* Noch schmaler auf ganz kleinen Screens */
    }
    .sb-input {
        font-size: 0.9rem; /* Kleinere Schrift */
        padding-left: 10px;
    }
}

.sb-history-title {
    font-size: 1.1rem;
    margin: 0;
}

/* Sentinel Fix */
#sticky-sentinel {
    height: 1px;
    width: 100%;
    opacity: 0; /* Statt visibility: hidden, damit es sicher im Layout ist */
    pointer-events: none;
    margin-bottom: -1px; /* Damit er keinen Platz wegnimmt */
}

/* Mobile Sticky Morphing (Optimized) */
@media (max-width: 799.9px) {
    /* Transition Base for Morphing Elements */
    .sb-cat-btn, .sb-type-dropdown {
        transition: all 0.3s ease;
        overflow: hidden;
    }

    /* Mobile Sticky: Fixed Position */
    .sticky-search-container.is-sticky {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        margin: 0 !important;
        z-index: 9999; /* Über allem */
        min-height: 0; /* Reset min-height für Mobile, da Fixed */

        /* Mobile-spezifisches Styling (kompakter) */
        border-top: none;
        padding-top: 5px;
        padding-bottom: 5px;
    }

    .sticky-search-container.is-sticky .search-wrapper {
        flex-wrap: nowrap;
        padding: 0 5px;
        gap: 0;
    }

    .sticky-search-container.is-sticky .sb-cat-btn,
    .sticky-search-container.is-sticky .sb-type-dropdown {
        /* Animate out instead of display: none */
        width: 0 !important;
        min-width: 0 !important;
        padding: 0 !important;
        border: none !important;
        opacity: 0;
        margin: 0 !important;
        flex: 0 0 0 !important; /* Prevent flex taking space */
    }

    .sticky-search-container.is-sticky .sb-input-wrapper {
        order: 1;
        margin: 0 5px 0 0;
        flex: 1;
    }

    .sticky-search-container.is-sticky .sb-history-btn {
        order: 2;
        margin-right: 0;
    }

    .sticky-search-container.is-sticky .sb-view-toggle {
        order: 3;
        margin-left: 5px;
    }
}