/**
 * TAGIFY PERSONALIZADO - MOBILE FIRST
 * Optimización UX para selección de tags con categorías
 */

/* ============================================================================================================
   CONTENEDOR PRINCIPAL - Mobile First
   ============================================================================================================ */
.tags-section {
    margin-bottom: 1.5rem;
}

.tags-title {
    font-size: 1rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ============================================================================================================
   FILTROS DE CATEGORÍA - Scroll horizontal en móviles
   ============================================================================================================ */
.btn-group.overflow-auto {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #dee2e6 transparent;
}

.btn-group.overflow-auto::-webkit-scrollbar {
    height: 4px;
}

.btn-group.overflow-auto::-webkit-scrollbar-track {
    background: transparent;
}

.btn-group.overflow-auto::-webkit-scrollbar-thumb {
    background: #dee2e6;
    border-radius: 4px;
}

.btn-group .btn.flex-shrink-0 {
    white-space: nowrap;
}

.btn-group .btn {
    font-size: 0.875rem;
    padding: 0.375rem 0.75rem;
    border-radius: 20px;
    transition: all 0.2s ease;
    font-weight: 500;
}

.btn-group .btn.active {
    font-weight: 600;
}

/* Mobile: scroll horizontal suave */
@media (max-width: 576px) {
    .btn-group .btn {
        font-size: 0.8rem;
        padding: 0.35rem 0.65rem;
        min-height: 36px;
    }
}

/* ============================================================================================================
   TAGIFY INPUT - Optimizado para móvil
   ============================================================================================================ */
.tagify {
    border-radius: 8px;
    border: 2px solid #dee2e6;
    transition: border-color 0.2s ease;
    min-height: 50px; /* Área táctil adecuada para móvil */
    font-size: 1rem;
}

.tagify:hover {
    border-color: #0d6efd;
}

.tagify.tagify--focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.15);
}

/* Input interno */
.tagify__input {
    min-width: 120px;
    padding: 0.5rem;
    font-size: 1rem;
}

.tagify__input::before {
    color: #6c757d;
    opacity: 0.7;
}

/* ============================================================================================================
   TAGS SELECCIONADAS - Pills con bordes de color (SIN RELLENO)
   ============================================================================================================ */
.tagify__tag {
    margin: 0.25rem;
    padding: 0.4rem 0.75rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
    cursor: default;
    min-height: 36px;
    box-shadow: none !important;
    animation: tagify-tag-show 0.2s ease;
    background: transparent !important;
}

.tagify__tag:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1) !important;
    background: rgba(0, 0, 0, 0.02) !important;
}

.tagify__tag::before,
.tagify__tag::after,
.tagify__tag:hover::before,
.tagify__tag:hover::after {
    display: none !important;
}

.tagify__tag > div {
    padding: 0;
    margin: 0;
    line-height: normal;
    border-top: none !important;
    box-shadow: none !important;
}

.tagify__tag > div::before,
.tagify__tag > div::after,
.tagify__tag:hover > div::before,
.tagify__tag:hover > div::after {
    display: none !important;
    box-shadow: none !important;
    border: none !important;
}

/* Colores por categoría - SOLO BORDES */
.tagify__tag--primary {
    background: transparent !important;
    color: #0d6efd !important;
    border: 2px solid #0d6efd !important;
}

.tagify__tag--info {
    background: transparent !important;
    color: #0dcaf0 !important;
    border: 2px solid #0dcaf0 !important;
}

.tagify__tag--secondary {
    background: transparent !important;
    color: #6c757d !important;
    border: 2px solid #6c757d !important;
}

.tagify__tag--success {
    background: transparent !important;
    color: #198754 !important;
    border: 2px solid #198754 !important;
}

.tagify__tag--warning {
    background: transparent !important;
    color: #ffc107 !important;
    border: 2px solid #ffc107 !important;
}

.tagify__tag--danger {
    background: transparent !important;
    color: #dc3545 !important;
    border: 2px solid #dc3545 !important;
}

.tagify__tag--dark {
    background: transparent !important;
    color: #212529 !important;
    border: 2px solid #212529 !important;
}

.tagify__tag--cyan {
    background: transparent !important;
    color: #17a2b8 !important;
    border: 2px solid #17a2b8 !important;
}

.tagify__tag--purple {
    background: transparent !important;
    color: #9b59b6 !important;
    border: 2px solid #9b59b6 !important;
}

.tagify__tag--teal {
    background: transparent !important;
    color: #20c997 !important;
    border: 2px solid #20c997 !important;
}

