/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Sistema de colores moderno - Fase 1 */
    /* Colores primarios - Azul corporativo moderno */
    --primary-50: #eff6ff;
    --primary-100: #dbeafe;
    --primary-200: #bfdbfe;
    --primary-300: #93c5fd;
    --primary-400: #60a5fa;
    --primary-500: #3b82f6;
    --primary-600: #2563eb;
    --primary-700: #1d4ed8;
    --primary-800: #1e40af;
    --primary-900: #1e3a8a;
    
    /* Colores semánticos mejorados */
    --success-50: #ecfdf5;
    --success-100: #d1fae5;
    --success-500: #10b981;
    --success-600: #059669;
    --success-700: #047857;
    
    --warning-50: #fffbeb;
    --warning-100: #fef3c7;
    --warning-500: #f59e0b;
    --warning-600: #d97706;
    --warning-700: #b45309;
    
    --error-50: #fef2f2;
    --error-100: #fee2e2;
    --error-500: #ef4444;
    --error-600: #dc2626;
    --error-700: #b91c1c;
    
    --info-50: #f0f9ff;
    --info-100: #e0f2fe;
    --info-500: #06b6d4;
    --info-600: #0891b2;
    --info-700: #0e7490;
    
    /* Gradientes modernos */
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --gradient-warning: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    --gradient-error: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    
    /* Compatibilidad con sistema anterior */
    --primary-color: var(--primary-600);
    --primary-dark: var(--primary-700);
    --secondary-color: #64748b;
    --success-color: var(--success-500);
    --warning-color: var(--warning-500);
    --error-color: var(--error-500);
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    
    /* Layout variables */
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 70px;
    --topbar-height: 70px;
    --border-radius: 12px; /* Más redondeado para look moderno */
    --border-radius-sm: 8px;
    --border-radius-lg: 16px;
    
    /* Sombras mejoradas */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 10px 10px -5px rgb(0 0 0 / 0.04);
    
    /* Transiciones suaves */
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Layout */
#app-container {
    display: flex;
    min-height: 100vh;
}

/* Configuración pages layout */
.container-fluid .row {
    margin-left: 0;
    margin-right: 0;
}

.container-fluid .row .col-md-2.sidebar {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    height: 100vh !important;
    z-index: 1000 !important;
    width: var(--sidebar-width) !important;
}

.container-fluid .row .col-md-10 {
    margin-left: var(--sidebar-width) !important;
    padding-left: 20px !important;
    padding-right: 20px !important;
}

/* Configuración pages specific styles */
.config-page {
    margin-left: var(--sidebar-width) !important;
    padding: 20px !important;
    min-height: 100vh !important;
    position: relative !important;
    z-index: 1 !important;
}

.config-page .table-responsive {
    margin-top: 20px;
    background: var(--surface-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    overflow: visible;
}

.config-page .table {
    margin-bottom: 0;
}

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

.config-page .table td {
    padding: 12px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
}

.config-page .btn {
    margin: 2px;
}

.config-page .card {
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.config-page .card-header {
    background-color: var(--background-color);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

/* WhatsApp Messaging Module */
.whatsapp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1.5rem;
}

.whatsapp-header .header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.whatsapp-status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.75rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1px solid var(--border-color);
    background: var(--surface-color);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.whatsapp-status .status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border-color);
    display: inline-block;
}

.whatsapp-status.online {
    border-color: var(--success-200);
    color: var(--success-600);
    background: var(--success-50);
}

.whatsapp-status.online .status-dot {
    background: var(--success-500);
}

.whatsapp-status.offline {
    border-color: var(--warning-200);
    color: var(--warning-600);
    background: var(--warning-50);
}

.whatsapp-status.offline .status-dot {
    background: var(--warning-500);
}

.whatsapp-layout {
    display: flex;
    gap: 1.5rem;
    min-height: 640px;
}

.whatsapp-sidebar {
    width: 320px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.whatsapp-sidebar .sidebar-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.search-field {
    position: relative;
    flex: 1;
}

.search-field i {
    position: absolute;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.search-field input {
    width: 100%;
    padding: 0.6rem 0.75rem 0.6rem 2.4rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    background: var(--background-color);
    color: var(--text-primary);
    transition: border var(--transition-fast), box-shadow var(--transition-fast);
}

.search-field input:focus {
    outline: none;
    border-color: var(--primary-300);
    box-shadow: 0 0 0 3px var(--primary-100);
}

.whatsapp-conversation-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-right: 0.25rem;
}

.whatsapp-conversation-item {
    padding: 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--surface-color);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.whatsapp-conversation-item:hover {
    border-color: var(--primary-200);
    box-shadow: var(--shadow-md);
}

.whatsapp-conversation-item.active {
    border-color: var(--primary-500);
    background: var(--primary-50);
    box-shadow: var(--shadow-md);
}

.whatsapp-conversation-item .conversation-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.25rem;
    font-weight: 600;
}

.whatsapp-conversation-item .conversation-title .name {
    color: var(--text-primary);
    font-size: 0.95rem;
}

.whatsapp-conversation-item .conversation-title .time {
    color: var(--text-secondary);
    font-size: 0.75rem;
    white-space: nowrap;
}

.whatsapp-conversation-item .conversation-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.whatsapp-conversation-item .conversation-preview {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    line-height: 1.3;
}

.whatsapp-empty,
.whatsapp-loading {
    background: var(--surface-color);
    border: 1px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 2rem;
    text-align: center;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.95rem;
}

.whatsapp-loading i {
    font-size: 1.2rem;
}

.whatsapp-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem;
}

.whatsapp-empty-state i {
    font-size: 3rem;
    color: var(--primary-400);
}

.whatsapp-empty-state h3 {
    font-size: 1.3rem;
    color: var(--text-primary);
    font-weight: 600;
}

.whatsapp-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.whatsapp-conversation-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.conversation-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.conversation-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.conversation-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    font-weight: 600;
}

.status-chip.status-active {
    background: var(--success-50);
    color: var(--success-600);
}

.status-chip.status-closed {
    background: var(--warning-50);
    color: var(--warning-600);
}

.conversation-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    background: var(--background-color);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.whatsapp-message {
    display: flex;
    align-items: flex-end;
}

.whatsapp-message.inbound {
    justify-content: flex-start;
}

.whatsapp-message.outbound {
    justify-content: flex-end;
}

.whatsapp-message .message-bubble {
    max-width: 70%;
    background: #ffffff;
    border-radius: 1.2rem;
    padding: 0.85rem 1rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(148, 163, 184, 0.2);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
}

.whatsapp-message.outbound .message-bubble {
    background: linear-gradient(135deg, #34d399 0%, #10b981 100%);
    color: #ffffff;
    border: none;
}

.whatsapp-message.outbound .message-meta span,
.whatsapp-message.outbound .message-meta i {
    color: rgba(255, 255, 255, 0.8);
}

.whatsapp-message .message-text {
    font-size: 0.95rem;
    line-height: 1.5;
}

.message-type-pill {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.whatsapp-message.outbound .message-type-pill {
    color: rgba(255, 255, 255, 0.85);
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.message-attachment {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--surface-color);
    transition: border var(--transition-fast), box-shadow var(--transition-fast);
}

.message-attachment:hover {
    border-color: var(--primary-200);
    box-shadow: var(--shadow-sm);
}

.whatsapp-message.outbound .message-attachment {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.4);
}

.attachment-preview img {
    max-width: 120px;
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-sm);
}

.attachment-body {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex: 1;
}

.attachment-icon {
    font-size: 1.5rem;
    color: var(--primary-500);
}

.attachment-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.attachment-name {
    font-weight: 600;
    color: var(--text-primary);
}

.attachment-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.attachment-actions .btn {
    padding: 0.35rem 0.6rem;
}

.attachment-actions .btn i {
    font-size: 0.9rem;
}

.attachment-pending {
    font-size: 0.8rem;
    color: var(--warning-600);
}

.conversation-composer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--surface-color);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.conversation-composer textarea {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    resize: none;
    min-height: 80px;
    transition: border var(--transition-fast), box-shadow var(--transition-fast);
}

.conversation-composer textarea:focus {
    outline: none;
    border-color: var(--primary-300);
    box-shadow: 0 0 0 3px var(--primary-100);
}

.composer-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.attachment-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn.btn-text {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 0.25rem;
    cursor: pointer;
    transition: color var(--transition-fast);
}

.btn.btn-text:hover {
    color: var(--error-500);
}

.composer-notice {
    margin: 0 1.5rem 1rem;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
}

@media (max-width: 1024px) {
    .whatsapp-layout {
        flex-direction: column;
    }

    .whatsapp-sidebar {
        width: 100%;
    }

    .whatsapp-main {
        min-height: 540px;
    }
}

@media (max-width: 768px) {
    .whatsapp-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .whatsapp-sidebar .sidebar-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .composer-footer {
        flex-direction: column;
        align-items: stretch;
    }

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

    .whatsapp-conversation-item .conversation-title {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.1rem;
    }
}

/* Responsive adjustments for config pages */
@media (max-width: 768px) {
    .container-fluid .row .col-md-2.sidebar {
        position: relative;
        height: auto;
        width: 100%;
    }
    
    .container-fluid .row .col-md-10 {
        margin-left: 0;
        padding-left: 15px;
        padding-right: 15px;
    }
    
    .config-page {
        margin-left: 0;
        padding: 15px;
    }
}

