/**
 * static/css/chat.css
 * 
 * Estilos do widget de chat CosplayBot.
 * Tema: Neon Glass - Segue o design system "Tokyo Neon Nights"
 * 
 * Otimizações de performance:
 * - will-change para aceleração de GPU
 * - contain: paint para isolar repaint
 * - backdrop-filter com valores otimizados
 */

/* ==============================================================================
   VARIÁVEIS DO CHAT - Integradas ao Design System Global
   ============================================================================== */

.chat-widget {
    /* Backgrounds Glass */
    --chat-bg: rgba(11, 7, 16, 0.85);
    --chat-bg-glass: rgba(28, 28, 36, 0.7);
    --chat-border: rgba(255, 255, 255, 0.08);

    /* Header Gradient - Neon Vibrant */
    --chat-header-bg: linear-gradient(135deg, #ff00ff 0%, #9333ea 100%);

    /* Bolhas de Mensagem */
    --chat-user-bg: linear-gradient(135deg, #db2777 0%, #9333ea 100%);
    --chat-bot-bg: rgba(31, 41, 55, 0.7);

    /* Neon Effects */
    --chat-glow-pink: rgba(255, 0, 255, 0.4);
    --chat-glow-purple: rgba(147, 51, 234, 0.3);

    /* Shadows */
    --chat-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    --chat-shadow-neon: 0 0 30px var(--chat-glow-purple);

    /* Sizing */
    --chat-radius: 16px;
}

/* ==============================================================================
   BOTÃO FLUTUANTE
   ============================================================================== */

.chat-toggle-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    /* Reduzido levemente de 64px */
    height: 56px;
    border-radius: 50%;
    padding: 0;
    background: transparent;
    /* Removido gradiente de fundo */
    border: none;
    /* Removido border */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    /* Removido shadow/glow para ficar "só o jpg" */
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 9998;
    overflow: hidden;
    /* Garante que a img não vaze */
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
    /* Sem borda ou shadow no hover também, apenas escala */
}

.chat-toggle-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    pointer-events: none;
}

.chat-toggle-pulse {
    /* Ocultar pulse se queremos só a imagem estática limpa, ou manter sutil? 
     O usuário disse "só o jpg". Vamos remover/ocultar o pulse para ser fiel. */
    display: none;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 0.5;
    }

    50% {
        transform: scale(1.3);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 0;
    }
}

@keyframes icon-pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

/* Tooltip do Botão */
.chat-tooltip {
    position: fixed;
    bottom: 35px;
    /* Centralizado verticalmente com o botão */
    right: 90px;
    background: rgba(11, 7, 16, 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 0, 255, 0.3);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transform: translateX(10px);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
    z-index: 9998;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3), 0 0 10px rgba(255, 0, 255, 0.1);
}

.chat-toggle-btn:hover+.chat-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

/* Oculta tooltip e botão quando chat está aberto */
.chat-widget.is-open .chat-toggle-btn,
.chat-widget.is-open .chat-tooltip {
    transform: scale(0) rotate(90deg);
    opacity: 0;
    pointer-events: none;
}

/* Oculta botão quando chat está aberto */
.chat-widget.is-open .chat-toggle-btn {
    transform: scale(0) rotate(90deg);
    opacity: 0;
    pointer-events: none;
}

/* ==============================================================================
   CONTAINER DO CHAT - Glassmorphism
   ============================================================================== */

.chat-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 100px);
    z-index: 9999;

    /* Glassmorphism Effect */
    background: var(--chat-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius);

    /* Shadows & Glow */
    box-shadow: var(--chat-shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.05);

    /* Performance Optimizations */
    will-change: transform, opacity;
    contain: paint;

    /* Layout */
    display: none;
    flex-direction: column;
    overflow: hidden;

    /* Animation */
    transform-origin: bottom right;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-widget.is-open .chat-container {
    display: flex;
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: var(--chat-shadow-neon), var(--chat-shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==============================================================================
   HEADER - Neon Gradient
   ============================================================================== */

.chat-header {
    background: var(--chat-header-bg);
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

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

.chat-avatar {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 50%;
    box-shadow: 0 0 10px var(--chat-glow-pink);
    overflow: hidden;
    /* Garante corte redondo */
    background: transparent;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-header-text {
    display: flex;
    flex-direction: column;
}

.chat-title {
    font-weight: 700;
    font-size: 1rem;
    color: white;
    letter-spacing: 0.5px;
}

.chat-subtitle {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.chat-action-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: background 0.2s ease, transform 0.2s ease;
}

.chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.chat-action-btn svg {
    width: 16px;
    height: 16px;
}

/* ==============================================================================
   ÁREA DE MENSAGENS - Com Orbs Decorativos
   ============================================================================== */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

/* Orbs Decorativos Internos */
.chat-messages::before,
.chat-messages::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    pointer-events: none;
    z-index: 0;
}

.chat-messages::before {
    top: 10px;
    left: 10px;
    width: 120px;
    height: 120px;
    background: rgba(147, 51, 234, 0.15);
}

.chat-messages::after {
    bottom: 20px;
    right: 10px;
    width: 100px;
    height: 100px;
    background: rgba(219, 39, 119, 0.15);
}

/* Scrollbar customizada */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ==============================================================================
   MENSAGENS - Bolhas Glass e Gradient
   ============================================================================== */

.chat-message {
    display: flex;
    gap: 12px;
    max-width: 90%;
    animation: fadeIn 0.3s ease-out;
    position: relative;
    z-index: 1;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

.chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: transparent;
}

.chat-message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-message-user .chat-message-avatar {
    display: none;
}

.chat-message-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    position: relative;
    backdrop-filter: blur(5px);
}

.chat-message-user .chat-message-content {
    background: var(--chat-user-bg);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    border-top-right-radius: 4px;
    box-shadow: 0 0 15px rgba(236, 72, 153, 0.2);
}

.chat-message-assistant .chat-message-content {
    background: var(--chat-bot-bg);
    border: 1px solid var(--chat-border);
    color: #f3f4f6;
    border-top-left-radius: 4px;
}

.chat-message-content p {
    margin: 0 0 8px 0;
}

.chat-message-content p:last-child {
    margin-bottom: 0;
}

.chat-message-content strong {
    color: #ff00ff;
}

.chat-message-content ul,
.chat-message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.chat-message-content li {
    margin-bottom: 4px;
}

.chat-link {
    color: #ff00ff;
    text-decoration: underline;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

.chat-link:hover {
    color: #ff66cc;
}

/* ==============================================================================
   INDICADOR DE DIGITAÇÃO
   ============================================================================== */

.chat-typing {
    display: flex;
    gap: 12px;
    padding: 0 16px 16px;
    position: relative;
    z-index: 1;
}

.chat-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--chat-bot-bg);
    border: 1px solid var(--chat-border);
    border-radius: 16px;
    border-top-left-radius: 4px;
}

.chat-typing-indicator span {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    animation: typing 1.4s infinite both;
}

.chat-typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* ==============================================================================
   FORMULÁRIO DE INPUT - Gradient Border
   ============================================================================== */

.chat-form {
    padding: 16px;
    background: rgba(17, 24, 39, 0.4);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--chat-border);
    flex-shrink: 0;
}

