:root {
    /* Color Palette - Core */
    --primary-50: #EFF6FF;
    --primary-100: #DBEAFE;
    --primary-500: #3B82F6;
    --primary-600: #2563EB;
    --primary-color: #0F3B84; /* Deep Corporate Navy (Brand) */
    --primary-hover: #0A295C;
    --primary-light: #EBF1F9;
    
    --secondary-color: #1E293B; /* Slate 800 */
    --secondary-light: #334155; /* Slate 700 */
    
    /* Semantic Colors */
    --accent-color: #059669; /* Emerald 600 */
    --accent-hover: #047857;
    --error-color: #DC2626; /* Red 600 */
    --warning-color: #D97706; /* Amber 600 */
    --info-color: #0284C7; /* Sky 600 */
    
    /* Neutrals & Surfaces */
    --bg-color: #F8FAFC; /* Slate 50 */
    --card-bg: #FFFFFF;
    --text-main: #0F172A; /* Slate 900 */
    --text-muted: #475569; /* Slate 600 */
    --border-color: #CBD5E1; /* Slate 300 */
    
    /* Spacing Tokens */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    
    /* Typography & Structure */
    --font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    
    --border-radius: 6px;
    --border-radius-sm: 4px;
    --border-radius-pill: 9999px;
    
    /* Solid Shadows */
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    /* Focus Ring (A11y) */
    --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.4);
    
    --transition-speed: 0.2s;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color var(--transition-speed) ease;
}

a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

a:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--border-radius-sm);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--secondary-color);
    margin-bottom: 0.5rem;
    letter-spacing: -0.01em;
}

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* Auth Layout */
.auth-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 2rem;
    background-color: var(--bg-color);
}

.auth-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    padding: 2.5rem 2.5rem;
    width: 100%;
    max-width: 420px;
    border: 1px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header img {
    height: 50px;
    margin-bottom: 1rem;
}

.auth-header h1 {
    font-size: 1.5rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

/* Dashboard Layout */
.dashboard-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    background: var(--secondary-color);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-speed) ease;
    border-right: 1px solid rgba(0,0,0,0.1);
    z-index: 10;
}

.sidebar-brand {
    padding: 1.25rem 1.5rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: #FFFFFF;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: 0;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.85rem 1.5rem;
    color: #CBD5E1;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all var(--transition-speed) ease;
    gap: 12px;
    border-left: 3px solid transparent;
}

.nav-item i {
    font-size: 1.05rem;
    width: 20px;
    text-align: center;
}

.nav-item:hover {
    background: rgba(255,255,255,0.05);
    color: #FFFFFF;
    text-decoration: none;
}

.nav-item.active {
    background: rgba(255,255,255,0.08);
    color: #FFFFFF;
    border-left-color: var(--primary-color);
    font-weight: 600;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

.top-header {
    background: var(--card-bg);
    height: 60px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    box-shadow: var(--shadow-xs);
    position: sticky;
    top: 0;
    z-index: 5;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--secondary-color);
}

.content-area {
    padding: 2rem;
    flex: 1;
    overflow-y: auto;
}

/* Cards & Widgets */
.grid-widgets {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.widget-card {
    background: var(--card-bg);
    padding: 1.25rem 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 1.25rem;
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary-color);
}

.widget-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--border-radius-sm);
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
    font-size: 1.5rem;
}

.widget-info h3 {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.widget-info p {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--secondary-color);
    line-height: 1.2;
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--secondary-color);
}

