:root {
    --primary-color: #25d366;
    --secondary-color: #128c7e;
    --light-bg: #f8f9fa;
    --border-color: #e9ecef;
    --text-muted: #6c757d;
    --chat-bg: #f0f2f5;
    --message-sent: #dcf8c6;
    --message-received: #ffffff;
    --sidebar-width: 360px;
    --header-height: 48px;
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--chat-bg);
    margin: 0;
    height: 100%;
    min-height: 100vh;
    overflow: hidden;
}

/* Zoom geral do chat: interface ~82% para conteúdo menor e melhor visualização */
.chat-app-wrapper {
    display: flex;
    position: relative;
    width: 121.95%;   /* 100% / 0.82 */
    height: 121.95vh;
    transform: scale(0.82);
    transform-origin: 0 0;
    overflow: hidden;
}

/* Sidebar: altura 100% do wrapper para a linha divisória chegar até o final */
.sidebar {
    width: var(--sidebar-width);
    background: #fff;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1050;
    transition: left 0.3s;
}

.sidebar-header {
    background: #fff;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header .actions {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
}

.sidebar-header .btn {
    background: transparent;
    border: 1px solid #ddd;
    color: #666;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.sidebar-header .btn:hover {
    background: #f5f5f5;
    border-color: #ccc;
    transform: scale(1.05);
}

.user-info {
    background: linear-gradient(135deg, #f8fafb 0%, #f0f4f8 100%);
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(145deg, #25d366 0%, #128c7e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.95rem;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(37, 211, 102, 0.3);
}

.user-details {
    min-width: 0;
    flex: 1;
}

.user-details h6 {
    margin: 0 0 1px 0;
    font-weight: 600;
    font-size: 0.88rem;
    color: #1a1a1a;
    letter-spacing: 0.01em;
}

.user-details small {
    color: #667781;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.user-details small:first-of-type::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #25d366;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(37, 211, 102, 0.3);
}

#carteira-count {
    margin-left: 4px;
}

/* Abas da sidebar: nunca encolher para não sumir em 1366x768 */
.sidebar #sidebar-tabs,
.sidebar #sidebar-tabs-instrucao {
    flex-shrink: 0 !important;
}
.sidebar .agendados-filter-wrap {
    flex-shrink: 0 !important;
}

/* Em telas baixas (ex.: 1366x768) compactar topo da sidebar para as abas aparecerem */
@media (max-height: 800px) {
    .sidebar .sidebar-header {
        padding: 0.5rem 1rem;
    }
    .sidebar .user-info {
        padding: 0.6rem 1rem;
    }
    .sidebar .user-avatar {
        width: 38px;
        height: 38px;
        font-size: 1rem;
    }
    .sidebar .user-details h6 {
        font-size: 0.88rem;
    }
    .sidebar .user-details small {
        font-size: 0.7rem;
    }
    .sidebar .search-container {
        padding: 0.5rem 1rem;
    }
    .sidebar .search-input {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }
}

.search-container {
    padding: 0.5rem 0.75rem;
    background: white;
    border-bottom: 1px solid var(--border-color);
}

.search-container-with-scope {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.search-scope {
    flex-shrink: 0;
    width: auto;
    min-width: 108px;
    padding: 0.4rem 0.5rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--light-bg);
    font-size: 0.8rem;
    color: #333;
}
.search-input {
    background: var(--light-bg);
    border: none;
    border-radius: 18px;
    padding: 0.5rem 0.75rem;
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
}

.search-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--primary-color);
}

/* Chat List */
.chat-list {
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
    background: white;
    padding: 0.5em 0.6em;
}

/* Botão "mais conversas" no cantinho da sidebar */
.chat-list-load-more-wrap {
    position: absolute;
    right: 14px;
    bottom: 14px;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    pointer-events: none;
}

.chat-list-load-more {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 50%;
    background: #ffffff;
    color: #667781;
    box-shadow: 0 2px 10px rgba(11, 20, 26, 0.18);
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.chat-list-load-more:hover:not(:disabled) {
    transform: translateY(-1px) scale(1.04);
    background: #f0f2f5;
    color: #00a884;
    box-shadow: 0 4px 14px rgba(11, 20, 26, 0.22);
}

.chat-list-load-more:disabled,
.chat-list-load-more.is-loading {
    opacity: 0.7;
    cursor: wait;
    transform: none;
}

.chat-list-load-more i {
    font-size: 0.85rem;
    line-height: 1;
}

.chat-list-load-more .spinner-border {
    width: 0.85rem;
    height: 0.85rem;
    border-width: 0.12em;
}

.chat-item {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: #fff;
    border-radius: 10px;
    margin-bottom: 0.4em;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
    min-width: 0;
    overflow: hidden;
}

/* Evitar que texto ultrapasse: flex children podem encolher */
#chat-list .chat-item .d-flex {
    min-width: 0;
    overflow: hidden;
}
#chat-list .chat-item .d-flex > div {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}
#chat-list .chat-item .fw-bold,
#chat-list .chat-item .text-muted.small,
#chat-list .chat-item .text-truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
#chat-list .chat-item .profile-pic {
    flex-shrink: 0;
}

.chat-item:hover {
    background: var(--light-bg);
}

.chat-item.selected {
    background: var(--primary-color);
    color: #333;
}

.chat-item.selected .text-muted {
    color: #666 !important;
}

.chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 0.9rem;
    font-weight: bold;
    flex-shrink: 0;
    overflow: hidden;
}

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

.chat-content {
    flex: 1;
    min-width: 0;
}

.chat-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-preview {
    color: var(--text-muted);
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
}

.chat-time {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.notification-badge {
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: bold;
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

/* Overlay para mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1049;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Chat Area – fixo na viewport; footer sempre no rodapé */
.main-content {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: var(--sidebar-width);
    width: auto;
    margin: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-width: 0;
    height: auto;
    overflow: hidden;
    touch-action: none;
    transition: left 0.3s;
    z-index: 1;
}
.chat-header {
    grid-row: 1;
    background: white;
    border-bottom: 1px solid var(--border-color);
    padding: 0.4rem 0.6rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--header-height);
    flex-shrink: 0;
}

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

.chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 0.9rem;
    font-weight: bold;
    overflow: hidden;
}

.chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 10px;
}

.chat-header-details h6 {
    margin: 0;
    font-weight: 600;
    font-size: 0.9rem;
}

