﻿/* Searchable Select Component - Complete CSS with Dark Mode Support */

/* Base variables for light mode */
:root {
    --primary-color: #ffffff;
    --primary-light: rgba(255, 255, 255, 0.2);
    --primary-dark: #f3f4f6;
    --border-color: #d1d5db;
    --text-color: #374151;
    --text-light: #6b7280;
    --placeholder-color: #9ca3af;
    --background-color: #f3f4f6;
    --selected-background: #FF6E1B; /* Orange for selected items */
    --selected-text: #ffffff;
    --hover-background: rgba(255, 110, 27, 0.1); /* Light orange for hover */
    --error-color: #ef4444;
    --dropdown-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --focus-shadow: 0 0 0 3px rgba(255, 110, 27, 0.2);
    --transition-speed: 0.2s;
}

/* Dark mode variables - aligned with form styling (dark:bg-gray-700) */
/* Support both class-based (.dark) and media query based dark mode */
.dark,
.dark * {
    --primary-color: #374151; /* gray-700 to match form inputs */
    --primary-light: rgba(55, 65, 81, 0.2);
    --primary-dark: #1f2937;
    --border-color: #4b5563; /* gray-600 */
    --text-color: #e5e7eb; /* gray-200 */
    --text-light: #9ca3af;
    --placeholder-color: #6b7280;
    --background-color: #1f2937;
    --hover-background: rgba(255, 110, 27, 0.2);
    --dropdown-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --focus-shadow: 0 0 0 3px rgba(255, 110, 27, 0.3);
}

/* Media query based dark mode support - DISABLED to respect application theme setting */
/* The application uses .dark class on html/body to control theme, not OS preference */

/* Container */
.searchable-select-container {
    position: relative;
    width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin-top: 0.25rem; /* mt-1 equivalent */
}

/* Button styling - aligned with form inputs (px-3 py-3 rounded-lg) */
.searchable-select-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.75rem; /* py-3 px-3 */
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--text-color);
    background-color: var(--primary-color);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem; /* rounded-lg */
    cursor: pointer;
    transition: all var(--transition-speed) ease-in-out;
    text-align: left;
    min-height: 2.75rem; /* Match form input height */
}

    .searchable-select-button:hover {
        border-color: var(--selected-background);
    }

    .searchable-select-button:focus {
        outline: none;
        border-color: var(--selected-background);
        box-shadow: var(--focus-shadow);
    }

/* Button text */
.searchable-select-button-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-grow: 1;
    flex-shrink: 1;
}

/* Right side container for icons */
.searchable-select-right {
    display: flex;
    align-items: center;
    margin-left: 8px;
    flex-shrink: 0;
}

