/* Menu styles */
/* User Menu Dropdown */
.user-menu {
    position: absolute;
    top: 75px;
    right: 0px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    padding: 20px;
    width: 180px;
    height: 350px;
    z-index: 4000;
    pointer-events: auto;
}

/* Overlay for mobile menu */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: none;
    pointer-events: none;
    transition: opacity 0.2s;
}
.menu-overlay[style*="display: block"] {
    pointer-events: auto !important;
    opacity: 1;
}


.user-profile {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(45deg, #7CB342, #8BC34A);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 20px;
    cursor: pointer;
}

.user-info h3 {
    color: #333;
    font-size: 16px;
    margin-bottom: 5px;
}

.user-info p {
    color: #666;
    font-size: 12px;
}

.menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    color: #333;
    text-decoration: none;
    font-size: 14px;
    border-bottom: 1px solid #f5f5f5;
    transition: color 0.3s;
}

.menu-item:hover {
    color: #7CB342;
}

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

.language-toggle {
    color: #7CB342;
    font-weight: 500;
}

.toggle-switch {
    width: 40px;
    height: 20px;
    background: #7CB342;
    border-radius: 10px;
    position: relative;
    cursor: pointer;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: right 0.3s;
}

/* Modal styles */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.32);
    z-index: 1000;
    display: block;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 4px 32px 0 rgba(0,0,0,0.13);
    padding: 32px 28px 24px 28px;
    z-index: 1010;
    min-width: 320px;
    max-width: 90vw;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.modal-title {
    font-size: 1.45rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 22px;
    color: #222;
}

.change-password-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-input {
    width: 100%;
    padding: 12px 16px;
    border-radius: 10px;
    border: none;
    background: #f2f2f2;
    font-size: 1.08rem;
    color: #222;
    outline: none;
    font-style: italic;
    margin-bottom: 0;
    box-sizing: border-box;
}

.modal-input:focus {
    background: #e9f6d2;
    border: 1.5px solid #91c300;
}

.modal-submit {
    width: 80px;
    min-width: 60px;
    max-width: 100px;
    background: #b6e100;
    color: #fff;
    font-size: 0.92rem;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    padding: 8px 0;
    margin-top: 8px;
    cursor: pointer;
    transition: background 0.18s;
}

.modal-submit:hover {
    background: #91c300;
}

.modal-close {
    position: absolute;
    top: 18px;
    right: 22px;
    background: none;
    border: none;
    font-size: 2rem;
    color: #222;
    cursor: pointer;
    z-index: 2;
    line-height: 1;
}

.modal.change-password-modal {
    min-width: 260px;
    max-width: 95vw;
    width: 320px;
    padding: 70px 30px 60px 30px;
    min-height: 350px;
    border-radius: 16px;
    box-shadow: 0 6px 28px 0 rgba(0,0,0,0.15);
}

.change-password-form {
    gap: 18px;
    align-items: center;
}

.modal.change-password-modal .modal-submit {
    width: 80px;
    min-width: 60px;
    max-width: 100px;
    margin-top: 18px;
    font-size: 0.92rem;
    border-radius: 8px;
    padding: 8px 0;
    display: block;
    margin-left: auto;
    margin-right: auto;
    background: #b6e100;
    color: #fff;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background 0.18s;
    text-align: center;
}

/* Avatar Modal */
.modal.change-avatar-modal {
    min-width: 280px;
    max-width: 95vw;
    width: 400px;
    padding: 70px 30px 60px 30px;
    min-height: 350px;
    border-radius: 20px;
    box-shadow: 0 8px 32px 0 rgba(0,0,0,0.15);
    background: #fff;
}

.avatar-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 40px;
    position: relative;
}

.avatar-circle {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    border: 4px solid #b6e100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(45deg, #7CB342, #8BC34A);
    position: relative;
    overflow: visible;
    cursor: pointer;
    transition: transform 0.2s;
}

.avatar-circle:hover {
    transform: scale(1.02);
}

.avatar-circle img {
    width: calc(100% - 8px);
    height: calc(100% - 8px);
    object-fit: cover;
    border-radius: 50%;
    position: absolute;
    top: 4px;
    left: 4px;
}

.avatar-placeholder {
    color: white;
    font-weight: bold;
    font-size: 56px;
    line-height: 1;
}

.camera-overlay {
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 36px;
    height: 36px;
    background: #333;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10;
}

.camera-overlay:hover {
    background: #555;
    transform: scale(1.1);
}

.camera-icon {
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
}

