/*=============================================
THEME — OneFlow CRM (rediseño)

Filosofía:
 - Tokens sobre :root, dark mode sobreescribe
 - Mantiene compatibilidad con Bootstrap y con
   las clases existentes del CRM
 - Nuevos componentes: sidebar oscuro, nav
   limpio, cards de contacto con avatar
   gradiente, chips modernos
=============================================*/

:root {
  /* Superficies */
  --bg-app:            #f4f5fa;
  --surface:           #ffffff;
  --surface-muted:     #f8fafc;
  --surface-chat:      #efeae2;

  /* Sidebar */
  --sidebar-bg:        #10152d;
  --sidebar-bg-2:      #171c39;
  --sidebar-fg:        #9ca3c4;
  --sidebar-fg-strong: #e5e7ee;
  --sidebar-hover:     #1e2447;
  --sidebar-active-bg: rgba(96, 165, 250, 0.14);
  --sidebar-active-fg: #7dd3fc;

  /* Texto */
  --text-primary:      #0f172a;
  --text-secondary:    #475569;
  --text-muted:        #94a3b8;

  /* Bordes */
  --border:            #e2e8f0;
  --border-strong:     #cbd5e1;
  --divider:           #eef1f6;

  /* Acentos */
  --accent-primary:    #2563eb;
  --accent-hover:      #1d4ed8;
  --accent-soft:       #dbeafe;
  --accent-text:       #1e3a8a;

  --success:           #16a34a;
  --success-soft:      #dcfce7;
  --success-text:      #14532d;

  --warning:           #f59e0b;
  --warning-soft:      #fef3c7;
  --warning-text:      #78350f;

  --danger:            #dc2626;
  --danger-soft:       #fee2e2;
  --danger-text:       #7f1d1d;

  --client-bubble:     #dcf7c5;
  --business-bubble:   #ffffff;

  /* Radios */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 999px;

  /* Sombras */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 2px 6px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.10);

  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode */
html[data-theme="dark"] {
  --bg-app:            #0a0e1f;
  --surface:           #12172c;
  --surface-muted:     #0e1327;
  --surface-chat:      #0d1123;

  --text-primary:      #e5e7ee;
  --text-secondary:    #a1a8bd;
  --text-muted:        #6b7285;

  --border:            #1e2447;
  --border-strong:     #2a3160;
  --divider:           #171c39;

  --accent-soft:       rgba(37, 99, 235, 0.18);
  --accent-text:       #93c5fd;

  --success-soft:      rgba(22, 163, 74, 0.15);
  --success-text:      #86efac;

  --warning-soft:      rgba(245, 158, 11, 0.15);
  --warning-text:      #fcd34d;

  --danger-soft:       rgba(220, 38, 38, 0.15);
  --danger-text:       #fca5a5;

  --client-bubble:     #1e3a2f;
  --business-bubble:   #1a1f3d;
}

/* ============================================================
   BASE — aplica Inter globalmente
   ============================================================ */
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--bg-app);
  color: var(--text-primary);
}

/* Bootstrap compat: mantener sus utilities pero con nuestros colores */
.backDashboard {
  background: var(--bg-app);
}

/* ============================================================
   TOPNAV (nav.php) — barra superior
   ============================================================ */
.topnav-new {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  gap: 16px;
}

.topnav-left,
.topnav-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.topnav-icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition);
  font-size: 18px;
}
.topnav-icon-btn:hover {
  background: var(--surface-muted);
  color: var(--text-primary);
}
.topnav-icon-btn i { font-size: 18px; }

.topnav-user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 5px;
  border-radius: var(--radius-full);
  color: var(--text-primary);
  text-decoration: none;
  transition: all var(--transition);
  background: var(--surface-muted);
}
.topnav-user-chip:hover {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.topnav-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4FC3F7, #2563eb);
  display: grid;
  place-items: center;
  color: white;
  font-size: 14px;
}

.topnav-user-name {
  font-size: 13px;
  font-weight: 500;
}

/* ============================================================
   SIDEBAR (sidebar.php) — barra lateral oscura
   ============================================================ */
#sidebar-wrapper.sidebar-wrapper-new,
.sidebar-wrapper-new {
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 250px;
  transition: width var(--transition);
  overflow: hidden;
}

/* Brand del CRM (arriba del sidebar) */
.sidebar-brand-new {
  padding: 18px 16px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  margin-bottom: 8px;
}

