/* ===== HEADER MOBILE OPTIMIZATION ===== */

/* Desktop Header Enhancements */
.topbar {
    height: 64px !important;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    will-change: transform;
    transform: translateZ(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.topbar-content {
    max-width: 1400px !important;
    padding: 0 24px !important;
    gap: 20px;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s ease, transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    will-change: transform;
}

.sidebar-toggle:active {
    transform: scale(0.95) translateZ(0);
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

.header-user-info {
    gap: 12px !important;
    padding: 0 !important;
    flex-wrap: nowrap;
}

.user-name {
    white-space: nowrap;
}

.user-balance {
    white-space: nowrap;
    padding: 6px 12px;
    background: rgba(0, 188, 212, 0.1);
    border-radius: 20px;
    border: 1px solid rgba(0, 188, 212, 0.2);
}

.btn-topup,
.btn-logout {
    padding: 8px 16px !important;
    border-radius: 8px !important;
    font-size: 13px !important;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}

.btn-topup {
    background: linear-gradient(135deg, var(--accent-start), var(--accent-end)) !important;
    color: white !important;
    box-shadow: 0 2px 8px rgba(0, 188, 212, 0.3);
    border: none !important;
}

.btn-topup:hover {
    box-shadow: 0 4px 12px rgba(0, 188, 212, 0.4);
    transform: translateY(-2px);
}

.btn-logout {
    background: rgba(255, 255, 255, 0.05) !important;
    color: var(--text-secondary) !important;
    border: 1px solid var(--border-color) !important;
}

.btn-logout:hover {
    background: rgba(255, 82, 82, 0.1) !important;
    color: var(--danger) !important;
    border-color: var(--danger) !important;
}

/* ===== TABLET (768px) ===== */
@media (max-width: 768px) {
    .topbar {
        height: 60px !important;
    }

    .topbar-content {
        padding: 0 16px !important;
        gap: 12px;
    }

    .header-user-info {
        gap: 10px !important;
    }

    .user-name {
        font-size: 13px;
    }

    .user-balance {
        font-size: 12px;
        padding: 5px 10px;
    }

    .btn-topup,
    .btn-logout {
        padding: 6px 12px !important;
        font-size: 12px !important;
    }
}

/* ===== MOBILE (540px) ===== */
@media (max-width: 540px) {
    .topbar {
        height: auto !important;
        min-height: 56px;
        padding: 8px 0 !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        will-change: transform;
    }

    .topbar-content {
        padding: 0 12px !important;
        gap: 6px;
        flex-wrap: wrap;
        /* Chỉ wrap khi không đủ chỗ */
    }

    .sidebar-toggle {
        width: 36px;
        height: 36px;
        font-size: 20px;
        flex-shrink: 0;
        -webkit-tap-highlight-color: rgba(0, 188, 212, 0.1);
    }

    .logo {
        font-size: 14px !important;
        flex-shrink: 0;
    }

    /* Header user info - hiển thị trên 1 hàng, chỉ wrap khi cần */
    .header-user-info {
        flex: 1;
        gap: 6px !important;
        justify-content: flex-end;
        flex-wrap: wrap;
        /* Chỉ wrap khi không đủ chỗ */
        border-top: none;
        padding-top: 0 !important;
        margin-top: 0;
        min-width: 0;
    }

    .user-avatar {
        display: none;
        /* Ẩn avatar trên mobile để tiết kiệm chỗ */
    }

    .user-name {
        font-size: 11px !important;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        flex-shrink: 1;
    }

    .user-balance {
        font-size: 10px !important;
        padding: 4px 8px !important;
        line-height: 1.3;
        will-change: transform;
        flex-shrink: 0;
    }

    .user-balance strong {
        font-size: 11px;
    }

    .btn-topup {
        padding: 6px 10px !important;
        font-size: 10px !important;
        border-radius: 6px !important;
        min-height: 32px;
        flex-shrink: 0;
        -webkit-tap-highlight-color: rgba(0, 188, 212, 0.1);
        transition: transform 0.15s ease;
    }

    .btn-topup:active {
        transform: scale(0.96) translateZ(0);
    }

    .btn-logout {
        padding: 6px 10px !important;
        font-size: 10px !important;
        border-radius: 6px !important;
        min-height: 32px;
        flex-shrink: 0;
        -webkit-tap-highlight-color: rgba(255, 82, 82, 0.1);
        transition: transform 0.15s ease;
    }

    .btn-logout:active {
        transform: scale(0.96) translateZ(0);
    }

    /* Fixed Header Spacing - ONLY when topbar is present */
    .topbar+.content,
    .topbar+main,
    .topbar+*+main {
        padding-top: 70px !important;
    }

    /* Guest Header (Static) Spacing */
    header+main {
        padding-top: 10px !important;
    }
}

/* ===== VERY SMALL MOBILE (420px) ===== */
@media (max-width: 420px) {
    .topbar {
        min-height: 52px !important;
        padding: 6px 0 !important;
    }

    .topbar-content {
        padding: 0 8px !important;
        gap: 4px;
    }

    .sidebar-toggle {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }

    .logo {
        font-size: 13px !important;
    }

    .user-name {
        font-size: 10px !important;
        max-width: 60px;
        /* Giới hạn độ rộng tên để tiết kiệm chỗ */
    }

    .user-balance {
        font-size: 9px !important;
        padding: 3px 6px !important;
    }

    .user-balance strong {
        font-size: 10px;
    }

    .btn-topup,
    .btn-logout {
        padding: 5px 8px !important;
        font-size: 9px !important;
        min-height: 28px;
    }

    .content,
    main {
        padding-top: 65px !important;
    }
}