/* ==========================================================================
   FTF Category Sidebar — v2.0.0 — Storefront Widget Integration
   ========================================================================== */

:root {
    --ftf-primary: #C41E3A;
}

/* ==========================================================================
   Desktop: Sticky sidebar inside Storefront's #secondary
   ========================================================================== */

@media (min-width: 769px) {
    /* Make sidebar sticky so it follows scroll */
    #secondary .widget_ftf_category_nav {
        position: sticky;
        top: 20px;
    }

    /* Hide mobile-only elements */
    .ftf-sidebar-close,
    .ftf-sidebar-toggle,
    .ftf-sidebar-overlay {
        display: none !important;
    }
}

/* ==========================================================================
   Widget Header
   ========================================================================== */

.widget_ftf_category_nav {
    padding: 0 !important;
    border: 1px solid #e8e8e8;
    border-top: 3px solid var(--ftf-primary);
    border-radius: 0 0 6px 6px;
    background: #fff;
    overflow: hidden;
}

.ftf-sidebar-header {
    padding: 14px 16px;
    border-bottom: 2px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ftf-sidebar-title {
    margin: 0 !important;
    padding: 0 !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    color: var(--ftf-primary) !important;
    text-transform: uppercase;
    letter-spacing: 1.2px;
}

.ftf-sidebar-close {
    width: 30px;
    height: 30px;
    background: #f5f5f5;
    border: none;
    border-radius: 4px;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    color: #666;
    display: none;
}

.ftf-sidebar-close:hover {
    background: #eee;
    color: var(--ftf-primary);
}

/* ==========================================================================
   Category List
   ========================================================================== */

.ftf-sidebar-nav {
    overflow-y: auto;
    max-height: calc(100vh - 120px);
}

.ftf-category-list {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

.ftf-category-item {
    border-bottom: 1px solid #f0f0f0;
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

.ftf-category-item:last-child {
    border-bottom: none;
}

.ftf-category-toggle,
.ftf-category-link {
    width: 100%;
    padding: 11px 16px;
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s, color 0.15s;
    text-decoration: none !important;
    font-family: inherit;
    box-sizing: border-box;
    line-height: 1.4;
}

.ftf-category-toggle:hover,
.ftf-category-link:hover {
    background: #f8f8f8;
    color: var(--ftf-primary);
}

.ftf-category-toggle.active {
    color: var(--ftf-primary);
    background: #fef2f2;
}

.ftf-arrow {
    font-size: 9px;
    color: var(--ftf-primary);
    transition: transform 0.2s;
    flex-shrink: 0;
    margin-left: 8px;
}

.ftf-category-toggle.active .ftf-arrow {
    transform: rotate(180deg);
}

/* ==========================================================================
   Subcategory List (expand/collapse)
   ========================================================================== */

.ftf-subcategory-list {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: #fafafa;
}

.ftf-category-item.expanded .ftf-subcategory-list {
    max-height: 1000px;
}

.ftf-subcategory-list li {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

.ftf-subcategory-list a {
    display: block;
    padding: 9px 16px 9px 30px;
    color: #666 !important;
    text-decoration: none !important;
    font-size: 12px;
    border-left: 3px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.ftf-subcategory-list a:hover {
    background: #f0f0f0;
    color: var(--ftf-primary) !important;
    border-left-color: var(--ftf-primary);
}

/* Scrollbar */
.ftf-sidebar-nav::-webkit-scrollbar {
    width: 5px;
}
.ftf-sidebar-nav::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* ==========================================================================
   Mobile Toggle Button
   ========================================================================== */

.ftf-sidebar-toggle {
    display: none;
    position: fixed;
    left: 15px;
    bottom: 25px;
    padding: 14px 22px;
    background: var(--ftf-primary);
    border: none;
    border-radius: 50px;
    color: #fff !important;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    z-index: 9999;
    box-shadow: 0 4px 20px rgba(196,30,58,0.5);
    align-items: center;
    gap: 10px;
    font-family: inherit;
    transition: background 0.2s, transform 0.2s;
}

.ftf-sidebar-toggle:hover {
    background: #a01830;
    transform: translateY(-2px);
}

.ftf-toggle-icon {
    font-size: 18px;
}

/* ==========================================================================
   Overlay
   ========================================================================== */

.ftf-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9998;
}

.ftf-sidebar-overlay.active {
    display: block;
}

/* ==========================================================================
   Mobile: Sidebar becomes a slide-in drawer
   ========================================================================== */

@media (max-width: 768px) {
    /* Turn Storefront's #secondary into a fixed slide-in drawer */
    #secondary.widget-area {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 300px;
        max-width: 85vw;
        background: #fff;
        z-index: 99999;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
        box-shadow: none;
        margin: 0;
        padding: 0;
        float: none;
    }

    #secondary.widget-area.ftf-open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    }

    /* Override Storefront left-sidebar layout when sidebar is a drawer */
    .left-sidebar .content-area,
    .left-sidebar #primary {
        width: 100% !important;
        float: none !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .left-sidebar #secondary {
        width: 300px !important;
        max-width: 85vw !important;
    }

    /* Prevent iOS horizontal scroll from off-screen elements */
    html {
        overflow-x: hidden;
    }

    .ftf-sidebar-close {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }

    .ftf-sidebar-toggle {
        display: flex !important;
    }

    .ftf-sidebar-nav {
        max-height: calc(100vh - 60px);
    }

    .widget_ftf_category_nav {
        border: none;
        border-top: 3px solid var(--ftf-primary);
        border-radius: 0;
    }
}

@media (max-width: 480px) {
    #secondary.widget-area {
        width: 100%;
        max-width: 100%;
    }

    .ftf-toggle-text {
        display: none;
    }

    .ftf-sidebar-toggle {
        padding: 14px 18px;
    }
}