.sidebar-brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #7dd3fc, #2563eb);
  display: grid;
  place-items: center;
  color: white;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.02em;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  flex-shrink: 0;
  overflow: hidden;
}
/* Si el symbol_admin es una <img> o SVG, que se adapte */
.sidebar-brand-mark img,
.sidebar-brand-mark svg {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sidebar-brand-name {
  color: var(--sidebar-fg-strong);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Lista de páginas */
.sidebar-nav-list {
  list-style: none;
  padding: 4px 8px;
  margin: 0;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar-nav-list::-webkit-scrollbar { width: 6px; }
.sidebar-nav-list::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
}
.sidebar-nav-list::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.1); }

.sidebar-nav-item-wrap {
  position: relative;
  margin: 2px 0;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--sidebar-fg);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: all var(--transition);
  position: relative;
}

.sidebar-nav-item:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-fg-strong);
  text-decoration: none;
}

.sidebar-nav-item i {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  color: var(--sidebar-fg);
  transition: color var(--transition);
}
.sidebar-nav-item:hover i {
  color: var(--sidebar-active-fg);
}

/* Item activo (detectado por URL current — se puede setear con JS) */
.sidebar-nav-item.active,
.sidebar-nav-item[aria-current="page"] {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-fg);
  font-weight: 600;
}
.sidebar-nav-item.active i,
.sidebar-nav-item[aria-current="page"] i {
  color: var(--sidebar-active-fg);
}

.sidebar-nav-item.active::before,
.sidebar-nav-item[aria-current="page"]::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--sidebar-active-fg);
  border-radius: 0 3px 3px 0;
}

/* Acciones de superadmin (mover/editar/borrar) */
.sidebar-item-actions {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 2px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 6px;
  padding: 3px;
  opacity: 0;
  transition: opacity var(--transition);
}

.sidebar-nav-item-wrap:hover .sidebar-item-actions {
  opacity: 1;
}

.sidebar-action {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  border-radius: 4px;
  color: var(--sidebar-fg);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all var(--transition);
  font-size: 12px;
  padding: 0;
}
.sidebar-action:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--sidebar-fg-strong);
}
.sidebar-action.deletePage:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

/* Footer del sidebar */
.sidebar-footer-new {
  padding: 12px 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-add-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  color: var(--sidebar-fg);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.sidebar-add-btn:hover {
  background: var(--sidebar-hover);
  border-color: var(--sidebar-active-fg);
  color: var(--sidebar-active-fg);
}
.sidebar-add-btn i {
  font-size: 14px;
}

/* Sidebar colapsado (cuando el user aprieta el hamburguesa) */
#wrapper.toggled .sidebar-wrapper-new,
#wrapper.toggled #sidebar-wrapper {
  width: 68px;
}
#wrapper.toggled .menu-text,
#wrapper.toggled .sidebar-brand-name,
#wrapper.toggled .sidebar-item-actions,
#wrapper.toggled .sidebar-add-btn span {
  display: none;
}
#wrapper.toggled .sidebar-add-btn {
  padding: 10px 0;
}

/* ============================================================
   MAIN CONTAINER (layout del chat)
   ============================================================ */
.main-container {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: row;
  overflow: hidden;
  background: var(--bg-app);
}

#page-content-wrapper:has(.main-container) {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}
#page-content-wrapper:has(.main-container) > .container-fluid {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   CONTACT LIST (bandeja de chats)
   ============================================================ */
.contact-list {
  width: 380px;
  background-color: var(--surface);
  border-right: 1px solid var(--border);
  padding: 0;
  order: -1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* Header de la bandeja */
.contact-list h5 {
  padding: 20px 20px 12px;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

#chatsCount {
  background: var(--accent-soft) !important;
  color: var(--accent-text) !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  padding: 2px 9px !important;
  border-radius: var(--radius-full) !important;
  vertical-align: middle;
  margin-left: 6px;
}

/* Search dentro de la bandeja */
.contact-list .searchContact {
  margin: 0 16px 12px;
  padding: 10px 14px 10px 40px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-primary);
  width: calc(100% - 32px);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 14px center;
  transition: all var(--transition);
}
.contact-list .searchContact:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
  background-color: var(--surface);
  outline: none;
}
.contact-list .searchContact::placeholder {
  color: var(--text-muted);
}

/* Status tabs (Abiertos/Cerrados) */
.status-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin: 0 16px 12px;
  background: var(--surface-muted);
  border-radius: var(--radius-md);
  width: calc(100% - 32px);
}

