/**
 * 3Syxty Studio — Select Component
 *
 * Native select styling and custom dropdown select with search,
 * grouping, multi-select, and beautiful option rendering.
 */

/* -----------------------------------------------------------------------
   Native Select (enhanced)
   ----------------------------------------------------------------------- */

.select {
    width: 100%;
    height: var(--input-height-md);
    padding: 0 calc(var(--space-3) + 20px) 0 var(--space-3);
    font: var(--type-body);
    color: var(--text-primary);
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius-md);
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m3 4.5 3 3 3-3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    transition: border-color var(--motion-instant),
                box-shadow var(--motion-instant);
}

.select:hover:not(:disabled) {
    border-color: var(--border-default);
}

.select:focus {
    border-color: var(--input-border-focus);
    box-shadow: 0 0 0 3px var(--input-ring);
}

.select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.select-sm {
    height: var(--input-height-sm);
    padding: 0 calc(var(--space-2-5) + 18px) 0 var(--space-2-5);
    font-size: 12px;
    border-radius: var(--radius-sm);
}

.select-lg {
    height: var(--input-height-lg);
    padding: 0 calc(var(--space-4) + 22px) 0 var(--space-4);
    font-size: 15px;
    border-radius: var(--radius-lg);
}

/* -----------------------------------------------------------------------
   Custom Dropdown (Alpine.js powered)
   ----------------------------------------------------------------------- */

.select-dropdown {
    position: relative;
    display: inline-flex;
    width: 100%;
}

.select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: var(--input-height-md);
    padding: 0 var(--space-3);
    font: var(--type-body);
    color: var(--text-primary);
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: border-color var(--motion-instant),
                box-shadow var(--motion-instant);
}

.select-trigger:hover {
    border-color: var(--border-default);
}

.select-trigger[aria-expanded="true"] {
    border-color: var(--input-border-focus);
    box-shadow: 0 0 0 3px var(--input-ring);
}

.select-trigger-placeholder {
    color: var(--text-muted);
}

.select-trigger-chevron {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    transition: transform var(--motion-fast);
    flex-shrink: 0;
    margin-left: var(--space-2);
}

.select-trigger[aria-expanded="true"] .select-trigger-chevron {
    transform: rotate(180deg);
}

/* Dropdown Panel */
.select-panel {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: var(--space-1);
    background-color: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-heavy);
    z-index: var(--z-dropdown);
    overflow: hidden;
    animation: scale-in var(--motion-fast) forwards;
    transform-origin: top center;
}

/* Search within dropdown */
.select-search {
    padding: var(--space-2);
    border-bottom: 1px solid var(--border-subtle);
}

.select-search .input {
    height: var(--input-height-sm);
    font-size: 13px;
}

/* Options list */
.select-options {
    max-height: 240px;
    overflow-y: auto;
    padding: var(--space-1);
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.select-option {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    font: var(--type-body);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color var(--motion-instant);
}

.select-option:hover,
.select-option[data-highlighted="true"] {
    background-color: var(--accent-primary-subtle);
}

.select-option[aria-selected="true"] {
    color: var(--accent-primary);
    font-weight: 500;
}

.select-option[aria-selected="true"]::after {
    content: '';
    margin-left: auto;
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236C5CE7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 8 3 3 5-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    flex-shrink: 0;
}

.select-option:disabled,
.select-option[aria-disabled="true"] {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* Option description */
.select-option-desc {
    font: var(--type-caption);
    color: var(--text-muted);
    margin-top: 1px;
}

/* Group label */
.select-group-label {
    padding: var(--space-2) var(--space-3) var(--space-1);
    font: var(--type-overline);
    color: var(--text-muted);
}

/* Empty state */
.select-empty {
    padding: var(--space-4) var(--space-3);
    text-align: center;
    font: var(--type-body-sm);
    color: var(--text-muted);
}

/* Multi-select tags */
.select-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    flex: 1;
    min-height: 24px;
    align-items: center;
}

.select-tag {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px var(--space-2);
    font: var(--type-caption);
    color: var(--accent-primary);
    background-color: var(--accent-primary-subtle);
    border-radius: var(--radius-full);
    max-width: 150px;
}

.select-tag-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.select-tag-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color var(--motion-instant);
}

.select-tag-remove:hover {
    background-color: var(--accent-primary-muted);
}

.select-tag-remove svg {
    width: 10px;
    height: 10px;
}
