/* Asistente de IA flotante (AIChatPanel). Global a propósito: el DxPopup pinta su contenido fuera del alcance del CSS aislado del componente. */

.ai-chat-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed, #06b6d4);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(124, 58, 237, 0.5);
    cursor: pointer;
    z-index: 1000;
}

.ai-chat-fab:hover {
    filter: brightness(1.1);
}

.ai-chat-fab-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #ec4899;
    color: #fff;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
}

/* ---- Ventana ---- */

.ai-popup .dxbl-modal-content,
.ai-popup.dxbl-modal-content {
    background: #15122a;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 18px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
    overflow: hidden;
}

.ai-popup .dxbl-modal-header {
    background: radial-gradient(120% 220% at 10% 0%, #241b3d 0%, #15122a 70%);
    border: none;
    padding: 12px 16px;
    cursor: move;
}

.ai-popup .dxbl-modal-header .dxbl-btn-close,
.ai-popup .dxbl-modal-header .dxbl-btn {
    filter: invert(1);
}

.ai-popup .dxbl-modal-body {
    padding: 0;
    background: radial-gradient(120% 140% at 15% 0%, #241b3d 0%, #15122a 45%, #0d0c1a 100%);
    /* Barras de desplazamiento vertical y horizontal cuando la ventana se achica o el contenido no cabe */
    overflow: auto;
}

/* ---- Contenido ---- */

.ai-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px 16px 16px;
    min-width: 560px;
    min-height: 420px;
    height: 100%;
    box-sizing: border-box;
    color: #EDEAF7;
}

.ai-header-title {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1 1 auto;
}

.ai-header-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #7c3aed, #06b6d4);
    color: #fff;
    box-shadow: 0 6px 18px rgba(124, 58, 237, 0.45);
    flex-shrink: 0;
}

.ai-header-heading {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: 0.01em;
    background: linear-gradient(90deg, #fff, #c9c3f5);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.ai-header-subtitle {
    font-size: 12.5px;
    color: #A9A3CC;
    margin-top: 1px;
}

.ai-status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: #B9F5D8;
    background: rgba(16, 185, 129, 0.14);
    border: 1px solid rgba(16, 185, 129, 0.35);
    border-radius: 999px;
    padding: 6px 12px;
    margin-right: 8px;
    white-space: nowrap;
}

.ai-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #34D399;
    animation: ai-pulse 1.8s infinite;
}

@keyframes ai-pulse {
    0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.55); }
    70% { box-shadow: 0 0 0 8px rgba(52, 211, 153, 0); }
    100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

.ai-chat-shell {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.10);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
    overflow: hidden;
    display: flex;
}

/* Mientras se prepara la respuesta: puntitos, lo que está haciendo y cuánto lleva */
.ai-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    min-height: 24px;
}

.ai-progress-text {
    font-size: 13px;
    opacity: 0.9;
}

.ai-progress-meta {
    font-size: 12px;
    opacity: 0.55;
}

/* Barra de voz debajo del chat: botón de micrófono y lo que se va escuchando */
.ai-voice-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
    min-height: 36px;
}

.ai-voice-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid rgba(124, 58, 237, 0.55);
    background: rgba(124, 58, 237, 0.15);
    color: inherit;
    border-radius: 18px;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 13px;
}

.ai-voice-btn:hover {
    background: rgba(124, 58, 237, 0.30);
}

.ai-voice-btn.ai-voice-on {
    background: #DC2626;
    border-color: #DC2626;
    color: #fff;
    animation: ai-voice-pulse 1.2s ease-in-out infinite;
}

@keyframes ai-voice-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.55); }
    50% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
}

.ai-voice-text {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 13px;
    opacity: 0.85;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-chat {
    width: 100%;
    height: 100%;
    background: transparent !important;
    border: none !important;
    --dxbl-ai-chat-bg: transparent;
    color: #EDEAF7;
}

.ai-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 10px;
    padding: 30px 20px;
    color: #EDEAF7;
}

.ai-empty-icon {
    width: 68px;
    height: 68px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.35), rgba(6, 182, 212, 0.35));
    color: #fff;
    margin-bottom: 4px;
}

.ai-empty-title {
    font-size: 19px;
    font-weight: 700;
}

.ai-empty-subtitle {
    font-size: 13.5px;
    color: #A9A3CC;
    max-width: 420px;
}

/* ---- Mensajes ---- */

.ai-msg-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 100%;
}

.ai-msg-row.ai-msg-user {
    flex-direction: row-reverse;
}

.ai-msg-avatar {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
}

.ai-msg-user .ai-msg-avatar {
    background: linear-gradient(135deg, #06b6d4, #0891b2);
}

.ai-msg-assistant .ai-msg-avatar {
    background: linear-gradient(135deg, #7c3aed, #a855f7);
}

.ai-msg-bubble {
    max-width: min(720px, 85%);
    border-radius: 14px;
    padding: 10px 14px;
    font-size: 13.5px;
    line-height: 1.55;
    overflow-x: auto;
}

.ai-msg-user .ai-msg-bubble {
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.28), rgba(8, 145, 178, 0.28));
    border: 1px solid rgba(6, 182, 212, 0.35);
    border-top-right-radius: 4px;
}

