/* ==============================================
   BRANCHES MODAL - Modern CSS with Nesting
   ============================================== */

/* CSS Custom Properties */
:root {
    --branches-modal-bg: rgba(0, 0, 0, 0.6);
    --branches-modal-content-bg: #ffffff;
    --branches-modal-radius: 16px;
    --branches-modal-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --branches-primary-color: #CC2128;
    --branches-text-primary: #1f2937;
    --branches-text-secondary: #6b7280;
    --branches-border-color: #e5e7eb;
    --branches-hover-bg: #f9fafb;
    --branches-selected-bg: #fef2f2;
    --branches-transition: all 0.2s ease;
}

/* Modal Backdrop */
.branches-modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--branches-modal-bg);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;

    &.active {
        opacity: 1;
        visibility: visible;
    }

    /* Modal Content Container */
    & .branches-modal-content {
        background: var(--branches-modal-content-bg);
        border-radius: var(--branches-modal-radius);
        box-shadow: var(--branches-modal-shadow);
        width: 90vw;
        max-width: 1100px;
        height: 80vh;
        max-height: 700px;
        display: grid;
        grid-template-columns: 380px 1fr;
        overflow: hidden;
        transform: scale(0.95) translateY(20px);
        transition: transform 0.3s ease;

        @media (max-width: 900px) {
            grid-template-columns: 1fr;
            height: 90vh;
            max-height: none;
        }
    }

    &.active .branches-modal-content {
        transform: scale(1) translateY(0);
    }
}

/* Left Panel - Branch List */
.branches-list-panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--branches-border-color);
    overflow: hidden;

    @media (max-width: 900px) {
        border-right: none;
        border-bottom: 1px solid var(--branches-border-color);
        max-height: 50vh;
    }

    /* Header with search */
    & .branches-header {
        padding: 20px;
        border-bottom: 1px solid var(--branches-border-color);
        background: #fafafa;

        & .branches-title {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 16px;

            & h2 {
                font-size: 18px;
                font-weight: 700;
                color: var(--branches-text-primary);
                margin: 0;
            }

            & .branches-close-btn {
                width: 32px;
                height: 32px;
                border: none;
                background: transparent;
                cursor: pointer;
                border-radius: 8px;
                display: flex;
                align-items: center;
                justify-content: center;
                color: var(--branches-text-secondary);
                transition: var(--branches-transition);

                &:hover {
                    background: var(--branches-hover-bg);
                    color: var(--branches-text-primary);
                }

                & svg {
                    width: 20px;
                    height: 20px;
                }
            }
        }

        & .branches-search {
            position: relative;

            & input {
                width: 100%;
                padding: 12px 16px 12px 44px;
                border: 1px solid var(--branches-border-color);
                border-radius: 10px;
                font-size: 14px;
                outline: none;
                transition: var(--branches-transition);
                box-sizing: border-box;

                &::placeholder {
                    color: var(--branches-text-secondary);
                }

                &:focus {
                    border-color: var(--branches-primary-color);
                    box-shadow: 0 0 0 3px rgba(204, 33, 40, 0.1);
                }
            }

            & .search-icon {
                position: absolute;
                left: 14px;
                top: 50%;
                transform: translateY(-50%);
                color: var(--branches-text-secondary);
                pointer-events: none;

                & svg {
                    width: 18px;
                    height: 18px;
                }
            }
        }
    }

    /* Location status */
    & .branches-location-status {
        padding: 12px 20px;
        background: #f0fdf4;
        border-bottom: 1px solid #bbf7d0;
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 13px;
        color: #166534;

        &.loading {
            background: #fefce8;
            border-color: #fef08a;
            color: #854d0e;
        }

        &.error {
            background: #fef2f2;
            border-color: #fecaca;
            color: #991b1b;
        }

        & svg {
            width: 16px;
            height: 16px;
            flex-shrink: 0;
        }
    }

    /* Branch items list */
    & .branches-items {
        flex: 1;
        overflow-y: auto;
        scroll-behavior: smooth;

        &::-webkit-scrollbar {
            width: 6px;
        }

        &::-webkit-scrollbar-track {
            background: transparent;
        }

        &::-webkit-scrollbar-thumb {
            background: #d1d5db;
            border-radius: 3px;

            &:hover {
                background: #9ca3af;
            }
        }
    }
}

