/* ============================================
   NAVIGATION - Almanik PMS
   Version: 1.1
   Date: 2025-12-17
   Updated: 2025-12-17 - FASE 1 fixes
   ============================================ */

/* CSS Custom Properties for easy theming */
:root {
    --nav-bg-start: #1e40af;
    --nav-bg-end: #2563eb;
    --nav-text: white;
    --nav-hover: rgba(255,255,255,0.15);
    --nav-active: rgba(255,255,255,0.2);
    --nav-height: 60px;
    --nav-breakpoint: 900px;
    --dropdown-bg: white;
    --dropdown-text: #374151;
    --dropdown-hover: #f3f4f6;
    --dropdown-active-bg: #eff6ff;
    --dropdown-active-text: #2563eb;
}

/* Reset and base */
.main-nav {
    background: linear-gradient(135deg, var(--nav-bg-start) 0%, var(--nav-bg-end) 100%);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 60px;
}

/* Logo */
.nav-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: white;
    font-weight: 700;
    font-size: 1.25rem;
}

.nav-logo-icon {
    font-size: 1.5rem;
}

/* Desktop Menu */
.nav-menu {
    display: flex;
    align-items: center;
    gap: 5px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-item {
    position: relative;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    color: white;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 6px;
    transition: background 0.2s;
}

.nav-link:hover {
    background: rgba(255,255,255,0.15);
}

.nav-link.active {
    background: rgba(255,255,255,0.2);
}

.nav-arrow {
    font-size: 0.7rem;
    transition: transform 0.2s;
}

.nav-item:hover .nav-arrow {
    transform: rotate(180deg);
}

/* Dropdown */
.nav-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 220px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s ease;
    padding: 8px 0;
    margin-top: 5px;
}

.nav-item:hover .nav-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: #374151;
    text-decoration: none;
    font-size: 0.9rem;
    transition: background 0.15s;
}

.dropdown-item:hover {
    background: #f3f4f6;
}

.dropdown-item.active {
    background: #eff6ff;
    color: #2563eb;
}

.dropdown-icon {
    width: 20px;
    text-align: center;
    font-size: 1rem;
}

.dropdown-text {
    flex: 1;
}

.dropdown-desc {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 2px;
}

.dropdown-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 8px 0;
}

/* User Menu */
.nav-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-user-info {
    text-align: right;
    color: white;
}

.nav-user-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.nav-user-role {
    font-size: 0.75rem;
    opacity: 0.8;
}

.nav-logout {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.nav-logout:hover {
    background: rgba(255,255,255,0.25);
}

/* Mobile Menu Toggle */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
}

/* Mobile Styles */
@media (max-width: 900px) {
    .nav-toggle {
        display: block;
    }

    .nav-menu {
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        bottom: 0;
        background: white;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 0;
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .nav-menu.open {
        transform: translateX(0);
    }

    .nav-item {
        border-bottom: 1px solid #e5e7eb;
    }

    .nav-link {
        color: #374151;
        padding: 16px 20px;
        border-radius: 0;
        justify-content: space-between;
    }

    .nav-link:hover {
        background: #f3f4f6;
    }

    .nav-dropdown {
        position: static;
        opacity: 1;
        visibility: visible;
        transform: none;
        box-shadow: none;
        border-radius: 0;
        margin: 0;
        padding: 0;
        background: #f9fafb;
        display: none;
    }

    .nav-item.open .nav-dropdown {
        display: block;
    }

    .nav-item.open .nav-arrow {
        transform: rotate(180deg);
    }

    .dropdown-item {
        padding-left: 50px;
    }

    .nav-user {
        padding: 16px 20px;
        border-top: 1px solid #e5e7eb;
        background: #f9fafb;
    }

    .nav-user-info {
        text-align: left;
        color: #374151;
        flex: 1;
    }
}

/* Overlay for mobile */
.nav-overlay {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

.nav-overlay.open {
    display: block;
}

/* Hide nav on login page */
body.login-page .main-nav {
    display: none;
}

/* Adjust main content when nav is present */
.main-content-with-nav {
    min-height: calc(100vh - var(--nav-height));
}

/* FASE 1.3: Fallback for browsers without :has() support (Firefox < 121, Safari < 15.4) */
/* Uses .has-nav class added by JavaScript */
body.has-nav {
    padding-top: 0 !important;
    background-attachment: fixed;
}

body.has-nav .container {
    padding-top: 20px;
}

/* Modern browsers with :has() support - progressive enhancement */
@supports selector(:has(.main-nav)) {
    body:has(.main-nav) {
        padding-top: 0 !important;
        background-attachment: fixed;
    }

    body:has(.main-nav) .container {
        padding-top: 20px;
    }
}

/* Focus styles for accessibility */
.nav-link:focus,
.nav-logout:focus {
    outline: 2px solid var(--nav-text);
    outline-offset: 2px;
}

.dropdown-item:focus {
    outline: 2px solid var(--dropdown-active-text);
    outline-offset: -2px;
    background: var(--dropdown-active-bg);
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .nav-dropdown,
    .nav-menu,
    .nav-arrow {
        transition: none;
    }
}

/* Mobile user menu */
.nav-user-mobile {
    display: none;
}

.nav-user-desktop {
    display: flex;
}

@media (max-width: 900px) {
    .nav-user-mobile {
        display: block;
    }

    .nav-user-desktop {
        display: none;
    }
}
