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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    padding-top: 70px;
    font-size: 16px;
    line-height: 1.5;
}

.navbar {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 20px rgba(0,0,0,0.1);
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 1000;
}

.nav-container {
    max-width:  100%;
    margin: 0 auto;
    padding: 0 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 70px;
}

.logo {
    font-size: 24px;
    font-weight: bold;
    color: #4a5568;
    text-decoration: none;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    color: #4a5568;
    cursor: pointer;
    padding: 10px;
    border-radius: 8px;
    transition: background 0.3s ease;
}

.mobile-menu-btn:hover {
    background: rgba(102, 126, 234, 0.1);
}

.nav-menu {
    display: flex;
    justify-content: space-evenly;
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-item {
    position: relative;
    list-style: none;
    margin: 0 5px;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 15px 8px;
    text-decoration: none;
    color: #4a5568;
    font-weight: 500;
    transition: all 0.3s ease;
    border-radius: 8px;
    margin: 0 5px;
    cursor: pointer;
    font-size: 18px;
    flex-direction: row;
    justify-content: flex-start;
}

.nav-link:hover {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
}

.nav-link .icon {
    margin-right: 0;
    font-size: 18px;
}

.dropdown-arrow {
    margin-left: 8px;
    font-size: 12px;
    transition: transform 0.3s ease;
}

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

.dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    min-width: 280px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,.15);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    z-index: 2000;
}

/* Desktop only - ใช้ max-height และ overflow เฉพาะหน้าจอใหญ่ */
@media (min-width: 769px) {
    .dropdown {
        max-height: 400px;
        overflow-y: auto;
    }
}

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

.dropdown-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    text-decoration: none;
    color: #4a5568;
    transition: all 0.3s ease;
    border-bottom: 1px solid #f7fafc;
    font-size: 18px;
}

.dropdown-item:hover {
    background: #f7fafc;
    color: #667eea;
    transform: translateX(5px);
}

.dropdown-item .icon {
    margin-right: 0;
    font-size: 16px;
}

.dropdown-item:last-child {
    border-bottom: none;
}

