/* Variáveis globais - estilo WhatsApp elevado, moderno */
:root {
    --bg-app: #eef1f0;
    --bg-chat: #efeae2;
    --bg-panel: #ffffff;
    --primary: #00a884;
    --primary-dark: #008069;
    --primary-soft: #e6f7f3;
    --text-main: #111b21;
    --text-muted: #667781;
    --border-color: #e9edef;
    --msg-in: #ffffff;
    --msg-out: #d9fdd3;
    --hover-bg: #f5f6f6;
    --danger: #d32f2f;
    --danger-soft: #fee2e2;
    --shadow-soft: 0 4px 12px rgba(0,0,0,0.05);
    --shadow-card: 0 2px 10px rgba(16,24,32,0.06);
    --shadow-modal: 0 20px 45px rgba(16,24,32,0.25);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
    font-family: inherit;
}

/* ==================== TELA DE LOGIN ==================== */
.login-body {
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    padding: 20px;
    overflow-y: auto;
}

.login-container {
    width: 100%;
    max-width: 400px;
}

.login-card {
    background: #fff;
    padding: 40px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-modal);
    text-align: center;
}

.login-header {
    margin-bottom: 30px;
}

.login-icon {
    color: var(--primary);
    margin-bottom: 10px;
}

.login-header h2 {
    font-size: 24px;
    color: var(--text-main);
    margin-bottom: 5px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 14px;
}

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-main);
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: var(--radius-sm);
    font-size: 15px;
    transition: all 0.2s;
    font-family: inherit;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 168, 132, 0.12);
}