.chat-header-details small {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.user-details .text-success {
    color: #25d366 !important;
}
.user-details .text-success i {
    color: #25d366 !important;
}

.chat-header-actions {
    display: flex;
    gap: 0.5rem;
}

.chat-header-actions .btn {
    border-radius: 50%;
    width: 34px;
    height: 34px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    transition: all 0.3s ease;
}

.chat-header-actions .btn:hover {
    transform: scale(1.05);
}

/* ========== Área de mensagens – ocupa o espaço entre header e footer; só ela rola ========== */
.chat-messages {
    grid-row: 2;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: auto;
    padding: 10px 12px 10px;
    background: var(--chat-bg);
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

/* Cada mensagem = uma linha full width; enviadas à direita, recebidas à esquerda */
.message {
    display: flex;
    flex-direction: row;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin-bottom: 2px;
    padding: 2px 0;
    box-sizing: border-box;
}

.message.sent {
    justify-content: flex-end !important;
}

.message.received {
    justify-content: flex-start !important;
}

/* Container: limite de largura igual ao WhatsApp Web (bolhas não ocupam toda a largura) */
.message-container {
    max-width: min(55%, 480px);
    min-width: 0;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.message.received .message-container {
    align-items: flex-start;
}

@media (min-width: 992px) {
    .message.received .message-container {
        width: min(100%, 480px);
        max-width: 480px !important;
    }
}

/* Container com mídia/documento: permite bolha mais larga, com largura mínima (estilo WhatsApp Web) */
.message-container:has(.message-bubble--has-media),
.message-container:has(.message-content.document-message),
.message-container:has(.message-content.media-message) {
    max-width: min(75%, 400px);
    min-width: min(260px, 92%);
}

/* Bolha: largura conforme texto, até 100% do container; visual WhatsApp Web */
.message-bubble {
    display: inline-block;
    max-width: 100%;
    min-width: 0;
    padding: 6px 10px 8px;
    border-radius: 8px;
    position: relative;
    word-break: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box;
    background: #fff;
    font-size: 14px;
    line-height: 1.4;
    overflow: hidden;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.08);
}

/* Bolhas com documento/PDF/mídia: mais largas, com largura mínima para não cortar nome/botão */
.message-bubble--has-media,
.message-bubble:has(.message-content.document-message),
.message-bubble:has(.message-content.media-message) {
    max-width: min(75%, 400px) !important;
    min-width: min(260px, 92%) !important;
}
.message-bubble--has-media .message-content.document-message,
.message-bubble--has-media .message-content.media-message,
.message-bubble:has(.message-content.document-message) .message-content.document-message,
.message-bubble:has(.message-content.media-message) .message-content.media-message {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
}
.message-bubble--has-media .pdf-preview,
.message-bubble--has-media .doc-preview,
.message-bubble--has-media .excel-preview,
.message-bubble--has-media .media-preview,
.message-bubble:has(.document-message) .pdf-preview,
.message-bubble:has(.media-message) .media-preview {
    width: 100% !important;
    max-width: 100% !important;
    min-width: min(220px, 100%) !important;
}
/* Botões/links em mídia: largura mínima para "Visualizar"/"Baixar" não cortar */
.message-bubble--has-media .pdf-preview .btn,
.message-bubble--has-media .pdf-preview .media-link,
.message-bubble--has-media .doc-preview .btn,
.message-bubble--has-media .doc-preview .media-link,
.message-bubble--has-media .media-preview .btn,
.message-bubble--has-media .media-preview .media-link,
.chat-messages .message-bubble .pdf-preview .btn,
.chat-messages .message-bubble .pdf-preview .media-link,
.chat-messages .message-bubble .doc-preview .btn,
.chat-messages .message-bubble .doc-preview .media-link {
    max-width: 100% !important;
    min-width: 72px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

/* Enviadas: verde claro, “rabinho” no canto inferior direito */
.message.sent .message-bubble {
    background: var(--message-sent);
    color: #111;
    border-bottom-right-radius: 4px;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    border-bottom-left-radius: 8px;
}

/* Recebidas: fundo claro, “rabinho” no canto inferior esquerdo */
.message.received .message-bubble {
    background: var(--message-received);
    color: #111;
    border-bottom-left-radius: 4px;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.08);
}

/* Destaque temporário da mensagem ao abrir pelo resultado da busca */
.message.message-highlight-search .message-bubble {
    box-shadow: 0 0 0 2px #25d366;
    animation: messageHighlightPulse 0.6s ease-out;
}
.search-highlight,
.search-highlight-text {
    background-color: #ffeb3b !important;
    color: #111 !important;
    padding: 0 2px;
    border-radius: 2px;
}
@keyframes messageHighlightPulse {
    0% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.5); }
    70% { box-shadow: 0 0 0 8px rgba(37, 211, 102, 0); }
    100% { box-shadow: 0 0 0 2px #25d366; }
}

/* Remetente: uma linha, compacto */
.message-username {
    font-size: 15px;
    color: var(--text-muted);
    margin-bottom: 2px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.message-content {
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 14px;
}

.message-content.text-message {
    white-space: pre-line;
    max-width: 100%;
    word-break: normal;
    overflow-wrap: normal;
}

.message-content.text-message span {
    display: inline-block;
    max-width: 100%;
}

.message-content.image-message img {
    max-width: 100%;
    max-height: 220px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    display: block;
}

/* Vídeo e mídia: tamanho limitado para não dominar a tela */
.message-content.video-message {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
}
.message-content.video-message video {
    max-width: 100%;
    max-height: 220px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    display: block;
    background: #000;
}
.message-content.video-message .video-caption {
    font-size: 0.8rem;
    padding: 0.35rem 0.5rem !important;
    margin-top: 0.35rem !important;
    word-break: break-word;
    overflow-wrap: break-word;
}
.message-content.video-message .file-name {
    font-size: 0.7rem;
    margin-top: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.message-content.video-message .btn,
.message-content.video-message .media-link {
    font-size: 0.72rem !important;
    padding: 0.25rem 0.5rem !important;
    margin-top: 0.25rem !important;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-content.document-message,
.message-content.media-message {
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    word-break: break-word;
    overflow-wrap: break-word;
}

/* Vídeo dentro de .media-message (estrutura com .video-preview) */
.message-content.media-message .video-preview,
.message-content.video-message .video-preview {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    border-radius: 8px;
    background: #000;
}
.message-content.media-message .video-preview video,
.message-content.video-message .video-preview video,
.message-content.media-message video,
.message-content.video-message video {
    max-width: 100% !important;
    max-height: 220px !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain;
    display: block;
    border-radius: 8px;
}

/* Documentos e arquivos dentro da bolha */
.message-content.media-message .mt-2,
.message-content.document-message .mt-2 {
    margin-top: 0.35rem !important;
}
.message-content.media-message .btn,
.message-content.media-message .media-link,
.message-content.document-message .btn,
.message-content.document-message .media-link {
    font-size: 0.72rem !important;
    padding: 0.3rem 0.5rem !important;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

.pdf-preview, .doc-preview, .excel-preview, .media-preview {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.4rem;
    background: rgba(0,0,0,0.05);
    border-radius: 6px;
    margin: 0.2rem 0;
    max-width: 100%;
    min-width: min(220px, 100%);
    overflow: hidden;
}
/* Nome do arquivo: ellipsis; botão pode encolher para não estourar */
.pdf-preview .btn,
.pdf-preview .media-link,
.doc-preview .btn,
.doc-preview .media-link,
.media-preview .btn,
.media-preview .media-link {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pdf-preview span,
.doc-preview span,
.media-preview span {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* Imagem dentro de .media-message (quando não é .image-message) */
.message-content.media-message img {
    max-width: 100% !important;
    max-height: 220px !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain;
    border-radius: 8px;
    display: block;
}
.message-bubble .message-content .btn,
.message-bubble .message-content .media-link {
    font-size: 0.72rem !important;
    padding: 0.3rem 0.5rem !important;
}
/* Iframe/embed de PDF ou outro documento */
.message-content.media-message iframe,
.message-content.document-message iframe,
.message-bubble iframe {
    max-width: 100% !important;
    max-height: 220px !important;
    width: 100%;
    height: auto;
    min-height: 120px;
    border: none;
    border-radius: 6px;
}

/* Em telas menores, vídeo/imagem limitados; container um pouco mais estreito */
@media (max-width: 1400px), (max-height: 800px) {
    .message-content.image-message img {
        max-height: 180px;
    }
    .message-content.video-message video,
    .message-content.media-message video,
    .message-content.media-message .video-preview video,
    .message-content.video-message .video-preview video {
        max-height: 180px !important;
    }
    .message-container {
        max-width: min(55%, 340px);
    }
    .message-container:has(.message-bubble--has-media),
    .message-container:has(.message-content.document-message),
    .message-container:has(.message-content.media-message) {
        max-width: min(75%, 400px) !important;
        min-width: min(260px, 92%) !important;
    }
}

.audio-message-container {
    width: 100%;
    padding: 0.4rem;
    border-radius: 6px;
    background: rgba(0,0,0,0.05);
    margin: 0.2rem 0;
    max-width: 100%;
}

/* Hora e status: uma linha, sem quebrar */
.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 2px;
    font-size: 11px;
    white-space: nowrap;
    flex-shrink: 0;
}

.message.sent .message-meta i.message-status-failed,
.message.sent.message-failed .message-meta i.message-status-failed {
    color: #dc3545 !important;
    opacity: 1 !important;
}


.message-time {
    font-size: 15px;
    color: var(--text-muted);
}

.message-date {
    text-align: center;
    margin: 0.5rem 0;
    padding: 0 0.25rem;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    box-sizing: border-box;
}

/* Chat Footer – sempre colado embaixo em qualquer navegador/tela */
.chat-footer {
    grid-row: 3;
    background: white;
    border-top: 1px solid var(--border-color);
    padding: 0.35rem 0.6rem;
    flex-shrink: 0;
    flex-grow: 0;
    margin-top: 0;
    width: 100%;
    min-height: 60px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.chat-input-container {
    background: #ffffff;
    border: 1px solid #e9edef;
    border-radius: 18px;
    padding: 4px 6px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
}

.chat-input-container:focus-within {
    border-color: #00a884;
    box-shadow: 0 0 0 2px rgba(0, 168, 132, 0.2);
}

.chat-input-container .input-group {
    border: none;
    box-shadow: none;
}

.chat-input-container .input-group .btn {
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    transition: all 0.2s ease;
}

.chat-input-container .input-group .btn-outline-secondary {
    background: transparent;
    color: #667781;
    border: none;
}

.chat-input-container .input-group .btn-outline-secondary:hover {
    background: #f5f6f6;
    color: #3b4a54;
}

.chat-input-container .input-group .btn-success {
    background: #00a884;
    border: none;
}

.chat-input-container .input-group .btn-success:hover {
    background: #008f73;
}

.message-textarea {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    font-size: 13px;
    line-height: 1.3;
    resize: none;
    overflow: hidden;
    min-height: 16px;
    max-height: 72px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: #3b4a54;
    padding: 4px 6px !important;
}

.message-textarea:focus {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

.message-textarea::placeholder {
    color: #667781;
    font-size: 13px;
    line-height: 1.3;
}

/* Dica e hint do rodapé – compactos, dica fechada por padrão libera espaço */
.chat-footer-dica {
    margin-top: 0.25rem !important;
    padding: 0.25rem 0.5rem !important;
    font-size: 0.72rem !important;
    line-height: 1.25;
    border-radius: 6px;
}
.chat-footer-dica:not([open]) summary {
    margin: 0;
    padding: 0;
}
.chat-footer-dica summary {
    cursor: pointer;
    font-weight: 600;
}
.chat-footer-dica .dica-body {
    margin-top: 0.15rem;
    padding-top: 0.2rem;
    border-top: 1px solid rgba(0,0,0,0.06);
    font-size: 0.7rem;
}
.chat-footer-hint {
    font-size: 0.7rem !important;
    margin-top: 0.15rem !important;
    line-height: 1.2;
    color: var(--text-muted);
}

/* Botão do microfone */
.btn-mic {
    background: var(--light-bg);
    color: var(--text-muted);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 6px;
}
.btn-mic.recording {
    background: #dc3545;
    color: #fff;
    animation: pulse 1s infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(220,53,69, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(220,53,69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220,53,69, 0); }
}

/* File Preview */
.file-preview {
    background: white;
    border-radius: 10px;
    padding: 0.75rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
}

.file-preview-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.file-icon {
    width: 40px;
    height: 40px;
    background: var(--light-bg);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
}

.file-info {
    flex: 1;
}

.file-name {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.file-size {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ========== LAYOUT MOBILE (estilo WhatsApp: lista tela cheia, ao clicar chat tela cheia com voltar) ========== */
@media (max-width: 991.98px) {
    :root {
        --mobile-header-h: 52px;
        --mobile-footer-h: 64px;
    }
    .chat-app-wrapper {
        display: block !important;
        width: 100vw !important;
        min-width: 0 !important;
        max-width: 100vw !important;
        height: 100vh !important;
        transform: none !important;
        box-sizing: border-box;
        padding: 0 !important;
        margin: 0 !important;
    }
    /* Sidebar = lista de chats em tela cheia */
    .sidebar {
        display: flex;
        flex-direction: column;
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        height: 100vh !important;
        z-index: 10;
        transition: none;
    }
    .sidebar.hide {
        display: none !important;
    }
    .sidebar .chat-list {
        padding-bottom: 16px !important;
    }
    /* Área do chat: escondida até ter .active (ao clicar no contato) */
    .main-content {
        display: none !important;
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        height: 100vh !important;
        margin: 0 !important;
        z-index: 11;
    }
    .main-content.active {
        display: flex !important;
        flex-direction: column !important;
        height: 100vh !important;
        min-height: 100vh !important;
        max-height: 100vh !important;
        overflow: hidden !important;
        overflow-x: hidden !important;
        overflow-y: hidden !important;
        touch-action: none !important;
    }
    .chat-header,
    .chat-messages {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100vw !important;
        box-sizing: border-box;
        margin: 0 !important;
        padding: 0 !important;
    }
    .chat-footer {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100vw !important;
        box-sizing: border-box;
        margin-left: 0 !important;
        margin-right: 0 !important;
        margin-bottom: 0 !important;
        margin-top: auto !important;
        padding: 0 !important;
        flex-shrink: 0 !important;
    }
    /* Header compacto */
    .chat-header {
        flex-shrink: 0;
        padding: 0 10px 0 8px !important;
        min-height: var(--mobile-header-h) !important;
        max-height: var(--mobile-header-h) !important;
        align-items: center;
        gap: 8px;
    }
    .chat-header-info {
        gap: 8px;
        min-width: 0;
    }
    .chat-header-back {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        flex-shrink: 0;
        border: none;
        background: transparent;
        color: #54656f;
        border-radius: 50%;
    }
    .chat-header-back:hover {
        background: #f0f2f5;
    }
    .chat-header-avatar {
        width: 36px !important;
        height: 36px !important;
        flex-shrink: 0;
        border-radius: 8px;
    }
    .chat-header-avatar img {
        border-radius: 8px;
    }
    .chat-header-details {
        min-width: 0;
        flex: 1;
    }
    .chat-header-details h6 {
        font-size: 0.95rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin: 0;
    }
    .chat-header-details small {
        font-size: 0.7rem;
        display: block;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .chat-header-actions {
        flex-shrink: 0;
        gap: 4px;
    }
    .chat-header-actions .btn {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        padding: 0 !important;
        font-size: 0.9rem;
    }
    .chat-header-actions-mobile .dropdown .btn {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .chat-header-actions-mobile .dropdown-menu {
        font-size: 0.9rem;
    }
    /* Mensagens ocupam o meio; footer fica no rodapé */
    .chat-messages {
        flex: 1 1 0 !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding: 12px 10px 20px !important;
    }
    .message-container {
        max-width: min(82%, 360px) !important;
    }
    .message-bubble {
        max-width: 100% !important;
        min-width: 0 !important;
        word-break: break-word;
        box-sizing: border-box;
        padding: 6px 10px 8px !important;
        border-radius: 8px;
    }
    .message-bubble--has-media,
    .message-bubble:has(.message-content.document-message),
    .message-bubble:has(.message-content.media-message) {
        max-width: 100% !important;
        min-width: min(220px, 92%) !important;
    }
    .message.sent,
    .message.received {
        padding: 2px 0 !important;
    }
    /* Bolhas de arquivo/PDF mais compactas no mobile */
    .message-bubble .message-content.document-message,
    .message-bubble .message-content.media-message {
        padding: 4px 0 !important;
    }
    .message-bubble .document-message .btn,
    .message-bubble .media-message .btn,
    .message-bubble .media-link {
        font-size: 0.7rem !important;
        padding: 4px 8px !important;
        margin-top: 4px;
    }
    .message-bubble .pdf-preview,
    .message-bubble .doc-preview,
    .message-bubble .media-preview {
        padding: 4px !important;
        margin: 2px 0 !important;
    }
    .message-bubble .message-meta {
        font-size: 0.65rem !important;
        margin-top: 2px !important;
    }
    .message-date {
        margin: 0.5rem 0 !important;
        font-size: 0.7rem !important;
    }
    .chat-footer {
        flex-shrink: 0 !important;
        margin-top: auto !important;
        width: 100% !important;
        border-top: 1px solid #e9ecef;
        background: #f0f2f5;
        display: flex !important;
        flex-direction: column !important;
        padding: 4px 8px 16px 8px !important;
        gap: 0;
        visibility: visible !important;
        opacity: 1 !important;
        min-height: auto;
        box-sizing: border-box;
    }
    .main-content.active .chat-footer:not(.d-none) {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    .chat-footer .chat-input-container {
        padding: 4px 6px !important;
        border-radius: 18px;
        min-height: 0;
    }
    .chat-footer .chat-input-container .input-group {
        gap: 2px;
        align-items: center;
    }
    .chat-footer .chat-input-container .input-group .btn {
        width: 28px !important;
        height: 28px !important;
        min-width: 28px !important;
        font-size: 0.8rem;
        padding: 0 !important;
    }
    .chat-footer .message-textarea {
        font-size: 13px !important;
        line-height: 18px !important;
        min-height: 18px !important;
        padding: 4px 6px !important;
        max-height: 64px !important;
    }
    .chat-footer .message-textarea::placeholder {
        font-size: 13px;
        line-height: 18px;
    }
    /* Hint e Dica numa linha, bem compactos */
    .chat-footer-hint {
        font-size: 0.65rem !important;
        margin-top: 2px !important;
        line-height: 1.2;
        opacity: 0.85;
    }
    .chat-footer-dica {
        margin-top: 2px !important;
        padding: 4px 8px !important;
        font-size: 0.65rem !important;
        line-height: 1.25;
        border-radius: 6px;
        background: #e9ecef !important;
        color: #495057 !important;
    }
    .chat-footer-dica summary {
        cursor: pointer;
        font-weight: 600;
        list-style: none;
        display: flex;
        align-items: center;
        gap: 2px;
        font-size: 0.65rem;
    }
    .chat-footer-dica summary::-webkit-details-marker {
        display: none;
    }
    .chat-footer-dica summary::after {
        content: "▼";
        font-size: 0.5rem;
        margin-left: 2px;
        transition: transform 0.2s;
    }
    .chat-footer-dica[open] summary::after {
        transform: rotate(-180deg);
    }
    .chat-footer-dica .dica-body {
        margin-top: 2px;
        padding-top: 2px;
        border-top: 1px solid rgba(0,0,0,0.06);
        font-size: 0.65rem;
    }
    .main-content {
        padding-bottom: 0 !important;
    }
    #file-preview {
        position: fixed;
        left: 0;
        bottom: 80px;
        width: 100vw;
        z-index: 101;
        border-radius: 0;
        margin-bottom: 0;
        padding: 8px 12px;
        box-shadow: 0 2px 12px rgba(0,0,0,0.08);
        background: #fff;
    }
    .chat-list {
        flex: 1 1 auto;
        min-height: 0;
        min-width: 0;
        max-height: 100vh;
        overflow-y: auto;
        overflow-x: hidden;
    }
}
@media (min-width: 992px) {
    .sidebar {
        display: flex;
        position: fixed;
        width: var(--sidebar-width);
        z-index: 1050;
        left: 0;
    }
    .main-content {
        left: var(--sidebar-width);
    }
    /* Botão voltar só no mobile */
    .chat-header-back {
        display: none !important;
    }
}

/* Scrollbar personalizada */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Animações */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-item {
    animation: fadeIn 0.3s ease;
}

.message {
    animation: fadeIn 0.3s ease;
}

.start-chat-hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #6c757d;
    font-size: 0.95em;
    opacity: 0.8;
    text-align: center;
    padding-top: 40px;
}

.btn-close {
    background: transparent;
    border: none;
    cursor: pointer;
    width: 32px;
    height: 32px;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: transform 0.2s ease, background 0.2s ease;
}

.btn-close::before,
.btn-close::after {
    content: "";
    position: absolute;
    width: 60%;
    height: 2px;
    background-color: #333;
    border-radius: 1px;
    transition: background 0.2s ease;
}

.btn-close::before {
    transform: rotate(45deg);
}

.btn-close::after {
    transform: rotate(-45deg);
}

.btn-close:hover {
    background: rgba(0,0,0,0.05);
    transform: scale(1.1);
}

.btn-close:hover::before,
.btn-close:hover::after {
    background-color: #000;
}

.profile-pic {
    border-radius: 8px; /* ou 12px para mais arredondado */
}

/* Modal Nova Conversa: lista de contatos com scroll e itens legíveis */
#new-chat-modal #contacts-list {
    max-height: 280px;
    min-height: 120px;
    overflow-y: auto;
    overflow-x: hidden;
}

#new-chat-modal #contacts-list .list-group-item.chat-item {
    display: flex;
    align-items: center;
    min-height: 52px;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
}

#new-chat-modal #contacts-list .list-group-item.chat-item .d-flex {
    min-width: 0;
    flex: 1;
    align-items: center;
    gap: 0.75rem;
}

#new-chat-modal #contacts-list .list-group-item.chat-item .profile-pic {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    flex-shrink: 0;
    object-fit: cover;
    border-radius: 8px;
}

#new-chat-modal #contacts-list .list-group-item.chat-item .d-flex > div {
    min-width: 0;
    overflow: hidden;
}

#new-chat-modal #contacts-list .list-group-item.chat-item .fw-bold {
    font-size: 0.875rem !important;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

#new-chat-modal #contacts-list .list-group-item.chat-item .text-muted.small {
    font-size: 0.75rem !important;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

/* Bot Status Indicators */
.bot-status-indicators {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 0.5rem;
}

.bot-status-indicators .badge {
    font-size: 0.65rem;
    padding: 4px 8px;
    border-radius: 8px;
    font-weight: 500;
    width: fit-content;
    line-height: 1.2;
    letter-spacing: 0.02em;
}

.bot-status-indicators .badge.bg-warning {
    background: linear-gradient(135deg, #ffc107 0%, #e0a800 100%) !important;
    color: #000;
}

.bot-status-indicators .badge.bg-success {
    background: linear-gradient(135deg, #25d366 0%, #128c7e 100%) !important;
    color: #fff;
}

.bot-status-indicators .badge.bg-secondary {
    background: #e8eaed !important;
    color: #5f6368;
}

.user-details .bot-status-indicators {
    margin-top: 8px;
}

.user-details .bot-status-indicators .badge {
    font-size: 0.62rem;
    padding: 3px 7px;
    border-radius: 6px;
}

@media (max-width: 480px) {
    .chat-messages {
        padding: 10px 8px 20px !important;
    }
    .chat-footer {
        padding: 5px 8px 16px 8px !important;
    }
}

/* Emoji picker (estilo WhatsApp) */
.emoji-picker-panel {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 6px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 10px;
    z-index: 1050;
    max-height: 280px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
}
.emoji-picker-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
}
.emoji-picker-grid button {
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: background 0.15s;
}
.emoji-picker-grid button:hover {
    background: #f0f2f5;
}
.emoji-picker-grid button:active {
    transform: scale(0.95);
}

/* ========== DARK MODE (nizap-dark-mode) ========== */
html.dark-mode {
    color-scheme: dark;
    --text-muted: #8696a0;
}

html.dark-mode body {
    background: #111b21;
    color: #e9edef;
}

html.dark-mode .chat-app-wrapper {
    background: #111b21;
    color: #e9edef;
}

html.dark-mode .sidebar {
    background: #111b21;
    border-right-color: #2a3942;
    color: #e9edef;
}

html.dark-mode .sidebar p,
html.dark-mode .sidebar span,
html.dark-mode .sidebar small,
html.dark-mode .sidebar label,
html.dark-mode .sidebar h1,
html.dark-mode .sidebar h2,
html.dark-mode .sidebar h3,
html.dark-mode .sidebar h4,
html.dark-mode .sidebar h5,
html.dark-mode .sidebar h6 {
    color: #e9edef !important;
}

html.dark-mode .sidebar .text-muted {
    color: #8696a0 !important;
}

html.dark-mode .sidebar-header {
    background: #202c33;
    border-color: #2a3942;
}

html.dark-mode .sidebar-header .btn {
    color: #e9edef;
    border-color: #3b4a54;
}

html.dark-mode .sidebar-header .btn:hover {
    background: #2a3942 !important;
    border-color: #3b4a54 !important;
    color: #e9edef !important;
}

/* Evitar hover branco em qualquer botão do chat no dark mode */
html.dark-mode .chat-app-wrapper .btn:hover {
    background: #3b4a54 !important;
    color: #e9edef !important;
    border-color: #4a5a64 !important;
}

html.dark-mode .chat-app-wrapper .btn-success:hover {
    background: #008f73 !important;
    color: #fff !important;
    border-color: #008f73 !important;
}

html.dark-mode .user-info {
    background: linear-gradient(135deg, #1a2332 0%, #151d29 100%);
    border-color: #2a3942;
}

html.dark-mode .user-avatar {
    background: linear-gradient(145deg, #00a884 0%, #008f73 100%);
    box-shadow: 0 4px 12px rgba(0, 168, 132, 0.3);
}

html.dark-mode .user-details h6 {
    color: #e9edef;
}

html.dark-mode .user-details small {
    color: #8696a0;
}

html.dark-mode .user-details .text-success,
html.dark-mode .user-details .text-success i {
    color: #25d366 !important;
}

html.dark-mode .user-details small:first-of-type::before {
    background: #00a884;
    box-shadow: 0 0 0 2px rgba(0, 168, 132, 0.3);
}

html.dark-mode .search-container {
    background: #111b21;
    border-color: #2a3942;
}

html.dark-mode .search-scope {
    background: #2a3942;
    border-color: #3b4a54;
    color: #e9edef;
}

html.dark-mode .search-input {
    background: #2a3942;
    color: #e9edef;
}

html.dark-mode .search-input::placeholder {
    color: #8696a0;
}

html.dark-mode .chat-list {
    background: #111b21;
}

html.dark-mode .chat-list-load-more-wrap {
    background: transparent;
    border: none;
}

html.dark-mode .chat-list-load-more {
    background: #202c33;
    color: #aebac1;
    border-color: #3b4a54;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

html.dark-mode .chat-list-load-more:hover:not(:disabled) {
    background: #2a3942;
    color: #00a884;
}

/* Aba Grupos: fundo e itens no dark mode (sobrescreve inline style do JS) */
html.dark-mode #group-list {
    background-color: #111b21 !important;
}
html.dark-mode #group-list .chat-item {
    background-color: #202c33 !important;
    border-color: #2a3942 !important;
    color: #e9edef;
}
html.dark-mode #group-list .chat-item .fw-bold {
    color: #e9edef !important;
}
html.dark-mode #group-list .chat-item .text-muted {
    color: #8696a0 !important;
}
html.dark-mode #group-list .chat-item:hover {
    background-color: #2a3942 !important;
}

html.dark-mode .chat-item {
    background: #202c33;
    border-color: #2a3942;
    color: #fff;
}

html.dark-mode .chat-item .chat-name,
html.dark-mode .chat-item .fw-bold {
    color: #fff !important;
}

html.dark-mode .chat-item .chat-preview,
html.dark-mode .chat-item .chat-time,
html.dark-mode .chat-item .text-muted,
html.dark-mode .chat-item small {
    color: #e9edef !important;
}

html.dark-mode .chat-item:hover,
html.dark-mode .chat-item.selected {
    background: #2a3942;
}

html.dark-mode .chat-item.selected .chat-name,
html.dark-mode .chat-item.selected .chat-preview,
html.dark-mode .chat-item.selected .chat-time,
html.dark-mode .chat-item.selected .text-muted,
html.dark-mode .chat-item.selected small {
    color: #fff !important;
}

html.dark-mode .chat-item .chat-avatar {
    background: #2a3942;
    color: #e9edef;
}

html.dark-mode .main-content {
    background: #111b21;
    color: #e9edef;
}

html.dark-mode .main-content p,
html.dark-mode .main-content span,
html.dark-mode .main-content small,
html.dark-mode .main-content label,
html.dark-mode .main-content h1,
html.dark-mode .main-content h2,
html.dark-mode .main-content h3,
html.dark-mode .main-content h4,
html.dark-mode .main-content h5,
html.dark-mode .main-content h6 {
    color: #e9edef !important;
}

html.dark-mode .chat-messages p,
html.dark-mode .chat-messages span,
html.dark-mode .chat-messages small,
html.dark-mode .chat-messages strong {
    color: #e9edef !important;
}

html.dark-mode .chat-messages .text-muted {
    color: #8696a0 !important;
}

html.dark-mode .chat-header {
    background: #202c33;
    border-color: #2a3942;
}

html.dark-mode .chat-header-back,
html.dark-mode .chat-header-details h6,
html.dark-mode .chat-header-details small {
    color: #e9edef;
}

html.dark-mode .chat-header-actions .btn {
    color: #e9edef;
    background: #2a3942;
    border-color: #3b4a54;
}

html.dark-mode .chat-header-actions .btn:hover {
    background: #3b4a54 !important;
    border-color: #4a5a64 !important;
    color: #fff !important;
}

/* Barra de pesquisa de mensagens (Buscar) no dark mode */
html.dark-mode .chat-search-container,
html.dark-mode .chat-search-bar {
    background: #202c33 !important;
    border-color: #2a3942 !important;
    color: #e9edef;
}
html.dark-mode .chat-search-bar .btn,
html.dark-mode .chat-search-bar .btn-link,
html.dark-mode .chat-search-bar .btn-outline-secondary {
    color: #e9edef !important;
    background: #2a3942 !important;
    border-color: #3b4a54 !important;
}
html.dark-mode .chat-search-bar .btn:hover:not(:disabled),
html.dark-mode .chat-search-bar .btn-link:hover,
html.dark-mode .chat-search-bar .btn-outline-secondary:hover:not(:disabled) {
    background: #3b4a54 !important;
    border-color: #4a5a64 !important;
    color: #fff !important;
}
html.dark-mode .chat-search-bar .btn:disabled {
    opacity: 0.5;
    color: #8696a0 !important;
}
html.dark-mode #chat-search-input {
    background: #2a3942 !important;
    border-color: #3b4a54 !important;
    color: #e9edef !important;
}
html.dark-mode #chat-search-input::placeholder {
    color: #8696a0 !important;
}
html.dark-mode #chat-search-counter {
    color: #8696a0 !important;
}

html.dark-mode .chat-messages {
    background: #111b21;
}

html.dark-mode .message-bubble {
    background: #202c33;
    color: #e9edef;
}

html.dark-mode .message.sent .message-bubble {
    background: #005c4b;
    color: #e9edef;
}

/* Mensagens recebidas: fundo claro e fonte preta no dark mode */
html.dark-mode .message.received .message-bubble {
    background: #e9edef !important;
    color: #000 !important;
}

html.dark-mode .message.received .message-bubble .message-content,
html.dark-mode .message.received .message-bubble .message-content span,
html.dark-mode .message.received .message-bubble .message-content p,
html.dark-mode .message.received .message-bubble .message-content div {
    color: #000 !important;
}

html.dark-mode .message.received .message-bubble .message-username,
html.dark-mode .message.received .message-bubble .message-time {
    color: #54656f !important;
}

html.dark-mode .message-username {
    color: #8696a0 !important;
}

html.dark-mode .message.sent .message-bubble .message-username,
html.dark-mode .message.sent .message-bubble .message-time {
    color: #8696a0 !important;
}

html.dark-mode .message.sent .message-meta i.message-status-failed {
    color: #f87171 !important;
}

html.dark-mode .message-content,
html.dark-mode .message-content span,
html.dark-mode .message-content p,
html.dark-mode .message-content div {
    color: #e9edef !important;
}

/* Excecao para bolhas recebidas claras no dark mode.
   As regras globais acima clareiam todos os spans da area principal. */
html.dark-mode #chat-messages .message.received .message-bubble,
html.dark-mode #chat-messages .message-bubble-received {
    background: #e9edef !important;
    color: #111b21 !important;
}

html.dark-mode #chat-messages .message.received .message-bubble .message-content,
html.dark-mode #chat-messages .message.received .message-bubble .message-content span,
html.dark-mode #chat-messages .message.received .message-bubble .message-content p,
html.dark-mode #chat-messages .message.received .message-bubble .message-content div,
html.dark-mode #chat-messages .message-bubble-received .message-content,
html.dark-mode #chat-messages .message-bubble-received .message-content span,
html.dark-mode #chat-messages .message-bubble-received .message-content p,
html.dark-mode #chat-messages .message-bubble-received .message-content div {
    color: #111b21 !important;
}