.ai-msg-assistant .ai-msg-bubble {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-top-left-radius: 4px;
}

.ai-msg-content > :first-child { margin-top: 0; }
.ai-msg-content > :last-child { margin-bottom: 0; }

.ai-msg-content table {
    border-collapse: collapse;
    font-size: 12.5px;
    margin: 6px 0;
}

.ai-msg-content th,
.ai-msg-content td {
    padding: 4px 10px;
    border: 1px solid rgba(120, 120, 140, 0.45);
    text-align: left;
    white-space: nowrap;
}

.ai-msg-content th {
    background: rgba(124, 58, 237, 0.12);
}

.ai-msg-content pre {
    background: rgba(0, 0, 0, 0.35);
    border-radius: 8px;
    padding: 10px 12px;
    overflow-x: auto;
}

.ai-msg-content code {
    font-size: 12.5px;
}

.ai-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}

.ai-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #C9C3F5;
    animation: ai-typing-bounce 1.1s infinite;
}

.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ai-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ---- Orden pendiente de confirmar ---- */

.ai-order-card {
    flex: 0 0 auto;
    max-height: 45%;
    overflow-y: auto;
    border-radius: 16px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(124, 58, 237, 0.55);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.30);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-order-title {
    font-size: 12px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: rgba(237, 234, 247, 0.65);
}

.ai-order-line {
    font-size: 13.5px;
}

.ai-order-items {
    margin: 2px 0;
    padding-left: 18px;
    font-size: 13px;
}

.ai-order-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.ai-order-btn {
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: transparent;
    color: inherit;
    border-radius: 10px;
    padding: 6px 16px;
    cursor: pointer;
}

.ai-order-btn:hover {
    background: rgba(255, 255, 255, 0.10);
}

.ai-order-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

.ai-order-btn-primary {
    border-color: transparent;
    background: linear-gradient(135deg, #7c3aed, #06b6d4);
    color: #fff;
}

.ai-order-btn-primary:hover {
    filter: brightness(1.1);
    background: linear-gradient(135deg, #7c3aed, #06b6d4);
}

/* Botón opcional para bajar a Excel las tablas de una respuesta */
.ai-export-btn {
    margin-top: 8px;
    border: 1px solid rgba(124, 58, 237, 0.55);
    background: transparent;
    color: inherit;
    border-radius: 8px;
    padding: 3px 12px;
    font-size: 12px;
    cursor: pointer;
}

.ai-export-btn:hover {
    background: rgba(124, 58, 237, 0.15);
}

/* Gráficas dentro de una burbuja de respuesta */
.ai-msg-bubble:has(.ai-chart) {
    width: min(720px, 85%);
}

.ai-chart {
    width: 100%;
    min-width: 360px;
    margin: 6px 0;
    overflow-x: auto;
}

/* Prueba de entrega (POD) dentro de una burbuja de respuesta */
.ai-msg-bubble:has(.ai-pod) {
    width: min(720px, 85%);
}

.ai-pod {
    margin: 6px 0;
}

.ai-pod-title {
    font-weight: 600;
    margin-bottom: 6px;
}

.ai-pod-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
}

.ai-pod-item {
    margin: 0;
    border: 1px solid rgba(120, 120, 140, 0.45);
    border-radius: 8px;
    overflow: hidden;
    cursor: zoom-in;
    background: rgba(0, 0, 0, 0.15);
}

.ai-pod-item:hover {
    border-color: rgba(124, 58, 237, 0.75);
}

.ai-pod-item img {
    display: block;
    width: 100%;
    height: 150px;
    object-fit: cover;
    background: #fff;
}

.ai-pod-item figcaption {
    padding: 4px 8px;
    font-size: 11.5px;
    line-height: 1.35;
}

/* Attachments que no son imagen: ícono del tipo de archivo y link de descarga */
.ai-attach-file {
    cursor: default;
}

.ai-attach-icon {
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.06);
    font-weight: 600;
    font-size: 18px;
}

.ai-attach-icon img {
    width: 64px;
    height: 64px;
    object-fit: contain;
    background: transparent;
}

.ai-attach-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-attach-file a {
    color: inherit;
    text-decoration: underline;
}

.ai-pod-viewer {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.8);
    cursor: zoom-out;
}

.ai-pod-viewer img {
    max-width: 92vw;
    max-height: 82vh;
    object-fit: contain;
    background: #fff;
    border-radius: 6px;
    cursor: default;
}

.ai-pod-viewer-caption {
    color: #fff;
    font-size: 13px;
}

.ai-pod-viewer-caption a {
    color: #fff;
    margin-left: 10px;
    font-size: 16px;
    text-decoration: none;
}

/* El avatar del asistente muestra la palabra "Raptor": se ensancha en vez de recortarla */
.ai-msg-assistant .ai-msg-avatar {
    width: auto;
    min-width: 30px;
    padding: 0 7px;
    font-size: 9.5px;
    letter-spacing: 0.02em;
}
