:root {
    /* Design System Planet Smart City (planetsmartcity.com.br) */
    --planet-dark:       #18214D; /* texto principal, títulos */
    --planet-light:      #3E4462; /* texto de apoio */
    --planet-muted:      #6D7288; /* texto secundário, legendas */
    --planet-primary:    #309BDA; /* azul: ações principais, links, ativo */
    --planet-primary-hover: #2787C2;
    --planet-secondary:  #EAAF3E; /* amarelo: destaque, alerta */
    --planet-tertiary:   #DF4853; /* vermelho: erro, exclusão */
    --planet-quaternary: #7EC152; /* verde: sucesso */
    --planet-success-text: #4F8A2C; /* verde legível sobre fundo claro */

    --planet-white:      #FFFFFF;
    --planet-grey:       #F5F5F7; /* fundo da aplicação */
    --planet-grey-2:     #EBEBEC;
    --planet-grey-3:     #F7F7F6;
    --planet-input:      #EFF2F6; /* fundo de campos */
    --planet-border:     #DFE4EA;

    --planet-radius-sm:  8px;  /* botões, campos */
    --planet-radius-md:  14px; /* cards */
    --planet-radius-lg:  24px; /* painéis grandes */
    --planet-shadow:     3px 3px 7px rgba(62, 68, 98, 0.12);
    --planet-font:       'Noto Sans', sans-serif;

    /* Tema do Chat */
    --bg-app: var(--planet-grey);
    --bg-sidebar: var(--planet-white);
    --bg-chat: transparent;
    --bg-sidebar-header: var(--planet-white);
    --bg-item-active: #E8F3FB;
    --bg-item-hover: var(--planet-grey);
    --border-sidebar: var(--planet-border);
    --text-primary: var(--planet-dark);
    --text-secondary: var(--planet-muted);

    --whatsapp-accent: var(--planet-primary);
    --bubble-user: var(--planet-white);
    --bubble-bot: #E8F3FB; /* azul Planet bem claro */
    --chat-shadow: var(--planet-shadow);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Noto Sans', sans-serif;
}

body {
    background: var(--bg-app);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-container {
    display: flex;
    width: 100%;
    max-width: 1400px;
    height: calc(100vh - 40px);
    border: 1px solid var(--planet-border);
    border-radius: var(--planet-radius-lg);
    box-shadow: var(--planet-shadow);
    background: var(--planet-white);
    overflow: hidden;
}

/* Sidebar Styling */
.sidebar {
    width: 350px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-sidebar);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    background-color: var(--bg-sidebar-header);
    padding: 20px;
}

.sidebar-header h1 {
    font-size: 1.2rem;
    color: var(--text-primary);
    margin-bottom: 10px;
    font-weight: 700;
}

.search-box input {
    width: 100%;
    padding: 12px 15px;
    background-color: var(--planet-input);
    border: 1px solid transparent;
    border-radius: var(--planet-radius-sm);
    color: var(--text-primary);
    outline: none;
    font-size: 0.9rem;
}

.search-box input::placeholder {
    color: var(--text-secondary);
}

.client-list {
    flex: 1;
    overflow-y: auto;
}

