/* =====================================================
   SHOPNOI ENHANCED MEGAMENU
   Professional & Clean Product Navigation Menu
   Version: 3.0 - Text Wrap Support
   Author: ShopNoi Development Team
   ===================================================== */

/* ===== BASE MEGAMENU STRUCTURE ===== */
.dropdown-megamenu {
    position: static !important;
}

.dropdown-megamenu:hover .megamenu {
    visibility: visible !important;
    opacity: 1 !important;
    top: 199px !important;
}

.megamenu {
    position: absolute !important;
    top: 230px !important;
    left: 50% !important;
    z-index: 9999 !important;
    width: 1200px !important;
    max-width: 96vw !important;
    max-height: 75vh !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    border-radius: 20px !important;
    padding: 0 !important;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%) !important;
    border: 1px solid rgba(0, 0, 0, 0.06) !important;
    box-shadow: 
        0 25px 60px -15px rgba(0, 0, 0, 0.2),
        0 10px 20px -10px rgba(0, 0, 0, 0.1),
        0 0 0 1px rgba(0, 0, 0, 0.03) !important;
    transform: translateX(-50%) !important;
    visibility: hidden !important;
    opacity: 0 !important;
    transition: 
        opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        top 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        visibility 0.3s !important;
}

/* Custom Scrollbar */
.megamenu::-webkit-scrollbar {
    width: 8px;
}

.megamenu::-webkit-scrollbar-track {
    background: transparent;
    margin: 12px 0;
}

.megamenu::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #cbd5e1, #94a3b8);
    border-radius: 10px;
    border: 2px solid #f8fafc;
}

.megamenu::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #94a3b8, #64748b);
}

/* ===== MEGAMENU INNER CONTAINER ===== */
.megamenu > .container {
    padding: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
}

.megamenu > .container > .row,
.megamenu .row.row-cols-5 {
    margin: 0 !important;
    padding: 24px !important;
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 20px !important;
    width: 100% !important;
}

/* Reset col styles */
.megamenu .col-4,
.megamenu [class*="col-"] {
    flex: none !important;
    max-width: 100% !important;
    padding: 0 !important;
    width: 100% !important;
}

/* ===== CATEGORY CARD WRAPPER ===== */
.megamenu-wrap {
    background: #ffffff !important;
    border-radius: 16px !important;
    border: 1px solid #e2e8f0 !important;
    overflow: hidden !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04) !important;
}

.megamenu-wrap:hover {
    border-color: #3b82f6 !important;
    box-shadow: 
        0 8px 25px -8px rgba(59, 130, 246, 0.25),
        0 0 0 1px rgba(59, 130, 246, 0.1) !important;
    transform: translateY(-2px) !important;
}

/* ===== CATEGORY TITLE/HEADER ===== */
.megamenu-title {
    display: block !important;
    padding: 14px 16px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    color: #1e293b !important;
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%) !important;
    border-bottom: 2px solid #3b82f6 !important;
    margin: 0 !important;
    position: relative !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

.megamenu-title::before {
    content: '' !important;
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    width: 4px !important;
    background: linear-gradient(180deg, #3b82f6, #1d4ed8) !important;
}

/* ===== PRODUCT LIST ===== */
.megamenu-list {
    list-style: none !important;
    margin: 0 !important;
    padding: 8px !important;
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 2px !important;
}

.megamenu-list li {
    margin: 0 !important;
    padding: 0 !important;
}

/* ===== PRODUCT LINK - KEY FIX FOR LONG TEXT ===== */
.megamenu-list li a {
    display: flex !important;
    align-items: flex-start !important;
    gap: 12px !important;
    padding: 10px 12px !important;
    border-radius: 10px !important;
    color: #334155 !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    line-height: 1.4 !important;
    text-decoration: none !important;
    background: transparent !important;
    transition: all 0.2s ease !important;
    
    /* KEY: Allow text to wrap */
    white-space: normal !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    min-height: 40px !important;
}

.megamenu-list li a:hover {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%) !important;
    color: #1d4ed8 !important;
    transform: translateX(4px) !important;
}

.megamenu-list li a:hover img {
    transform: scale(1.15) !important;
    filter: brightness(1.1) !important;
}

/* ===== PRODUCT ICON ===== */
.megamenu-list li a img {
    width: 24px !important;
    height: 24px !important;
    min-width: 24px !important;
    object-fit: contain !important;
    border-radius: 6px !important;
    background: #f8fafc !important;
    padding: 2px !important;
    transition: all 0.25s ease !important;
    flex-shrink: 0 !important;
    margin-top: 2px !important;
}

/* ===== PRODUCT TEXT WRAPPER ===== */
.megamenu-list li a span,
.megamenu-list li a {
    flex: 1 !important;
    min-width: 0 !important;
}

