/* ── Dropdown Select Component (C3 v3) ──
   All colors via CSS variables from app.css — no hardcoded values.
   Dark mode adapts automatically via variable overrides. */

/* ── Base ── */

.zf-dropdown {
    position: relative;
    cursor: pointer;
    user-select: none;
}

.zf-dropdown:focus {
    outline: none;
}

/* ── Trigger ── */

.zf-dropdown__trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--zf-border);
    border-radius: 10px;
    padding: 10px 14px;
    background: var(--zf-input-bg);
    font-size: 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.zf-dropdown--open .zf-dropdown__trigger {
    border-color: var(--zf-primary);
    box-shadow: 0 0 0 3px var(--zf-primary-light);
}

.zf-dropdown__value {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--zf-text-primary);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.zf-dropdown__value--placeholder {
    color: var(--zf-text-placeholder);
}

/* Flag icon used inside option labels and the selected-value display. */
.zf-dropdown__flag {
    width: 22px;
    height: 16px;
    object-fit: cover;
    border-radius: 2px;
    flex-shrink: 0;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
    vertical-align: middle;
}

.zf-dropdown__code {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--zf-text-secondary, #64748b);
    margin-right: 4px;
}

/* ── Chevron ── */

.zf-dropdown__chevron {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--zf-tenant-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.zf-dropdown--open .zf-dropdown__chevron {
    transform: rotate(180deg);
}

/* ── Clear Button ── */

.zf-dropdown__clear {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--zf-text-muted);
    cursor: pointer;
    padding: 2px;
    flex-shrink: 0;
    transition: color 0.15s ease;
}

.zf-dropdown__clear:hover {
    color: var(--zf-text-primary);
}

/* ── Disabled ── */

.zf-dropdown--disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.zf-dropdown--disabled .zf-dropdown__trigger {
    background: var(--zf-disabled-bg);
}

.zf-dropdown--disabled .zf-dropdown__value {
    color: var(--zf-text-muted);
}

.zf-dropdown--disabled .zf-dropdown__chevron {
    opacity: 0.5;
}

/* ── Error ── */

.zf-dropdown.has-error .zf-dropdown__trigger {
    border-color: var(--zf-error);
}

.zf-error-message {
    display: block;
    font-size: 0.8125rem;
    color: var(--zf-error);
    margin-top: 4px;
}

/* ── Menu ── */

.zf-dropdown__menu {
    display: none;
    flex-direction: column;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    /* Size to content so long option labels and the search box render in
       full, even when the trigger column is narrow. min-width keeps the
       menu at least as wide as the trigger so it always covers it.
       max-width caps the menu at the viewport edge — if content is wider
       than that, it gets clipped (acceptable trade-off vs. overflowing
       off-screen). */
    width: max-content;
    min-width: 100%;
    max-width: calc(100vw - 100px);
    background: var(--zf-card-bg);
    border: 1px solid var(--zf-border);
    border-radius: 12px;
    box-shadow: var(--zf-card-shadow-hover);
    max-height: 400px;
    z-index: 999;
    overflow: hidden;
}

.zf-dropdown--open .zf-dropdown__menu {
    display: flex;
}

/* Flip upward when the trigger sits near the bottom of its scroll/clip container
   (e.g. a field low in a short card inside an overflow:auto content pane). Opening
   downward there would spill the menu past the card and get it clipped. openDropdown
   in dropdown-select.js toggles this class and clamps max-height to the space that
   actually fits, so the menu always renders fully instead of overflowing. */
.zf-dropdown--drop-up .zf-dropdown__menu {
    top: auto;
    bottom: calc(100% + 6px);
}

/* ── Search ── */

.zf-dropdown__search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-bottom: 1px solid var(--zf-border);
    flex-shrink: 0;
    background: var(--zf-card-bg);
}

.zf-dropdown__search-icon {
    color: var(--zf-text-muted);
    flex-shrink: 0;
}

.zf-dropdown__search-input {
    flex: 1;
    padding: 8px 12px;
    background: var(--zf-section-bg);
    border: 1px solid var(--zf-border);
    border-radius: 8px;
    font-size: 13px;
    color: var(--zf-text-primary);
    outline: none;
    font-family: inherit;
}

.zf-dropdown__search-input::placeholder {
    color: var(--zf-text-placeholder);
}

/* ── Options List ── */

.zf-dropdown__options {
    list-style: none;
    margin: 0;
    padding: 4px;
    overflow-y: auto;
    min-height: 0;
    flex: 1;
}

/* ── Option ── */

.zf-dropdown__option {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 14px;
    color: var(--zf-text-primary);
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.zf-dropdown__option:hover,
.zf-dropdown__option--highlighted {
    background: var(--zf-primary-light);
}

.zf-dropdown__option--selected {
    background: var(--zf-primary);
    color: #fff;
}

.zf-dropdown__option--selected:hover,
.zf-dropdown__option--selected.zf-dropdown__option--highlighted {
    background: var(--zf-primary);
    color: #fff;
}

.zf-dropdown__option--disabled {
    color: var(--zf-text-muted);
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.zf-dropdown__option-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* ── Checkmark ── */

.zf-dropdown__check {
    display: none;
    flex-shrink: 0;
    margin-left: 8px;
}

.zf-dropdown__option--selected .zf-dropdown__check {
    display: block;
    color: #fff;
}

/* ── Group Headers ── */

.zf-dropdown__group-header {
    font-size: 12px;
    font-weight: 700;
    color: var(--zf-text-primary);
    letter-spacing: 0.3px;
    padding: 8px 10px;
    list-style: none;
    cursor: default;
}

.zf-dropdown__group-header ~ .zf-dropdown__group-header {
    margin-top: 4px;
}

.zf-dropdown__option--grouped {
    margin-left: 6px;
    padding-left: 22px;
}
