/* ==========================================================================
   Chat Widget & Support Panel — IBED
   ========================================================================== */

/* ----- FAB (Floating Action Button) ----- */
.chat-fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9990;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #1d72b8;
    color: #fff;
    border: none;
    box-shadow: 0 4px 16px rgba(0,0,0,.25);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    transition: background .2s, transform .15s;
}
.chat-fab:hover { background: #155fa0; transform: scale(1.07); }

.chat-fab-support {
    right: 96px; /* deslocado para não sobrepor o widget do user */
    background: #1d72b8;
}
.chat-fab-support:hover { background: #155fa0; }

/* Badge */
.chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e3342f;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* ----- Chat Window (usuário) ----- */
.chat-window {
    position: fixed;
    bottom: 90px;
    right: 28px;
    z-index: 9995;
    width: 360px;
    max-width: calc(100vw - 24px);
    height: 500px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ----- Support Panel ----- */
.chat-support-panel {
    position: fixed;
    bottom: 90px;
    right: 96px;
    z-index: 9995;
    width: 720px;
    max-width: calc(100vw - 24px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
    display: flex;
    overflow: hidden;
}

/* ----- Header ----- */
.chat-header {
    background: #1d72b8;
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.chat-header-support { background: #155fa0; }

.chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255,255,255,.4);
    flex-shrink: 0;
}
.chat-header-title {
    flex: 1;
    font-weight: 600;
    font-size: 14px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.chat-header-subtitle {
    font-size: 11px;
    opacity: .8;
}
.chat-header-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 18px;
    padding: 2px 6px;
    border-radius: 6px;
    transition: background .15s;
    flex-shrink: 0;
}
.chat-header-close:hover { background: rgba(0,0,0,.15); }

/* ----- Messages Area ----- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #f5f7fa;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

/* ----- Bubble ----- */
.chat-bubble-wrap {
    display: flex;
    flex-direction: column;
    max-width: 78%;
}
.chat-bubble-wrap.mine { align-self: flex-end; align-items: flex-end; }
.chat-bubble-wrap.theirs { align-self: flex-start; align-items: flex-start; }
.chat-bubble-wrap.continued { margin-top: 2px; }

.chat-bubble-meta { min-height: 0; }

.chat-bubble {
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.45;
    word-break: break-word;
    white-space: pre-wrap;
}
.chat-bubble.mine   { background: #1d72b8; color: #fff; border-bottom-right-radius: 4px; }
.chat-bubble.theirs { background: #fff; color: #222; border-bottom-left-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.1); }

.chat-bubble-meta {
    font-size: 10.5px;
    color: #888;
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Checkmarks leitura */
.chat-read-icon { font-size: 11px; }
.chat-read-icon.read   { color: #1d72b8; }
.chat-read-icon.unread { color: #aaa; }

/* ----- Arquivo inline ----- */
.chat-file-img {
    max-width: 220px;
    max-height: 160px;
    border-radius: 10px;
    cursor: pointer;
    display: block;
    margin-bottom: 2px;
}
.chat-file-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 10px;
    background: rgba(0,0,0,.07);
    color: inherit;
    text-decoration: none;
    font-size: 12.5px;
}
.chat-file-link:hover { background: rgba(0,0,0,.13); }

/* ----- Skeleton loading ----- */
@keyframes chatShimmer {
    0%   { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}
.chat-skeleton-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid #f1f5f9;
}
.chat-skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 400px 100%;
    animation: chatShimmer 1.3s infinite linear;
}
.chat-skeleton-line {
    height: 11px;
    border-radius: 6px;
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 400px 100%;
    animation: chatShimmer 1.3s infinite linear;
}

/* ----- Settings Overlay ----- */
.chat-settings-overlay {
    position: absolute;
    inset: 0;
    background: #fff;
    z-index: 10;
    display: flex;
    flex-direction: column;
    border-radius: 16px;
    overflow: hidden;
}
.chat-settings-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 10px;
    margin-bottom: 6px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}
.chat-settings-toggle {
    border: none;
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s;
}
.chat-settings-toggle.on  { background: #dcfce7; color: #15803d; }
.chat-settings-toggle.off { background: #f1f5f9; color: #64748b; }
.chat-settings-toggle:hover { filter: brightness(.95); }

/* ----- Typing indicator ----- */
.chat-typing {
    padding: 4px 16px;
    font-size: 11.5px;
    color: #777;
    min-height: 22px;
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f5f7fa;
    flex-shrink: 0;
}
.chat-typing-dots { display: flex; gap: 3px; }
.chat-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #999;
    animation: chatDot .9s infinite ease-in-out;
}
.chat-typing-dots span:nth-child(2) { animation-delay: .15s; }
.chat-typing-dots span:nth-child(3) { animation-delay: .30s; }
@keyframes chatDot {
    0%, 80%, 100% { transform: scale(1); opacity: .5; }
    40%           { transform: scale(1.3); opacity: 1; }
}
@keyframes chatUploadPulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: .4; }
}

/* ----- Input Area ----- */
.chat-input-area {
    padding: 10px 12px;
    border-top: 1px solid #e8ecf0;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #fff;
    flex-shrink: 0;
}
.chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13.5px;
    resize: none;
    max-height: 100px;
    outline: none;
    line-height: 1.4;
    font-family: inherit;
}
.chat-input:focus { border-color: #1d72b8; }

.chat-send-btn, .chat-attach-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: background .15s, transform .1s;
}
.chat-send-btn  { background: #1d72b8; color: #fff; }
.chat-send-btn:hover  { background: #155fa0; transform: scale(1.08); }
.chat-send-btn:disabled  { background: #b0c4d8; cursor: not-allowed; transform: none; }
.chat-attach-btn { background: #f0f4f8; color: #555; }
.chat-attach-btn:hover { background: #dde6ef; }

/* ----- Support Panel Layout ----- */
.chat-support-list {
    width: 240px;
    border-right: 1px solid #e8ecf0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.chat-support-tabs {
    display: flex;
    border-bottom: 1px solid #e8ecf0;
    flex-shrink: 0;
}
.chat-support-tab {
    flex: 1;
    padding: 10px 4px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 11.5px;
    color: #666;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: color .15s, border-color .15s;
}
.chat-support-tab.active { color: #1d72b8; border-bottom-color: #1d72b8; }

.chat-support-conv-list {
    flex: 1;
    overflow-y: auto;
}
.chat-support-conv-item {
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    border-bottom: 1px solid #f2f4f6;
    transition: background .12s;
}
.chat-support-conv-item:hover    { background: #f5f7fa; }
.chat-support-conv-item.selected { background: #e8f0fb; }

.chat-support-conv-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.chat-support-conv-info { flex: 1; min-width: 0; }
.chat-support-conv-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-support-conv-preview {
    font-size: 11.5px;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-support-conv-time {
    font-size: 10.5px;
    color: #aaa;
    flex-shrink: 0;
}
.chat-support-conv-badge {
    background: #e3342f;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 17px;
    height: 17px;
    border-radius: 9px;
    padding: 0 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-support-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.chat-support-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #aaa;
    font-size: 14px;
    gap: 10px;
}
.chat-support-empty i { font-size: 40px; }

/* ----- Close/End button ----- */
.chat-end-btn {
    background: none;
    border: 1px solid rgba(255,255,255,.5);
    color: #fff;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 10px;
    cursor: pointer;
    transition: background .15s;
    flex-shrink: 0;
}
.chat-end-btn:hover { background: rgba(0,0,0,.15); }

/* ----- Status badge ----- */
.chat-status-waiting,
.chat-status-active,
.chat-status-closed {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 6px;
    border-radius: 20px;
    font-size: .8em;
    font-weight: 700;
    letter-spacing: .4px;
    text-transform: uppercase;
}
.chat-status-waiting { background: #f59e0b; color: #fff; }
.chat-status-active  { background: #10b981; color: #fff; }
.chat-status-closed  { background: rgba(255,255,255,.2); color: #fff; }

/* ----- Closed conversation notice ----- */
.chat-closed-notice {
    text-align: center;
    padding: 10px;
    font-size: 12px;
    color: #888;
    border-top: 1px solid #e8ecf0;
    background: #fafafa;
    flex-shrink: 0;
}

/* ----- Responsive ----- */
@media (max-width: 600px) {
    .chat-window  { right: 12px; width: calc(100vw - 24px); }
    .chat-support-panel { right: 12px; width: calc(100vw - 24px); height: calc(100vh - 120px); }
    .chat-support-list  { width: 200px; }
    .chat-fab-support   { right: 80px; }
}