html.dark-mode #chat-messages .message.received .message-bubble .message-username,
html.dark-mode #chat-messages .message.received .message-bubble .message-time,
html.dark-mode #chat-messages .message-bubble-received .message-username,
html.dark-mode #chat-messages .message-bubble-received .message-time,
html.dark-mode #chat-messages .message-bubble-received .edited-indicator {
    color: #54656f !important;
}

html.dark-mode .message-content a {
    color: #00a884 !important;
}

html.dark-mode .message-date {
    color: #8696a0;
}

html.dark-mode .message-time {
    color: #8696a0;
}

html.dark-mode .chat-header-avatar {
    color: #e9edef !important;
    background: #2a3942 !important;
}

html.dark-mode .pdf-preview,
html.dark-mode .doc-preview,
html.dark-mode .excel-preview,
html.dark-mode .media-preview,
html.dark-mode .audio-message-container {
    background: rgba(255,255,255,0.06) !important;
    color: #e9edef !important;
}

html.dark-mode .file-preview {
    background: #2a3942 !important;
    border-color: #3b4a54 !important;
    color: #e9edef !important;
}

html.dark-mode .file-preview *,
html.dark-mode .file-preview-content {
    color: #e9edef !important;
}

html.dark-mode .chat-footer {
    background: #202c33;
    border-color: #2a3942;
}

