/* Mega Menu Styles */
.nav-item-with-mega {
    position: relative;
}

/*
  Mega menu spacing knobs
  - Adjust the values below to increase/decrease spacing uniformly for LTR/RTL
  - --mega-start-inset controls how far cards are inset from the start side (LTR: left, RTL: right)
  - --mega-icon-start-margin adds a tiny buffer between card edge and the icon box
  - --mega-text-extra-start optionally adds extra space between the icon and text (in addition to `gap`)
  - --mega-card-padding-block and --mega-card-padding-inline control the card vertical/horizontal padding
  - --mega-cta-min-width increases the CTA button width to avoid text overflow
*/
:root {
  --mega-start-inset: 56px;           /* Change this to tweak the global start-side inset of each card */
  --mega-icon-start-margin: 12px;      /* Change this to nudge icons inward/outward from the card edge */
  --mega-text-extra-start: 6px;       /* Optional: extra spacing between icon and text block */
  --mega-icon-text-gap: 48px;         /* Space between icon and text inside each link (via gap) */
  --mega-icon-size: 56px;             /* Size of the icon square (width/height) */
  --mega-title-size: 17px;            /* Title font size */
  --mega-desc-size: 14px;             /* Description font size */
  --mega-card-padding-block: 44px;    /* Vertical padding for each card (top/bottom) */
  --mega-card-padding-inline: 48px;   /* Horizontal padding for each card (start/end, overridden on start) */
  --mega-card-min-height: 150px;      /* Minimum height for each card to avoid cramped look */
  --mega-card-min-height-md: 112px;   /* Min-height for medium screens (<=1024px) */
  --mega-menu-width: 980px;           /* Total width of the mega menu on desktop */
  --mega-menu-width-md: 760px;        /* Mega menu width for <= 1024px */
  --mega-cta-min-width: 280px;        /* Minimum width for footer CTA button */
  --mega-cta-padding-inline: 36px;    /* Horizontal padding for the CTA button */
}

.mega-menu {
    position: fixed; /* Anchor to viewport for true full-width */
    top: var(--header-current-height, 72px); /* Align right under header */
    left: 0;
    right: 0;
    /* Full-bleed width on desktop */
    width: 100vw;
    background: var(--white);
    border-radius: var(--border-radius-large);
    box-shadow: 0 20px 45px rgba(18, 32, 56, 0.14);
    opacity: 0;
    visibility: hidden;
    /* Start slightly below the header to avoid overlapping it during animation */
    transform: translateY(6px);
    transition: all var(--transition-medium);
    z-index: 999; /* Keep below header (header z-index: 1000) */
    border: 1px solid var(--gray-200);
    /* Allow internal scrolling when content overflows viewport height */
    max-height: 80vh;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Ensure RTL direction within the mega menu so logical properties (inline-start) map to the right in Arabic */
html[lang="ar"] .mega-menu {
    direction: rtl;
}

.nav-item-with-mega::after {
    /* Old inline caret removed. We now render a centered caret under the link text via a::before */
    content: none;
}

/* Premium underline highlight on Services link when active */
.nav-item-with-mega > a {
    position: relative;
}
/* Centered caret placed directly under the Services label */
.nav-item-with-mega > a::before {
    content: '▼';
    position: absolute;
    left: 50%;
    bottom: -12px;
    transform: translateX(-50%) translateY(0);
    font-size: 10px;
    color: var(--gray-600);
    opacity: 1; /* Always visible to indicate a submenu */
    transition: transform var(--transition-fast), opacity var(--transition-fast), color var(--transition-fast);
    z-index: 1002; /* Above the .mega-menu (1000) */
}
.nav-item-with-mega:hover > a,
.nav-item-with-mega.open > a,
.nav-item-with-mega:focus-within > a {
    color: var(--primary-color);
}
.nav-item-with-mega:hover > a::before,
.nav-item-with-mega.open > a::before,
.nav-item-with-mega:focus-within > a::before {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    color: var(--primary-color);
}

/* Legacy li::after caret rotation removed (caret now handled on a::before above) */
/* Removed old caret rotation rule set since caret is now handled on the anchor (::before) */

.nav-item-with-mega:hover .mega-menu,
.nav-item-with-mega.open .mega-menu,
.nav-item-with-mega:focus-within .mega-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* When the desktop mega menu is open, prevent page scroll */
body.nav-open { overflow: hidden; }

.mega-menu-container {
    padding: 40px;
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, rgba(var(--primary-color-rgb), 0.03), rgba(var(--secondary-color-rgb), 0.03));
}

