/* Sidebar - barra lateral de filtros */
/*  esto es el panel de la izquierda donde puedes filtrar por tags, NSFW, etc */

/* Sidebar en desktop - ocupa 300px de ancho fijo */
/* flex-direction: column apila los filtros verticalmente */
.sidebar {
    width: 300px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: #1a1a1a;
    border-radius: 12px;
    padding: 20px;
}

.filter-box {
    background: #252525;
    border-radius: 20px;
    padding: 20px;
}

/* Toggle NSFW personalizado - un interruptor hecho con CSS puro */
.nsfw-toggle {
    margin: 15px 0;
}

.nsfw-toggle label {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    user-select: none;
}

/* Checkbox personalizado estilizado como un interruptor */
/* appearance: none elimina el estilo nativo del checkbox */
.nsfw-toggle input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 50px;
    height: 28px;
    background: #4CAF50;
    border-radius: 14px;
    border: none;
    cursor: pointer;
    position: relative;
    transition: background-color 0.3s ease;
    outline: none;
}

/* La bolita blanca del interruptor - pseudo-elemento ::before */
.nsfw-toggle input[type="checkbox"]::before {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: white;
    top: 2px;
    left: 2px;
    transition: left 0.3s ease;
}

/* Cuando esta activado, el fondo cambia a rojo */
.nsfw-toggle input[type="checkbox"]:checked {
    background: #f44336;
}

/* Y la bolita se mueve a la derecha */
.nsfw-toggle input[type="checkbox"]:checked::before {
    left: 24px;
}

.nsfw-toggle span {
    font-weight: 500;
    font-size: 14px;
    min-width: 60px;
}

/* Lista de tags en formato flex con wrap */
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

/* Boton de tag individual con borde y transicion */
.tag-btn {
    display: inline-block;
    background: #1a1a1a;
    color: #f0f0f0;
    border: 2px solid #414141;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
    flex: 0 0 auto;
}

.tag-btn:hover {
    border-color: #f0f0f0;
    background: #252525;
}

/* Tag activo (seleccionado) - fondo blanco, texto negro */
.tag-btn[data-active="true"] {
    background: #ffffff;
    color: #000000;
    border-color: #ffffff;
}

.tag-btn[data-active="true"]:hover {
    background: #f0f0f0;
    border-color: #f0f0f0;
}

/* Modal de filtros para movil - cubre toda la pantalla */
#filtersModal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 24px;
}

#filtersModal.active {
    display: flex;
}

/* Contenido del modal - usa min/max-width para adaptarse */
.filters-content {
    position: relative;
    width: min(560px, 42vw);
    min-width: min(320px, 92vw);
    max-width: min(94vw, 560px);
    max-height: min(78vh, 760px);
    background: #111;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}

#filtersModal .sidebar {
    max-height: calc(78vh - 24px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

/* Boton de cerrar el modal en posicion absoluta */
#closeFilters {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

/* Cuando el sidebar esta dentro del modal, ocupa todo el ancho */
#filtersModal .sidebar {
    position: relative;
    right: auto;
    top: auto;
    width: 100%;
    max-height: min(78vh, 760px);
    overflow-y: auto;
    background: transparent;
    transform: none;
    transition: none;
    border-radius: 0;
    padding: 22px 22px 28px;
}

/* Secciones plegables dentro de los filtros */
.filter-section {
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    padding-bottom: 10px;
    margin-bottom: 12px;
}

.filter-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

/* Boton para expandir/colapsar seccion */
.section-toggle {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: transparent;
    color: inherit;
    border: none;
    padding: 8px 0;
    font-size: 16px;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}

.section-arrow {
    font-size: 16px;
    transition: transform 0.2s ease;
}

/* Contenido de seccion oculto por defecto */
.filters-content .section-content {
    display: none;
    padding-top: 6px;
}

.filters-content .section-content.is-open {
    display: block;
}

/* Flecha rotada segun el estado expandido/colapsado */
.section-toggle[aria-expanded="true"] .section-arrow {
    transform: rotate(0deg);
}

.section-toggle[aria-expanded="false"] .section-arrow {
    transform: rotate(-90deg);
}

/* Repetido para el sidebar de escritorio */
.filter-section .section-content {
    display: none;
    padding-top: 6px;
}

.filter-section .section-content.is-open {
    display: block;
}

.section-toggle[aria-expanded="true"] .section-arrow,
.filter-section .section-toggle[aria-expanded="true"] .section-arrow {
    transform: rotate(0deg);
}

.section-toggle[aria-expanded="false"] .section-arrow,
.filter-section .section-toggle[aria-expanded="false"] .section-arrow {
    transform: rotate(-90deg);
}

/* Desktop - el layout usa flexbox para poner sidebar al lado del contenido */
@media (min-width: 901px) {
    .layout {
        display: flex;
        gap: 20px;
    }

    .sidebar {
        display: flex;
    }
}

/* Movil - la sidebar se oculta y solo se accede via modal */
/*  aca es donde se rompe porque en pantallas chicas no hay espacio para la sidebar fija */
@media (max-width: 900px),
(max-device-width: 900px) {
    .layout {
        flex-direction: column;
        display: block;
    }

    .layout>.sidebar {
        display: none;
    }

    .content {
        width: 100%;
    }

    #filtersModal .sidebar {
        width: 100%;
    }

    .sidebar h3,
    .sidebar h4 {
        font-size: 18px;
        margin-bottom: 12px;
    }

    .sidebar {
        padding: 24px;
        gap: 18px;
    }

    .tag-list {
        gap: 12px;
    }

    .tag-btn {
        padding: 12px 18px;
        font-size: 16px;
        min-width: 32%;
        border-radius: 24px;
    }

    .nsfw-toggle {
        margin: 20px 0;
    }

    .nsfw-toggle label {
        gap: 14px;
    }

    .nsfw-toggle span {
        font-size: 16px;
    }

    .nsfw-toggle input[type="checkbox"] {
        width: 56px;
        height: 32px;
    }

    .nsfw-toggle input[type="checkbox"]::before {
        width: 28px;
        height: 28px;
        top: 2px;
        left: 2px;
    }

    .nsfw-toggle input[type="checkbox"]:checked::before {
        left: 26px;
    }
}

/* Estilos para cuando JS agrega body.mobile */
body.mobile .layout>.sidebar {
    display: none;
}

body.mobile #filtersBtn {
    display: block;
}

body.mobile .content {
    width: 100%;
}

body.mobile #filtersModal .sidebar {
    width: 100%;
}

body.mobile .sidebar {
    padding: 26px;
    gap: 20px;
}

body.mobile .sidebar h3,
body.mobile .sidebar h4 {
    font-size: 19px;
}

body.mobile .tag-btn {
    padding: 14px 20px;
    font-size: 17px;
    min-width: 36%;
}

body.mobile .nsfw-toggle span {
    font-size: 17px;
}

body.mobile .nsfw-toggle input[type="checkbox"] {
    width: 60px;
    height: 34px;
}

body.mobile .nsfw-toggle input[type="checkbox"]::before {
    width: 30px;
    height: 30px;
    top: 2px;
    left: 2px;
}

body.mobile .nsfw-toggle input[type="checkbox"]:checked::before {
    left: 28px;
}
