/* ========================================
   VARIABLES Y CONFIGURACIÓN GLOBAL
   ======================================== */
:root {
    --primary-color: #2563eb;
    --primary-dark: #1e40af;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --info-color: #3b82f6;
    
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-dark: #1e293b;
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-light: #64748b;
    
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 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);
    
    --sidebar-width: 260px;
    --topbar-height: 70px;
    
    --transition: all 0.3s ease;
}

/* Dark Theme Variables */
body.dark-theme {
    --bg-primary: #1e293b;
    --bg-secondary: #0f172a;
    --bg-dark: #334155;
    
    --text-primary: #f8fafc;
    --text-secondary: #e2e8f0;
    --text-light: #cbd5e1;
    
    --border-color: #334155;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3), 0 1px 2px 0 rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
}

/* Dark Theme Specific Overrides */
body.dark-theme .form-control {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    border-color: var(--border-color);
}

body.dark-theme .form-control::placeholder {
    color: var(--text-light);
}

body.dark-theme .form-control:disabled {
    background-color: var(--bg-secondary);
    color: var(--text-light);
}

/* Alertas en modo oscuro */
body.dark-theme .alert-success {
    background-color: rgba(16, 185, 129, 0.15);
    color: #6ee7b7;
    border-color: rgba(16, 185, 129, 0.3);
}

body.dark-theme .alert-error {
    background-color: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.3);
}

body.dark-theme .alert-warning {
    background-color: rgba(245, 158, 11, 0.15);
    color: #fcd34d;
    border-color: rgba(245, 158, 11, 0.3);
}

body.dark-theme .alert-info {
    background-color: rgba(59, 130, 246, 0.15);
    color: #93c5fd;
    border-color: rgba(59, 130, 246, 0.3);
}

/* Badges en modo oscuro */
body.dark-theme .badge-success {
    background-color: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
}

body.dark-theme .badge-warning {
    background-color: rgba(245, 158, 11, 0.2);
    color: #fcd34d;
}

body.dark-theme .badge-danger {
    background-color: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

body.dark-theme .badge-info {
    background-color: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

body.dark-theme .badge-secondary {
    background-color: var(--bg-dark);
    color: var(--text-secondary);
}

/* Quick action buttons en modo oscuro */
body.dark-theme .quick-action-btn {
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-secondary) 100%);
    border-color: var(--border-color);
    color: var(--text-primary);
}

body.dark-theme .quick-action-btn:hover {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
}

body.dark-theme .quick-action-btn svg {
    color: var(--primary-color);
}

body.dark-theme .quick-action-btn:hover svg {
    color: white;
}

/* Tablas en modo oscuro */
body.dark-theme .table th {
    color: var(--text-primary);
}

body.dark-theme .table td {
    color: var(--text-secondary);
    border-bottom-color: var(--border-color);
}

body.dark-theme .table tbody tr:hover {
    background-color: var(--bg-dark);
}

body.dark-theme .table thead {
    background-color: var(--bg-dark);
}

/* Títulos y textos en modo oscuro */
body.dark-theme h1,
body.dark-theme h2,
body.dark-theme h3,
body.dark-theme h4,
body.dark-theme h5,
body.dark-theme h6 {
    color: var(--text-primary);
}

body.dark-theme label {
    color: var(--text-primary) !important;
}

body.dark-theme .form-group label {
    color: var(--text-primary) !important;
}

body.dark-theme .form-section h3 {
    color: var(--text-primary) !important;
}

body.dark-theme .form-section {
    background-color: var(--bg-primary) !important;
}

body.dark-theme .calc-display {
    background-color: var(--bg-dark) !important;
}

body.dark-theme .calc-row {
    color: var(--text-primary) !important;
}

body.dark-theme .calc-row.total {
    color: var(--text-primary) !important;
}

