:root {
  --bg: #f7f7f5; --surface: #fff; --text: #1d1d1b; --muted: #6b6b66; --border: #e3e3de;
  --accent: #e8590c; --ok: #2b8a3e; --danger: #c92a2a; --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151514; --surface: #1f1f1d; --text: #ededea; --muted: #9a9a94; --border: #33332f; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 16px 4rem; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .brand { font-weight: 700; color: var(--text); }
.topbar .brand span, .accent { color: var(--accent); }
.spacer { flex: 1; }
.account-switch details { position: relative; }
.account-switch summary { cursor: pointer; padding: .45rem .7rem; border: 1px solid var(--border); border-radius: var(--radius); list-style: none; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-switch summary::after { content: " ▾"; color: var(--muted); font-weight: 400; }
.account-switch ul { position: absolute; z-index: 20; left: 0; right: 0; margin: .3rem 0 0; padding: .3rem; list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 220px; max-height: 60vh; overflow-y: auto; box-shadow: 0 6px 24px rgba(0,0,0,.15); }
.account-switch li a.current { font-weight: 600; }
.account-switch li a { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem .5rem; color: var(--text); border-radius: 6px; }
.account-switch li a:hover { background: var(--bg); }
.tabs { display: flex; gap: .25rem; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs a { padding: .6rem .8rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-color: var(--accent); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.account-card { display: flex; justify-content: space-between; align-items: center; color: var(--text); }
.module { color: var(--text); }
.module p { color: var(--muted); margin: .3rem 0 0; }
.module.soon { opacity: .7; }
.badge { font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.pill { display: inline-block; margin: 0 .4rem 1rem 0; padding: .2rem .7rem; border-radius: 999px; font-size: .85rem; border: 1px solid var(--border); }
.pill.ok { border-color: var(--ok); color: var(--ok); }
.pill.off { color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); }
table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
th, td { text-align: left; padding: .45rem .4rem; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--muted); font-size: .85rem; }
input, select, button { font: inherit; padding: .45rem .6rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
button { background: var(--accent); border-color: var(--accent); color: #fff; cursor: pointer; }
button.link { background: none; border: none; color: var(--accent); padding: 0; }
button.link.danger { color: var(--danger); }
form.inline { display: flex; flex-wrap: wrap; gap: .5rem; }
form.stack, .login form { display: flex; flex-direction: column; gap: .75rem; max-width: 460px; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; }
[hidden] { display: none !important; }
.login { max-width: 400px; margin: 10vh auto 0; }
pre.secret { padding: .75rem; background: var(--bg); border-radius: 8px; font-size: 1.1rem; }
.topbar form { margin: 0; }
@media (max-width: 640px) { .topbar .muted { display: none; } }

/* ── Dashboard ─────────────────────────────────────────────────────────── */
:root { --series-1: #2a78d6; --grid: #ececE8; --ok-text: #2b8a3e; --bad-text: #c92a2a; }
@media (prefers-color-scheme: dark) { :root { --series-1: #3987e5; --grid: #2c2c29; --ok-text: #69db7c; --bad-text: #ff8787; } }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem; }
.page-head h1 { margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filters form { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg a { padding: .35rem .7rem; color: var(--muted); font-size: .9rem; }
.seg a.active { background: var(--text); color: var(--bg); }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.ok-text { color: var(--ok-text); }
.card.narrow { max-width: 480px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .75rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar .brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar .brand span, .accent { color: var(--accent); }
.topbar nav { display: flex; gap: 1rem; align-items: center; }
.topbar form { margin: 0; }
main.page { max-width: 960px; margin: 1.5rem auto; padding: 0 1.25rem; }
.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.apps ul { list-style: none; padding: 0; margin: .5rem 0 0; }
.apps li { display: flex; justify-content: space-between; padding: .35rem 0; border-top: 1px solid var(--border); }
.inline { display: inline-flex; gap: .4rem; align-items: center; margin: 0; }
.inline select { padding: .2rem .4rem; font-size: .85rem; }
.copy { word-break: break-all; background: var(--bg); padding: .5rem; border-radius: 6px; font-size: .85rem; }
/* ── Barra superior ──────────────────────────────────────────────── */
.topbar nav a.active { color: var(--accent); font-weight: 600; }
.account-switch { position: relative; }
.account-switch summary { cursor: pointer; font-weight: 600; }
.account-switch ul { position: absolute; z-index: 5; list-style: none; margin: .3rem 0 0; padding: .4rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; min-width: 200px; }
.account-switch li a { display: block; padding: .25rem .4rem; }
.tag { display: inline-block; font-size: .72rem; padding: .05rem .45rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.tag.ok { color: var(--ok-text); border-color: var(--ok-text); }
.tag.warn { color: #b35c00; border-color: #e8a15c; }
.tag.bot { color: #6a4ce2; border-color: #b6a6f0; }
.pad { padding: .75rem; }
.unread { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 .45rem; font-size: .72rem; font-weight: 700; }

/* ── Bandeja: lista | chat | oportunidad ─────────────────────────── */
body.full { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.inbox { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(280px, 340px) 1fr; }
.inbox-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.inbox-search { padding: .6rem; border-bottom: 1px solid var(--border); }
.inbox-search input { width: 100%; box-sizing: border-box; }
.inbox-filters { display: flex; flex-wrap: wrap; gap: .3rem; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
.inbox-filters a { font-size: .8rem; padding: .15rem .6rem; border-radius: 999px; border: 1px solid var(--border); text-decoration: none; color: var(--text); }
.inbox-filters a.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#conv-list { flex: 1; overflow-y: auto; }
.conv-items { list-style: none; margin: 0; padding: 0; }
.conv-item { display: flex; gap: .6rem; padding: .6rem .7rem; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text); }
.conv-item:hover { background: var(--bg); }
.conv-item.current { background: var(--bg); box-shadow: inset 3px 0 0 var(--accent); }
.avatar { flex: 0 0 2.3rem; height: 2.3rem; border-radius: 50%; background: var(--border); display: grid; place-items: center; font-weight: 700; color: var(--muted); }
.conv-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.conv-top, .conv-bottom { display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.conv-top .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-top .when { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.conv-bottom .preview { font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-tags { display: flex; flex-wrap: wrap; gap: .2rem; }

.inbox-chat { min-height: 0; display: flex; }
.chat-empty { margin: auto; text-align: center; }
.chat { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr minmax(240px, 300px); }
.chat-main { min-height: 0; display: flex; flex-direction: column; }
.chat-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; padding: .6rem 1rem; border-bottom: 1px solid var(--border); background: var(--surface); }
.chat-actions { display: flex; gap: .5rem; align-items: center; }
.chat-actions form { margin: 0; }
.messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .35rem; background: #efeae2; }
.day { text-align: center; margin: .5rem 0; }
.day span { background: #fff; color: var(--muted); font-size: .72rem; padding: .15rem .6rem; border-radius: 6px; }
.bubble { max-width: min(72%, 560px); padding: .4rem .6rem .25rem; border-radius: 8px; background: #fff; box-shadow: 0 1px 0 rgba(0,0,0,.08); align-self: flex-start; color: #111b21; }
.bubble.out { align-self: flex-end; background: #d9fdd3; }
.bubble.failed { background: #fde2e1; }
.bubble.reaction { background: transparent; box-shadow: none; font-size: 1.3rem; padding: 0; }
.bubble .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble img, .bubble video { max-width: 100%; max-height: 320px; border-radius: 6px; display: block; }
.bubble audio { max-width: 260px; }
.bubble .meta { display: flex; justify-content: flex-end; gap: .4rem; font-size: .68rem; color: #667781; margin-top: .1rem; }
.tick.read { color: #53bdeb; }
.tick.bad { color: var(--danger); }
#composer { border-top: 1px solid var(--border); background: var(--surface); padding: .5rem .75rem; }
.composer { display: flex; gap: .5rem; align-items: flex-end; }
.composer textarea { flex: 1; resize: vertical; min-height: 2.6rem; max-height: 10rem; font: inherit; padding: .5rem .6rem; border-radius: 8px; border: 1px solid var(--border); }
.composer-note { margin: .2rem 0 .4rem; }
.template-picker { margin-top: .4rem; }
.template-picker select { max-width: 100%; margin: .3rem 0; }
.tpl-form { margin-top: .3rem; }
.tpl-preview { white-space: pre-wrap; background: var(--bg); padding: .4rem .6rem; border-radius: 6px; margin: 0 0 .3rem; }
.lead-panel { border-left: 1px solid var(--border); overflow-y: auto; padding: .75rem 1rem; background: var(--surface); }
.lead-panel h3 { margin-top: 0; }
.lead-facts { display: grid; grid-template-columns: auto 1fr; gap: .2rem .6rem; margin: 0 0 .6rem; }
.lead-facts dt { color: var(--muted); }
.lead-facts dd { margin: 0; }
.note { border-top: 1px solid var(--border); padding: .4rem 0; }
.note p { margin: .2rem 0 0; white-space: pre-wrap; }

@media (max-width: 1100px) { .chat { grid-template-columns: 1fr; } .lead-panel { display: none; } }
@media (max-width: 720px) {
  .inbox { grid-template-columns: 1fr; }
  .inbox[data-current]:not([data-current=""]) .inbox-list { display: none; }
  .inbox[data-current=""] .inbox-chat { display: none; }
}
.bot-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 420px); gap: 1rem; align-items: start; }
.bot-sim { position: sticky; top: 1rem; }
.sim-messages { max-height: 55vh; min-height: 200px; border-radius: 8px; margin-bottom: .5rem; }
form.stack { display: flex; flex-direction: column; gap: .7rem; }
fieldset { border: 1px solid var(--border); border-radius: 8px; display: flex; flex-direction: column; gap: .4rem; }
textarea { font: inherit; padding: .45rem .6rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
@media (max-width: 900px) { .bot-layout { grid-template-columns: 1fr; } }
.checks { display: flex; flex-wrap: wrap; gap: .3rem .9rem; max-height: 9rem; overflow-y: auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .6rem; margin: 1rem 0; }
.stat { margin: 0; padding: .7rem; }
.stat .big { font-size: 1.6rem; font-weight: 700; }
td.num, th.num { text-align: right; }