.mega-menu-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--primary-color), var(--secondary-color), transparent);
    animation: shimmer 3s ease-in-out infinite;
}

@keyframes shimmer {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

.mega-menu-header {
    text-align: center;
    margin-bottom: 36px;
    position: relative;
    padding-bottom: 4px;
}

.mega-menu-header h3 {
    font-size: 26px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
    animation: glow 2s ease-in-out infinite alternate;
    letter-spacing: -0.02em;
}

@keyframes glow {
    from { filter: brightness(1); }
    to { filter: brightness(1.2); }
}

.mega-menu-header p {
    color: var(--gray-500);
    font-size: 15px;
    margin: 0;
    font-weight: 400;
    opacity: 0.9;
}

.mega-menu-grid {
    display: grid;
    /* Keep two blocks (categories) but allow them to breathe on wide screens */
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 44px;
    margin-bottom: 36px;
    padding: 8px 12px 0 12px;
    position: relative;
}
.mega-menu-grid::after { display: none; }

.mega-menu-category h4 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 18px;
    position: relative;
    padding-left: 18px;
}

.mega-menu-category h4::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 20px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 2px;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: translateY(-50%) scale(1); }
    50% { transform: translateY(-50%) scale(1.1); }
}

.mega-menu-category ul {
    list-style: none;
    padding: 0;
    margin: 0;
    /* Wrap cards side-by-side inside each category to reduce height */
    display: grid;
    grid-template-columns: repeat(2, minmax(280px, 1fr));
    gap: 16px 16px;
}

.mega-menu-category li { margin: 0; }

/* Remove extra bottom margins now that we use grid gaps */
.mega-menu-category li .mega-menu-link { margin-bottom: 0; }

/* Adjust wrapping for narrower desktops */
@media (max-width: 1200px) {
  .mega-menu-category ul {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  }
}

.mega-menu-link {
    display: block;
    position: relative;
    box-sizing: border-box;
    padding: var(--mega-card-padding-block, 24px) var(--mega-card-padding-inline, 30px);
    min-height: var(--mega-card-min-height, 120px);
    border-radius: 16px;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(248, 250, 252, 0.95));
    border: 1px solid rgba(var(--primary-color-rgb), 0.08);
    margin-bottom: 12px;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
}

.mega-menu-link::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transition: left 0.5s ease;
}

.mega-menu-link:hover::before {
    left: 100%;
}

.mega-menu-link:hover {
    background: linear-gradient(135deg, rgba(var(--primary-color-rgb), 0.08), rgba(var(--secondary-color-rgb), 0.08));
    border-color: rgba(var(--primary-color-rgb), 0.3);
    transform: translateY(-2px) scale(1.02);
    box-shadow: 
        0 12px 28px rgba(var(--primary-color-rgb), 0.15),
        0 4px 12px rgba(0, 0, 0, 0.08),
        0 0 0 1px rgba(var(--primary-color-rgb), 0.12);
}

/* Active state (persistent highlight for current page) */
.mega-menu-link.active,
.mega-menu-link[aria-current="page"] {
    background: linear-gradient(135deg, rgba(var(--primary-color-rgb), 0.08), rgba(var(--secondary-color-rgb), 0.08));
    border-color: rgba(var(--primary-color-rgb), 0.3);
    box-shadow:
        0 10px 24px rgba(var(--primary-color-rgb), 0.14),
        0 3px 10px rgba(0, 0, 0, 0.08),
        0 0 0 1px rgba(var(--primary-color-rgb), 0.12);
    transform: none; /* Keep layout stable when highlighted */
}

