/* Reset & Base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

body {
    background-color: #d1d7db;
    height: 100vh;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* Login Screen */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #00a884;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    text-align: center;
    width: 350px;
}

.login-box h2 {
    color: #00a884;
    margin-bottom: 20px;
}

.login-box input {
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    border: 1px solid #ddd;
    border-radius: 5px;
    outline: none;
}

.login-box button {
    width: 100%;
    padding: 12px;
    background-color: #008069;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    margin-top: 10px;
    transition: background 0.2s;
}

.login-box button:hover {
    background-color: #006b58;
}

.error-msg {
    color: red;
    font-size: 0.9em;
    margin-top: 10px;
}

/* Health Status (Login) */
.health-container-login {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #f0f0f0;
    text-align: left;
    font-size: 0.85em;
    color: #555;
    animation: fadeIn 0.5s ease-in-out;
}

.health-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    line-height: 1.3;
}

.health-item strong {
    font-weight: 500;
    color: #333;
}

.health-subitem {
    margin-left: 10px;
    padding-left: 8px;
    border-left: 2px solid #e0e0e0;
    font-size: 0.9em;
    color: #777;
    margin-bottom: 4px;
}

.status-indicator {
    font-size: 0.9em;
    margin-left: 5px;
}

.health-subitem div {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2px;
}

/* App Container (WhatsApp Web Layout) */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    background-color: #f0f2f5;
    max-width: 1600px;
    margin: 0 auto;
    box-shadow: 0 0 20px rgba(0,0,0,0.05);
}

/* Sidebar */
.sidebar {
    width: 400px; /* Largura fixa típica */
    background: white;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e9edef;
}

.sidebar-header {
    height: 60px;
    background: #f0f2f5;
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #d1d7db;
}

/* Tabs & Filters */
.tabs-header {
    display: flex;
    background: #fff;
    border-bottom: 1px solid #e9edef;
}

.tab-btn {
    flex: 1;
    padding: 12px;
    background: none;
    border: none;
    cursor: pointer;
    font-weight: bold;
    color: #54656f;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    background-color: #f5f6f6;
}

.tab-btn.active {
    color: #00a884;
    border-bottom: 3px solid #00a884;
}

.help-icon {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 0.9em;
    color: #999;
    cursor: pointer;
    transition: color 0.2s;
    z-index: 10;
}

.help-icon:hover {
    color: #00a884;
}

.filters-bar {
    padding: 8px 12px;
    background: #fff;
    /* Adaptação para permitir que filtros se acumulem em múltiplas linhas */
    overflow-x: visible; /* Remove scroll horizontal */
    white-space: normal; /* Permite quebra de linha */
    height: auto; /* Permite crescimento vertical */
    border-bottom: 1px solid #f0f2f5;
}

.filters-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap; /* Permite que os chips quebrem para próxima linha */
}

.filter-chip {
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid #e9edef;
    background: #f0f2f5;
    color: #54656f;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-chip:hover {
    background: #e9edef;
}

.filter-chip.active {
    background: #e7fce3;
    color: #008069;
    border-color: #00a884;
}

