/**
 * Custom Menu Tab - Frontend Grid Styles
 * Phase 5 Implementation (Complete)
 *
 * Styles for category grid display in IQIT Megamenu dropdown
 * Compatible with Warehouse Theme (Bootstrap 4.2.1)
 * Fully namespaced to avoid conflicts
 *
 * @author    Your Company
 * @copyright 2025 Your Company
 * @license   AFL 3.0
 */

/* ============================================
   Grid Wrapper (Height Constraint Container)
   ============================================ */

.custom-menu-grid-wrapper {
    min-height: calc(95vh - 200px);
    max-height: calc(95vh - 200px);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px;
    box-sizing: border-box;
}

/* Custom scrollbar styling for grid wrapper */
.custom-menu-grid-wrapper::-webkit-scrollbar {
    width: 6px;
}

.custom-menu-grid-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.custom-menu-grid-wrapper::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.custom-menu-grid-wrapper::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* ============================================
   Grid Container
   ============================================ */

.custom-menu-grid {
    /* Use Bootstrap's native .row flexbox - DO NOT override */
    overflow: visible !important; /* Allow subcategories to extend beyond */
}

.custom-menu-grid-col {
    /* Use Bootstrap's native column padding for proper gutters */
    margin-bottom: 20px;
    position: relative; /* Required for absolute positioned subcategories */
    overflow: visible !important; /* Allow subcategories to extend beyond column */
    z-index: 1; /* Base z-index for stacking context */
}

/* Increase z-index when card inside is hovered - ensures subcategories appear above other cards */
.custom-menu-grid-col:hover {
    z-index: 100;
}


/* ============================================
   Grid Item (Card) - HORIZONTAL LAYOUT
   ============================================ */

.custom-menu-grid-item {
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 4px;
    padding: 0; /* Remove padding - let inner elements handle spacing */
    height: 100%;
    display: flex;
    flex-direction: row; /* HORIZONTAL: Image LEFT, Content RIGHT */
    transition: all 0.3s cubic-bezier(0.7, 0, 0.3, 1);
    position: relative;
    overflow: visible; /* Allow subcategories dropdown to extend beyond card */
    min-height: 180px; /* Ensure minimum height for horizontal layout */
}

/* Hover Effect: Lift & Shadow */
.custom-menu-grid-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    border-color: #2fb5d2;
    z-index: 10; /* Ensure hovered card is above other cards */
}

/* Hover effect for cards WITH subcategories - stronger border */
.custom-menu-grid-item.has-subcategories:hover {
    border-color: #2fb5d2;
    border-width: 2px;
    z-index: 10; /* Maintain z-index for cards with subcategories */
}

/* ============================================
   Image (LEFT SIDE - 40% width)
   ============================================ */

.custom-menu-grid-item-image {
    flex: 0 0 40%; /* Fixed 40% width, don't grow or shrink */
    max-width: 40%;
    height: 100%; /* Full height of card */
    overflow: hidden;
    border-radius: 4px 0 0 4px; /* Rounded corners on left side only */
    background: #f5f5f5;
    position: relative;
}

.custom-menu-grid-item-image a {
    display: block;
    width: 100%;
    height: 100%;
    position: relative;
}

.custom-menu-grid-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Fill the space, crop if needed */
    transition: transform 0.3s cubic-bezier(0.7, 0, 0.3, 1);
}

/* Image Hover Effect: Slight Zoom */
.custom-menu-grid-item:hover .custom-menu-grid-item-image img {
    transform: scale(1.05);
}

/* ============================================
   Content Wrapper (RIGHT SIDE - 60% width)
   ============================================ */

.custom-menu-grid-item-content {
    flex: 1; /* Take remaining space (60%) */
    padding: 20px;
    display: flex;
    flex-direction: column; /* Stack title, description, CTA vertically */
    justify-content: flex-start;
}

/* Subcategories dropdown - positioned below parent card */
.custom-menu-subcategories {
    position: absolute;
    top: 100%;
    left: -1px;
    right: -1px;
    background: #fff;
    border: 1px solid #2fb5d2;
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.2);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    max-height: 300px;
    overflow-y: auto;
}