/* Ensure tables are fully visible */
.config-page .table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100% !important;
    max-width: none !important;
}

.config-page .table {
    min-width: 600px !important;
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* Force visibility of main content */
.config-page .card {
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100% !important;
    max-width: none !important;
}

.config-page .card-body {
    padding: 20px !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* Override any conflicting styles for config pages */
body .config-page {
    margin-left: var(--sidebar-width) !important;
    padding-left: 20px !important;
    padding-right: 20px !important;
    width: calc(100% - var(--sidebar-width)) !important;
    max-width: none !important;
    position: relative !important;
    z-index: 1 !important;
}

/* Ensure main content is not hidden behind sidebar */
.container-fluid .row .col-md-9,
.container-fluid .row .col-md-10 {
    margin-left: var(--sidebar-width) !important;
    padding-left: 20px !important;
    padding-right: 20px !important;
    width: calc(100% - var(--sidebar-width)) !important;
    max-width: none !important;
}

/* Modal adjustments for config pages */
.config-page .modal-dialog {
    max-width: 500px;
}

.config-page .modal-body {
    padding: 20px;
}

.config-page .form-label {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.config-page .form-control,
.config-page .form-select {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 10px 12px;
}

.config-page .form-control:focus,
.config-page .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.25);
}

/* Sidebar - Mejorado con efectos modernos */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--surface-color) 0%, rgba(248, 250, 252, 0.95) 100%);
    backdrop-filter: blur(10px);
    border-right: 1px solid rgba(255, 255, 255, 0.2);
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 1000;
    transition: all var(--transition-normal);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Sidebar header mejorado */
.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-height);
    background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 100%);
    backdrop-filter: blur(10px);
    position: relative;
}

.sidebar-header::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 1.5rem;
    right: 1.5rem;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.3), transparent);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary-color);
    transition: all var(--transition-normal);
    position: relative;
}

.logo:hover {
    transform: scale(1.02);
}

.logo i {
    font-size: 1.5rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    transition: all var(--transition-normal);
}

.logo:hover i {
    transform: scale(1.1) rotate(5deg);
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
}

.sidebar-toggle:hover {
    background-color: var(--background-color);
    color: var(--text-primary);
}

.sidebar.collapsed .logo span {
    display: none;
}

.sidebar.collapsed .sidebar-toggle {
    display: none;
}

/* Sidebar Menu */
.sidebar-menu {
    list-style: none;
    padding: 1rem 0;
    flex: 1;
    overflow-y: auto;
}

.menu-item {
    margin: 0.25rem 0;
}

/* Menu items mejorados con efectos sofisticados */
.menu-item a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all var(--transition-normal);
    border-radius: var(--border-radius);
    margin: 0.25rem 0.75rem;
    position: relative;
    overflow: hidden;
}

.menu-item a::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.1), transparent);
    transition: left var(--transition-slow);
}

.menu-item a:hover {
    background: linear-gradient(135deg, var(--primary-50) 0%, rgba(59, 130, 246, 0.05) 100%);
    color: var(--primary-700);
    transform: translateX(4px);
    box-shadow: var(--shadow-sm);
}

.menu-item a:hover::before {
    left: 100%;
}

.menu-item a:hover i {
    transform: scale(1.1);
    color: var(--primary-600);
}

.menu-item.active a {
    background: var(--gradient-primary);
    color: white;
    position: relative;
    box-shadow: var(--shadow-md);
    transform: translateX(4px);
}

.menu-item.active a::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(180deg, rgba(255,255,255,0.8) 0%, rgba(255,255,255,0.4) 100%);
    border-radius: 0 2px 2px 0;
}

.menu-item.active a i {
    transform: scale(1.1);
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}

/* Submenu styles */
.menu-item.has-submenu {
    position: relative;
}

.menu-item.has-submenu > a {
    position: relative;
}

.submenu-toggle {
    margin-left: auto;
    transition: transform var(--transition-normal);
    font-size: 0.75rem;
}

.menu-item.has-submenu.active .submenu-toggle {
    transform: rotate(180deg);
}

.submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    margin-top: 0.5rem;
    margin-left: 2rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-sm);
    border-left: 2px solid var(--primary-400);
    max-height: 0;
    overflow: hidden;
    transition: all var(--transition-normal);
    opacity: 0;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(59, 130, 246, 0.1);
}

.menu-item.has-submenu.active .submenu {
    max-height: 500px;
    opacity: 1;
    padding: 0.5rem 0;
}

.submenu .menu-item {
    margin: 0;
}

.submenu .menu-item a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    transition: all var(--transition-normal);
    border-radius: var(--border-radius-sm);
    margin: 0.125rem 0.5rem;
    position: relative;
    overflow: hidden;
    font-size: 0.875rem;
    font-weight: 500;
}

.submenu .menu-item a::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.1), transparent);
    transition: left var(--transition-slow);
}

.submenu .menu-item a:hover {
    background: linear-gradient(135deg, var(--primary-50) 0%, rgba(59, 130, 246, 0.05) 100%);
    color: var(--primary-700);
    transform: translateX(4px);
    box-shadow: var(--shadow-sm);
}

.submenu .menu-item a:hover::before {
    left: 100%;
}

.submenu .menu-item a:hover i {
    transform: scale(1.1);
    color: var(--primary-600);
}

.submenu .menu-item a i {
    font-size: 0.875rem;
    width: 16px;
    text-align: center;
    transition: all var(--transition-normal);
    color: var(--primary-500);
}

/* Animación de entrada para submenu */
.submenu .menu-item {
    animation: submenuSlideIn 0.3s ease-out;
    animation-fill-mode: both;
}

.submenu .menu-item:nth-child(1) { animation-delay: 0.05s; }
.submenu .menu-item:nth-child(2) { animation-delay: 0.1s; }
.submenu .menu-item:nth-child(3) { animation-delay: 0.15s; }
.submenu .menu-item:nth-child(4) { animation-delay: 0.2s; }
.submenu .menu-item:nth-child(5) { animation-delay: 0.25s; }
.submenu .menu-item:nth-child(6) { animation-delay: 0.3s; }
.submenu .menu-item:nth-child(7) { animation-delay: 0.35s; }
.submenu .menu-item:nth-child(8) { animation-delay: 0.4s; }
.submenu .menu-item:nth-child(9) { animation-delay: 0.45s; }

@keyframes submenuSlideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.sidebar.collapsed .menu-item a span {
    display: none;
}

.sidebar.collapsed .menu-item a {
    justify-content: center;
    padding: 0.75rem;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.sidebar.collapsed + .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

/* Top Bar */
/* Topbar mejorado con efectos profesionales */
.topbar {
    height: var(--topbar-height);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(248, 250, 252, 0.9) 100%);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-normal);
}

.topbar::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.2), transparent);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--border-radius);
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Barra de búsqueda moderna con glassmorphism */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-box i {
    position: absolute;
    left: 1rem;
    color: var(--text-secondary);
    z-index: 2;
    transition: all var(--transition-normal);
    font-size: 1.1rem;
}

.search-box input {
    padding: 0.75rem 1rem 0.75rem 3rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--border-radius-lg);
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    width: 320px;
    transition: all var(--transition-normal);
    font-size: 0.95rem;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    position: relative;
}

.search-box input::placeholder {
    color: var(--text-secondary);
    opacity: 0.8;
    transition: opacity var(--transition-fast);
}

.search-box input:focus {
    outline: none;
    border-color: rgba(59, 130, 246, 0.3);
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1), var(--shadow-lg);
    transform: translateY(-1px);
}

.search-box input:focus + i {
    color: var(--primary-600);
    transform: scale(1.1);
}

.search-box input:focus::placeholder {
    opacity: 0.6;
}

/* Efecto de onda en el icono */
.search-box::after {
    content: '';
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: 2px solid var(--primary-500);
    border-radius: 50%;
    opacity: 0;
    animation: searchPulse 2s infinite;
    z-index: 1;
}

.search-box input:focus ~ .search-box::after {
    animation: searchPulse 1s infinite;
}

@keyframes searchPulse {
    0% {
        transform: translateY(-50%) scale(0.8);
        opacity: 0.7;
    }
    50% {
        transform: translateY(-50%) scale(1.2);
        opacity: 0.3;
    }
    100% {
        transform: translateY(-50%) scale(1.5);
        opacity: 0;
    }
}

/* Global Search Dropdown */
/* Global Search Dropdown - Glassmorphism */
.global-search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-xl);
    z-index: 1000;
    max-height: 400px;
    overflow-y: auto;
    margin-top: 4px;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.search-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--background-color);
}