/* Sobrescribir fondos blancos y claros en modo oscuro */
body.dark-theme [style*="background: white"],
body.dark-theme [style*="background:white"],
body.dark-theme [style*="background: #fff"],
body.dark-theme [style*="background:#fff"],
body.dark-theme [style*="background: #ffffff"],
body.dark-theme [style*="background:#ffffff"],
body.dark-theme [style*="background: #f8f9fa"],
body.dark-theme [style*="background:#f8f9fa"],
body.dark-theme [style*="background: #f5f7fa"],
body.dark-theme [style*="background:#f5f7fa"],
body.dark-theme [style*="background: #e9ecef"],
body.dark-theme [style*="background:#e9ecef"],
body.dark-theme [style*="background: #f0f7ff"],
body.dark-theme [style*="background:#f0f7ff"],
body.dark-theme [style*="background: #eff6ff"],
body.dark-theme [style*="background:#eff6ff"],
body.dark-theme [style*="background: #e3f2fd"],
body.dark-theme [style*="background:#e3f2fd"],
body.dark-theme [style*="background: #f0f4ff"],
body.dark-theme [style*="background:#f0f4ff"],
body.dark-theme [style*="background: #f9fafb"],
body.dark-theme [style*="background:#f9fafb"],
body.dark-theme [style*="background: #f3f4f6"],
body.dark-theme [style*="background:#f3f4f6"],
body.dark-theme [style*="background: #fafafa"],
body.dark-theme [style*="background:#fafafa"],
body.dark-theme [style*="background: #f5f5f5"],
body.dark-theme [style*="background:#f5f5f5"],
body.dark-theme [style*="background: #f9f9f9"],
body.dark-theme [style*="background:#f9f9f9"] {
    background: var(--bg-primary) !important;
}

/* Sobrescribir colores de texto oscuros en modo oscuro */
body.dark-theme [style*="color: #2c3e50"],
body.dark-theme [style*="color:#2c3e50"],
body.dark-theme [style*="color: #34495e"],
body.dark-theme [style*="color:#34495e"],
body.dark-theme [style*="color: #495057"],
body.dark-theme [style*="color:#495057"],
body.dark-theme [style*="color: #212529"],
body.dark-theme [style*="color:#212529"] {
    color: var(--text-primary) !important;
}

/* Badges de estado en modo oscuro - mantener colores pero ajustar fondos */
body.dark-theme .status-badge.vigente,
body.dark-theme .badge-QUI,
body.dark-theme .type-badge.preventivo {
    background: rgba(76, 175, 80, 0.2) !important;
    color: #81c784 !important;
}

body.dark-theme .status-badge.proxima,
body.dark-theme .badge-HEM {
    background: rgba(33, 150, 243, 0.2) !important;
    color: #64b5f6 !important;
}

body.dark-theme .status-badge.urgente,
body.dark-theme .badge-EMO,
body.dark-theme .urgency-badge.esta_semana {
    background: rgba(255, 152, 0, 0.2) !important;
    color: #ffb74d !important;
}

body.dark-theme .status-badge.vencida,
body.dark-theme .type-badge.correctivo,
body.dark-theme .badge-inactivo {
    background: rgba(244, 67, 54, 0.2) !important;
    color: #e57373 !important;
}

body.dark-theme .badge-COPRO {
    background: rgba(156, 39, 176, 0.2) !important;
    color: #ba68c8 !important;
}

body.dark-theme .badge-MICRO {
    background: rgba(233, 30, 99, 0.2) !important;
    color: #f06292 !important;
}

body.dark-theme .badge-INMU {
    background: rgba(0, 121, 107, 0.2) !important;
    color: #4db6ac !important;
}

body.dark-theme .badge-pendiente {
    background: rgba(255, 193, 7, 0.2) !important;
    color: #ffd54f !important;
}

body.dark-theme .badge-cancelado {
    background: rgba(244, 67, 54, 0.2) !important;
    color: #e57373 !important;
}

/* Fondos de alertas y avisos en modo oscuro */
body.dark-theme [style*="background: #fff3cd"],
body.dark-theme [style*="background:#fff3cd"],
body.dark-theme [style*="background: #fff3e0"],
body.dark-theme [style*="background:#fff3e0"],
body.dark-theme [style*="background: #fffbeb"],
body.dark-theme [style*="background:#fffbeb"] {
    background: rgba(255, 193, 7, 0.15) !important;
}