/* Show subcategories on parent hover - ONLY for cards with subcategories */
.custom-menu-grid-item.has-subcategories:hover .custom-menu-subcategories {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

/* Subcategory item */
.custom-menu-subcategory-item {
    padding: 10px 15px;
    border-bottom: 1px solid #f0f0f0;
    background: #fff;
    transition: background 0.2s ease;
}

.custom-menu-subcategory-item:last-child {
    border-bottom: none;
    border-radius: 0 0 6px 6px;
}

.custom-menu-subcategory-item:hover {
    background: #f8f8f8;
}

.custom-menu-subcategory-item a {
    color: #333;
    text-decoration: none;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s ease;
}

.custom-menu-subcategory-item a:hover {
    color: #2fb5d2;
    padding-left: 8px;
}

/* Subcategory thumbnail image */
.custom-menu-subcategory-item .subcategory-thumbnail {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #e5e5e5;
    flex-shrink: 0;
}

.custom-menu-subcategory-item .subcategory-title {
    flex: 1;
}

/* ============================================
   Title (in content wrapper)
   ============================================ */

.custom-menu-grid-item-title {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
    margin: 0 0 12px 0;
    color: #414141;
}

.custom-menu-grid-item-title a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s ease;
}

.custom-menu-grid-item-title a:hover {
    color: #2fb5d2;
    text-decoration: none;
}

/* ============================================
   Description (in content wrapper)
   ============================================ */

.custom-menu-grid-item-description {
    font-size: 14px;
    line-height: 1.6;
    color: #878787;
    margin: 0 0 15px 0;
    flex-grow: 1; /* Take available space, pushing CTA to bottom */
}

/* ============================================
   CTA Button (in content wrapper)
   ============================================ */

.custom-menu-grid-item-cta {
    margin-top: auto; /* Push to bottom of content wrapper */
}

.custom-menu-grid-item-cta .btn {
    display: inline-block; /* NOT full width in horizontal layout */
    font-size: 14px;
    font-weight: 600;
    padding: 10px 24px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.2s ease;
}

.custom-menu-grid-item-cta .btn-primary {
    background-color: #2fb5d2;
    border-color: #2fb5d2;
    color: #fff;
}

.custom-menu-grid-item-cta .btn-primary:hover {
    background-color: #26a3bf;
    border-color: #26a3bf;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(47, 181, 210, 0.3);
}

/* ============================================
   Responsive Design
   ============================================ */

/* Tablets (768px - 991px) */
@media (max-width: 991px) {
    .custom-menu-grid-wrapper {
        min-height: calc(90vh - 150px);
        max-height: calc(90vh - 150px);
    }

    .custom-menu-grid-item {
        padding: 12px;
        max-height: 300px;
    }

    .custom-menu-grid-item-title {
        font-size: 16px;
    }

    .custom-menu-grid-item-description {
        font-size: 13px;
    }

    .custom-menu-grid-item-image {
        margin-bottom: 12px;
    }
}

