:root {
  --bg: #f4f5f7; --panel: #fff; --text: #1d2127; --muted: #69717d; --line: #e3e6ea;
  --accent: #128c7e; --accent-2: #0b6b60; --danger: #c0392b; --warn: #b7791f; --ok: #1f8a4c;
  --in: #fff; --out: #dcf8c6; --ia: #e7f0fe; --note: #fff7d6;
  --radius: 10px; --shadow: 0 1px 3px rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --panel: #1b1f24; --text: #e6e8eb; --muted: #9aa3ad; --line: #2c3238;
    --in: #232a31; --out: #1f4a3c; --ia: #1f2f4a; --note: #3a3320; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select { width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 10px; }
textarea { resize: vertical; }
label { display: block; font-weight: 600; margin: 14px 0 4px; }
.hint { color: var(--muted); font-size: 13px; margin: 3px 0 0; font-weight: 400; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }

/* login */
.login { max-width: 360px; margin: 12vh auto; }
.login h1 { font-size: 22px; margin: 0 0 6px; }
.err { color: var(--danger); margin-top: 10px; min-height: 1em; }

/* layout */
.shell { display: grid; grid-template-columns: 250px 1fr; grid-template-rows: 52px 1fr; height: 100dvh; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--accent); color: #fff; }
.top .brand { font-weight: 700; }
.top button { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.top .burger { display: none; }
.sidemenu { display: none; }
.side { border-right: 1px solid var(--line); background: var(--panel); overflow: auto; }
.side h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 14px 14px 6px; }
.num { display: flex; gap: 10px; align-items: center; padding: 10px 14px; cursor: pointer; border-left: 3px solid transparent; }
.num:hover { background: var(--bg); }
.num.sel { background: var(--bg); border-left-color: var(--accent); }
.num .nombre { font-weight: 600; }
.num small { color: var(--muted); display: block; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.WORKING { background: var(--ok); }
.dot.SCAN_QR_CODE, .dot.STARTING { background: var(--warn); }
.dot.FAILED, .dot.STOPPED { background: var(--danger); }
.badge { background: var(--accent); color: #fff; border-radius: 10px; font-size: 12px; padding: 0 7px; margin-left: auto; }
.main { overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.tabs { display: flex; gap: 2px; padding: 8px 16px 0; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; color: var(--muted); }
.tabs button.sel { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .title { font-weight: 700; margin-right: 12px; align-self: center; }
.content { flex: 1; overflow: auto; padding: 18px; }
.content.flush { padding: 0; overflow: hidden; display: flex; }
.narrow { max-width: 820px; }

/* conversaciones */
.chats { width: 320px; border-right: 1px solid var(--line); overflow: auto; background: var(--panel); flex: none; }
.chatitem { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.chatitem:hover, .chatitem.sel { background: var(--bg); }
.chatitem .l1 { display: flex; gap: 8px; align-items: baseline; }
.chatitem .l1 b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chatitem .l2 { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); }
.tag.warn { color: var(--warn); border-color: var(--warn); }
.tag.err { color: var(--danger); border-color: var(--danger); }
.tag.perfil { color: var(--accent); border-color: var(--accent); }
.modal.ancho { max-width: 760px; }
.pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.pane .head { padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.pane .head .back { display: none; }
.msgs { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 75%; padding: 7px 10px; border-radius: 10px; background: var(--in); box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word; }
.msg.saliente { align-self: flex-end; background: var(--out); }
.msg.ia { background: var(--ia); }
.msg.interna { align-self: center; background: var(--note); font-size: 13px; max-width: 90%; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; }
.msg .meta .e-error { color: var(--danger); font-weight: 600; }
.msg img { max-width: 260px; max-height: 260px; border-radius: 6px; display: block; margin-bottom: 4px; }
.msg audio { max-width: 260px; display: block; margin-bottom: 4px; }
.composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { min-height: 42px; max-height: 160px; }
.empty { margin: auto; color: var(--muted); text-align: center; padding: 30px; }
.iabar { font-size: 13px; margin-top: 6px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* probar */
.test { display: flex; flex-direction: column; height: 60vh; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.qr img { width: 280px; height: 280px; background: #fff; padding: 10px; border-radius: 8px; }
.code { font: 700 30px/1 ui-monospace, monospace; letter-spacing: 4px; }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: 90vw; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
.modal { max-width: 640px; width: 100%; }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .top .burger { display: inline-block; }
  .topmenu { display: none; }
  .sidemenu { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px; border-top: 1px solid var(--line); margin-top: 10px; }
  .side { position: fixed; top: 52px; bottom: 0; left: 0; width: 80vw; max-width: 300px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .shell.menu .side { transform: none; box-shadow: 0 0 20px rgba(0,0,0,.3); }
  .chats { width: 100%; }
  .content.flush.chat-open .chats { display: none; }
  .content.flush:not(.chat-open) .pane { display: none; }
  .pane .head .back { display: inline-block; }
  /* con un chat abierto, pantalla completa para que no se corte el cuadro de escribir */
  .shell.fullchat { grid-template-rows: 1fr; }
  .shell.fullchat .top, .shell.fullchat .tabs { display: none; }
  .msg { max-width: 88%; }
}
