:root {
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
    
    /* ===== LIGHT MODE COLORS (DEFAULT) ===== */
    --color-bg-primary: #f9fafb;
    --color-bg-secondary: #ffffff;
    --color-bg-tertiary: #f3f4f6;
    --color-text-primary: #111827;
    --color-text-secondary: #6b7280;
    --color-text-tertiary: #9ca3af;
    --color-border: #e5e7eb;
    --color-border-secondary: #d1d5db;
    --color-shadow: rgba(0, 0, 0, 0.1);
    --color-shadow-lg: rgba(0, 0, 0, 0.15);
    
    /* Button colors */
    --color-button-primary: #3b82f6;
    --color-button-primary-hover: #2563eb;
    --color-button-secondary: #6b7280;
    --color-button-secondary-hover: #4b5563;
    
    /* Status colors */
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-error: #ef4444;
    --color-info: #3b82f6;
}

/* ===== DARK MODE COLORS ===== */
.dark {
    --color-bg-primary: #0f172a;
    --color-bg-secondary: #1e293b;
    --color-bg-tertiary: #334155;
    --color-text-primary: #f1f5f9;
    --color-text-secondary: #cbd5e1;
    --color-text-tertiary: #94a3b8;
    --color-border: #334155;
    --color-border-secondary: #475569;
    --color-shadow: rgba(0, 0, 0, 0.3);
    --color-shadow-lg: rgba(0, 0, 0, 0.4);
    
    /* Button colors for dark mode */
    --color-button-primary: #3b82f6;
    --color-button-primary-hover: #1d4ed8;
    --color-button-secondary: #64748b;
    --color-button-secondary-hover: #475569;
}

/* ===== BASE STYLES ===== */
html, body {
    height: 100%;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-family: system-ui, -apple-system, sans-serif;
    margin: 0;
    padding: 0;
}

body {
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
    background-color: var(--color-bg-primary) !important;
    color: var(--color-text-primary) !important;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ===== LAYOUT OVERRIDES ===== */
/* Force correct background colors */
.bg-white {
    background-color: var(--color-bg-secondary) !important;
}

.bg-gray-50 {
    background-color: var(--color-bg-primary) !important;
}

.bg-gray-100 {
    background-color: var(--color-bg-tertiary) !important;
}

/* Force correct text colors */
.text-gray-900 {
    color: var(--color-text-primary) !important;
}

.text-gray-700 {
    color: var(--color-text-primary) !important;
}

.text-gray-600 {
    color: var(--color-text-secondary) !important;
}

.text-gray-500 {
    color: var(--color-text-tertiary) !important;
}

.text-gray-400 {
    color: var(--color-text-tertiary) !important;
}

/* Force correct border colors */
.border-gray-200 {
    border-color: var(--color-border) !important;
}

.border-gray-300 {
    border-color: var(--color-border-secondary) !important;
}

.divide-gray-200 > :not([hidden]) ~ :not([hidden]) {
    border-color: var(--color-border) !important;
}

/* ===== COMPONENT STYLES ===== */

/* Cards and containers */
.bg-white,
.dark .bg-white {
    background-color: var(--color-bg-secondary) !important;
    color: var(--color-text-primary) !important;
    border: 1px solid var(--color-border);
}

/* Shadows */
.shadow {
    box-shadow: 0 1px 3px 0 var(--color-shadow), 0 1px 2px 0 var(--color-shadow) !important;
}

.shadow-sm {
    box-shadow: 0 1px 2px 0 var(--color-shadow) !important;
}

.shadow-lg {
    box-shadow: 0 4px 6px -1px var(--color-shadow-lg), 0 2px 4px -1px var(--color-shadow) !important;
}

/* ===== PRIORITY INDICATORS ===== */
.priority-essencial {
    border-left: 4px solid #ef4444;
}

.priority-importante {
    border-left: 4px solid #f59e0b;
}

.priority-opcional {
    border-left: 4px solid #10b981;
}

/* ===== HOVER STATES ===== */
.payment-card {
    transition: all 0.2s ease;
    background-color: var(--color-bg-secondary) !important;
    border: 1px solid var(--color-border);
}

.payment-card:hover {
    background-color: var(--color-bg-tertiary) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--color-shadow-lg);
}

