/* ==========================================================================
   CSS VARIABLES & DESIGN SYSTEM (Industrial Steel Theme - INPROMETAL)
   ========================================================================== */
:root {
    --bg-app: #080c14;
    --bg-main: #0e1626;
    --bg-sidebar: #0a0f1b;
    
    /* Glassmorphism Cards */
    --card-bg: rgba(22, 33, 54, 0.45);
    --card-border: rgba(255, 255, 255, 0.05);
    --card-hover-bg: rgba(22, 33, 54, 0.65);
    --card-hover-border: rgba(59, 130, 246, 0.2);
    
    /* Brand Colors & Gradients (Metal/Industrial Theme) */
    --color-primary: #3b82f6;          /* Steel Blue */
    --color-primary-hover: #2563eb;
    --color-danger: #ef4444;
    --color-success: #10b981;
    --color-warning: #f59e0b;
    
    --gradient-primary: linear-gradient(135deg, #3b82f6, #1d4ed8);
    --gradient-accent: linear-gradient(135deg, #06b6d4, #0891b2); /* Cyan Accent */
    --gradient-danger: linear-gradient(135deg, #ef4444, #b91c1c);
    
    /* Text Colors */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #475569;
    
    /* Settings */
    --font-primary: 'Plus Jakarta Sans', sans-serif;
    --font-title: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    --border-radius: 16px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   GLOBAL RESET & BASICS
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-app);
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: 14px;
    line-height: 1.5;
    overflow-x: hidden;
    min-height: 100vh;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}
::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.2);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(59, 130, 246, 0.4);
}

/* ==========================================================================
   LAYOUT STRUCTURE
   ========================================================================== */
.app-container {
    display: flex;
    min-height: 100vh;
    width: 100vw;
}

/* Sidebar Styling */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 40px;
    padding: 0 8px;
}

.logo-icon {
    width: 42px;
    height: 42px;
    background: var(--gradient-primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.logo-icon i {
    width: 22px;
    height: 22px;
}

.logo-title {
    font-family: var(--font-title);
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}

.logo-subtitle {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: -2px;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}

.nav-item {
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    color: var(--text-secondary);
    border-radius: 12px;
    font-family: var(--font-primary);
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    transition: var(--transition);
    position: relative;
    width: 100%;
}

.nav-item i {
    width: 18px;
    height: 18px;
    transition: var(--transition);
}

.nav-item:hover {
    color: var(--text-primary);
    background-color: rgba(59, 130, 246, 0.05);
}

.nav-item:hover i {
    transform: translateX(2px);
}

.nav-item.active {
    color: var(--text-primary);
    background-color: var(--card-bg);
    border: 1px solid rgba(59, 130, 246, 0.15);
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.03);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 25%;
    height: 50%;
    width: 4px;
    background: var(--color-primary);
    border-radius: 0 4px 4px 0;
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-top: 20px;
    border-top: 1px solid var(--card-border);
}

.sync-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-indicator.online {
    background-color: var(--color-success);
    box-shadow: 0 0 8px var(--color-success);
}

.status-indicator.loading {
    background-color: var(--color-warning);
    box-shadow: 0 0 8px var(--color-warning);
    animation: pulse 1.5s infinite;
}

.watermark-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background-color: rgba(0, 0, 0, 0.2);
    padding: 10px;
    border-radius: 10px;
}

.watermark-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
}

.watermark-val {
    font-size: 12px;
    color: var(--text-primary);
    font-weight: 600;
}

/* Main Content Area */
.main-content {
    margin-left: 260px;
    flex-grow: 1;
    min-height: 100vh;
    padding: 32px 40px;
    background-color: var(--bg-main);
    background-image: 
        radial-gradient(at 100% 0%, rgba(59, 130, 246, 0.04) 0px, transparent 50%),
        radial-gradient(at 0% 100%, rgba(6, 182, 212, 0.02) 0px, transparent 50%);
}

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

.header-title {
    font-family: var(--font-title);
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.header-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

/* ==========================================================================
   UI COMPONENTS (Cards, Buttons, Inputs)
   ========================================================================== */
.card {
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.35);
    transition: var(--transition);
}

/* Button styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-family: var(--font-primary);
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: var(--gradient-primary);
    color: #fff;
    border: none;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.btn-primary:hover {
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
    border: 1px solid var(--card-border);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.08);
    border-color: rgba(59, 130, 246, 0.20);
}

.btn-danger {
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--color-danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
    background-color: rgba(239, 68, 68, 0.25);
    border-color: rgba(239, 68, 68, 0.4);
}

.btn-icon-only {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 6px;
}

.btn-icon-only i {
    width: 14px;
    height: 14px;
}

/* Form controls */
.form-select, .form-input {
    background-color: rgba(10, 15, 27, 0.7);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    padding: 10px 14px;
    border-radius: 8px;
    font-family: var(--font-primary);
    font-size: 13px;
    outline: none;
    transition: var(--transition);
    width: 100%;
}

.form-select:focus, .form-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