/* Clear button */
.searchable-select-clear {
    display: none; /* Hidden by default */
    margin-right: 8px;
    cursor: pointer;
    color: var(--placeholder-color);
    transition: color var(--transition-speed) ease;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

    .searchable-select-clear:hover {
        color: var(--error-color);
    }

/* Dropdown icon */
.searchable-select-icon {
    flex-shrink: 0;
    transition: transform var(--transition-speed) ease;
    width: 16px;
    height: 16px;
    color: var(--text-light);
}

.searchable-select-button.active .searchable-select-icon {
    transform: rotate(180deg);
}

/* Dropdown container */
.searchable-select-dropdown {
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0;
    width: 100%;
    max-height: 15rem;
    overflow-y: auto;
    background-color: var(--primary-color);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem; /* rounded-lg to match button */
    box-shadow: var(--dropdown-shadow);
    z-index: 50; /* Higher z-index to ensure visibility */
    display: none;
    scrollbar-width: thin;
    scrollbar-color: var(--hover-background) transparent;
    transition: background-color var(--transition-speed) ease-in-out, border-color var(--transition-speed) ease-in-out;
}

    /* Custom scrollbar for webkit browsers */
    .searchable-select-dropdown::-webkit-scrollbar {
        width: 6px;
    }

    .searchable-select-dropdown::-webkit-scrollbar-track {
        background: transparent;
    }

    .searchable-select-dropdown::-webkit-scrollbar-thumb {
        background-color: var(--hover-background);
        border-radius: 3px;
    }

/* Search input container */
.searchable-select-search {
    position: sticky;
    top: 0;
    padding: 0.5rem;
    background-color: var(--primary-color);
    border-bottom: 1px solid var(--border-color);
    z-index: 1;
    transition: background-color var(--transition-speed) ease-in-out, border-color var(--transition-speed) ease-in-out;
}

    /* Search input */
    .searchable-select-search input {
        width: 100%;
        padding: 0.5rem;
        font-size: 0.875rem;
        border: 1px solid var(--border-color);
        border-radius: 0.25rem;
        transition: border-color var(--transition-speed) ease-in-out, box-shadow var(--transition-speed) ease-in-out, background-color var(--transition-speed) ease-in-out, color var(--transition-speed) ease-in-out;
        background-color: var(--primary-color);
        color: var(--text-color);
    }

        .searchable-select-search input:focus {
            outline: none;
            border-color: var(--selected-background);
            box-shadow: 0 0 0 2px rgba(255, 110, 27, 0.2);
        }

        .searchable-select-search input::placeholder {
            color: var(--placeholder-color);
        }

/* Options list */
.searchable-select-options {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* Option item */
.searchable-select-option {
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--text-color);
}

    .searchable-select-option:hover {
        background-color: var(--hover-background);
    }

    .searchable-select-option.selected {
        background-color: var(--selected-background);
        color: var(--selected-text);
        font-weight: 500;
    }

    /* Highlighted option (keyboard navigation) */
    .searchable-select-option.highlighted {
        background-color: var(--hover-background);
        outline: 2px solid var(--selected-background);
        outline-offset: -2px;
    }

    .searchable-select-option.highlighted.selected {
        background-color: var(--selected-background);
        color: var(--selected-text);
    }

/* No results message */
.searchable-select-no-results {
    padding: 0.75rem 1rem;
    color: var(--placeholder-color);
    font-style: italic;
    font-size: 0.875rem;
}

/* Animation for dropdown */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.searchable-select-dropdown.show {
    display: block;
    animation: fadeIn var(--transition-speed) ease-out forwards;
}

/* Responsive styles */
@media (max-width: 768px) {
    .searchable-select-dropdown {
        max-height: 12rem;
    }

    .searchable-select-button {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }

    .searchable-select-option {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }

    .searchable-select-search input {
        padding: 0.4375rem;
        font-size: 0.8125rem;
    }
}

@media (max-width: 480px) {
    .searchable-select-dropdown {
        max-height: 10rem;
    }

    .searchable-select-button {
        min-height: 2.25rem;
    }

   
    .searchable-select-icon {
        width: 14px;
        height: 14px;
    }
    .searchable-select-clear
    {
        width: 14px;
        height: 57px;
    }
    .searchable-select-clear {
        padding: 21px;
        margin: -8px;
    }
}

/* Disabled state */
.searchable-select-container.disabled .searchable-select-button {
    background-color: var(--background-color);
    color: var(--placeholder-color);
    cursor: not-allowed;
    border-color: var(--border-color);
}

    .searchable-select-container.disabled .searchable-select-button:hover,
    .searchable-select-container.disabled .searchable-select-button:focus {
        border-color: var(--border-color);
        box-shadow: none;
    }

/* Error state */
.searchable-select-container.error .searchable-select-button {
    border-color: var(--error-color);
}

    .searchable-select-container.error .searchable-select-button:focus {
        box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
    }

/* Touch device optimizations */
@media (hover: none) {
    .searchable-select-option {
        padding: 0.625rem 1rem; /* Slightly larger touch targets */
    }

    .searchable-select-clear {
        padding: 21px;
        margin: -8px;
    }
}

/* RTL support */
[dir="rtl"] .searchable-select-button {
    text-align: right;
}

[dir="rtl"] .searchable-select-right {
    margin-left: 0;
    margin-right: 8px;
}

[dir="rtl"] .searchable-select-clear {
    margin-right: 0;
    margin-left: 8px;
}

/* Error state - enhanced */
.searchable-select-container.error .searchable-select-button {
    border-color: var(--error-color);
    border-width: 2px; /* Make border thicker */
}

/* Add a helper text for errors */
.searchable-select-error-text {
    color: var(--error-color);
    font-size: 0.75rem;
    margin-top: 0.25rem;
    display: none;
}

.searchable-select-container.error .searchable-select-error-text {
    display: block;
}

/* Additional styles to match other form controls */
.searchable-select-button {
    height: 2.5rem; /* Match height of text inputs */
    padding: 0.5rem 0.75rem;
}

    /* Focus ring that matches other form elements */
    .searchable-select-button:focus-visible {
        outline: 2px solid transparent;
        outline-offset: 2px;
        box-shadow: var(--focus-shadow);
    }

/* Ensure transitions are smooth when switching themes */
.searchable-select-button,
.searchable-select-dropdown,
.searchable-select-search,
.searchable-select-search input,
.searchable-select-option {
    transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out, border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

/* ============================================ */
/* DARK MODE - System Preference (media query) */
/* Matches Tailwind CDN default behavior       */
/* ============================================ */

@media (prefers-color-scheme: dark) {
    .searchable-select-button {
        background-color: #374151 !important;
        border-color: #4b5563 !important;
        color: #e5e7eb !important;
    }

    .searchable-select-dropdown {
        background-color: #374151 !important;
        border-color: #4b5563 !important;
    }

    .searchable-select-search {
        background-color: #374151 !important;
        border-color: #4b5563 !important;
    }

    .searchable-select-search input {
        background-color: #1f2937 !important;
        border-color: #4b5563 !important;
        color: #e5e7eb !important;
    }

    .searchable-select-search input::placeholder {
        color: #9ca3af !important;
    }

    .searchable-select-option {
        color: #e5e7eb !important;
        background-color: #374151 !important;
    }

    .searchable-select-option:hover {
        background-color: rgba(255, 110, 27, 0.2) !important;
    }

    .searchable-select-option.selected {
        background-color: #FF6E1B !important;
        color: #ffffff !important;
    }

    .searchable-select-option.highlighted {
        background-color: rgba(255, 110, 27, 0.2) !important;
        outline: 2px solid #FF6E1B !important;
        outline-offset: -2px;
    }

    .searchable-select-option.highlighted.selected {
        background-color: #FF6E1B !important;
        color: #ffffff !important;
    }

    .searchable-select-icon {
        color: #9ca3af !important;
    }

    .searchable-select-clear {
        color: #6b7280 !important;
    }

    .searchable-select-no-results {
        color: #9ca3af !important;
    }
}

/* ============================================ */
/* LIGHT MODE - System Preference (media query)*/
/* Explicit light styles when NOT dark         */
/* ============================================ */

@media (prefers-color-scheme: light) {
    .searchable-select-button {
        background-color: #ffffff !important;
        border-color: #d1d5db !important;
        color: #374151 !important;
    }

    .searchable-select-dropdown {
        background-color: #ffffff !important;
        border-color: #d1d5db !important;
    }

    .searchable-select-search {
        background-color: #ffffff !important;
        border-color: #d1d5db !important;
    }

    .searchable-select-search input {
        background-color: #ffffff !important;
        border-color: #d1d5db !important;
        color: #374151 !important;
    }

    .searchable-select-option {
        color: #374151 !important;
        background-color: #ffffff !important;
    }

    .searchable-select-option:hover {
        background-color: rgba(255, 110, 27, 0.1) !important;
    }

    .searchable-select-option.highlighted {
        background-color: rgba(255, 110, 27, 0.1) !important;
        outline: 2px solid #FF6E1B !important;
        outline-offset: -2px;
    }

    .searchable-select-option.highlighted.selected {
        background-color: #FF6E1B !important;
        color: #ffffff !important;
    }

    .searchable-select-icon {
        color: #6b7280 !important;
    }

    .searchable-select-clear {
        color: #9ca3af !important;
    }

    .searchable-select-no-results {
        color: #9ca3af !important;
    }
}

/* ============================================ */
/* CLASS-BASED DARK MODE (.dark on html)       */
/* For manual theme toggle support             */
/* ============================================ */

html.dark .searchable-select-button,
.dark .searchable-select-button {
    background-color: #374151 !important;
    border-color: #4b5563 !important;
    color: #e5e7eb !important;
}

html.dark .searchable-select-dropdown,
.dark .searchable-select-dropdown {
    background-color: #374151 !important;
    border-color: #4b5563 !important;
}

html.dark .searchable-select-search,
.dark .searchable-select-search {
    background-color: #374151 !important;
    border-color: #4b5563 !important;
}

html.dark .searchable-select-search input,
.dark .searchable-select-search input {
    background-color: #1f2937 !important;
    border-color: #4b5563 !important;
    color: #e5e7eb !important;
}

html.dark .searchable-select-search input::placeholder,
.dark .searchable-select-search input::placeholder {
    color: #9ca3af !important;
}

html.dark .searchable-select-option,
.dark .searchable-select-option {
    color: #e5e7eb !important;
    background-color: #374151 !important;
}

html.dark .searchable-select-option:hover,
.dark .searchable-select-option:hover {
    background-color: rgba(255, 110, 27, 0.2) !important;
}

html.dark .searchable-select-option.selected,
.dark .searchable-select-option.selected {
    background-color: #FF6E1B !important;
    color: #ffffff !important;
}

html.dark .searchable-select-option.highlighted,
.dark .searchable-select-option.highlighted {
    background-color: rgba(255, 110, 27, 0.2) !important;
    outline: 2px solid #FF6E1B !important;
    outline-offset: -2px;
}

html.dark .searchable-select-option.highlighted.selected,
.dark .searchable-select-option.highlighted.selected {
    background-color: #FF6E1B !important;
    color: #ffffff !important;
}

html.dark .searchable-select-icon,
.dark .searchable-select-icon {
    color: #9ca3af !important;
}

html.dark .searchable-select-clear,
.dark .searchable-select-clear {
    color: #6b7280 !important;
}

html.dark .searchable-select-no-results,
.dark .searchable-select-no-results {
    color: #9ca3af !important;
}