html.dark-mode .chat-input-container {
    background: #2a3942;
    border-color: #3b4a54;
}

html.dark-mode .message-textarea {
    background: transparent !important;
    color: #e9edef !important;
}

html.dark-mode .message-textarea::placeholder {
    color: #8696a0;
}

html.dark-mode .chat-footer .chat-input-container .btn {
    color: #8696a0;
}

html.dark-mode .chat-footer .chat-input-container .btn:hover {
    background: #3b4a54 !important;
    color: #e9edef !important;
}

html.dark-mode .chat-input-container .input-group .btn-outline-secondary:hover {
    background: #3b4a54 !important;
    color: #e9edef !important;
}

html.dark-mode .chat-footer .chat-input-container .btn-success {
    color: #fff !important;
    background: #00a884 !important;
}

html.dark-mode .chat-footer .chat-input-container .btn-success:hover {
    color: #fff !important;
    background: #008f73 !important;
}

html.dark-mode .chat-footer-dica {
    background: #2a3942 !important;
    color: #8696a0 !important;
}

html.dark-mode .chat-footer-hint {
    color: #8696a0 !important;
}

html.dark-mode #sidebar-tabs {
    border-color: #3b4a54;
}

html.dark-mode #sidebar-tabs .nav-link {
    background: #2a3942;
    border-color: #3b4a54;
    color: #8696a0;
}

