/* ════════════════════════════════════════════════════════════════════════════
   Caotize-se Buscador IA — Chat Widget
   Tema: preto e branco com detalhes amarelos
   ════════════════════════════════════════════════════════════════════════════ */

/* ── Variáveis ────────────────────────────────────────────────────────────── */
#czbia-widget {
    --czbia-yellow:      #FFD600;
    --czbia-yellow-dark: #E6C000;
    --czbia-black:       #0a0a0a;
    --czbia-dark:        #141414;
    --czbia-dark-2:      #1e1e1e;
    --czbia-dark-3:      #2a2a2a;
    --czbia-border:      #333333;
    --czbia-white:       #ffffff;
    --czbia-gray:        #aaaaaa;
    --czbia-error:       #3d0000;
    --czbia-shadow:      0 8px 32px rgba(0, 0, 0, 0.7);
    --czbia-radius:      12px;
    --czbia-panel-w:     360px;
    --czbia-panel-h:     500px;
    --czbia-z:           99999;

    position:  fixed;
    bottom:    80px;
    left:      0;
    z-index:   var(--czbia-z);
    font-family: 'Lexend Deca', system-ui, sans-serif;
    font-size: 14px;

    /* Visibilidade controlada por JS (inatividade) */
    transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Estado inativo — esconde deslizando para a esquerda */
#czbia-widget.czbia-inactive {
    opacity:        0;
    transform:      translateX(-20px);
    pointer-events: none;
}

/* Quando o painel estiver aberto, nunca esconde o widget */
#czbia-widget.czbia-open.czbia-inactive {
    opacity:        1;
    transform:      none;
    pointer-events: auto;
}

/* ── Botão "Precisa de ajuda?" ────────────────────────────────────────────── */
#czbia-toggle {
    display:         flex;
    align-items:     center;
    gap:             8px;
    background:      var(--czbia-yellow);
    color:           var(--czbia-black);
    border:          none;
    border-radius:   0 24px 24px 0;  /* tab saindo da borda esquerda */
    padding:         12px 20px 12px 16px;
    font-family:     inherit;
    font-size:       13px;
    font-weight:     700;
    letter-spacing:  0.01em;
    cursor:          pointer;
    box-shadow:      3px 3px 12px rgba(0,0,0,0.4);
    white-space:     nowrap;
    transition:      background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    position:        relative;
}

#czbia-toggle:hover {
    background:  var(--czbia-yellow-dark);
    transform:   translateX(3px);
    box-shadow:  5px 3px 16px rgba(0,0,0,0.5);
}

#czbia-toggle:active {
    transform: translateX(1px);
}

/* Ícones dentro do botão */
.czbia-icon-chat,
.czbia-icon-close {
    display:    flex;
    align-items: center;
    gap:         6px;
    transition: opacity 0.2s ease;
    line-height: 1;
}

.czbia-icon-close {
    position: absolute;
    left:     16px;
    top:      50%;
    transform: translateY(-50%);
    opacity:  0;
    font-size: 13px;
    font-weight: 700;
    pointer-events: none;
}

/* Estado aberto — oculta o botão toggle (fechar só pelo × do header) */
.czbia-open #czbia-toggle {
    opacity:        0;
    pointer-events: none;
    transform:      translateX(-16px);
}

/* ── Painel principal ─────────────────────────────────────────────────────── */
#czbia-panel {
    position:       absolute;
    bottom:         calc(100% + 12px);
    left:           0;
    width:          var(--czbia-panel-w);
    height:         var(--czbia-panel-h);
    background:     var(--czbia-black);
    border:         1px solid var(--czbia-border);
    border-radius:  var(--czbia-radius);
    box-shadow:     var(--czbia-shadow);
    display:        flex;
    flex-direction: column;
    overflow:       hidden;

    transform-origin: bottom left;
    animation:      czbia-pop-in 0.22s ease both;
}

#czbia-panel[hidden] {
    display: none;
}

@keyframes czbia-pop-in {
    from { opacity: 0; transform: scale(0.88) translateY(10px); }
    to   { opacity: 1; transform: scale(1)    translateY(0);    }
}

/* ── Header ───────────────────────────────────────────────────────────────── */
#czbia-header {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    padding:         12px 16px;
    background:      var(--czbia-dark);
    border-bottom:   2px solid var(--czbia-yellow);
    flex-shrink:     0;
}

#czbia-header-title {
    color:       var(--czbia-white);
    font-weight: 700;
    font-size:   14px;
    display:     flex;
    align-items: center;
    gap:         8px;
}

/* Bolinha amarela no header */
#czbia-header-title::before {
    content:       '';
    display:       inline-block;
    width:         8px;
    height:        8px;
    border-radius: 50%;
    background:    var(--czbia-yellow);
    box-shadow:    0 0 6px var(--czbia-yellow);
}

#czbia-close {
    background:   none;
    border:       none;
    color:        var(--czbia-gray);
    cursor:       pointer;
    font-size:    20px;
    line-height:  1;
    padding:      2px 6px;
    border-radius: 6px;
    transition:   background 0.15s, color 0.15s;
}

#czbia-close:hover {
    background: rgba(255,255,255,0.08);
    color:      var(--czbia-white);
}

/* ── Área de mensagens ────────────────────────────────────────────────────── */
#czbia-messages {
    flex:            1;
    overflow-y:      auto;
    padding:         14px 12px;
    display:         flex;
    flex-direction:  column;
    gap:             10px;
    scroll-behavior: smooth;
    background:      var(--czbia-black);
}

