/**
 * Base CSS Framework
 * Minimal base styles for multi-tenant CMS
 * Theme-specific styles are loaded dynamically
 * Version: 1.9.1 - Mobile Menu Fix
 * Last Updated: 2025-11-17
 */

/* ==============================================
   CSS Reset & Base
   ============================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    overflow-x: hidden;
}

body.menu-open {
    overflow: hidden;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ==============================================
   Header Structure
   ============================================== */

.site-header {
    width: 100%;
    z-index: 1000;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: nowrap;
}

.logo a {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.logo-image {
    max-height: 50px;
    width: auto;
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    white-space: nowrap;
}

.tagline {
    font-size: 0.875rem;
    opacity: 0.8;
    font-weight: 400;
}

/* ==============================================
   Navigation
   ============================================== */

.main-nav {
    display: block;
}

.main-nav ul {
    list-style: none;
    display: flex;
    gap: 8px;
    align-items: center;
}

.main-nav ul li {
    position: relative;
}

.main-nav ul li a {
    text-decoration: none;
    font-weight: 500;
    white-space: nowrap;
}

/* Dropdown Menu */
.has-dropdown {
    position: relative;
}

/* Create invisible bridge between parent and dropdown to prevent gap */
.has-dropdown::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: 12px;
    display: block;
}

.dropdown-arrow {
    margin-left: 4px;
    font-size: 0.75em;
    transition: transform 0.3s ease;
    display: inline-block;
}

.has-dropdown:hover .dropdown-arrow {
    transform: rotate(180deg);
}

.dropdown-menu {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 240px;
    max-width: 320px;
    background: #ffffff;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.06);
    border-radius: 14px;
    margin-top: 0;
    padding: 10px;
    z-index: 1000;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
}

/* Prevent dropdown from going off-screen on the left */
.has-dropdown:first-child .dropdown-menu,
.has-dropdown:nth-child(1) .dropdown-menu,
.has-dropdown:nth-child(2) .dropdown-menu {
    left: auto;
    right: auto;
}

/* For dropdowns that would overflow left edge */
@media (min-width: 769px) {
    .dropdown-menu {
        left: auto;
        right: auto;
        transform-origin: top left;
    }

    /* Smart positioning - stays within viewport */
    .has-dropdown .dropdown-menu {
        left: 0;
    }
}

.has-dropdown:hover > .dropdown-menu,
.dropdown-menu:hover {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
    transition-delay: 0s;
}

.dropdown-menu li {
    display: block;
    list-style: none;
    width: 100%;
    position: relative;
}

.dropdown-menu li:not(:last-child)::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 16px;
    right: 16px;
    height: 1px;
    background: linear-gradient(to right, transparent, #e5e7eb 20%, #e5e7eb 80%, transparent);
    opacity: 0.5;
}

.dropdown-menu li a {
    padding: 12px 16px;
    display: block;
    width: 100%;
    color: #1f2937 !important;
    font-weight: 500;
    font-size: 14px;
    border-radius: 8px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    text-align: left;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.5;
}