html.dark-mode #sidebar-tabs .nav-link:hover {
    background: #3b4a54;
    color: #00a884;
}

html.dark-mode #sidebar-tabs .nav-link.active {
    background: #00a884 !important;
    color: #fff !important;
}

html.dark-mode .start-chat-hint {
    color: #8696a0;
}

/* SweetAlert2 (Finalizar conversa, Agendar, etc.) no dark mode */
html.dark-mode .swal2-container {
    background: rgba(0,0,0,0.6) !important;
}
html.dark-mode .swal2-popup {
    background: #202c33 !important;
    color: #e9edef !important;
    border: 1px solid #2a3942;
}
html.dark-mode .swal2-title {
    color: #e9edef !important;
}
html.dark-mode .swal2-html-container {
    color: #e9edef !important;
}
html.dark-mode .swal2-popup p,
html.dark-mode .swal2-popup span,
html.dark-mode .swal2-popup div,
html.dark-mode .swal2-popup label {
    color: #e9edef !important;
}
html.dark-mode .swal2-popup .form-control,
html.dark-mode .swal2-popup .form-select,
html.dark-mode .swal2-popup input[type="text"],
html.dark-mode .swal2-popup input[type="email"],
html.dark-mode .swal2-popup input[type="number"],
html.dark-mode .swal2-popup textarea {
    background: #2a3942 !important;
    border-color: #3b4a54 !important;
    color: #e9edef !important;
}
html.dark-mode .swal2-popup input::placeholder {
    color: #8696a0 !important;
}
html.dark-mode .swal2-styled.swal2-confirm {
    background: #00a884 !important;
    color: #fff !important;
}
html.dark-mode .swal2-styled.swal2-cancel {
    background: #2a3942 !important;
    color: #e9edef !important;
    border-color: #3b4a54 !important;
}
html.dark-mode .swal2-styled.swal2-deny {
    background: #3b4a54 !important;
    color: #e9edef !important;
}
html.dark-mode .swal2-icon.swal2-warning,
html.dark-mode .swal2-icon.swal2-error,
html.dark-mode .swal2-icon.swal2-success {
    border-color: rgba(255,255,255,0.2) !important;
}
html.dark-mode .swal2-icon .swal2-icon-content {
    color: inherit !important;
}

