/* ==================================================================
   Bandeja de WhatsApp — los cajeros responden desde Tricapi.
   Mismos tokens que el panel (public/style.css) y la consola del chat.
   ================================================================== */
:root {
  --ib-accent: #6366f1;
  --ib-accent-2: #4f46e5;
  --ib-accent-light: #a5b4fc;
  --ib-bg: #080a0f;
  --ib-panel: #0d111a;
  --ib-panel-hi: #121826;
  --ib-panel-2: rgba(255, 255, 255, 0.045);
  --ib-panel-3: rgba(99, 102, 241, 0.15);
  --ib-border: rgba(255, 255, 255, 0.07);
  --ib-border-hi: rgba(255, 255, 255, 0.14);
  --ib-text: #f3f4f6;
  --ib-muted: #9ca3af;
  --ib-muted-2: #6b7280;
  --ib-out: #2b2f7a;
  --ib-in: #171c2a;
  --ib-ok: #10b981;
  --ib-warn: #f59e0b;
  --ib-danger: #ef4444;
  --ib-read: #38bdf8;
  --ib-principal: #c084fc;
  --ib-principal-bg: rgba(192, 132, 252, 0.16);
  --ib-publi: #22d3ee;
  --ib-publi-bg: rgba(34, 211, 238, 0.13);
  --ib-radius: 14px;
  --ib-focus: 0 0 0 2px rgba(129, 140, 248, 0.7);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ib-bg);
  color: var(--ib-text);
  font-family: 'Outfit', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button:focus-visible, a:focus-visible, label:focus-visible, input:focus-visible, textarea:focus-visible { outline: none; box-shadow: var(--ib-focus); }
.ib-muted { color: var(--ib-muted); }
.ib-small { font-size: 0.8rem; margin: 0; }
.ib-kbd {
  display: inline-block;
  font: 600 0.7rem/1 'Outfit', system-ui, sans-serif;
  padding: 0.18rem 0.38rem;
  border-radius: 5px;
  border: 1px solid var(--ib-border-hi);
  border-bottom-width: 2px;
  color: var(--ib-muted);
  background: rgba(255,255,255,.03);
  vertical-align: 1px;
}

.ib-app {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr auto;
  height: 100vh;
  height: 100dvh;
}