#czbia-messages::-webkit-scrollbar       { width: 4px; }
#czbia-messages::-webkit-scrollbar-track { background: transparent; }
#czbia-messages::-webkit-scrollbar-thumb {
    background:    var(--czbia-dark-3);
    border-radius: 4px;
}

/* ── Mensagens ────────────────────────────────────────────────────────────── */
.czbia-msg {
    display:   flex;
    max-width: 88%;
}

.czbia-msg--user      { align-self: flex-end; }
.czbia-msg--assistant { align-self: flex-start; }

.czbia-bubble {
    padding:    10px 14px;
    border-radius: 12px;
    line-height:   1.55;
    word-break:    break-word;
}

/* Usuário — amarelo sobre preto */
.czbia-msg--user .czbia-bubble {
    background:                var(--czbia-yellow);
    color:                     var(--czbia-black);
    border-bottom-right-radius: 3px;
    font-weight:               500;
}

/* Assistente — branco sobre escuro */
.czbia-msg--assistant .czbia-bubble {
    background:                var(--czbia-dark-2);
    color:                     var(--czbia-white);
    border:                    1px solid var(--czbia-border);
    border-bottom-left-radius: 3px;
}

/* Links dentro das respostas */
.czbia-msg--assistant .czbia-bubble a {
    color:                 var(--czbia-yellow);
    text-decoration:       underline;
    text-underline-offset: 2px;
    transition:            opacity 0.15s;
}
.czbia-msg--assistant .czbia-bubble a:hover {
    opacity: 0.8;
}

/* Erro */
.czbia-error .czbia-bubble {
    background:   var(--czbia-error) !important;
    color:        #ffaaaa !important;
    border-color: #660000 !important;
}

/* Markdown */
.czbia-bubble p              { margin: 0 0 8px; }
.czbia-bubble p:last-child   { margin-bottom: 0; }
.czbia-bubble ul             { margin: 4px 0 8px; padding-left: 18px; }
.czbia-bubble ul:last-child  { margin-bottom: 0; }
.czbia-bubble li             { margin-bottom: 4px; }
.czbia-bubble strong         { color: var(--czbia-yellow); font-weight: 700; }

/* ── Indicador de digitação ───────────────────────────────────────────────── */
.czbia-typing .czbia-bubble {
    display:     flex;
    align-items: center;
    gap:         5px;
    padding:     12px 16px;
}

.czbia-typing .czbia-bubble span {
    width:         7px;
    height:        7px;
    background:    var(--czbia-yellow);
    border-radius: 50%;
    display:       inline-block;
    animation:     czbia-bounce 1.2s infinite ease-in-out;
}
.czbia-typing .czbia-bubble span:nth-child(2) { animation-delay: 0.2s; }
.czbia-typing .czbia-bubble span:nth-child(3) { animation-delay: 0.4s; }

@keyframes czbia-bounce {
    0%, 60%, 100% { transform: translateY(0);    opacity: 0.35; }
    30%           { transform: translateY(-6px); opacity: 1;    }
}

/* ── Área de input ────────────────────────────────────────────────────────── */
#czbia-input-area {
    display:      flex;
    align-items:  flex-end;
    gap:          8px;
    padding:      10px 12px;
    border-top:   1px solid var(--czbia-border);
    background:   var(--czbia-dark);
    flex-shrink:  0;
}

#czbia-input {
    flex:          1;
    background:    var(--czbia-dark-3);
    border:        1px solid var(--czbia-border);
    border-radius: 8px;
    color:         var(--czbia-white);
    font-family:   inherit;
    font-size:     13px;
    line-height:   1.5;
    padding:       8px 12px;
    resize:        none;
    outline:       none;
    min-height:    36px;
    max-height:    120px;
    transition:    border-color 0.2s, box-shadow 0.2s;
}

#czbia-input::placeholder { color: #666; }

#czbia-input:focus {
    border-color: var(--czbia-yellow);
    box-shadow:   0 0 0 2px rgba(255, 214, 0, 0.15);
}

#czbia-send {
    width:          36px;
    height:         36px;
    flex-shrink:    0;
    background:     var(--czbia-yellow);
    border:         none;
    border-radius:  8px;
    color:          var(--czbia-black);
    cursor:         pointer;
    display:        flex;
    align-items:    center;
    justify-content: center;
    transition:     opacity 0.2s, transform 0.15s;
    padding:        0;
}

#czbia-send:hover:not(:disabled) {
    opacity:   0.85;
    transform: scale(1.05);
}

#czbia-send:disabled {
    opacity: 0.3;
    cursor:  default;
}

/* ── Footer ───────────────────────────────────────────────────────────────── */
#czbia-footer {
    text-align:  center;
    font-size:   10px;
    color:       #555;
    padding:     5px 12px 7px;
    border-top:  1px solid var(--czbia-border);
    background:  var(--czbia-black);
    flex-shrink: 0;
}

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    #czbia-widget {
        bottom: 24px;
    }

    /* Painel ocupa a tela toda — altura dinâmica considera o teclado */
    #czbia-panel {
        position:      fixed !important;
        top:           0;
        left:          0;
        right:         0;
        bottom:        auto;
        width:         100%;
        height:        100dvh; /* ajusta quando teclado aparece (browsers modernos) */
        max-height:    none;
        border-radius: 0;
        transform-origin: bottom center;
        animation:     czbia-slide-up 0.25s ease both;
    }
}

@keyframes czbia-slide-up {
    from { opacity: 0; transform: translateY(30px); }
    to   { opacity: 1; transform: translateY(0); }
}
