/**
 * KSM Menu - Frontend Styles
 * Desktop and Mobile Navigation with Mega Menu
 */

/* ====================
   DESKTOP NAVIGATION
   ==================== */

.ksm-navigation--desktop {
    position: relative;
    width: 100%;
    padding: 0;
    margin: 0;
    z-index: 1000;
}

.ksm-menu {
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 2rem;
    border-bottom: 2px solid var(--light);
}

.ksm-menu__item {
    position: static; /* Changed from relative to static so mega menu positions relative to nav */
    margin: 0;
    padding: 0;
}

.ksm-menu__link {
    display: flex;
    align-items: center;
    padding: 1.2rem 1.5rem;
    text-decoration: none;
    color: inherit;
    font-size: var(--ksm-desktop-menu-font-size, 1rem);
    transition: color 0.2s ease;
    position: relative;
    text-transform: var(--ksm-text-transform, none);
}

.ksm-menu__link:hover {
    color: var(--ksm-font-hover-color, #0073aa);
}

.ksm-menu__item--current > .ksm-menu__link {
    color: var(--ksm-font-active-color, #005a87);
    font-weight: 600;
}

/* Parent indicator (triangle) - positioned outside wrapper */
.ksm-menu__item--has-children > .ksm-menu__link::after {
    content: '';
    position: absolute;
    top: calc(100% - 0px); /* Position higher to overlap border */
    left: 50%;
    transform: translateX(-50%);
    width: 32px; /* Increased from 24px */
    height: 16px; /* Increased from 12px */
    /* Use background color from CSS variable for the triangle fill */
    background: var(--ksm-arrow-color, currentColor);
    /* Mask the triangle shape */
    -webkit-mask-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="12" viewBox="0 0 24 12"><path d="M 12 12 L 0 0 L 24 0 Z" fill="black"/></svg>');
    mask-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="12" viewBox="0 0 24 12"><path d="M 12 12 L 0 0 L 24 0 Z" fill="black"/></svg>');
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    /* Overlay the white stroke lines as a separate background layer */
    background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="12" viewBox="0 0 24 12"><line x1="0" y1="0" x2="12" y2="12" stroke="white" stroke-width="2" stroke-linecap="round"/><line x1="24" y1="0" x2="12" y2="12" stroke="white" stroke-width="2" stroke-linecap="round"/></svg>');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.15));
    opacity: 1;
    z-index: 1001; /* Higher z-index to sit above border */
    margin-top: 0;
}

.ksm-menu__item--has-children:hover > .ksm-menu__link::after {
    opacity: 1;
}

/* Hover indicator line */
.ksm-menu__item--has-children:hover > .ksm-menu__link::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    height: 3px;
    background-color: currentColor;
}

/* ====================
   MEGA MENU (Desktop Submenu)
   ==================== */

.ksm-mega-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 100vw;
    background-color: var(--ksm-submenu-bg-color, #f7f7f7);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 999;
    padding: 2rem 0;
}

.ksm-mega-menu__container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
}

.ksm-mega-menu__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
}

.ksm-mega-menu__item {
    display: flex;
}

.ksm-mega-menu__link {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    text-decoration: none;
    color: var(--ksm-submenu-font-color, inherit);
    border-radius: 8px;
    transition: background-color 0.2s ease, transform 0.2s ease, color 0.2s ease;
    width: 100%;
}