body.dark-theme [style*="background: #ffebee"],
body.dark-theme [style*="background:#ffebee"],
body.dark-theme [style*="background: #f8d7da"],
body.dark-theme [style*="background:#f8d7da"] {
    background: rgba(244, 67, 54, 0.15) !important;
}

body.dark-theme [style*="background: #e8f5e9"],
body.dark-theme [style*="background:#e8f5e9"],
body.dark-theme [style*="background: #f0fdf4"],
body.dark-theme [style*="background:#f0fdf4"] {
    background: rgba(76, 175, 80, 0.15) !important;
}

body.dark-theme [style*="background: #f3e5f5"],
body.dark-theme [style*="background:#f3e5f5"] {
    background: rgba(156, 39, 176, 0.15) !important;
}

/* Barras de progreso en modo oscuro */
body.dark-theme [style*="background: #e0e0e0"],
body.dark-theme [style*="background:#e0e0e0"] {
    background: var(--bg-dark) !important;
}

/* Colores de texto de estado que deben mantenerse visibles */
body.dark-theme [style*="color: #2e7d32"],
body.dark-theme [style*="color:#2e7d32"],
body.dark-theme [style*="color: #388e3c"],
body.dark-theme [style*="color:#388e3c"] {
    color: #81c784 !important;
}

body.dark-theme [style*="color: #1976d2"],
body.dark-theme [style*="color:#1976d2"],
body.dark-theme [style*="color: #1565c0"],
body.dark-theme [style*="color:#1565c0"],
body.dark-theme [style*="color: #2563eb"],
body.dark-theme [style*="color:#2563eb"] {
    color: #64b5f6 !important;
}

body.dark-theme [style*="color: #f57c00"],
body.dark-theme [style*="color:#f57c00"],
body.dark-theme [style*="color: #e65100"],
body.dark-theme [style*="color:#e65100"],
body.dark-theme [style*="color: #856404"],
body.dark-theme [style*="color:#856404"] {
    color: #ffb74d !important;
}

body.dark-theme [style*="color: #c62828"],
body.dark-theme [style*="color:#c62828"],
body.dark-theme [style*="color: #721c24"],
body.dark-theme [style*="color:#721c24"] {
    color: #e57373 !important;
}

body.dark-theme [style*="color: #7b1fa2"],
body.dark-theme [style*="color:#7b1fa2"] {
    color: #ba68c8 !important;
}

body.dark-theme [style*="color: #c2185b"],
body.dark-theme [style*="color:#c2185b"] {
    color: #f06292 !important;
}

body.dark-theme [style*="color: #00796b"],
body.dark-theme [style*="color:#00796b"] {
    color: #4db6ac !important;
}

body.dark-theme [style*="color: #4caf50"],
body.dark-theme [style*="color:#4caf50"],
body.dark-theme [style*="color: #2f855a"],
body.dark-theme [style*="color:#2f855a"],
body.dark-theme [style*="color: #27ae60"],
body.dark-theme [style*="color:#27ae60"],
body.dark-theme [style*="color: #28a745"],
body.dark-theme [style*="color:#28a745"] {
    color: #81c784 !important;
}

/* Colores de advertencia adicionales en modo oscuro */
body.dark-theme [style*="color: #f44336"],
body.dark-theme [style*="color:#f44336"],
body.dark-theme [style*="color: #dc3545"],
body.dark-theme [style*="color:#dc3545"],
body.dark-theme [style*="color: #e74c3c"],
body.dark-theme [style*="color:#e74c3c"] {
    color: #f87171 !important;
}

/* Colores de información adicionales en modo oscuro */
body.dark-theme [style*="color: #667eea"],
body.dark-theme [style*="color:#667eea"],
body.dark-theme [style*="color: #3498db"],
body.dark-theme [style*="color:#3498db"],
body.dark-theme [style*="color: #17a2b8"],
body.dark-theme [style*="color:#17a2b8"] {
    color: #60a5fa !important;
}

