/* ==================== MOBILE MENU LATERAL DIREITO ==================== */

/* Mobile Header Premium - Branco com Logo */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 70px;
    background: var(--white);
    box-shadow: none;
    z-index: 999;
    padding: 0 20px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-bottom: 1px solid transparent;
}

/* Estado quando rolado */
.mobile-header.scrolled {
    height: 60px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    border-bottom-color: var(--gray-light);
}

.mobile-header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
    padding-top: 0;
}

/* Logo Monetix Premium */
.mobile-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--black);
    font-size: 24px;
    font-weight: 900;
    letter-spacing: -0.5px;
    font-style: italic;
    position: relative;
    transition: all 0.3s ease;
}

.mobile-header.scrolled .mobile-logo {
    font-size: 20px;
}

/* Primeira letra M em destaque */
.mobile-logo-text::first-letter {
    background: linear-gradient(135deg, #0066CC, #4A90E2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 1.2em;
    filter: drop-shadow(0 2px 4px rgba(0, 102, 204, 0.3));
}

.mobile-logo i {
    display: none; /* Esconde ícone, só mostra texto */
}

/* Botão Hambúrguer (3 linhas) - CORRIGIDO */
.mobile-menu-toggle {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 40px;
    height: 40px;
    background: var(--gray-lighter);
    border: 1px solid var(--gray-light);
    border-radius: 10px;
    cursor: pointer;
    padding: 10px;
    z-index: 10001 !important;
    position: relative;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    pointer-events: auto !important;
}

.mobile-header.scrolled .mobile-menu-toggle {
    width: 36px;
    height: 36px;
}

.mobile-menu-toggle:hover {
    background: var(--gray-light);
    border-color: var(--gray-medium);
}

.mobile-menu-toggle:active {
    transform: scale(0.95);
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.mobile-menu-toggle:active span {
    background: var(--white) !important;
}

.mobile-menu-toggle span {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--gray-dark);
    border-radius: 3px;
    transition: all 0.3s ease;
    pointer-events: none !important;
}

.mobile-header.scrolled .mobile-menu-toggle span {
    height: 2px;
}

.mobile-menu-toggle:hover span {
    background: var(--primary-color);
}

/* Sidebar Mobile Overlay */
.mobile-sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none; /* CRÍTICO - não recebe cliques quando fechado */
}

.mobile-sidebar-overlay.active {
    display: block;
    opacity: 1;
    pointer-events: auto; /* CRÍTICO - recebe cliques quando aberto */
}

/* Sidebar Mobile */
.mobile-sidebar {
    position: fixed;
    top: 0;
    right: -100%;
    width: 320px;
    max-width: 85%;
    height: 100vh;
    background: var(--white);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    visibility: hidden; /* CRÍTICO - esconde quando fechada */
}

.mobile-sidebar.active {
    right: 0;
    visibility: visible; /* CRÍTICO - mostra quando aberta */
}

