/* ================================
   SELECT2 STYLING FÜR LTX KURSAUSWAHLEN - Modern & General
   ================================ */

/* Select2 Container Grundstyles */
.select2-container--ltx-theme {
    display: block;
    width: 100% !important;
}

/* Fix für falsche Höhenberechnung: Original-Select auch stylen */
.gfield select.ltx-kurs1-select,
.gfield select.ltx-kurs2-select,
.gfield select.ltx-intervall-select,
.gfield select.ltx-laufzeit-select,
.ltx-kurs1-select select,
.ltx-kurs2-select select,
.ltx-intervall-select select,
.ltx-laufzeit-select select {
    height: 72px !important;
    min-height: 72px !important;
    opacity: 0; /* Statt display:none, damit Höhe berechnet werden kann falls nötig */
}

.select2-container--ltx-theme .select2-selection--single {
    position: relative; /* Wichtig für absolute Positionierung von Pfeil/Clear */
    background-color: var(--ltx-surface, #fff);
    border: 1px solid var(--ltx-border, #e2e8f0);
    border-radius: var(--ltx-radius, 12px);
    height: 72px !important; /* Erhöht für mehr Platz - WICHTIG: !important */
    min-height: 72px !important;
    padding: 10px 16px;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    box-sizing: border-box; /* Wichtig für korrekte Höhenberechnung */
}

.select2-container--ltx-theme.select2-container--focus .select2-selection--single {
    border-color: var(--ltx-primary, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    outline: none;
}

.select2-container--ltx-theme .select2-selection--single:hover {
    border-color: var(--ltx-primary, #2563eb);
}

/* Selection Text */
.select2-container--ltx-theme .select2-selection__rendered {
    color: var(--ltx-text, #0f172a);
    line-height: normal !important; /* Reset line-height for flex children */
    padding-left: 0;
    padding-right: 40px !important; /* Space for X and Arrow */
    font-weight: 500;
    display: flex !important;
    align-items: center !important;
    height: 100%;
}

/* Ensure selected option displays correctly */
.select2-container--ltx-theme .select2-selection__rendered .ltx-selected-option {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    height: 100%;
}

/* Selected Option in der Select-Box */
.ltx-selected-option {
    display: flex;
    align-items: center;
    gap: 8px; /* Further reduced gap */
    width: 100%;
    height: 100%;
}

/* Reuse styles inside selected option */
.ltx-selected-option .ltx-kurs-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
}

.ltx-selected-option .ltx-trainer-photo {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
}

.ltx-selected-option .ltx-kurs-details {
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ltx-text-muted, #64748b);
}

/* Mobile adjustments for selected option */
@media (max-width: 768px) {
    .select2-container--ltx-theme .select2-selection--single {
        height: 64px;
        padding: 8px 12px;
    }

    .ltx-selected-option .ltx-kurs-avatar {
        width: 40px;
        height: 40px;
    }
    
    .ltx-selected-option .ltx-kurs-name {
        font-size: 14px;
    }
    
    .ltx-selected-option .ltx-kurs-details {
        font-size: 12px;
    }
}

/* Placeholder */
.select2-container--ltx-theme .select2-selection__placeholder {
    color: var(--ltx-text-muted, #64748b);
    font-style: italic;
    line-height: 32px; /* Center placeholder vertically */
}

/* Arrow */
.select2-container--ltx-theme .select2-selection__arrow {
    position: absolute;
    height: 100%;
    top: 0;
    right: 16px;
    width: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.select2-container--ltx-theme .select2-selection__arrow b {
    border-color: var(--ltx-text-muted, #64748b) transparent transparent transparent;
    border-style: solid;
    border-width: 6px 5px 0 5px;
    height: 0;
    width: 0;
    margin: 0;
    position: relative;
    top: auto;
    left: auto;
}

.select2-container--ltx-theme.select2-container--open .select2-selection__arrow b {
    border-color: transparent transparent var(--ltx-text-muted, #64748b) transparent;
    border-width: 0 5px 6px 5px;
}

/* Clear Button */
.select2-container--ltx-theme .select2-selection__clear {
    color: var(--ltx-text-muted, #64748b);
    cursor: pointer;
    font-weight: bold;
    margin-right: 0;
    position: absolute;
    top: 0;
    right: 35px; /* Position left of arrow */
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    z-index: 2;
}

.select2-container--ltx-theme .select2-selection__clear:hover {
    color: #ef4444;
}

/* Dropdown Container - General Open State */
.select2-container--ltx-theme.select2-container--open .select2-dropdown {
    border: 1px solid var(--ltx-primary, #2563eb);
    box-shadow: var(--ltx-shadow-lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1));
    background-color: var(--ltx-surface, #fff);
    z-index: 999999 !important; /* Ensure it's on top */
}

/* Dropdown Opening BELOW */
.select2-container--ltx-theme .select2-dropdown--below {
    border-top: none;
    border-radius: 0 0 var(--ltx-radius, 12px) var(--ltx-radius, 12px);
    /* Fix für Höhenberechnung: Select2 denkt das Feld ist ca 40px hoch, es ist aber 72px. 
       Daher schieben wir das Dropdown manuell 30px nach unten. */
    margin-top: 30px !important; 
}

/* Dropdown Opening ABOVE */
.select2-container--ltx-theme .select2-dropdown--above {
    border-bottom: none;
    border-radius: var(--ltx-radius, 12px) var(--ltx-radius, 12px) 0 0;
    /* Fix für Höhenberechnung bei Anzeige oben */
    margin-top: 33px !important; 
}

/* Selection Box Styling when Open BELOW */
.select2-container--ltx-theme.select2-container--open.select2-container--below .select2-selection--single {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom-color: var(--ltx-surface, #fff); /* Hide border visually */
    border-color: var(--ltx-primary, #2563eb); /* Active color */
}

/* Selection Box Styling when Open ABOVE */
.select2-container--ltx-theme.select2-container--open.select2-container--above .select2-selection--single {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-top-color: var(--ltx-surface, #fff); /* Hide border visually */
    border-color: var(--ltx-primary, #2563eb); /* Active color */
}

/* Fix for the gap/overlap issue */
.select2-container--ltx-theme .select2-dropdown {
    /* Reset default margins */
    margin: 0;
}

/* Search Box */
.select2-container--ltx-theme .select2-search--dropdown {
    padding: 12px;
    background: var(--ltx-bg, #f8fafc);
    border-bottom: 1px solid var(--ltx-border, #e2e8f0);
}

.select2-container--ltx-theme .select2-search__field {
    background: var(--ltx-surface, #fff);
    border: 1px solid var(--ltx-border, #e2e8f0);
    border-radius: 6px;
    color: var(--ltx-text, #0f172a);
    font-size: 14px;
    padding: 8px 12px;
    width: 100%;
}

.select2-container--ltx-theme .select2-search__field:focus {
    border-color: var(--ltx-primary, #2563eb);
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* Results */
.select2-container--ltx-theme .select2-results {
    max-height: 300px;
    padding: 4px 0;
}

.select2-container--ltx-theme .select2-results__option {
    padding: 0;
    color: var(--ltx-text, #0f172a);
    cursor: pointer;
    transition: all 0.2s ease;
}

.select2-container--ltx-theme .select2-results__option:hover,
.select2-container--ltx-theme .select2-results__option--highlighted {
    background-color: var(--ltx-bg, #f8fafc);
}

.select2-container--ltx-theme .select2-results__option--selected {
    background-color: var(--ltx-primary, #2563eb);
    color: white;
}

.select2-container--ltx-theme .select2-results__option--selected:hover {
    background-color: var(--ltx-primary-hover, #1d4ed8);
}

/* Custom Kurs Option Layout - Exakt wie im Design */
.ltx-select2-option {
    display: flex;
    align-items: center;
    padding: 8px 12px; /* Further reduced padding */
    border-bottom: 1px solid var(--ltx-border, #e2e8f0);
    gap: 8px; /* Further reduced gap */
    transition: all 0.2s ease;
}

.ltx-select2-option:last-child {
    border-bottom: none;
}

.ltx-select2-option:hover {
    background-color: var(--ltx-bg, #f8fafc);
}

/* Avatar Container */
.ltx-kurs-avatar {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    background: #f0f0f0;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.ltx-trainer-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Kurs Content */
.ltx-kurs-content {
    flex: 1;
    min-width: 0;
}

.ltx-kurs-name {
    font-weight: 600;
    font-size: 16px;
    color: var(--ltx-text, #0f172a);
    margin-bottom: 6px;
    line-height: 1.3;
}

.ltx-kurs-details {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--ltx-text-muted, #64748b);
    flex-wrap: wrap;
}

.ltx-trainer-name {
    color: var(--ltx-primary, #2563eb) !important;
    font-weight: 500;
}

.ltx-schedule {
    color: var(--ltx-secondary, #64748b) !important;
}

.ltx-level {
    color: #e67e22 !important;
    font-weight: 500;
}

.ltx-kurs-details span:not(:last-child):after {
    content: "•";
    margin-left: 8px;
    color: var(--ltx-border, #e2e8f0);
    font-weight: bold;
}

/* Selected Option in der Select-Box */
.ltx-selected-option {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    overflow: hidden; /* Prevent overflow */
}

.ltx-selected-avatar {
    width: 28px !important;
    height: 28px !important;
    max-width: 28px !important;
    max-height: 28px !important;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--ltx-border, #e2e8f0);
    flex-shrink: 0;
    display: block;
}

.ltx-selected-text {
    font-weight: 500;
    color: var(--ltx-text, #0f172a);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Selected State für Custom Option */
.select2-container--ltx-theme .select2-results__option--selected {
    background-color: var(--ltx-primary, #2563eb);
    color: white;
}

.select2-container--ltx-theme .select2-results__option--selected .ltx-kurs-name {
    color: white;
}

.select2-container--ltx-theme .select2-results__option--selected .ltx-kurs-details span {
    color: rgba(255, 255, 255, 0.9) !important;
}

.select2-container--ltx-theme .select2-results__option--selected:hover {
    background-color: var(--ltx-primary-hover, #1d4ed8);
}

/* Highlight State */
.select2-container--ltx-theme .select2-results__option--highlighted {
    background-color: var(--ltx-bg, #f8fafc);
}

.select2-container--ltx-theme .select2-results__option--highlighted .ltx-kurs-name {
    color: var(--ltx-text, #0f172a);
}

/* Simple Option (Fallback) */
.ltx-select2-simple {
    padding: 16px 20px;
    font-size: 15px;
    color: var(--ltx-text, #0f172a);
    font-style: normal;
}

/* No Results / Loading */
.select2-container--ltx-theme .select2-results__message {
    color: var(--ltx-text-muted, #64748b);
    cursor: default;
    padding: 16px;
    text-align: center;
    font-style: italic;
}

/* Disabled State */
.select2-container--ltx-theme.select2-container--disabled .select2-selection--single {
    background-color: var(--ltx-bg, #f8fafc);
    color: var(--ltx-text-muted, #64748b);
    cursor: not-allowed;
    border-color: var(--ltx-border, #e2e8f0);
}

/* Focus Within Container */
.gfield.ltx-kurs1-select:focus-within,
.gfield.ltx-kurs2-select:focus-within {
    position: relative;
    z-index: 100; /* Ensure focused field is on top */
}

/* Ensure parent container is relative for dropdownParent positioning */
.ginput_container_select,
.ginput_container {
    position: relative;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .select2-container--ltx-theme .select2-selection--single {
        height: 44px;
        padding: 6px 10px;
    }
    
    .select2-container--ltx-theme .select2-selection__arrow {
        height: 42px;
    }
    
    .ltx-select2-option {
        padding: 12px 16px;
        gap: 12px;
    }
    
    .ltx-kurs-avatar {
        width: 40px;
        height: 40px;
    }
    
    .ltx-kurs-name {
        font-size: 14px;
    }
    
    .ltx-kurs-details {
        font-size: 13px;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    
    .ltx-kurs-details span:not(:last-child):after {
        display: none;
    }
    
    .ltx-selected-avatar {
        width: 24px;
        height: 24px;
    }
}

/* Chips Styling */
.ltx-chip {
    display: inline-flex !important;
    align-items: center;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    margin-left: 6px;
    white-space: nowrap;
}

.ltx-chip-level {
    background-color: rgba(230, 126, 34, 0.1) !important;
    color: #e67e22 !important;
}

.ltx-chip-age {
    background-color: rgba(16, 185, 129, 0.1) !important;
    color: #10b981 !important;
}

/* Adjust separator for chips */
.ltx-kurs-details span.ltx-chip:after {
    display: none !important;
}

/* Remove separator before chips */
.ltx-kurs-details span:has(+ .ltx-chip):after {
    display: none !important;
}
/* Fallback for browsers not supporting :has */
.ltx-schedule:after {
    content: "" !important;
    margin: 0 !important;
}