.mega-menu-link.featured {
    background: linear-gradient(135deg, rgba(var(--primary-color-rgb), 0.1), rgba(var(--secondary-color-rgb), 0.1));
    border: 1px solid rgba(var(--primary-color-rgb), 0.3);
    position: relative;
}

.mega-menu-link.featured::after {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    bottom: -1px;
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color), var(--accent-color), var(--primary-color));
    border-radius: 12px;
    z-index: -1;
    animation: rotate 3s linear infinite;
    opacity: 0.7;
}

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

.mega-link-icon {
    width: var(--mega-icon-size, 56px);
    height: var(--mega-icon-size, 56px);
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--mega-icon-size, 56px) * 0.5);
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    display: flex;
    align-items: center;
    justify-content: center;
    /* Remove order property from here - we'll set it based on language */
    /* Use only gap for spacing relative to the text; no extra end margin */
    margin: 0;
    margin-inline-end: 0;
    /* Fallback for older browsers */
    margin-right: 0;
    flex: 0 0 auto;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    box-shadow: 
        0 4px 12px rgba(var(--primary-color-rgb), 0.25),
        0 2px 6px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* RTL overrides (fallback when logical properties are unsupported) */
html[lang="ar"] .mega-menu-link {
    /*padding-right: var(--mega-start-inset, 56px);
    /* Reset left padding to the base horizontal value to avoid double inset on old browsers */
    padding-left: 40px;
}

html[lang="ar"] .mega-link-icon {
    /* No extra margins in RTL either; we rely on gap and card padding */
    margin: 0;
}

/* Force layout structure for all languages */

/* Content positioning base styles */
.mega-link-content {
    display: block;
}

/* French/English (LTR): text aligned left with space for icon */
html:not([lang="ar"]) .mega-link-content {
    text-align: left;
    padding-right: calc(var(--mega-icon-size, 56px) + 24px);
    padding-left: 20px;
    padding-top: 10px;
    padding-bottom: 10px;
}

/* Arabic (RTL): text aligned right with space for icon */
html[lang="ar"] .mega-link-content {
    text-align: right;
    padding-left: calc(var(--mega-icon-size, 56px) + 24px);
    padding-right: 20px;
    padding-top: 10px;
    padding-bottom: 10px;
}

/* Direction-specific adjustments removed to simplify layout */

/* Style adjustments for icon */
.mega-link-icon {
    width: var(--mega-icon-size, 56px);
    height: var(--mega-icon-size, 56px);
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 14px;
}

/* Icon positioning for different languages */
/* French/English (LTR): Icon on the RIGHT side */
html:not([lang="ar"]) .mega-link-icon {
    right: 48px;
    left: auto;
}

/* Arabic (RTL): Icon on the LEFT side */
html[lang="ar"] .mega-link-icon {
    left: 48px;
    right: auto;
}


.mega-link-icon::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
}

.mega-menu-link:hover .mega-link-icon::before {
    transform: translateX(100%);
}

