/* ============================================================================
   subcat-modal.css
   Modal visual de subcategorías (cuadrícula de iconos). Sigue el mismo lenguaje
   del bottom-sheet de filtros: hoja inferior en móvil, tarjeta centrada en
   escritorio, handle, overlay difuminado y estado seleccionado oscuro.
   ========================================================================== */

/* ── Overlay ───────────────────────────────────────────────────────────── */
.subcat-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 100020;
    /* por encima del sheet de filtros (10010) */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0s linear 0.35s;
}

.subcat-modal-overlay.is-open {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.35s ease, visibility 0s linear 0s;
}

/* ── Contenedor del modal (hoja inferior en móvil por defecto) ─────────── */
.subcat-modal {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100021;
    background: var(--bg-card, #fff);
    border-radius: 24px 24px 0 0;
    padding: 40px 18px calc(20px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
    max-height: 82dvh;
    overflow-y: auto;
    scrollbar-width: none;
    transform: translateY(105%);
    transition: transform 0.45s cubic-bezier(0.32, 0.72, 0, 1);
    will-change: transform;
    visibility: hidden;
    overscroll-behavior: contain;
}

.subcat-modal::-webkit-scrollbar {
    display: none;
}

.subcat-modal.is-open {
    transform: translateY(0);
    visibility: visible;
}

/* Grab handle */
.subcat-modal::before {
    content: '';
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: #e5e7eb;
    border-radius: 10px;
}

[data-theme="dark"] .subcat-modal::before {
    background: rgba(255, 255, 255, 0.2);
}

/* ── Cabecera ──────────────────────────────────────────────────────────── */
.subcat-modal-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    padding: 0 4px;
}

.subcat-modal-title {
    font-family: var(--font, 'Poppins', sans-serif);
    font-size: 18px;
    font-weight: 700;
    color: var(--text-main);
    margin: 0;
}

.subcat-parent-chip {
    font-family: var(--font, 'Poppins', sans-serif);
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    background: var(--text-main, #202322);
    padding: 4px 12px;
    border-radius: 999px;
    line-height: 1.4;
}

[data-theme="dark"] .subcat-parent-chip {
    background: #f0f0f0;
    color: #141414;
}

.subcat-modal-close {
    position: absolute;
    top: 22px;
    right: 16px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-main);
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease;
}

.subcat-modal-close svg {
    width: 20px;
    height: 20px;
}

.subcat-modal-close:active {
    transform: scale(0.9);
}

/* ── Cuadrícula de iconos ──────────────────────────────────────────────── */
.subcat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.subcat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 16px 8px;
    min-height: 96px;
    border: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.08));
    border-radius: 16px;
    background: var(--bg-card, #fff);
    color: var(--text-main);
    font-family: var(--font, 'Poppins', sans-serif);
    cursor: pointer;
    text-align: center;
    transition: transform 0.15s ease, border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.subcat-card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    color: var(--text-main);
}

.subcat-card-icon svg {
    width: 100%;
    height: 100%;
}

.subcat-card-svg {
    width: 100%;
    height: 100%;
    display: block;
    fill: currentColor;
}

.subcat-card-label {
    font-size: 12px;
    font-weight: 500;
    line-height: 1.25;
    color: var(--text-main);
    word-break: break-word;
}

.subcat-card:active {
    transform: scale(0.96);
}

@media (hover: hover) {
    .subcat-card:hover {
        border-color: var(--text-main, #202322);
    }
}

/* Estado seleccionado → oscuro (mismo lenguaje que el pill de categoría) */
.subcat-card.is-selected {
    background: var(--text-main, #202322);
    border-color: var(--text-main, #202322);
    color: #fff;
}

.subcat-card.is-selected .subcat-card-icon,
.subcat-card.is-selected .subcat-card-label {
    color: #fff;
}

/* En oscuro, las tarjetas usan un tono ligeramente más claro que el fondo del
   modal para no quedar planas, y su borde se ve algo más definido. */
[data-theme="dark"] .subcat-card {
    background: var(--bg-card-alt, #1a1a1a);
    border-color: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .subcat-card.is-selected {
    background: #f0f0f0;
    border-color: #f0f0f0;
    color: #141414;
}

[data-theme="dark"] .subcat-card.is-selected .subcat-card-icon,
[data-theme="dark"] .subcat-card.is-selected .subcat-card-label {
    color: #141414;
}

.subcat-card:focus-visible {
    outline: 2px solid var(--text-main, #202322);
    outline-offset: 2px;
}

/* La tarjeta "Todas" ocupa la fila completa como acción de reinicio */
.subcat-card.is-reset {
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: center;
    min-height: 0;
    padding: 12px;
    gap: 10px;
}

.subcat-card.is-reset .subcat-card-icon {
    width: 20px;
    height: 20px;
}

.subcat-card.is-reset .subcat-card-label {
    font-size: 13px;
    font-weight: 600;
}

/* ── Escritorio: tarjeta centrada en lugar de hoja inferior ────────────── */
@media (min-width: 900px) {
    .subcat-modal {
        left: 50%;
        right: auto;
        bottom: auto;
        top: 50%;
        width: min(560px, 92vw);
        max-height: 80vh;
        border-radius: 22px;
        padding: 26px 24px;
        transform: translate(-50%, -46%) scale(0.96);
        opacity: 0;
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.28s ease;
    }

    .subcat-modal.is-open {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }

    .subcat-modal::before {
        display: none;
    }

    .subcat-modal-close {
        top: 18px;
    }

    .subcat-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 12px;
    }
}
