:root {
  --side: #2b313b; --side-2: #353c48; --side-text: #c4cad4; --side-muted: #8b94a3;
  --bg: #f4f6f9; --card: #fff; --line: #e4e8ee; --text: #1f2933; --muted: #6b7684;
  --accent: #1a9e83; --accent-2: #138a71; --accent-soft: #e3f5f0;
  --blue: #5b6ee1; --red: #e04b5a; --yellow: #f2b51c; --orange: #f08a24;
  --chat-bg: #efeae2; --bubble-in: #fff; --bubble-out: #d9fdd3; --note: #fff6d6;
  --radius: 10px; --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--accent-2); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.grow { flex: 1; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox], input[type=radio] { width: auto; }
input[type=color] { padding: 2px; height: 36px; }
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 12px; }
label > input, label > select, label > textarea { margin-top: 5px; font-weight: 400; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 600; white-space: nowrap; text-decoration: none; color: var(--text);
}
.btn:hover { background: #f7f8fa; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; font-size: 18px; cursor: pointer; padding: 6px 9px; border-radius: 8px; line-height: 1; }
.icon-btn:hover { background: rgba(0,0,0,.06); }
.error { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; background: linear-gradient(135deg, #2b313b, #1a9e83); padding: 16px; }
.login-card { background: #fff; width: 100%; max-width: 380px; padding: 32px; border-radius: 16px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card h1 { margin: 6px 0 2px; font-size: 22px; }
.login-card p { margin: 0 0 20px; }
.login-logo { font-size: 40px; }

/* Layout */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 230px; background: var(--side); color: var(--side-text); flex-shrink: 0; overflow-y: auto; transition: margin .2s; }
.app.collapsed .sidebar { margin-left: -230px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; font-weight: 700; font-size: 17px; color: #fff; border-bottom: 1px solid rgba(255,255,255,.06); }
.brand-icon { background: var(--accent); width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-size: 17px; }
.nav-section { font-size: 11px; color: var(--side-muted); padding: 18px 22px 6px; letter-spacing: .06em; }
.sidebar nav a { display: flex; align-items: center; gap: 12px; padding: 10px 22px; color: var(--side-text); text-decoration: none; position: relative; }
.sidebar nav a i { font-style: normal; width: 20px; text-align: center; filter: grayscale(.3); }
.sidebar nav a:hover { background: var(--side-2); color: #fff; }
.sidebar nav a.active { background: var(--side-2); color: #fff; box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
.nav-badge { margin-left: auto; background: var(--accent); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-left: auto; background: #6b7280; }
.dot.ok { background: #22c55e; } .dot.warn { background: var(--yellow); } .dot.bad { background: var(--red); }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 58px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 0 16px; gap: 10px; flex-shrink: 0; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: #22c55e; }
.conn.off { background: var(--red); }
.user-menu { position: relative; }
.user-btn { border: 0; background: #f1f3f6; border-radius: 20px; padding: 4px 12px 4px 4px; display: flex; gap: 8px; align-items: center; cursor: pointer; }
.dropdown { position: absolute; right: 0; top: 44px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.12); min-width: 200px; z-index: 50; overflow: hidden; }
.dropdown a { display: block; padding: 10px 14px; color: var(--text); text-decoration: none; }
.dropdown a:hover { background: var(--bg); }
.view { flex: 1; overflow: auto; padding: 20px; }
.view.full { padding: 12px; overflow: hidden; }
.page-title { font-size: 18px; font-weight: 700; margin: 0 0 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; }

/* Avatares, etiquetas */
.avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex-shrink: 0; font-size: 15px; position: relative; }
.avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.avatar .ch { position: absolute; right: -3px; bottom: -3px; width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff; font-size: 9px; display: grid; place-items: center; }
.ch.meta { background: #25d366; } .ch.qr { background: #5b6ee1; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 12px; font-size: 11.5px; font-weight: 600; color: #fff; white-space: nowrap; }
.tag.light { color: #222; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; background: #eef0f4; color: var(--muted); }
.pill.green { background: #dcfce7; color: #166534; } .pill.red { background: #fee2e2; color: #991b1b; } .pill.blue { background: #e0e7ff; color: #3730a3; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; padding: 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:hover td { background: #fafbfc; }
.actions { display: flex; gap: 6px; justify-content: flex-end; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; flex-wrap: wrap; gap: 8px; }
.switch { position: relative; width: 40px; height: 22px; display: inline-block; margin: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cbd2dc; border-radius: 22px; cursor: pointer; transition: .2s; }
.switch span:before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--blue); }
.switch input:checked + span:before { transform: translateX(18px); }

/* Dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; position: relative; }
.stat .n { font-size: 28px; font-weight: 700; }
.stat .l { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; margin-top: 4px; }
.stat .ic { position: absolute; right: 16px; top: 14px; font-size: 22px; opacity: .7; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 170px; padding-top: 10px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bars .pair { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bars .b { width: 40%; max-width: 22px; border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .b.in { background: var(--blue); } .bars .b.out { background: var(--accent); }
.bars .d { font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.hbar { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.hbar .track { flex: 1; height: 8px; background: #eef0f4; border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 4px; }
.hbar .nm { width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.hbar .v { width: 34px; text-align: right; font-weight: 700; font-size: 13px; }

/* Chat */
.chat { display: flex; height: 100%; gap: 0; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.chat-list { width: 340px; border-right: 1px solid var(--line); display: flex; flex-direction: column; flex-shrink: 0; }
.chat-list-head { padding: 10px; border-bottom: 1px solid var(--line); }
.search-row { display: flex; gap: 6px; }
.search-row input { background: #f1f3f6; border-color: transparent; border-radius: 20px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: thin; }
.chip { border: 0; background: #eef0f4; border-radius: 16px; padding: 5px 11px; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.chip.active { background: var(--side); color: #fff; }
.active-filters { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.conv-items { flex: 1; overflow-y: auto; }
.conv { display: flex; gap: 10px; padding: 11px 12px; border-bottom: 1px solid #f0f2f5; cursor: pointer; align-items: center; }
.conv:hover { background: #f7f8fa; }
.conv.sel { background: #eaf6f3; }
.conv .body { flex: 1; min-width: 0; }
.conv .top { display: flex; justify-content: space-between; gap: 6px; }
.conv .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .tm { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.conv .bot { display: flex; justify-content: space-between; gap: 6px; align-items: center; margin-top: 2px; }
.conv .pv { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv.unread .pv { color: var(--text); font-weight: 600; }
.unread-b { background: var(--accent); color: #fff; border-radius: 10px; min-width: 20px; height: 20px; font-size: 11px; font-weight: 700; display: grid; place-items: center; padding: 0 6px; }
.conv .tagdots { display: flex; gap: 3px; margin-top: 4px; flex-wrap: wrap; }
.conv .tagdots .tag { font-size: 10px; padding: 1px 6px; }
.tick { font-size: 12px; color: #8696a0; letter-spacing: -3px; margin-right: 3px; }
.tick.read { color: #34b7f1; } .tick.failed { color: var(--red); letter-spacing: 0; }
.list-empty { padding: 30px; text-align: center; color: var(--muted); }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-empty { flex: 1; display: grid; place-items: center; font-size: 26px; color: var(--muted); background: #f7f8fa; text-align: center; }
.chat-head { padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.chat-head .who { flex: 1; min-width: 160px; cursor: pointer; }
.chat-head .who b { font-size: 15px; }
.chat-head .who .ph { font-size: 12px; color: var(--muted); }
.chat-head .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.chat-head select { width: auto; padding: 6px 8px; font-size: 13px; }
.msgs { flex: 1; overflow-y: auto; padding: 16px 6%; background: var(--chat-bg); background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px); background-size: 18px 18px; }
.day-sep { text-align: center; margin: 12px 0; }
.day-sep span { background: #fff; padding: 4px 12px; border-radius: 8px; font-size: 12px; color: var(--muted); box-shadow: var(--shadow); }
.msg { display: flex; margin: 4px 0; }
.msg.out { justify-content: flex-end; }
.bubble { max-width: 68%; padding: 7px 10px 5px; border-radius: 9px; box-shadow: 0 1px .5px rgba(0,0,0,.13); background: var(--bubble-in); word-wrap: break-word; overflow-wrap: anywhere; position: relative; }
.msg.out .bubble { background: var(--bubble-out); }
.msg.note .bubble { background: var(--note); border: 1px dashed #e0c25a; }
.msg.note { justify-content: flex-end; }
.msg.system { justify-content: center; }
.msg.system .bubble { background: #e1f0ff; color: #33507a; font-size: 12px; box-shadow: none; max-width: 80%; text-align: center; }
.bubble .txt { white-space: pre-wrap; }
.bubble .meta { font-size: 10.5px; color: #667781; text-align: right; margin-top: 2px; display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.bubble .who { font-size: 11px; font-weight: 700; color: var(--accent-2); margin-bottom: 2px; }
.bubble img, .bubble video { max-width: 280px; max-height: 300px; border-radius: 6px; display: block; margin-bottom: 4px; cursor: pointer; }
.bubble audio { max-width: 260px; display: block; }
.bubble .doc { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.05); padding: 8px 10px; border-radius: 6px; margin-bottom: 4px; text-decoration: none; color: var(--text); }
.bubble .err { color: var(--red); font-size: 11.5px; margin-top: 3px; }
.load-more { text-align: center; margin-bottom: 8px; }
.window-warn { background: #e8f1ff; color: #24427a; padding: 10px 14px; font-size: 13px; display: flex; gap: 10px; align-items: center; border-top: 1px solid #cfe0ff; flex-wrap: wrap; }
.composer { border-top: 1px solid var(--line); padding: 8px 10px; background: #f7f8fa; position: relative; }
.composer.note-mode { background: #fff8e1; }
.composer-row { display: flex; gap: 6px; align-items: flex-end; }
.composer textarea { resize: none; min-height: 42px; max-height: 160px; border-radius: 20px; padding: 10px 14px; }
.composer .send { border-radius: 50%; width: 42px; height: 42px; padding: 0; justify-content: center; font-size: 17px; flex-shrink: 0; }
.composer-tools { display: flex; gap: 4px; align-items: center; margin-bottom: 4px; font-size: 12px; }
.attach-preview { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin-bottom: 6px; font-size: 13px; }
.qr-pop { position: absolute; bottom: 100%; left: 10px; right: 10px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 -6px 24px rgba(0,0,0,.12); max-height: 280px; overflow-y: auto; z-index: 20; }
.qr-pop div { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid #f2f3f5; }
.qr-pop div:hover, .qr-pop div.hl { background: var(--accent-soft); }
.qr-pop b { display: block; font-size: 13px; }
.qr-pop small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-info { width: 300px; border-left: 1px solid var(--line); overflow-y: auto; padding: 16px; flex-shrink: 0; background: #fff; }
.chat-info h4 { margin: 18px 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tag-toggle { display: flex; gap: 6px; flex-wrap: wrap; }
.tag-toggle .tag { cursor: pointer; opacity: .35; }
.tag-toggle .tag.on { opacity: 1; }
.closure { font-size: 12.5px; border-left: 3px solid var(--line); padding: 4px 8px; margin-bottom: 8px; }
.back-btn { display: none; }

/* Canales */
.qr-box { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.qr-box img { width: 260px; height: 260px; border: 1px solid var(--line); border-radius: 12px; }
.code { font-family: Consolas, monospace; background: #f1f3f6; padding: 8px 10px; border-radius: 6px; word-break: break-all; font-size: 12.5px; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.help { font-size: 13px; color: var(--muted); line-height: 1.55; }
.help ol { padding-left: 18px; margin: 6px 0; }
.mode-opts { display: flex; gap: 10px; flex-wrap: wrap; }
.mode-opt { flex: 1; min-width: 200px; border: 2px solid var(--line); border-radius: 10px; padding: 12px; cursor: pointer; font-weight: 400; margin: 0; }
.mode-opt.on { border-color: var(--accent); background: var(--accent-soft); }
.mode-opt b { display: block; margin-bottom: 4px; }

/* Modal, toasts */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 25px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 760px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 16px; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1f2933; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 360px; animation: up .2s; cursor: pointer; }
.toast.err { background: var(--red); } .toast.ok { background: var(--accent-2); }
@keyframes up { from { transform: translateY(10px); opacity: 0; } }
.img-view { max-width: 92vw; max-height: 88vh; border-radius: 8px; }

@media (max-width: 1200px) { .chat-info { position: absolute; right: 12px; top: 70px; bottom: 12px; z-index: 30; box-shadow: -8px 0 30px rgba(0,0,0,.12); border-radius: 0 var(--radius) var(--radius) 0; } }
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 60; height: 100%; margin-left: -230px; }
  .app.menu-open .sidebar { margin-left: 0; box-shadow: 10px 0 40px rgba(0,0,0,.3); }
  .view { padding: 12px; }
  .view.full { padding: 0; }
  .chat { border-radius: 0; }
  .chat-list { width: 100%; }
  .chat.has-sel .chat-list { display: none; }
  .chat:not(.has-sel) .chat-main { display: none; }
  .back-btn { display: inline-block; }
  .bubble { max-width: 85%; }
  .msgs { padding: 12px; }
  .chat-info { left: 0; right: 0; top: 58px; bottom: 0; width: auto; border-radius: 0; position: fixed; }
}

/* Cliente en WispControl (panel de información del chat) */
.wisp-card { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 10px; font-size: 13px; }
.wisp-card dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 8px; margin: 8px 0; }
.wisp-card dt { color: var(--muted); } .wisp-card dd { margin: 0; overflow-wrap: anywhere; }
.wisp-debe { color: var(--red); font-weight: 700; } .wisp-ok { color: #166534; font-weight: 600; }
.wisp-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.wisp-ref { float: right; margin-top: -6px; font-size: 14px; }
#wispChip .pill { margin-left: 4px; }
