/* ============================================================
   WIDGET DE CHAT - Code Rumble (Atendimento Online)
   ============================================================ */

/* FAB do chat (centralizado no rodape da tela) */
.cr-fab {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    width: 60px;
    height: 60px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff6b00, #dd5300);
    color: #fff;
    font-size: 26px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(255, 107, 0, 0.45);
    transition: transform 0.25s, box-shadow 0.25s;
}

.cr-fab:hover { transform: translateX(-50%) scale(1.08); }

.cr-fab.cr-fab-open { background: #171717; border: 2px solid #ff6b00; }

.cr-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 5px;
    border-radius: 11px;
    background: #e53935;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 22px;
    text-align: center;
    display: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.cr-fab-badge.cr-visible { display: block; }

/* Painel do chat */
.cr-panel {
    position: fixed;
    bottom: 92px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
    width: min(370px, calc(100vw - 24px));
    max-height: calc(100vh - 112px);
    display: none;
    flex-direction: column;
    background: #111;
    border: 1px solid rgba(255, 107, 0, 0.45);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    overflow: hidden;
}

.cr-panel.cr-open { display: flex; }

/* Header */
.cr-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #ff6b00, #dd5300);
    color: #fff;
}

.cr-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    overflow: hidden;
}

.cr-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.cr-header-info { flex: 1; min-width: 0; }

.cr-header-info strong {
    display: block;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cr-header-status { display: flex; align-items: center; gap: 6px; font-size: 12px; }

.cr-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #69f0ae;
    box-shadow: 0 0 6px #69f0ae;
}

