:root {
  --bg: #eaf2fb; --card: #fff; --border: #dfeaec; --text: #0f172a; --muted: #64748b;
  --primary: #0aa5ba; --primary-dark: #077885; --primary-light: #e0f5f8;
  --danger: #dc2626; --warn: #d97706; --ok: #16a34a; --radius: 10px;
  --in: #ffffff; --out: #d9f7ee; --nota: #fff7d6;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.erro { color: var(--danger); min-height: 1em; }
h2 { margin: 0 0 12px; font-size: 20px; }
h3 { margin: 0 0 10px; font-size: 15px; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-light); border-color: var(--primary); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

.btn { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--primary-light); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 4px 10px; font-size: 13px; }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(circle at 20% 15%, #0f8a9c, #075866 45%, #052f38); padding: 16px; }
.login-box { background: #fff; border-radius: 16px; padding: 28px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-box h1 { margin: 0; font-size: 20px; }
.login-box p { margin: 0; }
.login-box label { text-align: left; }
.login-logo { height: 56px; align-self: center; }

/* topo */
#app { display: flex; flex-direction: column; height: 100vh; }
.topo { display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: #fff; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { height: 34px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text span { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
nav button { font: inherit; border: 0; background: transparent; color: var(--muted); padding: 7px 12px; border-radius: 8px; cursor: pointer; }
nav button:hover { background: var(--primary-light); }
nav button.ativo { background: var(--primary); color: #fff; }
.me { display: flex; align-items: center; gap: 12px; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: #f1f5f9; color: var(--muted); }
.pill.ok { background: #dcfce7; color: #166534; }
.pill.alerta { background: #fef3c7; color: #92400e; }
.pill.ruim { background: #fee2e2; color: #991b1b; }
.switch { flex-direction: row; align-items: center; gap: 6px; cursor: pointer; color: var(--text); }

.view { flex: 1; min-height: 0; }
.pad { padding: 20px; overflow: auto; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }

/* atendimento */
.atendimento { display: grid; grid-template-columns: 320px minmax(0, 1fr) 300px; }
.lista { background: #fff; border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.abas { display: flex; border-bottom: 1px solid var(--border); }
.abas button { flex: 1; font: inherit; font-size: 13px; padding: 10px 4px; border: 0; background: none; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.abas button.ativo { color: var(--primary-dark); border-bottom-color: var(--primary); font-weight: 600; }
.abas b { background: #f1f5f9; border-radius: 999px; padding: 0 6px; font-size: 11px; }
.filtros { display: flex; flex-direction: column; gap: 6px; margin: 8px; }
.filtros select, .filtros input { width: 100%; }
#conversas { list-style: none; margin: 0; padding: 0; overflow-y: auto; overflow-x: hidden; flex: 1; }
#conversas li { padding: 10px 12px; border-bottom: 1px solid #f1f5f9; cursor: pointer; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; }
#conversas li:hover { background: #f8fafc; }
#conversas li.sel { background: var(--primary-light); }
#conversas .nome { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#conversas .prev { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#conversas .meta { font-size: 11px; color: var(--muted); text-align: right; }
#conversas .badge { background: var(--primary); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; justify-self: end; }
#conversas .linha3 { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 10px; text-transform: uppercase; letter-spacing: .03em; padding: 1px 6px; border-radius: 4px; background: #f1f5f9; color: var(--muted); }
.tag.tag-num { background: #e0f5f8; color: #077885; }
.tag.tag-sim { background: #ede9fe; color: #5b21b6; }
.tag.sla { background: #fee2e2; color: #991b1b; }
.tag.st-fila { background: #fef3c7; color: #92400e; }
.tag.st-triagem { background: #e0e7ff; color: #3730a3; }
.tag.st-em_atendimento { background: #dcfce7; color: #166534; }
.tag.st-pesquisa { background: #fae8ff; color: #86198f; }

.chat { display: flex; flex-direction: column; min-height: 0; background: #f4f8f9; }
.vazio { margin: auto; color: var(--muted); }
.chat-topo { padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chat-topo .t { flex: 1; min-width: 0; }
.chat-topo .t b { display: block; }
.msgs { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 70%; padding: 6px 10px 4px; border-radius: 10px; background: var(--in); box-shadow: 0 1px 1px rgba(0,0,0,.06); white-space: pre-wrap; word-wrap: break-word; }
.msg.out { align-self: flex-end; background: var(--out); }
.msg.nota { align-self: center; background: var(--nota); border: 1px dashed #e5c84b; max-width: 85%; }
.msg.sistema { align-self: center; background: transparent; box-shadow: none; color: var(--danger); font-size: 12px; }
.msg .rod { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg .autor { font-size: 11px; font-weight: 600; color: var(--primary-dark); }
.midia { margin: 2px 0 4px; }
.midia img.imagem { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; }
.midia img.figurinha { width: 120px; height: 120px; object-fit: contain; display: block; }
.midia video { max-width: 280px; max-height: 260px; border-radius: 8px; display: block; }
.midia audio { width: 240px; max-width: 100%; display: block; }
.midia .doc { display: inline-block; padding: 8px 10px; background: rgba(0,0,0,.05); border-radius: 8px; color: var(--primary-dark); text-decoration: none; word-break: break-all; }
.linha-btn { display: flex; gap: 6px; }
.evt { align-self: center; font-size: 11px; color: var(--muted); background: #e8eef0; border-radius: 999px; padding: 2px 10px; }
.envio { display: flex; gap: 8px; padding: 10px; background: #fff; border-top: 1px solid var(--border); align-items: flex-end; }
.envio textarea { flex: 1; resize: none; min-height: 40px; max-height: 140px; }
.envio.nota-on textarea { background: var(--nota); }
.envio .op { display: flex; flex-direction: column; gap: 6px; }
.aviso-envio { padding: 12px; text-align: center; background: #fff; border-top: 1px solid var(--border); }

.detalhes { background: #fff; border-left: 1px solid var(--border); padding: 16px; overflow: auto; }
.detalhes dl { margin: 0 0 16px; display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; font-size: 13px; }
.detalhes dt { color: var(--muted); }
.detalhes dd { margin: 0; word-break: break-all; }
.detalhes h4 { margin: 16px 0 6px; font-size: 12px; text-transform: uppercase; color: var(--muted); }
.detalhes ul { padding-left: 16px; margin: 0; font-size: 12px; color: var(--muted); }

/* painel */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.kpi span { font-size: 12px; color: var(--muted); display: block; }
.kpi b { font-size: 24px; font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid #f1f5f9; font-size: 13px; }
th { background: #f8fafc; text-transform: uppercase; font-size: 11px; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* simulador */
.sim { display: grid; grid-template-columns: 300px 380px; gap: 16px; align-items: start; }
.sim form.card { display: flex; flex-direction: column; gap: 10px; }
.atalhos { display: flex; gap: 6px; flex-wrap: wrap; }
.celular { background: #efeae2; border: 8px solid #1f2937; border-radius: 24px; height: 560px; display: flex; flex-direction: column; overflow: hidden; }
.cel-topo { background: #075e54; color: #fff; padding: 10px 14px; font-weight: 600; }
.cel-msgs { flex: 1; overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.cel-msgs .msg { max-width: 85%; }
.cel-msgs .msg.in { align-self: flex-end; background: #d9fdd3; }
.cel-msgs .msg.out { align-self: flex-start; background: #fff; }
.cel-envio { display: flex; gap: 6px; padding: 8px; background: #f0f2f5; }
.cel-envio input { flex: 1; }

/* conectores */
.conexoes { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; margin-bottom: 16px; }
.conector { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.conector .cab { display: flex; align-items: center; gap: 8px; }
.conector .cab b { flex: 1; font-size: 15px; }
.conector .qr { width: 100%; max-width: 300px; height: auto; aspect-ratio: 1; align-self: center; }
.conector .qr img { width: 100%; height: auto; }
.passos-card ol { margin: 6px 0 0; }
/* conexão */
.conexao { display: grid; grid-template-columns: 1fr 340px; gap: 24px; max-width: 900px; }
.acoes { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.passos { padding-left: 18px; }
.qr { width: 320px; height: 320px; display: grid; place-items: center; border: 1px dashed var(--border); border-radius: var(--radius); background: #fff; }
.qr img { width: 300px; height: 300px; }

.tabela-rolavel { overflow-x: auto; }
.canais { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.canais label, .canais-novo label { flex-direction: row; align-items: center; gap: 4px; color: var(--text); white-space: nowrap; }
.canais-novo { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; width: 100%; }
.acoes-linha { display: flex; gap: 6px; flex-wrap: wrap; }
.form-linha { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form-linha h3 { width: 100%; }
.config { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; max-width: 1000px; }
.config textarea { min-height: 80px; }
.config .full { grid-column: 1 / -1; }

.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-box { background: #fff; border-radius: 14px; padding: 20px; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px; }
.modal-box .acoes { justify-content: flex-end; margin: 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #0b3a42; color: #fff; padding: 10px 18px; border-radius: 999px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20; }
.toast.on { opacity: 1; }

@media (max-width: 1100px) {
  .atendimento { grid-template-columns: 280px 1fr; }
  .detalhes { display: none; }
  .grid2, .conexao, .sim, .config { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .atendimento { grid-template-columns: 1fr; }
  .atendimento.aberta .lista { display: none; }
  .atendimento:not(.aberta) .chat { display: none; }
}