/* Branch Item */
.branch-item {
    padding: 16px 20px;
    cursor: pointer;
    border-bottom: 1px solid var(--branches-border-color);
    transition: var(--branches-transition);
    display: flex;
    gap: 12px;

    &:last-child {
        border-bottom: none;
    }

    &:hover {
        background: var(--branches-hover-bg);
    }

    &.selected {
        background: var(--branches-selected-bg);
        border-left: 3px solid var(--branches-primary-color);
    }

    &.nearest {
        & .branch-distance {
            background: var(--branches-primary-color);
            color: white;
        }
    }

    & .branch-icon {
        flex-shrink: 0;
        width: 40px;
        height: 40px;
        background: linear-gradient(135deg, var(--branches-primary-color), #ef4444);
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;

        & svg {
            width: 20px;
            height: 20px;
        }
    }

    & .branch-info {
        flex: 1;
        min-width: 0;

        & .branch-name {
            font-size: 14px;
            font-weight: 600;
            color: var(--branches-text-primary);
            margin-bottom: 4px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        & .branch-address {
            font-size: 12px;
            color: var(--branches-text-secondary);
            line-height: 1.4;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }

        & .branch-state {
            font-size: 11px;
            color: var(--branches-primary-color);
            font-weight: 500;
            margin-top: 4px;
        }
    }

    & .branch-distance {
        flex-shrink: 0;
        font-size: 12px;
        font-weight: 600;
        color: var(--branches-text-secondary);
        background: #f3f4f6;
        padding: 4px 8px;
        border-radius: 6px;
        align-self: flex-start;
    }
}

/* Empty state */
.branches-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--branches-text-secondary);

    & svg {
        width: 48px;
        height: 48px;
        margin-bottom: 12px;
        opacity: 0.5;
    }

    & p {
        margin: 0;
        font-size: 14px;
    }
}

/* Right Panel - Map */
.branches-map-panel {
    position: relative;
    background: #e5e7eb;

    @media (max-width: 900px) {
        min-height: 300px;
    }

    & #branchesMap {
        width: 100%;
        height: 100%;
    }

    /* Map controls overlay */
    & .map-controls {
        position: absolute;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        display: flex;
        gap: 8px;
    }

    & .map-btn {
        padding: 10px 20px;
        background: white;
        border: none;
        border-radius: 8px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        transition: var(--branches-transition);

        &:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        }

        &.primary {
            background: var(--branches-primary-color);
            color: white;

            &:hover {
                background: #b91c23;
            }
        }
    }
}

