:root {
    --roxo: #667eea;
    --roxo-escuro: #5568d3;
    --verde: #22a06b;
    --laranja: #f59e0b;
    --vermelho: #e5484d;
    --texto: #1f2430;
    --texto-fraco: #6b7280;
    --borda: #e5e7eb;
    --fundo: #f6f7f9;
    --painel: #ffffff;
}

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

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--fundo);
    color: var(--texto);
    font-size: 14px;
    overflow: hidden; /* quem rola é o .conteudo, não a página — senão a aba Chat não consegue travar a rolagem no painel de mensagens */
}

.layout { display: flex; height: 100vh; }

.sidebar {
    width: 220px;
    background: var(--painel);
    border-right: 1px solid var(--borda);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}
.sidebar-header h1 { font-size: 17px; font-weight: 600; }
.sidebar-header p { font-size: 12px; opacity: .85; margin-top: 2px; }

.nav { padding: 12px 8px; flex: 1; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; margin-bottom: 2px;
    border-radius: 8px; cursor: pointer;
    color: var(--texto-fraco); font-weight: 500;
    border: none; background: none; width: 100%;
    text-align: left; font-size: 14px; font-family: inherit;
}
.nav-item:hover { background: #f1f2f6; color: var(--texto); }
.nav-item.ativo { background: var(--roxo); color: white; }

.sidebar-rodape { padding: 12px; border-top: 1px solid var(--borda); }

.conteudo {
    flex: 1; padding: 24px 28px; min-width: 0;
    overflow-x: hidden; overflow-y: auto; height: 100vh;
    display: flex; flex-direction: column;
}
.conteudo > *:not(.chat-pagina) { flex-shrink: 0; }

.topo {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 22px; gap: 16px; flex-wrap: wrap;
}
.topo h2 { font-size: 21px; font-weight: 650; }
.topo .sub { color: var(--texto-fraco); font-size: 13px; margin-top: 2px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 26px; }
.card {
    background: var(--painel); border: 1px solid var(--borda);
    border-radius: 10px; padding: 16px;
}
.card .rotulo { font-size: 12px; color: var(--texto-fraco); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.card .valor { font-size: 27px; font-weight: 680; margin-top: 6px; }
.card .valor.verde { color: var(--verde); }
.card .valor.vermelho { color: var(--vermelho); }

.painel {
    background: var(--painel); border: 1px solid var(--borda);
    border-radius: 10px; overflow: hidden; margin-bottom: 20px;
}
.painel-topo {
    padding: 14px 16px; border-bottom: 1px solid var(--borda);
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.painel-topo h3 { font-size: 15px; font-weight: 620; }

.tabela-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
    text-align: left; padding: 10px 16px; font-size: 11.5px;
    color: var(--texto-fraco); text-transform: uppercase;
    letter-spacing: .04em; font-weight: 600;
    border-bottom: 1px solid var(--borda); white-space: nowrap;
}
td { padding: 12px 16px; border-bottom: 1px solid #f1f2f4; vertical-align: middle; }
tr:last-child td { border-bottom: none; }

.pill {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px; border-radius: 20px;
    font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill.verde { background: #e3f5ec; color: #14724b; }
.pill.laranja { background: #fdf0d5; color: #96620a; }
.pill.vermelho { background: #fdeaea; color: #a92c30; }
.pill.cinza { background: #eef0f3; color: #55606e; }

.ponto { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

button.btn {
    padding: 8px 14px; border-radius: 7px; border: none;
    background: var(--roxo); color: white; cursor: pointer;
    font-size: 13px; font-weight: 550; font-family: inherit;
}
button.btn:hover { background: var(--roxo-escuro); }
button.btn:disabled { background: #c9cdd6; cursor: not-allowed; }
button.btn.fantasma {
    background: transparent; color: var(--texto-fraco);
    border: 1px solid var(--borda);
}
button.btn.fantasma:hover { background: #f1f2f6; color: var(--texto); }
button.btn.pequeno { padding: 5px 10px; font-size: 12px; }
button.btn.perigo { background: transparent; color: var(--vermelho); border: 1px solid #f3c8ca; }
button.btn.perigo:hover { background: #fdeaea; }

code.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12.5px; background: #f1f2f6; padding: 2px 7px; border-radius: 5px;
}

.vazio { padding: 34px 16px; text-align: center; color: var(--texto-fraco); }

/* Modal */
.overlay {
    position: fixed; inset: 0; background: rgba(15,18,25,.5);
    display: none; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.overlay.aberto { display: flex; }
.modal {
    background: var(--painel); border-radius: 12px; padding: 22px;
    width: 100%; max-width: 460px; box-shadow: 0 12px 40px rgba(0,0,0,.22);
    max-height: 90vh; overflow-y: auto;
}
.modal h3 { font-size: 17px; margin-bottom: 6px; }
.modal .desc { color: var(--texto-fraco); font-size: 13px; margin-bottom: 16px; }
.campo { margin-bottom: 13px; }
.campo label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
.campo input, .campo select {
    width: 100%; padding: 9px 11px; border: 1px solid var(--borda);
    border-radius: 7px; font-size: 14px; font-family: inherit; background: white;
}
.campo input:focus, .campo select:focus {
    outline: none; border-color: var(--roxo); box-shadow: 0 0 0 3px rgba(102,126,234,.13);
}
.campo .dica { font-size: 12px; color: var(--texto-fraco); margin-top: 4px; }
.modal-acoes { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

.aviso {
    background: #fff8e6; border: 1px solid #f5dfa8; border-radius: 8px;
    padding: 12px; font-size: 13px; color: #8a6410; margin-bottom: 14px;
}
.chave-box {
    background: #f1f2f6; border-radius: 8px; padding: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12.5px; word-break: break-all; margin-bottom: 10px;
    border: 1px solid var(--borda);
}

.erro { color: var(--vermelho); font-size: 12.5px; margin-top: 8px; }

.qr-box { text-align: center; }
.qr-box img { width: 240px; max-width: 100%; border: 1px solid var(--borda); border-radius: 8px; padding: 8px; background: white; }

.tags { display: flex; flex-wrap: wrap; gap: 5px; }

.spinner {
    border: 2px solid rgba(255,255,255,.35); border-top-color: white;
    border-radius: 50%; width: 14px; height: 14px;
    animation: girar .8s linear infinite; display: inline-block;
}
@keyframes girar { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
    .layout { flex-direction: column; }
    .sidebar { width: 100%; }
    .nav { display: flex; overflow-x: auto; padding: 8px; }
    .nav-item { white-space: nowrap; width: auto; }
    .sidebar-rodape { display: none; }
    .conteudo { padding: 16px; }
}

/* ---------- Tela de Chat ---------- */
/* Ocupa toda a altura que sobra dentro de .conteudo (que já é 100vh com scroll próprio).
   flex:1 + min-height:0 é o que permite o painel de mensagens ter scroll interno de
   verdade, em vez de esticar a página inteira — sem isso o filho flex nunca encolhe
   abaixo do seu conteúdo e o overflow-y dele nunca entra em ação. */
.chat-pagina {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    flex: 1;
}

.chat-layout {
    display: grid;
    grid-template-columns: 310px 1fr;
    gap: 0;
    background: var(--painel);
    border: 1px solid var(--borda);
    border-radius: 10px;
    overflow: hidden;
    flex: 1;
    min-height: 0;
}

.chat-lista {
    border-right: 1px solid var(--borda);
    overflow-y: auto;
    background: #fbfbfc;
}

.chat-item {
    display: block; width: 100%; text-align: left;
    padding: 11px 14px; border: none; background: none;
    border-bottom: 1px solid #f1f2f4; cursor: pointer;
    font-family: inherit; font-size: 13px;
}
.chat-item:hover { background: #f1f2f6; }
.chat-item.ativo { background: #eef0fd; box-shadow: inset 3px 0 0 var(--roxo); }

.chat-item-topo { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chat-item-nome { font-weight: 600; color: var(--texto); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-hora { font-size: 11.5px; color: var(--texto-fraco); white-space: nowrap; }
.chat-item-previa {
    color: var(--texto-fraco); margin-top: 3px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-item-meta { color: var(--texto-fraco); font-size: 11.5px; margin-top: 4px; }

.chat-painel { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.chat-cabecalho {
    padding: 12px 16px; border-bottom: 1px solid var(--borda);
    display: flex; align-items: baseline; gap: 10px; flex-shrink: 0;
}

.chat-mensagens {
    flex: 1; overflow-y: auto; padding: 16px;
    background: #f6f7f9; display: flex; flex-direction: column; gap: 8px;
}

.chat-linha { display: flex; }
.chat-linha.entrada { justify-content: flex-start; }
.chat-linha.saida { justify-content: flex-end; }

.chat-bolha {
    max-width: min(560px, 78%);
    background: var(--painel);
    border: 1px solid var(--borda);
    border-radius: 10px;
    padding: 8px 11px;
}
.chat-linha.saida .chat-bolha { background: #e8f6ef; border-color: #cfe9dd; }

.chat-autor { font-size: 12px; font-weight: 600; color: var(--roxo-escuro); margin-bottom: 3px; }
.chat-linha.saida .chat-autor { color: #14724b; }
.chat-texto { font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.chat-hora { font-size: 11px; color: var(--texto-fraco); text-align: right; margin-top: 4px; }

@media (max-width: 820px) {
    .chat-layout { grid-template-columns: 1fr; }
    .chat-lista { max-height: 220px; border-right: none; border-bottom: 1px solid var(--borda); }
    .chat-mensagens { min-height: 320px; }
}

/* ---------- Sub-abas (usado em Configurações e no Chat) ---------- */
/* overflow-y: hidden — com overflow-x: auto o navegador liga a rolagem vertical também, e o
   margin-bottom: -1px dos itens (que encaixa a linha da aba ativa na borda) sobra 1px. */
.subnav {
    display: flex; gap: 4px; margin-bottom: 20px;
    border-bottom: 1px solid var(--borda); overflow-x: auto; overflow-y: hidden;
}
.subnav-item {
    padding: 10px 14px; border: none; background: none; cursor: pointer;
    font-family: inherit; font-size: 13.5px; font-weight: 600; color: var(--texto-fraco);
    white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subnav-item:hover { color: var(--texto); }
.subnav-item.ativo { color: var(--roxo); border-bottom-color: var(--roxo); }

/* ---------- Barra de filtro (usado em Mensagens) ---------- */
.filtro-barra {
    display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
    padding: 12px 16px; border-bottom: 1px solid var(--borda); background: #fbfbfc;
}
.filtro-barra input, .filtro-barra select {
    padding: 7px 10px; border: 1px solid var(--borda); border-radius: 7px;
    font-size: 13px; font-family: inherit; background: white;
}
.filtro-barra input[type="text"] { flex: 1; min-width: 160px; }
.filtro-barra input:focus, .filtro-barra select:focus {
    outline: none; border-color: var(--roxo); box-shadow: 0 0 0 3px rgba(102,126,234,.13);
}

.secao-titulo {
    font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    color: var(--texto-fraco); margin: 22px 0 8px;
}
.secao-titulo:first-child { margin-top: 0; }
