/* ============================================================
   DON ALE — COMPONENTES REUTILIZABLES (components.css)
   Cards, KPIs, Tabla Responsiva, Modales, Toasts, Skeletons
   ============================================================ */

/* --- GLASS CARD --- */
.glass-card {
    background: var(--bg-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    box-shadow: var(--shadow-card);
    transition: border-color 0.25s ease, box-shadow 0.25s ease, background-color 0.3s ease;
}

.glass-card:hover {
    border-color: var(--border-medium);
}

/* --- BOTONES --- */
.btn-primary {
    background: var(--gradient-brand);
    color: white;
    font-weight: 600;
    font-size: 0.88rem;
    padding: 9px 18px;
    border-radius: var(--radius-md);
    gap: 8px;
    box-shadow: 0 2px 10px var(--accent-orange-glow);
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--accent-orange-glow);
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    font-weight: 500;
    font-size: 0.88rem;
    padding: 9px 16px;
    border-radius: var(--radius-md);
    gap: 8px;
}

.btn-secondary:hover {
    background: var(--bg-active);
    border-color: var(--border-hover);
    color: var(--accent-orange);
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.btn-icon:hover {
    background: var(--bg-active);
    color: var(--text-primary);
    border-color: var(--border-medium);
}

.btn-full {
    width: 100%;
}

.btn-manage-lead {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 13px;
    font-size: 0.81rem;
    font-weight: 600;
    color: #FFFFFF !important;
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: var(--radius-md);
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 6px rgba(4, 120, 87, 0.25);
}

.btn-manage-lead:hover {
    background: linear-gradient(135deg, #047857 0%, #065F46 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(4, 120, 87, 0.4);
    color: #FFFFFF !important;
}

.btn-manage-lead:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

/* --- KPI GRID & CARDS --- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 20px 22px;
}

.kpi-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.kpi-value {
    font-family: var(--font-display);
    font-size: 1.85rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
}

.kpi-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    margin-top: 10px;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
}

.badge-up { background: var(--accent-green-subtle); color: var(--accent-green); }
.badge-hot { background: var(--accent-red-subtle); color: var(--accent-red); }
.badge-stock { background: var(--accent-blue-subtle); color: var(--accent-blue); }
.badge-amber { background: var(--accent-amber-subtle); color: var(--accent-amber); }

.kpi-icon-wrapper {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

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

/* --- MÓDULOS DE AGENTES (SWITCH) --- */
.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
    margin-top: 16px;
}

.module-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-hover);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.module-item.online {
    border-color: rgba(16, 185, 129, 0.25);
}

.module-item.offline {
    border-color: rgba(239, 68, 68, 0.2);
    opacity: 0.7;
}

.dot-pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-green);
    box-shadow: 0 0 8px var(--accent-green);
    flex-shrink: 0;
}

.dot-pulse.offline {
    background: var(--accent-red);
    box-shadow: 0 0 6px var(--accent-red);
}

/* Switch Component (Accesible y Preparado para R3) */
.switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 20px;
    margin-left: auto;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--border-medium);
    transition: .3s;
    border-radius: var(--radius-full);
}

.switch-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .switch-slider {
    background-color: var(--accent-green);
}

input:checked + .switch-slider:before {
    transform: translateX(18px);
}

/* --- TABLA RESPONSIVA (DESKTOP FILAS -> MÓVIL TARJETAS) --- */
.data-table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    background: var(--bg-surface);
}

.modern-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.88rem;
}

.modern-table th {
    padding: 14px 18px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border-subtle);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
}

.modern-table td {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

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

.modern-table tr:hover td {
    background: var(--bg-hover);
}

/* Badges de Temperatura */
.badge-temp {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: var(--radius-full);
    font-size: 0.74rem;
    font-weight: 600;
}

.temp-hot { background: var(--accent-red-subtle); color: var(--accent-red); border: 1px solid rgba(239, 68, 68, 0.3); }
.temp-warm { background: var(--accent-amber-subtle); color: var(--accent-amber); border: 1px solid rgba(245, 158, 11, 0.3); }
.temp-cold { background: var(--accent-blue-subtle); color: var(--accent-blue); border: 1px solid rgba(14, 165, 233, 0.3); }
.temp-won { background: var(--accent-green-subtle); color: var(--accent-green); border: 1px solid rgba(16, 185, 129, 0.3); }

/* Transformación de Tabla en Móvil (<768px) */
@media (max-width: 768px) {
    .modern-table thead {
        display: none;
    }

    .modern-table, .modern-table tbody, .modern-table tr, .modern-table td {
        display: block;
        width: 100%;
    }

    .modern-table tr {
        background: var(--bg-surface);
        border: 1px solid var(--border-subtle);
        border-radius: var(--radius-md);
        margin-bottom: 12px;
        padding: 14px 16px;
    }

    .modern-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border-bottom: 1px solid var(--border-subtle);
    }

    .modern-table td:last-child {
        border-bottom: none;
        margin-top: 10px;
        padding-top: 10px;
        justify-content: flex-end;
    }

    .modern-table td::before {
        content: attr(data-label);
        font-size: 0.72rem;
        font-weight: 600;
        color: var(--text-muted);
        text-transform: uppercase;
    }

    .kpi-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .kpi-card {
        padding: 14px 16px;
    }

    .kpi-value {
        font-size: 1.45rem;
    }
}