.mega-link-icon i {
    color: white;
    font-size: 20px;
    z-index: 1;
    position: relative;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

.mega-menu-link:hover .mega-link-icon {
    transform: scale(1.1) rotate(3deg);
    box-shadow: 
        0 6px 20px rgba(var(--primary-color-rgb), 0.4),
        0 3px 8px rgba(0, 0, 0, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.mega-menu-link.active .mega-link-icon,
.mega-menu-link[aria-current="page"] .mega-link-icon {
    transform: scale(1.05);
    box-shadow:
        0 5px 16px rgba(var(--primary-color-rgb), 0.35),
        0 2px 6px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.mega-link-content {
    flex: 1;
    position: relative;
    margin-right: 0;
    /* Add padding to ensure text isn't flush with any edge */
    padding-inline-start: var(--mega-text-extra-start, 20px);
    /* Fallback for older browsers */
    padding-left: var(--mega-text-extra-start, 20px);
    /* Remove order property from here - we'll set it based on language */
}

.mega-link-title {
    display: block;
    font-weight: 700;
    color: var(--text-color);
    font-size: var(--mega-title-size, 17px);
    line-height: 1.3;
    margin-bottom: 8px;
    transition: all 0.3s ease;
    letter-spacing: -0.01em;
}

.mega-menu-link:hover .mega-link-title {
    color: var(--primary-color);
    transform: translateX(2px);
}

.mega-menu-link.active .mega-link-title,
.mega-menu-link[aria-current="page"] .mega-link-title {
    color: var(--primary-color);
}

.mega-link-desc {
    display: block;
    font-size: var(--mega-desc-size, 14px);
    color: var(--gray-500);
    transition: all 0.3s ease;
    line-height: 1.6;
    font-weight: 400;
}

.mega-menu-link:hover .mega-link-desc {
    color: var(--gray-700);
    transform: translateX(2px);
}

/* Mirror the subtle hover shift in RTL so content moves toward inline-start */
html[lang="ar"] .mega-menu-link:hover .mega-link-title,
html[lang="ar"] .mega-menu-link:hover .mega-link-desc {
    transform: translateX(-2px);
}

.mega-link-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: linear-gradient(135deg, var(--accent-color), #ef4444);
    color: white;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 8px;
    animation: bounce 2s ease-in-out infinite;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4);
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-2px); }
}

.mega-menu-footer {
    border-top: 1px solid rgba(var(--gray-200), 0.6);
    padding: 28px 32px 32px;
    text-align: center;
    background: linear-gradient(135deg, rgba(248, 250, 252, 0.8), rgba(255, 255, 255, 0.95));
    position: relative;
    margin-top: 24px;
    backdrop-filter: blur(10px);
}

.mega-menu-cta {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.mega-cta-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    /* Make the button a bit bigger and allow text to wrap when needed */
    padding: 16px var(--mega-cta-padding-inline, 36px);
    min-width: var(--mega-cta-min-width, 280px);
    white-space: normal;
    overflow-wrap: anywhere; /* Prevent text from overflowing the button */
    text-align: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white !important;
    font-weight: 700;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    box-shadow: 
        0 4px 15px rgba(var(--primary-color-rgb), 0.25),
        0 2px 8px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    letter-spacing: -0.01em;
}

.mega-cta-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s ease;
}

.mega-cta-btn:hover::before {
    left: 100%;
}

.mega-cta-btn:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 
        0 8px 25px rgba(var(--primary-color-rgb), 0.35),
        0 4px 12px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.mega-cta-btn::after {
    content: '→';
    transition: transform 0.3s ease;
    /* Ensure a bit of visual space between text and arrow */
    margin-inline-start: 8px;
}

.mega-cta-btn:hover::after {
    transform: translateX(4px);
}

.mega-cta-text {
    font-size: 12px;
    color: var(--gray-600);
    font-style: italic;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .mega-menu {
        width: 100vw; /* keep full width on medium desktops */
    }
    .mega-menu-link {
        min-height: var(--mega-card-min-height-md, 112px);
    }
    
    .mega-menu-container {
        padding: 32px;
    }
    
    .mega-menu-grid {
        gap: 28px;
    }
}

@media (max-width: 768px) {
    .mega-menu {
        width: 100vw;
        left: 0;
    }
    
    .mega-menu-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    .mega-menu-grid::after { display: none; }
    
    .mega-menu-container {
        padding: 24px;
    }
    /* On smaller viewports, let the CTA button fill the width to prevent overflow */
    .mega-menu-footer .mega-cta-btn {
        width: 100%;
        max-width: 100%;
    }
}