textarea.form-input {
    resize: vertical;
}

/* ==========================================================================
   TABS & FORMS SYSTEM
   ========================================================================== */
.tab-content.hidden {
    display: none !important;
}

/* Form Card Styles (CRUD Inserción) */
.form-container {
    margin-bottom: 24px;
    border: 1px solid rgba(59, 130, 246, 0.2);
    box-shadow: 0 8px 32px 0 rgba(59, 130, 246, 0.05);
    animation: slideDown 0.3s ease-out;
}

.form-container.hidden {
    display: none !important;
}

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

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

.form-title {
    font-family: var(--font-title);
    font-size: 16px;
    font-weight: 700;
    color: var(--color-primary);
}

.btn-close-form {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-close-form:hover {
    color: var(--text-primary);
}

.operation-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid var(--card-border);
    padding-top: 16px;
}

/* ==========================================================================
   KPIs GRID
   ========================================================================== */
.kpis-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.kpi-card {
    display: flex;
    align-items: center;
    gap: 20px;
}

.kpi-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.kpi-icon.soles {
    background-color: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.15);
}

.kpi-icon.dolares {
    background-color: rgba(6, 182, 212, 0.1);
    color: #06b6d4;
    border: 1px solid rgba(6, 182, 212, 0.15);
}

.kpi-icon.transacciones {
    background-color: rgba(16, 185, 129, 0.1);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.15);
}

.kpi-icon.revisar {
    background-color: rgba(139, 92, 246, 0.1);
    color: #8b5cf6;
    border: 1px solid rgba(139, 92, 246, 0.15);
}

.kpi-data {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.kpi-value {
    font-size: 22px;
    font-family: var(--font-title);
    font-weight: 700;
    letter-spacing: -0.5px;
}

.kpi-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ==========================================================================
   CHARTS GRID
   ========================================================================== */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    margin-bottom: 24px;
}

.chart-card {
    display: flex;
    flex-direction: column;
    min-height: 380px;
}

.chart-header {
    margin-bottom: 20px;
}

.chart-title {
    font-family: var(--font-title);
    font-size: 16px;
    font-weight: 600;
}

.chart-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.chart-container {
    flex-grow: 1;
    position: relative;
    height: 100%;
    width: 100%;
}

/* ==========================================================================
   DATA TABLE & CRUD ACTIONS
   ========================================================================== */
.table-actions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-title {
    font-family: var(--font-title);
    font-size: 18px;
    font-weight: 700;
}

.table-responsive {
    overflow-x: auto;
    width: 100%;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 13px;
}

.data-table th {
    background-color: rgba(10, 15, 27, 0.4);
    color: var(--text-secondary);
    padding: 14px 16px;
    font-weight: 600;
    border-bottom: 1px solid var(--card-border);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
    color: var(--text-primary);
    vertical-align: middle;
}

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

.data-table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.015);
}

/* Badges de Estados en OTs y Facturas */
.state-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Estados de OTs */
.state-badge.ot-activo,
.state-badge.ot-en_proceso {
    background-color: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.2);
}
.state-badge.ot-planificado {
    background-color: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.2);
}
.state-badge.ot-completado,
.state-badge.ot-finalizada {
    background-color: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.2);
}
.state-badge.ot-entregado {
    background-color: rgba(139, 92, 246, 0.15);
    color: #8b5cf6;
    border: 1px solid rgba(139, 92, 246, 0.2);
}
.state-badge.ot-cancelado {
    background-color: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* Estados de Facturas */
.state-badge.inv-pendiente {
    background-color: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.2);
}
.state-badge.inv-cobrado,
.state-badge.inv-pagado {
    background-color: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.2);
}
.state-badge.inv-detraccion_pendiente {
    background-color: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.2);
}
.state-badge.inv-anulado,
.state-badge.inv-anulada {
    background-color: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
}
.state-badge.inv-falta_enviar_a_correo {
    background-color: rgba(139, 92, 246, 0.15);
    color: #8b5cf6;
    border: 1px solid rgba(139, 92, 246, 0.2);
}

.table-actions-cell {
    display: flex;
    gap: 8px;
    align-items: center;
}

.select-table-status {
    background-color: rgba(10, 15, 27, 0.8);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 11px;
    outline: none;
    width: auto;
}

/* ==========================================================================
   MODAL OVERLAY (SYNC CONSOLE)
   ========================================================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: var(--transition);
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-card {
    background-color: var(--bg-sidebar);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius);
    width: 680px;
    max-width: 90%;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.modal-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-title-icon {
    color: var(--color-primary);
}

.modal-title {
    font-family: var(--font-title);
    font-size: 18px;
    font-weight: 600;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.spinner.hidden {
    display: none;
}

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

.modal-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modal-description {
    color: var(--text-secondary);
    font-size: 13px;
}

.console-box {
    background-color: #02050b;
    border: 1px solid rgba(255,255,255,0.03);
    border-radius: 8px;
    height: 300px;
    overflow-y: auto;
    padding: 16px;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.6;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.console-line {
    word-break: break-all;
}

.console-line.system {
    color: var(--color-primary);
    font-weight: 600;
}

.console-line.error {
    color: var(--color-danger);
    font-weight: 600;
}

.console-line.success {
    color: var(--color-success);
    font-weight: 600;
}

.console-line.warn {
    color: var(--color-warning);
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--card-border);
    display: flex;
    justify-content: flex-end;
}

/* ==========================================================================
   ANIMATIONS & RESPONSIVE DESIGN
   ========================================================================== */