.btn-login {
    width: 100%;
    padding: 14px;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.btn-login:hover { background-color: var(--primary-dark); }
.btn-login:active { transform: scale(0.99); }

.error-msg {
    background-color: var(--danger-soft);
    color: #b91c1c;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 14px;
}

/* ==================== ESTRUTURA PRINCIPAL DO APP ==================== */
.app-container {
    display: flex;
    max-width: 1700px;
    margin: 0 auto;
    height: 100%;
    background-color: var(--bg-panel);
    box-shadow: var(--shadow-soft);
}

.sidebar {
    width: 380px;
    min-width: 320px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background-color: #fff;
}

.sidebar-header {
    height: 60px;
    min-height: 60px;
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #f7f8f9;
    border-bottom: 1px solid var(--border-color);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.user-name {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    background-color: var(--primary);
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
    font-size: 18px;
}

.header-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.logout-btn {
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    transition: color 0.15s, background 0.15s;
}

.logout-btn:hover {
    color: var(--primary-dark);
    background: var(--hover-bg);
}

/* ==================== FILTROS ==================== */
.search-bar {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

.filter-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 10px;
}

.filter-stack-tight { gap: 8px; }

.filter-row {
    display: flex;
    gap: 8px;
}

.filter-col { flex: 1; }

.filter-label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.filter-label-title {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.filter-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d7dde1;
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.filter-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 168, 132, 0.1);
}

.filter-checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-checkbox-row input { width: 18px; height: 18px; cursor: pointer; accent-color: var(--danger); }

.filter-sla-label {
    font-size: 12px;
    color: #b91c1c;
    font-weight: 600;
    cursor: pointer;
}

.btn-primary-block {
    width: 100%;
    padding: 10px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s;
}

.btn-primary-block:hover { background: var(--primary-dark); }

.btn-primary-inline {
    padding: 9px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s;
    white-space: nowrap;
}
.btn-primary-inline:hover { background: var(--primary-dark); }

.btn-secondary {
    padding: 9px 16px;
    background: #fff;
    color: var(--text-main);
    border: 1px solid #d7dde1;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s;
}
.btn-secondary:hover { background: var(--hover-bg); }

.btn-danger {
    padding: 9px 16px;
    background: var(--danger-soft);
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
}
.btn-danger:hover { background: #fecaca; }

.btn-sm { padding: 6px 10px; font-size: 12px; }

.search-input-wrapper {
    display: flex;
    align-items: center;
    background-color: #f0f2f5;
    border-radius: var(--radius-sm);
    padding: 0 12px;
}

.search-icon { color: var(--text-muted); flex-shrink: 0; }

.search-input-wrapper input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px;
    font-size: 14px;
    color: var(--text-main);
    min-width: 0;
}

.search-input-wrapper input:focus { outline: none; }

/* ==================== LISTA DE CONTATOS ==================== */
.contacts-list {
    flex: 1;
    overflow-y: auto;
}

.contact-item {
    display: flex;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid #f2f2f2;
}

.contact-item:hover, .contact-item.active { background-color: var(--hover-bg); }
.contact-item.active { box-shadow: inset 3px 0 0 var(--primary); }

.contact-avatar {
    margin-right: 15px;
    background-color: #cfd9df;
    color: #333;
}

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

.contact-header {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.contact-name {
    font-weight: 500;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-time { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }

.contact-msg {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-top: 6px;
}

.badge-seller {
    font-size: 11px;
    background-color: var(--primary-soft);
    color: var(--primary-dark);
    padding: 3px 7px;
    border-radius: 6px;
    font-weight: 500;
}

.badge-sla {
    font-size: 11px;
    background-color: var(--danger-soft);
    color: #b91c1c;
    padding: 3px 7px;
    border-radius: 6px;
    font-weight: bold;
    animation: pulse-red 2s infinite;
}

.badge-excluded {
    font-size: 11px;
    background-color: #f1f5f9;
    color: #64748b;
    padding: 3px 7px;
    border-radius: 6px;
    font-weight: 500;
}

@keyframes pulse-red {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* ==================== ÁREA DE CHAT ==================== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #f0f2f5;
    position: relative;
    min-width: 0;
}

.chat-placeholder {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #f0f2f5;
    z-index: 10;
}

.placeholder-content { text-align: center; color: var(--text-muted); max-width: 400px; padding: 20px; }
.placeholder-content svg { margin-bottom: 20px; }
.placeholder-content h2 { font-size: 26px; font-weight: 300; margin-bottom: 10px; color: #41525d; }

.chat-room { display: flex; flex-direction: column; height: 100%; }
.hidden { display: none !important; }

.chat-header {
    min-height: 60px;
    padding: 10px 16px;
    background-color: #f7f8f9;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.mobile-back-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
}
.mobile-back-btn:hover { background: var(--hover-bg); }

.chat-header-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-title { min-width: 0; }
.chat-title h3 { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-phone { font-size: 13px; color: var(--text-muted); }

.chat-header-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.tool-btn {
    background: #fff;
    border: 1px solid #d7dde1;
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text-main);
    transition: background 0.15s, border-color 0.15s;
}
.tool-btn:hover { background: var(--hover-bg); }
.tool-btn-active {
    background: var(--danger-soft);
    border-color: #fecaca;
    color: #991b1b;
}

.seller-badge {
    background-color: #fff;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-main);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    white-space: nowrap;
}
.seller-badge strong { color: var(--primary-dark); }

/* Painel de resultado do CRM */
.crm-panel {
    padding: 12px 16px;
    background: #fbfcfd;
    border-bottom: 1px solid var(--border-color);
    max-height: 260px;
    overflow-y: auto;
}

.crm-empty { color: var(--text-muted); font-size: 13px; }

.crm-contact-card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 8px;
}
.crm-contact-card:last-child { margin-bottom: 0; }
.crm-contact-name { font-weight: 600; font-size: 14px; }
.crm-contact-meta { font-size: 12px; color: var(--text-muted); margin: 4px 0 8px; }
.crm-contact-deals { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.crm-open-link { font-size: 12px; color: var(--primary-dark); font-weight: 600; text-decoration: none; }
.crm-open-link:hover { text-decoration: underline; }

/* ==================== MENSAGENS ==================== */
.messages-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: var(--bg-chat);
    background-image: url('data:image/svg+xml,%3Csvg width="60" height="60" viewBox="0 0 60 60" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="none" fill-rule="evenodd"%3E%3Cg fill="%23dfd8c8" fill-opacity="0.4"%3E%3Cpath d="M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z"/%3E%3C/g%3E%3C/g%3E%3C/svg%3E');
}

.date-divider { text-align: center; margin: 15px 0; font-size: 12px; color: #54656f; text-transform: uppercase; font-weight: 500; }
.date-divider span { background: #fff; padding: 6px 12px; border-radius: 8px; box-shadow: 0 1px 1px rgba(0,0,0,0.05); }

.message-wrapper { display: flex; margin-bottom: 10px; width: 100%; }
.msg-sent { justify-content: flex-end; }
.msg-received { justify-content: flex-start; }

.message {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 10px;
    position: relative;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
    font-size: 14.2px;
    line-height: 1.4;
}

.msg-sent .message { background-color: var(--msg-out); border-top-right-radius: 2px; }
.msg-received .message { background-color: var(--msg-in); border-top-left-radius: 2px; }

.msg-content { word-wrap: break-word; margin-bottom: 15px; white-space: pre-wrap; }
.msg-time { font-size: 11px; color: var(--text-muted); position: absolute; bottom: 4px; right: 8px; }
.msg-sender-name { font-size: 12px; font-weight: 500; color: #d81b60; margin-bottom: 4px; display: block; }
.msg-sent .msg-sender-name { color: var(--primary-dark); }

.loading-state, .error-state { padding: 20px; text-align: center; color: var(--text-muted); font-size: 14px; }
.error-state { color: #b91c1c; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.3); }

/* ==================== DASHBOARD ==================== */
.dash-area { padding: 30px; overflow-y: auto; background-color: #f8fafc; }
.dash-page-title { margin-bottom: 4px; color: #1e293b; font-size: 22px; }

.dash-filter-bar { padding: 20px; border-bottom: 1px solid var(--border-color); }
.dash-metrics-col { padding: 20px; }

.metric-card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-card);
}

.metric-card h3 { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.03em; }
.metric-value { font-size: 32px; font-weight: 700; color: var(--primary-dark); }

.dash-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 24px;
    margin-top: 20px;
}

.dash-box {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 24px;
    box-shadow: var(--shadow-card);
}

.dash-title { font-size: 15px; font-weight: 600; margin-bottom: 20px; color: var(--text-main); }
.chart-container { height: 300px; width: 100%; }

/* ==================== ADMINISTRAÇÃO ==================== */
.admin-nav { padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.admin-nav-item {
    text-align: left;
    padding: 10px 12px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    color: var(--text-main);
    font-weight: 500;
}
.admin-nav-item:hover { background: var(--hover-bg); }
.admin-nav-item.active { background: var(--primary-soft); color: var(--primary-dark); }

.admin-tab-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }

.admin-hint { color: var(--text-muted); font-size: 13px; margin-bottom: 20px; max-width: 700px; line-height: 1.5; }
.admin-hint-inline { color: var(--text-muted); font-size: 12px; font-weight: 400; }

.admin-card-list { display: flex; flex-direction: column; gap: 10px; }

.admin-card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    box-shadow: var(--shadow-card);
}

.admin-card-main { min-width: 0; flex: 1; }
.admin-card-title { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.admin-card-sellers { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.admin-card-actions { display: flex; gap: 8px; flex-shrink: 0; }

.admin-inline-form { display: flex; gap: 8px; margin-bottom: 14px; }
.admin-inline-form input {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid #d7dde1;
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.admin-tag-list { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    padding: 6px 8px 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
}
.admin-tag button {
    background: none;
    border: none;
    color: var(--primary-dark);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 2px 4px;
}
.admin-tag button:hover { color: var(--danger); }

.admin-checkbox-row { display: flex; align-items: center; gap: 8px; }
.admin-checkbox-row input { width: 16px; height: 16px; cursor: pointer; }
.admin-checkbox-row label { margin: 0; font-weight: 400; font-size: 13px; cursor: pointer; }

.admin-checklist {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 6px;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px;
}
.admin-checklist-item { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.admin-checklist-item input { cursor: pointer; }

/* Modal */
.admin-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.admin-modal {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-modal);
}
.admin-modal h3 { margin-bottom: 18px; font-size: 18px; }
.admin-modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ==================== RESPONSIVO / MOBILE ==================== */
@media (max-width: 768px) {
    body { overflow: auto; height: auto; min-height: 100vh; }

    .app-container {
        flex-direction: column;
        height: 100vh;
        max-width: 100%;
    }

    .sidebar {
        width: 100%;
        min-width: 0;
        height: 100%;
    }

    .chat-area { position: absolute; inset: 0; z-index: 20; display: none; }

    /* Quando um chat está aberto no mobile, esconde a lista e mostra só o chat */
    .app-container.mobile-chat-open .sidebar { display: none; }
    .app-container.mobile-chat-open .chat-area { display: flex; }

    .mobile-back-btn { display: flex; }

    .chat-header { flex-wrap: wrap; }
    .chat-header-tools { width: 100%; justify-content: flex-start; }

    .filter-row { flex-direction: column; }

    .dash-area { padding: 16px; }
    .dash-grid { grid-template-columns: 1fr; gap: 16px; }
    .dash-box { padding: 16px; }
    .chart-container { height: 240px; }

    .admin-tab-header { flex-direction: column; align-items: stretch; }
    .admin-card { flex-direction: column; align-items: stretch; }
    .admin-card-actions { justify-content: flex-end; }

    .login-card { padding: 28px 22px; }

    .form-group input, .filter-input, button {
        min-height: 40px;
    }
}

@media (max-width: 480px) {
    .chat-header-info { max-width: 100%; }
    .seller-badge { display: none; }
    .message { max-width: 80%; }
}
