/* ============================================================
   ResourceHub — Global Custom Dropdown
   ------------------------------------------------------------
   One reusable dropdown pattern for every "choose one value from a
   short fixed list" control on the site (filters, sort, admin status
   selects) - see static/js/dropdown.js for the behavior. Visually a
   sibling of the existing form-control language (.contribute-input's
   radius/border/focus-ring) for the trigger, and a light card-style
   surface (matching .resource-card's elevation, just smaller) for the
   menu - not a new, unrelated visual language.

   Deliberately NOT used for: searchable/dynamic-option selects
   (contribute.html's topic/type/level pickers already use Tom Select,
   which does that job well) or simple navigation menus (the navbar's
   Admin dropdown and notification bell stay on Bootstrap's dropdown,
   which is already accessible and low-value to rebuild) - see the
   phase report for the full reasoning.
   ============================================================ */

.rh-dropdown {
    position: relative;
    display: inline-block;
    width: 100%;
    max-width: 100%;
}

.rh-dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    width: 100%;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 0.65rem 1rem;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 500;
    color: #1e293b;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.rh-dropdown-trigger:hover {
    border-color: rgba(var(--brand-color-rgb), 0.4);
}

.rh-dropdown-trigger:focus-visible {
    outline: none;
    border-color: var(--brand-color);
    box-shadow: 0 0 0 4px rgba(var(--brand-color-rgb), 0.14);
}

.rh-dropdown.is-open .rh-dropdown-trigger {
    border-color: var(--brand-color);
    box-shadow: 0 0 0 4px rgba(var(--brand-color-rgb), 0.14);
}

.rh-dropdown-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rh-dropdown-trigger[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
}

.rh-dropdown-caret {
    flex-shrink: 0;
    color: #94a3b8;
    font-size: 0.9rem;
    transition: transform 0.2s ease;
}

.rh-dropdown.is-open .rh-dropdown-caret {
    transform: rotate(180deg);
    color: var(--brand-color);
}

/* Sizing modifier - compact filter chips (search/topic filters) vs the
   default full-width form control sizing used in admin panels. */
.rh-dropdown--sm .rh-dropdown-trigger {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    border-radius: 999px;
    width: auto;
}
.rh-dropdown--sm { width: auto; }

/* The menu is `position: fixed` and positioned by JS from the
   trigger's getBoundingClientRect() on open - that's what keeps it
   from being clipped by an `overflow: hidden` card/container ancestor
   (a `position: fixed` element is only ever clipped by an ancestor
   that establishes its own containing block via transform/filter/
   perspective/will-change, which nothing between these triggers and
   <body> does), without resorting to an oversized z-index or DOM
   portal. */
.rh-dropdown-menu {
    position: fixed;
    z-index: 1080;
    min-width: 180px;
    max-height: min(320px, 60vh);
    overflow-y: auto;
    margin: 0;
    padding: 0.4rem;
    list-style: none;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 14px;
    box-shadow: 0 20px 40px -8px rgba(0, 0, 0, 0.16), 0 4px 12px -2px rgba(0, 0, 0, 0.06);
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
    transform-origin: top;
    pointer-events: none;
    transition: opacity 0.16s ease, transform 0.16s ease;
}

.rh-dropdown-menu.drop-up {
    transform-origin: bottom;
}

.rh-dropdown-menu.is-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.rh-dropdown-option {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.55rem 0.7rem;
    border-radius: 9px;
    font-size: 0.86rem;
    color: #334155;
    cursor: pointer;
    scroll-margin-block: 0.4rem;
}

.rh-dropdown-check {
    visibility: hidden;
    flex-shrink: 0;
    color: var(--brand-color);
    font-size: 0.9rem;
}

.rh-dropdown-option.is-selected {
    font-weight: 600;
    color: var(--brand-color);
    background: rgba(var(--brand-color-rgb), 0.07);
}
.rh-dropdown-option.is-selected .rh-dropdown-check {
    visibility: visible;
}

.rh-dropdown-option:hover,
.rh-dropdown-option.is-active {
    background: rgba(var(--brand-color-rgb), 0.1);
}

.rh-dropdown-empty {
    padding: 0.75rem;
    font-size: 0.82rem;
    color: #94a3b8;
    text-align: center;
}

@media (prefers-reduced-motion: reduce) {
    .rh-dropdown-menu,
    .rh-dropdown-caret {
        transition: none !important;
    }
}

/* ---------- Dark mode ---------- */
html.dark-mode body .rh-dropdown-trigger {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.12);
    color: #f1f5f9;
}
html.dark-mode body .rh-dropdown-caret {
    color: #94a3b8;
}
html.dark-mode body .rh-dropdown-menu {
    background: #1a1f24;
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 20px 40px -8px rgba(0, 0, 0, 0.6), 0 4px 12px -2px rgba(0, 0, 0, 0.3);
}
html.dark-mode body .rh-dropdown-option {
    color: #cbd5e1;
}
html.dark-mode body .rh-dropdown-option:hover,
html.dark-mode body .rh-dropdown-option.is-active {
    background: rgba(255, 255, 255, 0.08);
}
html.dark-mode body .rh-dropdown-option.is-selected {
    background: rgba(var(--brand-color-rgb), 0.18);
}
html.dark-mode body .rh-dropdown-empty {
    color: #64748b;
}

/* ---------- Themed native <select> ----------
   For the selects deliberately left native (simple short forms where a
   real <select> is more appropriate - see the phase report) - same
   trigger visual language as .rh-dropdown-trigger above, so a native
   select and a custom one are indistinguishable at rest. */
.rh-select {
    display: block;
    width: 100%;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 0.65rem 2.2rem 0.65rem 1rem;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 500;
    color: #1e293b;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.rh-select:hover {
    border-color: rgba(var(--brand-color-rgb), 0.4);
}
.rh-select:focus-visible {
    outline: none;
    border-color: var(--brand-color);
    box-shadow: 0 0 0 4px rgba(var(--brand-color-rgb), 0.14);
}
html.dark-mode body .rh-select {
    background-color: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.12);
    color: #f1f5f9;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
html.dark-mode body .rh-select option {
    background: #1a1f24;
    color: #f1f5f9;
}