.form-control {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-family: var(--font-family);
    font-size: 0.9rem;
    background-color: #FFFFFF;
    color: var(--text-main);
    transition: border-color var(--transition-speed) ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: var(--focus-ring);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1.25rem;
    border-radius: var(--border-radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background-color var(--transition-speed) ease, border-color var(--transition-speed) ease;
    border: 1px solid transparent;
    gap: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn:hover {
    text-decoration: none;
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.btn i {
    font-size: 0.95rem;
}

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-hover);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-success {
    background-color: var(--accent-color);
    border-color: var(--accent-hover);
    color: white;
}

.btn-success:hover {
    background-color: var(--accent-hover);
}

.btn-danger {
    background-color: var(--error-color);
    border-color: #B91C1C;
    color: white;
}

.btn-danger:hover {
    background-color: #B91C1C;
}

.btn-outline {
    background-color: #FFFFFF;
    border-color: var(--border-color);
    color: var(--secondary-color);
}

.btn-outline:hover {
    background-color: var(--bg-color);
    border-color: #94A3B8;
}

.btn-outline.text-success { color: var(--accent-color); }
.btn-outline.text-danger { color: var(--error-color); }
.btn-outline.text-warning { color: var(--warning-color); }
.btn-outline.text-info { color: var(--info-color); }

.btn-block {
    width: 100%;
}

.btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

/* Tables (Corporate DataGrid Style) */
.table-container {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
    border: 1px solid var(--border-color);
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th, .table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
    vertical-align: middle;
}

.table th {
    background: var(--bg-color);
    font-weight: 600;
    color: var(--secondary-color);
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.table tbody tr:hover {
    background-color: #F8FAFC;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* Badges */
.badge {
    padding: 0.2rem 0.5rem;
    border-radius: var(--border-radius-sm);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.badge-success { background: #DEF7EC; color: #03543F; border: 1px solid #84E1BC; }
.badge-warning { background: #FDF6B2; color: #723B13; border: 1px solid #FACA15; }
.badge-danger { background: #FDE8E8; color: #9B1C1C; border: 1px solid #F8B4B4; }
.badge-info { background: #E1EFFE; color: #1E429F; border: 1px solid #A4CAFE; }
.badge-neutral { background: #F3F4F6; color: #374151; border: 1px solid #D1D5DB; }

/* Modals (Solid Corporate) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.75);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 5vh;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    position: relative;
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #F8FAFC;
    position: sticky;
    top: 0;
    z-index: 10;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.15rem;
    color: var(--primary-color);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    background: #F8FAFC;
    position: sticky;
    bottom: 0;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    min-width: 300px;
    padding: 1rem 1.25rem;
    border-radius: var(--border-radius-sm);
    color: white;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    font-size: 0.9rem;
}

.toast.success { background-color: var(--accent-color); }
.toast.error { background-color: var(--error-color); }
.toast.warning { background-color: var(--warning-color); }
.toast.info { background-color: var(--primary-color); }

/* Responsive */
#mobileMenuBtn {
    display: none;
}

@media (max-width: 768px) {
    #mobileMenuBtn {
        display: inline-flex;
    }

    .dashboard-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        transform: translateX(-100%);
        position: fixed;
        z-index: 100;
        height: 100vh;
        box-shadow: 4px 0 15px rgba(0,0,0,0.2);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .top-header {
        padding: 0 1rem;
    }
    
    .content-area {
        padding: 1rem;
    }
}

/* Utilities */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 1rem; }
.w-100 { width: 100%; }
.text-primary { color: var(--primary-color); }
.text-muted { color: var(--text-muted); }
.text-warning { color: var(--warning-color); }
.text-success { color: var(--accent-color); }
.text-danger { color: var(--error-color); }

/* Standard Scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: #F1F5F9; 
    border-left: 1px solid var(--border-color);
}

::-webkit-scrollbar-thumb {
    background: #94A3B8; 
}

::-webkit-scrollbar-thumb:hover {
    background: #64748B; 
}

/* Print Media */
@media print { 
    body {
        background-color: white !important;
    }
    .dashboard-layout, .auth-wrapper, .d-print-none { 
        display: none !important; 
    }
    .modal-overlay {
        position: static !important;
        background: transparent !important;
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
    .modal-content {
        box-shadow: none !important;
        max-width: 100% !important;
        margin: 0 !important;
        border: none !important;
    }
    #facturaPrintArea {
        padding: 1rem !important;
    }
    @page { margin: 0.5cm; size: auto; }
}