.search-results-count {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.btn-close-search {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.btn-close-search:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.search-category {
    border-bottom: 1px solid var(--border-color);
}

.search-category:last-child {
    border-bottom: none;
}

.search-category-title {
    padding: 12px 16px 8px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--background-color);
    margin: 0;
}

.search-items {
    padding: 0 8px 8px;
}

.search-item {
    padding: 12px 8px;
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.search-item-main {
    cursor: pointer;
}

.search-item:hover {
    background: var(--background-color);
    border-color: var(--border-color);
}

.search-item-title {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
    font-size: 0.875rem;
}

.search-item-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    line-height: 1.4;
}

.search-item-badges {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.search-no-results {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-secondary);
}

.search-no-results i {
    font-size: 2rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.search-no-results p {
    margin: 0;
    font-size: 0.875rem;
}

/* Actividades del cliente en búsqueda */
.search-item-activities {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

.activity-group {
    margin-bottom: 6px;
}

.activity-group:last-child {
    margin-bottom: 0;
}

.activity-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 2px;
}

.activity-items {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.activity-item {
    font-size: 0.7rem;
    color: var(--text-secondary);
    background: var(--background-color);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    display: inline-block;
    margin-right: 4px;
    margin-bottom: 2px;
}

/* User menu mejorado con avatar profesional */
.user-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-lg);
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.user-menu:hover {
    background: linear-gradient(135deg, var(--primary-50) 0%, rgba(59, 130, 246, 0.1) 100%);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.user-menu::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, transparent 100%);
    border-radius: var(--border-radius-lg);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.user-menu:hover::before {
    opacity: 1;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: var(--gradient-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-normal);
    position: relative;
    z-index: 2;
}

.user-menu:hover .user-avatar {
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

.user-avatar::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, rgba(255,255,255,0.3), transparent);
    border-radius: 50%;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.user-menu:hover .user-avatar::before {
    opacity: 1;
}

/* ===========================================
   SKELETON LOADERS Y ESTADOS DE CARGA MODERNOS
   =========================================== */

/* Skeleton base */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--border-radius);
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Skeleton para cards */
.skeleton-card {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    margin-bottom: 1rem;
    position: relative;
    overflow: hidden;
}

.skeleton-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    animation: skeleton-shine 2s infinite;
}

@keyframes skeleton-shine {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

.skeleton-icon {
    width: 64px;
    height: 64px;
    border-radius: var(--border-radius-lg);
    margin-bottom: 1rem;
}

.skeleton-title {
    height: 2rem;
    width: 60%;
    margin-bottom: 0.5rem;
}

.skeleton-subtitle {
    height: 1rem;
    width: 40%;
    margin-bottom: 1rem;
}

.skeleton-text {
    height: 0.875rem;
    width: 100%;
    margin-bottom: 0.5rem;
}

.skeleton-text:last-child {
    width: 70%;
}

/* Skeleton para tablas */
.skeleton-table {
    width: 100%;
    border-collapse: collapse;
}

.skeleton-table th,
.skeleton-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.skeleton-table th {
    height: 1.5rem;
    width: 20%;
}

.skeleton-table td {
    height: 1rem;
    width: 15%;
}

.skeleton-table td:nth-child(1) {
    width: 30%;
}

/* Skeleton para listas */
.skeleton-list-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.skeleton-list-content {
    flex: 1;
}

.skeleton-list-title {
    height: 1.25rem;
    width: 70%;
    margin-bottom: 0.5rem;
}

.skeleton-list-subtitle {
    height: 1rem;
    width: 50%;
}

/* Loading spinner moderno */
.modern-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(59, 130, 246, 0.1);
    border-top: 3px solid var(--primary-600);
    border-radius: 50%;
    animation: modern-spin 1s linear infinite;
    position: relative;
}

.modern-spinner::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    border: 3px solid transparent;
    border-top: 3px solid var(--primary-300);
    border-radius: 50%;
    animation: modern-spin 1.5s linear infinite reverse;
}

@keyframes modern-spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* Loading overlay mejorado */
.loading-overlay-modern {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: all var(--transition-normal);
}

.loading-overlay-modern.fade-out {
    opacity: 0;
    transform: scale(0.95);
}

.loading-content {
    text-align: center;
    padding: 2rem;
    background: var(--surface-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-xl);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.loading-text {
    margin-top: 1rem;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 1.1rem;
}

.loading-subtext {
    margin-top: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Pulsing dots para loading */
.loading-dots {
    display: inline-flex;
    gap: 0.25rem;
    margin-top: 1rem;
}

.loading-dot {
    width: 8px;
    height: 8px;
    background: var(--primary-600);
    border-radius: 50%;
    animation: loading-dot-pulse 1.4s infinite ease-in-out;
}

.loading-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes loading-dot-pulse {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Estados de carga específicos */
.dashboard-loading {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    padding: 2rem;
}

.table-loading {
    background: var(--surface-color);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table-loading-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--background-color);
}

.table-loading-body {
    padding: 1rem;
}

/* Animación de entrada para skeleton */
.skeleton-enter {
    animation: skeleton-enter 0.5s ease-out;
}

@keyframes skeleton-enter {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* Page Content */
.page-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    overflow-x: hidden; /* evita scroll lateral del layout */
}

.page {
    max-width: 100%; /* usar todo el ancho disponible */
    margin: 0 auto;
}

/* Page Header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
}

.page-header h2 {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Buttons - Rediseño moderno */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition-normal);
    font-size: 0.875rem;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.btn:hover::before {
    left: 100%;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    border: 1px solid var(--primary-600);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
}

/* =============================================================================
   COMPONENTES DE UI REUTILIZABLES
   ============================================================================= */

/* Modales */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

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

.modal-content {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    margin: 0;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.modal-close:hover {
    background-color: var(--background-color);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 20px;
    border-top: 1px solid var(--border-color);
    background-color: var(--background-color);
}

/* Notificaciones */
.notifications-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1001;
    max-width: 400px;
}

.notification {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    padding: 15px 20px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid;
    opacity: 1;
    transform: translateX(100%);
    transition: all 0.3s ease;
    animation: slideIn 0.3s ease forwards;
}

@keyframes slideIn {
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.notification.fade-out {
    transform: translateX(100%);
    opacity: 0;
}

.notification-success {
    border-left-color: var(--success-color);
}

.notification-error {
    border-left-color: var(--error-color);
}

.notification-warning {
    border-left-color: var(--warning-color);
}

.notification-info {
    border-left-color: var(--primary-color);
}

.notification button {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    margin-left: 10px;
}

.notification button:hover {
    color: var(--text-primary);
}

/* Indicadores de carga */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1002;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.loading-overlay.fade-out {
    opacity: 0;
}

.loading-spinner {
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-spinner p {
    color: var(--text-secondary);
    margin: 0;
}

/* Estados vacíos */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 16px;
    margin-bottom: 10px;
}

.empty-row {
    text-align: center !important;
    color: var(--text-secondary);
    font-style: italic;
}

/* Tablas de datos */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.data-table th,
.data-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background-color: var(--background-color);
    font-weight: 600;
    color: var(--text-primary);
}

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

/* Paginación */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
    margin-top: 20px;
}

.pagination button {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    background: white;
    color: var(--text-primary);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.pagination button.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.pagination span {
    padding: 8px 12px;
    color: var(--text-secondary);
}

/* Campos de formulario con error */
.form-group .error {
    border-color: var(--error-color) !important;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.1) !important;
}

.form-group .error:focus {
    border-color: var(--error-color) !important;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2) !important;
}

/* Utilidades responsive */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        margin: 20px;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 15px;
    }

    .notifications-container {
        left: 10px;
        right: 10px;
        max-width: none;
    }

    .pagination {
        flex-wrap: wrap;
        gap: 2px;
    }

    .pagination button {
        padding: 6px 10px;
        font-size: 14px;
    }
}

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

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

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

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

/* Stat Cards - Mejoradas con gradientes y animaciones */
.stat-card {
    background: linear-gradient(135deg, var(--surface-color) 0%, rgba(255,255,255,0.8) 100%);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    animation: slideInUp 0.6s ease-out;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gradient-primary);
    transform: scaleX(0);
    transition: transform var(--transition-normal);
}

.stat-card::after {
    content: '';
    position: absolute;
    top: -50%;
    right: -50%;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.1) 0%, transparent 70%);
    opacity: 0;
    transition: opacity var(--transition-slow);
}

.stat-card:hover {
    box-shadow: var(--shadow-xl);
    transform: translateY(-6px) scale(1.02);
    background: linear-gradient(135deg, var(--surface-color) 0%, rgba(255,255,255,0.95) 100%);
}

.stat-card:hover::before {
    transform: scaleX(1);
}

.stat-card:hover::after {
    opacity: 1;
}

.stat-icon {
    width: 64px;
    height: 64px;
    background: var(--gradient-primary);
    border-radius: var(--border-radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.75rem;
    box-shadow: var(--shadow-lg);
    transition: all var(--transition-normal);
    position: relative;
    z-index: 2;
}

.stat-icon::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, rgba(255,255,255,0.2) 0%, transparent 100%);
    border-radius: var(--border-radius-lg);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.stat-card:hover .stat-icon {
    transform: scale(1.15) rotate(8deg);
    box-shadow: var(--shadow-xl);
}

.stat-card:hover .stat-icon::before {
    opacity: 1;
}

.stat-content {
    position: relative;
    z-index: 2;
}

.stat-content h3 {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    transition: all var(--transition-normal);
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--primary-600) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-card:hover .stat-content h3 {
    transform: scale(1.05);
}

.stat-content p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    transition: color var(--transition-normal);
}

.stat-card:hover .stat-content p {
    color: var(--primary-600);
}

/* Animaciones de entrada */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Micro-interacciones avanzadas para la Segunda Fase */
@keyframes float {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-10px);
    }
}

