/**
 * Custom Dropdown Styles
 * Mobile-optimized dropdown component for dnevna razmatranja and book chapters
 */

.custom-dropdown {
    position: relative;
    width: 100%;
    font-family: "Roboto Condensed", sans-serif;
    font-weight: 500;
}

/* Trigger Button */
.custom-dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 48px; /* Touch-friendly height */
    font-size: 16px; /* Prevent zoom on iOS */
}

.custom-dropdown-trigger:hover {
    border-color: #26AEF2;
    box-shadow: 0 2px 8px rgba(38, 174, 242, 0.1);
}

.custom-dropdown.open .custom-dropdown-trigger {
    border-color: #26AEF2;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    box-shadow: 0 2px 8px rgba(38, 174, 242, 0.15);
}

.custom-dropdown-label {
    flex: 1;
    text-align: left;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
}

.custom-dropdown-arrow {
    color: #666;
    font-size: 12px;
    transition: transform 0.2s ease;
    margin-left: 8px;
}

.custom-dropdown.open .custom-dropdown-arrow {
    transform: rotate(180deg);
}

/* Dropdown Menu */
.custom-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 2px solid #26AEF2;
    border-top: none;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    max-height: 400px;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
}

.custom-dropdown.open .custom-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Enable interactions only when dropdown is open */
.custom-dropdown.open .custom-dropdown-options {
    pointer-events: auto; /* Re-enable interactions when dropdown is open */
    user-select: text; /* Allow text selection when open (for search) */
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

/* Search Input */
.custom-dropdown-search {
    padding: 12px;
    border-bottom: 1px solid #e0e0e0;
    background: #f8f9fa;
}

.custom-dropdown-search-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 16px; /* Prevent zoom on iOS */
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
}

.custom-dropdown-search-input:focus {
    border-color: #26AEF2;
    box-shadow: 0 0 0 2px rgba(38, 174, 242, 0.1);
}

/* Options Container */
.custom-dropdown-options {
    max-height: 320px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth; /* Smooth scrolling for focus */

    /* Prevent text selection and interaction when dropdown is closed */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    pointer-events: none; /* Disable all mouse/touch events when closed */
}

/* Group Headers */
.custom-dropdown-group-header {
    padding: 12px 16px 8px;
    font-weight: 600;
    font-size: 14px;
    color: #26AEF2;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Options */
.custom-dropdown-option {
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.15s ease;
    border-bottom: 1px solid #f0f0f0;
    min-height: 24px; /* Touch-friendly */
    display: flex;
    align-items: center;
    color: #333 !important; /* Force dark text on light background */
    font-size: 14px !important; /* Ensure text is visible */
    line-height: 1.4 !important; /* Ensure text is visible */
}

.custom-dropdown-option:last-child {
    border-bottom: none;
}

.custom-dropdown-option:hover,
.choicesHolder .custom-dropdown-option:hover,
.mbr-choices .custom-dropdown-option:hover {
    background: rgba(166, 230, 230, .5) !important;
    color: #26AEF2 !important;
}

.custom-dropdown-option.selected {
    background: #26AEF2;
    color: #fff;
    font-weight: 600;
    position: relative;
    border-left: 12px solid #1e9bd1; /* Extra highlight for selected */
}
/* Focus highlight class for when scrolling to selected item */
.custom-dropdown-option.focus-highlight {
    background: #1e9bd1 !important;
    transform: scale(1.02);
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(38, 174, 242, 0.3);
}

/* Smooth transitions for all options */
.custom-dropdown-option {
    transition: all 0.2s ease;
}

/* Add a subtle pulse animation when dropdown opens */
.custom-dropdown.open .custom-dropdown-option.selected {
    animation: selectedPulse 0.8s ease-out;
}

@keyframes selectedPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(38, 174, 242, 0.4);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(38, 174, 242, 0.2);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(38, 174, 242, 0);
    }
}

.custom-dropdown-option.selected:hover {
    background: #1e9bd1;
}

/* Removed .option-label rules - no longer using nested spans */