/* ── Lista ─────────────────────────────────────────────── */
.ib-side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--ib-border);
  background: var(--ib-panel);
}
.ib-side-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.95rem 1rem 0.7rem;
}
.ib-back {
  color: var(--ib-muted);
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 10px;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.ib-back:hover { background: var(--ib-panel-2); color: var(--ib-text); }
.ib-brand { display: flex; flex-direction: column; line-height: 1.2; }
.ib-brand strong { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; }
.ib-brand span { font-size: 0.8rem; }
.ib-logout { margin-left: auto; }
.ib-back[hidden], .ib-logout[hidden] { display: none; }

.ib-lines {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding: 0.1rem 1rem 0.7rem;
  scrollbar-width: none;
}
.ib-line {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.38rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--ib-border);
  background: transparent;
  color: var(--ib-muted);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.ib-line:hover { color: var(--ib-text); border-color: var(--ib-border-hi); }
.ib-line.active { background: var(--ib-panel-3); border-color: rgba(99,102,241,.5); color: var(--ib-text); }

/* Grupos por tipo de línea (Todas · Principales · Publicidad) */
.ib-groups {
  display: flex;
  gap: 0.2rem;
  margin: 0 1rem 0.55rem;
  padding: 0.2rem;
  border-radius: 10px;
  background: var(--ib-panel-2, rgba(255,255,255,.03));
  border: 1px solid var(--ib-border);
  overflow-x: auto;
  scrollbar-width: none;
}
.ib-groups[hidden] { display: none; }
.ib-group {
  flex: 1 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.38rem 0.3rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ib-muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.ib-group i { font-size: 0.72rem; }
.ib-group:hover { color: var(--ib-text); }
.ib-group.active { background: var(--ib-panel-3); color: var(--ib-text); box-shadow: 0 0 0 1px rgba(99,102,241,.45) inset; }
/* Cada tipo con su color: violeta = Principal, celeste = Publicidad */
.ib-group.principal i { color: var(--ib-principal); }
.ib-group.publicidad i { color: var(--ib-publi); }
.ib-group.principal.active { background: var(--ib-principal-bg); box-shadow: 0 0 0 1px var(--ib-principal) inset; }
.ib-group.publicidad.active { background: var(--ib-publi-bg); box-shadow: 0 0 0 1px var(--ib-publi) inset; }
.ib-lines.split { flex-direction: column; gap: 0.35rem; overflow: visible; }
.ib-lines-row { display: flex; align-items: center; gap: 0.4rem; overflow-x: auto; scrollbar-width: none; }
.ib-lines-label {
  position: sticky; left: 0; z-index: 1;
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 0.4rem;
  width: 6.4rem;
  align-self: stretch;
  background: var(--ib-panel);
  font-size: 0.78rem; font-weight: 600;
}
.ib-lines-label i { width: 0.9rem; text-align: center; font-size: 0.72rem; }
.ib-lines-row.principal .ib-lines-label { color: var(--ib-principal); }
.ib-lines-row.publicidad .ib-lines-label { color: var(--ib-publi); }
.ib-lines-row.principal .ib-line.active { background: var(--ib-principal-bg); border-color: var(--ib-principal); }
.ib-lines-row.publicidad .ib-line.active { background: var(--ib-publi-bg); border-color: var(--ib-publi); }
.ib-type {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0 0.4rem;
  border-radius: 5px;
  font-size: 0.68rem; font-weight: 600; line-height: 1.55;
  white-space: nowrap;
}
.ib-type i { font-size: 0.6rem; }
.ib-type.principal { color: var(--ib-principal); background: var(--ib-principal-bg); }
.ib-type.publicidad { color: var(--ib-publi); background: var(--ib-publi-bg); }
.ib-group:focus-visible, .ib-line:focus-visible { outline: 2px solid rgba(99,102,241,.7); outline-offset: 1px; }
.ib-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ib-muted-2); flex-shrink: 0; }
.ib-dot.on { background: var(--ib-ok); box-shadow: 0 0 0 3px rgba(16,185,129,.15); }
.ib-dot.warn { background: var(--ib-warn); }
.ib-dot.off { background: var(--ib-danger); }
.ib-count { background: var(--ib-ok); color: #04110b; font-weight: 700; border-radius: 999px; padding: 0 0.42rem; font-size: 0.7rem; line-height: 1.5; }

.ib-search { position: relative; margin: 0 1rem 0.55rem; }
.ib-search > i { position: absolute; left: 0.8rem; top: 50%; transform: translateY(-50%); color: var(--ib-muted-2); font-size: 0.85rem; pointer-events: none; }
.ib-search input {
  width: 100%;
  padding: 0.6rem 3.6rem 0.6rem 2.2rem;
  border-radius: 12px;
  border: 1px solid var(--ib-border);
  background: var(--ib-panel-2);
  outline: none;
  transition: border-color .15s, background .15s;
}
.ib-search input:focus { border-color: rgba(99,102,241,.6); background: rgba(255,255,255,.06); box-shadow: none; }
.ib-search input::-webkit-search-cancel-button { filter: invert(.6); }
.ib-search .ib-kbd { position: absolute; right: 0.6rem; top: 50%; transform: translateY(-50%); pointer-events: none; }
.ib-search input:focus ~ .ib-kbd, .ib-search input:not(:placeholder-shown) ~ .ib-kbd { display: none; }

.ib-filters { display: flex; gap: 0.3rem; padding: 0 1rem 0.6rem; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--ib-border); }
.ib-filter {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.32rem 0.7rem;
  border-radius: 999px;
  border: 0;
  background: transparent;
  color: var(--ib-muted);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.ib-filter:hover { color: var(--ib-text); background: rgba(255,255,255,.03); }
.ib-filter.active { background: var(--ib-panel-3); color: var(--ib-text); }
.ib-filter .fa-star { color: #fbbf24; font-size: 0.72rem; }
.ib-fcount:empty { display: none; }
.ib-fcount { background: rgba(255,255,255,.1); border-radius: 999px; padding: 0 0.4rem; font-size: 0.7rem; line-height: 1.55; }
.ib-filter[data-filter="pending"] .ib-fcount { background: rgba(245,158,11,.18); color: #fcd34d; }

.ib-chats { flex: 1; overflow-y: auto; min-height: 0; padding: 0.3rem 0.45rem; }
.ib-chat-item {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  gap: 0.75rem;
  align-items: center;
  width: 100%;
  padding: 0.6rem 0.6rem;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background .12s;
}
.ib-chat-item.type-principal, .ib-chat-item.type-publicidad { position: relative; }
.ib-chat-item.type-principal::before, .ib-chat-item.type-publicidad::before {
  content: ''; position: absolute; left: 0; top: 0.6rem; bottom: 0.6rem; width: 3px; border-radius: 3px;
}
.ib-chat-item.type-principal::before { background: var(--ib-principal); }
.ib-chat-item.type-publicidad::before { background: var(--ib-publi); }
.ib-chat-item:hover { background: var(--ib-panel-2); }
.ib-chat-item.active { background: var(--ib-panel-3); }
.ib-avatar {
  --av: 235;
  width: 46px; height: 46px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  background: hsl(var(--av) 45% 22%);
  color: hsl(var(--av) 85% 78%);
  flex-shrink: 0;
  position: relative;
}
.ib-avatar .ib-av-star {
  position: absolute; right: -2px; bottom: -2px;
  width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center;
  background: #fbbf24; color: #3b2a02; font-size: 0.55rem;
  border: 2px solid var(--ib-panel);
}
.ib-chat-mid { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ib-chat-top { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.ib-chat-top strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.ib-chat-item.unread .ib-chat-top strong { font-weight: 700; }
.ib-preview {
  display: flex; align-items: center; gap: 0.25rem;
  color: var(--ib-muted);
  font-size: 0.85rem;
  min-width: 0;
}
.ib-preview > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ib-preview .fa-check, .ib-preview .fa-check-double { font-size: 0.7rem; color: var(--ib-muted-2); flex-shrink: 0; }
.ib-chat-item.unread .ib-preview { color: var(--ib-text); }
.ib-chat-end { display: flex; flex-direction: column; align-items: flex-end; gap: 0.3rem; font-size: 0.74rem; color: var(--ib-muted-2); white-space: nowrap; }
.ib-chat-item.unread .ib-chat-end > span:first-child { color: var(--ib-ok); font-weight: 600; }
.ib-unread { background: var(--ib-ok); color: #04110b; font-weight: 700; border-radius: 999px; min-width: 20px; padding: 0 0.42rem; text-align: center; font-size: 0.72rem; line-height: 20px; }
.ib-wait { color: #fcd34d; font-size: 0.7rem; display: inline-flex; align-items: center; gap: 0.25rem; }
.ib-tagpill { font-size: 0.68rem; color: var(--ib-accent-light); background: rgba(99,102,241,.12); border-radius: 5px; padding: 0 0.35rem; white-space: nowrap; }
.ib-flags { font-size: 0.78rem; line-height: 1; letter-spacing: 0.08em; white-space: nowrap; flex-shrink: 0; }

/* Fila de la lista: el chat + el botón de borrar (aparece al pasar el mouse). */
.ib-chat-row { position: relative; }
.ib-chat-del {
  position: absolute; right: 0.5rem; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 0; border-radius: 9px;
  background: var(--ib-panel-hi);
  color: var(--ib-muted);
  font-size: 0.8rem;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s, color .12s, background .12s;
}
.ib-chat-row:hover .ib-chat-del, .ib-chat-del:focus-visible { opacity: 1; pointer-events: auto; }
.ib-chat-del:hover { color: var(--ib-danger); background: rgba(239,68,68,.12); }
@media (hover: none) { .ib-chat-del { display: none; } }
.ib-no-delete .ib-chat-del, .ib-no-delete .ib-quick-del { display: none !important; }
.ib-line-deleted { font-style: normal; opacity: .65; font-size: .9em; }
.ib-composer[hidden] { display: none !important; }

/* Etiquetas en el encabezado del chat abierto. */
.ib-flag-toggles { display: flex; gap: 0.15rem; flex-shrink: 0; }
.ib-flag-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 0; border-radius: 9px;
  background: transparent;
  font-size: 0.95rem; line-height: 1;
  cursor: pointer;
  filter: grayscale(1);
  opacity: 0.4;
  transition: opacity .12s, filter .12s, background .12s;
}
.ib-flag-btn:hover { opacity: 0.85; background: var(--ib-panel-2); }
.ib-flag-btn.on { filter: none; opacity: 1; background: var(--ib-panel-3); }
.ib-line-tag { font-size: 0.7rem; color: var(--ib-muted-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ib-chats-empty { padding: 2.5rem 1.25rem; color: var(--ib-muted); text-align: center; font-size: 0.9rem; line-height: 1.5; }
.ib-chats-empty i { display: block; font-size: 1.6rem; margin-bottom: 0.6rem; color: var(--ib-muted-2); }

/* Esqueletos de carga */
.ib-skel-row, .ib-skel-msg {
  border-radius: 12px;
  background: linear-gradient(90deg, rgba(255,255,255,.035) 0%, rgba(255,255,255,.07) 50%, rgba(255,255,255,.035) 100%);
  background-size: 200% 100%;
  animation: ib-shimmer 1.3s ease-in-out infinite;
}
.ib-skel-row { height: 62px; margin: 0.25rem 0.15rem; }
.ib-skel-msg { height: 38px; width: 46%; margin: 8px 0; }
.ib-skel-msg.out { margin-left: auto; width: 34%; }
@keyframes ib-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ── Conversación ──────────────────────────────────────── */
.ib-main { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.ib-empty {
  margin: auto;
  max-width: 420px;
  text-align: center;
  color: var(--ib-muted);
  padding: 2rem;
}
.ib-empty-icon {
  width: 76px; height: 76px; margin: 0 auto;
  border-radius: 22px;
  display: grid; place-items: center;
  background: rgba(16,185,129,.1);
  border: 1px solid rgba(16,185,129,.22);
}
.ib-empty-icon i { font-size: 2.3rem; color: var(--ib-ok); }
.ib-empty h2 { color: var(--ib-text); font-size: 1.25rem; margin: 1.1rem 0 0.4rem; font-weight: 600; letter-spacing: -0.01em; }
.ib-empty p { margin: 0; font-size: 0.92rem; line-height: 1.55; }
.ib-tips { list-style: none; padding: 0; margin: 1.6rem 0 0; display: flex; flex-direction: column; gap: 0.6rem; text-align: left; }
.ib-tips li {
  display: flex; gap: 0.75rem; align-items: flex-start;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  background: var(--ib-panel-2);
  border: 1px solid var(--ib-border);
  font-size: 0.86rem; line-height: 1.45;
}
.ib-tips li > i { color: var(--ib-accent-light); margin-top: 0.2rem; width: 1rem; text-align: center; flex-shrink: 0; }
.ib-tips strong { color: var(--ib-text); font-weight: 600; }

.ib-chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.ib-chat-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--ib-border);
  background: var(--ib-panel);
  min-height: 62px;
}
.ib-chat-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  border-radius: 10px;
}
.ib-chat-title:hover { background: var(--ib-panel-2); }
.ib-chat-title .ib-avatar { width: 40px; height: 40px; font-size: 0.88rem; }
.ib-chat-names { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.ib-chat-names strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.ib-chat-names span { font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ib-chat-names .ib-type { font-size: 0.7rem; vertical-align: bottom; margin-right: 0.2rem; }
/* Franja del color del tipo: se ve desde qué línea se está respondiendo */
.ib-chat[data-type="principal"] .ib-chat-head { box-shadow: inset 0 3px 0 var(--ib-principal); }
.ib-chat[data-type="publicidad"] .ib-chat-head { box-shadow: inset 0 3px 0 var(--ib-publi); }
.ib-badge {
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(251,191,36,.12);
  color: #fbbf24;
  white-space: nowrap;
  font-weight: 500;
}
.ib-badge.cliente { background: rgba(16,185,129,.12); color: var(--ib-ok); }
.ib-badge.nuevo { background: rgba(99,102,241,.14); color: var(--ib-accent-light); }
.ib-icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--ib-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.ib-icon-btn:hover { background: var(--ib-panel-2); color: var(--ib-text); }
.ib-icon-btn[aria-expanded="true"] { color: var(--ib-accent-light); background: var(--ib-panel-3); }
.ib-icon-btn.ib-danger { color: var(--ib-danger); }
.ib-only-mobile { display: none; }

.ib-line-warning {
  display: flex; gap: 0.5rem; align-items: center;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  background: rgba(245,158,11,.1);
  color: #fcd34d;
  border-bottom: 1px solid rgba(245,158,11,.2);
}
/* Aviso informativo (la línea vuelve sola): azul, no alarma. */
.ib-line-warning.info {
  background: rgba(99,102,241,.12);
  color: #c7d2fe;
  border-bottom-color: rgba(99,102,241,.28);
}

.ib-messages-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.ib-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem max(4%, 1rem) 0.75rem;
  background:
    radial-gradient(circle at 12% 8%, rgba(99,102,241,.06) 0%, transparent 38%),
    radial-gradient(circle at 88% 92%, rgba(16,185,129,.035) 0%, transparent 40%),
    var(--ib-bg);
}
.ib-to-bottom {
  position: absolute; right: 1.1rem; bottom: 0.9rem;
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--ib-border-hi);
  background: var(--ib-panel-hi);
  color: var(--ib-text);
  display: grid; place-items: center;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.ib-to-bottom:hover { background: #1a2133; }
.ib-to-bottom-count {
  position: absolute; top: -6px; right: -4px;
  background: var(--ib-ok); color: #04110b;
  font-size: 0.68rem; font-weight: 700;
  border-radius: 999px; min-width: 18px; line-height: 18px; padding: 0 0.3rem; text-align: center;
}
.ib-load-more {
  display: block;
  margin: 0 auto 0.8rem;
  border: 1px solid var(--ib-border);
  background: var(--ib-panel);
  color: var(--ib-muted);
  border-radius: 999px;
  padding: 0.35rem 0.95rem;
  font-size: 0.8rem;
  cursor: pointer;
}
.ib-load-more:hover { color: var(--ib-text); }
.ib-day { text-align: center; margin: 0.9rem 0; }
.ib-day span {
  font-size: 0.74rem;
  background: rgba(18,24,38,.92);
  backdrop-filter: blur(6px);
  color: var(--ib-muted);
  padding: 0.28rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--ib-border);
}
.ib-unread-sep { text-align: center; margin: 0.9rem 0; }
.ib-unread-sep span {
  display: inline-block;
  font-size: 0.75rem; font-weight: 600;
  color: var(--ib-ok);
  background: rgba(16,185,129,.1);
  padding: 0.28rem 0.85rem;
  border-radius: 999px;
}
.ib-msg { display: flex; margin: 2px 0; }
.ib-msg.out { justify-content: flex-end; }
.ib-bubble {
  position: relative;
  max-width: min(560px, 76%);
  padding: 0.42rem 0.65rem 0.28rem;
  border-radius: 12px;
  background: var(--ib-in);
  line-height: 1.42;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  box-shadow: 0 1px 1px rgba(0,0,0,.25);
}
.ib-bubble a { color: var(--ib-accent-light); }
.ib-msg.out .ib-bubble { background: var(--ib-out); }
.ib-msg.first { margin-top: 10px; }
.ib-msg.first.in .ib-bubble { border-top-left-radius: 3px; }
.ib-msg.first.out .ib-bubble { border-top-right-radius: 3px; }
/* colita del globo, solo en el primero de cada tanda */
.ib-msg.first .ib-bubble::before {
  content: '';
  position: absolute; top: 0;
  width: 9px; height: 12px;
  background: inherit;
}
.ib-msg.first.in .ib-bubble::before { left: -7px; clip-path: polygon(100% 0, 0 0, 100% 100%); border-top-left-radius: 2px; }
.ib-msg.first.out .ib-bubble::before { right: -7px; clip-path: polygon(0 0, 100% 0, 0 100%); border-top-right-radius: 2px; }
.ib-msg.new .ib-bubble { animation: ib-pop .18s ease-out; }
@keyframes ib-pop { from { opacity: 0; transform: translateY(6px); } }
.ib-meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.68rem;
  color: rgba(255,255,255,.5);
  margin-top: 2px;
  white-space: nowrap;
}
.ib-meta .ib-by { margin-right: auto; padding-right: 0.7rem; color: rgba(255,255,255,.42); }
.ib-tick.read, .ib-tick.played { color: var(--ib-read); }
.ib-tick.failed { color: var(--ib-danger); }
.ib-edited { font-style: italic; }

/* Envío optimista: "enviando…" mientras sale, rojo si no salió */
.ib-msg.pending .ib-bubble { opacity: 0.72; }
.ib-msg.pending.failed .ib-bubble { opacity: 1; box-shadow: inset 0 0 0 1px rgba(239,68,68,.55); }
.ib-failed-row { margin: 3px 0 8px; }
.ib-failed {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.35rem 0.6rem;
  max-width: min(560px, 76%);
  font-size: 0.76rem; color: #fca5a5; text-align: right;
}
.ib-failed-actions { display: inline-flex; gap: 0.3rem; }
.ib-failed.ib-waiting { color: var(--ib-muted); }
.ib-failed-actions button {
  border: 1px solid var(--ib-border-hi); background: var(--ib-panel-2); color: var(--ib-text);
  border-radius: 7px; padding: 0.16rem 0.55rem; font: inherit; cursor: pointer;
}
.ib-failed-actions button:hover { border-color: rgba(129,140,248,.6); }
.ib-failed-actions button[data-retry], .ib-failed-actions button[data-force] { background: var(--ib-panel-3); }
/* Aviso de naturalidad: espera la decisión del cajero, no frena a los demás */
.ib-failed.ib-held { color: #fde68a; }

/* Lista de chats: lo que todavía no salió (reloj) o quedó sin enviar (alerta) */
.ib-preview .ib-prev-wait { font-size: 0.72rem; color: var(--ib-muted-2); flex-shrink: 0; }
.ib-preview .ib-prev-stuck { font-size: 0.78rem; color: var(--ib-danger); flex-shrink: 0; }
.ib-preview .ib-prev-stuck-text { color: #fca5a5; }

/* "escribiendo…" del cliente y borradores en la lista */
.ib-typing { color: var(--ib-ok); font-weight: 500; }
.ib-preview .ib-typing { white-space: nowrap; }
.ib-draft { color: var(--ib-warn); font-weight: 600; }
.ib-media-img {
  display: block;
  max-width: 100%;
  width: 280px;
  max-height: 340px;
  object-fit: cover;
  border-radius: 8px;
  cursor: zoom-in;
  background: rgba(255,255,255,.04);
  min-height: 120px;
}
.ib-sticker { width: 130px; height: 130px; object-fit: contain; }
.ib-audio { display: flex; align-items: center; gap: 0.45rem; min-width: 240px; }
.ib-audio audio { width: 100%; height: 36px; }
.ib-doc {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.65rem;
  border-radius: 9px;
  background: rgba(0,0,0,.2);
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  border: 0;
  width: 100%;
  text-align: left;
}
.ib-doc i { font-size: 1.4rem; color: var(--ib-accent-light); }

/* PDF: miniatura de la primera página arriba del nombre */
.ib-doc-pdf { flex-direction: column; align-items: stretch; gap: 0; padding: 0; overflow: hidden; width: 260px; max-width: 100%; }
.ib-pdf-thumb {
  display: grid;
  place-items: center;
  height: 150px;
  background: rgba(255,255,255,.04);
  overflow: hidden;
}
.ib-pdf-thumb i { font-size: 2rem; opacity: .45; }
.ib-pdf-thumb:not(.ready):not(.failed) i { animation: ib-pdf-pulse 1.2s ease-in-out infinite; }
.ib-pdf-thumb.ready { background: #fff; }
.ib-pdf-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.ib-doc-row { display: flex; align-items: center; gap: 0.55rem; padding: 0.55rem 0.65rem; min-width: 0; }
.ib-doc-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-doc-pdf:hover .ib-pdf-thumb img { opacity: .92; }
@keyframes ib-pdf-pulse { 50% { opacity: .2; } }
@media (prefers-reduced-motion: reduce) { .ib-pdf-thumb:not(.ready):not(.failed) i { animation: none; } }

/* Visor de PDF a pantalla completa */
.ib-pdf-viewer { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.9); display: flex; flex-direction: column; }
.ib-pdf-bar {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 0.85rem;
  padding-top: calc(0.6rem + env(safe-area-inset-top));
  background: var(--ib-panel); border-bottom: 1px solid var(--ib-border); color: var(--ib-text);
}
.ib-pdf-bar > i { color: var(--ib-accent-light); font-size: 1.15rem; }
.ib-pdf-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.ib-pdf-btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  min-height: 36px; min-width: 36px; justify-content: center;
  padding: 0 0.7rem; border-radius: 9px; border: 1px solid var(--ib-border-hi);
  background: var(--ib-panel-2); color: var(--ib-text); font: inherit; cursor: pointer;
}
.ib-pdf-btn:hover { background: var(--ib-panel-3); }
.ib-pdf-pages { flex: 1; overflow: auto; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.ib-pdf-page { background: #fff; border-radius: 4px; box-shadow: 0 4px 24px rgba(0,0,0,.5); max-width: 100%; height: auto !important; }
.ib-pdf-loading { color: var(--ib-muted); margin: auto; text-align: center; padding: 1rem; }
@media (max-width: 560px) { .ib-pdf-btn span { display: none; } }
.ib-note { font-style: italic; color: var(--ib-muted); }

/* ── Composer ──────────────────────────────────────────── */
.ib-composer {
  border-top: 1px solid var(--ib-border);
  background: var(--ib-panel);
  padding: 0.6rem 0.85rem calc(0.5rem + env(safe-area-inset-bottom));
}
.ib-compose-row, .ib-recording, .ib-attach-preview { display: flex; align-items: flex-end; gap: 0.55rem; }
.ib-recording, .ib-attach-preview { align-items: center; }
.ib-input {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  gap: 0.1rem;
  padding: 0.18rem 0.3rem;
  border-radius: 22px;
  border: 1px solid var(--ib-border);
  background: var(--ib-panel-2);
  transition: border-color .15s, background .15s;
}
.ib-input:focus-within { border-color: rgba(99,102,241,.55); background: rgba(255,255,255,.06); }
.ib-input .ib-icon-btn { width: 36px; height: 36px; border-radius: 50%; }
#ib-text {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 160px;
  padding: 0.5rem 0.35rem;
  border: 0;
  background: transparent;
  outline: none;
  line-height: 1.4;
  font-size: 16px; /* evita el zoom de iOS */
  box-shadow: none;
}
.ib-attach-preview { margin-bottom: 0.5rem; padding: 0.4rem 0.55rem; border-radius: 12px; background: var(--ib-panel-2); border: 1px solid var(--ib-border); font-size: 0.85rem; }
.ib-attach-preview span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }
.ib-attach-preview input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; padding: 0.3rem; box-shadow: none; }
.ib-send {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--ib-accent);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
  box-shadow: 0 4px 14px rgba(99,102,241,.35);
}
.ib-send:hover { background: var(--ib-accent-2); }
.ib-send:active { transform: scale(.94); }
.ib-send:disabled { opacity: .5; cursor: progress; }
.ib-recording { padding: 0.15rem 0; }
.ib-rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ib-danger); animation: ib-pulse 1.1s infinite; }
#ib-rec-time { font-variant-numeric: tabular-nums; min-width: 3ch; }
.ib-recording .ib-muted { flex: 1; }
@keyframes ib-pulse { 50% { opacity: .3; } }
.ib-kbd-hint { font-size: 0.72rem; color: var(--ib-muted-2); padding: 0.4rem 0.4rem 0; }
.ib-kbd-hint .ib-kbd { font-size: 0.64rem; padding: 0.12rem 0.3rem; }

/* Respuestas guardadas */
.ib-quick {
  margin-bottom: 0.55rem;
  border-radius: var(--ib-radius);
  background: var(--ib-panel-hi);
  border: 1px solid var(--ib-border-hi);
  box-shadow: 0 -8px 30px rgba(0,0,0,.35);
  overflow: hidden;
}
.ib-quick-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; padding: 0.6rem 0.85rem; border-bottom: 1px solid var(--ib-border); flex-wrap: wrap; }
.ib-quick-head strong { font-size: 0.88rem; font-weight: 600; display: inline-flex; gap: 0.45rem; align-items: center; }
.ib-quick-head .fa-bolt { color: #fbbf24; }
.ib-quick-list { max-height: 240px; overflow-y: auto; padding: 0.3rem; }
.ib-quick-item {
  display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; align-items: center;
  width: 100%;
  padding: 0.5rem 0.6rem;
  border-radius: 10px;
  border: 0; background: transparent; text-align: left; cursor: pointer;
}
.ib-quick-item:hover, .ib-quick-item.sel { background: var(--ib-panel-3); }
.ib-quick-item b { font-weight: 600; font-size: 0.85rem; color: var(--ib-accent-light); }
.ib-quick-item b::before { content: '/'; opacity: .6; }
.ib-quick-item p { margin: 0.1rem 0 0; font-size: 0.82rem; color: var(--ib-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ib-quick-item .ib-quick-del { opacity: 0; width: 30px; height: 30px; }
.ib-quick-item:hover .ib-quick-del, .ib-quick-item.sel .ib-quick-del, .ib-quick-del:focus-visible { opacity: 1; }
.ib-quick-empty { padding: 0.9rem; font-size: 0.85rem; color: var(--ib-muted); text-align: center; line-height: 1.45; }
.ib-quick-new {
  display: flex; gap: 0.45rem; align-items: center; justify-content: center;
  width: 100%;
  padding: 0.6rem;
  border: 0; border-top: 1px solid var(--ib-border);
  background: transparent; color: var(--ib-accent-light);
  font-size: 0.85rem; cursor: pointer;
}
.ib-quick-new:hover { background: var(--ib-panel-2); }
.ib-quick-form { display: flex; flex-direction: column; gap: 0.5rem; padding: 0.7rem 0.85rem; border-top: 1px solid var(--ib-border); }
.ib-quick-form input, .ib-quick-form textarea {
  padding: 0.5rem 0.65rem; border-radius: 10px;
  border: 1px solid var(--ib-border); background: var(--ib-panel-2);
  outline: none; resize: vertical; font-size: 15px;
}
.ib-quick-form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.ib-quick-form-actions .ib-btn { padding: 0.5rem 1rem; }

/* ── Ficha ─────────────────────────────────────────────── */
.ib-card {
  width: 340px;
  border-left: 1px solid var(--ib-border);
  background: var(--ib-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.ib-card-head { display: flex; align-items: center; justify-content: space-between; padding: 0.8rem 1rem; border-bottom: 1px solid var(--ib-border); min-height: 62px; }
.ib-card-body { padding: 1rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.9rem; }
.ib-summary {
  border-radius: var(--ib-radius);
  background: var(--ib-panel-2);
  border: 1px solid var(--ib-border);
  padding: 0.9rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem 0.8rem;
}
.ib-summary .ib-sum-level { grid-column: 1 / -1; font-weight: 600; display: flex; align-items: center; gap: 0.45rem; }
.ib-summary div span { display: block; font-size: 0.74rem; color: var(--ib-muted); }
.ib-summary div strong { font-size: 0.98rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.ib-field { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--ib-muted); }
.ib-field input, .ib-field textarea {
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--ib-border);
  background: var(--ib-panel-2);
  color: var(--ib-text);
  outline: none;
  resize: vertical;
  font-size: 15px;
}
.ib-field input:focus, .ib-field textarea:focus { border-color: rgba(99,102,241,.55); box-shadow: none; }
.ib-btn {
  border: 0;
  border-radius: 10px;
  padding: 0.65rem;
  background: var(--ib-accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.ib-btn:hover { background: var(--ib-accent-2); }
.ib-btn:disabled { opacity: .6; cursor: progress; }
.ib-star { color: #fbbf24; font-size: 0.75rem; }

/* ── Toasts / visor ────────────────────────────────────── */
.ib-toasts { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); display: flex; flex-direction: column; gap: 0.5rem; z-index: 50; width: min(440px, calc(100% - 32px)); pointer-events: none; }
.ib-toast {
  padding: 0.7rem 0.95rem;
  border-radius: 12px;
  background: #1b2133;
  border: 1px solid var(--ib-border-hi);
  font-size: 0.9rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  animation: ib-pop .2s ease-out;
}
.ib-toast.error { border-color: rgba(239,68,68,.5); }
.ib-toast.warn { border-color: rgba(245,158,11,.5); }
/* ── Modal de confirmación (borrar chat) ───────────────── */
.ib-modal { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 16px; }
.ib-modal[hidden] { display: none; }
.ib-modal-backdrop { position: absolute; inset: 0; background: rgba(3,5,10,.72); backdrop-filter: blur(3px); animation: ib-fade .15s ease-out; }
.ib-modal-box {
  position: relative;
  width: min(400px, 100%);
  padding: 1.5rem 1.4rem 1.25rem;
  border-radius: 18px;
  background: var(--ib-panel-hi);
  border: 1px solid var(--ib-border-hi);
  box-shadow: 0 24px 60px rgba(0,0,0,.55);
  text-align: center;
  animation: ib-pop .18s ease-out;
}
.ib-modal-icon {
  width: 48px; height: 48px; margin: 0 auto 0.9rem;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(239,68,68,.14);
  color: var(--ib-danger);
  font-size: 1.05rem;
}
.ib-modal-box h2 { margin: 0 0 0.5rem; font-size: 1.08rem; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.ib-modal-box p { margin: 0 0 1.25rem; color: var(--ib-muted); font-size: 0.9rem; line-height: 1.5; }
.ib-modal-actions { display: flex; gap: 0.6rem; }
.ib-modal-actions > button { flex: 1; padding: 0.7rem 1rem; font-size: 0.92rem; font-weight: 600; border-radius: 11px; }
.ib-btn-danger { background: var(--ib-danger); }
.ib-btn-danger:hover { background: #dc2626; }
@keyframes ib-fade { from { opacity: 0; } }
@keyframes ib-sheet { from { transform: translateY(100%); } }
@media (max-width: 760px) {
  /* En celular: hoja desde abajo, botones grandes y apilados. */
  .ib-modal { place-items: end stretch; padding: 0; }
  .ib-modal-box {
    width: 100%;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    padding: 1.4rem 1.25rem calc(1.1rem + env(safe-area-inset-bottom));
    animation: ib-sheet .22s cubic-bezier(.2,.8,.2,1);
  }
  .ib-modal-actions { flex-direction: column-reverse; }
  .ib-modal-actions > button { padding: 0.85rem 1rem; font-size: 1rem; }
}
.ib-viewer { position: fixed; inset: 0; background: rgba(0,0,0,.88); display: grid; place-items: center; z-index: 60; cursor: zoom-out; }
.ib-viewer img { max-width: 94vw; max-height: 92vh; border-radius: 8px; }

/* ── Stickers ──────────────────────────────────────────── */
.ib-stickers {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 0.4rem;
  margin-bottom: 0.55rem;
  padding: 0.6rem;
  border-radius: var(--ib-radius);
  background: var(--ib-panel-hi);
  border: 1px solid var(--ib-border-hi);
  box-shadow: 0 -8px 30px rgba(0,0,0,.35);
  max-height: 230px;
  overflow-y: auto;
}
.ib-sticker-opt {
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 0.25rem;
  cursor: pointer;
  aspect-ratio: 1;
  transition: background .12s, transform .12s;
}
.ib-sticker-opt:hover, .ib-sticker-opt:focus-visible { background: var(--ib-panel-3); transform: scale(1.04); }
.ib-sticker-opt img { width: 100%; height: 100%; object-fit: contain; display: block; }

/* ── Naturalidad: avisos y confirmación ────────────────── */
/* Los avisos van ARRIBA del cuadro de texto, bien a la vista, y el cuadro
   se pinta del color del aviso mientras haya uno. */
.ib-hints { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.5rem; }
.ib-hints:empty { display: none; }
.ib-hint {
  font-size: 0.9rem;
  color: var(--ib-text);
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  padding: 0.55rem 0.8rem;
  line-height: 1.4;
  border-radius: 12px;
  background: rgba(148, 163, 184, 0.10);
  border: 1px solid rgba(148, 163, 184, 0.28);
  animation: ib-pop .18s ease-out;
}
.ib-hint.warn {
  color: #fde68a;
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.6);
  font-weight: 600;
}
.ib-hint.warn i { color: #fbbf24; font-size: 1.05rem; }
.ib-hint i { flex-shrink: 0; margin-top: 0.12rem; }
/* Cómo sale el mensaje con las variables completas */
.ib-hint.vars {
  background: rgba(129, 140, 248, 0.10);
  border-color: rgba(129, 140, 248, 0.35);
}
.ib-hint.vars i { color: var(--ib-accent-light); }
.ib-hint.vars span {
  white-space: pre-wrap; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
/* Menú de variables (mismo panel que las respuestas guardadas) */
.ib-vars .ib-quick-head .fa-wand-magic-sparkles { color: var(--ib-accent-light); }
.ib-var-item { grid-template-columns: 1fr; }
.ib-var-item b::before { content: none; }
.ib-var-item .ib-var-title { font-size: 0.82rem; color: var(--ib-text); }
.ib-var-item p { white-space: normal; }
.ib-hints:not(:empty) ~ .ib-kbd-hint { display: none; }
.ib-hints:has(.warn) + .ib-compose-row .ib-input,
.ib-hints:has(.warn) + .ib-compose-row .ib-input:focus-within { border-color: rgba(245, 158, 11, 0.75); }
.ib-confirm {
  margin-bottom: 0.55rem;
  padding: 0.8rem 0.9rem;
  border-radius: var(--ib-radius);
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.3);
  font-size: 0.88rem;
}
.ib-confirm strong { color: #fcd34d; display: flex; gap: 0.45rem; align-items: center; }
.ib-confirm ul { margin: 0.45rem 0 0.7rem; padding-left: 1.15rem; color: var(--ib-text); line-height: 1.45; }
.ib-confirm li + li { margin-top: 0.25rem; }
.ib-confirm-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.ib-confirm-actions .ib-btn { padding: 0.5rem 0.9rem; }
.ib-btn-ghost {
  border: 1px solid var(--ib-border);
  border-radius: 10px;
  padding: 0.5rem 0.9rem;
  background: transparent;
  color: var(--ib-muted);
  cursor: pointer;
}
.ib-btn-ghost:hover { color: var(--ib-text); border-color: var(--ib-border-hi); }
/* Stickers sin globo, como en WhatsApp */
.ib-bubble.ib-bubble-sticker, .ib-msg.out .ib-bubble.ib-bubble-sticker { background: transparent; padding: 0; box-shadow: none; }
.ib-bubble.ib-bubble-sticker::before { display: none; }
.ib-bubble-sticker .ib-meta { justify-content: flex-end; }
.ib-bubble-sticker .ib-meta span, .ib-bubble-sticker .ib-meta i { background: rgba(0,0,0,.45); border-radius: 6px; padding: 0 0.3rem; }
.ib-bubble-sticker .ib-sticker { background: transparent; min-height: 0; }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 1180px) {
  .ib-card { position: fixed; right: 0; top: 0; bottom: 0; z-index: 40; box-shadow: -20px 0 50px rgba(0,0,0,.5); }
}
@media (max-width: 760px) {
  .ib-app { grid-template-columns: minmax(0, 1fr); }
  .ib-side, .ib-main { min-width: 0; }
  .ib-app[data-view="list"] .ib-main { display: none; }
  .ib-app[data-view="chat"] .ib-side { display: none; }
  .ib-only-mobile { display: grid; }
  .ib-only-desktop { display: none !important; }
  .ib-messages { padding: 0.75rem 0.85rem 0.5rem; }
  .ib-bubble { max-width: 86%; }
  .ib-card { width: 100%; }
  .ib-badge { display: none; }
  /* Poco lugar: solo el ícono, así se ven el número y el “escribiendo…” */
  .ib-chat-names .ib-type { font-size: 0; padding: 0.15rem 0.3rem; }
  .ib-chat-names .ib-type i { font-size: 0.68rem; }
  .ib-chat-head { padding: 0.5rem 0.5rem; gap: 0.3rem; }
  .ib-chat-head .ib-icon-btn { width: 34px; height: 34px; }
  .ib-flag-btn { width: 30px; height: 30px; }
  .ib-composer { padding-left: 0.55rem; padding-right: 0.55rem; }
}
@media (prefers-reduced-motion: reduce) {
  .ib-skel-row, .ib-skel-msg, .ib-rec-dot { animation: none; }
  .ib-msg.new .ib-bubble, .ib-toast { animation: none; }
  .ib-modal-backdrop, .ib-modal-box { animation: none; }
}