/* Botón de eliminar tag */
.tagify__tag__removeBtn {
    margin-left: 0.5rem;
    font-size: 1rem;
    opacity: 0.7;
    transition: opacity 0.2s ease;
    min-width: 20px;
    min-height: 20px;
}

.tagify__tag__removeBtn:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.1);
}

/* ============================================================================================================
   DROPDOWN - Optimizado para búsqueda rápida
   ============================================================================================================ */
.tagify__dropdown {
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid #dee2e6;
    z-index: 9999;
    -webkit-overflow-scrolling: touch;
}

/* Cuando el dropdown está dentro del anchor in-flow:
   Override solo POSICIONAMIENTO. No tocar display/opacity/visibility
   para que Tagify gestione show/hide correctamente via transiciones. */
#tagify-dropdown-anchor .tagify__dropdown {
    position: relative !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    width: 100% !important;
    margin-top: 6px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Wrapper: controla altura máxima y scroll dentro del anchor */
#tagify-dropdown-anchor .tagify__dropdown__wrapper {
    max-height: 180px !important;
    overflow-y: auto !important;
}

/* Estado inicial: override translateY(-1em) que no tiene sentido en position:relative.
   Mantener max-height:0 para que la transición de apertura funcione. */
#tagify-dropdown-anchor .tagify__dropdown--initial .tagify__dropdown__wrapper {
    max-height: 0 !important;
    transform: none !important;
}

/* Móvil: dropdown más compacto */
@media (max-width: 576px) {
    #tagify-dropdown-anchor .tagify__dropdown__wrapper {
        max-height: 150px !important;
    }
}

.tagify__dropdown__wrapper {
    background: white;
    border-radius: 8px;
}

/* Items del dropdown - compactos para móvil */
.tagify__dropdown__item {
    padding: 0.5rem 0.85rem;
    font-size: 0.9rem;
    transition: background 0.15s ease;
    min-height: 38px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tagify__dropdown__item:hover,
.tagify__dropdown__item--active {
    background: linear-gradient(90deg, #f8f9fa 0%, #e9ecef 100%);
    cursor: pointer;
}

.tagify__dropdown__item strong {
    color: #212529;
}

.tagify__dropdown__item .text-muted {
    color: #6c757d;
    font-size: 0.85rem;
}

/* ============================================================================================================
   CONTADOR DE TAGS - Badge visual
   ============================================================================================================ */
#contador-tags {
    font-size: 0.95rem;
    padding: 0.5rem 1rem;
    margin-bottom: 0.75rem;
    transition: all 0.2s ease;
}

#contador-tags i {
    margin-right: 0.25rem;
}

/* Helper text animado */
#tags-helper {
    transition: all 0.3s ease;
    display: inline-block;
}

#tags-helper strong {
    color: #0d6efd;
    font-weight: 600;
}

/* ============================================================================================================
   RESPONSIVE - Adaptaciones para diferentes tamaños
   ============================================================================================================ */
@media (max-width: 768px) {
    .tagify__tag {
        font-size: 0.85rem;
        padding: 0.35rem 0.65rem;
    }
    
    .tagify__dropdown__item {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
        min-height: 38px;
    }
}

@media (max-width: 576px) {
    .tags-title {
        font-size: 0.95rem;
    }
    
    .tagify {
        min-height: 45px;
    }
    
    .tagify__tag {
        font-size: 0.8rem;
        padding: 0.3rem 0.6rem;
        margin: 0.2rem;
    }
    
    .tagify__dropdown__item {
        padding: 0.4rem 0.65rem;
        font-size: 0.85rem;
        min-height: 34px;
    }
}

/* ============================================================================================================
   ANIMACIONES Y TRANSICIONES
   ============================================================================================================ */
@keyframes tagify-tag-show {
    0% {
        opacity: 0;
        transform: scale(0.8);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* ============================================================================================================
   ACCESIBILIDAD
   ============================================================================================================ */
.tagify__tag:focus,
.tagify__dropdown__item:focus {
    outline: none;
}

.btn-group .btn:focus {
    outline: none;
    box-shadow: none;
}

/* Alto contraste para mejor legibilidad */
@media (prefers-contrast: high) {
    .tagify {
        border-width: 3px;
    }
    
    .tagify__tag {
        font-weight: 600;
    }
}

/* Modo oscuro */
@media (prefers-color-scheme: dark) {
    .tagify {
        background: #2d2d2d;
        border-color: #444;
        color: #fff;
    }
    
    .tagify__dropdown {
        background: #2d2d2d;
        border-color: #444;
    }
    
    .tagify__dropdown__item {
        color: #fff;
    }
    
    .tagify__dropdown__item:hover {
        background: #444;
    }
}