.status-tabs .status-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition);
  border: none;
  background: transparent;
}
.status-tabs .status-tab:hover {
  color: var(--text-primary);
}
.status-tabs .status-tab.active {
  background: var(--surface);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}
.status-tabs .status-tab i {
  font-size: 14px;
}
.status-tabs .status-tab .badge {
  font-size: 11px;
  color: var(--text-muted);
  background: transparent;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  font-weight: 600;
}
.status-tabs .status-tab.active .badge {
  background: var(--accent-soft);
  color: var(--accent-text);
}

/* Lista scroll de items */
#lastIdMessage {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 8px 16px;
}
#lastIdMessage::-webkit-scrollbar { width: 6px; }
#lastIdMessage::-webkit-scrollbar-track { background: transparent; }
#lastIdMessage::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}
#lastIdMessage::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Los enlaces del chat.php ya envuelven todo con <a>. No queremos que rompa el layout */
#lastIdMessage a {
  text-decoration: none;
  color: inherit;
  display: block;
}

/* Item de contacto (contact-item) — rediseñado */
.contact-item {
  display: flex;
  gap: 12px;
  padding: 12px !important;
  margin: 2px 0 !important;
  background: transparent !important;
  border: 1px solid transparent !important;
  border-radius: var(--radius-md) !important;
  cursor: pointer;
  position: relative;
  transition: all var(--transition);
  box-shadow: none !important;
  align-items: flex-start;
}
.contact-item:hover {
  background: var(--surface-muted) !important;
}

/* Contact-item con borde verde original → nuestro estilo activo */
.contact-item[style*="border:1px solid #090"],
.contact-item[style*="border: 1px solid #090"] {
  background: var(--accent-soft) !important;
  border-color: rgba(37, 99, 235, 0.2) !important;
}

.contact-item .d-flex.justify-content-between {
  flex: 1;
  min-width: 0;
}

/* Nombre del contacto */
.contact-item strong {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

/* Fecha/hora */
.contact-item .small:not(.p) {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Preview del último mensaje */
.contact-item p.small {
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 4px 0 6px !important;
  max-width: 220px;
}

/* Bell notification */
.contact-item .bi-bell-fill {
  font-size: 12px;
  margin-right: 4px;
}
.contact-item .bi-bell-fill.text-success {
  color: var(--success) !important;
}

/* Checkbox del bot (IA) — más estilizado */
.contact-item .custom-checkbox {
  align-self: center;
}
.contact-item .form-check-input {
  width: 16px !important;
  height: 16px !important;
  border-radius: 4px !important;
  border-color: var(--border-strong) !important;
  cursor: pointer;
  margin-top: 0 !important;
}
.contact-item .form-check-input:checked {
  background-color: var(--success);
  border-color: var(--success);
}

.contact-item .custom-control-label i.fas.fa-robot {
  color: var(--text-muted);
  font-size: 14px;
}

/* Pill de canal (WhatsApp / Web) — .channel-pill del CRM actual */
.channel-pill {
  display: inline-flex !important;
  align-items: center !important;
  gap: 4px !important;
  padding: 2px 8px !important;
  border-radius: var(--radius-full) !important;
  font-size: 11px !important;
  font-weight: 500 !important;
  line-height: 1.4 !important;
  border: none !important;
  margin-top: 4px !important;
}
.channel-pill.channel-wa {
  background: var(--success-soft) !important;
  color: var(--success-text) !important;
}
.channel-pill.channel-web {
  background: var(--warning-soft) !important;
  color: var(--warning-text) !important;
}

/* Empty state */
.contact-list-empty,
#lastIdMessage > div[style*="text-align:center"] {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

/* ============================================================
   CHAT CONTAINER
   ============================================================ */
.chat-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface-chat);
  overflow: hidden;
  position: relative;
}

/* Chat header (arriba del chat) */
.chat-header {
  background: var(--surface) !important;
  border-bottom: 1px solid var(--border);
  padding: 12px 20px !important;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow-xs);
  z-index: 1;
  color: var(--text-primary) !important;
}

.chat-header > .d-flex:first-child {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-primary);
  min-width: 0;
}

.chat-header .bot-name {
  background: transparent !important;
  padding: 0 !important;
  color: var(--text-primary);
}