/* Force visibility */
.custom-dropdown-option,
.custom-dropdown-option * {
    color: #333 !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* Override any parent container styles - Direct text approach */
.choicesHolder .custom-dropdown-option,
.mbr-choices .custom-dropdown-option {
    font-size: 14px !important;
    line-height: 1.4 !important; /* Fix the line-height issue */
    color: #333 !important;
    background: transparent !important;
    text-shadow: none !important;
    font-weight: normal !important;
}

/* No Results */
.custom-dropdown-no-results {
    padding: 20px 16px;
    text-align: center;
    color: #666;
    font-style: italic;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .custom-dropdown-trigger {
        padding: 14px 16px;
        min-height: 52px;
        font-size: 16px;
    }
    
    .custom-dropdown-option {
        padding: 16px;
        min-height: 52px;
        font-size: 16px;
    }
    
    .custom-dropdown-search-input {
        padding: 12px 14px;
        font-size: 16px;
    }
    
    .custom-dropdown-menu {
        max-height: 60vh; /* Better mobile viewport usage */
    }
    
    .custom-dropdown-options {
        max-height: calc(60vh - 60px); /* Account for search bar */
    }
}

/* High DPI / Retina Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .custom-dropdown-trigger {
        border-width: 1px;
    }
    
    .custom-dropdown-menu {
        border-width: 1px;
        border-top: none;
    }
}

/* Force Light Mode - Override system dark mode for better visibility */
/* This ensures dropdowns are always readable regardless of system theme */
@media (prefers-color-scheme: dark) {
    .custom-dropdown-trigger {
        background: #fff !important;
        border-color: #e0e0e0 !important;
        color: #333 !important;
    }

    .custom-dropdown-label {
        color: #333 !important;
    }

    .custom-dropdown-arrow {
        color: #666 !important;
    }

    .custom-dropdown-menu {
        background: #fff !important;
        border-color: #26AEF2 !important;
    }

    .custom-dropdown-option {
        color: #333 !important;
        background: #fff !important;
        border-bottom-color: #f0f0f0 !important;
    }

    .custom-dropdown-option:hover {
        background: rgba(166, 230, 230, .5) !important;
        color: #26AEF2 !important;
    }

    .custom-dropdown-option.selected {
        background: #26AEF2 !important;
        color: #fff !important;
        border-left-color: #1e9bd1 !important;
    }

    .custom-dropdown-option.selected:hover {
        background: #1e9bd1 !important;
    }

    .custom-dropdown-search {
        background: #f8f9fa !important;
        border-bottom-color: #e0e0e0 !important;
    }

    .custom-dropdown-search-input {
        background: #fff !important;
        border-color: #ddd !important;
        color: #333 !important;
    }

    .custom-dropdown-search-input::placeholder {
        color: #999 !important;
    }

    .custom-dropdown-group-header {
        background: #f8f9fa !important;
        border-bottom-color: #e0e0e0 !important;
        color: #26AEF2 !important;
    }

    .custom-dropdown-no-results {
        color: #666 !important;
    }

    /* Scrollbar styling in dark mode */
    .custom-dropdown-options::-webkit-scrollbar-track {
        background: #f1f1f1 !important;
    }

    .custom-dropdown-options::-webkit-scrollbar-thumb {
        background: #c1c1c1 !important;
    }

    .custom-dropdown-options::-webkit-scrollbar-thumb:hover {
        background: #a8a8a8 !important;
    }
}

/* Animation for smooth transitions */
@keyframes dropdownSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.custom-dropdown.open .custom-dropdown-menu {
    animation: dropdownSlideIn 0.2s ease;
}

/* Focus styles for accessibility */
.custom-dropdown-trigger:focus {
    outline: 2px solid #26AEF2;
    outline-offset: 2px;
}

.custom-dropdown-option:focus {
    background: #e3f2fd;
    outline: 2px solid #26AEF2;
    outline-offset: -2px;
}

/* Scrollbar styling for webkit browsers */
.custom-dropdown-options::-webkit-scrollbar {
    width: 6px;
}

.custom-dropdown-options::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.custom-dropdown-options::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.custom-dropdown-options::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}
