/* ═══════════════════════════════════════════════════════════════════
   Anvid · Bandeja de Entrada + CRM (vista "Chats")
   Consistente con el panel: dark navy, glass, teal, Inter, pills.
   Tokens vienen de :root en dashboard.html (--bg, --accent, --border…).
   ═══════════════════════════════════════════════════════════════════ */

.ib-wrap {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 18px;
  height: calc(100vh - 230px);
  min-height: 480px;
}

/* ── Columna IZQ: lista de chats ── */
.ib-list {
  display: flex; flex-direction: column; min-height: 0;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-soft, #1f2b40);
  border-radius: 16px; overflow: hidden;
}
.ib-tools {
  padding: 14px; border-bottom: 1px solid var(--border-soft, #1f2b40);
  display: grid; gap: 10px;
}
.ib-search { position: relative; }
.ib-search svg {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--placeholder, #64748b); pointer-events: none;
}
.ib-search .form-input { padding-left: 38px; }
.ib-etiqueta-sel { font-size: 0.86em; }

.ib-rows { flex: 1; overflow-y: auto; min-height: 0; }
.ib-rows::-webkit-scrollbar, .ib-msgs::-webkit-scrollbar { width: 6px; }
.ib-rows::-webkit-scrollbar-thumb, .ib-msgs::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.10); border-radius: 10px;
}