.client-item {
    padding: 15px 20px;
    border-bottom: 1px solid var(--planet-border);
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.client-item:hover {
    background-color: var(--bg-item-hover);
}

.client-item.active {
    background-color: var(--bg-item-active);
}

.client-avatar-small {
    width: 45px;
    height: 45px;
    background: var(--planet-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
    box-shadow: 0 4px 10px rgba(48, 155, 218, 0.3);
}

.client-item-info h3 {
    font-size: 1rem;
    font-weight: 600;
}

.client-item-info p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Chat Area Styling */
.chat-area {
    flex: 1;
    background-color: transparent;
    display: flex;
    flex-direction: column;
    position: relative;
}

.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background-color: transparent;
    z-index: 10;
}

.welcome-content {
    background: var(--planet-white);
    padding: 60px 40px;
    border-radius: var(--planet-radius-lg);
    border: 1px solid var(--planet-border);
    box-shadow: var(--chat-shadow);
}

.welcome-icon {
    font-size: 5rem;
    margin-bottom: 20px;
}

.chat-header {
    background-color: var(--bg-sidebar-header);
    padding: 10px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-left: 1px solid var(--border-sidebar);
    z-index: 20;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-tag {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: 600;
}

.status-tag.ia-atendendo {
    background-color: rgba(126, 193, 82, 0.2);
    color: #4F8A2C;
    border: 1px solid #7EC152;
}

.status-tag.ia-pausada {
    background-color: rgba(234, 175, 62, 0.2);
    color: #8F6512;
    border: 1px solid #EAAF3E;
}

.status-tag.agendado {
    background-color: rgba(48, 155, 218, 0.2);
    color: #1F74A8;
    border: 1px solid #309BDA;
}

.status-tag.cv-tag {
    background-color: rgba(48, 155, 218, 0.1);
    color: #1F74A8;
    border: 1px solid rgba(48, 155, 218, 0.3);
}

.unpause-btn {
    background: transparent;
    color: #8F6512;
    border: 1px solid #EAAF3E;
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.unpause-btn:hover {
    background: #EAAF3E;
    color: black;
}

.download-btn {
    background: var(--whatsapp-accent);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.download-btn:hover {
    background: #7EC152;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.download-btn:active {
    transform: translateY(0);
}

.client-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.client-avatar {
    width: 40px;
    height: 40px;
    background-color: #309BDA;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.client-details h2 {
    font-size: 1rem;
    font-weight: 500;
}

.client-details span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.chat-history {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background-color: rgba(255, 255, 255, 0.45);
}
    
    /* Date Divider */
    .date-divider {
        text-align: center;
        margin: 10px 0;
        width: 100%;
        display: flex;
        justify-content: center;
    }
    
    .date-divider span {
        background-color: var(--bg-sidebar); /* Matches whatsapp standard visually */
        color: var(--text-secondary);
        padding: 6px 14px;
        border-radius: 8px;
        font-size: 0.75rem;
        font-weight: 500;
        box-shadow: var(--chat-shadow);
    }
    
    /* Bubbles */
.message-bubble {
    max-width: 65%;
    padding: 10px 12px;
    border-radius: 10px;
    position: relative;
    font-size: 0.95rem;
    line-height: 1.4;
    box-shadow: var(--chat-shadow);
}

.message-bubble.user {
    align-self: flex-start;
    background-color: var(--bubble-bot);
    border-top-left-radius: 0;
}

.message-bubble.bot {
    align-self: flex-end;
    background-color: var(--bubble-user);
    border-top-right-radius: 0;
}

.message-meta {
    display: flex;
    justify-content: flex-end;
    margin-top: 5px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.message-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
}

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

::-webkit-scrollbar-thumb {
    background-color: rgba(255,255,255,0.1);
}

/* Loader */
.loader-container {
    display: flex;
    justify-content: center;
    margin-top: 30px;
}

.loader {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(126, 193, 82, 0.2);
    border-top: 3px solid var(--whatsapp-accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Chat Input Area Styling */
.chat-input-area {
    background-color: var(--bg-sidebar-header);
    padding: 15px 20px;
    border-top: 1px solid var(--border-sidebar);
}

.input-container {
    display: flex;
    align-items: center;
    gap: 12px;
    background-color: transparent;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--planet-primary);
    padding: 8px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    background-color: rgba(48, 155, 218, 0.1);
}

.message-input-wrapper {
    flex: 1;
    background-color: var(--planet-input);
    border: 1px solid transparent;
    border-radius: var(--planet-radius-sm);
    padding: 0 16px;
}

#messageInput {
    width: 100%;
    padding: 12px 0;
    background: transparent;
    border: none;
    color: var(--text-primary);
    outline: none;
    font-size: 0.95rem;
}

.send-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s;
}

.send-btn:hover {
    color: var(--whatsapp-accent);
}

.send-btn.active {
    color: var(--whatsapp-accent);
}

/* Animations and Polishing */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-bubble {
    animation: fadeIn 0.3s ease-out;
}

.client-item {
    transition: all 0.2s ease;
}

.client-item:active {
    background-color: var(--bg-item-active);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spin {
    animation: spin 2s linear infinite;
    display: inline-block;
}

/* Context Menu */
.context-menu {
    position: absolute;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    z-index: 1000;
    overflow: hidden;
}

.context-menu-item {
    padding: 12px 20px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.context-menu-item:hover {
    background: rgba(48, 155, 218, 0.1);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.9);
    width: 600px;
    max-width: 90%;
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid var(--border-sidebar);
}

.modal-header h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.2rem;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: 0.2s;
}

.close-btn:hover {
    color: #B8323D;
}

.modal-body {
    padding: 25px;
    overflow-y: auto;
    max-height: 60vh;
}

.preview-box {
    padding: 12px;
    border-radius: 8px;
    margin-top: 8px;
    font-size: 0.95rem;
    line-height: 1.4;
}

.client-box {
    background: rgba(255, 255, 255, 0.5);
    color: var(--text-primary);
    border-left: 3px solid var(--planet-primary);
}

.btn-primary:hover {
    background: var(--planet-primary) !important;
    color: white !important;
}

.btn-secondary:hover {
    background: rgba(255,255,255,0.3) !important;
}

/* ── Mensagens com Resposta Cadastrada ─────────────────────────── */
.message-bubble.user.has-answer {
    border-left: 3px solid #7EC152;
    background-color: rgba(126, 193, 82, 0.08);
    box-shadow: 0 4px 14px rgba(126, 193, 82, 0.15);
}

.answered-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    align-self: flex-start;
    margin-top: 4px;
    margin-left: 2px;
    font-size: 0.7rem;
    color: #4F8A2C;
    font-weight: 600;
    letter-spacing: 0.02em;
    animation: fadeIn 0.4s ease-out;
}

.answered-badge span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    background: #7EC152;
    color: white;
    border-radius: 50%;
    font-size: 0.6rem;
    font-weight: 700;
}

/* ── Toast de Sucesso ──────────────────────────────────────────── */
.success-toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(126, 193, 82, 0.4);
    border-left: 4px solid #7EC152;
    color: #2F5419;
    padding: 14px 20px;
    border-radius: 14px;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 10px 30px rgba(126, 193, 82, 0.2);
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    transform: translateY(12px);
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.success-toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.success-toast span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: #7EC152;
    color: white;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* ── Search Results ──────────────────────────────────────────────── */
.search-section-label {
    padding: 10px 20px 5px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    border-top: 1px solid rgba(255, 255, 255, 0.4);
    margin-top: 4px;
    background: rgba(255, 255, 255, 0.15);
}

.message-snippet {
    font-size: 0.78rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    margin-top: 1px;
}

mark.search-highlight {
    background: rgba(48, 155, 218, 0.2);
    color: var(--planet-primary);
    border-radius: 3px;
    padding: 0 2px;
    font-weight: 700;
    font-style: normal;
}

.search-empty {
    padding: 30px 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
}

.search-loading-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.search-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(48, 155, 218, 0.2);
    border-top: 2px solid var(--planet-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}
/* ── File Bubbles & Cards ─────────────────────────────────────────── */
.file-bubble {
    padding: 0 !important;
    overflow: hidden;
    max-width: 300px !important;
}

.file-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

.file-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.5);
    transition: background 0.2s;
}