@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.6; }
    100% { transform: scale(1); opacity: 1; }
}

@media (max-width: 1024px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        border-right: none;
        border-bottom: 1px solid var(--card-border);
        padding: 16px;
    }
    .logo-section {
        margin-bottom: 20px;
    }
    .nav-menu {
        flex-direction: row;
        gap: 4px;
        margin-bottom: 16px;
        flex-wrap: wrap;
    }
    .nav-item {
        padding: 8px 12px;
        font-size: 12px;
        width: auto;
    }
    .nav-item span {
        display: none;
    }
    .main-content {
        margin-left: 0;
        padding: 20px;
    }
    .main-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }
    .header-actions {
        width: 100%;
    }
    .btn-sync {
        width: 100%;
    }
    .form-grid {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   CHATBOT DE IA (Inprometal AI)
   ========================================================================== */
.ai-chat-bubble {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    box-shadow: 0 8px 32px rgba(139, 92, 246, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    z-index: 999;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-chat-bubble:hover {
    transform: scale(1.1) rotate(15deg);
    box-shadow: 0 12px 40px rgba(139, 92, 246, 0.6), 0 0 20px rgba(59, 130, 246, 0.4);
}

.ai-chat-bubble i {
    width: 26px;
    height: 26px;
}

.ai-chat-window {
    position: fixed;
    bottom: 105px;
    right: 30px;
    width: 380px;
    height: 520px;
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 999;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: bottom right;
}

.ai-chat-window.hidden {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    pointer-events: none;
}

.chat-window-header {
    background: rgba(30, 41, 59, 0.5);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(59, 130, 246, 0.25);
}

.chat-avatar i {
    width: 20px;
    height: 20px;
}

.chat-title {
    font-family: var(--font-title);
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    margin: 0;
}

.chat-status {
    font-size: 11px;
    color: var(--color-success);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-status::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--color-success);
    box-shadow: 0 0 6px var(--color-success);
}

.chat-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: var(--transition);
}

.chat-close:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.chat-close i {
    width: 16px;
    height: 16px;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-msg {
    display: flex;
    max-width: 85%;
}

.chat-msg.bot {
    align-self: flex-start;
}

.chat-msg.user {
    align-self: flex-end;
}

.msg-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 12.5px;
    line-height: 1.5;
    word-break: break-word;
}

.chat-msg.bot .msg-bubble {
    background-color: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-bottom-left-radius: 2px;
}

.chat-msg.user .msg-bubble {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: #fff;
    border-bottom-right-radius: 2px;
}

.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(15, 23, 42, 0.95);
    display: flex;
    gap: 10px;
    align-items: center;
}

.chat-input {
    flex-grow: 1;
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #fff;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 12px;
    outline: none;
    transition: var(--transition);
}

.chat-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.btn-chat-send {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--gradient-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.btn-chat-send:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-chat-send i {
    width: 14px;
    height: 14px;
}

/* Estilos de Markdown en el chat */
.msg-bubble p {
    margin: 0 0 8px 0;
}
.msg-bubble p:last-child {
    margin-bottom: 0;
}
.msg-bubble ul, .msg-bubble ol {
    margin: 0 0 8px 0;
    padding-left: 20px;
}
.msg-bubble li {
    margin-bottom: 4px;
}
.msg-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 11px;
}
.msg-bubble th, .msg-bubble td {
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 6px;
    text-align: left;
}
.msg-bubble th {
    background-color: rgba(255, 255, 255, 0.05);
}

@media (max-width: 480px) {
    .ai-chat-window {
        width: calc(100vw - 40px);
        height: 450px;
        bottom: 95px;
        right: 20px;
        left: 20px;
    }
    .ai-chat-bubble {
        bottom: 20px;
        right: 20px;
    }
}

/* ==========================================================================
   UPDATED CUSTOM STYLES (KANBAN, ROI & SIMULATOR)
   ========================================================================== */
.global-filters-card {
    border-left: 4px solid var(--color-primary);
}

.kanban-column {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    transition: var(--transition);
}

.kanban-column:hover {
    border-color: rgba(59, 130, 246, 0.15) !important;
}

.kanban-card {
    transition: var(--transition);
}

.kanban-card:hover {
    transform: translateY(-2px);
    border-color: var(--card-hover-border) !important;
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.1) !important;
}

.roi-layout .card {
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
}

.simulator {
    border-top: 4px solid var(--color-primary);
}

.simulator-results {
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.3);
}
