/* =========================================================================
   ESTILOS PARA FILTROS INCRUSTADOS EN CABECERA DE TABLA
   ========================================================================= */

.th-content-stack {
    display: flex;
    flex-direction: column;
    /* Alineación vertical: empujar el text label al fondo */
    justify-content: flex-end;
    align-items: flex-start;
    gap: 6px;
    padding-bottom: 2px;
    height: 100%;
    /* Altura mínima para asegurar que los labels del TH sin filtro (ej: Pieza)
       se alineen horizontalmente con los que SÍ tienen filtro (ej: Autor).
       50-52px es aprox la altura de (Input 30px + Gap 6px + Label 15px).
    */
    min-height: 56px;
    overflow: visible !important;
    width: 100%;
    min-width: 0;
}

.th-sort-label {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.88rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-encabezado-tabla, var(--color-texto));
    display: inline-flex;
    align-items: center;
    gap: 4px;
    user-select: none;
    transition: color 0.2s;
    white-space: nowrap;

    /* Espaciado superior para separarse bien del input */
    margin-top: auto;
}

.th-sort-label:hover {
    opacity: 0.95;
    text-decoration: underline;
    text-underline-offset: 0.18em;
}

/* Indicadores de orden */
.th-sort-label::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    opacity: 0.3;
    margin-left: 2px;
}

.th-sort-label.sort-asc::after {
    border-bottom: 5px solid currentColor;
    opacity: 1;
}

.th-sort-label.sort-desc::after {
    border-top: 5px solid currentColor;
    opacity: 1;
}

/* Wrapper del filtro dentro del TH */
.th-filter-wrapper {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    /* Dejar que el TH controle el ancho mínimo */
    /* Empujar hacia arriba */
    position: relative;
    margin-bottom: auto;
    margin-top: 2px;
}

/* Columnas angostas (AÑO): alinear y permitir encoger */
.year-col .th-filter-wrapper {
    min-width: 0;
    width: 100%;
    margin: 0;
}

.year-col .th-content-stack {
    align-items: flex-start !important;
    justify-content: flex-end;
    text-align: left;
    overflow: visible;
    min-width: 100%;
}

/* Modificación para input con botón de borrado */
select.in-table-header {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    /* Asegurar que el borde/focus ring no se corte */
    box-sizing: border-box;
    display: block;
    /* ... (resto de propiedades) ... */
    height: 28px;
    /* Altura más compacta y refinada */
    padding: 0 36px 0 10px;
    /* Reducimos padding para ahorrar espacio */
    font-size: 0.8rem;
    line-height: normal;

    border-radius: 999px;
    /* Píldora compacta */
    border: 1px solid var(--color-borde);
    background-color: rgba(255, 255, 255, 0.03);
    /* Fondo muy sutil */
    color: var(--color-texto);

    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23a3a3a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center !important;
    background-size: 10px;

    /* Centrado óptico de texto para inputs cortos */
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;

    cursor: pointer;
    transition: all 0.2s ease;
}

/* Cuando el filtro está vacío, el texto se ve más tenue */
select.in-table-header.filter-empty {
    color: var(--color-texto-muy-suave);
}

/* BOTÓN DE LIMPIAR FILTRO (Cruz) - Posicionado estratégicamente */
.filter-clear-btn {
    position: absolute;
    right: 24px;
    /* A la izquierda del icono de flecha, que está a ~6-8px */
    top: 50%;
    transform: translateY(-50%);
    /* Centrado vertical perfecto */

    background: transparent;
    border: none;
    color: var(--color-texto-suave);
    /* Discreto por defecto */

    width: 20px;
    height: 20px;
    border-radius: 50%;
    /* Circular para mejor área de clic */

    display: none;
    /* Se controla vía JS */
    align-items: center;
    justify-content: center;

    font-size: 16px;
    /* Tamaño de la cruz */
    line-height: 1;
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
    padding: 0;
    transition: all 0.2s ease;
}

.filter-clear-btn:hover {
    color: var(--color-error);
    /* Rojo suave al pasar el mouse para indicar "borrar" */
    background: rgba(255, 255, 255, 0.1);
    /* Fondo sutil al hover */
}

/* Columna de año: input simple, alineado a la izquierda */
.year-col select.in-table-header {
    width: 100%;
    padding-right: 12px !important;
    padding-left: 2px;
    font-size: 0.78rem;
    text-align: left;
    text-align-last: left;
}

