/* Tokens medidos sobre los fotogramas del vídeo (modo oscuro 2:33 y 3:08; modo claro 4:00). */
:root, [data-theme="dark"] {
  --bg: #131416;
  --bg-chat: #0b0c0f;
  --surface: #1b1a1f;
  --surface-2: #242328;
  --hover: #1d1e22;
  --border: #25262b;
  --border-strong: #34353b;
  --text: #f0f1f5;
  --text-2: #a3a4aa;
  --text-3: #6f7076;
  --primary: #0ea1e6;
  --primary-hover: #0b8fcd;
  --primary-soft: rgba(14, 161, 230, .14);
  --row-selected: #192730;
  --bubble-out: #0e2c40;
  --bubble-in: #2a2b30;
  --chip: #2b2c31;
  --note-bg: #3a3221;
  --note-border: #6e5a24;
  --warn-bg: #3a3226;
  --warn-border: #6a5427;
  --danger: #ef4444;
  --green: #22c55e;
  --wa: #25d366;
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #ffffff;
  --bg-chat: #f6f7fa;
  --surface: #f3f4f7;
  --surface-2: #e8eaf0;
  --hover: #f1f2f6;
  --border: #e1e0e9;
  --border-strong: #d2d3dc;
  --text: #16171b;
  --text-2: #5d5f68;
  --text-3: #8d8f99;
  --primary-soft: rgba(14, 161, 230, .12);
  --row-selected: #e4f3fc;
  --bubble-out: #d9effb;
  --bubble-in: #ffffff;
  --chip: #eceef3;
  --note-bg: #fff7dc;
  --note-border: #f0d47e;
  --warn-bg: #fff4e0;
  --warn-border: #f2c879;
  --shadow: 0 8px 28px rgba(20, 22, 40, .14);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Roboto, sans-serif;
  font-size: 14px; letter-spacing: -0.006em; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
svg.i { width: 16px; height: 16px; flex: none; display: block; }
[hidden] { display: none !important; }

/* ---------- Estructura de columnas (anchuras medidas: 200 / 224 / 305 / fluido / 320) ---------- */
.app { display: grid; grid-template-columns: 200px minmax(0, 1fr); height: 100vh; overflow: hidden; }
.page { min-width: 0; min-height: 0; height: 100vh; overflow: hidden; }
.inbox-grid { display: grid; grid-template-columns: 224px 305px minmax(360px, 1fr) 320px; height: 100%; }
.inbox-grid.contact-closed { grid-template-columns: 224px 305px minmax(360px, 1fr) 0; }
.col-nav, .col-views, .col-list, .col-contact { background: var(--bg); min-width: 0; overflow: hidden; }
.col-nav, .col-views, .col-list { border-right: 1px solid var(--border); }
.col-contact { border-left: 1px solid var(--border); }
.col-chat { background: var(--bg-chat); display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; position: relative; }

/* ---------- Navegación principal ---------- */
.col-nav { display: flex; flex-direction: column; padding: 14px 10px 10px; }
.ws { display: flex; align-items: center; gap: 8px; padding: 2px 4px 2px 2px; height: 40px; margin-bottom: 12px; }
.ws-logo { width: 30px; height: 30px; border-radius: 9px; background: var(--surface-2); display: grid; place-items: center; }
.ws-logo img { width: 22px; height: 22px; }
.ws-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws .caret { color: var(--text-2); }
.ws .pin { margin-left: auto; color: var(--text-2); }
.nav-item {
  white-space: nowrap; text-decoration: none;
  display: flex; align-items: center; gap: 10px; width: 100%; height: 32px; padding: 0 10px;
  border-radius: 8px; color: var(--text-2); font-size: 13px; margin-bottom: 2px; height: 34px; text-align: left; position: relative;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.nav-item .badge { margin-left: auto; }
.nav-spacer { flex: 1; }
.nav-item .dot { position: absolute; left: 21px; top: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); }
.avatar {
  width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  font-size: 10px; font-weight: 700; color: #fff; background: #3b3c42; position: relative; letter-spacing: .2px;
}
.avatar.lg { width: 36px; height: 36px; font-size: 13px; }
.avatar .online { position: absolute; right: -1px; bottom: -1px; width: 8px; height: 8px; border-radius: 50%; background: var(--green); border: 2px solid var(--bg); }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }

