/* ==========================================
   Gymdooh Entity Selector Component
   Reusable searchable dropdown for accounts,
   locations, devices, and products.
   ========================================== */

/* ==========================================
   Entity Selector Wrapper
   ========================================== */

.entity-selector {
    position: relative;
    margin-bottom: 25px;
}

/* Standalone mode: gets its own box */
.entity-selector--standalone {
    background: var(--dark-bg-tertiary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 20px;
}

/* Embedded mode: minimal wrapper inside forms */
.entity-selector--embedded {
    background: transparent;
    padding: 0;
}

/* ==========================================
   Label
   ========================================== */

.entity-selector__label {
    display: block;
    font-size: var(--font-size-small, 0.875rem);
    font-weight: 600;
    color: var(--text-secondary, #B0B0B0);
    margin-bottom: 10px;
}

/* ==========================================
   Filter Row (type filter + status filter)
   ========================================== */

.entity-selector__filters {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.entity-selector__filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.entity-selector__filter-group label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted, #707070);
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.entity-selector__filter-select {
    padding: 6px 12px;
    background: var(--dark-bg-secondary, #151515);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: var(--text-primary, #FFFFFF);
    font-size: var(--font-size-small, 0.875rem);
    cursor: pointer;
    min-width: 120px;
}

.entity-selector__filter-select:focus {
    outline: none;
    border-color: var(--primary-color, #5BCBCF);
}

.entity-selector__filter-select option {
    background: var(--dark-bg-secondary, #151515);
    color: var(--text-primary, #FFFFFF);
}

/* ==========================================
   Search Input
   ========================================== */

.entity-selector__search-wrapper {
    position: relative;

    /* One source for the icon's geometry AND the text inset it needs. They used to be
       two hand-tuned numbers (left: 14px / padding-left: 38px) that could drift apart. */
    --es-icon-left: 14px;
    --es-icon-size: 1rem;
    --es-icon-gap: 10px;
}

.entity-selector__search-icon {
    position: absolute;
    left: var(--es-icon-left);
    top: 50%;
    transform: translateY(-50%);
    /* Fixed box: emoji glyphs are wider than their font-size and vary by platform, so
       the inset below cannot be derived from the character itself. */
    width: var(--es-icon-size);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted, #707070);
    font-size: var(--es-icon-size);
    line-height: 1;
    pointer-events: none;
}

.entity-selector__search {
    width: 100%;
    padding: 12px 15px;
    background: var(--dark-bg-secondary, #151515);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text-primary, #FFFFFF);
    font-size: var(--font-size-small, 0.875rem);
    font-family: var(--font-family);
    transition: border-color 0.2s ease;
}

/* Keep the text clear of the magnifier no matter what the page wraps the selector in.
 *
 * This needs the extra class for specificity, not for style: forms.css has
 * `.form-group input { padding: 15px 20px }` at (0,1,1), which outranks a lone
 * `.entity-selector__search` at (0,1,0). Every selector that sits inside a .form-group —
 * the advertisement form, the wizard, the targeting page — therefore lost its 38px inset
 * and drew the selected account's name straight through the icon.
 *
 * Only the inset is pinned here; the vertical padding is left to the surrounding form so
 * the search box keeps the same height as the inputs next to it.
 */
.entity-selector__search-wrapper .entity-selector__search {
    padding-left: calc(var(--es-icon-left) + var(--es-icon-size) + var(--es-icon-gap));
}

.entity-selector__search::placeholder {
    color: var(--text-muted, #707070);
}

.entity-selector__search:focus {
    outline: none;
    border-color: var(--primary-color, #5BCBCF);
}

/* ==========================================
   Dropdown List
   ========================================== */

.entity-selector__dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--dark-bg-tertiary, #1F1F1F);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    margin-top: 4px;
    max-height: 280px;
    overflow-y: auto;
    z-index: 200;
    display: none;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.entity-selector__dropdown.open {
    display: block;
}

/* ==========================================
   Dropdown Items
   ========================================== */

.entity-selector__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.entity-selector__item:last-child {
    border-bottom: none;
}

.entity-selector__item:hover,
.entity-selector__item--focused {
    background: var(--dark-bg-secondary, #151515);
}

.entity-selector__item--selected {
    background: rgba(91, 203, 207, 0.1);
    border-left: 3px solid var(--primary-color, #5BCBCF);
}

.entity-selector__item-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.entity-selector__item-info {
    flex: 1;
    min-width: 0;
}

.entity-selector__item-name {
    font-size: var(--font-size-small, 0.875rem);
    font-weight: 500;
    color: var(--text-primary, #FFFFFF);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.entity-selector__item-meta {
    font-size: 0.75rem;
    color: var(--text-muted, #707070);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.entity-selector__item-badge {
    flex-shrink: 0;
}

/* Type badges (reuse portal badge styles) */
/* The account-type badges in the result list are .type-tag now (css/portal-common.css).
   This file used to style them itself, on a third palette: Operator in the brand cyan and
   Agency in #F59E0B — the exact attention status tone — so on the eight pages carrying this
   search bar, an agency account looked like an account that needed attention. */

/* ==========================================
   Selected Display
   ========================================== */

.entity-selector__selected {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    background: var(--dark-bg-secondary, #151515);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.entity-selector__selected:hover {
    border-color: var(--primary-color, #5BCBCF);
}

.entity-selector__selected-text {
    flex: 1;
    font-size: var(--font-size-small, 0.875rem);
    color: var(--text-primary, #FFFFFF);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.entity-selector__selected-placeholder {
    color: var(--text-muted, #707070);
}

.entity-selector__selected-clear {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: var(--text-muted, #707070);
    border-radius: 50%;
    transition: all 0.2s ease;
    background: transparent;
    border: none;
    cursor: pointer;
}

.entity-selector__selected-clear:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary, #FFFFFF);
}

.entity-selector__chevron {
    flex-shrink: 0;
    font-size: 0.625rem;
    color: var(--text-muted, #707070);
    transition: transform 0.2s ease;
}

.entity-selector__chevron.open {
    transform: rotate(180deg);
}

/* ==========================================
   All Option
   ========================================== */

.entity-selector__item--all {
    font-style: italic;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.entity-selector__item--all .entity-selector__item-name {
    color: var(--text-secondary, #B0B0B0);
}

/* ==========================================
   Loading & Empty States
   ========================================== */

.entity-selector__loading,
.entity-selector__empty {
    padding: 20px 16px;
    text-align: center;
    font-size: var(--font-size-small, 0.875rem);
    color: var(--text-muted, #707070);
}

.entity-selector__loading::before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary-color, #5BCBCF);
    border-radius: 50%;
    animation: entity-selector-spin 0.6s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes entity-selector-spin {
    to { transform: rotate(360deg); }
}

/* ==========================================
   Error Message
   ========================================== */

.entity-selector__error {
    display: none;
    font-size: 0.75rem;
    color: var(--danger-color, #dc3545);
    margin-top: 6px;
}

.entity-selector__error.show {
    display: block;
}

/* ==========================================
   Scrollbar Styling
   ========================================== */

.entity-selector__dropdown::-webkit-scrollbar {
    width: 6px;
}

.entity-selector__dropdown::-webkit-scrollbar-track {
    background: transparent;
}

.entity-selector__dropdown::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.entity-selector__dropdown::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ==========================================
   Responsive
   ========================================== */

@media (max-width: 768px) {
    .entity-selector__filters {
        flex-direction: column;
    }

    .entity-selector__filter-group {
        width: 100%;
    }

    .entity-selector__filter-select {
        flex: 1;
    }
}