/* Colores grises y textos secundarios en modo oscuro */
body.dark-theme [style*="color: #999"],
body.dark-theme [style*="color:#999"],
body.dark-theme [style*="color: #7f8c8d"],
body.dark-theme [style*="color:#7f8c8d"],
body.dark-theme [style*="color: #95a5a6"],
body.dark-theme [style*="color:#95a5a6"],
body.dark-theme [style*="color: #6b7280"],
body.dark-theme [style*="color:#6b7280"],
body.dark-theme [style*="color: #718096"],
body.dark-theme [style*="color:#718096"],
body.dark-theme [style*="color: #64748b"],
body.dark-theme [style*="color:#64748b"] {
    color: var(--text-light) !important;
}

/* Colores de advertencia naranja en modo oscuro */
body.dark-theme [style*="color: #f39c12"],
body.dark-theme [style*="color:#f39c12"],
body.dark-theme [style*="color: #f59e0b"],
body.dark-theme [style*="color:#f59e0b"],
body.dark-theme [style*="color: #856404"],
body.dark-theme [style*="color:#856404"] {
    color: #fbbf24 !important;
}

body.dark-theme p {
    color: var(--text-secondary);
}

body.dark-theme .text-muted {
    color: var(--text-light) !important;
}

/* Clase auxiliar para textos secundarios */
.text-muted-custom,
.text-secondary-custom {
    color: var(--text-secondary);
}

body.dark-theme .text-muted-custom,
body.dark-theme .text-secondary-custom {
    color: var(--text-light);
}

