/* --- Variables --- */
:root {
    --tm-purple: #3d2b4f;
    --tm-blue-btn: #b2c8d8;
    --tm-bg-cream: #fdfaf3;
}

/* --- Header Reset & Transparency --- */
#site-header.main-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    padding: 1rem 2rem;
    background-color: transparent !important;
    /* Height is handled by JS for the mega menu expansion */
    transition: background-color 0.3s ease, height 0.4s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease;
    overflow: visible;
    border: none;
}

/* White background on Hover (is-active) or Scroll (is-sticky) */
#site-header.main-header.is-active,
#site-header.main-header.is-sticky {
    background-color: #ffffff !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
}

.header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0 auto;
    position: relative;
}

/* Admin Bar Adjustments */
.admin-bar .main-header { top: 32px; }
@media screen and (max-width: 782px) { .admin-bar .main-header { top: 46px; } }

.header-logo img {
    max-width: 93px;
    height: auto;
    display: block;
    transition: filter 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Logo Color Filter #462850 */
.main-header:hover .header-logo img,
.main-header.is-sticky .header-logo img {
    filter: brightness(0) invert(15%) sepia(21%) saturate(2251%) hue-rotate(247deg) brightness(96%) contrast(92%);
}

/* --- Navigation --- */
.desktop-nav {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    position: static; /* Required for the sub-menu to align to the header container */
}

ul.nav-menu {
    display: flex !important;
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 40px;
}

/* The Hover Bridge: Prevents menu closing when moving mouse toward sub-menu */
ul.nav-menu > li {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

ul.nav-menu > li::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    height: 30px; /* This "fills the gap" between top item and mega menu */
}

ul.nav-menu > li > a {
    text-decoration: none;
    color: #ffffff;
    font-size: 18px;
    font-weight: 400;
    padding: 10px 0;
    display: flex;
    align-items: center;
    transition: color 0.3s ease;
}

#site-header.main-header.is-active ul.nav-menu > li > a,
#site-header.main-header.is-sticky ul.nav-menu > li > a {
    color: var(--tm-purple);
}

/* --- Sliding Underline --- */
#moving-underline {
    position: absolute;
    bottom: 5px; /* Aligned with text bottom */
    height: 2px;
    background-color: var(--tm-purple);
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    opacity: 0;
    pointer-events: none;
    z-index: 10;
}

/* --- Mega Menu (Left Aligned) --- */
ul.nav-menu .sub-menu {
    position: absolute;
    top: 100%;
    left: 2rem; /* Aligns with the logo/flex container start */
    width: auto;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    padding: 20px 0 40px 0;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: translateY(10px);
    list-style: none !important;
    z-index: 100;
}

ul.nav-menu li:hover > .sub-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

ul.nav-menu .sub-menu li a {
    color: var(--tm-purple);
    text-decoration: none;
    padding: 10px 0;
    font-size: 32px; /* Matching the high-end look of your screenshot */
    display: inline-block;
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0.5;
}

ul.nav-menu .sub-menu li a:hover {
    opacity: 1;
    transform: translateX(15px);
}

/* --- Rotating Arrows --- */
.menu-item-has-children > a::after {
    content: '';
    display: inline-block;
    width: 10px;
    height: 6px;
    margin-left: 8px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 10 6'%3E%3Cpath stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m1 1 4 4 4-4'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    transition: transform 0.3s ease;
}

#site-header.main-header.is-active .menu-item-has-children > a::after,
#site-header.main-header.is-sticky .menu-item-has-children > a::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 10 6'%3E%3Cpath stroke='%233d2b4f' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m1 1 4 4 4-4'/%3E%3C/svg%3E");
}

.menu-item-has-children:hover > a::after { transform: rotate(180deg); }

/* --- Actions --- */
.header-actions { display: flex; align-items: center; gap: 20px; }
.phone-link svg { stroke: #ffffff; transition: stroke 0.3s ease; }
#site-header.main-header.is-active .phone-link svg,
#site-header.main-header.is-sticky .phone-link svg { stroke: var(--tm-purple); }

.btn-find-teacher {
    background: var(--tm-blue-btn);
    color: var(--tm-purple);
    padding: 12px 28px;
    border-radius: 50px;
    text-decoration: none;
    font-weight: 500;
    transition: transform 0.2s ease, background 0.2s ease;
}
.btn-find-teacher:hover { transform: scale(1.05); }

/* --- Clean Mobile Menu Items --- */
#mobile-menu-overlay ul {
    list-style: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

#mobile-menu-overlay li {
    list-style: none !important;
    padding: 0 !important;
    margin-bottom: 25px; /* Spacing between links */
}

#mobile-menu-overlay li a {
    font-size: 32px; /* Matching the high-end look */
    color: var(--tm-purple);
    text-decoration: none !important; /* Removes default underlines */
    display: inline-block;
    opacity: 0.6;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Apply the "Slide to Right" effect on mobile tap/hover */
#mobile-menu-overlay li a:active,
#mobile-menu-overlay li a:hover {
    opacity: 1;
    transform: translateX(15px);
    color: var(--tm-purple);
}

/* Hide the arrows and sub-menus on mobile to keep it a flat, clean list 
   (unless you specifically want nested dropdowns on mobile too) */
#mobile-menu-overlay .sub-menu {
    display: none; 
}

/* Ensure the X icon is purple when the menu is open over the cream background */
.mobile-toggle.is-open span {
    background-color: var(--tm-purple) !important;
}

/* --- Desktop Enforcements (1025px and up) --- */
@media (min-width: 1025px) {
    #mobile-menu-overlay, 
    .mobile-toggle,
    div[id*="mobile-menu"] { /* Catch-all for potential ID variations */
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
}

/* --- Mobile Enforcements (1024px and down) --- */
@media (max-width: 1024px) {
    .desktop-nav, 
    #moving-underline {
        display: none !important;
    }
    
    .mobile-toggle {
        display: flex !important;
    }
}

/* --- The Underline Precision --- */
#moving-underline {
    position: absolute;
    bottom: 0; /* Attach to the bottom of the desktop-nav container */
    height: 2px;
    background-color: var(--tm-purple);
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    opacity: 0;
    pointer-events: none;
    z-index: 100; /* Ensure it sits above background elements */
}