* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background: #f0f2f5;
    color: #1c1e21;
}
a { color: #075e54; text-decoration: none; }
a:hover { text-decoration: underline; }

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

.app-sidebar {
    width: 220px;
    flex-shrink: 0;
    background: #075e54;
    color: #fff;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
}
.app-sidebar-brand { font-weight: 600; font-size: 17px; padding: 20px 20px 16px; }
.app-sidebar-nav { display: flex; flex-direction: column; flex: 1; }
.app-sidebar-nav .nav-link {
    color: #d5e8e6;
    padding: 12px 20px;
    font-size: 14px;
}
.app-sidebar-nav .nav-link:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.app-sidebar-nav .nav-link.active { background: rgba(255,255,255,.15); color: #fff; font-weight: 600; border-left: 3px solid #fff; }
.app-sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.15); }
.app-sidebar-user { font-size: 13px; opacity: .8; margin-bottom: 8px; }
.app-sidebar-footer a { color: #fff; }

.app-main { flex: 1; overflow-y: auto; height: 100vh; }
.app-main.no-scroll { overflow: hidden; display: flex; flex-direction: column; }

.container { max-width: 1100px; margin: 24px auto; padding: 0 16px; }

.card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.12);
    padding: 20px;
    margin-bottom: 20px;
}