/* Modais: fontes 9px em todas as resoluções desktop */
@media (min-width: 992px) {
    .modal .modal-content {
        font-size: 9px !important;
    }
    .modal .modal-title,
    .modal h5.modal-title,
    .modal h4, .modal h6 {
        font-size: 9px !important;
    }
    .modal .modal-body,
    .modal .modal-body *,
    .modal-body {
        font-size: 9px !important;
    }
    .modal .form-label,
    .modal label,
    .modal small,
    .modal .text-muted {
        font-size: 9px !important;
    }
    .modal .form-control,
    .modal .form-select,
    .modal .input-group-text,
    .modal input,
    .modal select {
        font-size: 9px !important;
        padding: 0.35rem 0.5rem !important;
    }
    .modal .btn {
        font-size: 9px !important;
        padding: 0.35rem 0.65rem !important;
    }
    .modal .modal-header,
    .modal .modal-header * {
        font-size: 9px !important;
    }
    .modal .modal-header {
        padding: 0.5rem 0.75rem !important;
    }
    .modal .modal-footer,
    .modal .modal-footer * {
        font-size: 9px !important;
    }
    .modal .modal-footer {
        padding: 0.5rem 0.75rem !important;
    }
    #new-chat-modal #contacts-list .list-group-item.chat-item .fw-bold,
    #new-chat-modal #contacts-list .list-group-item.chat-item .text-muted.small,
    #new-chat-modal #contacts-list .list-group-item.chat-item,
    #new-chat-modal .modal-body * {
        font-size: 9px !important;
    }
    #new-chat-modal #contacts-list .list-group-item.chat-item {
        padding: 0.35rem 0.5rem !important;
    }
    #new-chat-modal .new-number-section .form-control,
    #new-chat-modal .new-number-section .btn {
        font-size: 9px !important;
    }
    #add-contact-modal .modal-body *,
    #add-contact-modal .form-label,
    #add-contact-modal .form-control {
        font-size: 9px !important;
    }
    #transferModal .modal-body *,
    #transferModal .form-label,
    #transferModal .form-select,
    #customTransferSelectDropdown,
    #customTransferSelectDropdown .dropdown-item {
        font-size: 9px !important;
    }
    #customTransferSelectDropdown .dropdown-item {
        padding: 0.35rem 0.5rem !important;
    }
    /* SweetAlert2 (Swal.fire): 9px em desktop */
    .swal2-popup {
        font-size: 9px !important;
        padding: 0.5rem 0.75rem !important;
    }
    .swal2-title {
        font-size: 9px !important;
    }
    .swal2-html-container,
    .swal2-html-container * {
        font-size: 9px !important;
    }
    .swal2-popup .form-label,
    .swal2-popup label,
    .swal2-popup .form-control,
    .swal2-popup input[type="text"],
    .swal2-popup input {
        font-size: 9px !important;
        padding: 0.35rem 0.5rem !important;
    }
    .swal2-styled {
        font-size: 9px !important;
        padding: 0.35rem 0.65rem !important;
    }
    .swal2-actions .swal2-confirm,
    .swal2-actions .swal2-cancel {
        font-size: 9px !important;
    }
}

