:root {
    --navy: #1F2C34;
    --navy-light: #2C3D48;
    --green: #25984C;
    --green-light: #2FBE60;
    --bg: #F6F7F9;
    --card: #FFFFFF;
    --border: #E9ECEF;
    --text: #1c1e21;
    --text-muted: #6b7280;
    --danger: #d64545;
    --shadow-sm: 0 1px 2px rgba(16,24,40,0.06);
    --shadow-md: 0 4px 14px rgba(16,24,40,0.08);
    --radius: 14px;

    /* Só usadas no chat — têm valor próprio por tema, não seguem --green/--navy direto */
    --chat-wallpaper: #e5ddd5;
    --chat-bubble-in: #ffffff;
    --chat-bubble-out: #dcf8c6;
    --chat-bubble-text: #1c1e21;
}

/* ===================== TEMA ESCURO ===================== */
[data-theme="dark"] {
    --navy: #15202b;
    --navy-light: #1e2c38;
    --green: #2FBE60;
    --green-light: #3ad374;
    --bg: #10161b;
    --card: #1a2229;
    --border: #2a343d;
    --text: #e7ebee;
    --text-muted: #93a1ab;
    --danger: #e5665a;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.35);
    --shadow-md: 0 4px 14px rgba(0,0,0,0.45);

    --chat-wallpaper: #0b141a;
    --chat-bubble-in: #202c33;
    --chat-bubble-out: #005c4b;
    --chat-bubble-text: #e9edef;
}

/* ===================== TEMA AZUL ===================== */
[data-theme="blue"] {
    --navy: #1b3a63;
    --navy-light: #254b7d;
    --green: #2563eb;
    --green-light: #3b82f6;
    --bg: #F5F8FC;
    --card: #FFFFFF;
    --border: #E3EAF2;
    --text: #1c1e21;
    --text-muted: #64748b;
    --danger: #d64545;

    --chat-wallpaper: #dce7f5;
    --chat-bubble-in: #ffffff;
    --chat-bubble-out: #cfe2ff;
    --chat-bubble-text: #1c1e21;
}

/* Aplica as cores de chat via variável, no lugar dos valores fixos de antes */
.messages { background: var(--chat-wallpaper) !important; }
.bubble.in { background: var(--chat-bubble-in) !important; color: var(--chat-bubble-text); }
.bubble.out { background: var(--chat-bubble-out) !important; color: var(--chat-bubble-text); }

/* Aviso central discreto (ex: "conversa encerrada") — não é uma bolha normal */
.system-note {
    align-self: center;
    background: rgba(0,0,0,0.08);
    color: var(--text-muted);
    font-size: 12px;
    padding: 6px 14px;
    border-radius: 999px;
    margin: 10px 0;
    text-align: center;
}
[data-theme="dark"] .system-note { background: rgba(255,255,255,0.08); }

/* Seletor de tema, no rodapé do menu lateral */
.theme-switcher { padding: 10px 20px 4px; }
.theme-switcher label { color: #9fb0b8; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; display:block; margin-bottom: 6px; }
.theme-switcher select {
    width: 100%;
    padding: 7px 10px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.06);
    color: #e7ebee;
    font-size: 13px;
}
.theme-switcher select option { color: #1c1e21; }

/* Ajustes finos do modo escuro — elementos do chat que tinham cor fixa (não variável) */
[data-theme="dark"] .chat-header,
[data-theme="dark"] .no-chat-selected,
[data-theme="dark"] .input-bar,
[data-theme="dark"] .file-preview,
[data-theme="dark"] .star-btn,
[data-theme="dark"] .input-bar .attach-btn,
[data-theme="dark"] .chat-sidebar-header {
    background: var(--card) !important;
    color: var(--text);
    border-color: var(--border) !important;
}
[data-theme="dark"] .no-chat-selected { background: var(--chat-wallpaper) !important; color: var(--text-muted); }
[data-theme="dark"] .input-bar textarea,
[data-theme="dark"] .input-bar .attach-btn {
    background: var(--navy-light) !important;
    border-color: var(--border) !important;
    color: var(--text);
}
[data-theme="dark"] .conversation:hover { background: rgba(255,255,255,0.04); }
[data-theme="dark"] .conversation.active { background: rgba(47,190,96,0.12); }
[data-theme="dark"] .conversation.unread { background: rgba(255,255,255,0.03); }

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    background: var(--navy-light);
    border: 1px solid var(--border);
    color: var(--text);
}
[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder { color: var(--text-muted); }

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* ---------- Layout geral (sidebar + conteúdo) ---------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    background: var(--navy);
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    padding: 20px 12px;
}