/* Clases auxiliares para colores de estado */
.text-success-custom { color: #10b981; }
.text-danger-custom { color: #ef4444; }
.text-warning-custom { color: #f59e0b; }
.text-info-custom { color: #3b82f6; }

body.dark-theme .text-success-custom { color: #34d399; }
body.dark-theme .text-danger-custom { color: #f87171; }
body.dark-theme .text-warning-custom { color: #fbbf24; }
body.dark-theme .text-info-custom { color: #60a5fa; }

/* Badges personalizados en modo oscuro */
body.dark-theme .badge-HEM { 
    background: rgba(25, 118, 210, 0.2); 
    color: #90caf9; 
}

body.dark-theme .badge-EMO { 
    background: rgba(245, 124, 0, 0.2); 
    color: #ffb74d; 
}

body.dark-theme .badge-COPRO { 
    background: rgba(123, 31, 162, 0.2); 
    color: #ce93d8; 
}

body.dark-theme .badge-QUI { 
    background: rgba(56, 142, 60, 0.2); 
    color: #81c784; 
}

body.dark-theme .badge-MICRO { 
    background: rgba(194, 24, 91, 0.2); 
    color: #f48fb1; 
}

body.dark-theme .badge-INMU { 
    background: rgba(0, 121, 107, 0.2); 
    color: #80cbc4; 
}

/* Estilos inline comunes en modo oscuro */
body.dark-theme [style*="color: #666"],
body.dark-theme [style*="color:#666"] {
    color: var(--text-secondary) !important;
}

body.dark-theme [style*="background: #f8f9fa"],
body.dark-theme [style*="background:#f8f9fa"],
body.dark-theme [style*="background: #f5f5f5"],
body.dark-theme [style*="background:#f5f5f5"] {
    background: var(--bg-dark) !important;
}

body.dark-theme [style*="background: white"],
body.dark-theme [style*="background:white"],
body.dark-theme [style*="background: #fff"],
body.dark-theme [style*="background:#fff"],
body.dark-theme [style*="background: #ffffff"],
body.dark-theme [style*="background:#ffffff"] {
    background: var(--bg-primary) !important;
}

body.dark-theme [style*="background: #f0fdf4"] {
    background: rgba(16, 185, 129, 0.1) !important;
}

body.dark-theme [style*="background: #e5e7eb"] {
    background: var(--bg-dark) !important;
}

/* Links en modo oscuro */
body.dark-theme a:not(.btn) {
    color: #60a5fa;
}

body.dark-theme a:not(.btn):hover {
    color: #93c5fd;
}

/* ========================================
   RESET Y ESTILOS GLOBALES
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
}

body {
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    max-width: 100vw;
    width: 100%;
}

/* Prevenir desbordamiento en todo el sistema */
.dashboard,
.main-content,
.content-wrapper,
.container-fluid,
.card,
.table-responsive {
    overflow-x: hidden;
    max-width: 100%;
}

/* Hacer todas las tablas responsivas con scroll */
.table-container,
table:not(.no-responsive) {
    overflow-x: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

table {
    max-width: 100%;
}

/* Imágenes y contenido multimedia responsivo */
img,
video,
iframe,
embed,
object {
    max-width: 100%;
    height: auto;
}

/* Pre y code blocks no deben desbordar */
pre,
code {
    overflow-x: auto;
    max-width: 100%;
    word-wrap: break-word;
}

a {
    text-decoration: none;
    color: inherit;
}

ul {
    list-style: none;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
}

/* ========================================
   PÁGINA DE LOGIN
   ======================================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 420px;
}

.login-box {
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 40px;
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-header .logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.login-header h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.login-form {
    margin-top: 20px;
}

.login-footer {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.login-footer p {
    margin-bottom: 8px;
}

/* ========================================
   FORMULARIOS
   ======================================== */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 14px;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    transition: var(--transition);
    background-color: var(--bg-primary);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-control:disabled {
    background-color: var(--bg-secondary);
    cursor: not-allowed;
}

select.form-control {
    cursor: pointer;
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

/* ========================================
   BOTONES
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    transition: var(--transition);
    cursor: pointer;
    border: none;
}

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

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

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

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #475569;
}

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

.btn-success:hover:not(:disabled) {
    background-color: #059669;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background-color: #dc2626;
}

.btn-warning {
    background-color: var(--warning-color);
    color: white;
}

.btn-warning:hover:not(:disabled) {
    background-color: #d97706;
}

.btn-info {
    background-color: #0ea5e9;
    color: white;
}

.btn-info:hover:not(:disabled) {
    background-color: #0284c7;
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-outline:hover:not(:disabled) {
    background-color: var(--bg-secondary);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 16px;
}

.btn-logout {
    background-color: transparent;
    color: var(--danger-color);
    padding: 8px 16px;
}

.btn-logout:hover {
    background-color: rgba(239, 68, 68, 0.1);
}

/* ========================================
   ALERTAS
   ======================================== */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.alert svg {
    flex-shrink: 0;
}

.alert-success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.alert-error {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.alert-warning {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}

.alert-info {
    background-color: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

/* ========================================
   DASHBOARD LAYOUT
   ======================================== */
.dashboard {
    display: flex;
    min-height: 100vh;
}

/* ========================================
   SIDEBAR
   ======================================== */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-dark);
    color: white;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 1000;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

/* Sidebar colapsado */
.sidebar.collapsed {
    width: 70px;
}

.sidebar.collapsed .sidebar-header h2,
.sidebar.collapsed .menu-section-title span,
.sidebar.collapsed .submenu-link span,
.sidebar.collapsed .menu-link span {
    opacity: 0;
    visibility: hidden;
    width: 0;
    overflow: hidden;
}

.sidebar.collapsed .logo img {
    width: 40px !important;
    height: auto;
}

.sidebar.collapsed .menu-arrow {
    display: none;
}

.sidebar.collapsed .submenu {
    display: none !important;
}

.sidebar.collapsed .menu-item.expanded {
    background: transparent;
}

.sidebar.collapsed .menu-section-header,
.sidebar.collapsed .menu-link {
    justify-content: center;
    padding: 12px 10px;
}

.sidebar.collapsed .menu-section-header svg,
.sidebar.collapsed .menu-link svg {
    margin: 0;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.sidebar-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.sidebar-nav {
    padding: 20px 0;
    flex: 1;
    overflow-y: auto;
}

.sidebar-nav ul {
    display: flex;
    flex-direction: column;
}

.sidebar-nav li {
    margin-bottom: 4px;
}

.sidebar-nav li.active a {
    background-color: rgba(37, 99, 235, 0.2);
    color: white;
    border-left: 3px solid var(--primary-color);
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: rgba(255, 255, 255, 0.7);
    transition: var(--transition);
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: white;
}

/* Estilos para menú desplegable */
.menu-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: rgba(255, 255, 255, 0.7);
    transition: var(--transition);
    border-left: 3px solid transparent;
}

.menu-link:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: white;
}

.menu-item {
    margin-bottom: 2px;
}

.menu-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.9);
    transition: var(--transition);
    border-left: 3px solid transparent;
    user-select: none;
}

.menu-section-header:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: white;
}

.menu-section-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
    font-size: 14px;
}

.menu-arrow {
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.menu-item.expanded .menu-arrow {
    transform: rotate(180deg);
}

.submenu {
    max-height: 0 !important;
    overflow: hidden;
    transition: max-height 0.3s ease-out, opacity 0.3s ease-out, visibility 0.3s ease-out;
    background-color: rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
}

.menu-item.expanded .submenu {
    max-height: 500px !important;
    opacity: 1;
    visibility: visible;
}

.submenu-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px 10px 50px;
    color: rgba(255, 255, 255, 0.6);
    transition: var(--transition);
    font-size: 13px;
    border-left: 3px solid transparent;
}

.submenu-heading {
    padding: 12px 20px 4px 50px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: rgba(255, 255, 255, 0.45);
    font-weight: 600;
}

.submenu-link:hover {
    background-color: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.95);
    padding-left: 52px;
}

.submenu-link.active {
    background-color: rgba(37, 99, 235, 0.15);
    color: white;
    border-left: 3px solid var(--primary-color);
}

.submenu-link svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.menu-section {
    padding: 12px 20px 6px 20px;
}

.menu-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.5);
    font-weight: 600;
}

/* Theme Toggle */
.theme-toggle-container {
    margin-top: auto;
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.theme-toggle-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.9);
    transition: var(--transition);
    font-size: 14px;
}

.theme-toggle-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.theme-toggle-btn svg {
    flex-shrink: 0;
}

.theme-toggle-btn .sun-icon {
    display: none;
}

.theme-toggle-btn .moon-icon {
    display: block;
}

body.dark-theme .theme-toggle-btn .sun-icon {
    display: block;
}

body.dark-theme .theme-toggle-btn .moon-icon {
    display: none;
}

.theme-toggle-text {
    flex: 1;
    text-align: left;
}

/* ========================================
   MAIN CONTENT
   ======================================== */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: calc(100vw - var(--sidebar-width));
    overflow-x: hidden;
    transition: var(--transition);
}

/* Main content cuando el sidebar está colapsado */
.main-content.sidebar-collapsed {
    margin-left: 70px;
    max-width: calc(100vw - 70px);
}

/* ========================================
   TOPBAR
   ======================================== */
.topbar {
    height: var(--topbar-height);
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    position: sticky;
    top: 0;
    z-index: 999;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.topbar-left h1 {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-menu {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    color: var(--text-primary);
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-menu:hover {
    background-color: var(--bg-secondary);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-menu:active {
    transform: scale(0.95);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 14px;
}

.user-role {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ========================================
   CONTENT WRAPPER
   ======================================== */
.content-wrapper {
    flex: 1;
    padding: 30px;
    max-width: 100%;
    overflow-x: hidden;
}

@media (max-width: 768px) {
    .content-wrapper {
        padding: 15px;
    }
}

/* ========================================
   CARDS
   ======================================== */
.card {
    background-color: var(--bg-primary);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.card-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    padding: 20px;
}

/* ========================================
   STATS GRID
   ======================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background-color: var(--bg-primary);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
}

.stat-icon {
    width: 64px;
    height: 64px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.stat-icon.bg-blue {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.stat-icon.bg-green {
    background: linear-gradient(135deg, #10b981, #059669);
}

.stat-icon.bg-orange {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

.stat-icon.bg-red {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

.stat-icon.bg-purple {
    background: linear-gradient(135deg, #a855f7, #9333ea);
}

.stat-icon.bg-teal {
    background: linear-gradient(135deg, #14b8a6, #0d9488);
}

.stat-icon.bg-indigo {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
}

.stat-content h3 {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.stat-content p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ========================================
   CONTENT GRID
   ======================================== */
.content-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

/* ========================================
   QUICK ACTIONS
   ======================================== */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.quick-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 12px;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    transition: var(--transition);
    color: var(--text-primary);
    text-decoration: none;
    min-height: 95px;
    box-shadow: var(--shadow-sm);
}

.quick-action-btn:hover {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.quick-action-btn svg {
    color: var(--primary-color);
    flex-shrink: 0;
    transition: var(--transition);
}

.quick-action-btn:hover svg {
    color: white;
    transform: scale(1.1);
}

.quick-action-btn span {
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    line-height: 1.3;
    display: block;
}

/* ========================================
   ACTIVITY LIST
   ======================================== */
.activity-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.activity-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    background-color: var(--bg-secondary);
    border-radius: 6px;
    border-left: 3px solid var(--primary-color);
}

.activity-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.activity-content {
    flex: 1;
}

.activity-content p {
    margin-bottom: 4px;
    color: var(--text-primary);
    font-size: 14px;
}

.activity-content small {
    color: var(--text-secondary);
    font-size: 12px;
}

/* ========================================
   TABLAS
   ======================================== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
    max-width: 100%;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    table-layout: auto;
    min-width: 100%;
}

/* Wrapper para tablas grandes */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    margin: 20px 0;
    background: var(--bg-primary);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.table-wrapper table {
    min-width: 900px;
    margin: 0;
}

.table thead {
    background-color: var(--bg-secondary);
}

.table th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
}

.table td {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

.table tbody tr:hover {
    background-color: var(--bg-secondary);
}

/* ========================================
   BADGES
   ======================================== */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success {
    background-color: #d1fae5;
    color: #065f46;
}

.badge-warning {
    background-color: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background-color: #fee2e2;
    color: #991b1b;
}

.badge-info {
    background-color: #dbeafe;
    color: #1e40af;
}

.badge-secondary {
    background-color: #f1f5f9;
    color: #475569;
}

/* ========================================
   UTILIDADES
   ======================================== */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-muted {
    color: var(--text-secondary);
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }

.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.p-3 { padding: 1.5rem; }
.p-4 { padding: 2rem; }

.d-flex {
    display: flex;
}

.justify-between {
    justify-content: space-between;
}

.align-center {
    align-items: center;
}

.gap-2 {
    gap: 1rem;
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .sidebar.collapsed {
        transform: translateX(-100%);
        width: var(--sidebar-width);
    }
    
    .main-content {
        margin-left: 0 !important;
        max-width: 100vw !important;
    }
    
    .topbar {
        padding: 0 15px;
    }
    
    .topbar-left h1 {
        font-size: 18px;
    }
    
    .user-details {
        display: none;
    }
    
    .content-wrapper {
        padding: 15px;
    }
    
    .stats-grid,
    .content-grid {
        grid-template-columns: 1fr;
    }
    
    .quick-actions {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }
    
    .quick-action-btn {
        min-height: 90px;
        padding: 14px 10px;
    }
    
    .quick-action-btn span {
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .login-box {
        padding: 30px 20px;
    }
    
    .quick-actions {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .quick-action-btn {
        min-height: 85px;
        padding: 12px 8px;
    }
    
    .quick-action-btn svg {
        width: 20px;
        height: 20px;
    }
    
    .quick-action-btn span {
        font-size: 11px;
    }
}

/* ========================================
   UTILIDADES PARA EVITAR DESBORDAMIENTO
   ======================================== */
.container-fluid {
    width: 100%;
    max-width: 100%;
    padding-right: 15px;
    padding-left: 15px;
    margin-right: auto;
    margin-left: auto;
    overflow-x: hidden;
}

.row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -15px;
    margin-left: -15px;
}

.col, .col-auto, .col-md-6, .col-md-4, .col-md-3 {
    position: relative;
    width: 100%;
    padding-right: 15px;
    padding-left: 15px;
}

.flex-grow-1 {
    flex-grow: 1 !important;
    max-width: 100%;
    overflow-x: hidden;
}

.d-flex {
    display: flex !important;
    overflow-x: hidden;
}

.p-4 {
    padding: 1.5rem !important;
}