.payment-card:active {
    transform: scale(0.98);
}

/* ===== FORM ELEMENTS ===== */
input, select, textarea {
    background-color: var(--color-bg-secondary) !important;
    border-color: var(--color-border-secondary) !important;
    color: var(--color-text-primary) !important;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--color-button-primary) !important;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2) !important;
    outline: none;
}

input::placeholder, textarea::placeholder {
    color: var(--color-text-tertiary) !important;
}

/* ===== BUTTONS ===== */
button {
    transition: all 0.2s ease;
}

.bg-blue-600 {
    background-color: var(--color-button-primary) !important;
}

.bg-blue-600:hover {
    background-color: var(--color-button-primary-hover) !important;
}

.bg-gray-300 {
    background-color: var(--color-button-secondary) !important;
    color: var(--color-text-primary) !important;
}

.bg-gray-300:hover {
    background-color: var(--color-button-secondary-hover) !important;
}

/* ===== STATUS BADGES ===== */
.status-pendente {
    background-color: rgba(251, 191, 36, 0.1);
    color: #f59e0b;
    border: 1px solid rgba(251, 191, 36, 0.2);
}

.status-pago {
    background-color: rgba(16, 185, 129, 0.1);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-atrasado {
    background-color: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* ===== MODAL STYLES ===== */
.modal {
    display: none;
    backdrop-filter: blur(4px);
    background-color: rgba(0, 0, 0, 0.5);
}

.modal.active {
    display: flex !important;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    animation: slideUp 0.3s ease;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    background-color: var(--color-bg-secondary) !important;
    color: var(--color-text-primary) !important;
    border: 1px solid var(--color-border);
}

@keyframes slideUp {
    from { 
        transform: translateY(20px);
        opacity: 0;
    }
    to { 
        transform: translateY(0);
        opacity: 1;
    }
}

/* ===== FLOATING BUTTON ===== */
.btn-floating {
    position: fixed;
    bottom: calc(20px + var(--safe-area-inset-bottom));
    right: calc(20px + var(--safe-area-inset-right));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    z-index: 1000;
    background-color: var(--color-button-primary) !important;
    color: white !important;
    border: none;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.btn-floating:hover {
    background-color: var(--color-button-primary-hover) !important;
    transform: scale(1.05);
}

.btn-floating:active {
    transform: scale(0.95);
}

/* ===== SIDEBAR ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 18rem;
    padding: 1rem;
    background-color: var(--color-bg-secondary) !important;
    color: var(--color-text-primary) !important;
    box-shadow: 0 4px 12px var(--color-shadow-lg);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 50;
    border-right: 1px solid var(--color-border);
}

.sidebar.active {
    transform: translateX(0);
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.4);
    display: none;
    z-index: 40;
}

.sidebar-overlay.active {
    display: flex;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem;
    background-color: transparent;
    border: 1px solid transparent;
    border-radius: 0.5rem;
    transition: all 0.2s ease;
    text-align: left;
    color: var(--color-text-primary) !important;
    cursor: pointer;
}

.sidebar-item:hover {
    background-color: var(--color-bg-tertiary) !important;
    border-color: var(--color-border);
}

.sidebar-item-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

/* ===== HAMBURGER MENU ===== */
.hamburger span {
    display: block;
    width: 1.5rem;
    height: 0.125rem;
    background-color: var(--color-text-primary);
    margin: 0.25rem 0;
    transition: all 0.3s ease;
}

.hamburger.active span:nth-child(1) {
    transform: rotate(45deg) translateY(0.5rem);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    transform: rotate(-45deg) translateY(-0.5rem);
}

/* ===== NOTIFICATIONS ===== */
.notification-toast {
    position: fixed;
    top: calc(20px + var(--safe-area-inset-top));
    right: calc(20px + var(--safe-area-inset-right));
    left: calc(20px + var(--safe-area-inset-left));
    z-index: 9999;
    transform: translateY(-100px);
    transition: transform 0.3s ease;
    background-color: var(--color-bg-secondary) !important;
    color: var(--color-text-primary) !important;
    border: 1px solid var(--color-border);
    box-shadow: 0 4px 12px var(--color-shadow-lg);
}

.notification-toast.show {
    transform: translateY(0);
}

.notification-bell {
    position: relative;
    animation: none;
}

.notification-bell.has-alerts {
    animation: bellShake 0.5s ease-in-out infinite;
}

@keyframes bellShake {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-10deg); }
    75% { transform: rotate(10deg); }
}

.notification-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* ===== HEADER ===== */
header {
    background-color: var(--color-bg-secondary) !important;
    border-bottom: 1px solid var(--color-border) !important;
    color: var(--color-text-primary) !important;
}

.header-logo {
    color: var(--color-text-primary) !important;
}

/* ===== SPLASH SCREEN ===== */
.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: white;
    z-index: 10000;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.splash-screen.hide {
    opacity: 0;
    pointer-events: none;
}

.splash-logo {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ===== TOAST COLORS ===== */
.bg-red-50 {
    background-color: var(--color-bg-secondary) !important;
    border-left-color: #ef4444 !important;
}

.bg-yellow-50 {
    background-color: var(--color-bg-secondary) !important;
    border-left-color: #f59e0b !important;
}

.bg-blue-50 {
    background-color: var(--color-bg-secondary) !important;
    border-left-color: #3b82f6 !important;
}

.bg-green-50 {
    background-color: var(--color-bg-secondary) !important;
    border-left-color: #10b981 !important;
}

.text-red-800, .text-yellow-800, .text-blue-800, .text-green-800 {
    color: var(--color-text-primary) !important;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .payment-card {
        margin: 0 -4px;
    }

    .modal-content {
        margin: 10px;
        border-radius: 16px;
        max-height: calc(100vh - 20px);
    }

    .header-actions {
        gap: 8px;
    }

    .header-actions button {
        padding: 8px 12px;
        font-size: 14px;
    }

    .notification-toast {
        left: calc(10px + var(--safe-area-inset-left));
        right: calc(10px + var(--safe-area-inset-right));
    }
}

@media (min-width: 768px) {
    .dashboard-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .btn-floating {
        bottom: 30px;
        right: 30px;
    }

    .notification-toast {
        right: 30px;
        left: auto;
        max-width: 400px;
    }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== FOCUS STATES ===== */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--color-button-primary);
    outline-offset: 2px;
}

/* ===== LOADING STATE ===== */
.loading {
    opacity: 0.5;
    pointer-events: none;
}

/* ===== TOUCH OPTIMIZATIONS ===== */
* {
    -webkit-tap-highlight-color: transparent;
}

button, a, [role="button"] {
    touch-action: manipulation;
    min-height: 44px;
    min-width: 44px;
}

.scroll-container {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* ===== DARK MODE SPECIFIC ADJUSTMENTS ===== */
.dark .bg-gray-300 {
    background-color: var(--color-button-secondary) !important;
    color: var(--color-text-primary) !important;
}

.dark .bg-gray-300:hover {
    background-color: var(--color-button-secondary-hover) !important;
}

.dark .hover\:bg-gray-50:hover {
    background-color: var(--color-bg-tertiary) !important;
}

.dark .hover\:bg-gray-100:hover {
    background-color: var(--color-bg-tertiary) !important;
}

/* ===== ATTENTION PULSE ===== */
.attention-pulse {
    animation: attentionPulse 2s infinite;
}

@keyframes attentionPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

/* ===== FORCE CORRECT COLORS ON PROBLEMATIC ELEMENTS ===== */
main {
    background-color: var(--color-bg-primary) !important;
    color: var(--color-text-primary) !important;
}

.bg-gray-50 {
    background-color: var(--color-bg-primary) !important;
}

/* Ensure all text inherits correct color */
p, span, div, h1, h2, h3, h4, h5, h6 {
    color: inherit;
}

/* Fix specific problematic classes */
.text-gray-500.dark\:text-gray-400 {
    color: var(--color-text-tertiary) !important;
}

.text-gray-600.dark\:text-gray-400 {
    color: var(--color-text-secondary) !important;
}

.text-gray-900.dark\:text-gray-100 {
    color: var(--color-text-primary) !important;
}