:root {
    --primary: #6a00db;
    --primary-light: #3A5169;
    --accent: #6a00db;
    --accent-light: #8b51ce;
    --surface: #EDEBF0; 
    --surface-hover: #F8F9FA;
    --border: #9b9b9b;
    --text: #47325e;
    --text-secondary: #794ea7;
    --shadow-sm: 0 2px 8px #9b9b9b;
    --shadow-md: 0 4px 16px #9b9b9b;
    --shadow-lg: 0 8px 32px #9b9b9b;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.demo-container {
    max-width: 800px;
    width: 100%;
}

.demo-title {
    font-family: 'Playfair Display', serif;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.5rem;
    text-align: center;
}

.demo-subtitle {
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 2rem;
    font-size: 1.1rem;
}

.demo-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

@media (max-width: 768px) {
    .demo-grid {
        grid-template-columns: 1fr;
    }
}

.demo-section {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.section-title {
    font-family: 'Playfair Display', serif;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 1rem;
}

/* ─── Custom Select Component ──────────────────────────────────────────────── */

.custom-select {
    position: relative;
    width: 100%;
}

/*
 * FACE: contenedor visual del control (placeholder, valor, tags + flecha).
 * Es aria-hidden; toda la semántica vive en el <button> overlay.
 */
.custom-select-face {
    border-radius: 12px;
    padding: 0.75rem 3rem 0.75rem 1.25rem; /* derecha reservada para la flecha */
    min-height: 56px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow  0.3s cubic-bezier(0.4, 0, 0.2, 1),
                transform   0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    position: relative; /* para posicionar la flecha dentro */
}

.custom-select-face:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.custom-select.active .custom-select-face {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(106, 0, 219, 0.1);
}

/* Outline de foco accesible: se activa cuando el botón combobox o los × reciben foco */
.custom-select:focus-within .custom-select-face {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/*
 * TRIGGER: overlay absoluto transparente sobre la face.
 * Recibe el foco, los eventos de teclado y todos los atributos ARIA.
 * En modo multiple con tags activos se desactivan sus pointer-events
 * para que los clicks lleguen a los botones × de los tags.
 */
.custom-select-trigger {
    position: absolute;
    inset: 0;
    background: transparent;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    z-index: 1;
    /* Sin outline propio: el foco se visualiza en .custom-select-face via :focus-within */
    outline: none;
}

/* Cuando hay tags, el trigger no debe capturar clicks sobre ellos */
.custom-select-trigger.has-tags {
    pointer-events: none;
}

/* ─── Placeholder y valor seleccionado ────────────────────────────────────── */

.custom-select-placeholder {
    color: var(--text-secondary);
    font-size: 0.95rem;
    user-select: none;
}

.custom-select-single-value {
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 500;
}

/* ─── Tags (modo multiple) ────────────────────────────────────────────────── */

.custom-select-tag {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
    color: white;
    padding: 0.35rem 0.5rem 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    animation: tagSlideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    z-index: 2; /* sobre el overlay .trigger */
}

@keyframes tagSlideIn {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.custom-select-tag-label {
    pointer-events: none; /* el texto no interfiere con el click del botón × */
}

.custom-select-tag-remove {
    background: rgba(255, 255, 255, 0.3);
    border: none;
    color: white;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    line-height: 1;
    padding: 0;
    transition: background 0.2s, transform 0.2s;
    position: relative;
    z-index: 2;
    flex-shrink: 0;
}

.custom-select-tag-remove:hover {
    background: rgba(255, 255, 255, 0.5);
    transform: rotate(90deg);
}

.custom-select-tag-remove:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* ─── Flecha ──────────────────────────────────────────────────────────────── */

.custom-select-arrow {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%) rotate(0deg);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-secondary);
    pointer-events: none; /* no interfiere con clicks */
}

.custom-select-arrow.open {
    transform: translateY(-50%) rotate(180deg);
}

/* ─── Dropdown ────────────────────────────────────────────────────────────── */

.custom-select-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    overflow: hidden;
}

.dropdown-enter-active,
.dropdown-leave-active {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.dropdown-enter-from,
.dropdown-leave-to {
    opacity: 0;
    transform: translateY(-10px);
}

/* ─── Buscador ────────────────────────────────────────────────────────────── */

.custom-select-search {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}

.custom-select-search input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    background: var(--surface);
    color: var(--text);
}

.custom-select-search input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(106, 0, 219, 0.1);
}

/* ─── Lista de opciones ───────────────────────────────────────────────────── */

/* Resetear estilos de lista (ahora es <ul>) */
.custom-select-options {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
    padding: 0.5rem;
    margin: 0;
}

.custom-select-options::-webkit-scrollbar {
    width: 8px;
}

.custom-select-options::-webkit-scrollbar-track {
    background: transparent;
}

.custom-select-options::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.custom-select-options::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Cada opción es ahora un <li role="option"> */
.custom-select-option {
    padding: 0.875rem 1rem;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: relative;
    list-style: none;
}

.custom-select-option:hover {
    background: var(--surface-hover);
}

.custom-select-option.selected {
    background: rgba(106, 0, 219, 0.08);
}

/* Resaltado de foco por teclado (aria-activedescendant) */
.custom-select-option.focused {
    background: rgba(106, 0, 219, 0.12);
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.custom-select-no-results {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.95rem;
    list-style: none;
}

/* ─── Checkbox (modo multiple) ────────────────────────────────────────────── */

.custom-select-checkbox {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.custom-select-option.selected .custom-select-checkbox {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
    border-color: var(--accent);
}

.custom-select-checkbox::after {
    content: '✓';
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
    opacity: 0;
    transform: scale(0);
    transition: all 0.2s;
}

.custom-select-option.selected .custom-select-checkbox::after {
    opacity: 1;
    transform: scale(1);
}

/* ─── Radio (modo single) ─────────────────────────────────────────────────── */

.custom-select-radio {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    position: relative;
}

.custom-select-option.selected .custom-select-radio {
    border-color: var(--accent);
}

.custom-select-radio::after {
    content: '';
    width: 10px;
    height: 10px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
    border-radius: 50%;
    opacity: 0;
    transform: scale(0);
    transition: all 0.2s;
}

.custom-select-option.selected .custom-select-radio::after {
    opacity: 1;
    transform: scale(1);
}

/* ─── Label de opción ─────────────────────────────────────────────────────── */

.custom-select-option-label {
    flex: 1;
    font-size: 0.95rem;
    color: var(--text);
}

.custom-select-option.selected .custom-select-option-label {
    font-weight: 500;
    color: var(--accent);
}

/* ─── Acciones del dropdown (limpiar) ────────────────────────────────────── */

.custom-select-actions {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    background: var(--surface-hover);
}

.custom-select-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.custom-select-btn-clear {
    background: transparent;
    color: var(--text-secondary);
}

.custom-select-btn-clear:hover {
    background: var(--surface);
    color: var(--text);
}

.custom-select-btn-clear:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.custom-select-btn-select-all {
    background: var(--primary);
    color: white;
}

.custom-select-btn-select-all:hover {
    background: var(--primary-light);
    transform: translateY(-1px);
}

/* ─── Utilidades ──────────────────────────────────────────────────────────── */

.output {
    background: var(--surface-hover);
    padding: 1rem;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
    min-height: 60px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}