.ksm-mega-menu__link:hover {
    background-color: rgba(0, 0, 0, 0.05);
    transform: translateY(-2px);
    color: var(--ksm-submenu-font-hover-color, #0073aa);
}

.ksm-mega-menu__image {
    flex-shrink: 0;
    width: 120px;
    height: 80px;
    object-fit: cover;
    border-radius: 6px;
    margin-top:auto;
    margin-bottom:auto;
}

.ksm-mega-menu__content {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.ksm-mega-menu__title {
    font-size: var(--ksm-desktop-submenu-title-font-size, 1.1rem);
    font-weight: 600;
    color: var(--ksm-submenu-font-color, inherit);
    text-transform: var(--ksm-text-transform, none);
    line-height:1;
}

.ksm-mega-menu__excerpt {
    font-size: var(--ksm-desktop-submenu-excerpt-font-size, 0.9rem);
    color: var(--ksm-submenu-excerpt-font-color, #666);
    line-height: 1.4;
    opacity: 0.8;
}

/* Second level submenu */
.ksm-submenu {
    list-style: none;
    margin: 0.5rem 0 0 0;
    padding: 0;
}

.ksm-submenu__link {
    display: block;
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: var(--ksm-submenu-font-color, inherit);
    font-size: 0.95rem;
    transition: background-color 0.2s ease, color 0.2s ease;
    border-radius: 4px;
    text-transform: var(--ksm-text-transform, none);
}

.ksm-submenu__link:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--ksm-submenu-font-hover-color, #0073aa);
}

/* ====================
   MOBILE NAVIGATION
   ==================== */

.ksm-navigation--mobile {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background-color: #ffffff;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    overflow-y: auto;
    transition-property: transform, opacity, visibility;
    transition-duration: 300ms;
    transition-timing-function: ease-in-out;
}

/* Mobile menu animations */
.ksm-animation--fade {
    opacity: 0;
    visibility: hidden;
}

.ksm-animation--fade.ksm-navigation--visible {
    opacity: 1;
    visibility: visible;
}

.ksm-animation--slide-right {
    transform: translateX(100%);
    visibility: hidden;
}

.ksm-animation--slide-right.ksm-navigation--visible {
    transform: translateX(0);
    visibility: visible;
}

.ksm-animation--slide-left {
    transform: translateX(-100%);
    visibility: hidden;
}

.ksm-animation--slide-left.ksm-navigation--visible {
    transform: translateX(0);
    visibility: visible;
}

.ksm-animation--slide-top {
    transform: translateY(-100%);
    visibility: hidden;
}

.ksm-animation--slide-top.ksm-navigation--visible {
    transform: translateY(0);
    visibility: visible;
}

.ksm-animation--slide-bottom {
    transform: translateY(100%);
    visibility: hidden;
}

.ksm-animation--slide-bottom.ksm-navigation--visible {
    transform: translateY(0);
    visibility: visible;
}

/* Mobile overlay */
.ksm-mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9999;
}

/* Mobile menu header */
.ksm-mobile-menu__header {
    display: flex;
    justify-content: flex-end;
    padding: 1rem;
    border-bottom: 1px solid #e0e0e0;
}

.ksm-mobile-menu__close {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: var(--secondary, #333);
    border: none;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 1rem 1.5rem;
    color: #fff;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    font-weight: 600;
}

.ksm-mobile-menu__close:hover {
    background-color: var(--primary, #000);
}

.ksm-mobile-menu__close-icon {
    font-size: 2.5rem;
    line-height: 1;
}

.ksm-mobile-menu__close-text {
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ksm-mobile-menu__close-icon {
    display: block;
}

/* Mobile menu content */
.ksm-mobile-menu__content {
    padding: 1rem 0;
}

.ksm-mobile-menu__loading {
    padding: 2rem;
    text-align: center;
    color: #666;
}

.ksm-mobile-menu__error {
    padding: 2rem;
    text-align: center;
    color: #d63638;
}

/* Mobile menu list */
.ksm-mobile-menu__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.ksm-mobile-menu__item {
    border-bottom: 1px dotted #ddd;
}

.ksm-mobile-menu__item-wrapper {
    display: flex;
    align-items: center;
    position: relative;
}

.ksm-mobile-menu__link {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1rem;
    text-decoration: none;
    color: inherit;
    font-size: var(--ksm-mobile-menu-font-size, 1rem);
    transition: background-color 0.2s ease;
}

.ksm-mobile-menu__link:active {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Mobile menu images */
.ksm-mobile-menu__image {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    border:1px solid var(--light);
}

.ksm-mobile-menu__content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.ksm-mobile-menu__title {
    font-size: var(--ksm-mobile-submenu-title-font-size, 1rem);
    font-weight: 600;
    color: var(--ksm-mobile-title-font-color, inherit);
    text-transform: var(--ksm-text-transform, none);
}

.ksm-mobile-menu__excerpt {
    font-size: var(--ksm-mobile-submenu-excerpt-font-size, 0.85rem);
    color: var(--ksm-mobile-excerpt-font-color, #666);
    line-height: 1.3;
}

/* Mobile menu toggle arrow */
.ksm-mobile-menu__toggle {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--ksm-arrow-bg-color, #f0f0f0);
    border: none;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.ksm-mobile-menu__toggle:active {
    background-color: rgba(0, 0, 0, 0.1);
}

.ksm-mobile-menu__arrow {
    display: block;
    font-size: 1.2rem;
    transition: transform 0.2s ease;
}

.ksm-mobile-menu__toggle[aria-expanded="true"] .ksm-mobile-menu__arrow {
    transform: rotate(90deg);
}

/* Mobile submenu */
.ksm-mobile-menu__submenu {
    display: none;
    background-color: var(--ksm-mobile-submenu-bg-color, rgba(0, 0, 0, 0.02));
    padding-left: 1rem;
}

.ksm-mobile-menu__item--expanded > .ksm-mobile-menu__submenu {
    display: block;
}

/* Current page highlight */
.ksm-mobile-menu__item--current > .ksm-mobile-menu__item-wrapper {
    background-color: var(--ksm-mobile-submenu-item-active-bg-color, rgba(0, 115, 170, 0.1));
}

/* Hover state for submenu items */
.ksm-mobile-menu__submenu .ksm-mobile-menu__link:hover .ksm-mobile-menu__title {
    color: var(--ksm-mobile-title-font-hover-color, #0073aa);
}

.ksm-mobile-menu__submenu .ksm-mobile-menu__link:active {
    background-color: var(--ksm-mobile-submenu-item-active-bg-color, rgba(0, 0, 0, 0.05));
}



/* Mobile menu footer (widget area) */
.ksm-mobile-menu__footer {
    margin-top:2rem;
    padding: 1rem;
}

.ksm-mobile-widget {
    margin-bottom: 1rem;
}

.ksm-mobile-widget:last-child {
    margin-bottom: 0;
}

.ksm-mobile-widget__title {
    font-size: 2rem;
    font-weight: 600;
    margin: 0 0 0.5rem 0;
    text-align: center;
    border-bottom: 5px solid var(--accent);
    margin-bottom: 1rem;
}.ksm-mobile-widget .textwidget {
    margin-top: 3rem;
}
/* Mobile trigger button */
.ksm-mobile-trigger {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
}

.ksm-mobile-trigger__icon {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 28px;
}

.ksm-mobile-trigger__icon span {
    display: block;
    height: 3px;
    background-color: var(--light);
    transition: transform 0.2s ease;
}

/* Body scroll lock when menu open */
body.ksm-menu-open {
    overflow: hidden;
}

/* ====================
   RESPONSIVE DESIGN
   ==================== */

@media screen and (max-width: 992px) {
    /* Hide desktop menu */
    .ksm-navigation--desktop {
        display: none;
    }

    /* Show mobile trigger */
    .ksm-mobile-trigger {
        display: flex;
    }

    /* Mobile menu structure (hidden by default, shown with animation classes) */
    .ksm-navigation--mobile {
        display: block;
        flex-direction: column;
    }
}

@media screen and (min-width: 993px) {
    /* Hide mobile elements on desktop */
    .ksm-mobile-overlay,
    .ksm-navigation--mobile {
        display: none !important;
    }
}

/* ====================
   ACCESSIBILITY
   ==================== */

.ksm-menu__link:focus,
.ksm-mobile-menu__link:focus,
.ksm-mobile-menu__toggle:focus,
.ksm-mobile-menu__close:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* Skip link */
.ksm-skip-link {
    position: absolute;
    top: -999px;
    left: -999px;
}

.ksm-skip-link:focus {
    top: 0;
    left: 0;
    z-index: 100000;
    background: #fff;
    padding: 1rem;
    border: 2px solid #0073aa;
}

/* Screen reader only */
.ksm-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}