@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 5px rgba(59, 130, 246, 0.2);
    }
    50% {
        box-shadow: 0 0 20px rgba(59, 130, 246, 0.4), 0 0 30px rgba(59, 130, 246, 0.2);
    }
}

@keyframes shimmer {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: calc(200px + 100%) 0;
    }
}

@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

/* Animación de conteo para números */
.stat-number {
    animation: countUp 1.5s ease-out;
}

@keyframes countUp {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.dashboard-card {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 1.5rem 1.5rem 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-content {
    padding: 1.5rem;
}

/* Filters Bar */
.filters-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
}

.search-input {
    position: relative;
    flex: 1;
    max-width: 400px;
}

.search-input i {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.search-input input {
    width: 100%;
    padding: 0.5rem 0.75rem 0.5rem 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--background-color);
}

.filter-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.filter-actions select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--surface-color);
    color: var(--text-primary);
}

/* Table */
.table-container {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    overflow-x: auto; /* si la tabla se desborda, que haga scroll local */
    box-shadow: var(--shadow-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed; /* evita desbordamientos por celdas muy largas */
}

.data-table th {
    background: var(--primary-600);
    color: white;
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--primary-700);
    position: relative;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
    transition: all var(--transition-fast);
}

.data-table th:hover {
    background: var(--primary-700);
    color: white;
}

/* Draggable column affordances */
.data-table th.th-draggable { cursor: move; }
.data-table th.dragging { opacity: 0.6; }
.data-table th.drag-over { outline: 2px dashed var(--primary-color); outline-offset: -4px; }

.data-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    word-break: break-word; /* permite romper palabras largas */
    overflow-wrap: anywhere; /* y cortar strings extensos (emails, URLs, etc.) */
}

/* Compact density mode: more rows visible */
body.compact .page-content {
    padding: 1rem;
}
body.compact .data-table { font-size: 0.85rem; }
body.compact .data-table th { padding: 0.5rem 0.5rem; font-size: 0.85rem; }
body.compact .data-table td { padding: 0.4rem 0.5rem; }
body.compact .data-table .btn,
body.compact .data-table .action-buttons .btn { padding: 0.25rem 0.4rem; font-size: 0.7rem; }
body.compact .pagination button { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
body.compact .page-header { margin-bottom: 1rem; }
body.compact .stats-grid { gap: 1rem; }

/* Ajuste específico para la tabla de Clientes: distribución fija y envoltura de texto */
#clientes .data-table { 
    table-layout: fixed; 
    width: 100%;
}
#clientes .data-table th,
#clientes .data-table td {
    white-space: normal;           /* permitir múltiples líneas para evitar overflow */
    text-overflow: ellipsis;       /* elipsis si no cabe verticalmente */
    overflow: hidden;
}

/* Asignación de anchos por columna (suma ~100%) */
#clientes .data-table th:nth-child(1),
#clientes .data-table td:nth-child(1) { width: 10%; white-space: nowrap; }

#clientes .data-table th:nth-child(2),
#clientes .data-table td:nth-child(2) { width: 34%; font-size: 0.92rem; line-height: 1.35; }

#clientes .data-table th:nth-child(3),
#clientes .data-table td:nth-child(3) { width: 14%; white-space: nowrap; }

#clientes .data-table th:nth-child(4),
#clientes .data-table td:nth-child(4) { width: 26%; font-size: 0.92rem; line-height: 1.35; }

#clientes .data-table th:nth-child(5),
#clientes .data-table td:nth-child(5) { width: 8%; white-space: nowrap; }

#clientes .data-table th:nth-child(6),
#clientes .data-table td:nth-child(6) { width: 8%; white-space: nowrap; }

/* Artículos: Ref, Nombre, Descripción, Precio, Stock, Acciones */
#articulos .data-table { table-layout: fixed; width: 100%; }
#articulos .data-table th,
#articulos .data-table td { white-space: normal; text-overflow: ellipsis; overflow: hidden; }
#articulos .data-table th:nth-child(1),
#articulos .data-table td:nth-child(1) { width: 12%; white-space: nowrap; }
#articulos .data-table th:nth-child(2),
#articulos .data-table td:nth-child(2) { width: 30%; }
#articulos .data-table th:nth-child(3),
#articulos .data-table td:nth-child(3) { width: 34%; }
#articulos .data-table th:nth-child(4),
#articulos .data-table td:nth-child(4) { width: 10%; white-space: nowrap; }
#articulos .data-table th:nth-child(5),
#articulos .data-table td:nth-child(5) { width: 8%; white-space: nowrap; }
#articulos .data-table th:nth-child(6),
#articulos .data-table td:nth-child(6) { width: 6%; white-space: nowrap; }

/* Pedidos: Número, Cliente, Fecha, Estado, Total, Acciones */
#pedidos .data-table { table-layout: auto; width: 100%; }
#pedidos .data-table th,
#pedidos .data-table td { white-space: normal; text-overflow: ellipsis; overflow: hidden; }
#pedidos .data-table th:nth-child(1),
#pedidos .data-table td:nth-child(1) { min-width: 80px; white-space: nowrap; }
#pedidos .data-table th:nth-child(2),
#pedidos .data-table td:nth-child(2) { min-width: 200px; }
#pedidos .data-table th:nth-child(3),
#pedidos .data-table td:nth-child(3) { min-width: 100px; white-space: nowrap; }
#pedidos .data-table th:nth-child(4),
#pedidos .data-table td:nth-child(4) { min-width: 80px; white-space: nowrap; }
#pedidos .data-table th:nth-child(5),
#pedidos .data-table td:nth-child(5) { min-width: 100px; white-space: nowrap; text-align: right; }
#pedidos .data-table th:nth-child(6),
#pedidos .data-table td:nth-child(6) { min-width: 200px; white-space: nowrap; }

/* Estilos específicos para botones de acción en pedidos */
#pedidos .action-buttons {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    justify-content: flex-start;
    align-items: center;
}

#pedidos .action-buttons .btn {
    min-width: 32px;
    height: 28px;
    padding: 4px 6px;
    font-size: 12px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#albaranes .action-buttons {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    justify-content: flex-start;
    align-items: center;
}

#albaranes .action-buttons .btn {
    min-width: 32px;
    height: 28px;
    padding: 4px 6px;
    font-size: 12px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Albaranes: Número, Cliente, Fecha, Serie, Total, Acciones */
#albaranes .data-table { table-layout: fixed; width: 100%; }
#albaranes .data-table th,
#albaranes .data-table td { white-space: normal; text-overflow: ellipsis; overflow: hidden; }
#albaranes .data-table th:nth-child(1),
#albaranes .data-table td:nth-child(1) { width: 10%; white-space: nowrap; }
#albaranes .data-table th:nth-child(2),
#albaranes .data-table td:nth-child(2) { width: 54%; }
#albaranes .data-table th:nth-child(3),
#albaranes .data-table td:nth-child(3) { width: 12%; white-space: nowrap; }
#albaranes .data-table th:nth-child(4),
#albaranes .data-table td:nth-child(4) { width: 6%; white-space: nowrap; }
#albaranes .data-table th:nth-child(5),
#albaranes .data-table td:nth-child(5) { width: 10%; white-space: nowrap; text-align: right; }
#albaranes .data-table th:nth-child(6),
#albaranes .data-table td:nth-child(6) { width: 8%; white-space: nowrap; }
#albaranes .data-table th:nth-child(7),
#albaranes .data-table td:nth-child(7) { width: 20%; white-space: nowrap; }

/* Facturas: Número, Serie, Cliente, Fecha, Estado, Total, Acciones */
#facturas .data-table { 
    table-layout: auto; 
    width: 100%;
    min-width: fit-content;
}
#facturas .data-table th,
#facturas .data-table td { 
    white-space: nowrap;
    padding: 10px 8px;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Número - Anchos iniciales con min-width para resize manual */
#facturas .data-table th:nth-child(1),
#facturas .data-table td:nth-child(1) { 
    min-width: 90px;
    width: 100px;
}
/* Serie */
#facturas .data-table th:nth-child(2),
#facturas .data-table td:nth-child(2) { 
    min-width: 50px;
    width: 60px;
    text-align: center;
}
/* Cliente - Puede hacer wrap en pantallas pequeñas */
#facturas .data-table th:nth-child(3),
#facturas .data-table td:nth-child(3) { 
    min-width: 200px;
    width: auto;
    max-width: 500px;
    white-space: normal;
    line-height: 1.3;
}
/* Fecha */
#facturas .data-table th:nth-child(4),
#facturas .data-table td:nth-child(4) { 
    min-width: 100px;
    width: 110px;
}
/* Estado - Ancho suficiente para "PENDIENTE" completo */
#facturas .data-table th:nth-child(5),
#facturas .data-table td:nth-child(5) { 
    min-width: 110px;
    width: 120px;
}
/* Total */
#facturas .data-table th:nth-child(6),
#facturas .data-table td:nth-child(6) { 
    min-width: 90px;
    width: 100px;
    text-align: right;
}
/* Acciones */
#facturas .data-table th:nth-child(7),
#facturas .data-table td:nth-child(7) { 
    min-width: 100px;
    width: 120px;
    text-align: center;
}