/* Ajout d'un petit triangle indicateur au menu */
.mega-menu::before {
    content: '';
    position: absolute;
    top: 0; /* Do not overlap header */
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid var(--white);
    z-index: 1001;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .mega-menu {
        background: var(--gray-900);
        border-color: var(--gray-800);
    }
    
    .mega-menu::before {
        border-bottom-color: var(--gray-900);
    }
    
    .mega-menu-container {
        background: linear-gradient(135deg, rgba(var(--primary-color-rgb), 0.1), rgba(var(--secondary-color-rgb), 0.1));
    }
    .mega-menu-grid::after { background: var(--gray-800); }
    
    .mega-menu-header h3 {
        background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }
    
    .mega-menu-category h4 {
        color: var(--white);
    }
    
    .mega-link-title {
        color: var(--white);
    }
    
    .mega-menu-link {
        background: rgba(255, 255, 255, 0.05);
        border-color: var(--gray-800);
    }
    
    .mega-menu-link:hover {
        background: rgba(255, 255, 255, 0.1);
        border-color: var(--primary-color);
    }
    .mega-menu-link.active,
    .mega-menu-link[aria-current="page"] {
        background: rgba(255, 255, 255, 0.1);
        border-color: var(--primary-color);
        box-shadow:
            0 10px 24px rgba(var(--primary-color-rgb), 0.25),
            0 3px 10px rgba(0, 0, 0, 0.25),
            0 0 0 1px rgba(var(--primary-color-rgb), 0.2);
    }
    
    .mega-menu-link:hover .mega-link-title {
        color: var(--primary-color);
    }
    .mega-menu-link.active .mega-link-title,
    .mega-menu-link[aria-current="page"] .mega-link-title {
        color: var(--primary-color);
    }
    .mega-menu-footer {
        background: var(--gray-900);
        border-color: var(--gray-800);
    }
    
    .mega-link-desc {
        color: var(--gray-400);
    }
}

/* Animation delays for staggered effect */
.mega-menu-category:nth-child(1) .mega-menu-link {
    animation-delay: 0.1s;
}

.mega-menu-category:nth-child(2) .mega-menu-link {
    animation-delay: 0.2s;
}

.mega-menu-link {
    animation: fadeInUp 0.5s ease-out both;
}

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

/* Keyboard focus styles for accessibility */
.mega-menu-link:focus,
.mega-menu-link:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(var(--primary-color-rgb), 0.15);
    background: linear-gradient(135deg, rgba(var(--primary-color-rgb), 0.06), rgba(var(--secondary-color-rgb), 0.06));
    border-color: var(--primary-color);
}

/* Flex gap fallback for older browsers */
@supports not (gap: 1rem) {
    .mega-menu-link { gap: 0; }
    /* For LTR: icon is on the right, add space before it */
    html:not([lang="ar"]) .mega-menu-link .mega-link-icon { 
        margin-inline-start: var(--mega-icon-text-gap, 48px);
        margin-left: var(--mega-icon-text-gap, 48px); /* Fallback */
    }
    /* For RTL: icon is on the left, add space after it */
    html[lang="ar"] .mega-menu-link .mega-link-icon {
        margin-inline-start: 0;
        margin-inline-end: var(--mega-icon-text-gap, 48px);
        margin-right: var(--mega-icon-text-gap, 48px); /* Fallback */
        margin-left: 0; /* Fallback */
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .mega-menu,
    .mega-menu-link,
    .mega-cta-btn,
    .mega-link-icon {
        transition: none !important;
    }
    .mega-menu-link,
    .mega-cta-btn,
    .mega-link-icon,
    .mega-menu-container::before,
    .mega-menu-header h3,
    .mega-menu-category h4::before,
    .mega-menu-link.featured::after,
    .mega-link-badge {
        animation: none !important;
    }
    .mega-menu-link:hover,
    .mega-cta-btn:hover,
    .mega-menu-link:hover .mega-link-icon {
        transform: none !important;
        box-shadow: none !important;
    }
}