html.dark-mode .modal-content {
    background: #202c33;
    border-color: #2a3942;
}

html.dark-mode .modal-header {
    border-color: #2a3942;
    color: #e9edef;
}

html.dark-mode .modal-body {
    background: #202c33;
    color: #e9edef;
}

html.dark-mode .modal .text-muted,
html.dark-mode .modal small.text-muted {
    color: #8696a0 !important;
}

.ticket-contact-panel {
    background: #f8f9fa;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
}

html.dark-mode .ticket-contact-panel {
    background: #202c33 !important;
    border-color: #2a3942 !important;
}

html.dark-mode .ticket-contact-panel .card-body {
    background: transparent !important;
}

html.dark-mode .btn-close {
    filter: invert(1);
}

html.dark-mode .btn-close:hover {
    background: rgba(255,255,255,0.15) !important;
}

html.dark-mode .btn-mic:hover {
    background: #3b4a54 !important;
    color: #e9edef !important;
}

html.dark-mode .dark-mode-toggle {
    background: #2a3942;
    color: #8696a0;
    border: 1px solid #3b4a54;
}

html.dark-mode .dark-mode-toggle:hover {
    background: #3b4a54;
    color: #00a884;
}

/* Garantir todo texto em branco/claro no chat (dark mode) */
html.dark-mode .chat-list .text-muted,
html.dark-mode .chat-list small {
    color: #8696a0 !important;
}