/* Nombre del contacto en el header (número o nombre) */
.chat-header h4,
.chat-header h5 {
  color: var(--text-primary) !important;
  font-size: 15px !important;
  font-weight: 600 !important;
  margin: 0 !important;
  letter-spacing: -0.01em;
}
.chat-header p,
.chat-header .small {
  color: var(--text-secondary) !important;
  font-size: 12px !important;
  margin: 2px 0 0 !important;
}

/* Botones de acción del chat header */
.chat-header .btn {
  color: var(--text-secondary) !important;
  background: transparent !important;
  border: none !important;
  padding: 6px !important;
  border-radius: var(--radius-md) !important;
  transition: all var(--transition);
  font-size: 15px;
}
.chat-header .btn:hover {
  background: var(--surface-muted) !important;
  color: var(--text-primary) !important;
}
.chat-header .btn:focus,
.chat-header .btn:active {
  box-shadow: none !important;
  outline: none !important;
}

/* El btn con bi-trash en el header → hover rojo */
.chat-header .btn:has(.bi-trash):hover,
.chat-header form#deleteContact .btn:hover {
  background: var(--danger-soft) !important;
  color: var(--danger-text) !important;
}

/* Toggle Abierto/Cerrado — estilo iOS switch */
.form-check-input.toggleStatus {
  width: 32px !important;
  height: 18px !important;
  cursor: pointer;
  background-color: #94a3b8;
  border-color: #94a3b8;
  transition: all var(--transition);
}
.form-check-input.toggleStatus:checked {
  background-color: #22c55e !important;
  border-color: #22c55e !important;
}
.form-check-input.toggleStatus:focus {
  box-shadow: 0 0 0 0.15rem rgba(34, 197, 94, 0.25) !important;
}

.form-check.form-switch label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}
.chat-header .form-check.form-switch label.text-white {
  color: var(--text-primary) !important;
}

/* Embudo pill dropdown */
.embudo-pill {
  display: inline-flex !important;
  align-items: center !important;
  gap: 6px !important;
  padding: 6px 14px !important;
  border-radius: var(--radius-full) !important;
  font-size: 12.5px !important;
  font-weight: 600 !important;
  color: white !important;
  border: none !important;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  box-shadow: none !important;
}
.embudo-pill:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm) !important;
  opacity: 0.95;
}
.embudo-pill:focus {
  outline: none !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15) !important;
}
.embudo-pill i {
  font-size: 12px !important;
}
.embudo-pill.dropdown-toggle::after {
  border: none !important;
  content: "";
  width: 8px;
  height: 8px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 16 16' fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-size: contain;
  vertical-align: middle;
  margin-left: 4px;
}

.embudo-menu {
  min-width: 240px !important;
  max-height: 400px;
  overflow-y: auto;
  font-size: 13px;
  padding: 6px !important;
  border-radius: var(--radius-md) !important;
  border: 1px solid var(--border) !important;
  background: var(--surface) !important;
  box-shadow: var(--shadow-lg) !important;
}
.embudo-menu .dropdown-item {
  padding: 8px 10px !important;
  border-radius: 6px !important;
  font-size: 13px;
  color: var(--text-primary) !important;
  transition: background var(--transition);
}
.embudo-menu .dropdown-item:hover {
  background: var(--surface-muted) !important;
}
.embudo-menu .dropdown-item.active {
  background: var(--accent-soft) !important;
  color: var(--accent-text) !important;
  font-weight: 600;
}
.embudo-menu .dropdown-divider {
  border-color: var(--divider);
  margin: 4px 0;
}

/* Modal historial embudo */
.embudo-mini-pill {
  color: #fff;
  padding: 3px 12px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  display: inline-block;
  line-height: 1.4;
}
.embudo-history-list {
  padding: 0;
  margin: 0;
}
.embudo-history-list li:last-child {
  border-bottom: none !important;
}

/* Dark mode overrides */
html[data-theme="dark"] .embudo-menu {
  background: #12172c !important;
  border-color: #1e2447 !important;
}
html[data-theme="dark"] .embudo-menu .dropdown-item {
  color: var(--text-primary) !important;
}
html[data-theme="dark"] .embudo-menu .dropdown-item:hover {
  background: #1e2447 !important;
}

/* ============================================================
   CHAT BODY (mensajes)
   ============================================================ */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 40px;
  background: var(--surface-chat);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(37, 99, 235, 0.03) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(125, 211, 252, 0.03) 0%, transparent 40%);
}
.chat-body::-webkit-scrollbar { width: 8px; }
.chat-body::-webkit-scrollbar-track { background: transparent; }
.chat-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}