.cr-dot.cr-offline { background: #bdbdbd; box-shadow: none; }

.cr-header-actions { display: flex; gap: 4px; flex-shrink: 0; }

.cr-icon-btn {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.cr-icon-btn:hover { background: rgba(255, 255, 255, 0.32); }

.cr-icon-btn.cr-wa { background: #25d366; }

.cr-icon-btn.cr-wa:hover { background: #1eb857; }

/* Corpo */
.cr-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background:
        radial-gradient(ellipse at top right, rgba(255, 107, 0, 0.06), transparent 55%),
        #111;
    min-height: 200px;
    max-height: 380px;
}

.cr-offline-banner {
    background: rgba(255, 193, 7, 0.12);
    border: 1px solid rgba(255, 193, 7, 0.35);
    color: #ffd54f;
    font-size: 12px;
    border-radius: 8px;
    padding: 8px 10px;
    text-align: center;
}

.cr-system-msg {
    text-align: center;
    font-size: 11px;
    color: #9e9e9e;
    margin: 2px 0;
}

/* Mensagens */
.cr-msg { display: flex; flex-direction: column; max-width: 82%; }

.cr-msg.cr-client { align-self: flex-end; align-items: flex-end; }

.cr-msg.cr-attendant { align-self: flex-start; align-items: flex-start; }

.cr-bubble {
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.45;
    word-break: break-word;
    white-space: pre-wrap;
}

.cr-msg.cr-attendant .cr-bubble {
    background: #222;
    color: #e8e8e8;
    border-top-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.cr-msg.cr-client .cr-bubble {
    background: linear-gradient(135deg, #ff6b00, #e05e00);
    color: #fff;
    border-top-right-radius: 4px;
}

.cr-msg-name { font-size: 10.5px; color: #ff8a3d; margin: 0 4px 3px; font-weight: 600; }

.cr-msg-time { font-size: 10px; color: #8a8a8a; margin: 3px 4px 0; }

/* Largura FIXA (nao 100%): dentro do balao flex a % colapsa para 0px e o
   navegador nao desenha os controles (some o play). Com largura fixa o
   player nativo sempre aparece. */
.cr-audio { width: 200px; max-width: 220px; border-radius: 8px; display: block; }

/* Imagem enviada: foto na conversa + link de download logo abaixo */
.cr-img-link { display: block; margin-bottom: 2px; }
.cr-img {
    display: block;
    max-width: 220px;
    max-height: 260px;
    border-radius: 12px;
    cursor: zoom-in;
    background: #222;
}

.cr-file {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    padding: 4px 2px;
}

.cr-file i { font-size: 20px; }

.cr-msg.cr-attendant .cr-file i { color: #ff8a3d; }

.cr-msg.cr-client .cr-file i { color: #fff; }

.cr-file-meta { min-width: 0; }

.cr-file-meta strong { display: block; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cr-file-meta span { font-size: 10.5px; opacity: 0.85; }

/* Tela de nome */
.cr-name-screen { display: flex; flex-direction: column; gap: 12px; padding: 8px 2px; }

.cr-name-screen p { margin: 0; font-size: 13.5px; color: #d5d5d5; }

.cr-name-input {
    padding: 11px 13px;
    border-radius: 10px;
    border: 1px solid #444;
    background: #1a1a1a;
    color: #fff;
    font-size: 14px;
    outline: none;
}

.cr-name-input:focus { border-color: #ff6b00; }

.cr-btn-primary {
    border: 0;
    padding: 11px;
    border-radius: 10px;
    background: linear-gradient(135deg, #ff6b00, #dd5300);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.cr-btn-primary:hover { opacity: 0.9; }

.cr-btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

/* Botao para iniciar nova conversa (quando encerrada/removida) */
.cr-new-conv {
    align-self: center;
    border: 1px solid #ff6b00;
    background: rgba(255, 107, 0, 0.12);
    color: #ffb877;
    padding: 9px 16px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    margin: 6px 0 2px;
    transition: background 0.2s;
}

.cr-new-conv:hover { background: rgba(255, 107, 0, 0.25); }

/* Rodape do chat */
.cr-footer {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    background: #161616;
    border-top: 1px solid rgba(255, 107, 0, 0.2);
}

.cr-input {
    flex: 1;
    padding: 10px 13px;
    border-radius: 22px;
    border: 1px solid #3a3a3a;
    background: #1e1e1e;
    color: #fff;
    font-size: 13.5px;
    outline: none;
    resize: none;
    max-height: 90px;
}

.cr-input:focus { border-color: #ff6b00; }

.cr-footer .cr-icon-btn { color: #ff8a3d; background: transparent; }

.cr-footer .cr-icon-btn:hover { background: rgba(255, 107, 0, 0.15); }

.cr-footer .cr-icon-btn.cr-send {
    background: linear-gradient(135deg, #ff6b00, #dd5300);
    color: #fff;
    font-size: 15px;
}

.cr-footer .cr-icon-btn.cr-send:disabled { opacity: 0.4; }

.cr-rec-ind {
    display: none;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #ff5252;
    padding: 8px 12px;
    background: #1a0a0a;
    border-top: 1px solid rgba(255, 82, 82, 0.3);
}

.cr-rec-ind.cr-on { display: flex; }

.cr-rec-ind .cr-dot { background: #ff5252; box-shadow: 0 0 8px #ff5252; animation: cr-blink 1s infinite; }

@keyframes cr-blink { 50% { opacity: 0.3; } }

.cr-hint {
    font-size: 10.5px;
    color: #7a7a7a;
    text-align: center;
    padding: 6px 12px 10px;
    background: #161616;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.cr-hint a { color: #25d366; font-weight: 600; text-decoration: none; }

/* Menu de anexo (mobile: tirar foto / enviar arquivo) */
.cr-attach-menu {
    position: absolute;
    left: 12px;
    bottom: 64px;
    z-index: 5;
    min-width: 190px;
    background: #1c1c1c;
    border: 1px solid rgba(255, 107, 0, 0.35);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
    padding: 6px;
    display: none;
}

.cr-attach-menu.cr-show { display: block; }

.cr-attach-opt {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    border: 0;
    background: transparent;
    color: #e8e8e8;
    font-size: 13.5px;
    cursor: pointer;
    border-radius: 8px;
    text-align: left;
    transition: background 0.2s;
}

.cr-attach-opt:hover { background: rgba(255, 107, 0, 0.15); }

.cr-attach-opt i { color: #ff8a3d; width: 18px; text-align: center; font-size: 15px; }

/* Upload indo (mensagem temporaria) */
.cr-uploading { opacity: 0.6; font-style: italic; }

/* ===== Responsivo ===== */
@media (max-width: 768px) {
    .cr-fab {
        bottom: 20px;
        left: 50%;
        width: 54px;
        height: 54px;
        font-size: 22px;
    }

    .cr-panel {
        bottom: 0;
        left: 0;
        right: 0;
        transform: none;
        width: 100%;
        max-height: none;
        height: 92vh;
        border-radius: 16px 16px 0 0;
    }

    .cr-body { max-height: none; flex: 1; }
}

@media (min-width: 769px) and (max-width: 1024px) {
    /* Em tablets (retrato) o painel nao pode passar dos cantos */
    .cr-panel { width: min(370px, calc(100vw - 24px)); }
}

@media (max-height: 520px) and (min-width: 769px) {
    /* Telas curtas: reduz altura maxima para caber no rodape */
    .cr-panel { max-height: calc(100vh - 112px); }
}

/* ===== Pagina dedicada /chat: painel ocupa a maior parte da tela ===== */
@media (min-width: 769px) {
    body.cr-dedicated .cr-fab { display: none; }

    body.cr-dedicated .cr-panel {
        width: min(80vw, 1100px);
        height: 82vh;
        max-height: none;
        bottom: auto;
        top: 50%;
        transform: translate(-50%, -50%);
    }

    body.cr-dedicated .cr-body {
        max-height: none;
        flex: 1;
    }
}