html.dark-mode .badge:not(.bg-success):not(.bg-primary):not(.bg-danger) {
    background: #2a3942 !important;
    color: #e9edef !important;
}

html.dark-mode .dropdown-menu {
    background: #202c33 !important;
    border-color: #2a3942 !important;
}

html.dark-mode .dropdown-item {
    color: #e9edef !important;
}

html.dark-mode .dropdown-item:hover {
    background: #2a3942 !important;
    color: #fff !important;
}

html.dark-mode .form-control,
html.dark-mode .form-select {
    background: #2a3942 !important;
    border-color: #3b4a54 !important;
    color: #e9edef !important;
}

html.dark-mode .form-control::placeholder {
    color: #8696a0 !important;
}

html.dark-mode .form-label {
    color: #e9edef !important;
}

/* Flatpickr: tema dark quando html.dark-mode */
html.dark-mode .flatpickr-calendar {
    background: #202c33 !important;
    border-color: #2a3942 !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4) !important;
}
html.dark-mode .flatpickr-calendar.arrowTop::before,
html.dark-mode .flatpickr-calendar.arrowTop::after {
    border-bottom-color: #202c33 !important;
}
html.dark-mode .flatpickr-months {
    background: #2a3942 !important;
}
html.dark-mode .flatpickr-month {
    background: transparent !important;
    color: #e9edef !important;
}
html.dark-mode .flatpickr-prev-month svg,
html.dark-mode .flatpickr-next-month svg {
    fill: #e9edef !important;
}
html.dark-mode .flatpickr-prev-month:hover svg,
html.dark-mode .flatpickr-next-month:hover svg {
    fill: #fff !important;
}
html.dark-mode .flatpickr-monthDropdown-months {
    background: #2a3942 !important;
    border-color: #3b4a54 !important;
    color: #e9edef !important;
}
html.dark-mode .flatpickr-current-month .numInputWrapper {
    background: transparent !important;
}
html.dark-mode .flatpickr-current-month .numInputWrapper input.cur-year {
    background: #2a3942 !important;
    border-color: #3b4a54 !important;
    color: #e9edef !important;
}
html.dark-mode .flatpickr-weekday {
    color: #8696a0 !important;
}
html.dark-mode .flatpickr-innerContainer {
    background: #202c33 !important;
    border-color: #2a3942 !important;
}
html.dark-mode .flatpickr-day {
    color: #e9edef !important;
    border-color: transparent !important;
}
html.dark-mode .flatpickr-day:hover {
    background: #2a3942 !important;
    border-color: #2a3942 !important;
    color: #e9edef !important;
}
html.dark-mode .flatpickr-day.today {
    border-color: #25d366 !important;
    color: #25d366 !important;
}
html.dark-mode .flatpickr-day.today:hover {
    background: #2a3942 !important;
    color: #e9edef !important;
}
html.dark-mode .flatpickr-day.selected {
    background: #25d366 !important;
    border-color: #25d366 !important;
    color: #111 !important;
}
html.dark-mode .flatpickr-day.selected:hover {
    background: #34e077 !important;
    border-color: #34e077 !important;
    color: #111 !important;
}
html.dark-mode .flatpickr-day.flatpickr-disabled {
    color: #5c6b75 !important;
}
html.dark-mode .flatpickr-day.nextMonthDay {
    color: #5c6b75 !important;
}
html.dark-mode .flatpickr-day.nextMonthDay:hover {
    color: #e9edef !important;
}