.file-card:hover {
    background: rgba(255, 255, 255, 0.8);
}

.file-card-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.file-pdf { background-color: rgba(223, 72, 83, 0.15); color: #B8323D; }
.file-video { background-color: rgba(48, 155, 218, 0.15); color: #1F74A8; }
.file-imagem { background-color: rgba(48, 155, 218, 0.15); color: #1F74A8; }
.file-arquivo { background-color: rgba(109, 114, 136, 0.1); color: #6D7288; }

.file-card-info {
    flex: 1;
    min-width: 0;
}

.file-card-name {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.file-card-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.file-card-action {
    font-size: 1.2rem;
    color: var(--text-secondary);
    opacity: 0.5;
    padding: 0 4px;
}

.message-bubble.file-bubble .message-meta {
    padding: 2px 10px 6px;
    background: rgba(255, 255, 255, 0.3);
}

/* ── Follow-Up Messages Styling ──────────────────────────────────── */
.message-bubble.followup-bubble {
    border: 2.5px solid var(--planet-primary) !important;
    background-color: rgba(48, 155, 218, 0.06) !important;
    box-shadow: 0 4px 14px rgba(48, 155, 218, 0.15);
    border-top-right-radius: 0;
}

/* Níveis de follow-up: uma cor da paleta Planet por nível */
.message-bubble.followup-bubble.level-1 { border-color: #309BDA !important; }
.message-bubble.followup-bubble.level-2 { border-color: #EAAF3E !important; background-color: rgba(234, 175, 62, 0.06) !important; }
.message-bubble.followup-bubble.level-3 { border-color: #7EC152 !important; background-color: rgba(126, 193, 82, 0.06) !important; }
.message-bubble.followup-bubble.level-4 { border-color: #EE7C1B !important; background-color: rgba(238, 124, 27, 0.06) !important; }
.message-bubble.followup-bubble.level-5 { border-color: #DF4853 !important; background-color: rgba(223, 72, 83, 0.06) !important; }
.message-bubble.followup-bubble.level-6 { border-color: #3E4462 !important; background-color: rgba(62, 68, 98, 0.06) !important; }
.message-bubble.followup-bubble.level-7 { border-color: #309BDA !important; }
.message-bubble.followup-bubble.level-8 { border-color: #18214D !important; background-color: rgba(24, 33, 77, 0.06) !important; }

.followup-badge {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-primary);
    opacity: 0.85;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

/* Texto dos selos em tons mais escuros das mesmas cores, para leitura sobre fundo claro */
.message-bubble.followup-bubble.level-1 .followup-badge { color: #1F74A8; }
.message-bubble.followup-bubble.level-2 .followup-badge { color: #8F6512; }
.message-bubble.followup-bubble.level-3 .followup-badge { color: #4F8A2C; }
.message-bubble.followup-bubble.level-4 .followup-badge { color: #A8520C; }
.message-bubble.followup-bubble.level-5 .followup-badge { color: #B8323D; }
.message-bubble.followup-bubble.level-6 .followup-badge { color: #3E4462; }
.message-bubble.followup-bubble.level-7 .followup-badge { color: #1F74A8; }
.message-bubble.followup-bubble.level-8 .followup-badge { color: #18214D; }


/* Marca Planet nos cabeçalhos laterais */
.brand-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-mark {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

/* Usuário logado + Sair (rodapé da lateral; preenchido por /painel-auth.js) */
.sidebar-user {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--planet-border);
    background: var(--bg-sidebar);
}

.sidebar-user-email {
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
    color: var(--planet-light);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user-sair {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--planet-border);
    border-radius: var(--planet-radius-sm);
    color: var(--planet-dark);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.sidebar-user-sair:hover {
    background: var(--planet-grey);
    border-color: var(--planet-tertiary);
    color: var(--planet-tertiary);
}

.sidebar-user-sair:focus-visible {
    outline: 3px solid rgba(48, 155, 218, 0.4);
    outline-offset: 2px;
}

.sidebar-user-sair:disabled {
    opacity: 0.6;
    cursor: wait;
}