.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.login-box { width: 340px; }
.login-box h1 { font-size: 20px; margin-bottom: 20px; text-align: center; color: #075e54; }

label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], select, textarea {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid #ccd0d5;
    border-radius: 6px;
    margin-bottom: 14px;
    font-size: 14px;
}
button, .btn {
    background: #075e54;
    color: #fff;
    border: none;
    padding: 9px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    display: inline-block;
}
button:hover, .btn:hover { background: #06463e; text-decoration: none; }
button.secondary, .btn.secondary { background: #667781; }
button.danger, .btn.danger { background: #b33939; }

.input-senha-wrap { position: relative; display: flex; align-items: center; margin-bottom: 14px; }
.input-senha-wrap input { padding-right: 40px; margin-bottom: 0; width: 100%; }
.olho-senha {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #667781;
    font-size: 16px;
    line-height: 1;
    padding: 4px 6px;
    cursor: pointer;
}
.olho-senha:hover { background: none; color: #075e54; }

.error { background: #fdecea; color: #b33939; padding: 10px 12px; border-radius: 6px; margin-bottom: 14px; font-size: 14px; }
.success { background: #e6f4ea; color: #1e7e34; padding: 10px 12px; border-radius: 6px; margin-bottom: 14px; font-size: 14px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #eee; font-size: 14px; }
th { color: #667781; font-weight: 600; font-size: 12px; text-transform: uppercase; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.badge.conectado { background: #e6f4ea; color: #1e7e34; }
.badge.desconectado { background: #fdecea; color: #b33939; }
.badge.fila { background: #fff4e5; color: #b26a00; }
.badge.atendimento { background: #e5f0ff; color: #1552b0; }
.badge.encerrado { background: #eee; color: #667781; }
.badge.aguardando_qr { background: #fff4e5; color: #b26a00; }
.badge.banido { background: #fdecea; color: #b33939; }
.badge.urgencia-alta { background: #fdecea; color: #b33939; }
.badge.urgencia-media { background: #fff4e5; color: #b26a00; }

.resumo-ia { background: #fff8e1; border-bottom: 1px solid #e0e0e0; padding: 10px 20px; font-size: 13px; color: #4a4a4a; display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.resumo-ia .fechar-resumo { background: none; border: none; color: #667781; cursor: pointer; font-size: 16px; padding: 0 4px; }
.transcricao-audio { font-size: 12px; color: #667781; margin-top: 4px; font-style: italic; }

/* Chat layout */
.chat-layout { display: flex; height: 100%; }
.chat-sidebar {
    width: 320px;
    background: #fff;
    border-right: 1px solid #e0e0e0;
    overflow-y: auto;
}
.chat-sidebar .tabs { display: flex; border-bottom: 1px solid #e0e0e0; }
.chat-sidebar .tabs button {
    flex: 1; background: none; color: #667781; border-radius: 0;
    border-bottom: 3px solid transparent; padding: 12px 0;
}
.chat-sidebar .tabs button.active { color: #075e54; border-bottom-color: #075e54; font-weight: 600; }

.conversa-item {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.conversa-item:hover { background: #f5f6f6; }
.conversa-item.active { background: #e9edef; }
.conversa-item .nome { font-weight: 600; font-size: 14px; }
.conversa-item .preview { font-size: 12px; color: #667781; max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-main { flex: 1; display: flex; flex-direction: column; background: #efeae2; }
.chat-header { background: #fff; padding: 14px 20px; border-bottom: 1px solid #e0e0e0; display: flex; justify-content: space-between; align-items: center; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 60%; padding: 8px 12px; border-radius: 8px; font-size: 14px; line-height: 1.4; }
.msg.entrada { background: #fff; align-self: flex-start; }
.msg.saida { background: #d9fdd3; align-self: flex-end; }
.msg .meta { font-size: 10px; color: #667781; margin-top: 4px; display: block; }
.msg .legenda { margin-top: 4px; }
.msg-media-img { max-width: 260px; max-height: 260px; border-radius: 6px; display: block; cursor: pointer; }
.msg-media-sticker { max-width: 120px; max-height: 120px; display: block; }
.msg-media-video { max-width: 280px; border-radius: 6px; display: block; }
.msg audio { max-width: 260px; }
.msg-doc { display: flex; align-items: center; gap: 6px; color: #075e54; font-weight: 600; }
.msg-doc:hover { text-decoration: underline; }

.chat-input { background: #fff; padding: 12px 16px; display: flex; gap: 10px; align-items: center; border-top: 1px solid #e0e0e0; }
.chat-input input[type=text] { margin-bottom: 0; flex: 1; }
.chat-input .secondary { padding: 8px 12px; font-size: 16px; line-height: 1; }
.chat-input .secondary.gravando { background: #b33939; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: #667781; }

.preview-midia { background: #fff; padding: 8px 16px; border-top: 1px solid #e0e0e0; font-size: 13px; color: #667781; display: flex; justify-content: space-between; align-items: center; }
.preview-midia button { padding: 4px 10px; font-size: 12px; }

.qr-box { text-align: center; }
.qr-box img { max-width: 260px; border: 1px solid #eee; padding: 10px; border-radius: 8px; }
.passo-a-passo { text-align: left; max-width: 380px; margin: 20px auto 0; padding-left: 20px; font-size: 13px; color: #4a4a4a; line-height: 1.8; }

/* Painel do atendente (Minhas Conexões) */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-tile {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.12);
    padding: 16px;
    text-align: center;
}
.stat-tile-link { color: inherit; display: flex; flex-direction: column; justify-content: center; transition: transform .1s; }
.stat-tile-link:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 3px 8px rgba(0,0,0,.16); }
.stat-valor { font-size: 28px; font-weight: 700; color: #075e54; line-height: 1.2; }
.stat-rotulo { font-size: 12px; color: #667781; margin-top: 4px; }

.empty-state { text-align: center; padding: 40px 20px; }
.empty-state-icone { font-size: 42px; margin-bottom: 12px; }

.conexoes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }
.conexao-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.12);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    border-left: 4px solid #ccc;
    transition: border-color .2s;
}
.conexao-card-conectado { border-left-color: #1e7e34; }
.conexao-card-desconectado { border-left-color: #b33939; }
.conexao-card-aguardando_qr { border-left-color: #b26a00; }
.conexao-card-banido { border-left-color: #b33939; }

.conexao-card-topo { display: flex; justify-content: space-between; align-items: center; }
.conexao-card-info { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #4a4a4a; }
.conexao-card-acoes { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }
.conexao-card-acoes .btn, .conexao-card-acoes button { font-size: 13px; padding: 6px 12px; }

.avatar-conexao {
    position: relative;
    width: 40px; height: 40px;
    border-radius: 50%;
    background: #075e54;
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 16px;
    flex-shrink: 0;
}
.ponto-status { position: absolute; bottom: -1px; right: -1px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; background: #ccc; }
.ponto-conectado { background: #1e7e34; animation: pulso 1.6s infinite; }
.ponto-desconectado, .ponto-banido { background: #b33939; }
.ponto-aguardando_qr { background: #b26a00; }
@keyframes pulso {
    0% { box-shadow: 0 0 0 0 rgba(30,126,52,.5); }
    70% { box-shadow: 0 0 0 6px rgba(30,126,52,0); }
    100% { box-shadow: 0 0 0 0 rgba(30,126,52,0); }
}

.qr-inline { text-align: center; }
.qr-inline img { max-width: 140px; border: 1px solid #eee; border-radius: 6px; padding: 6px; }

.link-historico { background: none; border: none; color: #075e54; font-size: 12px; text-align: left; padding: 0; cursor: pointer; }
.link-historico:hover { text-decoration: underline; }
.historico-lista { display: flex; flex-direction: column; gap: 6px; font-size: 12px; background: #f5f6f6; border-radius: 6px; padding: 8px 10px; }
.historico-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.grafico-wrap { overflow-x: auto; }
.grafico-svg { width: 100%; height: 180px; display: block; }
.barra-grafico { transition: fill .15s; }
.barra-grafico:hover { fill: #06463e; }

.toast-alerta {
    position: fixed; top: 16px; right: 16px; z-index: 999;
    background: #b33939; color: #fff; padding: 12px 18px; border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,.2);
    font-size: 13px; max-width: 320px;
    animation: entrar-toast .2s ease-out;
}
@keyframes entrar-toast { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