/* ---- Responsive: Mobile ---- */
@media (max-width: 768px) {
    html {
        overflow-x: hidden;
    }

    body {
        padding-top: 65px;
        font-size: 16px;
    }

    .nav-container {
        height: 65px;
        padding: 0 15px;
    }

    .logo {
        font-size: 20px;
        z-index: 1001;
        position: relative;
    }

    .mobile-menu-btn {
        display: block;
        z-index: 1001;
        font-size: 28px;
        padding: 8px;
        position: relative;
    }

    .nav-menu {
        position: fixed;
        top: 65px;
        left: 0;
        right: 0;
        bottom: 0;
        background: white;
        flex-direction: column;
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        transform: translateX(-100%);
        opacity: 0;
        visibility: hidden;
        transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
        height: calc(100vh - 65px);
        height: calc(100dvh - 65px);
        overflow-y: auto;
        overflow-x: hidden;
        z-index: 999;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        scrollbar-color: #667eea #f0f0f0;
        scrollbar-width: thin;
        will-change: transform, opacity;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
        padding: 0;
        margin: 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .nav-menu::-webkit-scrollbar {
        width: 8px;
        background: #f0f0f0;
    }

    .nav-menu::-webkit-scrollbar-thumb {
        background: #667eea;
        border-radius: 4px;
    }

    .nav-menu.active {
        transform: translateX(0);
        opacity: 1;
        visibility: visible;
        -webkit-transform: translateX(0);
        -moz-transform: translateX(0);
        -ms-transform: translateX(0);
    }

    .nav-item {
        width: 100%;
        margin: 0;
        display: block;
        opacity: 1;
        visibility: visible;
        flex-shrink: 0;
        border-bottom: 1px solid #f0f0f0;
    }

    .nav-item:last-child {
        border-bottom: none;
        padding-bottom: 20px;
    }

    .nav-link {
        justify-content: flex-start;
        margin: 0;
        border-radius: 0;
        padding: 15px 20px;
        border-bottom: none;
        font-size: 18px;
        font-weight: 600;
        background: white;
        transition: all 0.2s ease;
        line-height: 1.4;
        display: flex;
        width: 100%;
        align-items: center;
        flex-direction: row;
        min-height: 56px;
        text-align: left;
    }

    .nav-link:hover,
    .nav-link:active {
        background: #f0f9ff;
        color: #2563eb;
    }

    .nav-link.active {
        background: #eff6ff;
        color: #1d4ed8;
        border-left: 4px solid #2563eb;
    }

    .nav-link .icon {
        font-size: 20px;
        margin-right: 0;
        margin-left: 0;
    }

    .dropdown-arrow {
        font-size: 14px;
        font-weight: bold;
        transition: transform 0.3s ease;
        margin-left: auto;
        margin-right: 8px;
        flex-shrink: 0;
    }

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

    /* ส่วนสำคัญที่แก้ไข - ให้ dropdown แสดงทั้งหมดในมือถือ */
    .dropdown {
        position: static !important;
        opacity: 0;
        visibility: hidden;
        transform: none !important;
        box-shadow: none;
        background: #f8fafc;
        border-radius: 0;
        display: none;
        border-left: 3px solid #667eea;
        margin: 0;
        width: 100%;
    }

    .dropdown.active {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
        padding: 8px 0;
        position: static !important;
    }

    .dropdown-item {
        padding: 16px 20px 16px 50px;
        border-bottom: 1px solid #e8f4f8;
        font-size: 18px;
        line-height: 1.4;
        transition: all 0.2s ease;
        background: #f8fafc;
        font-weight: 500;
        display: flex !important;
        align-items: center;
        width: 100%;
        min-height: 50px;
        white-space: normal;
        opacity: 1 !important;
        visibility: visible !important;
        position: relative !important;
    }

    .dropdown-item:hover,
    .dropdown-item:active {
        background: #e6f3ff;
        color: #2563eb;
        padding-left: 55px;
    }

    .dropdown-item:last-child {
        border-bottom: none;
        margin-bottom: 0;
    }

    .dropdown-item .icon {
        font-size: 18px;
        margin-right: 0;
        flex-shrink: 0;
    }

    .dropdown-item span {
        flex: 1;
        word-wrap: break-word;
    }
}

body.menu-open {
    overflow: hidden !important;
    height: 100vh;
    height: 100dvh;
    touch-action: none;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
}

@supports (-webkit-touch-callout: none) {
    .nav-menu {
        -webkit-transform: translateX(-100%);
        height: calc(100vh - 65px);
        height: calc(100dvh - 65px);
    }

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

@media (max-width: 480px) {
    .nav-container {
        padding: 0 10px;
    }

    .logo {
        font-size: 18px;
    }

    .nav-link {
        padding: 15px 15px;
        font-size: 18px;
        min-height: 50px;
    }

    .dropdown-item {
        padding: 14px 15px 14px 40px;
        font-size: 18px;
        min-height: 46px;
    }

    .dropdown-item:hover,
    .dropdown-item:active {
        padding-left: 45px;
    }

    .nav-link .icon {
        font-size: 18px;
        margin-right: 10px;
    }

    .dropdown-item .icon {
        font-size: 16px;
        margin-right: 0px;
    }

    .dropdown-arrow {
        font-size: 12px;
    }
}

@media (max-width: 360px) {
    .nav-container {
        padding: 0 8px;
    }

    .logo {
        font-size: 18px;
    }

    .mobile-menu-btn {
        font-size: 24px;
        padding: 6px;
    }

    .nav-link {
        padding: 14px 12px;
        font-size: 18px;
        min-height: 48px;
    }

    .dropdown-item {
        padding: 12px 12px 12px 35px;
        font-size: 18px;
        min-height: 44px;
    }

    .dropdown-item:hover,
    .dropdown-item:active {
        padding-left: 40px;
    }
}

@media (prefers-color-scheme: dark) {
    @media (max-width: 768px) {
        .nav-menu {
            background: #1a202c;
        }

        .nav-link {
            background: #1a202c;
            color: #e2e8f0;
            border-bottom: 1px solid #2d3748;
        }

        .nav-link:hover,
        .nav-link:active {
            background: #2d3748;
            color: #90cdf4;
        }

        .dropdown {
            background: #2d3748;
        }

        .dropdown-item {
            background: #2d3748;
            color: #e2e8f0;
            border-bottom: 1px solid #4a5568;
        }

        .dropdown-item:hover,
        .dropdown-item:active {
            background: #4a5568;
            color: #90cdf4;
        }
    }
}