.dropdown-menu li a:hover {
    background: rgba(var(--theme-primary-rgb, 99, 102, 241), 0.08);
    color: var(--theme-primary, #6366f1) !important;
    transform: translateX(4px);
    padding-left: 20px;
    box-shadow: none;
    font-weight: 600;
    border-left: 3px solid var(--theme-primary, #6366f1);
}

/* Add subtle hover indicator */
.dropdown-menu li a::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid var(--theme-primary, #6366f1);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    opacity: 0;
    transition: all 0.2s ease;
}

.dropdown-menu li a:hover::before {
    opacity: 1;
    left: 12px;
}

/* Nested dropdowns */
.dropdown-menu .has-dropdown {
    position: relative;
}

/* Invisible bridge for nested dropdowns */
.dropdown-menu .has-dropdown::after {
    content: '';
    position: absolute;
    top: 0;
    left: 100%;
    bottom: 0;
    width: 12px;
    display: block;
}

.dropdown-menu .has-dropdown > a::after {
    content: '›';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    font-weight: bold;
    color: #9ca3af;
    transition: all 0.2s ease;
}

.dropdown-menu .has-dropdown > a:hover::after {
    color: var(--theme-primary, #6366f1);
    right: 12px;
}

.dropdown-menu .has-dropdown .dropdown-menu {
    left: 100%;
    top: -8px;
    margin-top: 0;
    margin-left: 0;
    display: flex;
    flex-direction: column;
}

/* If nested dropdown would overflow right, show on left side */
@media (min-width: 769px) {
    .dropdown-menu .has-dropdown:last-child .dropdown-menu,
    .dropdown-menu .has-dropdown:nth-last-child(2) .dropdown-menu {
        left: auto;
        right: 100%;
        margin-left: 0;
        margin-right: 0;
    }
}

.dropdown-menu .has-dropdown:hover > .dropdown-menu,
.dropdown-menu .has-dropdown .dropdown-menu:hover {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
    transition-delay: 0s;
}

.dropdown-menu .has-dropdown .dropdown-menu li {
    width: 100%;
    display: block;
}

/* ==============================================
   Mobile Menu
   ============================================== */

/* Hide mobile search on desktop */
.mobile-search-container {
    display: none;
}

.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    z-index: 1001;
}

.hamburger-icon {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 24px;
}

.hamburger-icon span {
    height: 3px;
    background: currentColor;
    border-radius: 2px;
    transition: all 0.3s ease;
}

/* Hamburger icon color adaptation based on header style */
.header-gradient .mobile-menu-toggle,
.header-gradient .mobile-menu-toggle .hamburger-icon {
    color: white;
}

.header-solid .mobile-menu-toggle,
.header-transparent .mobile-menu-toggle,
.header-minimal .mobile-menu-toggle {
    color: var(--theme-text, #1f2937);
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

.mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mobile-menu-overlay.is-visible {
    opacity: 1;
    visibility: visible;
}

/* ==============================================
   Main Content
   ============================================== */

.main-content {
    min-height: calc(100vh - 200px);
}

/* ==============================================
   Grid System
   ============================================== */

.grid {
    display: grid;
    gap: 24px;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ==============================================
   Utilities
   ============================================== */

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }

.py-1 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-2 { padding-top: 1rem; padding-bottom: 1rem; }
.py-3 { padding-top: 1.5rem; padding-bottom: 1.5rem; }
.py-4 { padding-top: 2rem; padding-bottom: 2rem; }

.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }

/* ==============================================
   Responsive
   ============================================== */

@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
    /* Show mobile toggle button */
    .mobile-menu-toggle {
        display: block;
        flex-shrink: 0;
        margin-left: auto;
    }

    /* Hide desktop navigation, show as mobile drawer */
    .main-nav {
        position: fixed;
        top: 0;
        right: -100%;
        width: 280px;
        height: 100vh;
        background: #fff;
        padding: 0 0 20px 0;
        overflow-y: auto;
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1002;
        box-shadow: -2px 0 8px rgba(0,0,0,0.1);
        display: flex;
        flex-direction: column;
    }

    /* When menu is open */
    .main-nav.is-open {
        right: 0;
    }

    /* Mobile menu list */
    .main-nav ul {
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 0;
        margin: 0;
        flex: 1;
        overflow-y: auto;
    }

    .main-nav ul li {
        border-bottom: 1px solid #e5e7eb;
    }

    .main-nav ul li a {
        display: block;
        padding: 16px 20px;
        color: #1f2937 !important;
        font-size: 15px;
        font-weight: 500;
        transition: background 0.2s;
    }

    .main-nav ul li a:hover {
        background: #f3f4f6;
        color: var(--theme-primary, #6366f1) !important;
    }

    /* Mobile dropdown */
    .dropdown-menu {
        position: static;
        box-shadow: none;
        opacity: 1;
        visibility: visible;
        transform: none;
        max-height: 0;
        overflow: hidden;
        background: #f9fafb;
        padding: 0;
        margin: 0;
        border-radius: 0;
        transition: max-height 0.3s ease;
    }

    .has-dropdown.is-open > .dropdown-menu {
        max-height: 500px;
    }

    .dropdown-menu li {
        border-bottom: none;
    }

    .dropdown-menu li a {
        padding: 12px 20px 12px 40px;
        font-size: 14px;
        color: #4b5563 !important;
    }

    .dropdown-menu li a:hover {
        background: #e5e7eb;
        color: var(--theme-primary, #6366f1) !important;
    }

    .has-dropdown.is-open > a .dropdown-arrow {
        transform: rotate(180deg);
    }

    /* Mobile Search Container - at top of mobile menu */
    .mobile-search-container {
        display: flex;
        align-items: center;
        padding: 15px;
        background: #f9fafb;
        border-bottom: 2px solid #e5e7eb;
        margin-bottom: 0;
        position: sticky;
        top: 0;
        z-index: 10;
        flex-shrink: 0;
        min-height: 70px;
        height: 70px;
    }

    .mobile-search-container .search-widget {
        max-width: 100%;
        width: 100%;
        position: static;
    }

    .mobile-search-container .search-input-container {
        width: 100%;
        display: flex;
        align-items: center;
        position: relative;
        background: white;
        border: 2px solid #e5e7eb;
        border-radius: 10px;
        transition: all 0.3s ease;
        overflow: hidden;
    }

    .mobile-search-container .search-input-container:focus-within {
        border-color: var(--theme-primary, #2563eb);
        box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    }

    /* Mobile search icon */
    .mobile-search-container .search-icon {
        position: absolute;
        left: 15px;
        top: 50%;
        transform: translateY(-50%);
        color: #9ca3af;
        display: flex;
        align-items: center;
        justify-content: center;
        pointer-events: none;
        z-index: 1;
    }

    /* Mobile search input - specific padding for icon and button */
    .mobile-search-container #mobile-search-input {
        flex: 1;
        padding: 12px 52px 12px 45px;
        border: none;
        font-size: 0.95rem;
        outline: none;
        background: transparent;
        width: 100%;
    }

    .mobile-search-container #mobile-search-input::placeholder {
        color: #9ca3af;
    }

    /* Mobile voice search button */
    .mobile-search-container #mobile-voice-search-btn {
        position: absolute;
        right: 10px;
        top: 50%;
        transform: translateY(-50%);
        background: transparent;
        border: none;
        padding: 8px;
        cursor: pointer;
        color: #6b7280;
        transition: all 0.3s;
        border-radius: 6px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-search-container #mobile-voice-search-btn:hover {
        background: #e5e7eb;
        color: var(--theme-primary, #2563eb);
    }

    /* Mobile search dropdown - positioned relative to mobile menu drawer */
    .mobile-search-container #mobile-search-dropdown {
        position: absolute;
        top: calc(100% + 0px);
        left: 0;
        right: 0;
        width: 100%;
        max-height: 60vh;
        overflow-y: auto;
        z-index: 1003;
        background: white;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }

    /* Grid adjustments */
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .logo-text {
        font-size: 1.25rem;
    }

    .tagline {
        font-size: 0.75rem;
    }
}

/* ==============================================
   Dropdown Special Cases
   ============================================== */

/* Ensure dropdown arrow is visible on gradient headers */
.header-style-gradient .has-dropdown .dropdown-arrow {
    color: rgba(255, 255, 255, 0.9);
}

/* Smooth animation for dropdown appearance */
@keyframes dropdownSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.has-dropdown:hover > .dropdown-menu {
    animation: dropdownSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==============================================
   Header Scroll Effect
   ============================================== */

.site-header.scrolled {
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}

.theme-minimal .site-header.scrolled,
.theme-transparent .site-header.scrolled {
    background: white;
    color: var(--theme-text);
}

/* ==============================================
   Animation Classes
   ============================================== */

.fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.slide-up {
    animation: slideUp 0.5s ease-out;
}

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

/* ==============================================
   Print Styles
   ============================================== */

@media print {
    .site-header,
    .mobile-menu-toggle,
    .mobile-menu-overlay {
        display: none;
    }
}