.ib-empty {
  padding: 34px 20px; text-align: center;
  color: var(--placeholder, #64748b); font-size: 0.88em; line-height: 1.7;
}

.ib-row {
  display: flex; gap: 12px; padding: 12px 14px; cursor: pointer;
  border-bottom: 1px solid rgba(51, 65, 85, 0.35);
  border-left: 2px solid transparent;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.ib-row:hover { background: rgba(255, 255, 255, 0.04); }
.ib-row.sel { background: color-mix(in srgb, var(--accent) 12%, transparent); border-left-color: var(--accent, #14b8a6); }

.ib-avatar {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft, color-mix(in srgb, var(--accent) 14%, transparent));
  border: 1px solid color-mix(in srgb, var(--accent) 32%, transparent);
  color: var(--accent, #14b8a6); font-weight: 700; font-size: 1em;
}
.ib-row-main { flex: 1; min-width: 0; }
.ib-row-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ib-row-nombre {
  font-weight: 600; font-size: 0.94em; color: var(--text, #f8fafc);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ib-row-hora { font-size: 0.72em; color: var(--placeholder, #64748b); flex-shrink: 0; }
.ib-row-tel { font-size: 0.76em; color: var(--muted, #94a3b8); letter-spacing: 0.2px; }
.ib-row-bot { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.ib-row-last {
  flex: 1; min-width: 0; font-size: 0.82em; color: var(--muted, #94a3b8);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ib-badge {
  background: var(--accent-2, #10b981); color: #fff;
  border-radius: 100px; min-width: 20px; height: 20px; padding: 0 6px;
  font-size: 0.72em; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.ib-pill { font-size: 0.7em !important; padding: 2px 10px !important; flex-shrink: 0; }
.ib-pill::before { width: 6px; height: 6px; }

/* ── Columna DER: hilo de mensajes ── */
.ib-thread {
  display: flex; flex-direction: column; min-height: 0;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-soft, #1f2b40);
  border-radius: 16px; overflow: hidden;
}
.ib-thread-empty {
  margin: auto; padding: 44px 30px; text-align: center;
  color: var(--muted, #94a3b8);
}
.ib-thread-empty svg { width: 48px; height: 48px; color: var(--placeholder, #64748b); margin-bottom: 14px; }
.ib-thread-empty h3 { color: var(--text, #f8fafc); font-size: 1.05em; font-weight: 700; margin-bottom: 6px; }
.ib-thread-empty p { font-size: 0.9em; }

.ib-thread-head {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 18px; border-bottom: 1px solid var(--border-soft, #1f2b40);
  background: rgba(30, 41, 59, 0.35);
}
.ib-thread-id { flex: 1; min-width: 0; }
.ib-thread-nombre {
  font-weight: 700; font-size: 1em; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ib-thread-tel { font-size: 0.78em; color: var(--muted, #94a3b8); letter-spacing: 0.3px; }
.ib-btn-datos { padding: 8px 14px; font-size: 0.82em; height: auto; flex-shrink: 0; }

.ib-back {
  display: none; width: 34px; height: 34px; flex-shrink: 0;
  align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border, #334155);
  border-radius: 9px; color: var(--text, #f8fafc); cursor: pointer;
}
.ib-back svg { width: 18px; height: 18px; }

.ib-msgs {
  flex: 1; overflow-y: auto; min-height: 0;
  padding: 20px 18px; display: flex; flex-direction: column; gap: 10px;
  /* Fondo con identidad Anvid: patrón geométrico sutil (puntos, anillos y
     cuadros redondeados teal) sobre navy — inspirado en chat moderno, NO en
     el estilo doodle de WhatsApp (para evitar confusiones de marca). */
  background-color: #0a1322;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='%232dd4bf' fill-opacity='0.05'%3E%3Ccircle cx='24' cy='30' r='2.2'/%3E%3Ccircle cx='96' cy='14' r='1.6'/%3E%3Ccircle cx='134' cy='52' r='2'/%3E%3Ccircle cx='58' cy='86' r='1.8'/%3E%3Ccircle cx='118' cy='118' r='2.4'/%3E%3Ccircle cx='16' cy='128' r='1.6'/%3E%3C/g%3E%3Cg fill='none' stroke='%232dd4bf' stroke-opacity='0.055' stroke-width='1.4'%3E%3Crect x='52' y='24' width='16' height='16' rx='5' transform='rotate(14 60 32)'/%3E%3Crect x='112' y='76' width='12' height='12' rx='4' transform='rotate(-12 118 82)'/%3E%3Crect x='20' y='72' width='10' height='10' rx='3' transform='rotate(8 25 77)'/%3E%3Cpath d='M84 56l10-6 10 6' stroke-linecap='round'/%3E%3Cpath d='M44 132l8 6 8-6' stroke-linecap='round'/%3E%3Cpath d='M132 140l7-5 7 5' stroke-linecap='round'/%3E%3Ccircle cx='80' cy='104' r='8'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 160px 160px;
  background-attachment: local;
}
.ib-msg { display: flex; }
.ib-msg.out { justify-content: flex-end; }
.ib-bubble {
  max-width: 72%; padding: 10px 14px; border-radius: 16px;
  font-size: 0.92em; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  color: var(--text, #f8fafc);
}
.ib-msg.in .ib-bubble {
  background: rgba(51, 65, 85, 0.45);
  border: 1px solid var(--border, #334155);
  border-bottom-left-radius: 6px;
}
.ib-msg.out .ib-bubble {
  background: color-mix(in srgb, var(--accent-2) 16%, transparent);
  border: 1px solid rgba(45, 212, 191, 0.32);
  border-bottom-right-radius: 6px;
}
.ib-hora {
  display: block; margin-top: 4px; text-align: right;
  font-size: 0.68em; color: var(--placeholder, #64748b);
}

.ib-composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 14px; border-top: 1px solid var(--border-soft, #1f2b40);
}
.ib-composer textarea {
  flex: 1; resize: none; min-height: 42px; max-height: 140px;
  line-height: 1.5; padding: 10px 14px;
}
.ib-btn-send { flex-shrink: 0; height: 42px; padding: 0 22px; }
.ib-composer-acc {
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0;
}
.ib-contador {
  font-size: 0.68em; color: var(--placeholder, #64748b); min-height: 12px;
}
.ib-contador.limite { color: #f87171; font-weight: 600; }
.ib-no-entregado {
  display: block; margin-top: 4px; font-size: 0.68em; color: #f87171; font-style: italic;
}
.ib-msg.fallido .ib-bubble {
  border-color: rgba(248, 113, 113, 0.5);
}
.ib-retry { margin-top: 8px; }
.ib-banner-err {
  padding: 8px 12px; margin: 6px; border-radius: 8px; font-size: 0.82em;
  background: rgba(248, 113, 113, 0.12); border: 1px solid rgba(248, 113, 113, 0.35);
  color: #f87171;
}
.ib-retry-inline {
  background: none; border: none; color: inherit; cursor: pointer;
  text-decoration: underline; font: inherit; padding: 0;
}

/* ── Toggle Bot / Humano (header chico + modal grande) ── */
.ib-toggle-btn {
  position: relative; width: 104px; height: 32px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 100px; cursor: pointer;
  border: 1px solid rgba(245, 158, 11, 0.5);
  background: rgba(245, 158, 11, 0.18);
  color: var(--warn, #f59e0b); font-weight: 700; font-size: 0.78em;
  font-family: inherit; transition: background 0.22s ease, border-color 0.22s ease, color 0.22s ease;
}
.ib-toggle-btn .ib-knob {
  position: absolute; left: 5px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--warn, #f59e0b);
  transition: left 0.22s ease, background 0.22s ease;
}
.ib-toggle-btn.on {
  border-color: rgba(45, 212, 191, 0.5);
  background: color-mix(in srgb, var(--accent-2) 18%, transparent);
  color: var(--ok-light, #34d399);
}
.ib-toggle-btn.on .ib-knob { left: calc(100% - 27px); background: var(--ok-light, #34d399); }
.ib-toggle-btn.sm { width: 96px; height: 30px; font-size: 0.74em; }

/* ── Modal: Datos del cliente (CRM) ── */
.ib-datos-card { max-width: 480px; width: 100%; }
.ib-dato-tel {
  font-size: 1em; font-weight: 600; letter-spacing: 0.3px;
  color: var(--accent, #14b8a6); margin-bottom: 16px;
}
.ib-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; min-height: 28px; }
.ib-tags-vacio { color: var(--placeholder, #64748b); font-size: 0.82em; }
.ib-tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 100px;
  background: color-mix(in srgb, var(--accent) 14%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--ok-light, #34d399); font-size: 0.8em; font-weight: 600;
}
.ib-tag-x {
  background: none; border: none; color: inherit; cursor: pointer;
  font-size: 1.15em; line-height: 1; opacity: 0.8; padding: 0;
}
.ib-tag-x:hover { opacity: 1; color: var(--danger, #ef4444); }
.ib-tag-add { display: flex; gap: 8px; }
.ib-tag-add .form-input { flex: 1; }
.ib-tag-add .btn { height: 42px; padding: 0 16px; flex-shrink: 0; }

.ib-toggle-grande {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 16px; border-radius: 12px;
  background: rgba(30, 41, 59, 0.5); border: 1px solid var(--border, #334155);
}
.ib-toggle-grande .ib-toggle-btn { width: 116px; height: 38px; font-size: 0.86em; }
.ib-toggle-txt { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ib-toggle-txt strong { font-size: 0.92em; color: var(--text, #f8fafc); }
.ib-toggle-txt span { font-size: 0.78em; color: var(--muted, #94a3b8); line-height: 1.5; }

/* ── Responsive: <900px lista completa y el hilo se abre al elegir chat ── */
@media (max-width: 900px) {
  .ib-wrap { display: block; height: auto; min-height: 0; }
  .ib-list { height: calc(100vh - 210px); min-height: 380px; }
  .ib-thread { display: none; height: calc(100vh - 210px); min-height: 380px; }
  .ib-wrap.ib-open .ib-list { display: none; }
  .ib-wrap.ib-open .ib-thread { display: flex; }
  .ib-back { display: inline-flex; }
  .ib-btn-datos { padding: 7px 11px; font-size: 0.76em; }
  .ib-toggle-btn.sm { width: 84px; }
}