/* ---------- Columna de vistas ---------- */
.col-views { padding: 14px 10px; overflow-y: auto; }
.views-head { display: flex; align-items: center; justify-content: space-between; height: 32px; padding: 0 6px 0 10px; color: var(--text-2); font-size: 13px; margin-bottom: 8px; }
.view-item {
  text-decoration: none;
  display: flex; align-items: center; gap: 10px; width: 100%; height: 32px; padding: 0 10px; border-radius: 8px;
  color: var(--text-2); text-align: left; border: 1px solid transparent; margin-bottom: 1px; font-size: 13px; white-space: nowrap;
}
.view-item:hover { background: var(--hover); color: var(--text); }
.view-item.active { background: var(--surface); border-color: var(--border-strong); color: var(--text); font-weight: 600; }
.view-item .count { margin-left: auto; font-size: 12px; color: var(--text-2); font-weight: 600; }
.view-item.muted { opacity: .55; }
.view-item .chev { color: var(--text-3); margin-left: -2px; }
.section-head { text-align: left; white-space: nowrap; gap: 8px; display: flex; align-items: center; justify-content: space-between; width: 100%; height: 30px; padding: 0 10px; margin-top: 18px; color: var(--text-2); font-size: 13px; }
.section-head .chev { transition: transform .15s; }
.section-head.collapsed .chev { transform: rotate(-90deg); }
.view-item .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Lista de conversaciones ---------- */
.col-list { display: flex; flex-direction: column; }
.list-head { height: 62px; display: flex; align-items: center; gap: 8px; padding: 0 12px 0 16px; border-bottom: 1px solid var(--border); flex: none; }
.list-head h1 { font-size: 15px; font-weight: 600; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-head input { flex: 1; height: 32px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); padding: 0 10px; font: inherit; }
.round-btn { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--border-strong); color: var(--text); flex: none; }
.round-btn:hover { background: var(--hover); }
.round-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.round-btn.primary:hover { background: var(--primary-hover); }
.list-tools { padding: 10px 10px 0; flex: none; border-bottom: 1px solid var(--border); }
.segment { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border-radius: 10px; padding: 3px; height: 36px; border: 1px solid var(--border); }
.segment button { border-radius: 7px; color: var(--text-2); font-size: 13.5px; }
.segment button:hover { color: var(--text); }
.segment button.active { background: var(--surface-2); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.sort-row { display: flex; align-items: center; height: 42px; padding: 0 2px 0 6px; color: var(--text-2); }
.sort-row .sort { display: flex; align-items: center; gap: 4px; font-size: 13.5px; color: var(--text-2); }
.sort-row .sort:hover { color: var(--text); }
.sort-row .spacer { flex: 1; }
.icon-btn { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: var(--text-2); flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.active { color: var(--primary); }
.list-body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; }
.conv { display: block; width: 100%; text-align: left; cursor: pointer; outline: none; padding: 11px 10px 11px 10px; border-radius: 10px; position: relative; }
.conv + .conv::before { content: ""; position: absolute; left: 10px; right: 10px; top: 0; border-top: 1px solid var(--border); }
.conv:hover { background: var(--hover); }
.conv.selected { background: var(--row-selected); }
.conv.selected::before, .conv.selected + .conv::before, .conv:hover::before, .conv:hover + .conv::before { border-color: transparent; }
.conv-grid { display: grid; grid-template-columns: 26px 1fr auto; column-gap: 8px; row-gap: 3px; align-items: center; }
.ch-icon { width: 22px; height: 22px; border-radius: 50%; background: var(--wa); display: grid; place-items: center; color: #fff; }
.ch-icon svg { width: 14px; height: 14px; }
.conv-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--text-2); }
.conv-inbox { grid-column: 2 / 4; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.conv-inbox svg { width: 13px; height: 13px; }
.conv-dots { color: var(--text-3); display: grid; place-items: center; }
.conv-preview { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv.unread .conv-preview { color: var(--text); font-weight: 600; }
.conv-meta { grid-column: 1 / 4; display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.label-chip { height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; border: 1px solid; white-space: nowrap; }
.empty { text-align: center; padding: 64px 24px; color: var(--text-2); }
.empty .ill { width: 96px; height: 80px; margin: 0 auto 18px; color: var(--text-3); }
.empty h3 { color: var(--text); font-size: 15px; margin: 0 0 6px; font-weight: 700; }
.empty p { margin: 0; font-size: 14px; line-height: 1.45; }
.skeleton { height: 76px; border-radius: 10px; margin-bottom: 6px; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- Conversación ---------- */
.chat-head { height: 62px; display: flex; align-items: center; gap: 10px; padding: 0 12px 0 20px; border-bottom: 1px solid var(--border); background: var(--bg); flex: none; }
.chat-title { flex: 1; min-width: 0; }
.chat-title .row1 { display: flex; align-items: center; gap: 8px; }
.chat-title .name { font-size: 14.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title .sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.chat-title .sub.closed { color: #f2a23a; }
.chat-actions { display: flex; align-items: center; gap: 2px; }
.chat-actions .icon-btn.on { color: var(--primary); }
.chat-body { flex: 1; min-height: 0; overflow-y: auto; padding: 18px 24px 12px; display: flex; flex-direction: column; gap: 6px; }
.day-sep { align-self: center; font-size: 12px; color: var(--text-2); background: var(--surface); border: 1px solid var(--border); padding: 3px 10px; border-radius: 12px; margin: 10px 0; }
.msg-row { display: flex; align-items: flex-end; gap: 8px; max-width: 100%; }
.msg-row.out, .msg-row.note { justify-content: flex-end; }
.msg-row .hover-actions { display: none; gap: 2px; align-self: center; }
.msg-row:hover .hover-actions { display: flex; }
.msg-row.out .hover-actions, .msg-row.note .hover-actions { order: -1; }
.bubble { max-width: min(600px, 78%); padding: 9px 12px 7px; border-radius: 14px; line-height: 1.42; font-size: 13.5px; word-wrap: break-word; }
.bubble .txt { white-space: pre-wrap; }
.in .bubble { background: var(--bubble-in); border-bottom-left-radius: 4px; }
.out .bubble { background: var(--bubble-out); border-bottom-right-radius: 4px; }
.note .bubble { background: var(--note-bg); border: 1px solid var(--note-border); border-bottom-right-radius: 4px; }
.bubble-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 6px; font-size: 11.5px; color: var(--text-2); white-space: nowrap; }
.bubble-foot .author { display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 7px; border-radius: 6px; background: rgba(255,255,255,.07); color: var(--text); margin-right: auto; font-weight: 600; }
[data-theme="light"] .bubble-foot .author { background: rgba(0,0,0,.06); }
.bubble-foot .ticks { display: inline-flex; color: var(--text-2); }
.bubble-foot .ticks.read { color: var(--primary); }
.bubble-foot .ticks.failed { color: var(--danger); }
.bubble .mention { color: var(--primary); font-weight: 600; }
.doc { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: rgba(0,0,0,.18); min-width: 240px; }
.doc .ficon { width: 34px; height: 40px; border-radius: 6px; background: #e5484d; color: #fff; display: grid; place-items: center; font-size: 10px; font-weight: 800; }
.doc small { color: var(--text-2); display: block; }
.sys { align-self: center; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--text-2); font-size: 12px; margin: 8px 0; text-align: center; }
.sys svg { color: var(--text-3); }
.chat-empty { flex: 1; display: grid; place-items: center; color: var(--text-2); text-align: center; }
.chat-banner { margin: 0 20px; display: flex; gap: 10px; align-items: center; padding: 12px 14px; border: 1px solid var(--warn-border); background: var(--warn-bg); border-radius: 12px 12px 0 0; border-bottom: 0; font-size: 13.5px; }
.chat-banner .warn-ico { width: 18px; height: 18px; border-radius: 50%; background: #f2a23a; color: #1b1405; display: grid; place-items: center; font-weight: 800; font-size: 12px; flex: none; }
.composer { padding: 0 20px 16px; }
.chat-banner:not([hidden]) + .composer .composer-box { border-top-left-radius: 0; border-top-right-radius: 0; }
.composer-box { border: 1px solid var(--border-strong); background: var(--bg); border-radius: 12px; padding: 10px 10px 8px 14px; transition: background .15s, border-color .15s; }
.composer-box:focus-within { border-color: var(--primary); }
.composer-box.note { background: var(--note-bg); border-color: var(--note-border); }
.composer-box.disabled { opacity: .55; }
.composer textarea { width: 100%; resize: none; border: 0; outline: none !important; background: transparent; color: var(--text); font: inherit; line-height: 1.45; max-height: 180px; min-height: 22px; }
.composer textarea::placeholder { color: var(--text-3); }
.composer-bar { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.composer-left { display: flex; align-items: center; gap: 2px; }
.chip-btn { height: 26px; padding: 0 8px; border-radius: 7px; display: inline-flex; align-items: center; gap: 5px; color: var(--text-2); font-size: 13px; font-weight: 600; margin-left: 4px; border: 1px solid var(--border-strong); }
.chip-btn:hover { color: var(--text); background: var(--hover); }
.chip-btn.on { background: #f2c94c; border-color: #f2c94c; color: #2a2000; }
.chip-btn.ai { color: #b78cf7; }
.chip-btn svg { width: 14px; height: 14px; }
.btn { height: 34px; padding: 0 14px; border-radius: 8px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); }
.btn.sm { height: 30px; padding: 0 12px; font-size: 13px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; }

/* ---------- Panel de contacto ---------- */
.col-contact { display: flex; flex-direction: column; overflow-y: auto; }
.contact-head { height: 62px; display: flex; align-items: center; gap: 6px; padding: 0 12px 0 18px; border-bottom: 1px solid var(--border); flex: none; }
.contact-head h2 { font-size: 14.5px; font-weight: 700; margin: 0; flex: 1; }
.contact-head .icon-btn { border: 1px solid var(--border-strong); width: 28px; height: 28px; }
.contact-card { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.contact-card .nm { font-weight: 600; font-size: 14px; }
.contact-card .ph { color: var(--text-2); font-size: 13px; display: flex; align-items: center; gap: 5px; margin-top: 2px; }
.contact-card .ph svg { color: var(--wa); width: 13px; height: 13px; }
.c-row { display: flex; align-items: center; gap: 10px; min-height: 50px; font-size: 13.5px; padding: 0 16px 0 18px; border-bottom: 1px solid var(--border); width: 100%; text-align: left; }
.c-row .t { flex: 1; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.c-row .n { font-size: 11px; color: var(--text-2); background: var(--chip); border-radius: 5px; padding: 1px 6px; font-weight: 700; }
.c-row .chev { color: var(--text-2); transition: transform .15s; }
.c-row.open .chev { transform: rotate(90deg); }
.c-row:hover { background: var(--hover); }
.c-lists { display: flex; gap: 6px; }
.c-lists .label-chip { height: 24px; }
.c-panel { padding: 4px 18px 16px; border-bottom: 1px solid var(--border); }
.attr { display: grid; grid-template-columns: 118px 1fr; gap: 8px; padding: 7px 0; font-size: 13px; align-items: center; }
.attr dt { color: var(--text-2); }
.attr dd { margin: 0; overflow: hidden; text-overflow: ellipsis; }
.attr dd.ok { color: var(--green); }
.c-panel .item { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; margin-top: 8px; font-size: 13px; }
.c-panel .item small { color: var(--text-2); display: block; margin-top: 2px; }
.c-panel .item.link { cursor: pointer; width: 100%; text-align: left; }
.c-panel .item.link:hover { border-color: var(--border-strong); background: var(--hover); }
.c-panel .muted { color: var(--text-2); font-size: 13px; padding-top: 6px; }

/* ---------- Popover y toast ---------- */
.popover { position: fixed; z-index: 50; min-width: 220px; max-width: 300px; background: var(--bg); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; }
.popover .p-title { font-size: 12px; color: var(--text-2); padding: 6px 10px 4px; font-weight: 600; }
.popover .p-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 0 10px; height: 34px; border-radius: 8px; text-align: left; font-size: 14px; }
.popover .p-item:hover { background: var(--hover); }
.popover .p-item .check { margin-left: auto; color: var(--primary); }
.popover .p-item.danger { color: var(--danger); }
.popover .p-sep { border-top: 1px solid var(--border); margin: 6px 0; }
.popover .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.popover .theme-row { display: flex; gap: 6px; padding: 4px 10px 8px; }
.popover .theme-row button { flex: 1; height: 32px; border-radius: 8px; border: 1px solid var(--border-strong); display: grid; place-items: center; color: var(--text-2); }
.popover .theme-row button.on { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.popover .demo-tag { margin-left: auto; font-size: 10px; font-weight: 700; color: #f2a23a; border: 1px solid #f2a23a; border-radius: 4px; padding: 0 4px; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 600; z-index: 60; box-shadow: var(--shadow); max-width: 520px; }
.mode-pill { font-size: 10.5px; font-weight: 800; letter-spacing: .4px; color: #f2a23a; border: 1px solid rgba(242,162,58,.5); border-radius: 5px; padding: 1px 5px; margin-left: 4px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 8px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

.section-head > span { overflow: hidden; text-overflow: ellipsis; }
.nav-item > span:not(.avatar):not(.badge):not(.mode-pill) { overflow: hidden; text-overflow: ellipsis; }