.badge {
    background: #25d366;
    color: white;
    font-size: 0.75em;
    padding: 1px 5px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.header-actions button {
    background: none;
    border: none;
    font-size: 1.2em;
    color: #54656f;
    cursor: pointer;
    margin-left: 15px;
}

.search-bar {
    padding: 8px 12px;
    background: white;
    border-bottom: 1px solid #f0f2f5;
}

.search-input-wrapper {
    background: #f0f2f5;
    border-radius: 8px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
}

.search-input-wrapper i {
    color: #54656f;
    margin-right: 10px;
}

.search-input-wrapper input {
    border: none;
    background: transparent;
    width: 100%;
    outline: none;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    padding: 12px 16px;
    display: flex;
    cursor: pointer;
    border-bottom: 1px solid #f0f2f5;
    transition: background 0.2s;
}

.chat-item:hover {
    background-color: #f5f6f6;
}

.chat-item.active {
    background-color: #f0f2f5;
}

/* Indicador de Atendimento Humano */
.chat-item.human {
    background-color: #e3f2fd; /* Azul muito claro */
    border-left: 4px solid #2196f3;
}

/* Indicador de Bot com Pendência (Solicitação) */
.chat-item.pending {
    background-color: #fff9c4; /* Amarelo muito claro */
    border-left: 4px solid #ffeb3b;
}



/* Container do Avatar na lista (ajuste de margem) */
.chat-item-avatar {
    margin-right: 15px;
    background: none; /* Remove cor de fundo antiga se houver */
    width: auto;      /* Remove largura fixa do container */
    height: auto;     /* Remove altura fixa do container */
}

/* O Avatar em si (Círculo colorido) */
/* --- AVATAR DO USUÁRIO --- */
.user-avatar {
    width: 49px;
    height: 49px;
    border-radius: 50%;
    background-color: #dfe3e5; /* Cor default */
    color: white;
    font-size: 1.1em;
    font-weight: 500;
    display: flex;
    justify-content: center;
    align-items: center;
    text-transform: uppercase;
    transition: background-color 0.3s ease;
}

.user-avatar.default {
    background-color: #dfe3e5;
    color: #667781;
}

/* Cores de Status */
.user-avatar.status-pending {
    background-color: #ff9800; /* Laranja (Pendente/Aguardando) */
    color: white;
}

.user-avatar.status-mine {
    background-color: #25d366; /* Verde (Meu Atendimento) */
    color: white;
}

.user-avatar.status-mine-closed {
    background-color: #1b5e20; /* Verde Escuro (Meu Encerrado) */
    color: white;
}

.user-avatar.status-active {
    background-color: #2196f3; /* Azul (Em Atendimento por Outros) */
    color: white;
}

.user-avatar.status-bot {
    background-color: #673ab7; /* Roxo (Bot) */
    color: white;
}

.user-avatar.status-closed-human {
    background-color: #455a64; /* Cinza Escuro (Encerrado Humano) */
    color: white;
}

.user-avatar.status-closed-bot {
    background-color: #b0bec5; /* Cinza Claro (Encerrado Bot) */
    color: #37474f;
}

/* Ajuste no container da lista */
.chat-item-avatar {
    margin-right: 15px;
    width: auto;
    height: auto;
    background: none;
}


.chat-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.chat-item-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.contact-name {
    font-size: 1.1em;
    color: #111b21;
}

.last-msg-time {
    font-size: 0.8em;
    color: #667781;
}

.chat-item-bottom {
    display: flex;
    justify-content: space-between;
}

.last-message {
    font-size: 0.9em;
    color: #667781;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.pending-badge {
    background-color: #25d366;
    color: white;
    font-size: 0.75em;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: bold;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png'); /* Background padrão WhatsApp Web */
    background-repeat: repeat;
    background-color: #efeae2;
}

.chat-header {
    height: 60px;
    background: #f0f2f5;
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #d1d7db;
}

.chat-info {
    display: flex;
    align-items: center;
}

.chat-text-details {
    display: flex;
    flex-direction: column;
    margin-left: 10px;
}

.chat-info h3 {
    font-size: 1em;
    color: #111b21;
}

.chat-info span {
    font-size: 0.8em;
    color: #667781;
}

/* Indicador Janela 24h */
.window-open {
    border: 2px solid #25d366 !important;
    color: #25d366 !important;
    background-color: #fff !important;
}

.window-closed {
    border: 2px solid #f44336 !important;
    color: #f44336 !important;
    background-color: #fff !important;
}

.chat-actions button {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    margin-left: 10px;
}

.action-btn.secondary {
    background-color: #e9edef;
    color: #111b21;
}

.action-btn.danger {
    background-color: #aebac1; /* Cor desabilitada/suave */
    color: white;
}
.action-btn.danger:hover {
    background-color: #d32f2f;
}

.action-btn.warning {
    background-color: #ff9800; /* Laranja */
    color: white;
}
.action-btn.warning:hover {
    background-color: #f57c00;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 50px;
    display: flex;
    flex-direction: column;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #667781;
}

.empty-state i {
    font-size: 4em;
    margin-bottom: 20px;
    color: #d1d7db;
}

/* Date Divider */
.date-divider {
    align-self: center;
    background-color: #fff;
    color: #54656f;
    padding: 5px 12px;
    border-radius: 8px;
    font-size: 0.8em;
    margin: 10px 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    text-transform: uppercase;
    font-weight: 500;
}

.message-bubble {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 7.5px;
    margin-bottom: 10px;
    position: relative;
    font-size: 0.95em;
    line-height: 1.4;
    box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
}

.message-bubble.incoming {
    align-self: flex-start;
    background-color: white;
    border-top-left-radius: 0;
}

.message-bubble.outgoing {
    align-self: flex-end;
    background-color: #d9fdd3;
    border-top-right-radius: 0;
}

.msg-meta {
    display: flex;
    justify-content: flex-end;
    font-size: 0.7em;
    color: #667781;
    margin-top: 4px;
}

.msg-meta i {
    margin-left: 4px;
    font-size: 1em;
}

.status-icon {
    margin-left: 4px;
    font-size: 1.1em;
}

.status-sent {
    color: #8696a0; /* Cinza (um check) */
}

.status-delivered {
    color: #8696a0; /* Cinza (dois checks) */
}

.status-read {
    color: #53bdeb; /* Azul (dois checks) */
}

.status-failed {
    color: #f15c6d; /* Vermelho (exclamação) */
}

code {
    font-family: Consolas, "Courier New", monospace;
    background-color: rgba(0, 0, 0, 0.05);
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 0.9em;
}

.chat-input-area {
    height: 62px;
    background: #f0f2f5;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    border-top: 1px solid #d1d7db;
}

.chat-input-area input {
    flex: 1;
    padding: 12px;
    border-radius: 8px;
    border: none;
    margin: 0 10px;
    outline: none;
}

.attach-btn, .send-btn {
    background: none;
    border: none;
    font-size: 1.5em;
    color: #54656f;
    cursor: pointer;
}

.send-btn {
    color: #00a884;
}

/* Ícone de Verificado */
.verified-icon {
    color: #1da1f2; /* Azul estilo check */
    margin-left: 5px;
    font-size: 0.9em;
}

/* Time Badge in Filter Buttons */
.time-badge {
    font-size: 0.85em;
    margin-right: 6px;
    color: #54656f;
    font-weight: 500;
}

/* --- Avatar com Foto (Override) --- */
.user-avatar.has-photo {
    background-color: transparent !important;
    border: 2px solid transparent;
    padding: 0;
}

/* Imagem dentro do avatar */
.user-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: none; /* Oculto por padrão até carregar */
}