/* Mensajes tipo cliente y business */
.msg {
  max-width: 62%;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  animation: bubbleIn 200ms cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg.user,
.msg.client {
  align-self: flex-start;
  align-items: flex-start;
  background: var(--client-bubble) !important;
  padding: 8px 12px !important;
  border-radius: 14px 14px 14px 4px !important;
  color: var(--text-primary) !important;
  box-shadow: var(--shadow-xs);
}
.msg.business {
  align-self: flex-end;
  align-items: flex-end;
  background: var(--business-bubble) !important;
  padding: 8px 12px !important;
  border-radius: 14px 14px 4px 14px !important;
  color: var(--text-primary) !important;
  box-shadow: var(--shadow-xs);
}

/* Fecha "Hoy" / dividers */
.chat-body .badge.bg-success {
  background: var(--surface) !important;
  color: var(--text-secondary) !important;
  font-size: 11.5px;
  font-weight: 500;
  padding: 5px 14px !important;
  border-radius: var(--radius-full) !important;
  box-shadow: var(--shadow-xs);
  border: 1px solid var(--border);
}

/* Chat input (donde se escribe) */
.chat-container form.d-flex,
.chat-container > .d-flex:last-child {
  background: var(--surface) !important;
  border-top: 1px solid var(--border);
  padding: 12px 20px !important;
  gap: 10px;
}

.chat-container input[type="text"],
.chat-container textarea {
  background: var(--surface-muted) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-full) !important;
  padding: 10px 18px !important;
  font-size: 14px !important;
  color: var(--text-primary) !important;
  transition: all var(--transition);
}
.chat-container input[type="text"]:focus,
.chat-container textarea:focus {
  border-color: var(--accent-primary) !important;
  background: var(--surface) !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08) !important;
  outline: none !important;
}

/* Botón enviar */
.chat-container button[type="submit"] {
  background: linear-gradient(135deg, #2563eb, #1d4ed8) !important;
  color: white !important;
  border: none !important;
  width: 40px !important;
  height: 40px !important;
  border-radius: 50% !important;
  display: grid !important;
  place-items: center !important;
  transition: all var(--transition);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  padding: 0 !important;
}
.chat-container button[type="submit"]:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
}
.chat-container button[type="submit"] i {
  font-size: 16px;
}

/* ============================================================
   MODAL — overrides globales
   ============================================================ */
.modal-content {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  border-bottom: 1px solid var(--border) !important;
  padding: 16px 20px !important;
}
.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}
.modal-body {
  color: var(--text-primary);
  padding: 20px !important;
}
.modal-footer {
  border-top: 1px solid var(--border) !important;
  padding: 12px 20px !important;
}

/* Inputs de formulario */
.form-control,
.form-select {
  background: var(--surface-muted) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-md) !important;
  color: var(--text-primary) !important;
  padding: 10px 14px !important;
  font-size: 14px !important;
  transition: all var(--transition);
}
.form-control:focus,
.form-select:focus {
  border-color: var(--accent-primary) !important;
  background: var(--surface) !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08) !important;
  color: var(--text-primary) !important;
}
.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
}

/* Botones estilizados */
.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8) !important;
  border: none !important;
  padding: 8px 18px !important;
  border-radius: var(--radius-md) !important;
  font-weight: 500;
  transition: all var(--transition);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}
.btn-secondary {
  background: var(--surface-muted) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-secondary) !important;
  padding: 8px 18px !important;
  border-radius: var(--radius-md) !important;
}
.btn-secondary:hover {
  background: var(--surface) !important;
  color: var(--text-primary) !important;
}
.btn-danger {
  background: var(--danger) !important;
  border: none !important;
  padding: 8px 18px !important;
  border-radius: var(--radius-md) !important;
}

/* Alert banners */
.alert {
  border-radius: var(--radius-md) !important;
  border: 1px solid transparent !important;
  padding: 12px 16px !important;
  font-size: 13px;
}
.alert-warning {
  background: var(--warning-soft) !important;
  color: var(--warning-text) !important;
  border-color: rgba(245, 158, 11, 0.2) !important;
}
.alert-danger {
  background: var(--danger-soft) !important;
  color: var(--danger-text) !important;
  border-color: rgba(220, 38, 38, 0.2) !important;
}
.alert-info {
  background: var(--accent-soft) !important;
  color: var(--accent-text) !important;
  border-color: rgba(37, 99, 235, 0.2) !important;
}