/* ===== ANIMATION - STAGGERED FADE IN ===== */
.megamenu-wrap {
    animation: fadeInUp 0.35s ease forwards;
    opacity: 0;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Staggered animation delays */
.megamenu .col-4:nth-child(1) .megamenu-wrap { animation-delay: 0.02s; }
.megamenu .col-4:nth-child(2) .megamenu-wrap { animation-delay: 0.04s; }
.megamenu .col-4:nth-child(3) .megamenu-wrap { animation-delay: 0.06s; }
.megamenu .col-4:nth-child(4) .megamenu-wrap { animation-delay: 0.08s; }
.megamenu .col-4:nth-child(5) .megamenu-wrap { animation-delay: 0.10s; }
.megamenu .col-4:nth-child(6) .megamenu-wrap { animation-delay: 0.12s; }
.megamenu .col-4:nth-child(7) .megamenu-wrap { animation-delay: 0.14s; }
.megamenu .col-4:nth-child(8) .megamenu-wrap { animation-delay: 0.16s; }
.megamenu .col-4:nth-child(9) .megamenu-wrap { animation-delay: 0.18s; }
.megamenu .col-4:nth-child(10) .megamenu-wrap { animation-delay: 0.20s; }
.megamenu .col-4:nth-child(11) .megamenu-wrap { animation-delay: 0.22s; }
.megamenu .col-4:nth-child(12) .megamenu-wrap { animation-delay: 0.24s; }

/* ===== DARK MODE SUPPORT ===== */
[data-theme="dark"] .megamenu {
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%) !important;
    border-color: #334155 !important;
    box-shadow: 
        0 25px 60px -15px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.05) !important;
}

[data-theme="dark"] .megamenu::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #475569, #334155);
    border-color: #1e293b;
}

[data-theme="dark"] .megamenu-wrap {
    background: #1e293b !important;
    border-color: #334155 !important;
}

[data-theme="dark"] .megamenu-wrap:hover {
    border-color: #60a5fa !important;
    box-shadow: 
        0 8px 25px -8px rgba(96, 165, 250, 0.2),
        0 0 0 1px rgba(96, 165, 250, 0.1) !important;
}

[data-theme="dark"] .megamenu-title {
    background: linear-gradient(135deg, #334155 0%, #1e293b 100%) !important;
    color: #f1f5f9 !important;
    border-bottom-color: #60a5fa !important;
}

[data-theme="dark"] .megamenu-title::before {
    background: linear-gradient(180deg, #60a5fa, #3b82f6) !important;
}

[data-theme="dark"] .megamenu-list li a {
    color: #cbd5e1 !important;
}

[data-theme="dark"] .megamenu-list li a:hover {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.15) 0%, rgba(59, 130, 246, 0.1) 100%) !important;
    color: #93c5fd !important;
}

[data-theme="dark"] .megamenu-list li a img {
    background: #334155 !important;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 1199px) {
    .megamenu {
        width: 96vw !important;
        max-width: 96vw !important;
    }
    
    .megamenu > .container > .row,
    .megamenu .row.row-cols-5 {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 16px !important;
        padding: 20px !important;
    }
}

@media (max-width: 991px) {
    .megamenu {
        width: 98vw !important;
        max-width: 98vw !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        border-radius: 16px !important;
    }
    
    .dropdown-megamenu:hover .megamenu {
        transform: translateX(-50%) !important;
    }
    
    .megamenu > .container > .row,
    .megamenu .row.row-cols-5 {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 12px !important;
        padding: 16px !important;
    }
    
    .megamenu-title {
        font-size: 11px !important;
        padding: 12px 14px !important;
    }
    
    .megamenu-list li a {
        padding: 8px 10px !important;
        font-size: 12px !important;
        gap: 10px !important;
    }
    
    .megamenu-list li a img {
        width: 20px !important;
        height: 20px !important;
        min-width: 20px !important;
    }
}

@media (max-width: 767px) {
    .megamenu {
        max-height: 65vh !important;
        border-radius: 12px !important;
    }
    
    .megamenu > .container > .row,
    .megamenu .row.row-cols-5 {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
        padding: 12px !important;
    }
    
    .megamenu-wrap {
        border-radius: 12px !important;
    }
    
    .megamenu-title {
        font-size: 10px !important;
        padding: 10px 12px !important;
        letter-spacing: 0.5px !important;
    }
    
    .megamenu-list {
        padding: 6px !important;
    }
    
    .megamenu-list li a {
        padding: 8px !important;
        font-size: 11px !important;
        gap: 8px !important;
        border-radius: 8px !important;
    }
    
    .megamenu-list li a img {
        width: 18px !important;
        height: 18px !important;
        min-width: 18px !important;
    }
}

@media (max-width: 480px) {
    .megamenu > .container > .row,
    .megamenu .row.row-cols-5 {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
        padding: 10px !important;
    }
    
    .megamenu-title {
        font-size: 9px !important;
        padding: 8px 10px !important;
    }
    
    .megamenu-list li a {
        font-size: 10px !important;
        padding: 6px !important;
    }
}

/* ===== FIX FOR ROW COLS - 4 COLUMNS FIXED ===== */
.megamenu .row.row-cols-5 {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
}

@media (max-width: 1199px) {
    .megamenu .row.row-cols-5 {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

@media (max-width: 991px) {
    .megamenu .row.row-cols-5 {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

@media (max-width: 767px) {
    .megamenu .row.row-cols-5 {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 480px) {
    .megamenu .row.row-cols-5 {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ===== EMPTY STATE ===== */
.megamenu-list:empty::after {
    content: 'ไม่มีสินค้าในหมวดหมู่นี้';
    display: block;
    padding: 16px;
    text-align: center;
    color: #94a3b8;
    font-size: 12px;
    font-style: italic;
}

/* ===== LOADING STATE ===== */
.megamenu.loading {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.megamenu.loading::after {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== ACCESSIBILITY ===== */
.megamenu-list li a:focus {
    outline: 2px solid #3b82f6 !important;
    outline-offset: 2px !important;
    background: #eff6ff !important;
}

.megamenu-list li a:focus-visible {
    outline: 2px solid #3b82f6 !important;
    outline-offset: 2px !important;
}

/* ===== PRINT STYLES ===== */
@media print {
    .megamenu {
        display: none !important;
    }
}