/* Contenedor de tabla con scroll horizontal para pantallas pequeñas */
#facturas .table-container {
    overflow-x: auto;
    width: 100%;
}

/* Hacer las columnas resizable visualmente */
#facturas .data-table th {
    position: relative;
    user-select: none;
}

/* Estilo para el handle de resize (lo añade JavaScript) */
#facturas .resize-handle {
    cursor: col-resize !important;
}
#facturas .resize-handle:hover {
    background: rgba(0, 123, 255, 0.3) !important;
}

/* Estilos para botones de acción en facturas */
#facturas .action-buttons {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
}

#facturas .action-buttons .btn {
    min-width: 32px;
    height: 32px;
    padding: 6px 8px;
    font-size: 13px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.data-table tbody tr {
    transition: all var(--transition-fast);
}

.data-table tbody tr:hover {
    background: var(--primary-50);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

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

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

.pagination button {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    background: var(--surface-color);
    color: var(--text-primary);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
}

.pagination button:hover:not(:disabled) {
    background-color: var(--background-color);
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination button.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Coming Soon */
.coming-soon {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

.coming-soon i {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.coming-soon h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 100000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    max-width: 720px; /* modal base más ancho */
    width: 92%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    z-index: 100001;
}

.modal-content.modal-lg {
    max-width: 1100px; /* modal grande para presupuestos */
    width: 96%;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
}

.modal-close:hover {
    background-color: var(--background-color);
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

/* Loading Overlay */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.9);
    z-index: 3000;
    align-items: center;
    justify-content: center;
}

.loading-overlay.show {
    display: flex;
}

.loading-spinner {
    text-align: center;
    color: var(--primary-color);
}

.loading-spinner i {
    font-size: 2rem;
    margin-bottom: 1rem;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 2rem;
    right: 2rem;
    z-index: 4000;
}

.toast {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-bottom: 0.5rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 300px;
    animation: slideIn 0.3s ease;
}

.toast.success {
    border-left: 4px solid var(--success-color);
}

.toast.error {
    border-left: 4px solid var(--error-color);
}

.toast.warning {
    border-left: 4px solid var(--warning-color);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive Design */
@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.show {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .mobile-menu-toggle {
        display: block;
    }
    
    .topbar {
        padding: 0 1rem;
    }
    
    .page-content {
        padding: 1rem;
    }
    
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .search-input {
        max-width: none;
    }
    
    .filter-actions {
        justify-content: space-between;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .search-box input {
        width: 200px;
    }
    
    .user-name {
        display: none;
    }
}

@media (max-width: 480px) {
    .search-box {
        display: none;
    }
    
    .data-table {
        font-size: 0.875rem;
    }
    
    .data-table th,
    .data-table td {
        padding: 0.75rem 0.5rem;
    }
    
    .modal-content {
        width: 95%;
        margin: 1rem;
    }
    
    .toast-container {
        left: 1rem;
        right: 1rem;
        top: 1rem;
    }
    
    .toast {
        min-width: auto;
    }
}

/* Form Styles */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--surface-color);
    color: var(--text-primary);
    transition: all 0.2s ease;
}

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

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

.form-select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--surface-color);
    color: var(--text-primary);
}

/* Utility Classes */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }

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

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

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

.hidden { display: none; }
.block { display: block; }
.inline-block { display: inline-block; }
.flex { display: flex; }
.grid { display: grid; }

.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }

.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }

/* Status badges for presupuestos */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.status-pending {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #f59e0b;
}

.status-approved {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

.status-delivered {
    background-color: #dbeafe;
    color: #1e40af;
    border: 1px solid #3b82f6;
}

.status-rejected {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #ef4444;
}

.status-cancelled {
    background-color: #f3f4f6;
    color: #374151;
    border: 1px solid #6b7280;
}

/* Linea items for presupuestos */
.linea-item {
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1rem;
    background-color: #f9fafb;
}

.linea-item:last-child {
    margin-bottom: 0;
}

/* Badge styles */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: 0.25rem;
}

.badge-secondary {
    color: #fff;
    background-color: #6c757d;
}

