:root {
  --green: #00a884; --green-d: #008069; --bg: #f0f2f5; --panel: #fff; --line: #e9edef;
  --text: #111b21; --muted: #667781; --chat-bg: #efeae2; --out: #d9fdd3; --in: #fff; --danger: #e5484d;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--text); background: var(--bg); font-size: 14px; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .bold { font-weight: 600; }
.error { color: var(--danger); min-height: 1em; }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; border: 1px solid #d1d7db; border-radius: 8px; padding: 9px 11px; width: 100%; background: #fff; color: var(--text); }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--green); border-color: transparent; }

.btn { border: 1px solid #d1d7db; background: #fff; border-radius: 8px; padding: 7px 14px; white-space: nowrap; }
.btn:hover { background: #f5f6f6; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-d); }
.btn.danger { color: var(--danger); border-color: #f3c1c2; }
.icon-btn { border: 0; background: transparent; font-size: 18px; color: #54656f; width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.icon-btn:hover { background: rgba(0,0,0,.06); }

/* login */
.login { height: 100%; display: flex; align-items: center; justify-content: center; background: linear-gradient(var(--green) 0 220px, var(--bg) 220px); }
.login-card { background: #fff; padding: 32px; border-radius: 12px; width: min(380px, 92vw); display: flex; flex-direction: column; gap: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.12); }
.brand { font-size: 24px; }

/* layout */
.app { display: flex; height: 100%; }
.sidebar { width: 380px; min-width: 300px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: var(--bg); }
.me { display: flex; gap: 10px; align-items: center; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: #dfe5e7; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.wa-status { font-size: 12px; color: var(--muted); }
.wa-status.ok { color: var(--green); } .wa-status.bad { color: var(--danger); }
.tabs { display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tab { border: 0; background: var(--bg); padding: 6px 12px; border-radius: 16px; color: var(--muted); white-space: nowrap; }
.tab.active { background: #d9fdd3; color: var(--green-d); font-weight: 600; }
.tab .count { background: var(--green); color: #fff; border-radius: 10px; padding: 0 6px; margin-left: 4px; font-size: 11px; }
.search { padding: 8px 10px; }
.search input { background: var(--bg); border: 0; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv:hover { background: #f5f6f6; } .conv.active { background: #f0f2f5; }
.conv .mid { flex: 1; min-width: 0; }
.conv .row { display: flex; justify-content: space-between; gap: 8px; }
.conv .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .last { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.conv .time { color: var(--muted); font-size: 11px; white-space: nowrap; }
.conv .unread { background: var(--green); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.chip { display: inline-block; font-size: 10px; padding: 1px 7px; border-radius: 8px; color: #fff; margin-right: 4px; font-weight: 600; }
.chip.gray { background: #8696a0; } .chip.tag { background: #e7f3ff; color: #1a5fb4; }
.empty-list { padding: 30px; text-align: center; color: var(--muted); }

/* chat */
.chat { flex: 1; display: flex; flex-direction: column; background: var(--chat-bg); min-width: 0; position: relative; }
.empty { margin: auto; text-align: center; padding: 20px; } .empty .big { font-size: 64px; }
.chat-inner { display: flex; flex-direction: column; height: 100%; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--bg); border-left: 1px solid var(--line); }
.chat-title { flex: 1; min-width: 0; cursor: pointer; }
.chat-title > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-actions { display: flex; gap: 6px; align-items: center; }
.back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 4px; }
.msg { max-width: 65%; padding: 6px 9px 4px; border-radius: 8px; box-shadow: 0 1px .5px rgba(0,0,0,.13); background: var(--in); align-self: flex-start; word-wrap: break-word; white-space: pre-wrap; }
.msg.out { background: var(--out); align-self: flex-end; }
.msg.bot { background: #fff7d6; }
.msg .author { font-size: 12px; font-weight: 600; color: var(--green-d); margin-bottom: 2px; }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg img, .msg video { max-width: 280px; max-height: 320px; border-radius: 6px; display: block; }
.msg audio { width: 260px; }
.msg a { color: #027eb5; }
.sys { align-self: center; background: #e1f2fb; color: #54656f; font-size: 12px; padding: 4px 10px; border-radius: 8px; margin: 6px 0; }
.day { align-self: center; background: #fff; color: var(--muted); font-size: 12px; padding: 4px 10px; border-radius: 8px; margin: 8px 0; box-shadow: 0 1px .5px rgba(0,0,0,.1); }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 14px; background: var(--bg); }
.composer textarea { resize: none; max-height: 140px; border: 0; }
.send { border-radius: 50%; width: 42px; height: 42px; padding: 0; }
.qr-pop { position: absolute; bottom: 64px; left: 14px; right: 14px; background: #fff; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.18); max-height: 260px; overflow-y: auto; z-index: 5; }
.qr-pop div { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.qr-pop div:hover, .qr-pop div.sel { background: #f0f2f5; }
.qr-pop b { color: var(--green-d); }

/* info */
.info { width: 320px; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.info-head { display: flex; justify-content: space-between; align-items: center; padding: 14px; background: var(--bg); }
.info-body { padding: 14px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.info-body label, .modal label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(11,20,26,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: min(860px, 96vw); max-height: 92vh; overflow: hidden; display: flex; flex-direction: column; }
.modal.small { width: min(440px, 94vw); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.admin-wrap { display: flex; min-height: 480px; }
.admin-nav { width: 190px; background: var(--bg); padding: 10px; display: flex; flex-direction: column; gap: 4px; }
.admin-nav button { text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 8px; }
.admin-nav button.active { background: #fff; font-weight: 600; color: var(--green-d); }
.admin-content { flex: 1; padding: 18px; overflow-y: auto; max-height: 80vh; display: flex; flex-direction: column; gap: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { flex-direction: row !important; align-items: center; color: var(--text) !important; font-size: 14px !important; }
.checks input { width: auto; }
.qr-box { text-align: center; padding: 10px; }
.qr-box img { width: 280px; height: 280px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--bg); border-radius: 10px; padding: 14px; }
.stat b { font-size: 26px; display: block; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111b21; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 99; max-width: 90vw; }

/* mobile */
@media (max-width: 820px) {
  .sidebar { width: 100%; min-width: 0; }
  .chat { position: fixed; inset: 0; z-index: 10; }
  .app:not(.chat-open) .chat { display: none; }
  .back { display: inline-flex; }
  .chat-actions .btn { padding: 6px 8px; font-size: 12px; }
  .info { position: fixed; inset: 0; width: 100%; z-index: 20; }
  .msg { max-width: 85%; }
  .admin-wrap { flex-direction: column; }
  .admin-nav { width: 100%; flex-direction: row; overflow-x: auto; }
}
.presence-toggle {
  min-height: 32px;
  margin: 8px 10px 0;
  border: 1px solid #cfd8df;
  border-radius: 7px;
  background: #f5f7f9;
  color: #435564;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.presence-toggle[aria-pressed="true"] {
  background: #e5f8f1;
  border-color: #a6decc;
  color: #076b58;
}