/* En teléfonos móviles (incluido 390px iPhone), mantener grid de 2 columnas compacto */
@media (max-width: 480px) {
    .kpi-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .kpi-card {
        padding: 12px 14px;
    }

    .kpi-title {
        font-size: 0.72rem;
    }

    .kpi-value {
        font-size: 1.35rem;
    }

    .kpi-icon-wrapper {
        width: 36px;
        height: 36px;
    }

    .kpi-icon-wrapper i {
        width: 18px;
        height: 18px;
    }
}

/* --- SKELETON LOADER CON SHIMMER --- */
.skeleton-box {
    background: linear-gradient(90deg, 
        var(--bg-hover) 25%, 
        var(--border-subtle) 50%, 
        var(--bg-hover) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
    display: inline-block;
}

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

/* --- EMPTY & ERROR STATES --- */
.empty-state, .error-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 24px;
    color: var(--text-muted);
}

.empty-state i, .error-card i {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    opacity: 0.6;
}

.empty-title, .error-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.empty-desc, .error-desc {
    font-size: 0.88rem;
    max-width: 400px;
    margin-bottom: 20px;
}

/* --- TOAST NOTIFICATIONS --- */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    background: var(--bg-surface-solid);
    color: var(--text-primary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    padding: 12px 18px;
    box-shadow: var(--shadow-modal);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.88rem;
    font-weight: 500;
    animation: toastSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 380px;
}

.toast.toast-success { border-left: 4px solid var(--accent-green); }
.toast.toast-error { border-left: 4px solid var(--accent-red); }
.toast.toast-info { border-left: 4px solid var(--accent-blue); }

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

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

/* --- MODAL DIALOG --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-container {
    background: var(--bg-surface-solid);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-modal);
    transform: scale(0.96);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

.modal-title {
    font-size: 1.15rem;
    font-weight: 700;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

/* --- ESTADO DEL SISTEMA (CARDS KPI) --- */
.system-status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-top: 14px;
}

.system-status-item {
    background: var(--bg-hover);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.status-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.status-val {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* --- MÓDULOS DE AGENTES EXPANDIDOS --- */
.modules-grid-expanded {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
    margin-top: 16px;
}

.module-card-item {
    background: var(--bg-hover);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
    transition: all 0.2s ease;
}

.module-card-item:hover {
    border-color: var(--border-medium);
    background: var(--bg-surface-elevated);
}

.module-card-item.online {
    border-left: 3px solid var(--accent-green);
}

.module-card-item.offline {
    border-left: 3px solid var(--accent-red);
    opacity: 0.78;
}

.module-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.module-card-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.module-card-icon {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--accent-orange);
    flex-shrink: 0;
}

.module-card-name {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.module-card-desc {
    font-size: 0.76rem;
    color: var(--text-muted);
    line-height: 1.4;
    margin-top: 4px;
}

.module-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--border-subtle);
    padding-top: 10px;
}

.module-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.74rem;
    font-weight: 600;
}

/* Switch Interactivo */
.switch-interactive {
    cursor: pointer;
}

.switch-interactive input {
    cursor: pointer;
}

/* Barra de Acciones Masivas */
.bulk-actions-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.bulk-progress {
    font-size: 0.8rem;
    color: var(--accent-orange);
    font-weight: 600;
    display: none;
    align-items: center;
    gap: 6px;
}

.bulk-progress.active {
    display: inline-flex;
}

/* --- CONSOLA DEL SISTEMA (LIVE TERMINAL) --- */
.console-wrapper {
    background: #060913;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    margin-top: 24px;
}

.console-header {
    background: rgba(15, 23, 42, 0.95);
    border-bottom: 1px solid var(--border-subtle);
    padding: 12px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

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

.console-status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.74rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.status-live { background: var(--accent-green-subtle); color: var(--accent-green); }
.status-paused { background: var(--accent-amber-subtle); color: var(--accent-amber); }

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

.console-filter-select {
    background: var(--bg-surface-solid);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    font-size: 0.75rem;
    cursor: pointer;
}

.console-body {
    height: 320px;
    max-height: 320px;
    overflow-y: auto;
    padding: 14px 16px;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.6;
    color: #CBD5E1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}

.console-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}

.console-line {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    word-break: break-word;
    border-radius: var(--radius-xs);
    padding: 2px 6px;
    transition: background 0.15s;
}

.console-line:hover {
    background: rgba(255, 255, 255, 0.04);
}

.log-time {
    color: #64748B;
    flex-shrink: 0;
    user-select: none;
}

.log-tag {
    font-weight: 700;
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: var(--radius-xs);
    flex-shrink: 0;
    text-transform: uppercase;
}

.tag-system { background: rgba(14, 165, 233, 0.15); color: #38BDF8; }
.tag-whatsapp { background: rgba(37, 211, 102, 0.15); color: #4ADE80; }
.tag-crm { background: rgba(249, 115, 22, 0.15); color: #FB923C; }
.tag-analyst { background: rgba(139, 92, 246, 0.15); color: #A78BFA; }
.tag-auth { background: rgba(245, 158, 11, 0.15); color: #FBBF24; }
.tag-social { background: rgba(236, 72, 153, 0.15); color: #F472B6; }

.log-msg {
    flex: 1;
    color: #E2E8F0;
}

.line-info .log-msg { color: #E2E8F0; }
.line-success .log-msg { color: #86EFAC; }
.line-warning .log-msg { color: #FDE047; }
.line-error .log-msg { color: #FCA5A5; font-weight: 600; }

.console-empty {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748B;
    font-size: 0.85rem;
    gap: 8px;
}

