/**
 * MDH Sitewide Soft-Clay Popover Select (Desktop Popover + Mobile Bottom Sheet)
 *
 * Matches the Fatwa Compilation Hub Soft-Clay Popover design language sitewide
 * and automatically upgrades native <select> elements on MDH front-end pages.
 */

.mdh-ss-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
    pointer-events: none !important;
    opacity: 0 !important;
}

.mdh-ss-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-width: 0;
    max-width: 100%;
    vertical-align: middle;
}

.mdh-ss-wrap.is-block {
    display: flex;
    width: 100%;
}

.mdh-ss-trigger {
    width: 100%;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.55rem;
    padding: 0.5rem 0.85rem;
    border-radius: 14px;
    border: 1px solid rgba(42, 50, 46, 0.14);
    background: rgba(255, 255, 255, 0.88);
    color: #1F2B25;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.3;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 2px 6px -2px rgba(24, 42, 34, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.9);
    transition: border-color 0.16s ease, background-color 0.16s ease, box-shadow 0.16s ease;
    -webkit-tap-highlight-color: transparent;
}

.mdh-ss-wrap.is-compact .mdh-ss-trigger {
    min-height: 34px;
    padding: 0.34rem 0.72rem;
    border-radius: 11px;
    font-size: 0.78rem;
}

.mdh-ss-trigger:hover:not(:disabled) {
    border-color: rgba(61, 122, 98, 0.45);
    background: #FFFFFF;
}

.mdh-ss-wrap.is-open .mdh-ss-trigger,
.mdh-ss-trigger:focus-visible {
    outline: none;
    border-color: #3D7A62;
    background: #FFFFFF;
    box-shadow: 0 0 0 3px rgba(91, 140, 122, 0.16);
}

.mdh-ss-trigger:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    background: rgba(235, 241, 238, 0.7);
}

.mdh-ss-value {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mdh-ss-caret {
    flex-shrink: 0;
    width: 12px;
    height: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #4A5851;
    transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.mdh-ss-wrap.is-open .mdh-ss-caret {
    transform: rotate(180deg);
    color: #2D6A4F;
}

/* Shared Body-Portal Popover */
.mdh-ss-portal {
    position: fixed;
    inset: 0;
    z-index: 100050;
    pointer-events: none;
    display: none;
}

.mdh-ss-portal.is-open {
    display: block;
    pointer-events: auto;
}

.mdh-ss-backdrop {
    position: fixed;
    inset: 0;
    background: transparent;
}

.mdh-ss-popover {
    position: fixed;
    display: flex;
    flex-direction: column;
    max-height: 360px;
    border-radius: 18px;
    background: rgba(250, 252, 250, 0.98);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(91, 140, 122, 0.24);
    box-shadow: 0 20px 44px -12px rgba(20, 38, 31, 0.22), 0 6px 16px -4px rgba(20, 38, 31, 0.08), inset 0 1px 0 #FFFFFF;
    overflow: hidden;
    font-family: 'Plus Jakarta Sans', 'Google Sans', 'Noto Sans Arabic', -apple-system, BlinkMacSystemFont, sans-serif;
    animation: mdhSsPopIn 0.15s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes mdhSsPopIn {
    from {
        opacity: 0;
        transform: translateY(-6px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.mdh-ss-head {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.05rem 0.6rem;
    border-bottom: 1px solid rgba(42, 50, 46, 0.08);
    position: relative;
}

.mdh-ss-head::before {
    content: '';
    position: absolute;
    top: 7px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 9999px;
    background: rgba(42, 50, 46, 0.16);
}

.mdh-ss-head-title {
    font-size: 0.86rem;
    font-weight: 800;
    color: #1C2722;
    margin-top: 0.35rem;
}

.mdh-ss-head-close {
    width: 32px;
    height: 32px;
    margin-top: 0.35rem;
    border-radius: 9999px;
    border: 0;
    background: rgba(42, 50, 46, 0.08);
    color: #2C3933;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.mdh-ss-search-wrap {
    display: none;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid rgba(42, 50, 46, 0.08);
    background: rgba(236, 244, 239, 0.6);
}

.mdh-ss-search-wrap.is-visible {
    display: flex;
}

.mdh-ss-search-ico {
    color: #537B6B;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.mdh-ss-search-input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    color: #1D2823;
    padding: 0.1rem 0;
}

.mdh-ss-search-input::placeholder {
    color: #798981;
}

.mdh-ss-list {
    overflow-y: auto;
    padding: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.14rem;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.mdh-ss-group-label {
    padding: 0.45rem 0.7rem 0.25rem;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #5C7267;
    background: rgba(242, 248, 244, 0.92);
    border-radius: 10px;
    margin-top: 0.2rem;
}

.mdh-ss-option {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
    padding: 0.52rem 0.75rem;
    border-radius: 12px;
    border: 0;
    background: transparent;
    color: #2A3731;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.13s ease, color 0.13s ease;
}

.mdh-ss-option:hover:not(:disabled),
.mdh-ss-option.is-focused:not(:disabled) {
    background: rgba(91, 140, 122, 0.12);
    color: #162B22;
}

.mdh-ss-option.is-active {
    background: linear-gradient(135deg, #4E7D6B 0%, #3A6454 100%);
    color: #FFFFFF;
    font-weight: 700;
    box-shadow: 0 4px 12px -4px rgba(36, 74, 59, 0.35);
}

.mdh-ss-option.is-active:hover,
.mdh-ss-option.is-active.is-focused {
    background: linear-gradient(135deg, #457260 0%, #315748 100%);
    color: #FFFFFF;
}

.mdh-ss-option:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.mdh-ss-opt-text {
    flex: 1 1 auto;
    min-width: 0;
    word-break: break-word;
}

.mdh-ss-opt-check {
    flex-shrink: 0;
    width: 15px;
    height: 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
}

.mdh-ss-option.is-active .mdh-ss-opt-check {
    opacity: 1;
    color: #C7EFE0;
}

.mdh-ss-empty {
    padding: 1rem 0.75rem;
    text-align: center;
    font-size: 0.78rem;
    color: #6B7B73;
}

/* Native-App Mobile Bottom Sheet (< 768px) */
@media (max-width: 767px) {
    .mdh-ss-backdrop {
        background: rgba(18, 28, 24, 0.42);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }

    .mdh-ss-popover {
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        bottom: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 74vh;
        border-radius: 24px 24px 0 0;
        padding-bottom: env(safe-area-inset-bottom, 0.5rem);
        animation: mdhSsSheetUp 0.2s cubic-bezier(0.22, 1, 0.36, 1);
    }

    .mdh-ss-head {
        display: flex;
    }

    .mdh-ss-option {
        min-height: 44px;
        padding: 0.65rem 0.9rem;
        font-size: 0.86rem;
    }

    @keyframes mdhSsSheetUp {
        from {
            opacity: 0.5;
            transform: translateY(48px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
}
