/*
 * TeleMed SaaS — Searchable Select (Phase 6.1)
 *
 * Solid-color, dependency-free enhancement layered on top of a normal
 * <select>. Respects existing TeleMed tokens (no gradients / glass / neon).
 * Supports light + dark themes and LTR/RTL automatically through the
 * native [dir] attribute on <html>.
 */

.tm-searchable {
    position: relative;
}

.tm-searchable .tm-required {
    color: var(--color-danger);
    margin-inline-start: 2px;
}

.tm-help-text {
    color: var(--color-text-muted);
    font-size: 0.75rem;
}

.tm-searchable--enhanced .tm-searchable__native {
    /*
     * The native select stays in the DOM (kept for old() / form submit /
     * no-JS fallback) but is visually hidden once enhancement runs.
     */
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: none;
    margin: 0;
}

.tm-searchable__control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    font: inherit;
    line-height: 1.2;
    text-align: start;
    min-height: 38px;
    transition: border-color 120ms ease;
}

.tm-searchable__control:hover {
    border-color: var(--color-primary);
}

.tm-searchable__control:focus-visible,
.tm-searchable--open .tm-searchable__control {
    border-color: var(--color-primary);
    outline: 2px solid var(--color-primary-soft);
    outline-offset: 1px;
}

.tm-searchable__value {
    flex: 1 1 auto;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.tm-searchable__value--placeholder {
    color: var(--color-text-muted);
}

.tm-searchable__caret {
    flex: 0 0 auto;
    width: 12px;
    height: 12px;
    border-inline-start: 2px solid var(--color-text-muted);
    border-bottom: 2px solid var(--color-text-muted);
    transform: rotate(-45deg);
    margin-inline-end: 2px;
    transition: transform 120ms ease;
}

.tm-searchable--open .tm-searchable__caret {
    transform: rotate(135deg);
}

.tm-searchable__panel {
    position: absolute;
    inset-inline-start: 0;
    inset-inline-end: 0;
    top: calc(100% + 4px);
    z-index: 50;
    max-height: 280px;
    display: none;
    flex-direction: column;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

.tm-searchable--open .tm-searchable__panel {
    display: flex;
}

.tm-searchable__search {
    width: 100%;
    padding: 0.45rem 0.6rem;
    border: 0;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-soft);
    color: var(--color-text);
    font: inherit;
    outline: none;
}

.tm-searchable__search::placeholder {
    color: var(--color-text-muted);
}

.tm-searchable__list {
    list-style: none;
    margin: 0;
    padding: 0.25rem 0;
    overflow-y: auto;
    max-height: 220px;
}

.tm-searchable__option {
    padding: 0.45rem 0.75rem;
    cursor: pointer;
    color: var(--color-text);
    font-size: 0.875rem;
}

.tm-searchable__option:hover,
.tm-searchable__option--active {
    background: var(--color-hover);
}

.tm-searchable__option--selected {
    background: var(--color-primary-soft);
    color: var(--color-primary-text);
    font-weight: 500;
}

.tm-searchable__option--hidden {
    display: none;
}

.tm-searchable__empty {
    padding: 0.75rem;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

.tm-searchable__clear {
    background: transparent;
    border: 0;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0 0.25rem;
    font-size: 1rem;
    line-height: 1;
}

.tm-searchable__clear:hover {
    color: var(--color-danger);
}

.tm-searchable[disabled] .tm-searchable__control,
.tm-searchable--disabled .tm-searchable__control {
    background: var(--color-surface-soft);
    color: var(--color-text-muted);
    cursor: not-allowed;
}

[dir="rtl"] .tm-searchable__caret {
    /* The chevron is rotation-based — no horizontal flip required. */
}