/* Mobile Devices (up to 767px) - SWITCH TO VERTICAL LAYOUT */
@media (max-width: 767px) {
    .custom-menu-grid-wrapper {
        min-height: calc(90vh - 120px);
        max-height: calc(90vh - 120px);
        padding: 10px;
    }

    .custom-menu-grid-col {
        margin-bottom: 15px;
        /* Force 1 column on mobile */
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* VERTICAL LAYOUT on mobile: Stack image on top, content below */
    .custom-menu-grid-item {
        flex-direction: column !important; /* Stack vertically */
        min-height: auto;
        padding: 15px;
    }

    .custom-menu-grid-item-image {
        flex: 0 0 auto !important; /* Reset flex */
        max-width: 100% !important; /* Full width */
        height: 150px; /* Fixed height */
        border-radius: 4px 4px 0 0 !important; /* Rounded top only */
        margin-bottom: 15px;
    }

    .custom-menu-grid-item-content {
        padding: 0 !important; /* Remove padding in mobile vertical layout */
    }

    .custom-menu-grid-item-title {
        font-size: 16px;
        margin-bottom: 10px;
    }

    .custom-menu-grid-item-description {
        font-size: 14px;
        margin-bottom: 12px;
    }

    .custom-menu-grid-item-cta .btn {
        font-size: 14px;
        padding: 10px 20px;
        display: block; /* Full width on mobile */
        width: 100%;
        text-align: center;
    }

    /* Disable hover effects on touch devices */
    .custom-menu-grid-item:hover {
        transform: none;
        box-shadow: none;
    }

    .custom-menu-grid-item:hover .custom-menu-grid-item-image img {
        transform: scale(1);
    }

    /* Mobile: Subcategories appear inline (not as dropdown) */
    .custom-menu-subcategories {
        position: static !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        transform: none !important;
        margin-top: 15px;
        border-radius: 4px;
        border: 1px solid #e5e5e5;
        box-shadow: none;
        max-height: none;
    }

    .custom-menu-subcategory-item {
        padding: 10px 15px;
    }

    .custom-menu-subcategory-item a {
        font-size: 14px;
    }
}

/* Small Mobile (up to 575px) */
@media (max-width: 575px) {
    .custom-menu-grid {
        padding: 10px 0;
    }

    .custom-menu-grid-item-title {
        font-size: 14px;
    }

    .custom-menu-grid-item-description {
        font-size: 12px;
        line-height: 1.5;
    }
}

/* ============================================
   IQIT Megamenu Integration
   ============================================ */

/* Override IQIT megamenu dropdown container to fit content */
.cbp-hrmenu .cbp-hrsub {
    height: auto !important;
}

.cbp-hrmenu .cbp-hrsub-inner {
    height: auto !important;
}

/* Ensure grid displays correctly within megamenu dropdown */
.cbp-hrmenu .cbp-hrsub .custom-menu-grid {
    width: 100%;
    max-width: 100%;
}

/* Grid padding removed - wrapper already provides padding (line 23) */
/* Adding padding to Bootstrap .row breaks the grid system */

/* ============================================
   Column Adjustments for Different Layouts
   ============================================ */

/* 4 Columns (col-md-3) */
.custom-menu-grid .col-md-3 .custom-menu-grid-item {
    padding: 12px;
}

.custom-menu-grid .col-md-3 .custom-menu-grid-item-title {
    font-size: 16px;
}

.custom-menu-grid .col-md-3 .custom-menu-grid-item-description {
    font-size: 13px;
}

/* ============================================
   Accessibility
   ============================================ */

/* Focus styles for keyboard navigation */
.custom-menu-grid-item-title a:focus,
.custom-menu-grid-item-cta .btn:focus {
    outline: 2px solid #2fb5d2;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .custom-menu-grid-item {
        border: 2px solid #000;
    }

    .custom-menu-grid-item-title a:hover {
        color: #000;
        text-decoration: underline;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .custom-menu-grid-item,
    .custom-menu-grid-item-image img,
    .custom-menu-grid-item-title a,
    .custom-menu-grid-item-cta .btn {
        transition: none;
    }

    .custom-menu-grid-item:hover {
        transform: none;
    }

    .custom-menu-grid-item:hover .custom-menu-grid-item-image img {
        transform: translate(-50%, -50%) scale(1);
    }
}

/* ============================================
   Column Width Support (Bootstrap 4 compat)
   ============================================ */

@media (min-width: 768px) and (max-width: 991px) {
    .custom-menu-grid-col.col-md-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .custom-menu-grid-col.col-md-4 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .custom-menu-grid-col.col-md-3 {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

@media (min-width: 992px) {
    .custom-menu-grid-col.col-md-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .custom-menu-grid-col.col-md-4 {
        flex: 0 0 33.333333%;
        max-width: 33.333333%;
    }

    .custom-menu-grid-col.col-md-3 {
        flex: 0 0 25%;
        max-width: 25%;
    }
}
