/**
 * Layout Base Styles (Mobile-First)
 * Shared foundation for all layouts
 *
 * CSS Variables expected:
 * --primary-color: Primary color (e.g., #667eea)
 */

/* Page Loading Bar */
.page-loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 3px;
    background: var(--primary-color);
    z-index: 99999;
    transition: none;
    pointer-events: none;
}
.page-loading-bar.active {
    animation: pageLoadProgress 8s cubic-bezier(0.2, 0.5, 0.1, 1) forwards;
}
.page-loading-bar.done {
    width: 100%;
    animation: none;
    transition: opacity 0.3s 0.1s;
    opacity: 0;
}
@keyframes pageLoadProgress {
    0%   { width: 0; }
    10%  { width: 25%; }
    30%  { width: 50%; }
    50%  { width: 70%; }
    70%  { width: 85%; }
    90%  { width: 92%; }
    100% { width: 95%; }
}

/* Page Logo Loader */
.page-logo-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: color-mix(
        in srgb,
        var(--primary-color) 20%,
        transparent
    );
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.4s, visibility 0.4s;
}
.page-logo-loader.done {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.page-logo-loader-inner {
    text-align: center;
}
.page-logo-loader-ring {
    position: relative;
    width: 160px;
    height: 160px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto;
}
.page-logo-loader-ring::before {
    content: '';
    position: absolute;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--primary-color);
    animation: pageLogoSpin 1.6s linear infinite;
}
.page-logo-loader-ring img {
    width: 90px;
    max-height: 90px;
    object-fit: contain;
    z-index: 2;
    animation: pageLogoBreathe 3s ease-in-out infinite;
}
.page-logo-loader-text {
    margin-top: 20px;
    font-size: 13px;
    letter-spacing: 1px;
    color: var(--primary-color);
    text-transform: uppercase;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
@keyframes pageLogoSpin {
    to { transform: rotate(360deg); }
}
@keyframes pageLogoBreathe {
    0%, 100% { transform: scale(1); opacity: 0.95; }
    50% { transform: scale(1.06); opacity: 1; }
}

/* Prevent logo flickering on load */
.app-nav .logo img {
    opacity: 0;
    animation: logoFadeIn 0.3s ease forwards;
}
@keyframes logoFadeIn {
    to { opacity: 1; }
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { min-height: 100vh; overflow-x: hidden; margin: 0; padding: 0; }
*, *::before, *::after { box-sizing: border-box; }
img, video { max-width: 100%; height: auto; display: block; }

.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 20px; }

.global-header {
    background: linear-gradient(135deg, var(--primary-color), #764ba2);
    color: white;
    padding: 10px 20px;
    text-align: center;
    font-size: 14px;
}
.global-header a { color: white; text-decoration: underline; }

button, .btn, .btn-primary, a.btn, input[type='submit'] {
    min-height: 44px;
    touch-action: manipulation;
    cursor: pointer;
}

.form-container { width: 100%; max-width: 600px; margin: 0 auto; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 500; }
.form-control {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    transition: border-color 0.3s, box-shadow 0.3s;
    -webkit-appearance: none;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102,126,234,0.15);
}

.features-grid, .cards-grid {
    display: grid;
    gap: 25px;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.mobile-menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: inherit;
    padding: 0;
}

.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s;
}
.mobile-overlay.active { display: block; opacity: 1; }

@media (max-width: 768px) {
    html { font-size: 15px; }
    .container { padding: 0 15px; }
    .section { padding: 40px 0; }

    .mobile-menu-toggle { display: flex; }

    .app-nav .container {
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-direction: row-reverse;
    }

    .app-nav ul {
        position: fixed;
        justify-content: flex-start;
        top: 0;
        left: -100%;
        width: 85%;
        max-width: 320px;
        height: 100vh;
        background: white;
        flex-direction: column;
        padding: 80px 25px 25px;
        transition: left 0.3s ease;
        z-index: 999;
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
        margin: 0;
        list-style: none;
        overflow-y: auto;
    }

    .app-nav ul.open { left: 0; }

    .app-nav ul li { width: 100%; margin-bottom: 5px; }

    .app-nav ul a {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 14px 18px;
        border-radius: 10px;
        color: #333 !important;
        text-decoration: none;
        font-weight: 500;
        transition: all 0.2s;
    }

    .app-nav ul a:hover, .app-nav ul a.active {
        background: var(--primary-color);
        color: white !important;
    }

    /* Force single column layouts on mobile */
    .cards-grid, .features-grid {
        display: block !important;
    }
    .cards-grid > *, .features-grid > * {
        margin-bottom: 15px;
    }

    /* Override inline grid styles - exclude calendars */
    .gallery-grid, .stats-row, .quick-actions-grid {
        display: block !important;
    }
    .gallery-grid > *, .stats-row > *, .quick-actions-grid > * {
        margin-bottom: 15px;
    }
}

