/*
 * chat.css - Estilos del Widget de Chat Flotante e Interactivo dinorank-copilot
 */

.chat-widget-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-indigo), var(--accent-blue));
    color: #FFF;
    border: none;
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: transform 0.2s, box-shadow 0.2s;
}

.chat-widget-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 30px rgba(99, 102, 241, 0.6);
}

/* Backdrop Oscuro para el Modo Modal */
.chat-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(11, 14, 20, 0.75);
    backdrop-filter: blur(6px);
    z-index: 9990;
    transition: opacity 0.3s ease;
}

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

.chat-widget-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 420px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 120px);
    background: #11151E;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-widget-panel.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px) scale(0.95);
}

/* Modo Sidebar Derecho (25% de la pantalla) cuando el chat está abierto en modo lateral */
body.chat-sidebar-open .chat-widget-panel:not(.modal-mode) {
    top: 0;
    bottom: 0;
    right: 0;
    left: auto;
    width: 25vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    border-radius: 0;
    border-left: 1px solid var(--border-color);
    border-top: none;
    border-right: none;
    border-bottom: none;
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.6);
    z-index: 1000;
}

body.chat-sidebar-open .chat-widget-panel:not(.modal-mode).hidden {
    transform: translateX(100%);
    opacity: 0;
    pointer-events: none;
}

/* Modo Ventana Modal (Pantalla Grande con Márgenes) */
.chat-widget-panel.modal-mode {
    top: 5vh !important;
    bottom: 5vh !important;
    left: 5vw !important;
    right: 5vw !important;
    width: 90vw !important;
    height: 90vh !important;
    max-width: 1400px !important;
    max-height: none !important;
    margin: 0 auto;
    border-radius: var(--radius-lg) !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.85) !important;
    z-index: 10000 !important;
}

.chat-widget-panel.modal-mode.hidden {
    transform: translate(0, 30px) scale(0.96) !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Header del Chat */
.chat-header {
    background: var(--bg-card);
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-title-group {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

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

.chat-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
}

.chat-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Botones y Acciones del Header del Chat */
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-header-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.3rem;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
}

.chat-header-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
}

.chat-close-btn {
    font-size: 1.3rem;
    line-height: 1;
}

.chat-mode-btn svg {
    display: block;
}

.chat-mode-btn svg.hidden {
    display: none;
}

/* Área de Mensajes */
.chat-messages {
    flex: 1;
    padding: 1.25rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.2s ease-out;
}

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

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

.chat-message.assistant {
    align-self: flex-start;
}

.chat-bubble {
    padding: 0.8rem 1.1rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    line-height: 1.5;
    word-break: break-word;
}

.chat-message.user .chat-bubble {
    background: linear-gradient(135deg, var(--accent-indigo), #4F46E5);
    color: #FFF;
    border-bottom-right-radius: 2px;
}

.chat-message.assistant .chat-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-bottom-left-radius: 2px;
}

/* Notificación de Estado / Tool Calling */
.chat-status-pill {
    align-self: flex-start;
    margin: 0.3rem 0 0.5rem 0;
    background: rgba(14, 165, 233, 0.08);
    border: 1px solid rgba(56, 189, 248, 0.25);
    border-radius: 20px;
    padding: 0.35rem 0.85rem;
    font-size: 0.8rem;
    color: var(--accent-blue);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    animation: statusFadeIn 0.3s ease-out;
}

/* Indicador de Pensando (Spinner, Shimmer y Typing Dots) */
.chat-thinking-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 500;
    padding: 0.2rem 0;
}

.thinking-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(56, 189, 248, 0.2);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: thinkingSpin 0.8s linear infinite;
    display: inline-block;
}

.thinking-text {
    background: linear-gradient(90deg, var(--text-muted) 0%, var(--accent-blue) 50%, var(--text-muted) 100%);
    background-size: 200% auto;
    color: transparent;
    -webkit-background-clip: text;
    background-clip: text;
    animation: thinkingShimmer 2s linear infinite;
}

.typing-dots {
    display: inline-flex;
    gap: 2px;
}

.typing-dots span {
    animation: typingBlink 1.4s infinite ease-in-out both;
    font-weight: bold;
    color: var(--accent-blue);
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

.status-pulse-icon {
    display: inline-block;
    animation: statusIconPulse 1s ease-in-out infinite alternate;
}

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

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

@keyframes typingBlink {
    0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1.25); }
}

@keyframes statusIconPulse {
    0% { transform: scale(1); opacity: 0.7; }
    100% { transform: scale(1.25); opacity: 1; }
}

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

/* Input y Envío */
.chat-input-area {
    padding: 1rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.6rem;
}

.chat-input {
    flex: 1;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.7rem 1rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
}

.chat-input:focus {
    border-color: var(--accent-blue);
}

.chat-send-btn {
    background: var(--accent-blue);
    color: #000;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-send-btn:hover:not(:disabled) {
    background: #0284C7;
    color: #FFF;
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Enlaces a Fichas de Valores en el Chat */
.chat-bubble a.chat-ticker-link {
    color: var(--accent-blue);
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 3px;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    background: rgba(56, 189, 248, 0.12);
    border: 1px solid rgba(56, 189, 248, 0.25);
    transition: all 0.2s ease;
}

.chat-bubble a.chat-ticker-link:hover {
    color: #FFF;
    background: var(--accent-blue);
    text-decoration: none;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.4);
}

/* Estilos para Elementos Markdown en el Chat (Encabezados, Tablas, Separadores) */
.chat-bubble h1.chat-h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent-indigo);
    margin: 0.8rem 0 0.4rem 0;
}

.chat-bubble h2.chat-h2 {
    font-size: 1.12rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0.75rem 0 0.35rem 0;
}

.chat-bubble h3.chat-h3 {
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--accent-blue);
    margin: 0.7rem 0 0.3rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 0.25rem;
}

.chat-bubble hr.chat-hr {
    border: 0;
    height: 1px;
    background: var(--border-color);
    margin: 0.85rem 0;
}

/* Tablas Markdown en el Chat */
.chat-table-wrapper {
    overflow-x: auto;
    margin: 0.8rem 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: #0E121A;
}

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

.chat-table th {
    background: #191E2B;
    color: var(--accent-blue);
    padding: 0.55rem 0.75rem;
    font-weight: 700;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.chat-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

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

.chat-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.015);
}

.chat-table tbody tr:hover {
    background: rgba(56, 189, 248, 0.05);
}