.sidebar-logo { padding: 0 8px 24px; }
.sidebar-logo img { width: 100%; max-width: 170px; height: auto; display: block; }

.sidebar-nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }

.sidebar-nav a, .sidebar-logout {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    color: #b8c4cb;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-radius: 10px;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-badge {
    margin-left: auto;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}
.nav-badge + .nav-badge { margin-left: 4px; }
.nav-badge.queue { background: #e0a417; }
.nav-badge.unread { background: #ef4444; }

.sidebar-nav a:hover { background: rgba(255,255,255,0.07); color: #fff; }
.sidebar-nav a.active {
    background: var(--green);
    color: #fff;
    box-shadow: 0 2px 8px rgba(37, 152, 76, 0.35);
}
.sidebar-nav .icon { font-size: 16px; width: 20px; text-align: center; display: inline-flex; justify-content: center; }
.sidebar-nav .icon svg { width: 17px; height: 17px; }

.sidebar-logout {
    margin-top: auto;
    cursor: pointer;
    opacity: 0.75;
}
.sidebar-logout:hover { opacity: 1; }

.main-content { flex: 1; padding: 28px 32px; max-width: 1200px; }

.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 22px; margin: 0 0 4px; color: var(--navy); }
.page-header p { margin: 0; color: var(--text-muted); font-size: 14px; }

/* ---------- Cards ---------- */

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 22px 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.card h2 {
    margin-top: 0;
    font-size: 16px;
    color: var(--navy);
}

/* ---------- Grid de estatísticas ---------- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.alert-banner { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.alert-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    animation: pulse-pill 2s ease-in-out infinite;
}
.alert-pill.queue { background: #fff3cd; color: #8a6d1a; border: 1px solid #f0d98c; }
.alert-pill.unread { background: #e6f7ee; color: #0a7a3d; border: 1px solid #b7e4c7; }
@keyframes pulse-pill {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.75; }
}

.stat-card {
    background: var(--card);
    border-radius: 12px;
    padding: 18px 20px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.stat-card .stat-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

.stat-card .stat-value {
    font-size: 30px;
    font-weight: 700;
    color: var(--navy);
    margin-top: 6px;
}

.stat-card .stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-card.accent .stat-value { color: var(--green); }

/* ---------- Mini gráfico de barras (7 dias) ---------- */

.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 120px;
    margin-top: 12px;
}
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.bar-chart .bar {
    width: 100%;
    background: var(--green);
    border-radius: 4px 4px 0 0;
    min-height: 3px;
}
.bar-chart .bar-label { font-size: 10px; color: var(--text-muted); }

/* ---------- Tabela simples ---------- */

table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th {
    text-align: left;
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}
table.simple td { padding: 10px; border-bottom: 1px solid var(--border); }
table.simple tr:last-child td { border-bottom: none; }

/* ---------- Formulários ---------- */

label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    margin: 14px 0 6px;
    color: #444;
}
input[type=text], input[type=password] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d7dbe0;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type=text]:focus, input[type=password]:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(37, 152, 76, 0.15);
}
input[readonly] { background: #f0f0f0; color: #555; }
.row-copy { display: flex; gap: 8px; }
.row-copy input { flex: 1; }

button, .btn {
    background: var(--green);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 16px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    transition: opacity 0.15s ease, transform 0.1s ease;
}
button.secondary { background: #6b7280; }
button:hover { opacity: 0.9; }
button:active { transform: translateY(1px); }

.msg { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }
.msg.info { background: #e6f7ee; color: #0a7a3d; border: 1px solid #b7e4c7; }
.msg.error { background: #fdecea; color: #a52a2a; border: 1px solid #f5c6cb; }

.hint { font-size: 12px; color: #888; margin-top: 4px; }

/* ---------- Login ---------- */

.login-screen {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--navy);
}
.login-box {
    background: #fff;
    border-radius: 14px;
    padding: 36px 32px;
    width: 100%;
    max-width: 360px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.login-box img { max-width: 200px; margin-bottom: 20px; }
.login-box h2 { margin: 0 0 6px; color: var(--navy); font-size: 18px; }
.login-box p { color: var(--text-muted); font-size: 13px; margin-bottom: 4px; }
.login-box form { text-align: left; margin-top: 16px; }
.login-box button { width: 100%; padding: 12px; }
.login-credit { margin-top: 18px; text-align: center; color: rgba(255,255,255,0.55); font-size: 12px; }
.login-credit strong { color: rgba(255,255,255,0.85); }

/* ============================================================
   RESPONSIVO — CELULAR
   ============================================================ */

.mobile-topbar { display: none; }
.sidebar-overlay { display: none; }
.table-scroll { width: 100%; }
.chat-back-btn { display: none; }

@media (max-width: 768px) {

    /* ---------- Topo mobile com botão de menu ---------- */
    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 12px;
        background: var(--navy);
        color: #fff;
        padding: 14px 16px;
        position: sticky;
        top: 0;
        z-index: 60;
    }
    .mobile-topbar .hamburger {
        background: none;
        border: none;
        color: #fff;
        font-size: 22px;
        line-height: 1;
        cursor: pointer;
        padding: 4px;
    }
    .mobile-topbar .mobile-logo { height: 22px; }
    .mobile-topbar strong { font-size: 14px; }

    /* ---------- Menu lateral vira gaveta deslizante ---------- */
    .app-shell { flex-direction: column; }

    .sidebar {
        position: fixed;
        top: 0;
        left: -260px;
        height: 100vh;
        width: 250px;
        z-index: 80;
        transition: left 0.25s ease;
        box-shadow: 3px 0 16px rgba(0,0,0,0.35);
    }
    .sidebar.open { left: 0; }

    .sidebar-overlay.open {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.45);
        z-index: 70;
    }

    .main-content { padding: 16px; }
    .page-header h1 { font-size: 19px; }

    /* ---------- Tabelas: rolagem horizontal em vez de espremer ---------- */
    .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table.simple { min-width: 480px; }

    /* ---------- Chat: uma coluna por vez, igual o WhatsApp de verdade ---------- */
    .chat-sidebar { width: 100%; }
    .chat-back-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        color: inherit;
        font-size: 20px;
        cursor: pointer;
        padding: 0;
        margin-right: 4px;
        flex-shrink: 0;
    }

    .chat-shell.mobile-chat-open .chat-sidebar { display: none; }
    .chat-shell:not(.mobile-chat-open) .chat-area { display: none; }

    .bubble { max-width: 82%; }

    .login-box { margin: 0 16px; }
}

/* ---------- Chat ---------- */

.chat-shell { display: flex; height: 100vh; }
.chat-sidebar {
    width: 300px;
    background: #fff;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}
.chat-sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--navy);
}
.chat-sidebar-header img { height: 26px; }
.chat-sidebar-header a { color: #cbd5db; font-size: 12px; text-decoration: none; margin-left: auto; }
.chat-type-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 20px;
    color: #fff;
    white-space: nowrap;
}
.chat-type-badge.wa { background: var(--green); }
.chat-type-badge.internal { background: #5b6ee1; }
.bubble .sender-name { display: block; font-size: 12px; font-weight: 700; margin-bottom: 2px; }
.bubble.out .sender-name { color: #0a7a3d; }
.bubble.in .sender-name { color: #3949ab; }

.conversation { padding: 12px 16px; border-bottom: 1px solid #f0f0f0; cursor: pointer; border-left: 4px solid transparent; }
.conversation:hover { background: #f7f7f7; }
.conversation.active { background: #e9f7f1; }
.conversation.unread { background: #f3fbf6; }
.conversation.queue { background: #fffaf0; border-left-color: #e0a417; }
.conversation.queue:hover { background: #fff4e0; }
.conversation.queue.active { background: #fff0d9; }
.queue-badge {
    background: #e0a417;
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.03em;
    padding: 3px 8px;
    border-radius: 999px;
    white-space: nowrap;
    flex-shrink: 0;
    animation: pulse-pill 2s ease-in-out infinite;
}
.conv-row-top { display: flex; justify-content: space-between; align-items: baseline; }
.conv-row-top .name { font-weight: 600; font-size: 14px; }
.conversation.unread .conv-row-top .name { font-weight: 800; }
.conv-row-top .time { font-size: 11px; color: #aaa; flex-shrink: 0; margin-left: 8px; }
.conv-row-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; gap: 10px; }
.conv-row-bottom .preview { font-size: 12px; color: #888; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1 1 auto; min-width: 0; }
.conversation.unread .conv-row-bottom .preview { color: #333; font-weight: 600; }
.unread-badge {
    background: var(--green);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    flex-shrink: 0;
    margin-left: auto;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.empty-sidebar { padding: 20px; color: #999; font-size: 13px; text-align: center; }

.chat-area { flex: 1; display: flex; flex-direction: column; }
.chat-header { padding: 14px 20px; background: #fff; border-bottom: 1px solid var(--border); font-weight: 600; }
.messages { flex: 1; overflow-y: auto; padding: 20px; background: #e5ddd5; display: flex; flex-direction: column; }

.bubble { max-width: 60%; padding: 8px 12px; border-radius: 10px; margin-bottom: 8px; font-size: 14px; line-height: 1.4; position: relative; }
.bubble.in { align-self: flex-start; background: #fff; }
.bubble.out { align-self: flex-end; background: #dcf8c6; }
.bubble .meta { font-size: 10px; color: #999; margin-top: 4px; text-align: right; }
.bubble img.media-img { max-width: 260px; border-radius: 6px; display: block; margin-bottom: 4px; }
.bubble .media-doc { display: flex; align-items: center; gap: 8px; background: #f2f2f2; padding: 8px; border-radius: 6px; text-decoration: none; color: #1c1e21; margin-bottom: 4px; }
.bubble audio, .bubble video { max-width: 260px; display: block; margin-bottom: 4px; }

.star-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    font-size: 15px;
    cursor: pointer;
    opacity: 0.35;
    transition: opacity 0.15s ease, transform 0.1s ease;
    background: #fff;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    user-select: none;
    z-index: 2;
}
.star-btn:hover { opacity: 1; transform: scale(1.15); }
.star-btn:active { transform: scale(0.9); }
.star-btn.starred { opacity: 1; color: #e0a417; }

.no-chat-selected { flex: 1; display: flex; align-items: center; justify-content: center; color: #999; background: #e5ddd5; }

.input-bar { display: flex; align-items: flex-end; padding: 12px; background: #f0f0f0; border-top: 1px solid #ddd; gap: 8px; }
.input-bar textarea {
    flex: 1;
    padding: 10px 14px;
    border-radius: 20px;
    border: 1px solid #ccc;
    font-size: 14px;
    font-family: inherit;
    margin: 0;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
}
.input-bar button { margin: 0; border-radius: 20px; padding: 0 20px; height: 40px; align-self: flex-end; }
.bubble { }
.bubble .bubble-text { white-space: pre-wrap; word-wrap: break-word; }
.input-bar .attach-btn {
    background: #fff;
    border: 1px solid #ccc;
    color: var(--navy);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    flex-shrink: 0;
}
.input-bar .attach-btn:hover { background: #f5f5f5; }
.locked-bar { padding: 16px; background: #fff8e1; border-top: 1px solid #f0d98c; color: #8a6d1a; font-size: 13px; text-align: center; font-weight: 600; }
.template-bar {
    padding: 16px;
    background: #eef2ff;
    border-top: 1px solid #c7d2fe;
    color: #3730a3;
    font-size: 13px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    line-height: 1.5;
}
.template-bar .template-bar-text {
    max-width: 480px;
    font-weight: 500;
}
.template-bar button {
    margin: 0;
    background: #4f46e5;
    border-radius: 999px;
    padding: 10px 22px;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 1px 3px rgba(79,70,229,0.35);
}
.template-bar button:hover { background: #4338ca; opacity: 1; }
.file-preview { padding: 8px 16px; background: #fff; border-top: 1px solid #ddd; font-size: 13px; display: flex; align-items: center; gap: 10px; }
.file-preview .remove { color: var(--danger); cursor: pointer; font-weight: 600; }

/* Ajustes finos multi-empresa */
select { padding: 10px 12px; border: 1px solid #ccc; border-radius: 6px; font-size: 14px; width: 100%; }