/* ============================================================
   Dark mode: ajustes específicos que no son automáticos
   ============================================================ */
html[data-theme="dark"] body {
  background: var(--bg-app);
  color: var(--text-primary);
}
html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select {
  background: var(--surface) !important;
  color: var(--text-primary) !important;
}
html[data-theme="dark"] .form-control:focus {
  background: var(--surface-muted) !important;
}
html[data-theme="dark"] .chat-header {
  background: var(--surface) !important;
  border-color: var(--border);
}
html[data-theme="dark"] .contact-list {
  background: var(--surface);
}
html[data-theme="dark"] .contact-item:hover {
  background: var(--surface-muted) !important;
}
html[data-theme="dark"] .chat-body {
  background: var(--surface-chat);
}
html[data-theme="dark"] .msg.business {
  background: var(--business-bubble) !important;
  color: var(--text-primary) !important;
}
html[data-theme="dark"] .msg.client,
html[data-theme="dark"] .msg.user {
  background: var(--client-bubble) !important;
  color: var(--text-primary) !important;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 992px) {
  .contact-list {
    width: 100%;
    max-width: 100%;
    border-right: none;
  }
}

/* ============================================================
   AVATAR de contacto en la bandeja
   ============================================================ */
.contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
  position: relative;
  align-self: center;
}
.contact-avatar::after {
  content: '';
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--surface);
}
.contact-avatar.web::after { background: #f59e0b; }

/* Wrapper del contenido del item (nombre, preview, chip) */
.contact-body-wrap {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.contact-body-wrap > .d-flex {
  min-width: 0;
}
.contact-body-wrap > .d-flex > div:first-child {
  min-width: 0;
  flex: 1;
}

/* ============================================================
   FIXES post-lanzamiento
   ============================================================ */

/* Contact item activo — usando clase en vez de inline style */
.contact-item.is-active {
  background: var(--accent-soft) !important;
  border: 1px solid rgba(37, 99, 235, 0.25) !important;
}

/* Chip de etapa del embudo — versión mini para el card de contacto */
.embudo-chip-mini {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 10.5px;
  font-weight: 600;
  color: white;
  line-height: 1.4;
  letter-spacing: -0.01em;
  white-space: nowrap;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Status tabs — asegurar que ocupen todo el ancho */
.status-tabs {
  width: calc(100% - 32px) !important;
  margin: 0 16px 12px !important;
}
.status-tabs .status-tab {
  flex: 1 1 0;
  border-radius: 8px !important;
}
/* Anular estilos de Bootstrap btn-group si el HTML aún los trae */
.status-tabs.btn-group > .status-tab:not(:last-child) {
  border-top-right-radius: 8px !important;
  border-bottom-right-radius: 8px !important;
}
.status-tabs.btn-group > .status-tab:not(:first-child) {
  border-top-left-radius: 8px !important;
  border-bottom-left-radius: 8px !important;
  margin-left: 0 !important;
}

/* ============================================================
   FIX v2: Tabs más compactos + chip que no se salga
   ============================================================ */

/* Tabs Abiertos/Cerrados: texto más chico, padding reducido */
.status-tabs .status-tab {
  font-size: 12px !important;
  padding: 7px 8px !important;
  gap: 5px !important;
  min-width: 0;
  overflow: hidden;
}
.status-tabs .status-tab i {
  font-size: 12px !important;
  flex-shrink: 0;
}
.status-tabs .status-tab .badge {
  font-size: 10px !important;
  padding: 1px 5px !important;
  flex-shrink: 0;
}

/* El texto del tab (Abiertos/Cerrados) puede truncar si no cabe */
.status-tabs .status-tab {
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ============================================================
   BOTÓN "Cargar mensajes anteriores"
   ============================================================ */
.btn-load-older {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border, #e2e8f0);
  background: var(--surface, #ffffff);
  color: var(--text-secondary, #64748b);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 200ms ease;
  margin: 4px auto;
}
.btn-load-older:hover {
  background: var(--accent-soft, #f0f7ff);
  border-color: var(--accent, #7dd3fc);
  color: var(--text, #0f172a);
  transform: translateY(-1px);
}
.btn-load-older:active {
  transform: scale(0.97);
}
.btn-load-older i {
  font-size: 14px;
}
