:root {
  --bg: #f0f2f5; --panel: #fff; --line: #e3e6ea; --text: #1d2329; --muted: #6b7680;
  --brand: #0f7a5c; --brand-2: #0b5e47; --in: #fff; --out: #d9fdd3; --note: #fff6c8;
  --danger: #c0392b; --warn: #b26a00; --chat: #efeae2; --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px 12px; }
button:hover { background: #f5f6f7; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: var(--brand-2); }
button.danger { color: var(--danger); border-color: #e8c2bd; }
button.small { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { border: 1px solid #cfd4d9; border-radius: 6px; padding: 7px 9px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9fd8c6; border-color: var(--brand); }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
label.check input { width: auto; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: #f3f4f5; padding: 2px 5px; border-radius: 4px; word-break: break-all; }

/* login */
.login { max-width: 360px; margin: 10vh auto; background: var(--panel); padding: 28px; border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,.06); }
.login h1 { margin: 0 0 4px; font-size: 22px; color: var(--brand); }
.login button { width: 100%; margin-top: 18px; padding: 10px; }
.error { color: var(--danger); margin-top: 10px; min-height: 18px; }

/* layout */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar { display: flex; align-items: center; gap: 6px; background: var(--brand); color: #fff; padding: 0 12px; height: 48px; flex: none; }
.topbar .brand { font-weight: 700; margin-right: 14px; }
.topbar button { background: transparent; color: #fff; border-color: transparent; }
.topbar button.on, .topbar button:hover { background: rgba(255,255,255,.15); }
.topbar .who { margin-left: auto; font-size: 13px; opacity: .9; }
.main { flex: 1; display: flex; min-height: 0; }
.page { flex: 1; overflow: auto; padding: 18px; }

.sidebar { width: 340px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; border-radius: 0; padding: 10px 2px; font-size: 13px; background: none; border-bottom: 2px solid transparent; }
.tabs button.on { border-bottom-color: var(--brand); color: var(--brand); font-weight: 600; }
.tabs .count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: #e7ebee; font-size: 11px; margin-left: 3px; }
.tabs button.on .count { background: var(--brand); color: #fff; }
.search { padding: 8px; display: flex; gap: 6px; border-bottom: 1px solid var(--line); }
.list { flex: 1; overflow-y: auto; }
.item { padding: 10px 12px; border-bottom: 1px solid #f1f2f4; cursor: pointer; display: flex; gap: 10px; }
.item:hover { background: #f7f8f9; }
.item.on { background: #e9f5f0; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: #cfe6dd; color: var(--brand-2); display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.item .info { flex: 1; min-width: 0; }
.item .top { display: flex; justify-content: space-between; gap: 6px; }
.item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .time { font-size: 11px; color: var(--muted); flex: none; }
.item .prev { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: 2px; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 9px; background: #e7ebee; color: #444; white-space: nowrap; }
.badge.bot { background: #e4e7fb; color: #3949ab; }
.badge.queue { background: #fdeccc; color: var(--warn); }
.badge.open { background: #d8f2e7; color: var(--brand-2); }
.badge.closed { background: #eee; color: #777; }
.unread { background: #25d366; color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* chat */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--chat); }
.chat-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 8px 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chat-head .title { flex: 1; min-width: 160px; }
.chat-head .title b { display: block; }
.chat-head .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 6%; display: flex; flex-direction: column; gap: 4px; }
.bubble { max-width: 70%; padding: 6px 9px 4px; border-radius: 8px; background: var(--in); box-shadow: 0 1px 1px rgba(0,0,0,.08); align-self: flex-start; white-space: pre-wrap; word-wrap: break-word; position: relative; }
.bubble.out { background: var(--out); align-self: flex-end; }
.bubble.note { align-self: center; background: var(--note); font-size: 12px; max-width: 85%; text-align: center; box-shadow: none; }
.bubble .who { font-size: 11px; font-weight: 700; color: var(--brand-2); margin-bottom: 2px; }
.bubble .who.bot { color: #3949ab; }
.bubble .foot { font-size: 10.5px; color: var(--muted); text-align: right; margin-top: 2px; }
.bubble .err { color: var(--danger); font-size: 11px; }
.bubble img, .bubble video { max-width: 280px; max-height: 320px; border-radius: 6px; display: block; cursor: pointer; }
.bubble audio { width: 260px; }
.tick.read { color: #34b7f1; }
.day { align-self: center; background: #e1f2fb; font-size: 11.5px; padding: 3px 10px; border-radius: 6px; margin: 8px 0; color: #4a5560; }
.composer { background: #f0f2f5; padding: 8px 12px; border-top: 1px solid var(--line); position: relative; }
.composer .row { align-items: flex-end; }
.composer textarea { resize: none; max-height: 160px; min-height: 40px; }
.composer.note-mode textarea { background: var(--note); }
.warnbar { background: #fff3cd; color: #6b4e00; padding: 8px 12px; font-size: 13px; display: flex; align-items: center; gap: 10px; }
.quick { position: absolute; bottom: 100%; left: 12px; right: 12px; background: #fff; border: 1px solid var(--line); border-radius: 8px; max-height: 220px; overflow-y: auto; box-shadow: 0 -4px 12px rgba(0,0,0,.08); }
.quick div { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid #f2f2f2; }
.quick div:hover, .quick div.on { background: #e9f5f0; }
.placeholder { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); background: #f7f8f9; }

/* páginas */
.card { background: var(--panel); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; border: 1px solid var(--line); max-width: 920px; }
.card h2 { margin: 0 0 6px; font-size: 16px; }
.card h3 { margin: 16px 0 4px; font-size: 14px; }
.subtabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.subtabs button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid th { font-size: 12px; color: var(--muted); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.help { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 480px; max-height: 90vh; overflow: auto; padding: 18px; }
.modal h3 { margin: 0 0 8px; }
.modal .buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #263238; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; max-width: 90vw; }
.toast.err { background: var(--danger); }
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 70; display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
.viewer img { max-width: 95vw; max-height: 95vh; }

@media (max-width: 760px) {
  .sidebar { width: 100%; }
  .main.chat-open .sidebar { display: none; }
  .main:not(.chat-open) .chat, .main:not(.chat-open) .placeholder { display: none; }
  .msgs { padding: 10px; }
  .bubble { max-width: 88%; }
  .grid2 { grid-template-columns: 1fr; }
  .topbar .brand, .topbar .who { display: none; }
  .topbar { gap: 2px; padding: 0 6px; }
  .topbar button { padding: 6px 8px; }
  .topbar #logout { margin-left: auto; }
  .composer .row { flex-wrap: wrap; }
  .composer textarea { order: -1; flex-basis: 100%; }
  .composer #send { margin-left: auto; }
  .back { display: inline-block !important; }
}
.back { display: none; }

/* edição e exclusão: nada some, fica riscado */
.bubble .old { text-decoration: line-through; color: var(--muted); font-size: 12.5px; }
.bubble.deleted .txt, .bubble.deleted img, .bubble.deleted audio, .bubble.deleted video, .bubble.deleted a { text-decoration: line-through; opacity: .55; }
.bubble .tag { font-size: 10.5px; color: var(--muted); font-style: italic; }
.bubble .tag.del { color: var(--danger); }
.bubble .acts { display: none; gap: 4px; margin-top: 4px; justify-content: flex-end; }
.bubble:hover .acts { display: flex; }
.bubble .acts button { padding: 1px 6px; font-size: 11px; background: rgba(255,255,255,.7); }
@media (hover: none) { .bubble .acts { display: flex; } }

pre.terms { white-space: pre-wrap; font-family: inherit; font-size: 13px; line-height: 1.5; background: #f7f8f9; border: 1px solid var(--line); border-radius: 8px; padding: 14px; max-height: 50vh; overflow: auto; }
a.small { font-size: 12px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; color: inherit; }

.qr { background: #fff; display: inline-block; padding: 6px; border: 1px solid var(--line); border-radius: 8px; }
.qr svg { display: block; width: 220px; height: 220px; }