.chat-input-container {
    position: relative;
    display: flex;
    gap: 8px;
    align-items: center;
    background: #111827;
    border-radius: 12px;
    padding: 4px 8px 4px 16px;
    border: 1px solid var(--chat-border);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Gradient border effect on focus */
.chat-input-container:focus-within {
    border-color: #ff00ff;
    box-shadow: 0 0 0 2px rgba(255, 0, 255, 0.2), 0 0 15px rgba(255, 0, 255, 0.15);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    font-size: 0.9rem;
    padding: 10px 0;
    outline: none;
}

.chat-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: linear-gradient(135deg, #ff00ff, #9333ea);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    box-shadow: 0 0 10px var(--chat-glow-pink);
}

.chat-send-btn:disabled {
    background: #374151;
    cursor: not-allowed;
    box-shadow: none;
    opacity: 0.5;
}

.chat-send-btn:not(:disabled):hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px var(--chat-glow-pink);
}

.chat-send-btn svg {
    width: 16px;
    height: 16px;
}

.chat-input-hint {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.4);
    text-align: right;
    margin-top: 4px;
    padding-right: 4px;
}

/* ==============================================================================
   CARDS DE VÍDEOS RECOMENDADOS
   ============================================================================== */

.chat-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.chat-video-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    text-decoration: none;
    color: #d1d5db;
    transition: background 0.2s ease, border-color 0.2s ease;
    max-width: 100%;
}

.chat-video-card:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 0, 255, 0.5);
}

.chat-video-thumb {
    width: 48px;
    height: 27px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.chat-video-title {
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* ==============================================================================
   RESPONSIVO - Mobile Fullscreen
   ============================================================================== */

@media (max-width: 640px) {
    .chat-container {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .chat-toggle-btn {
        bottom: 80px;
        /* Acima da bottom nav */
    }
}

/* ==============================================================================
   LIGHT MODE - Adaptações para legibilidade
   ============================================================================== */

.light-mode .chat-widget {
    --chat-bg: rgba(255, 255, 255, 0.9);
    --chat-bg-glass: rgba(255, 255, 255, 0.8);
    --chat-border: rgba(0, 0, 0, 0.1);
    --chat-bot-bg: rgba(245, 245, 245, 0.9);
}

.light-mode .chat-container {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.light-mode .chat-widget.is-open .chat-container {
    box-shadow: 0 0 20px rgba(147, 51, 234, 0.15), 0 8px 32px rgba(0, 0, 0, 0.15);
}

.light-mode .chat-message-assistant .chat-message-content {
    color: #1a1a20;
    background: rgba(240, 240, 245, 0.95);
}

.light-mode .chat-input-container {
    background: #f5f5f5;
}

.light-mode .chat-input {
    color: #1a1a20;
}

.light-mode .chat-input::placeholder {
    color: rgba(0, 0, 0, 0.4);
}

.light-mode .chat-input-hint {
    color: rgba(0, 0, 0, 0.5);
}

.light-mode .chat-form {
    background: rgba(255, 255, 255, 0.6);
}

.light-mode .chat-messages::before {
    background: rgba(147, 51, 234, 0.08);
}

.light-mode .chat-messages::after {
    background: rgba(219, 39, 119, 0.08);
}

.light-mode .chat-video-card {
    background: rgba(0, 0, 0, 0.05);
    color: #1a1a20;
}

.light-mode .chat-video-card:hover {
    background: rgba(0, 0, 0, 0.1);
}