/**
 * Estilos para Copiloto Express - Asistente de Ayuda Inteligente
 * Express Web - Sistema Administrativo
 */

/* Contenedor del Botón Flotante Disparador */
.copilot-floating-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999;
    display: none; /* Controlado dinámicamente según autenticación y preferencia */
    align-items: center;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    border-radius: 9999px;
    box-shadow: 0 10px 25px -5px rgba(37, 99, 235, 0.4), 0 8px 10px -6px rgba(37, 99, 235, 0.3);
    padding: 3px 6px 3px 4px;
    gap: 2px;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}

.copilot-floating-widget:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 30px -4px rgba(37, 99, 235, 0.5), 0 10px 12px -5px rgba(37, 99, 235, 0.35);
}

.copilot-floating-btn {
    border: none;
    background: transparent;
    color: #ffffff;
    font-size: 0.88rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px 7px 8px;
    border-radius: 9999px;
    cursor: pointer;
    outline: none;
    transition: background 0.15s ease;
}

.copilot-floating-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.copilot-floating-btn:active {
    transform: translateY(1px) scale(0.98);
}

.copilot-floating-close-btn {
    border: none;
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
    flex-shrink: 0;
}

.copilot-floating-close-btn:hover {
    background: rgba(239, 68, 68, 0.85);
    color: #ffffff;
    transform: scale(1.1);
}

.copilot-floating-close-btn svg,
.copilot-floating-close-btn i,
.copilot-nav-restore-btn svg,
.copilot-nav-restore-btn i {
    pointer-events: none !important;
}

.copilot-docked-hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Estilos para el estado Anclado en la Barra Superior */
.copilot-nav-dock-pill {
    display: inline-flex;
    align-items: center;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 9999px;
    padding: 2px 4px 2px 8px;
    transition: all 0.2s ease;
}

.copilot-nav-dock-pill:hover {
    border-color: #93c5fd;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.12);
}

