/* ============ AI CHAT SIDEBAR - SCOUTIA ============ */

/* CSS variable controlada pelo JS para a largura do painel */
:root {
    --chat-sidebar-width: 380px;
}

/* ---- Tab de abertura (visível quando o chat está fechado) ---- */
.chat-open-tab {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 160px;
    background: var(--bg-secondary, #151528);
    border: 1px solid var(--border-color, #2a2a45);
    border-right: none;
    border-radius: 12px 0 0 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    z-index: 197;
    transition: width 0.15s, background 0.15s, opacity 0.2s;
    opacity: 1;
}

.chat-open-tab:hover {
    width: 48px;
    background: var(--bg-card, #1c1c36);
    border-color: var(--accent-green, #00d46a);
}

.chat-open-tab i {
    font-size: 1rem;
    color: var(--accent-green, #00d46a);
}

.chat-open-tab span {
    writing-mode: vertical-rl;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-secondary, #a0a0b8);
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

/* Quando o painel está aberto, esconde a tab */
body.chat-sidebar-open .chat-open-tab {
    opacity: 0;
    pointer-events: none;
}

/* ---- Painel principal ---- */
.ai-chat {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--chat-sidebar-width);
    height: 100vh;
    z-index: 199;
    font-family: inherit;
    display: flex;
    flex-direction: column;
    border-radius: 0;
    box-shadow: -6px 0 32px rgba(0, 0, 0, 0.35);
    background: var(--bg-card, #1c1c36);
    transform: translateX(100%);
    transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.ai-chat.open {
    transform: translateX(0);
}

/* ---- Conteúdo principal recua quando o painel abre ---- */
body.chat-sidebar-open main {
    margin-right: var(--chat-sidebar-width) !important;
    transition: margin-right 0.26s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Betslip também recua */
body.chat-sidebar-open .betslip {
    right: calc(var(--chat-sidebar-width) + 16px) !important;
}

/* ---- Handle de resize ---- */
.chat-resize-handle {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    cursor: col-resize;
    background: transparent;
    transition: background 0.15s;
    z-index: 10;
    flex-shrink: 0;
}

.chat-resize-handle:hover,
.chat-resize-handle.dragging {
    background: var(--accent-green, #00d46a);
}

/* ---- Header ---- */
.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary, #151528);
    border-bottom: 1px solid var(--border-color, #2a2a45);
    color: #fff;
    padding: 0.85rem 1.15rem;
    user-select: none;
    min-height: 52px;
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.01em;
}

.chat-logo {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent-green, #00d46a) 0%, #00b359 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    color: var(--bg-primary, #0d0d1a);
    flex-shrink: 0;
}

.chat-header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-badge {
    width: 28px;
    height: 28px;
    background: rgba(0, 212, 106, 0.15);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: var(--accent-green, #00d46a);
}

.chat-clear-btn,
.chat-close-btn {
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    color: var(--text-muted, #6b6b80);
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.chat-clear-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.chat-close-btn:hover {
    color: var(--text-primary, #fff);
    background: var(--bg-card, #1c1c36);
}

/* ---- Body ---- */
.ai-chat-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    background: var(--bg-card, #1c1c36);
}

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

/* ---- Welcome ---- */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 2rem 1rem;
}

.welcome-icon {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--accent-green, #00d46a) 0%, #00b359 100%);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--bg-primary, #0d0d1a);
    margin-bottom: 1rem;
}

.chat-welcome h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-primary, #fff);
}

.chat-welcome p {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary, #a0a0b8);
    margin-bottom: 1.5rem;
    max-width: 280px;
}

/* ---- Suggestions ---- */
.chat-suggestions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.chat-suggestion {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary, #151528);
    border: 1px solid var(--border-color, #2a2a45);
    border-radius: 12px;
    color: var(--text-primary, #fff);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    font-family: inherit;
}

.chat-suggestion:hover {
    border-color: var(--accent-green, #00d46a);
    background: rgba(0, 212, 106, 0.08);
}

.chat-suggestion i {
    color: var(--accent-green, #00d46a);
    width: 18px;
    font-size: 0.9rem;
    text-align: center;
    flex-shrink: 0;
}

/* ---- Bolhas de mensagem ---- */
.chat-message {
    display: flex;
    gap: 0.6rem;
    max-width: 90%;
    min-width: 0;
    animation: fadeIn 0.2s ease;
}

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

.chat-message.user      { flex-direction: row-reverse; align-self: flex-end; }
.chat-message.assistant { align-self: flex-start; max-width: 97%; }

.chat-avatar {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.chat-message.user .chat-avatar {
    background: var(--accent-green, #00d46a);
    color: var(--bg-primary, #0f0f1a);
}

.chat-message.assistant .chat-avatar {
    background: var(--bg-secondary, #151528);
    border: 1px solid var(--border-color, #2a2a45);
    color: var(--text-secondary, #a0a0b8);
}

.chat-bubble {
    padding: 0.75rem 1rem;
    border-radius: 16px;
    font-size: 0.88rem;
    line-height: 1.5;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: break-word;
    word-break: break-word;
}

.chat-message.user .chat-bubble {
    background: var(--accent-green, #00d46a);
    color: var(--bg-primary, #0f0f1a);
    border-bottom-right-radius: 6px;
}

.chat-message.assistant .chat-bubble {
    background: var(--bg-secondary, #151528);
    color: var(--text-primary, #fff);
    border-bottom-left-radius: 6px;
}

/* ---- Markdown no assistente ---- */
.chat-bubble h3, .chat-bubble h4 {
    font-size: 0.9rem;
    margin: 0.5rem 0 0.3rem;
    color: var(--accent-green, #00d46a);
}

.chat-bubble ul, .chat-bubble ol {
    margin: 0.3rem 0;
    padding-left: 1.2rem;
}

.chat-bubble li  { margin: 0.15rem 0; }

.chat-bubble strong {
    color: var(--accent-green, #00d46a);
    font-weight: 600;
}

.chat-bubble code {
    background: rgba(255, 255, 255, 0.08);
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-family: 'SF Mono', Monaco, monospace;
}

/* ---- Tabelas Markdown — sempre no formato card (sidebar nunca tem largura p/ tabelas largas) ---- */
.chat-table-wrap {
    margin: 0.4rem 0;
    border-radius: 8px;
    border: 1px solid var(--border-color, #2a2a45);
    overflow: hidden;
}

/* Cabeçalho: oculto — labels ficam nos data-label das células */
.chat-table thead { display: none; }

.chat-table,
.chat-table tbody,
.chat-table tr { display: block; }

.chat-table tbody tr {
    border-bottom: 1px solid var(--border-color, #2a2a45);
    padding: 0.3rem 0;
}

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

.chat-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.chat-table td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.2rem 0.65rem;
    border-bottom: none;
    font-size: 0.82rem;
    color: var(--text-primary, #fff);
    word-break: break-word;
}

/* Label extraído do cabeçalho via data-label */
.chat-table td::before {
    content: attr(data-label);
    color: var(--text-secondary, #a0a0b8);
    font-size: 0.75rem;
    font-weight: 500;
    flex-shrink: 0;
    min-width: 36%;
}

/* ---- Typing indicator ---- */
.chat-typing {
    display: flex;
    gap: 5px;
    padding: 0.5rem 0;
}

.chat-typing span {
    width: 7px;
    height: 7px;
    background: var(--text-muted, #6b6b80);
    border-radius: 50%;
    animation: bounce 1.2s infinite;
}

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

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%           { transform: translateY(-5px); }
}

/* ---- Imagem na bolha do usuário ---- */
.chat-msg-image {
    max-width: 100%;
    max-height: 180px;
    object-fit: contain;
    border-radius: 8px;
    display: block;
    margin-bottom: 0.35rem;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

/* ---- Preview da imagem pendente (acima do input) ---- */
.chat-image-preview {
    position: relative;
    display: inline-flex;
    margin-bottom: 0.6rem;
}

.chat-image-preview img {
    width: 68px;
    height: 68px;
    object-fit: cover;
    border-radius: 10px;
    border: 2px solid var(--accent-green, #00d46a);
    display: block;
}

.chat-image-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ef4444;
    border: none;
    color: #fff;
    font-size: 0.6rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: background 0.15s;
}

.chat-image-remove:hover {
    background: #dc2626;
}

/* ---- Input ---- */
.chat-input-area {
    padding: 0.85rem 1rem;
    background: var(--bg-secondary, #151528);
    border-top: 1px solid var(--border-color, #2a2a45);
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: var(--bg-card, #1c1c36);
    border: 1px solid var(--border-color, #2a2a45);
    border-radius: 14px;
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    transition: border-color 0.15s;
}

.chat-input-wrapper:focus-within {
    border-color: var(--accent-green, #00d46a);
}

#chatInput {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary, #fff);
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    padding: 0.3rem 0;
}

#chatInput::placeholder { color: var(--text-muted, #6b6b80); }
#chatInput:focus { outline: none; }

.chat-attach-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted, #6b6b80);
    cursor: pointer;
    flex-shrink: 0;
    font-size: 0.9rem;
    transition: color 0.15s;
    margin-bottom: 2px;
}
.chat-attach-btn:hover { color: var(--accent-green, #00d46a); }

.chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--accent-green, #00d46a);
    border: none;
    color: var(--bg-primary, #0f0f1a);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
    font-size: 0.85rem;
}

.chat-send-btn:hover:not(:disabled) {
    background: #00b359;
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    background: var(--border-color, #2a2a45);
    color: var(--text-muted, #6b6b80);
    cursor: not-allowed;
}

.chat-send-btn.loading i { animation: spin 0.8s linear infinite; }

@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ---- Scrollbar ---- */
.chat-messages::-webkit-scrollbar       { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color, #2a2a45);
    border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted, #6b6b80);
}

/* ---- Botão flutuante mobile para abrir o chat ---- */
.chat-mobile-fab {
    display: none;
    position: fixed;
    bottom: 64px;
    right: 16px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-green, #00d46a) 0%, #00b359 100%);
    border: none;
    color: var(--bg-primary, #0d0d1a);
    font-size: 1.15rem;
    cursor: pointer;
    z-index: 197;
    box-shadow: 0 4px 16px rgba(0, 212, 106, 0.35);
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, box-shadow 0.15s;
}

.chat-mobile-fab:active {
    transform: scale(0.92);
}

body.chat-sidebar-open .chat-mobile-fab {
    display: none !important;
}

/* ---- Mobile: fullscreen chat ---- */
@media (max-width: 768px) {
    .chat-open-tab { display: none; }

    .chat-mobile-fab {
        display: flex;
    }

    .ai-chat {
        position: fixed;
        top: 0;
        left: 0;
        /* 100vw garante que não ultrapassa a viewport horizontal */
        width: 100vw !important;
        /* dvh lida melhor com barra de endereço mobile; fallback para vh */
        height: 100vh !important;
        height: 100dvh !important;
        max-width: 100vw;
        box-sizing: border-box;
        border-radius: 0;
        border-left: none;
        border-top: none;
        transform: translateX(100%);
        overflow: hidden;
    }

    .ai-chat.open {
        transform: translateX(0);
    }

    /* Impede scroll do fundo sem usar position:fixed (que causa zoom-out em alguns dispositivos) */
    body.chat-sidebar-open {
        overflow: hidden !important;
    }

    body.chat-sidebar-open main {
        margin-right: 0 !important;
    }

    body.chat-sidebar-open .betslip {
        display: none !important;
    }

    .chat-resize-handle { display: none; }

    .ai-chat-body {
        flex: 1;
        height: 0;
        min-height: 0;
        overflow: hidden;
    }

    .chat-messages {
        flex: 1;
        min-height: 0;
    }

    .chat-input-area {
        padding-bottom: env(safe-area-inset-bottom, 8px);
        flex-shrink: 0;
    }

    .chat-input-wrapper {
        max-width: 100%;
        box-sizing: border-box;
    }

    .chat-close-btn {
        width: 32px;
        height: 32px;
    }
}

/* ---- Register Bet Card (exibido após IA sugerir registro) ---- */
.register-bet-card {
    background: var(--bg-secondary, #151528);
    border: 1px solid var(--accent-green, #00d46a);
    border-radius: 10px;
    padding: .9rem 1rem;
    margin-top: .8rem;
    max-width: 320px;
}

.rbc-header {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .82rem;
    font-weight: 700;
    color: var(--accent-green, #00d46a);
    margin-bottom: .65rem;
}

.rbc-badge {
    background: rgba(0, 212, 106, .15);
    color: var(--accent-green, #00d46a);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: .66rem;
    font-weight: 700;
    letter-spacing: .5px;
}

.rbc-sels {
    margin-bottom: .65rem;
}

.rbc-sel {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    padding: .4rem .55rem;
    background: var(--bg-card, #1c1c36);
    border-radius: 6px;
    margin-bottom: .3rem;
}

.rbc-match {
    font-size: .78rem;
    color: var(--text-primary, #f0f0ff);
    font-weight: 600;
}

.rbc-pick {
    font-size: .72rem;
    color: var(--accent-green, #00d46a);
    font-weight: 500;
}

.rbc-stats {
    display: flex;
    gap: .45rem;
    margin-bottom: .75rem;
}

.rbc-stat {
    flex: 1;
    background: var(--bg-card, #1c1c36);
    border-radius: 6px;
    padding: .4rem .3rem;
    text-align: center;
}

.rbc-stat span {
    display: block;
    font-size: .63rem;
    color: var(--text-secondary, #a0a0b8);
    margin-bottom: 2px;
    text-transform: uppercase;
    letter-spacing: .4px;
}

.rbc-stat strong {
    font-size: .8rem;
    color: var(--text-primary, #f0f0ff);
}

.rbc-actions {
    display: flex;
    gap: .45rem;
}

.rbc-btn {
    flex: 1;
    padding: .5rem;
    border-radius: 7px;
    font-size: .78rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    transition: opacity .15s;
    font-family: inherit;
}

.rbc-btn:hover { opacity: .82; }

.rbc-confirm {
    background: var(--accent-green, #00d46a);
    color: #0a0a16;
}

.rbc-cancel {
    background: rgba(239, 68, 68, .12);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, .28);
}

.rbc-loading {
    text-align: center;
    color: var(--text-secondary, #a0a0b8);
    font-size: .84rem;
    padding: .5rem 0;
}
