/**
 * Dropdown Component Styles
 *
 * Shared styles for popup/dropdown menus that appear on click.
 * These are NOT for native <select> elements - those keep their carat arrows.
 *
 * DESIGN RULE:
 * - Dropdown menus (popups triggered by buttons): Use accent stroke border, rounded corners
 * - Native <select> elements: Keep browser carat, use standard form styling
 */

/* =======================================================================
   BASE DROPDOWN PANEL
   Popup menus that appear when clicking a trigger button.
   Apply .dropdown-panel as a base class for consistent styling.
   ======================================================================= */

.dropdown-panel {
    position: absolute;
    background: var(--bg-card, #1a1a2e);
    border: 1px solid var(--accent);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 200;
    display: none;
}

.dropdown-panel.open,
.dropdown-panel.active {
    display: block;
}

/* =======================================================================
   DROPDOWN ITEMS
   Menu items inside dropdown panels.
   ======================================================================= */

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    background: transparent;
    border: none;
    color: var(--text, #fff);
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}

.dropdown-item:hover {
    background: rgba(255,255,255,0.08);
}

.dropdown-item:active {
    background: rgba(255,255,255,0.12);
}

.dropdown-item svg {
    color: var(--text-muted, #888);
    flex-shrink: 0;
}

.dropdown-item:not(:last-child) {
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.dropdown-item.active {
    color: var(--accent);
}

.dropdown-item.active svg {
    color: var(--accent);
}

/* First/last item border radius to match panel */
.dropdown-item:first-child {
    border-radius: 7px 7px 0 0;
}

.dropdown-item:last-child {
    border-radius: 0 0 7px 7px;
}

/* =======================================================================
   DROPDOWN CARET
   Optional pointer arrow that connects dropdown to trigger button.
   Add .dropdown-caret-top class to panel and set --caret-right or --caret-left.
   ======================================================================= */

.dropdown-caret-top::before {
    content: '';
    position: absolute;
    top: -5px;
    right: var(--caret-right, 10px);
    left: var(--caret-left, auto);
    width: 8px;
    height: 8px;
    background: var(--bg-card, #1a1a2e);
    border-left: 1px solid var(--accent);
    border-top: 1px solid var(--accent);
    rotate: 45deg;
}

/* =======================================================================
   ADAPTIVE DROPDOWNS
   Desktop/mouse: custom dropdown panels for better styling
   Touch devices: native <select> for better UX (OS picker, touch-friendly)

   Detection uses pointer/hover media queries, not screen size.
   This means a tablet in landscape still gets native selects.

   Usage:
   1. Wrap both in a container with .adaptive-dropdown
   2. Add .adaptive-dropdown-custom to your custom trigger/panel wrapper
   3. Add .adaptive-dropdown-native to your native <select>

   Example:
   <div class="adaptive-dropdown">
     <div class="adaptive-dropdown-custom">
       <button class="dropdown-trigger">Pick option</button>
       <div class="dropdown-panel">...</div>
     </div>
     <select class="adaptive-dropdown-native">...</select>
   </div>
   ======================================================================= */

/* Desktop: show custom, hide native */
.adaptive-dropdown-native {
    display: none;
}

.adaptive-dropdown-custom {
    display: block;
}

/* Adaptive dropdown wrapper */
.adaptive-dropdown {
    position: relative;
    display: inline-block;
}

/* Adaptive dropdown trigger button (desktop) */
.adaptive-dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-dark);
    color: var(--text);
    font-size: 0.95rem;
    cursor: pointer;
    transition: border-color 0.15s;
}

.adaptive-dropdown-trigger:hover {
    border-color: var(--text-muted);
}

.adaptive-dropdown-trigger:focus {
    outline: none;
    border-color: var(--accent);
}

.adaptive-dropdown-trigger.open {
    border-color: var(--accent);
}

.adaptive-dropdown-value {
    flex: 1;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.adaptive-dropdown-chevron {
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform 0.15s;
}

.adaptive-dropdown-trigger.open .adaptive-dropdown-chevron {
    transform: rotate(180deg);
}

/* Adaptive dropdown panel - hidden by default, shown on open */
.adaptive-dropdown-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 100%;
    max-height: 280px;
    overflow-y: auto;
    display: none !important;
    flex-direction: column;
    background: var(--bg-card, #1a1a2e);
    border: 1px solid var(--accent);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 200;
}

.adaptive-dropdown-panel.open {
    display: flex !important;
}

/* Ensure items stack vertically */
.adaptive-dropdown-panel .dropdown-item {
    display: block;
    width: 100%;
    flex-shrink: 0;
}

/* Touch devices: show native, hide custom */
/* pointer: coarse = touch input, hover: none = no mouse hover */
@media (pointer: coarse) and (hover: none) {
    .adaptive-dropdown-native {
        display: block;
        width: 100%;
        padding: 12px 36px 12px 12px;
        border: 1px solid var(--border);
        border-radius: 6px;
        background-color: var(--bg-dark);
        color: var(--text);
        font-size: 16px; /* Prevent iOS zoom */
        appearance: auto; /* Keep native carat arrow */
        -webkit-appearance: menulist;
    }

    .adaptive-dropdown-native:focus {
        outline: none;
        border-color: var(--accent);
    }

    .adaptive-dropdown-custom {
        display: none;
    }
}
