/* chat.css - Estilos específicos para a tela de Caixa de Entrada (IA) */

.chat-page-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
    background-color: var(--bg-body);
}

.chat-container {
    display: flex;
    flex: 1;
    margin-left: 260px;
    /* Sidebar width from dashboard.css */
    background: var(--bg-card);
    border-radius: 12px;
    margin-top: 24px;
    margin-bottom: 24px;
    margin-right: 24px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

/* Sidebar Responsive Logic */
@media (max-width: 1024px) {
    .chat-container {
        margin-left: 80px;
    }
}

@media (max-width: 768px) {
    .chat-container {
        margin-left: 16px;
        margin-right: 16px;
        flex-direction: column;
    }
}

/* ============================
   LEFT PANEL (CONTACT LIST)
   ============================ */
.chat-sidebar {
    width: 320px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
}

.chat-sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-sidebar);
}

.chat-sidebar-header h2 {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 16px 0;
    color: var(--text-primary);
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-box svg {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
}

.search-box input {
    width: 100%;
    padding: 10px 10px 10px 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-body);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
}

.search-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.contact-list {
    flex: 1;
    overflow-y: auto;
}

.contact-item {
    display: flex;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
    align-items: center;
}

.contact-item:hover {
    background: var(--bg-body);
}

.contact-item.active {
    background: rgba(99, 102, 241, 0.08);
    border-left: 4px solid var(--primary);
}

.contact-item.loading-state {
    justify-content: center;
    color: var(--text-muted);
    font-size: 14px;
    font-style: italic;
    cursor: default;
}

.contact-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary-light);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    margin-right: 16px;
    flex-shrink: 0;
}

.contact-details {
    flex: 1;
    min-width: 0;
}

.contact-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.contact-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-time {
    font-size: 12px;
    color: var(--text-muted);
}

.contact-last-msg {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================
   RIGHT PANEL (CHAT AREA)
   ============================ */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: url('data:image/svg+xml;utf8,<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h20v20H0z" fill="none"/><circle cx="2" cy="2" r="1.5" fill="rgba(255,255,255,0.03)"/></svg>') repeat;
    background-color: var(--bg-body);
    position: relative;
}

/* Empty State */
.chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-muted);
    padding: 20px;
}

.chat-empty-state .empty-icon {
    width: 80px;
    height: 80px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}

.chat-empty-state h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

/* Chat Header */
.chat-header {
    padding: 16px 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.chat-header-info {
    display: flex;
    align-items: center;
}

.chat-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary-light);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 18px;
    margin-right: 16px;
}

.chat-header-details h3 {
    margin: 0 0 4px 0;
    font-size: 16px;
    color: var(--text-primary);
}

.chat-subtitle {
    font-size: 13px;
    color: var(--text-muted);
}

/* AI Toggle Control */
.ai-control {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-status-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--success);
}

.ai-control.paused .ai-status-label {
    color: var(--warning);
}

/* The Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border);
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

input:checked+.slider {
    background-color: var(--success);
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--success);
}

input:checked+.slider:before {
    transform: translateX(26px);
}

.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}

/* Messages History */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    max-width: 75%;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.5;
    position: relative;
    color: var(--text-primary);
    word-wrap: break-word;
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    opacity: 0.8;
}

/* User Message (Lead) */
.message.user {
    align-self: flex-start;
}

.message.user .message-bubble {
    background: var(--bg-card);
    border-top-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Agent Message (AI) */
.message.agent {
    align-self: flex-end;
}

.message.agent .message-bubble {
    background: var(--primary);
    color: white;
    border-top-right-radius: 4px;
    box-shadow: 0 1px 2px rgba(99, 102, 241, 0.4);
}

.message.agent .message-time {
    color: rgba(255, 255, 255, 0.8);
    text-align: right;
}

/* Manual Agent Message (Not AI) */
.message.agent.manual .message-bubble {
    background: #059669;
    /* Emerald green to differentiate from AI */
    box-shadow: 0 1px 2px rgba(5, 150, 105, 0.4);
}

/* Date Divider */
.chat-date-divider {
    text-align: center;
    margin: 16px 0;
}

.chat-date-divider span {
    background: var(--bg-card);
    padding: 6px 16px;
    border-radius: 16px;
    font-size: 12px;
    color: var(--text-muted);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Chat Input Area */
.chat-input-area {
    padding: 16px 24px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
}

.ai-paused-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 12px;
    text-align: center;
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.chat-form {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#chat-input {
    flex: 1;
    background: var(--bg-body);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 12px 20px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 15px;
    outline: none;
    resize: none;
    max-height: 120px;
    transition: all 0.2s;
    line-height: 1.4;
}

#chat-input:focus {
    border-color: var(--primary);
    background: var(--bg-card);
}

.btn-send {
    background: var(--primary);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-send:hover {
    background: var(--primary-light);
    transform: scale(1.05);
}

.btn-send:disabled {
    background: var(--border);
    color: var(--text-muted);
    cursor: not-allowed;
    transform: none;
}