.user-avatar.has-photo img {
    display: block;
}

.user-avatar.has-photo .initials {
    display: none;
}

/* Cores da Borda para Avatar com Foto */
.user-avatar.status-pending.has-photo { border-color: #ff9800; }
.user-avatar.status-mine.has-photo { border-color: #25d366; }
.user-avatar.status-mine-closed.has-photo { border-color: #1b5e20; }
.user-avatar.status-active.has-photo { border-color: #2196f3; }
.user-avatar.status-bot.has-photo { border-color: #673ab7; }
.user-avatar.status-closed-human.has-photo { border-color: #455a64; }
.user-avatar.status-closed-bot.has-photo { border-color: #b0bec5; }

/* Time of Previous Message */
.msg-last-time {
    font-size: 0.7em;
    color: #999;
    text-align: right;
    line-height: 1;
    margin-top: 2px;
}

/* Chat List Item Meta (Date & Time) */
.chat-item-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.last-msg-date {
    font-size: 0.8em;
    color: #667781;
}

.last-msg-time {
    font-size: 0.7em;
    color: #8696a0;
    margin-top: 2px;
}

/* --- Modal Histórico de Status --- */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal.hidden {
    display: none !important;
}

.modal-content {
    background-color: white;
    padding: 0;
    border-radius: 8px;
    width: 400px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    background-color: #00a884;
    color: white;
    padding: 15px;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1em;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5em;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
    max-height: 400px;
    overflow-y: auto;
}

/* Timeline Styles */
.status-timeline {
    list-style: none;
    padding: 0;
    margin: 0;
}

.status-timeline li {
    display: flex;
    align-items: flex-start;
    margin-bottom: 20px;
    position: relative;
}

/* Linha vertical conectando os pontos */
.status-timeline li:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 9px; /* Ajuste fino */
    top: 25px;
    bottom: -20px;
    width: 2px;
    background-color: #e9edef;
}

.timeline-icon {
    font-size: 1.2em;
    margin-right: 15px;
    z-index: 1;
    background: white; /* Para cobrir a linha */
}

.timeline-content {
    display: flex;
    flex-direction: column;
}

.timeline-content strong {
    color: #111b21;
    font-size: 0.95em;
}

.timeline-content span {
    color: #667781;
    font-size: 0.85em;
}

/* Right Sidebar (History Panel) */
.right-sidebar {
    width: 350px;
    background: white;
    border-left: 1px solid #d1d7db;
    display: flex;
    flex-direction: column;
    height: 100vh;
    transition: width 0.3s ease;
}

.right-sidebar.hidden {
    width: 0 !important;
    display: none !important;
    /* Force hide to prevent layout shift if width transition fails or layout engine needs it */
}

.right-sidebar-header {
    height: 60px;
    background: #f0f2f5;
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #d1d7db;
}

.right-sidebar-header h3 {
    font-size: 1em;
    color: #54656f;
    margin: 0;
}

.close-btn-black {
    background: none;
    border: none;
    color: #54656f;
    font-size: 1.2em;
    cursor: pointer;
}

.right-sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background-color: #fff;
}

/* Patient Info Card */
.patient-card {
    background: #f0f2f5;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.patient-info-row {
    margin-bottom: 8px;
    font-size: 0.9em;
    color: #111b21;
}

.patient-info-row strong {
    color: #54656f;
}

/* History List */
.history-item {
    border-bottom: 1px solid #e9edef;
    padding: 12px 0;
}

.history-item:last-child {
    border-bottom: none;
}

.history-date {
    font-size: 0.85em;
    color: #667781;
    margin-bottom: 4px;
}

.history-title {
    font-weight: 600;
    color: #111b21;
    font-size: 0.95em;
    margin-bottom: 4px;
}

.history-details {
    font-size: 0.85em;
    color: #3b4a54;
    line-height: 1.4;
}

.history-status {
    display: inline-block;
    padding: 0;
    border-radius: 4px;
    font-size: 0.75em;
    background-color: transparent;
    color: #54656f;
    margin-top: 5px;
}

/* Etiquetas */
.msg-footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: 4px;
}

.msg-tag {
    background-color: #ffeb3b;
    color: #444;
    font-size: 0.7em;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
}

.msg-tag-add {
    color: #54656f;
    font-size: 0.85em;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.msg-tag-add:hover {
    opacity: 1;
    color: #00a884;
}

/* Toast Notification */
.toast-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background-color: #00a884;
    color: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease-out;
    max-width: 300px;
    font-size: 0.9em;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Unread Badge */
.unread-badge {
    background-color: #25d366;
    color: white;
    font-size: 0.75em;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: bold;
    min-width: 20px;
    text-align: center;
}

/* Negative Sentiment Alert */
.chat-item.negative-sentiment {
    background-color: rgba(255, 0, 0, 0.08) !important;
    border-left: 4px solid #d32f2f !important;
}

.chat-item.negative-sentiment:hover {
    background-color: rgba(255, 0, 0, 0.12) !important;
}

.chat-item.negative-sentiment.active {
    background-color: rgba(255, 0, 0, 0.15) !important; /* Slightly darker when active */
}

/* Highlight Negative Sentiment Message Bubble */
.message-bubble.bubble-negative {
    background-color: #ffebee !important; /* Light Red */
    border-left: 4px solid #d32f2f !important;
}

/* Ensure incoming messages also show the red if negative, overriding white default */
.message-bubble.incoming.bubble-negative {
    background-color: #ffebee !important;
}

/* Quick Reply Popup */
.quick-reply-popup {
    position: absolute;
    bottom: 70px; /* Above the input area */
    left: 60px; /* Aligned with buttons */
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    width: 300px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.quick-reply-item {
    padding: 10px 15px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.2s;
}

.quick-reply-item:hover {
    background-color: #f5f5f5;
}

.quick-reply-item:last-child {
    border-bottom: none;
}

.quick-reply-title {
    font-weight: bold;
    font-size: 0.9em;
    color: #333;
    margin-bottom: 2px;
}

.quick-reply-text {
    font-size: 0.85em;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