/* Loading spinner */
.branches-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    gap: 12px;

    & .spinner {
        width: 32px;
        height: 32px;
        border: 3px solid var(--branches-border-color);
        border-top-color: var(--branches-primary-color);
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
    }

    & span {
        font-size: 14px;
        color: var(--branches-text-secondary);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Animation for modal entrance */
@keyframes modalFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes modalSlideUp {
    from {
        transform: scale(0.95) translateY(20px);
    }
    to {
        transform: scale(1) translateY(0);
    }
}

/* ==============================================
   NEARER BRANCH NOTIFICATION BANNER
   ============================================== */

.nearer-branch-banner {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: linear-gradient(135deg, var(--branches-primary-color), #a81c22);
    color: white;
    padding: 16px 20px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(204, 33, 40, 0.3), 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 9998;
    display: flex;
    align-items: center;
    gap: 16px;
    max-width: 90vw;
    width: auto;
    opacity: 0;
    visibility: hidden;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), 
                opacity 0.3s ease,
                visibility 0.3s ease;

    &.active {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
        visibility: visible;
    }

    & .banner-icon {
        width: 40px;
        height: 40px;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;

        & svg {
            width: 24px;
            height: 24px;
            fill: currentColor;
        }
    }

    & .banner-content {
        flex: 1;
        min-width: 0;

        & .banner-title {
            font-size: 14px;
            font-weight: 600;
            margin-bottom: 2px;
        }

        & .banner-message {
            font-size: 13px;
            opacity: 0.9;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    }

    & .banner-actions {
        display: flex;
        gap: 8px;
        flex-shrink: 0;
    }

    & .banner-btn {
        padding: 8px 16px;
        border-radius: 8px;
        font-size: 13px;
        font-weight: 600;
        cursor: pointer;
        transition: var(--branches-transition);
        border: none;
        white-space: nowrap;

        &.primary {
            background: white;
            color: var(--branches-primary-color);

            &:hover {
                background: #f0f0f0;
                transform: scale(1.02);
            }
        }

        &.secondary {
            background: rgba(255, 255, 255, 0.2);
            color: white;

            &:hover {
                background: rgba(255, 255, 255, 0.3);
            }
        }
    }

    & .banner-close {
        position: absolute;
        top: -8px;
        right: -8px;
        width: 24px;
        height: 24px;
        background: white;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        transition: var(--branches-transition);

        & svg {
            width: 14px;
            height: 14px;
            stroke: var(--branches-text-secondary);
        }

        &:hover {
            transform: scale(1.1);
            
            & svg {
                stroke: var(--branches-primary-color);
            }
        }
    }
}

/* Mobile responsive for banner */
@media (max-width: 600px) {
    .nearer-branch-banner {
        bottom: 10px;
        left: 10px;
        right: 10px;
        transform: translateX(0) translateY(100px);
        flex-direction: column;
        text-align: center;
        padding: 16px;

        &.active {
            transform: translateX(0) translateY(0);
        }

        & .banner-icon {
            display: none;
        }

        & .banner-content .banner-message {
            white-space: normal;
        }

        & .banner-actions {
            width: 100%;
            justify-content: center;
        }
    }
}

/* ==============================================
   MOBILE UTILITIES BAR (Branch + Currency)
   ============================================== */

.mobile-utilities-bar {
    display: none;
    width: 100%;
    border-bottom: 1px solid var(--branches-border-color);
    padding: 8px 12px;
    box-sizing: border-box;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
}

.mobile-branch-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--branches-transition);
    flex: 1;
    max-width: 60%;
    text-decoration: none;
    color: var(--branches-text-primary);

    &:hover, &:active {
        border-color: var(--branches-primary-color);
        background: var(--branches-hover-bg);
    }

    & svg {
        flex-shrink: 0;
        color: var(--branches-primary-color);
    }

    & .mobile-branch-name {
        font-size: 13px;
        font-weight: 500;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        flex: 1;
    }

    & i {
        font-size: 10px;
        color: var(--branches-text-secondary);
        flex-shrink: 0;
    }
}

.mobile-currency-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: white;
    border-radius: 8px;
    border: 1px solid var(--branches-border-color);
    cursor: pointer;
    transition: var(--branches-transition);
    font-size: 13px;
    font-weight: 500;
    color: var(--branches-text-primary);

    &:hover {
        border-color: var(--branches-primary-color);
    }
}

@media (max-width: 900px) {
    .mobile-utilities-bar {
        padding-top: 2.5%;
        padding-bottom: 2.5%;
    }
}

/* Only show on mobile */
@media (max-width: 768px) { 
    #main_container_2  {
        padding-top: 155px;
    }
        
    .mobile-utilities-bar {
        display: flex;
        padding: 1px 12px;
    }
    
    /* Hide desktop branch selector on mobile */
    #search_nav_icon {
        display: none !important;
    }


    #categoriesBar {
        display: block;
        width: 100%;
        margin-top: 0px !important;
    }

}

/* Tablet/Desktop compacto: usar selector de tienda estilo mobile */
@media (min-width: 800px) and (max-width: 1200px) {
    .mobile-utilities-bar {
        display: flex;
        padding: 6px 12px;
    }

    .mobile-branch-selector {
        max-width: 100%;
    }

    #search_nav_icon {
        display: none !important;
    }
}