.avatar-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.avatar-btn {
    width: 200px;
    padding: 14px 20px;
    border-radius: 12px;
    border: none;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.18s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-btn {
    background: #b6e100;
    color: #fff;
}

.upload-btn:hover {
    background: #91c300;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(182, 225, 0, 0.3);
}

@media (max-width: 600px) {
    .dropdown-menu {
        left: 50%;
        transform: translateX(-50%);
        top: calc(100% + 5px); /* keep small gap below header */
    }
    
    .nav-dropdown.active .dropdown-menu {
        transform: translateX(-50%) translateY(0);
    }
    
    .dropdown-item {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
    
    /* Mobile submenu - positioned to the side */
    .submenu {
        position: absolute;
        left: calc(100% + 4px); /* Giảm khoảng cách cho mobile nhỏ */
        top: 12px; /* Lệch xuống ít hơn cho màn nhỏ */
        transform: translateY(0) translateX(-10px);
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
        margin: 0;
        border-radius: 8px;
        background: white;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        min-width: 140px;
        z-index: 1001;
    }
    
    .has-submenu.active .submenu,
    .has-submenu:hover .submenu,
    .has-submenu:focus-within .submenu {
        opacity: 1;
        visibility: visible;
        transform: translateY(0) translateX(0);
        padding: 8px 0;
    }
    
    .submenu-item {
        padding: 6px 10px;
        font-size: 0.75rem;
    }
}

/* Hiệu ứng chọn submenu theo thiết kế mới - nền hình mũi tên */
/* Chỉ hiển thị nền xanh khi item được chọn (có class selected) */
.submenu-item.selected {
    background: #91c300 !important;
    color: #fff !important;
    border-radius: 8px 0 0 8px !important; /* Bo góc bên trái, vuông góc bên phải */
    box-shadow: 0 2px 8px rgba(145, 195, 0, 0.3) !important;
    margin: 2px 8px !important;
    position: relative;
    font-weight: 600 !important;
}

/* Tạo mũi tên ở bên phải cho item được chọn */
.submenu-item.selected::after {
    content: '';
    position: absolute;
    top: 0;
    right: -8px; /* Đẩy ra ngoài item */
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 22px 0 22px 8px; /* Điều chỉnh kích thước mũi tên */
    border-color: transparent transparent transparent #91c300;
    z-index: 1;
}

/* Hover effect cho submenu item thường - chỉ có nền nhẹ */
.submenu-item:hover:not(.selected),
.submenu-item:active:not(.selected),
.submenu-item:focus:not(.selected) {
    background-color: #f8f9fa !important;
    color: #a6ce39 !important; /* Đổi màu chữ thành #a6ce39 khi hover */
    border-radius: 8px;
    margin: 2px 8px;
    transition: all 0.2s ease;
}

/* Đặc biệt cho touch devices - hiệu ứng active */
@media (hover: none) and (pointer: coarse) {
    .submenu-item:active:not(.selected) {
        background-color: #f8f9fa !important;
        color: #a6ce39 !important;
        border-radius: 8px;
        margin: 2px 8px;
        transition: all 0.1s ease;
        transform: scale(0.98);
    }
}

/* Khi item được chọn, override hover */
.submenu-item.selected:hover {
    background: #a6ce39 !important;
    color: #fff !important;
}

/* Cập nhật mũi tên khi hover item đã chọn */
.submenu-item.selected:hover::after {
    border-left-color: #a6ce39 !important;
}

/* Mũi tên submenu chuyển xanh lá khi submenu mở */
.has-submenu.open > .submenu-arrow,
.has-submenu.active > .submenu-arrow {
    color: #a6ce39 !important;
}

/* Desktop optimization cho menu */
@media (min-width: 1024px) {
    /* Header navigation hiển thị inline */
    .header-nav {
        display: flex !important;
        position: static !important;
        background: transparent !important;
        box-shadow: none !important;
        transform: none !important;
        width: auto !important;
        height: auto !important;
        padding: 0 !important;
        flex-direction: row !important;
        align-items: center;
        gap: 30px;
    }
    
    .nav-dropdown {
        position: relative;
    }
    /* HIỆN menu-toggle trên desktop để mở user menu (menu 3 gạch luôn hiển thị) */
    .menu-toggle {
        display: flex !important;
    }
    /* Overlay không hiển thị trên desktop */
    .menu-overlay {
        display: none !important;
        pointer-events: none !important;
        opacity: 0 !important;
    }
    /* Đảm bảo user-menu hiển thị đúng vị trí */
    .user-menu {
        top: 75px;
        right: 0;
        left: auto;
        position: absolute;
        border-radius: 15px;
        width: 180px;
        min-width: 180px;
        max-width: 260px;
        z-index: 4000;
    }
    
    /* Dropdown menus */
    .dropdown-menu {
        position: absolute;
        top: 100%;
        left: 50%;
        transform: translateX(-50%);
        background: white;
        border-radius: 10px;
        box-shadow: 0 6px 24px rgba(0,0,0,0.12);
        padding: 15px 0;
        min-width: 240px;
        display: none;
        z-index: 1000;
        opacity: 0;
        visibility: hidden;
        transition: all 0.2s ease;
        /* Tạo safe zone */
        margin-top: 5px;
    }
    
    .nav-dropdown:hover .dropdown-menu,
    .nav-dropdown.active .dropdown-menu,
    .dropdown-menu:hover {
        display: block;
        opacity: 1;
        visibility: visible;
        transition-delay: 0ms;
        transform: translateX(-50%);
    }
    
    /* Delay đóng dropdown */
    .dropdown-menu {
        transition-delay: 150ms;
    }
    
    .nav-dropdown:hover .dropdown-menu {
        transition-delay: 0ms;
    }
    
    /* Submenu positioning */
    .has-submenu {
        position: relative;
    }
    
    .submenu {
        position: absolute;
        left: calc(100% - 5px);
        top: -5px;
        background: white;
        border-radius: 10px;
        box-shadow: 0 6px 24px rgba(0,0,0,0.12);
        padding: 12px 0;
        min-width: 220px;
        display: none;
        z-index: 1001;
        opacity: 0;
        visibility: hidden;
        transition: all 0.2s ease;
        /* Tạo safe zone cho submenu */
        margin-left: 5px;
    }
    
    .has-submenu:hover .submenu,
    .has-submenu.active .submenu,
    .submenu:hover {
        display: block;
        opacity: 1;
        visibility: visible;
        transition-delay: 0ms;
    }
    
    /* Delay đóng submenu */
    .submenu {
        transition-delay: 200ms;
    }
    
    .has-submenu:hover .submenu {
        transition-delay: 0ms;
    }
    
    /* Tạo vùng hover lớn hơn cho has-submenu */
    .has-submenu::after {
        content: '';
        position: absolute;
        right: -10px;
        top: 0;
        width: 15px;
        height: 100%;
        background: transparent;
        z-index: 999;
    }
    
    /* Đảm bảo submenu items có thể click */
    .submenu-item {
        display: block;
        color: #333;
        text-decoration: none;
        padding: 10px 16px;
        transition: background-color 0.2s;
        cursor: pointer;
    }
    
    .submenu-item:hover,
    .submenu-item:active,
    .submenu-item:focus {
        background-color: #f8f9fa;
        color: #7CB342;
    }
    
    /* Hiệu ứng cho touch devices */
    .submenu-item:active {
        background-color: #f8f9fa !important;
        color: #7CB342 !important;
        transition: all 0.1s ease;
    }
    
    .submenu-item.selected {
        background-color: #e8f5e8;
        color: #7CB342;
    }
    
    /* User menu positioning */
    .user-menu {
        top: 100%;
        right: 0;
        width: 280px;
        height: auto;
        padding: 25px;
        border-radius: 12px;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .header-nav {
        gap: 25px;
    }
    
    .dropdown-menu {
        min-width: 220px;
        padding: 12px 0;
    }
    
    .user-menu {
        width: 260px;
        padding: 20px;
    }
}

/* Fix: Hiển thị dropdown cho tab Cộng đồng (header-dropdown) */
.header-dropdown {
    position: relative;
    display: inline-block;
}

.header-dropdown .dropdown-toggle {
    position: relative;
    transition: all 0.3s ease;
    padding: 6px 8px;
    margin: -6px -8px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #222;
    text-decoration: none;
    font-size: 0.85rem;
    min-width: 56px;
    cursor: pointer; /* Đảm bảo có cursor pointer */
    pointer-events: auto; /* Đảm bảo dropdown toggle luôn clickable */
}

.header-dropdown .dropdown-toggle:hover,
.header-dropdown .dropdown-toggle.active {
    color: #A6CE39 !important;
    background: #fff;
    border-radius: 8px 8px 0 0;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05), 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 1001;
    position: relative;
    margin-bottom: -1px;
}

.header-dropdown .dropdown-toggle:hover i,
.header-dropdown .dropdown-toggle.active i,
.header-dropdown .dropdown-toggle:hover span,
.header-dropdown .dropdown-toggle.active span {
    color: #A6CE39 !important;
}

/* Cải thiện submenu hover experience */
.has-submenu:hover .submenu {
    transition-delay: 0ms; /* Hiển thị submenu ngay lập tức khi hover */
}

.has-submenu .submenu {
    transition-delay: 100ms; /* Delay nhỏ khi ẩn để tránh flicker */
}

/* Tăng kích thước "khu vực an toàn" cho submenu items */
.submenu-item {
    position: relative;
    transition: all 0.2s ease;
}