/* Header da Sidebar Mobile */
.mobile-sidebar-header {
    padding: 24px 20px;
    background: linear-gradient(135deg, #0066CC 0%, #4A90E2 100%);
    color: var(--white);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.mobile-user-info {
    display: flex;
    gap: 14px;
    flex: 1;
}

.mobile-user-avatar {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.mobile-user-details {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.mobile-user-name {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 2px;
}

.mobile-user-email {
    font-size: 13px;
    opacity: 0.9;
}

.mobile-sidebar-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: var(--white);
    font-size: 18px;
    cursor: pointer;
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.mobile-sidebar-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Navegação da Sidebar Mobile */
.mobile-sidebar-nav {
    flex: 1;
    padding: 16px 0;
}

.mobile-sidebar-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 24px;
    color: var(--gray-dark);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    transition: var(--transition-fast);
    position: relative;
}

.mobile-sidebar-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--primary-color);
    transform: scaleY(0);
    transition: var(--transition-fast);
}

.mobile-sidebar-item:hover {
    background: var(--gray-lighter);
    color: var(--primary-color);
}

.mobile-sidebar-item.active {
    background: linear-gradient(90deg, rgba(0, 102, 204, 0.1) 0%, rgba(255, 255, 255, 0) 100%);
    color: var(--primary-color);
    font-weight: 600;
}

.mobile-sidebar-item.active::before {
    transform: scaleY(1);
}

.mobile-sidebar-item i {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

/* Footer da Sidebar Mobile */
.mobile-sidebar-footer {
    border-top: 1px solid var(--gray-light);
    padding: 12px 0;
}

.mobile-sidebar-divider {
    height: 1px;
    background: var(--gray-light);
    margin: 12px 24px;
}

/* Toggle Modo Dark */
.dark-mode-toggle {
    display: flex !important;
    justify-content: space-between !important;
    cursor: default !important;
}

.dark-mode-toggle:hover {
    background: transparent !important;
}

.dark-mode-content {
    display: flex;
    align-items: center;
    gap: 14px;
}

.toggle-switch {
    position: relative;
    width: 52px;
    height: 28px;
}

.toggle-checkbox {
    display: none;
}

.toggle-label {
    display: block;
    width: 100%;
    height: 100%;
    background: var(--gray-light);
    border-radius: 30px;
    cursor: pointer;
    position: relative;
    transition: var(--transition);
}

.toggle-slider {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    background: var(--white);
    border-radius: 50%;
    transition: var(--transition);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-checkbox:checked + .toggle-label {
    background: var(--primary-color);
}

.toggle-checkbox:checked + .toggle-label .toggle-slider {
    transform: translateX(24px);
}

/* Logout Item */
.logout-item {
    color: var(--danger) !important;
}

.logout-item:hover {
    background: var(--danger-light) !important;
}

/* ==================== MODO DARK ==================== */

:root.dark-mode {
    /* Cores Dark */
    --white: #FFFFFF;
    --black: #E5E7EB;
    --gray-dark: #D1D5DB;
    --gray-medium: #9CA3AF;
    --gray-light: #374151;
    --gray-lighter: #1F2937;
    --gray-bg: #111827;
    
    /* Backgrounds */
    --bg-primary: #111827;
    --bg-secondary: #1F2937;
    --bg-card: #1F2937;
}

.dark-mode {
    background: var(--bg-primary);
    color: var(--black);
}

.dark-mode .sidebar {
    background: var(--bg-secondary);
    border-right-color: var(--gray-light);
}

.dark-mode .sidebar-header {
    background: linear-gradient(135deg, #0066CC 0%, #4A90E2 100%);
}

.dark-mode .nav-link {
    color: var(--gray-dark);
}

.dark-mode .nav-link:hover {
    background: var(--gray-lighter);
    color: var(--primary-light);
}

.dark-mode .nav-item.active .nav-link {
    background: rgba(0, 102, 204, 0.15);
    color: var(--primary-light);
}

.dark-mode .main-content {
    background: var(--bg-primary);
}

.dark-mode .card,
.dark-mode .table-container,
.dark-mode .form-card-premium,
.dark-mode .history-section-premium {
    background: var(--bg-card);
    border-color: var(--gray-light);
}

.dark-mode .card-header,
.dark-mode .form-card-header {
    background: linear-gradient(135deg, #1F2937 0%, #111827 100%);
    border-bottom-color: var(--gray-light);
}

.dark-mode .form-control,
.dark-mode .form-control-secondary,
.dark-mode textarea {
    background: var(--bg-secondary);
    border-color: var(--gray-light);
    color: var(--black);
}

.dark-mode .form-control-hero {
    background: linear-gradient(135deg, #1E3A8A 0%, #1E40AF 100%);
    border-color: var(--primary-color);
    color: var(--white);
}

.dark-mode .table thead th {
    background: var(--gray-lighter);
    color: var(--gray-dark);
}

.dark-mode .table tbody tr:hover {
    background: var(--gray-lighter);
}

.dark-mode .page-title,
.dark-mode .page-title-large,
.dark-mode .card-title,
.dark-mode .form-card-title {
    color: var(--black);
}

.dark-mode .page-subtitle,
.dark-mode .page-subtitle-large,
.dark-mode .card-label,
.dark-mode .form-card-subtitle {
    color: var(--gray-medium);
}

.dark-mode .alert-success {
    background: rgba(16, 185, 129, 0.15);
    border-color: #10B981;
    color: #34D399;
}

.dark-mode .alert-error {
    background: rgba(239, 68, 68, 0.15);
    border-color: #EF4444;
    color: #F87171;
}

.dark-mode .monthly-insight {
    background: linear-gradient(135deg, rgba(254, 243, 199, 0.1) 0%, rgba(253, 230, 138, 0.1) 100%);
    border-left-color: #F59E0B;
}

.dark-mode .mobile-sidebar {
    background: var(--bg-secondary);
}

.dark-mode .mobile-sidebar-item {
    color: var(--gray-dark);
}

.dark-mode .mobile-sidebar-item:hover {
    background: var(--gray-lighter);
}

/* ==================== RESPONSIVE MOBILE ==================== */

@media (max-width: 768px) {
    /* Ativar Mobile Header */
    /* Não mostra mobile header na página de login */
    .login-page .mobile-header {
        display: none !important;
    }

    /* Não mostra mobile header na página de login */
    .login-page .mobile-sidebar,
    .login-page .mobile-sidebar-overlay {
        display: none !important;
    }

    .mobile-header {
        display: block !important;
    }
    
    .mobile-sidebar-overlay {
        display: block;
    }
    
    .sidebar {
        transform: translateX(-100%);
    }
    
    /* Só aplica padding quando NÃO é login */
    body:not(.login-page) .main-content {
        margin-left: 0;
        padding-top: 86px;
        padding-bottom: 20px;
        padding-left: 16px;
        padding-right: 16px;
        transition: padding-top 0.3s ease;
    }
    
    /* Quando header está scrolled (menor) */
    .mobile-header.scrolled ~ .main-content {
        padding-top: 76px;
    }
    
    /* Esconder sidebar desktop em mobile */
    .sidebar-nav,
    .sidebar-footer {
        display: none;
    }
}

@media (max-width: 480px) {
    .mobile-sidebar {
        width: 100%;
        max-width: 100%;
    }
    
    .main-content {
        padding-top: 80px;
    }
}