/* Modules in Profile Dropdown (desktop) */
.mobile-only-modules { display: none !important; }
.user-dropdown-modules {
    border-top: 1px solid #eee;
    padding-top: 4px;
    margin-top: 4px;
}
.user-dropdown-modules-label {
    padding: 10px 20px 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #999;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}
.user-dropdown-modules-label:hover {
    color: #666;
}
.user-dropdown-modules-label i {
    font-size: 12px;
    color: var(--primary-color);
}
.modules-toggle-icon {
    margin-left: auto;
    font-size: 10px !important;
    color: #bbb !important;
    transition: transform 0.2s;
}
.user-dropdown-modules.expanded .modules-toggle-icon {
    transform: rotate(180deg);
}
.user-dropdown-modules-list {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}
.user-dropdown-modules.expanded .user-dropdown-modules-list {
    max-height: 500px;
}
.user-dropdown-modules a {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    padding: 10px 20px 10px 28px !important;
    color: #333 !important;
    text-decoration: none !important;
    transition: background 0.2s !important;
    font-size: 13px !important;
    background: transparent !important;
    border-radius: 0 !important;
    font-weight: normal !important;
}
.user-dropdown-modules a:hover {
    background: #f5f5f5 !important;
    color: var(--primary-color) !important;
}
.user-dropdown-modules a i {
    width: 18px;
    text-align: center;
    color: var(--primary-color);
    font-size: 13px;
}

/* Modules Menu - Mobile standalone */
.nav-modules-menu { list-style: none !important; }
.modules-menu-wrapper { position: relative; display: flex; align-items: center; }
.modules-menu-btn {
    background: none !important;
    border: none !important;
    cursor: pointer;
    padding: 8px 12px !important;
    font-size: 14px !important;
    color: var(--primary-color) !important;
    border-radius: 8px !important;
    transition: all 0.2s;
    display: flex !important;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}
.modules-menu-btn:hover { background: rgba(0,0,0,0.05) !important; }
.modules-menu-dropdown {
    display: none;
    position: relative;
    width: 100%;
    margin-top: 5px;
    background: #f8f9fa;
    border-radius: 10px;
    overflow: hidden;
}
.modules-menu-dropdown.show { display: block !important; }
.modules-menu-dropdown a {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    padding: 12px 18px 12px 36px !important;
    color: #555 !important;
    text-decoration: none !important;
    transition: background 0.2s !important;
    font-size: 14px !important;
    background: transparent !important;
    border-radius: 0 !important;
    font-weight: normal !important;
    border-bottom: 1px solid #eee;
}
.modules-menu-dropdown a:last-child { border-bottom: none; }
.modules-menu-dropdown a:hover {
    background: var(--primary-color) !important;
    color: white !important;
}
.modules-menu-dropdown a:hover i { color: white !important; }
.modules-menu-dropdown a i {
    width: 20px;
    text-align: center;
    color: var(--primary-color);
    font-size: 14px;
}

@media (max-width: 768px) {
    /* Show standalone modules menu on mobile, hide from profile dropdown */
    .mobile-only-modules { display: list-item !important; }
    .user-dropdown-modules { display: none !important; }
    .nav-modules-menu {
        width: 100%;
        border-top: 1px solid #eee;
        padding-top: 10px;
        margin-top: 10px;
    }
    .modules-menu-wrapper {
        flex-direction: column;
        width: 100%;
    }
    .modules-menu-btn {
        width: 100%;
        justify-content: flex-start;
        padding: 14px 18px !important;
        color: #333 !important;
        font-size: 15px !important;
        border-radius: 10px !important;
    }
    .modules-menu-btn:hover {
        background: var(--primary-color) !important;
        color: white !important;
    }
}

@media (max-width: 480px) {
    .hero h1 { font-size: 1.75rem; line-height: 1.2; }
    .btn-primary, .btn { width: 100%; text-align: center; }
}

/* User Menu Dropdown - Global */
.nav-user-menu {
    list-style: none !important;
    position: fixed !important;
    top: 20px !important;
    right: 20px !important;
    z-index: 9999 !important;
}
.user-menu-wrapper { position: relative; display: flex; align-items: center; }
.user-menu-btn {
    background: none !important;
    border: none !important;
    cursor: pointer;
    padding: 8px !important;
    font-size: 28px !important;
    color: var(--primary-color) !important;
    border-radius: 50% !important;
    transition: all 0.2s;
    display: flex !important;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.user-menu-btn:hover { background: rgba(0,0,0,0.05) !important; }
.user-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    min-width: 220px;
    z-index: 9999;
    overflow: hidden;
    border: 1px solid #e0e0e0;
}
.user-dropdown.show { display: block !important; }
.user-dropdown-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--primary-color), #764ba2);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.user-dropdown-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.user-dropdown-header-left i { font-size: 32px; }
.user-dropdown-header-left span { font-weight: 600; font-size: 15px; }
.user-dropdown-header > i { font-size: 32px; }
.user-dropdown-header > span { font-weight: 600; font-size: 15px; }
.switch-app-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.2);
    border-radius: 8px;
    color: #fff;
    text-decoration: none;
    transition: all 0.2s;
}
.switch-app-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: scale(1.05);
}
.switch-app-btn i { font-size: 16px !important; }
.user-dropdown-menu {
    padding: 8px 0;
    background: #fff;
    max-height: 60vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
}
.user-dropdown-menu::-webkit-scrollbar { width: 5px; }
.user-dropdown-menu::-webkit-scrollbar-track { background: transparent; }
.user-dropdown-menu::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
.user-dropdown-menu::-webkit-scrollbar-thumb:hover { background: #aaa; }
.user-dropdown-menu a {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    padding: 12px 20px !important;
    color: #333 !important;
    text-decoration: none !important;
    transition: background 0.2s !important;
    font-size: 14px !important;
    background: transparent !important;
    border-radius: 0 !important;
    font-weight: normal !important;
}
.user-dropdown-menu a:hover {
    background: #f5f5f5 !important;
    color: var(--primary-color) !important;
}
.user-dropdown-menu a i {
    width: 18px;
    color: #888;
    font-size: 14px;
}
.user-dropdown-menu a:hover i { color: var(--primary-color); }
.user-dropdown-divider { height: 1px; background: #eee; margin: 8px 0; }
.user-dropdown-menu .logout-link { color: #dc3545 !important; }
.user-dropdown-menu .logout-link:hover { background: #fff5f5 !important; color: #dc3545 !important; }
.user-dropdown-menu .logout-link i { color: #dc3545 !important; }

/* Language Menu Dropdown - Global */
.nav-lang-menu { list-style: none !important; }
.lang-menu-wrapper { position: relative; display: flex; align-items: center; }
.lang-menu-btn {
    background: none !important;
    border: none !important;
    cursor: pointer;
    padding: 8px 12px !important;
    font-size: 14px !important;
    color: var(--primary-color) !important;
    border-radius: 8px !important;
    transition: all 0.2s;
    display: flex !important;
    align-items: center;
    gap: 6px;
}
.lang-menu-btn:hover { background: rgba(0,0,0,0.05) !important; }
.lang-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    min-width: 100px;
    z-index: 9999;
    overflow: hidden;
    border: 1px solid #e0e0e0;
}
.lang-dropdown.show { display: block !important; }
.lang-dropdown-menu { padding: 6px 0; }
.lang-dropdown-menu a {
    display: block !important;
    padding: 10px 18px !important;
    color: #333 !important;
    text-decoration: none !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    transition: background 0.2s !important;
    text-align: center;
}
.lang-dropdown-menu a:hover {
    background: #f5f5f5 !important;
    color: var(--primary-color) !important;
}
.lang-dropdown-menu a.active {
    background: var(--primary-color) !important;
    color: #fff !important;
}

/* Mobile User Menu - Fixed Top Right */
@media (max-width: 768px) {
    /* Move notification bell to fixed position */
    .nav-notify-menu {
        position: fixed !important;
        top: 10px;
        right: 104px;
        z-index: 1002;
        margin: 0 !important;
        padding: 0 !important;
    }
    .notify-btn {
        background: #fff !important;
        box-shadow: 0 2px 10px rgba(0,0,0,0.1) !important;
        border-radius: 50% !important;
        width: 40px !important;
        height: 40px !important;
        font-size: 18px !important;
    }

    /* Move user menu to fixed position in top right */
    .nav-user-menu {
        position: fixed !important;
        top: 10px;
        right: 60px;
        z-index: 1002;
        margin: 0 !important;
        padding: 0 !important;
    }

    .user-menu-wrapper {
        position: static;
    }

    .user-menu-btn {
        background: #fff !important;
        box-shadow: 0 2px 10px rgba(0,0,0,0.1) !important;
        border-radius: 50% !important;
        width: 40px !important;
        height: 40px !important;
        font-size: 20px !important;
    }

    .user-dropdown {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        border-radius: 20px 20px 0 0 !important;
        max-height: 70vh !important;
        overflow-y: auto !important;
        z-index: 10000 !important;
        box-shadow: 0 -5px 30px rgba(0,0,0,0.2) !important;
    }

    .user-dropdown.show {
        animation: slideUpDropdown 0.3s ease;
    }

    @keyframes slideUpDropdown {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    /* Overlay for mobile dropdown */
    .user-dropdown-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 9999;
    }
    .user-dropdown-overlay.show {
        display: block;
    }

    /* Language menu - stays in nav menu on mobile */
    .nav-lang-menu {
        width: 100%;
        margin-top: 10px;
        padding-top: 10px;
        border-top: 1px solid #eee;
    }

    .nav-lang-menu .lang-menu-wrapper {
        width: 100%;
    }

    .nav-lang-menu .lang-menu-btn {
        width: 100%;
        justify-content: center;
        background: #f5f5f5 !important;
        border-radius: 8px !important;
        padding: 12px 16px !important;
    }

    .nav-lang-menu .lang-dropdown {
        position: relative !important;
        top: auto !important;
        right: auto !important;
        width: 100%;
        margin-top: 8px;
        box-shadow: none !important;
        border: 1px solid #eee !important;
    }
}