/* Background label helpers (used by VeriFactu and badges) */
.bg-warning { background-color: #fef3c7; color: #92400e; }
.bg-success { background-color: #d1fae5; color: #065f46; }
.bg-danger  { background-color: #fee2e2; color: #991b1b; }
.bg-secondary { background-color: #e5e7eb; color: #374151; }

/* Button outline variants for consistency with usage */
.btn-outline-primary { border: 1px solid var(--primary-color); color: var(--primary-color); background: transparent; }
.btn-outline-primary:hover { background: rgba(37,99,235,.08); }
.btn-outline-secondary { border: 1px solid var(--border-color); color: var(--text-secondary); background: transparent; }
.btn-outline-secondary:hover { background: var(--background-color); color: var(--text-primary); }
.btn-outline-success { border: 1px solid var(--success-color); color: var(--success-color); background: transparent; }
.btn-outline-success:hover { background: rgba(16,185,129,.08); }
.btn-outline-info { border: 1px solid #0ea5e9; color: #0ea5e9; background: transparent; }
.btn-outline-info:hover { background: rgba(14,165,233,.08); }
.btn-outline-whatsapp { border: 1px solid #25d366; color: #1f8f58; background: transparent; }
.btn-outline-whatsapp:hover { background: rgba(37,211,102,.12); color: #0b6844; }

/* Form Grid */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.form-grid .form-group {
    margin-bottom: 0;
}

/* Card Header */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.card-header h3 {
    margin: 0;
    color: var(--text-primary);
}

/* Form Help */
.form-help {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Code styling for references */
code {
    background-color: #f1f5f9;
    color: #1e293b;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875rem;
}

/* Large Modal Styles */
.modal-large .modal-content {
    width: 98vw;
    max-width: 98vw;
    height: 98vh;
    max-height: 98vh;
    margin: 1vh auto;
    display: flex;
    flex-direction: column;
}

.modal-large .modal-body {
    flex: 1;
    /* Permitir que los dropdowns sobresalgan del flujo sin quedar recortados */
    overflow: visible;
    padding: 1.5rem;
}

.modal-large .modal-header {
    flex-shrink: 0;
    padding: 1.5rem 1.5rem 0 1.5rem;
}

.modal-large .modal-footer {
    flex-shrink: 0;
    padding: 0 1.5rem 1.5rem 1.5rem;
    border-top: 1px solid var(--border-color);
    margin-top: 1rem;
    padding-top: 1rem;
}

/* Enhanced form styling for large modals */
.modal-large .form-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.modal-large .linea-item {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.modal-large .linea-item .form-grid {
    grid-template-columns: 4fr 3fr 1fr 1fr 1fr 1fr auto; /* artículo y descripción más anchos */
    gap: 1rem;
    align-items: end;
}

/* Combo input (typeahead) */
.combo {
    position: relative;
}
.combo input.form-input {
    width: 100%;
}
.combo-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-top: none;
    max-height: 320px;
    overflow-y: auto;
    z-index: 6000; /* por encima del modal */
    display: none;
    box-shadow: var(--shadow-md);
    font-size: 0.95rem;
    width: 100%;
    min-width: 520px; /* más legible en pantallas grandes */
}
.combo-suggestions.show {
    display: block;
}
.combo-suggestion {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
}
.combo-suggestion:hover {
    background: var(--background-color);
}

/* Header del presupuesto: más ancho para el select de cliente */
.modal-large .presupuesto-header .form-grid {
    grid-template-columns: 1fr 2fr 1fr;
}

/* Presupuesto Form Styles */
.presupuesto-form {
    max-width: 100%;
}

.presupuesto-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.cliente-search-container {
    position: relative;
}

.presupuesto-lineas {
    margin: 2rem 0;
    overflow-x: auto;
}

.presupuesto-lineas .table-container {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.presupuesto-lineas .data-table {
    margin: 0;
}

.presupuesto-lineas .data-table th {
    background: var(--background-color);
    font-weight: 600;
    padding: 0.75rem;
    border-bottom: 2px solid var(--border-color);
}

.presupuesto-lineas .data-table td {
    padding: 0.5rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
}

.presupuesto-lineas .data-table tr:last-child td {
    border-bottom: none;
}

.presupuesto-lineas .form-input {
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.5rem;
    font-size: 0.9rem;
}

.presupuesto-lineas .form-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.presupuesto-totales {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    border: 2px solid var(--primary-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
}

.presupuesto-totales h4 {
    color: var(--primary-color);
    font-weight: 600;
}

.presupuesto-totales .form-input {
    background: var(--surface-color);
    border: 2px solid var(--border-color);
    font-weight: 500;
}

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

/* Combo styles for presupuesto */
.presupuesto-lineas .combo {
    position: relative;
    z-index: 10;
}

.presupuesto-lineas .combo-suggestions {
    position: fixed;
    top: auto;
    left: auto;
    right: auto;
    background: var(--surface-color);
    border: 3px solid var(--primary-color);
    border-radius: var(--border-radius);
    max-height: 300px;
    min-width: 400px;
    overflow-y: auto;
    z-index: 999999;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    display: none;
    margin-top: 5px;
}

.presupuesto-lineas .combo-suggestions.show {
    display: block;
}

.presupuesto-lineas .combo-suggestion {
    padding: 1.2rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: all 0.2s ease;
    font-size: 1rem;
    background: var(--surface-color);
}

.presupuesto-lineas .combo-suggestion:last-child {
    border-bottom: none;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
}

.presupuesto-lineas .combo-suggestion:hover {
    background: var(--primary-color);
    color: white;
    transform: translateX(2px);
}

.presupuesto-lineas .combo-suggestion.selected {
    background: var(--primary-color);
    color: white;
}

/* Tabs Styles */
.tabs-container {
    margin-bottom: 1.5rem;
}

.tabs {
    display: flex;
    background: var(--surface-color);
    border-radius: var(--border-radius);
    padding: 0.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.tab-button {
    flex: 1;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    border-radius: calc(var(--border-radius) - 2px);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.tab-button:hover {
    background: var(--background-color);
    color: var(--text-primary);
}

.tab-button.active {
    background: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-sm);
}

.tab-button.active:hover {
    background: var(--primary-dark);
}

.tab-content {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Button Group Styles */
.btn-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.btn-group .btn {
    white-space: nowrap;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .modal-large .modal-content {
        width: 98vw;
        height: 98vh;
        margin: 1vh auto;
    }
    
    .modal-large .linea-item .form-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .presupuesto-lineas .data-table {
        font-size: 0.8rem;
    }
    
    .presupuesto-lineas .data-table th,
    .presupuesto-lineas .data-table td {
        padding: 0.25rem;
    }
    
    .presupuesto-totales .form-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .tabs {
        flex-direction: column;
    }
    
    .tab-button {
        justify-content: flex-start;
    }
    
    .btn-group {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .btn-group .btn {
        width: 100%;
        justify-content: center;
    }
}

/* ===== COLUMN RESIZE HANDLES ===== */
.resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    background: transparent;
    cursor: col-resize;
    z-index: 10;
    transition: background-color 0.2s ease;
}

.resize-handle:hover {
    background: var(--primary-color) !important;
}

.resize-handle:active {
    background: var(--primary-dark) !important;
}

/* Table header styling for resize */
.data-table th {
    position: relative;
    user-select: none;
}

.data-table th:not(:last-child) {
    border-right: 1px solid var(--border-color);
}

/* Dragging state */
.data-table th.dragging {
    opacity: 0.7;
    background-color: var(--background-color);
}

.data-table th.drag-over {
    border-left: 2px solid var(--primary-color);
}

/* Column reorder visual feedback */
.th-draggable {
    cursor: move;
}

.th-draggable:hover {
    background-color: var(--background-color);
}

/* Sort indicators */
.data-table th[data-sort-key] {
    position: relative;
    padding-right: 20px;
}

.data-table th[data-sort-key]:after {
    content: '↕';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: var(--text-secondary);
    opacity: 0.5;
}

.data-table th[data-sort-key].sort-asc:after {
    content: '↑';
    opacity: 1;
    color: var(--primary-color);
}

.data-table th[data-sort-key].sort-desc:after {
    content: '↓';
    opacity: 1;
    color: var(--primary-color);
}

/* =============================================================================
   ESTILOS DEL ASISTENTE DE PRESUPUESTOS
   ============================================================================= */

/* Modal del asistente */
#budgetAssistantModal .modal-content {
    max-width: 900px;
    width: 95%;
}

.assistant-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.assistant-instructions {
    background: var(--background-color);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.assistant-instructions h3 {
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.assistant-instructions ul {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.assistant-instructions li {
    margin-bottom: 0.5rem;
}

.examples {
    margin-top: 1rem;
}

.examples h4 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.example-item {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.assistant-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.assistant-form .form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.assistant-form label {
    font-weight: 600;
    color: var(--text-primary);
}

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

.assistant-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

.assistant-loading {
    text-align: center;
    padding: 2rem;
    background: var(--background-color);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.assistant-preview {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-top: 1rem;
}

.budget-preview {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.budget-header {
    background: var(--background-color);
    padding: 1rem;
    border-radius: var(--border-radius);
    border-left: 4px solid var(--primary-color);
}

.budget-header h4 {
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.budget-header p {
    margin: 0.25rem 0;
    color: var(--text-secondary);
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

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

.preview-table th {
    background: var(--background-color);
    font-weight: 600;
    color: var(--text-primary);
}

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

.budget-totals {
    background: var(--background-color);
    padding: 1rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.total-line {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    padding: 0.25rem 0;
}

.total-line:last-child {
    margin-bottom: 0;
}

.total-final {
    border-top: 2px solid var(--primary-color);
    padding-top: 0.75rem;
    margin-top: 0.5rem;
    font-size: 1.1rem;
}

.budget-confidence {
    background: var(--warning-color);
    color: white;
    padding: 0.75rem;
    border-radius: var(--border-radius);
    text-align: center;
}

.budget-suggestions {
    background: var(--background-color);
    padding: 1rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.budget-suggestions h5 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.budget-suggestions ul {
    margin: 0;
    padding-left: 1.5rem;
}

.budget-suggestions li {
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
}

.budget-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1rem;
}

/* Botón del asistente en el formulario */
#budgetAssistantBtn {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    border: none;
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

#budgetAssistantBtn:hover {
    background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

#budgetAssistantBtn:active {
    transform: translateY(0);
}

/* Responsive design para el asistente */
@media (max-width: 768px) {
    #budgetAssistantModal .modal-content {
        width: 98%;
        margin: 1rem;
    }
    
    .assistant-actions {
        flex-direction: column;
    }
    
    .budget-actions {
        flex-direction: column;
    }
    
    .preview-table {
        font-size: 0.9rem;
    }
    
    .preview-table th,
    .preview-table td {
        padding: 0.5rem;
    }
}

/* ===== TRELLO MODAL STYLES ===== */
.trello-status {
    margin-bottom: 1rem;
}

.trello-status .alert {
    margin-bottom: 0;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.form-actions .btn {
    flex: 1;
}

#trelloBoardSelect,
#trelloListSelect {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-primary);
    color: var(--text-primary);
}

#trelloBoardSelect:focus,
#trelloListSelect:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

#trelloBoardSelect:disabled,
#trelloListSelect:disabled {
    background: var(--bg-secondary);
    color: var(--text-muted);
    cursor: not-allowed;
}

.trello-card-info {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-top: 1rem;
}

.trello-card-info h4 {
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
}

.trello-card-info p {
    margin: 0.25rem 0;
    color: var(--text-secondary);
}

.trello-card-info a {
    color: var(--primary-color);
    text-decoration: none;
}

.trello-card-info a:hover {
    text-decoration: underline;
}

/* Botón de Trello en la tabla */
.btn-info {
    background-color: #0079bf;
    border-color: #0079bf;
    color: white;
}

.btn-info:hover {
    background-color: #005a8b;
    border-color: #005a8b;
    color: white;
}

.btn-info:focus {
    box-shadow: 0 0 0 2px rgba(0, 121, 191, 0.25);
}

/* Responsive para el modal de Trello */
@media (max-width: 768px) {
    .form-actions {
        flex-direction: column;
    }
    
    .form-actions .btn {
        flex: none;
    }
}

/* Screen reader only - para accesibilidad */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* User Menu in Topbar */
.user-menu {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#userInfo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#userName {
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.9rem;
}

/* ===== FASE 3: RESPONSIVE DESIGN AVANZADO ===== */

/* Tablet optimizations (768px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 1rem;
    }
    
    .sidebar {
        width: 250px;
    }
    
    .main-content {
        margin-left: 250px;
    }
    
    .topbar {
        padding: 0.75rem 1.5rem;
    }
    
    .search-box {
        width: 250px;
    }
    
    .data-table {
        font-size: 0.9rem;
    }
    
    .data-table th,
    .data-table td {
        padding: 0.6rem 0.5rem;
    }
}

/* Enhanced mobile optimizations (768px and below) */
@media (max-width: 768px) {
    /* Sidebar mobile behavior */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        z-index: 1000;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }
    
    .sidebar.show {
        transform: translateX(0);
    }
    
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
    }
    
    .sidebar-overlay.show {
        display: block;
    }
    
    .main-content {
        margin-left: 0;
        width: 100%;
    }
    
    .mobile-menu-toggle {
        display: block;
        position: fixed;
        top: 1rem;
        left: 1rem;
        z-index: 1001;
        background: var(--primary-600);
        color: white;
        border: none;
        border-radius: 50%;
        width: 44px;
        height: 44px;
        box-shadow: var(--shadow-md);
        transition: all var(--transition-normal);
    }
    
    .mobile-menu-toggle:hover {
        background: var(--primary-700);
        transform: scale(1.05);
    }
    
    .topbar {
        padding: 0.5rem 1rem;
        margin-left: 0;
    }
    
    .search-box {
        width: 180px;
        font-size: 0.9rem;
    }
    
    .user-menu {
        margin-left: 0.5rem;
    }
    
    /* Dashboard mobile grid */
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    
    .stat-card {
        padding: 1rem;
        margin-bottom: 0.5rem;
    }
    
    .stat-card h3 {
        font-size: 1.4rem;
    }
    
    .stat-card p {
        font-size: 0.85rem;
    }
    
    /* Tables mobile optimization */
    .data-table {
        font-size: 0.8rem;
        table-layout: auto !important;
        width: max-content !important;
        min-width: 100%;
    }
    
    .data-table th,
    .data-table td {
        padding: 0.5rem 0.3rem;
        white-space: nowrap;
        min-width: 80px;
    }
    
    .data-table th:first-child,
    .data-table td:first-child {
        position: sticky;
        left: 0;
        background: var(--primary-600);
        color: white;
        z-index: 10;
        min-width: 120px;
    }
    
    /* Mobile table wrapper - CRITICAL for horizontal scroll */
    .table-responsive {
        position: relative;
        overflow-x: auto !important;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        border-radius: var(--border-radius);
        width: 100%;
        max-width: 100%;
    }
    
    /* Ensure table can scroll horizontally */
    .table-responsive .data-table {
        width: max-content !important;
        min-width: 100% !important;
        table-layout: auto !important;
    }
    
    /* Mobile table scroll indicator */
    .table-responsive::after {
        content: '← Desliza para ver más →';
        position: absolute;
        bottom: -20px;
        left: 50%;
        transform: translateX(-50%);
        font-size: 0.7rem;
        color: var(--text-secondary);
        white-space: nowrap;
        pointer-events: none;
    }
    
    /* Override specific table layouts for mobile */
    #clientes .data-table,
    #articulos .data-table,
    #pedidos .data-table,
    #albaranes .data-table,
    #facturas .data-table {
        table-layout: auto !important;
        width: max-content !important;
        min-width: 100% !important;
    }
    
    /* Reset column widths for mobile */
    #clientes .data-table th,
    #clientes .data-table td,
    #articulos .data-table th,
    #articulos .data-table td,
    #pedidos .data-table th,
    #pedidos .data-table td,
    #albaranes .data-table th,
    #albaranes .data-table td,
    #facturas .data-table th,
    #facturas .data-table td {
        width: auto !important;
        min-width: 80px;
        white-space: nowrap;
    }
    
    /* Test table with fixed content for mobile scroll testing */
    .data-table.test-table {
        width: 800px !important;
        min-width: 800px !important;
    }
    
    .data-table.test-table th,
    .data-table.test-table td {
        min-width: 100px !important;
        width: 100px !important;
    }
    
    /* Forms mobile optimization */
    .form-group {
        margin-bottom: 1rem;
    }
    
    .form-control {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .btn {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
    
    /* Modal mobile optimization */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: var(--border-radius);
    }
}

/* Small mobile optimizations (480px and below) */
@media (max-width: 480px) {
    .search-box {
        display: none;
    }
    
    .topbar {
        padding: 0.5rem;
    }
    
    .user-menu {
        margin-left: 0;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .stat-card {
        padding: 0.75rem;
    }
    
    .stat-card h3 {
        font-size: 1.25rem;
    }
    
    .data-table {
        font-size: 0.7rem;
    }
    
    .data-table th,
    .data-table td {
        padding: 0.4rem 0.2rem;
    }
    
    .btn {
        padding: 0.6rem 0.8rem;
        font-size: 0.8rem;
    }
    
    .modal-dialog {
        margin: 0.25rem;
        max-width: calc(100% - 0.5rem);
    }
}

/* Large mobile and small tablet (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .data-table {
        font-size: 0.75rem;
    }
    
    .search-box {
        width: 150px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    .menu-item a {
        min-height: 44px;
        padding: 0.75rem 1rem;
    }
    
    .data-table th,
    .data-table td {
        padding: 0.75rem 0.5rem;
    }
}

/* Estilos para campos obligatorios */
.required {
  color: var(--danger-500);
  font-weight: bold;
}

.form-label .required {
  margin-left: 0.25rem;
}

/* Mejoras en formularios */
.form-input:required {
  border-left: 3px solid var(--primary-500);
}

.form-input:required:focus {
  border-left-color: var(--primary-600);
  box-shadow: 0 0 0 3px var(--primary-100);
}

/* ============================================================
   CRM 360 Styles
   ============================================================ */
.crm360-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.5rem 1.5rem 0;
}

.crm360-back {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.crm360-title h2 {
    margin: 0;
    font-size: 1.75rem;
    color: var(--text-primary);
}

.crm360-title-meta {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.crm-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--gray-100);
    color: var(--gray-700);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.crm-badge.status-active {
    background: rgba(34, 197, 94, 0.12);
    color: #15803d;
}

.crm360-header-actions {
    display: flex;
    gap: 0.75rem;
}

.crm360-layout {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr) 340px;
    gap: 1.5rem;
    padding: 1.5rem;
    height: calc(100vh - 180px);
    overflow: hidden;
    min-height: 0;
}

.crm360-panel {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    overflow-y: auto;
    padding-right: 0.5rem;
    min-height: 0;
}

.crm360-main {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    overflow: hidden;
    min-height: 0;
    height: 100%;
    max-height: 100%;
}

.crm360-main-grid {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 1.25rem;
    height: 100%;
    min-height: 0;
}

.crm360-insights {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    min-height: 0;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.crm360-conversation {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.crm-card {
    background: var(--surface-color);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.crm-card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.crm-card-header h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.crm-card-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.crm-card-body {
    padding: 1.25rem;
}

.crm-client-details dl {
    margin: 0;
    display: grid;
    gap: 1rem;
}

.crm-client-details dt {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
}

.crm-client-details dd {
    margin: 0.25rem 0 0;
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 600;
}

.crm-channel-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

.crm-channel-chips .chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    background: rgba(99, 102, 241, 0.12);
    color: #4338ca;
    font-size: 0.75rem;
    font-weight: 600;
}

.crm-channel-chips .chip.whatsapp {
    background: rgba(16, 185, 129, 0.15);
    color: #0f766e;
}

.crm-channel-chips .chip.email {
    background: rgba(59, 130, 246, 0.15);
    color: #1d4ed8;
}

.crm-channel-chips .chip.inactive {
    background: rgba(148, 163, 184, 0.2);
    color: #475569;
}

.crm-card textarea {
    width: 100%;
    border: 1px solid rgba(148, 163, 184, 0.4);
    border-radius: 12px;
    padding: 0.75rem;
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
    min-height: 120px;
}

.crm-card textarea:focus {
    outline: none;
    border-color: var(--primary-400);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.crm-summary-intel {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.08), rgba(59, 130, 246, 0.02));
    border-radius: 16px;
    padding: 1.5rem;
    border: 1px solid rgba(148, 163, 184, 0.2);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    flex: 0 0 auto;
}

.crm-intel-highlight h4 {
    margin: 0 0 0.5rem;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.crm-intel-highlight p {
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
}

.crm-intel-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
}

.crm-intel-card {
    background: rgba(255, 255, 255, 0.7);
    border-radius: 14px;
    padding: 0.9rem 1rem;
    border: 1px solid rgba(148, 163, 184, 0.2);
    backdrop-filter: blur(6px);
}

.crm-intel-card .label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.crm-intel-card strong {
    font-size: 1.05rem;
    color: var(--text-primary);
}

.crm-timeline-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex: 0 0 auto;
}

.crm-timeline-filters {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.crm-segmented {
    display: inline-flex;
    background: rgba(148, 163, 184, 0.12);
    border-radius: 999px;
    padding: 0.25rem;
    gap: 0.25rem;
}

.crm-segmented button {
    border: none;
    background: transparent;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
}

.crm-segmented button.active {
    background: #ffffff;
    color: var(--primary-600);
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.15);
}

.crm-timeline-search {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(148, 163, 184, 0.16);
    padding: 0.5rem 0.75rem;
    border-radius: 999px;
}

.crm-timeline-search input {
    border: none;
    background: transparent;
    width: 200px;
}

.crm-timeline-search input:focus {
    outline: none;
}

.crm-timeline-actions {
    display: flex;
    gap: 0.75rem;
}

.crm-timeline {
    flex: 1 1 auto;
    background: transparent;
    border-radius: 16px;
    border: none;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 400px;
    position: relative;
    max-height: 100%;
}

.crm-timeline-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.95);
    z-index: 10;
    padding: 2rem;
}

.crm-timeline-loading.active {
    display: flex;
}

.crm-timeline-empty {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 2.5rem 1.5rem;
    text-align: center;
    color: var(--text-secondary);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    z-index: 5;
}

.crm-timeline-empty.active {
    display: flex;
}

.crm-timeline-empty i {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    color: var(--primary-400);
}

.crm-chat-scroll {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 1.5rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: linear-gradient(180deg, rgba(248, 250, 252, 0.65) 0%, rgba(241, 245, 249, 0.75) 100%);
    -webkit-overflow-scrolling: touch; /* Smooth scrolling en iOS */
    position: relative;
}

.crm-chat-scroll.hidden {
    display: none;
}

.crm-chat-scroll::-webkit-scrollbar {
    width: 8px;
}

.crm-chat-scroll::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.35);
    border-radius: 999px;
}

.crm-chat-composer {
    flex: 0 0 auto;
    padding: 0.75rem 1.5rem 1.5rem;
    border-top: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(250, 252, 255, 0.92);
    backdrop-filter: blur(6px);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.crm-chat-template {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.crm-chat-template label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.crm-chat-template select {
    flex: 1;
}

#crmWhatsappComposerForm .wa-composer-input-container {
    border-radius: 18px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    padding: 0.65rem 0.75rem;
    background: #ffffff;
}

#crmWhatsappComposerForm textarea {
    max-height: 160px;
}

/* .crm-timeline-loading ya está definido arriba con position: absolute */

.crm-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(59, 130, 246, 0.25);
    border-top-color: var(--primary-500);
    border-radius: 50%;
    animation: crmSpin 1s linear infinite;
}

@keyframes crmSpin {
    to {
        transform: rotate(360deg);
    }
}

.crm-timeline-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-left: auto;
    white-space: nowrap;
}

.crm-thread-card {
    width: 100%;
    box-sizing: border-box;
    background: var(--surface-color);
    border-radius: 18px;
    border: 1px solid rgba(148, 163, 184, 0.3);
    padding: 1rem 1.25rem;
    box-shadow: 0 16px 28px rgba(15, 23, 42, 0.08);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.crm-thread-card.whatsapp {
    border-left: 4px solid rgba(37, 211, 102, 0.85);
}

.crm-thread-card.email {
    border-left: 4px solid rgba(59, 130, 246, 0.85);
}

.crm-thread-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 24px 32px rgba(15, 23, 42, 0.12);
}

.crm-thread-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.crm-thread-channel {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    min-width: 0;
}

.crm-thread-icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    background: rgba(59, 130, 246, 0.12);
    color: var(--primary-600);
    flex-shrink: 0;
}

.crm-thread-icon.whatsapp {
    background: rgba(37, 211, 102, 0.15);
    color: #15803d;
}

.crm-thread-icon.email {
    background: rgba(99, 102, 241, 0.18);
    color: #312e81;
}

.crm-thread-text {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.crm-thread-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.crm-thread-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.crm-thread-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.crm-thread-pill {
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border-radius: 999px;
    padding: 0.2rem 0.7rem;
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-secondary);
    font-weight: 600;
}

.crm-thread-pill.outbound {
    background: rgba(59, 130, 246, 0.18);
    color: #1d4ed8;
}

.crm-thread-pill.inbound {
    background: rgba(34, 197, 94, 0.18);
    color: #15803d;
}

.crm-thread-status {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.crm-thread-status.whatsapp i {
    font-size: 1rem;
}

.crm-thread-status.pending {
    color: #b45309;
}

.crm-thread-status.error {
    color: #b91c1c;
}

.crm-thread-status.read {
    color: #1d4ed8;
}

.crm-thread-time {
    display: flex;
    flex-direction: column;
    text-align: right;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.crm-thread-time small {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.crm-thread-content {
    width: 100%;
    box-sizing: border-box;
    border-radius: 16px;
    border: 1px dashed rgba(148, 163, 184, 0.4);
    padding: 0.75rem 1rem;
    background: rgba(148, 163, 184, 0.08);
}

.crm-thread-content.wa-thread {
    background: var(--wa-chat-bg);
    border: 1px solid rgba(37, 211, 102, 0.15);
}

.crm-thread-content.email-thread {
    background: rgba(59, 130, 246, 0.06);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.crm-thread-content .wa-message-bubble {
    max-width: 100%;
}

.crm-thread-content .wa-message {
    margin-bottom: 6px;
}

.crm-email-body {
    font-size: 0.95rem;
    color: var(--text-primary);
    line-height: 1.5;
}

.crm-thread-empty {
    color: var(--text-secondary);
    font-style: italic;
}

.crm-email-attachments {
    margin-top: 0.75rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.crm-email-attachment {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0.75rem;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.4);
    background: #ffffff;
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.07);
}

.crm-email-attachment-icon i {
    font-size: 1rem;
}

.crm-email-attachment-info {
    display: flex;
    flex-direction: column;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.crm-email-attachment-info strong {
    font-size: 0.85rem;
    color: var(--text-primary);
}

.crm-composer-message {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

.btn-outline.active {
    background: rgba(59, 130, 246, 0.12);
    border-color: rgba(59, 130, 246, 0.3);
    color: var(--primary-600);
}

.crm-attachment-chip {
    border-radius: 12px;
    padding: 0.35rem 0.7rem;
    background: rgba(148, 163, 184, 0.22);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.crm-composer {
    background: var(--surface-color);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(148, 163, 184, 0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.crm-composer-tabs {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
}

.crm-composer-tabs button {
    border: none;
    padding: 0.85rem;
    font-weight: 600;
    background: rgba(148, 163, 184, 0.18);
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
}

.crm-composer-tabs button.active {
    background: #ffffff;
    color: var(--primary-600);
    box-shadow: inset 0 -3px 0 var(--primary-500);
}

.crm-composer-content {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.crm-composer-pane {
    display: none;
    flex-direction: column;
    gap: 1rem;
}

.crm-composer-pane.active {
    display: flex;
}

.crm-composer .form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.crm-composer label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.crm-composer textarea,
.crm-composer input,
.crm-composer select {
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    padding: 0.65rem 0.75rem;
    font-size: 0.95rem;
    background: rgba(248, 250, 252, 0.8);
}

.crm-composer textarea:focus,
.crm-composer input:focus,
.crm-composer select:focus {
    outline: none;
    border-color: var(--primary-400);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.crm-composer .btn-block {
    margin-top: 0.5rem;
}

.crm-quick-actions {
    display: grid;
    gap: 0.75rem;
}

.crm-kpi-list {
    display: grid;
    gap: 0.75rem;
}

.crm-kpi {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(148, 163, 184, 0.12);
    border-radius: 12px;
    padding: 0.75rem;
}

.crm-kpi span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.crm-kpi strong {
    font-size: 1rem;
    color: var(--text-primary);
}

.crm-orders-panel {
    width: 100%;
    flex: 0 0 auto;
    max-height: 300px;
    overflow-y: auto;
}

.crm-order-stats {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.crm-orders-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.crm-empty {
    text-align: center;
    color: var(--text-secondary);
    padding: 1rem 0;
    font-size: 0.9rem;
}

.crm-empty i {
    display: block;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--primary-400);
}

.crm-order-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    background: rgba(248, 250, 252, 0.9);
    cursor: pointer;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.crm-order-item:hover {
    border-color: rgba(59, 130, 246, 0.3);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
    background: #fff;
}

.crm-order-main {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.crm-order-number {
    font-weight: 600;
    color: var(--text-primary);
}

.crm-order-date {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.crm-order-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.crm-order-status {
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.crm-order-status.pending {
    background: rgba(249, 115, 22, 0.18);
    color: #b45309;
}

.crm-order-status.done {
    background: rgba(34, 197, 94, 0.18);
    color: #15803d;
}

.crm-order-submeta {
    font-size: 0.8rem;
    color: var(--text-tertiary);
}

.crm-notes-panel {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.crm-note-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.crm-note-actions select {
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.4);
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
}

.crm-notes-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 320px;
    overflow-y: auto;
}

.crm-notes-empty {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 1rem 0;
}

.crm-tasks-panel {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.crm-tasks-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 340px;
    overflow-y: auto;
}

.crm-task {
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 12px;
    padding: 0.75rem;
    background: rgba(248, 250, 252, 0.95);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.crm-task-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.crm-task-title {
    font-weight: 600;
    color: var(--text-primary);
}

.crm-task-meta {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.crm-task-status {
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.crm-task-status.pendiente {
    background: rgba(249, 115, 22, 0.15);
    color: #b45309;
}

.crm-task-status.en_progreso {
    background: rgba(59, 130, 246, 0.15);
    color: #1d4ed8;
}

.crm-task-status.hecho {
    background: rgba(34, 197, 94, 0.18);
    color: #15803d;
}

.crm-task-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.crm-note {
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 14px;
    padding: 0.75rem;
    background: rgba(248, 250, 252, 0.95);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.crm-note.pinned {
    border-left: 4px solid rgba(59, 130, 246, 0.85);
}

.crm-note.alta {
    border-left: 4px solid rgba(239, 68, 68, 0.9);
    background: rgba(254, 226, 226, 0.6);
}

.crm-note-body {
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.4;
    margin-bottom: 0.5rem;
}

.crm-note-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.crm-note-actions-inline {
    margin-top: 0.5rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.crm-note-action {
    border: none;
    background: transparent;
    color: var(--primary-600);
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
}

.crm-note-action.danger {
    color: #b91c1c;
}

.crm-note-action:hover {
    text-decoration: underline;
}

@media (max-width: 1440px) {
    .crm360-layout {
        grid-template-columns: 280px minmax(0, 1fr) 320px;
    }

    .crm360-main-grid {
        grid-template-columns: 260px minmax(0, 1fr);
    }
}

@media (max-width: 1200px) {
    .crm360-layout {
        grid-template-columns: minmax(0, 1fr);
        grid-auto-rows: min-content;
        height: auto;
        overflow: visible;
    }

    .crm360-panel-left,
    .crm360-panel-right {
        order: 2;
        overflow: visible;
    }

    .crm360-main {
        order: 1;
    }

    .crm360-main-grid {
        grid-template-columns: minmax(0, 1fr);
        height: auto;
    }

    .crm360-insights {
        overflow: visible;
        padding-right: 0;
    }

    .crm360-conversation {
        height: auto;
    }
}

@media (max-width: 768px) {
    .crm360-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .crm360-header-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .crm-timeline-actions {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .crm-timeline-search input {
        width: 140px;
    }

    .crm360-insights {
        gap: 1rem;
    }
}