/* Botón de limpiar invisible en columna de año para ahorrar espacio (opcional, o hacerlo minúsculo) */
.year-col .filter-clear-btn {
    right: 14px;
    /* Más pegado */
    width: 16px;
    height: 16px;
    font-size: 14px;
    display: none !important;
    /* Ocultar por defecto para ahorrar espacio, el usuario puede re-seleccionar "Todo" */
}

/* Ajuste cuando el filtro está activo (fondo dorado oscuro) -> asegurar contraste de la cruz */
select.filter-active-state~.filter-clear-btn {
    color: rgba(255, 255, 255, 0.8);
}

select.filter-active-state~.filter-clear-btn:hover {
    color: var(--color-texto);
    background: rgba(255, 255, 255, 0.2);
}

select.in-table-header:focus {
    outline: none;
    border-color: var(--color-marca);
    box-shadow: 0 0 0 2px rgba(var(--color-marca-rgb), 0.20);
    background-color: var(--color-superficie-3);
}

select.in-table-header:hover {
    border-color: var(--color-texto-suave);
    background-color: var(--color-superficie-3);
}

/* =========================================================================
   ESTADO ACTIVO: SEÑAL VISUAL DE FILTRO APLICADO
   Permite al usuario identificar rápidamente qué columnas están filtrando.
   ========================================================================= */
select.filter-active-state {
    /* Borde dorado de la marca para indicar actividad */
    border-color: var(--color-marca) !important;

    /* Fondo sutilmente teñido pero SÓLIDO para evitar problemas de renderizado en listas desplegables */
    /* Usamos un color oscuro con tinte dorado pre-calculado para que sea opaco */
    background-color: rgba(var(--color-marca-rgb), 0.10) !important;
    /* Mezcla aproximada de superficie oscura + dorado */

    /* Texto más brillante */
    color: var(--color-texto) !important;
    font-weight: 600;

    /* Sombra interna suave para profundidad */
    box-shadow: inset 0 0 0 1px rgba(var(--color-marca-rgb), 0.22);
}

select.filter-active-state:hover {
    background-color: rgba(var(--color-marca-rgb), 0.14) !important;
    border-color: rgba(var(--color-marca-rgb), 0.85) !important;
}

/*
   IMPORTANTE: Forzar estilo de las opciones (el menú desplegable)
   para que no hereden el color/fondo del select activo y se vuelvan ilegibles o blancas.
 */
select.in-table-header option {
    background-color: var(--color-superficie);
    color: var(--color-texto);
    font-weight: normal;
    /* Restaurar peso normal en las opciones */
}

/* Ocultar definitivamente los chips/badges de filtros antiguos por UX */
#active-filters {
    display: none !important;
}

/* Estilo específico para el select cuando está en HEADER (Consolidado Píldora) */
select.filter-select-compact.in-table-header {
    width: 100%;
    max-width: 100%;
    height: 30px;
    /* Altura óptima para header */
    padding: 0 28px 0 10px;
    /* Espacio para flecha/cruz */
    font-size: 0.8rem;
    border-radius: 999px;
    /* Píldora */
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--color-borde);
    color: var(--color-texto);
    transition: all 0.2s ease;
}

select.filter-select-compact.in-table-header.filter-empty {
    color: var(--color-texto-muy-suave);
    opacity: 0.7;
}

select.filter-select-compact.in-table-header:focus {
    border-color: var(--color-marca);
    background-color: var(--color-superficie-2);
    box-shadow: 0 0 0 2px rgba(var(--color-marca-rgb), 0.15);
}

select.filter-select-compact.in-table-header:hover {
    border-color: var(--color-texto-suave);
    background-color: rgba(255, 255, 255, 0.06);
}

/* Ajustes de responsive para tabla con filtros */
@media (max-width: 768px) {

    /* En móvil, volver a un layout más simple o permitir scroll horizontal */
    .th-filter-wrapper {
        min-width: 100px;
    }

    select.filter-select-compact.in-table-header,
    select.in-table-header {
        height: 40px;
        font-size: 0.9rem;
        border-radius: 8px;
        padding: 0 10px;
    }

    .th-content-stack {
        gap: 8px;
        min-height: 60px;
    }
}