.copilot-nav-open-btn {
    border: none;
    background: transparent;
    color: #1d4ed8;
    font-weight: 700;
    font-size: 0.78rem;
    padding: 0.2rem 0.4rem;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

.copilot-nav-restore-btn {
    border: none;
    background: rgba(37, 99, 235, 0.12);
    color: #2563eb;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-left: 2px;
    transition: all 0.2s ease;
    outline: none;
}

.copilot-nav-restore-btn:hover {
    background: #2563eb !important;
    color: #ffffff !important;
    transform: scale(1.12);
}

.copilot-floating-icon-wrap {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.copilot-floating-pulse {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #10b981;
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 rgba(16, 185, 129, 0.4);
    animation: copilotPulse 2s infinite;
}

@keyframes copilotPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }
    70% {
        box-shadow: 0 0 0 8px rgba(16, 185, 129, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* Panel Deslizante (Drawer) */
.copilot-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 440px;
    max-width: 96vw;
    height: 100vh;
    background: #ffffff;
    box-shadow: -10px 0 35px -5px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    transform: translateX(105%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    border-left: 1px solid var(--border, #e2e8f0);
}

.copilot-drawer.active {
    transform: translateX(0);
}

/* Encabezado del Drawer */
.copilot-header {
    background: linear-gradient(135deg, #1e293b, #0f172a);
    color: #ffffff;
    padding: 1rem 1.15rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.copilot-header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.copilot-avatar {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.copilot-header-title {
    font-size: 1.02rem;
    font-weight: 800;
    margin: 0;
    line-height: 1.2;
    display: flex;
    align-items: center;
    gap: 6px;
}

.copilot-header-subtitle {
    font-size: 0.72rem;
    color: #94a3b8;
    margin-top: 2px;
}

.copilot-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.copilot-btn-icon {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    user-select: none;
}

.copilot-btn-icon svg {
    pointer-events: none;
}

.copilot-btn-icon:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

/* Cuerpo de Mensajes */
.copilot-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    background: var(--bg-surface-secondary, #f8fafc);
}

/* Pantalla de Bienvenida / Sugerencias */
.copilot-welcome-card {
    background: #ffffff;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.copilot-chip-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.65rem;
}

.copilot-chip-btn {
    text-align: left;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1d4ed8;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.copilot-chip-btn:hover {
    background: #dbeafe;
    border-color: #93c5fd;
    transform: translateX(3px);
}

/* Burbujas de Chat */
.copilot-msg-row {
    display: flex;
    gap: 0.5rem;
    animation: fadeInMsg 0.2s ease-out;
}

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

.copilot-msg-user {
    justify-content: flex-end;
}

.copilot-msg-bubble-user {
    background: #2563eb;
    color: #ffffff;
    padding: 0.65rem 0.9rem;
    border-radius: 14px 14px 2px 14px;
    max-width: 84%;
    font-size: 0.84rem;
    line-height: 1.4;
    word-break: break-word;
    box-shadow: 0 2px 5px rgba(37, 99, 235, 0.25);
}

.copilot-msg-bot {
    justify-content: flex-start;
}

.copilot-msg-bubble-bot {
    background: #ffffff;
    color: #1e293b;
    border: 1px solid var(--border, #e2e8f0);
    padding: 0.85rem 1rem;
    border-radius: 14px 14px 14px 2px;
    max-width: 92%;
    font-size: 0.83rem;
    line-height: 1.5;
    word-break: break-word;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

/* Formato Markdown dentro de burbujas del bot */
.copilot-msg-bubble-bot p {
    margin: 0 0 0.5rem 0;
}

.copilot-msg-bubble-bot p:last-child {
    margin-bottom: 0;
}

.copilot-msg-bubble-bot h3, 
.copilot-msg-bubble-bot h4 {
    font-size: 0.88rem;
    font-weight: 800;
    margin: 0.65rem 0 0.35rem 0;
    color: #0f172a;
}

.copilot-msg-bubble-bot ul, 
.copilot-msg-bubble-bot ol {
    margin: 0.3rem 0 0.6rem 1.25rem;
    padding: 0;
}

.copilot-msg-bubble-bot li {
    margin-bottom: 0.25rem;
}

.copilot-msg-bubble-bot code {
    background: #f1f5f9;
    color: #0f172a;
    padding: 1px 4px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.8rem;
}

/* Botones de Navegación Interactiva (Deep Links) */
.copilot-deep-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #e0e7ff;
    color: #3730a3 !important;
    padding: 3px 8px;
    border-radius: 6px;
    font-weight: 700;
    text-decoration: none !important;
    font-size: 0.78rem;
    margin: 3px 2px;
    border: 1px solid #c7d2fe;
    transition: all 0.15s ease;
}

.copilot-deep-link:hover {
    background: #c7d2fe;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(55, 48, 163, 0.15);
}

/* Barra de Acciones del Mensaje (Copiar) */
.copilot-msg-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.4rem;
    padding-top: 0.3rem;
    border-top: 1px solid #f1f5f9;
}

.copilot-btn-copy {
    background: none;
    border: none;
    font-size: 0.7rem;
    color: #64748b;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 4px;
    border-radius: 4px;
}

.copilot-btn-copy:hover {
    color: #2563eb;
    background: #eff6ff;
}

/* Indicador de Escritura / Cursor Streaming */
.copilot-cursor {
    display: inline-block;
    width: 6px;
    height: 14px;
    background: #2563eb;
    margin-left: 2px;
    vertical-align: middle;
    animation: blinkCursor 0.7s infinite;
}

@keyframes blinkCursor {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Footer / Input del Asistente */
.copilot-footer {
    background: #ffffff;
    border-top: 1px solid var(--border, #e2e8f0);
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.copilot-input-box {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    background: #f8fafc;
    border: 1px solid var(--border, #cbd5e1);
    border-radius: 10px;
    padding: 0.4rem 0.5rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.copilot-input-box:focus-within {
    border-color: #2563eb;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.copilot-textarea {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 0.85rem;
    resize: none;
    outline: none;
    max-height: 110px;
    min-height: 24px;
    line-height: 1.4;
    padding: 4px;
    color: var(--text-primary, #0f172a);
}

.copilot-btn-send {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: none;
    background: #2563eb;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.copilot-btn-send:hover {
    background: #1d4ed8;
    transform: scale(1.05);
}

.copilot-btn-send:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    transform: none;
}

.copilot-disclaimer {
    font-size: 0.68rem;
    color: #94a3b8;
    text-align: center;
}

/* Telón / Backdrop opcional para móviles */
.copilot-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
    z-index: 9999;
    display: none;
}

.copilot-backdrop.active {
    display: block;
}

@media (max-width: 640px) {
    .copilot-drawer {
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
    }
    .copilot-floating-widget {
        bottom: 18px;
        right: 16px;
    }
    .copilot-floating-btn {
        padding: 7px 10px 7px 8px;
        font-size: 0.84rem;
    }
}

/* ==========================================================================
   Adaptación Nativa para Shell Móvil (PWA / Mobile Shell Activo)
   ========================================================================== */
body.mobile-shell-active .copilot-floating-widget {
    bottom: calc(var(--mobile-nav-height, 64px) + var(--safe-bottom, 0px) + 12px) !important;
    right: 12px !important;
    z-index: 1045 !important;
    padding: 3px 5px 3px 4px;
    box-shadow: 0 8px 20px -4px rgba(37, 99, 235, 0.45), 0 4px 8px -4px rgba(37, 99, 235, 0.3);
}

/* Si hay una barra flotante de acción en Cobranzas o Estado de Cuenta, elevar el botón para no taparla */
body.mobile-shell-active:has(.mobile-floating-action-bar) .copilot-floating-widget,
body.mobile-shell-active:has(.mobile-statement-floating-bar) .copilot-floating-widget {
    bottom: calc(var(--mobile-nav-height, 64px) + var(--safe-bottom, 0px) + 68px) !important;
}

body.mobile-shell-active .copilot-floating-btn {
    font-size: 0.80rem;
    padding: 5px 8px 5px 6px;
    gap: 6px;
}

body.mobile-shell-active .copilot-floating-icon-wrap {
    width: 24px;
    height: 24px;
}

body.mobile-shell-active .copilot-floating-close-btn {
    width: 22px;
    height: 22px;
}

/* Botón anclado en la barra superior móvil (#mobile-top-bar) */
.mobile-copilot-top-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #ffffff;
    border: none;
    border-radius: 9999px;
    padding: 4px 9px 4px 7px;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.mobile-copilot-top-pill:active {
    transform: scale(0.96);
}

