/**
 * Custom Dropdown Component
 * Modal-based dropdown to replace native <select> elements
 * Prefix: .cd- (custom dropdown)
 */

/* === Overlay === */
.cd-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 99999;
    opacity: 0;
    animation: cd-fade-in 0.2s ease-out forwards;
}

.cd-overlay--closing {
    animation: cd-fade-out 0.2s ease-out forwards;
}

/* === Modal Panel === */
.cd-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    width: 100%;
    max-width: 400px;
    max-height: 70vh;
    background-color: #ffffff;
    border-radius: 12px;
    z-index: 100000;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    will-change: transform, opacity;
    animation: cd-slide-up 0.25s ease-out forwards;
}

.cd-modal--closing {
    animation: cd-slide-down 0.25s ease-out forwards;
}

/* === Modal Header === */
.cd-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(to right, #0369a1, #1e3a8a);
    color: #ffffff;
    flex-shrink: 0;
}

.cd-modal-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.cd-close-btn {
    background: none;
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s ease;
    min-width: 44px;
    min-height: 44px;
}

.cd-close-btn:hover {
    opacity: 0.8;
}

.cd-close-btn svg {
    width: 20px;
    height: 20px;
}

/* === Modal Body === */
.cd-modal-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
}

/* === Search Bar === */
.cd-search-wrapper {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 12px 16px;
    background-color: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.cd-search-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.cd-search-input:focus {
    border-color: #0077b6;
    box-shadow: 0 0 0 3px rgba(0, 119, 182, 0.1);
}

.cd-search-input::placeholder {
    color: #9ca3af;
}

/* === Options List === */
.cd-options-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.cd-option {
    width: 100%;
    min-height: 44px;
    padding: 10px 16px;
    text-align: left;
    background: none;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9375rem;
    color: #1f2937;
    transition: background-color 0.15s ease, color 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cd-option:hover {
    background-color: #f3f4f6;
}

.cd-option:focus {
    outline: 2px solid #0077b6;
    outline-offset: -2px;
}

.cd-option--selected {
    background-color: #0077b6;
    color: #ffffff;
    font-weight: 500;
}

.cd-option--selected:hover {
    background-color: #005a8a;
}

.cd-option-text {
    flex: 1;
}

.cd-option-check {
    width: 16px;
    height: 16px;
    margin-left: 8px;
    display: none;
}

.cd-option--selected .cd-option-check {
    display: block;
}

.cd-no-results {
    padding: 40px 20px;
    text-align: center;
    color: #6b7280;
    font-size: 0.875rem;
}

/* === Trigger Button === */
.cd-trigger {
    width: 100%;
    min-height: 44px;
    padding: 10px 40px 10px 12px;
    text-align: left;
    background-color: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 1rem;
    color: #111827;
    cursor: pointer;
    position: relative;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    display: flex;
    align-items: center;
}

.cd-trigger:hover {
    border-color: #9ca3af;
}

.cd-trigger:focus {
    outline: none;
    border-color: #0077b6;
    box-shadow: 0 0 0 3px rgba(0, 119, 182, 0.1);
}

.cd-trigger--placeholder {
    color: #6b7280;
}

.cd-trigger-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cd-trigger-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: #6b7280;
    transition: transform 0.2s ease;
    pointer-events: none;
}

.cd-trigger--open .cd-trigger-icon {
    transform: translateY(-50%) rotate(180deg);
}

/* === Animations === */
@keyframes cd-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes cd-fade-out {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

@keyframes cd-slide-up {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes cd-slide-down {
    from {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    to {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.95);
    }
}

/* === Dark Mode === */
html[data-theme="dark"] .cd-overlay {
    background-color: rgba(0, 0, 0, 0.7);
}

html[data-theme="dark"] .cd-modal {
    background-color: #242424;
    border: 1px solid #3d3d3d;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

html[data-theme="dark"] .cd-modal-header {
    background-color: #ff9f1c;
    border-bottom: 1px solid #e68a00;
    color: #1a1a1a;
}

html[data-theme="dark"] .cd-close-btn {
    color: #1a1a1a;
}

html[data-theme="dark"] .cd-search-wrapper {
    background-color: #242424;
    border-bottom-color: #3d3d3d;
}

html[data-theme="dark"] .cd-search-input {
    background-color: #333333;
    border-color: #3d3d3d;
    color: #F3F4F6;
}

html[data-theme="dark"] .cd-search-input:focus {
    border-color: #ff9f1c;
    box-shadow: 0 0 0 3px rgba(255, 159, 28, 0.1);
}

html[data-theme="dark"] .cd-search-input::placeholder {
    color: #6b7280;
}

html[data-theme="dark"] .cd-option {
    color: #F3F4F6;
}

html[data-theme="dark"] .cd-option:hover {
    background-color: #333333;
}

html[data-theme="dark"] .cd-option:focus {
    outline-color: #ff9f1c;
}

html[data-theme="dark"] .cd-option--selected {
    background-color: #ff9f1c;
    color: #1a1a1a;
}

html[data-theme="dark"] .cd-option--selected:hover {
    background-color: #e68a00;
}

html[data-theme="dark"] .cd-no-results {
    color: #9ca3af;
}

html[data-theme="dark"] .cd-trigger {
    background-color: #1a1a1a;
    border-color: #3d3d3d;
    color: #F3F4F6;
}

html[data-theme="dark"] .cd-trigger:hover {
    border-color: #505050;
}

html[data-theme="dark"] .cd-trigger:focus {
    border-color: #ff9f1c;
    box-shadow: 0 0 0 3px rgba(255, 159, 28, 0.1);
}

html[data-theme="dark"] .cd-trigger--placeholder {
    color: #6b7280;
}

html[data-theme="dark"] .cd-trigger-icon {
    color: #9ca3af;
}

/* === Responsive (Mobile) === */
@media (max-width: 640px) {
    .cd-modal {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        transform: translateY(100%);
        max-width: none;
        max-height: 80vh;
        border-radius: 16px 16px 0 0;
        animation: cd-slide-up-mobile 0.25s ease-out forwards;
    }

    .cd-modal--closing {
        animation: cd-slide-down-mobile 0.25s ease-out forwards;
    }

    @keyframes cd-slide-up-mobile {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    @keyframes cd-slide-down-mobile {
        from {
            opacity: 1;
            transform: translateY(0);
        }
        to {
            opacity: 0;
            transform: translateY(100%);
        }
    }
}
