:root {
  --primary: #128c7e;
  --primary-dark: #075e54;
  --primary-light: #25d366;
  --bg-main: #f0f2f5;
  --bg-card: #ffffff;
  --text-main: #111b21;
  --text-muted: #667781;
  --border: #e9edef;
  --ia-bubble: #e7f3ff;
  --ia-text: #0b3d6f;
  --user-bubble: #ffffff;
  --agent-bubble: #d9fdd3;
  --agent-text: #0f4c1c;
  --danger: #ea4335;
  --warning: #f59e0b;
  --radius: 12px;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.06);

  /* Spacing Scale */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;

  /* Paleta de colores de las etapas CRM */
  --stage-prospeccion: #f59e0b;
  --stage-prospeccion-bg: #fef3c7;
  --stage-prospeccion-text: #92400e;
  --stage-prospeccion-border: #fde68a;

  --stage-radicacion: #2563eb;
  --stage-radicacion-bg: #dbeafe;
  --stage-radicacion-text: #1d4ed8;
  --stage-radicacion-border: #bfdbfe;

  --stage-legalizacion: #10b981;
  --stage-legalizacion-bg: #dcfce7;
  --stage-legalizacion-text: #15803d;
  --stage-legalizacion-border: #bbf7d0;

  --stage-aprobado: #059669;
  --stage-aprobado-bg: #ecfdf5;
  --stage-aprobado-text: #047857;
  --stage-aprobado-border: #a7f3d0;

  --stage-rechazado: #ef4444;
  --stage-rechazado-bg: #fee2e2;
  --stage-rechazado-text: #b91c1c;
  --stage-rechazado-border: #fecaca;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: white;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: white;
  color: var(--primary-dark);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: bold;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.app-header .subtitle {
  font-size: 0.8rem;
  opacity: 0.85;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.18);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 500;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background-color: #25d366;
  box-shadow: 0 0 6px #25d366;
}

/* Nav Tabs */
.nav-tabs {
  background: white;
  display: flex;
  gap: 8px;
  padding: 8px 24px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab-btn {
  background: none;
  border: none;
  padding: 10px 18px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  background-color: #f5f6f6;
  color: var(--text-main);
}

.tab-btn.active {
  background-color: #e8f5e9;
  color: var(--primary-dark);
}

/* Main Container */
.main-content {
  flex: 1;
  padding: 12px 18px;
  max-width: 100%;
  width: 100%;
  margin: 0;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.2s ease-in-out;
}

.tab-pane.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Live Chat Layout (Panel 1) */
.live-chat-container {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr) 350px;
  height: calc(100vh - 120px);
  min-height: 580px;
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow);
  width: 100%;
}

.copiloto-pane {
  border-left: 1px solid var(--border);
  background: #fcfcfc;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  padding: 14px 16px;
}

.chats-sidebar {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: #fcfcfc;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: white;
  flex-shrink: 0;
}

.search-box {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
  outline: none;
  background: #f0f2f5;
}

.search-box:focus {
  background: white;
  border-color: var(--primary);
}

.filter-pills-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
}

.pills-nav-btn {
  background: #e2e8f0;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 0.62rem;
  font-weight: bold;
  color: #475569;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
  user-select: none;
  padding: 0;
}

.pills-nav-btn:hover {
  background: var(--primary);
  color: white;
}

.filter-pills {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  white-space: nowrap;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
  padding: 2px 2px 4px 2px;
  flex: 1;
}

.filter-pills::-webkit-scrollbar {
  height: 4px;
}

.filter-pills::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.filter-pills::-webkit-scrollbar-track {
  background: transparent;
}

.pill-btn {
  background: #f0f2f5;
  border: none;
  padding: 4px 9px;
  border-radius: 12px;
  font-size: 0.73rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.pill-btn.active {
  background: var(--primary-dark);
  color: white;
}

.pill-count {
  display: inline-block;
  background: rgba(0, 0, 0, 0.08);
  padding: 1px 5px;
  border-radius: 8px;
  font-size: 0.65rem;
  font-weight: 700;
}

.pill-btn.active .pill-count {
  background: rgba(255, 255, 255, 0.28);
  color: white;
}

.conversations-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
}

.conv-item {
  padding: 12px 16px;
  border-bottom: 1px solid #f0f2f5;
  cursor: pointer;
  display: flex;
  gap: 12px;
  align-items: center;
  transition: background 0.15s ease;
}

.conv-item:hover {
  background-color: #f5f6f6;
}

.conv-item.active {
  background-color: #e8f5e9;
  border-left: 4px solid var(--primary);
}

.conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #dfe5e7;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #54656f;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.conv-info {
  flex: 1;
  min-width: 0;
}

.conv-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.conv-name {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.conv-preview {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-ia {
  background: #e3f2fd;
  color: #1976d2;
}

.badge-humano {
  background: #fff3e0;
  color: #e65100;
}

.badge-prospeccion {
  background: var(--stage-prospeccion-bg);
  color: var(--stage-prospeccion-text);
  border: 1px solid var(--stage-prospeccion-border);
}

.badge-radicacion {
  background: var(--stage-radicacion-bg);
  color: var(--stage-radicacion-text);
  border: 1px solid var(--stage-radicacion-border);
}

.badge-legalizacion {
  background: var(--stage-legalizacion-bg);
  color: var(--stage-legalizacion-text);
  border: 1px solid var(--stage-legalizacion-border);
}

.badge-aprobado {
  background: var(--stage-aprobado-bg);
  color: var(--stage-aprobado-text);
  border: 1px solid var(--stage-aprobado-border);
}

.badge-rechazado {
  background: var(--stage-rechazado-bg);
  color: var(--stage-rechazado-text);
  border: 1px solid var(--stage-rechazado-border);
}

.client-crm-bar {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  gap: 16px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.crm-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.crm-item strong {
  color: var(--text-main);
}

.crm-editable-tag {
  color: var(--text-main);
  font-weight: 700;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0,0,0,0.03);
  border: 1px dashed #cbd5e1;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.crm-editable-tag:hover {
  background: #e2e8f0;
  border-color: var(--primary);
  color: var(--primary-dark);
}

.crm-editable-tag::after {
  content: '✎';
  font-size: 0.65rem;
  opacity: 0.5;
}

.stage-select {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 700;
  background: white;
  cursor: pointer;
}

.badge-unread {
  background: #25d366;
  color: white;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 6px;
  font-weight: bold;
}

/* Chat Thread Area */
.chat-window {
  display: flex;
  flex-direction: column;
  background: #efeae2;
  position: relative;
  min-height: 0;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

.chat-header {
  background: white;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-title {
  font-weight: 700;
  font-size: 1rem;
}

.header-phone {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.handover-control {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle-mode-btn {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.toggle-mode-btn.is-ia {
  background: #e8f5e9;
  color: var(--primary-dark);
  border-color: #c8e6c9;
}

.toggle-mode-btn.is-human {
  background: #fff3e0;
  color: #e65100;
  border-color: #ffe0b2;
}

.chat-messages {
  flex: 1 1 0;
  min-height: 0;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-image: radial-gradient(#d4cdc4 1px, transparent 1px);
  background-size: 20px 20px;
  position: relative;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}

.msg-row.usuario {
  align-self: flex-start;
}

.msg-row.ia, .msg-row.asesor {
  align-self: flex-end;
}

.msg-bubble {
  padding: 11px 15px;
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.5;
  position: relative;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

/* Scrollbars siempre visibles y ergonómicos estilo WhatsApp Web */
.wa-screen,
.chat-messages,
.conversations-list {
  scrollbar-width: thin;
  scrollbar-color: #8c9b9e #f0ece6;
}

.wa-screen::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar,
.conversations-list::-webkit-scrollbar {
  width: 9px;
}
.wa-screen::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb,
.conversations-list::-webkit-scrollbar-thumb {
  background: #9ca3af;
  border-radius: 6px;
  border: 2px solid #efeae2;
}
.wa-screen::-webkit-scrollbar-thumb:hover,
.chat-messages::-webkit-scrollbar-thumb:hover,
.conversations-list::-webkit-scrollbar-thumb:hover {
  background: #4b5563;
}
.wa-screen::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track,
.conversations-list::-webkit-scrollbar-track {
  background: #f3f4f6;
  border-radius: 6px;
}

/* Botón flotante para bajar al último mensaje */
.btn-scroll-bottom {
  position: absolute;
  bottom: 74px;
  right: 18px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #ffffff;
  color: #4b5563;
  border: 1px solid rgba(0,0,0,0.12);
  box-shadow: 0 4px 10px rgba(0,0,0,0.16);
  font-size: 1.25rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0.95;
}

.btn-scroll-bottom:hover {
  background: #f3f4f6;
  color: var(--primary);
  transform: translateY(-2px) scale(1.06);
  box-shadow: 0 6px 14px rgba(0,0,0,0.22);
}

.msg-row.usuario .msg-bubble {
  background: var(--user-bubble);
  color: var(--text-main);
  border-top-left-radius: 0;
}

.msg-row.ia .msg-bubble {
  background: var(--ia-bubble);
  color: var(--ia-text);
  border-top-right-radius: 0;
}

.msg-row.asesor .msg-bubble {
  background: var(--agent-bubble);
  color: var(--agent-text);
  border-top-right-radius: 0;
}

.msg-sender-tag {
  font-size: 0.72rem;
  font-weight: 700;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.msg-time {
  font-size: 0.68rem;
  opacity: 0.7;
  text-align: right;
  margin-top: 4px;
}

.chat-input-bar {
  background: #f0f2f5;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.agent-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
}

.agent-input:focus {
  border-color: var(--primary);
  background: white;
}

.btn-send-agent {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
}

.btn-send-agent:hover {
  background: var(--primary-dark);
}

/* Auditoría y Métricas (Panel 2) */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: white;
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.kpi-title {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-main);
}

.kpi-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.audit-table-card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.audit-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
}

.audit-table th {
  background: #f8fafc;
  padding: 12px 18px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.audit-table td {
  padding: 12px 18px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}

/* Config & Prompt Engine (Panel 3) */
.config-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary-dark);
}

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-main);
}

.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(18, 140, 126, 0.15);
}

.form-textarea {
  min-height: 120px;
  resize: vertical;
}

.form-help {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.18s ease;
  user-select: none;
}

.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(18, 140, 126, 0.25);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: #f1f5f9;
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 9px 18px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.18s ease;
  user-select: none;
}

.btn-secondary:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
  transform: translateY(-1px);
}

.btn-secondary:active {
  transform: scale(0.97);
}

.btn-primary:disabled,
.btn-secondary:disabled,
button:disabled {
  opacity: 0.55 !important;
  cursor: not-allowed !important;
  transform: none !important;
  box-shadow: none !important;
}

/* Simulador WhatsApp (Smartphone Virtual) */
.simulator-layout {
  display: grid;
  grid-template-columns: minmax(360px, 460px) minmax(380px, 1fr);
  gap: 20px;
  width: 100%;
  height: calc(100vh - 120px);
  min-height: 580px;
  padding: 0;
  box-sizing: border-box;
}

@media (max-width: 950px) {
  .simulator-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
}

.simulator-layout:has(.phone-mockup.expanded-view) {
  grid-template-columns: minmax(420px, 1.25fr) minmax(360px, 1fr);
}

.phone-mockup {
  width: 100%;
  max-width: 100%;
  height: 100%;
  background: #ffffff;
  border-radius: 28px;
  box-shadow: 0 16px 36px rgba(0,0,0,0.14), 0 0 0 10px #1f2937;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-sizing: border-box;
}

.phone-mockup.expanded-view {
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(0,0,0,0.12), 0 0 0 4px #1f2937;
}

.phone-mockup.expanded-view .phone-speaker {
  display: none;
}

.phone-speaker {
  width: 60px;
  height: 5px;
  background: #374151;
  border-radius: 3px;
  position: absolute;
  top: 10px;
  left: calc(50% - 30px);
  z-index: 10;
}

.wa-header {
  background: var(--primary-dark);
  color: white;
  padding: 24px 16px 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.wa-avatar {
  width: 36px;
  height: 36px;
  background: white;
  color: var(--primary-dark);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.wa-contact-name {
  font-size: 0.95rem;
  font-weight: 600;
}

.wa-status {
  font-size: 0.72rem;
  opacity: 0.85;
}

.wa-screen {
  flex: 1 1 0;
  min-height: 0;
  background: #efeae2;
  padding: 16px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}

.wa-input-bar {
  background: #f0f2f5;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.wa-input {
  flex: 1;
  background: white;
  border: none;
  padding: 10px 14px;
  border-radius: 20px;
  font-size: 0.88rem;
  outline: none;
}

.wa-send-btn {
  background: var(--primary);
  color: white;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sim-controls-card {
  width: 100%;
  max-width: 100%;
  height: 100%;
  overflow-y: auto;
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  box-sizing: border-box;
}

/* Toast Notifier */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1f2937;
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
  font-size: 0.9rem;
  z-index: 9999;
  display: none;
  animation: slideIn 0.25s ease-out;
}

@keyframes slideIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Centro de Entrenamiento Modular (Nuevas Opciones) */
.training-header-box {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 20px 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.training-subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
  padding-bottom: 4px;
}

.training-subnav-btn {
  background: white;
  border: 1px solid #cbd5e1;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: all 0.15s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.training-subnav-btn:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

.training-subnav-btn.active {
  background: var(--primary-dark);
  color: white;
  border-color: var(--primary-dark);
  box-shadow: 0 3px 8px rgba(7, 94, 84, 0.25);
}

.training-badge-count {
  background: #f0f2f5;
  color: var(--text-main);
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 700;
}

.training-subnav-btn.active .training-badge-count {
  background: rgba(255, 255, 255, 0.25);
  color: white;
}

.training-pane {
  display: none;
  animation: fadeIn 0.2s ease-in-out;
}

.training-pane.active {
  display: block;
}

.training-item-card {
  background: #fcfcfc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  transition: all 0.15s ease;
}

.training-item-card:hover {
  border-color: #cbd5e1;
  background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.training-item-card.is-inactive {
  opacity: 0.55;
  background: #f9f9f9;
}

.training-pill-tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.pill-tag-red {
  background: #fee2e2;
  color: #991b1b;
}

.pill-tag-blue {
  background: #dbeafe;
  color: #1e40af;
}

.pill-tag-green {
  background: #dcfce7;
  color: #166534;
}

.pill-tag-yellow {
  background: #fef3c7;
  color: #92400e;
}

.pill-tag-purple {
  background: #f3e8ff;
  color: #6b21a8;
}

.btn-flag-chip {
  background: transparent;
  border: none;
  padding: 2px 6px;
  font-size: 0.68rem;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  transition: all 0.15s ease;
}

.btn-flag-chip:hover {
  background: rgba(225, 29, 72, 0.12) !important;
  color: #e11d48 !important;
  opacity: 1 !important;
}

.bubble-feedback-quote {
  transition: all 0.15s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.bubble-feedback-quote:hover {
  filter: brightness(0.97);
  transform: translateY(-1px);
}

.bubble-feedback-quote.is-resolved {
  opacity: 0.8;
  border-left-style: dashed !important;
}

.feedback-item-card {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.03);
  transition: all 0.2s ease;
}

.feedback-item-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.feedback-item-card.is-resolved {
  background: #f8fafc;
  opacity: 0.85;
  border-left: 4px solid #10b981;
}

.feedback-item-card.is-pending {
  border-left: 4px solid #e11d48;
}

/* ------------------------------------------------------------- */
/* ESTILOS DE RESPUESTAS RÁPIDAS (SNIPPETS & ATAJOS)             */
/* ------------------------------------------------------------- */
.pill-tag-amber {
  background: #fef3c7;
  color: #b45309;
}

.btn-quick-reply-trigger {
  background: #fef3c7;
  color: #b45309;
  border: 1px solid #fde68a;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
  user-select: none;
}

.btn-quick-reply-trigger:hover {
  background: #fde68a;
  color: #92400e;
  transform: scale(1.08);
  box-shadow: 0 2px 8px rgba(217, 119, 6, 0.25);
}

.btn-quick-reply-trigger.recording-active,
.btn-quick-reply-trigger.recording-active:hover {
  background: #dc2626 !important;
  color: #ffffff !important;
  border-color: #991b1b !important;
  animation: sim-recording-pulse 1s ease-in-out infinite !important;
  transform: scale(1.12) !important;
  box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.4) !important;
}

@keyframes sim-recording-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.65);
    transform: scale(1.08);
  }
  50% {
    box-shadow: 0 0 0 9px rgba(220, 38, 38, 0);
    transform: scale(1.15);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.65);
    transform: scale(1.08);
  }
}

.quick-reply-picker {
  position: absolute;
  bottom: 60px;
  left: 14px;
  width: 380px;
  max-width: calc(100vw - 32px);
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.06);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUpFade 0.15s ease-out;
}

@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.quick-reply-picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

.picker-close-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  padding: 0 4px;
}

.picker-close-btn:hover {
  color: #dc2626;
}

.quick-reply-picker-list {
  overflow-y: auto;
  max-height: 280px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.quick-reply-picker-item {
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.12s ease;
  border: 1px solid #f1f5f9;
  background: #ffffff;
}

.quick-reply-picker-item:hover {
  background: #fefce8;
  border-color: #fde047;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

.quick-reply-item-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.quick-reply-item-shortcut {
  font-family: monospace;
  font-size: 0.78rem;
  background: #f1f5f9;
  color: #0f172a;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  border: 1px solid #e2e8f0;
}

.quick-reply-item-text {
  font-size: 0.8rem;
  color: #475569;
  line-height: 1.4;
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (max-width: 900px) {
  .live-chat-container,
  .chats-layout-3col {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 0;
    border-radius: var(--radius);
    overflow: visible;
  }
  .chats-sidebar {
    width: 100%;
    max-height: 250px;
    overflow-y: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .chat-window {
    height: 520px;
    display: flex;
    flex-direction: column;
  }
  .copiloto-pane {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 85vw;
    max-width: 340px;
    z-index: 9999;
  }
  .config-layout {
    grid-template-columns: 1fr;
  }
  .simulator-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .quick-reply-picker {
    left: 8px;
    right: 8px;
    width: auto;
  }
}

/* =====================================================================
   Campañas de WhatsApp (assets/js/campanas.js)
   Los chips usan .f-chip.camp-* (dos clases) para ganarle a v2.css.
   ===================================================================== */
.camp-wrap { max-width: 1180px; margin: 0 auto; padding: 20px 16px 80px; display: grid; gap: 16px; }
.camp-head { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 12px; border-bottom: 1px solid var(--f-line); padding-bottom: 12px; }
.camp-head h1 { font-size: 1.25rem; font-weight: 700; color: var(--f-ink); margin: 0 0 4px; letter-spacing: -0.015em; }
.camp-head p { font-size: 0.84rem; color: var(--f-ink-2); margin: 0; max-width: 720px; line-height: 1.5; }
.camp-barra { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; padding: 12px 16px; background: var(--f-white); border: 1px solid var(--f-line); border-radius: var(--f-r); }
.camp-interruptor { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.camp-interruptor b { display: block; font-size: 14px; font-weight: 700; color: var(--f-ink-2); }
.camp-interruptor.on b { color: var(--f-ok); }
.camp-interruptor small { display: block; font-size: 12.5px; color: var(--f-ink-3); margin-top: 2px; }
.camp-cupo { font-size: 13.5px; font-weight: 600; color: var(--f-petrol); padding: 6px 12px; border-radius: 999px; background: var(--f-teal-wash); }
.camp-cupo.agotado { background: var(--f-danger-wash); color: var(--f-danger); }
.camp-aviso { padding: 10px 14px; border-radius: var(--f-r-sm); border: 1px solid var(--f-line); font-size: 0.88rem; white-space: pre-line; line-height: 1.5; }
.camp-aviso.ok { background: var(--f-ok-wash); border-color: var(--f-ok-line); color: var(--f-ok); }
.camp-aviso.warn { background: var(--f-sun-wash); border-color: var(--f-sun-line); color: var(--f-warn); }
.camp-aviso.error { background: var(--f-danger-wash); border-color: #EDC3BA; color: var(--f-danger); }
.camp-aviso-titulo { display: block; font-size: 0.98rem; margin-bottom: 2px; }
#campVistaLista, #campVistaForm, #campVistaDetalle { gap: 12px; align-content: start; }
#campVistaForm > .f-btn, #campVistaDetalle > .f-btn { justify-self: start; }
.camp-lista-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.camp-lista-head h2, .camp-wrap h3 { margin: 0; font-size: 1rem; font-weight: 700; color: var(--f-ink); }
.camp-lista { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.camp-card { background: var(--f-white); border: 1px solid var(--f-line); border-radius: var(--f-r); padding: 16px; display: grid; gap: 12px; align-content: start; }
.camp-item { cursor: pointer; text-align: left; font: inherit; color: inherit; width: 100%; transition: border-color var(--f-t), box-shadow var(--f-t); }
.camp-item:hover { border-color: var(--f-line-3); box-shadow: var(--f-shadow); }
.camp-item-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.camp-item-nombre { font-weight: 700; font-size: 15px; color: var(--f-ink); word-break: break-word; }
.camp-titulo { margin: 0; font-size: 1.1rem; font-weight: 700; color: var(--f-ink); word-break: break-word; }
.camp-sub { margin: 0; font-size: 12.5px; color: var(--f-ink-3); line-height: 1.5; }
.camp-prog { height: 8px; border-radius: 999px; background: var(--f-line-2); overflow: hidden; }
.camp-prog > span { display: block; height: 100%; background: var(--f-teal); transition: width var(--f-t); }
.camp-prog-txt { font-size: 12.5px; color: var(--f-ink-2); margin-top: 4px; }
.camp-cont { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--f-ink-2); }
.camp-cont b { color: var(--f-ink); font-weight: 700; }
.f-chip.camp-est-borrador { background: var(--f-panel); border-color: var(--f-line-3); color: var(--f-ink-2); }
.f-chip.camp-est-lista { background: var(--f-teal-wash); border-color: #D3E4EA; color: var(--f-petrol); font-weight: 600; }
.f-chip.camp-est-enviando { background: var(--f-sun); border-color: var(--f-sun); color: var(--f-petrol); font-weight: 600; }
.f-chip.camp-est-pausada { background: var(--f-sun-wash); border-color: var(--f-sun-line); color: var(--f-warn); font-weight: 600; }
.f-chip.camp-est-terminada { background: var(--f-ok-wash); border-color: var(--f-ok-line); color: var(--f-ok); font-weight: 600; }
.f-chip.camp-est-cancelada { background: var(--f-danger-wash); border-color: #EDC3BA; color: var(--f-danger); }
.f-chip.camp-d-pendiente { color: var(--f-ink-2); }
.f-chip.camp-d-enviando { background: var(--f-sun-wash); border-color: var(--f-sun-line); color: var(--f-warn); }
.f-chip.camp-d-enviado { background: var(--f-ok-wash); border-color: var(--f-ok-line); color: var(--f-ok); }
.f-chip.camp-d-fallido { background: var(--f-danger-wash); border-color: #EDC3BA; color: var(--f-danger); }
.f-chip.camp-d-omitido { background: var(--f-panel); color: var(--f-ink-3); }
.f-chip.camp-d-excluido { background: var(--f-panel); color: var(--f-ink-3); text-decoration: line-through; }
.camp-form { max-width: 820px; gap: 16px; }
.camp-form h2 { margin: 0; font-size: 1.05rem; font-weight: 700; color: var(--f-ink); }
.camp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.camp-vars, .camp-resps { display: grid; gap: 8px; margin-bottom: 8px; }
.camp-var { display: flex; gap: 8px; align-items: center; max-width: 420px; }
.camp-var code, .camp-resp-fila code { flex: none; min-width: 42px; text-align: center; font-size: 12.5px; padding: 3px 6px; border-radius: var(--f-r-sm); background: var(--f-panel); color: var(--f-ink-2); }
.camp-resp-fila { display: flex; gap: 8px; align-items: flex-start; padding: 10px; border: 1px solid var(--f-line-2); border-radius: var(--f-r-sm); background: var(--f-paper); }
.camp-resp-fila code { min-width: 28px; margin-top: 8px; }
.camp-resp-campos { flex: 1; display: grid; gap: 6px; min-width: 0; }
.camp-resp-campos .form-textarea { min-height: 70px; }
.camp-resp-lista { margin: 0; padding-left: 20px; display: grid; gap: 8px; font-size: 13px; }
.camp-resp-lista b { display: block; margin-bottom: 4px; color: var(--f-ink); }
.camp-acciones { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.camp-btn-peligro { color: var(--f-danger); border-color: #EDC3BA; }
.camp-btn-peligro:hover { background: var(--f-danger-wash); border-color: var(--f-danger); }
.camp-nota { margin-top: 8px; font-size: 12.5px; color: var(--f-warn); background: var(--f-sun-wash); border: 1px solid var(--f-sun-line); border-radius: var(--f-r-sm); padding: 6px 10px; }
.camp-instr { white-space: pre-wrap; word-break: break-word; background: var(--f-paper); border: 1px solid var(--f-line-2); border-radius: var(--f-r-sm); padding: 10px 12px; font-size: 13px; color: var(--f-ink); }
.camp-dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; font-size: 13px; margin: 0; }
.camp-dl dt { color: var(--f-ink-3); }
.camp-dl dd { margin: 0; color: var(--f-ink); word-break: break-word; }
.camp-pegar { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.camp-wrap .f-help code { font-size: 12px; background: var(--f-panel); padding: 0 4px; border-radius: 4px; }
.camp-resultado { font-size: 13px; padding: 10px 12px; border-radius: var(--f-r-sm); background: var(--f-teal-wash); color: var(--f-ink); }
.camp-excl { margin: 8px 0 0; padding-left: 18px; max-height: 220px; overflow: auto; color: var(--f-ink-2); }
.camp-filtro { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--f-ink-2); }
.camp-filtro .form-select { width: auto; padding: 6px 10px; font-size: 13px; }
.camp-tabla-wrap { overflow-x: auto; }
.camp-tabla { width: 100%; border-collapse: collapse; font-size: 13px; }
.camp-tabla th { text-align: left; font-weight: 600; color: var(--f-ink-3); padding: 8px; border-bottom: 1px solid var(--f-line); white-space: nowrap; }
.camp-tabla td { padding: 8px; border-bottom: 1px solid var(--f-line-2); vertical-align: top; color: var(--f-ink); }
.camp-tel { white-space: nowrap; }
.camp-datos { color: var(--f-ink-2); max-width: 260px; }
.camp-resp { max-width: 280px; word-break: break-word; }
.camp-mini { font-size: 11.5px; color: var(--f-ink-3); margin-top: 3px; }
.camp-paginador { display: flex; gap: 10px; align-items: center; justify-content: flex-end; flex-wrap: wrap; font-size: 13px; color: var(--f-ink-2); }
@media (max-width: 640px) {
  .camp-wrap { padding: 14px 10px 90px; }
  .camp-lista { grid-template-columns: 1fr; }
  .camp-dl { grid-template-columns: 1fr; }
  .camp-dl dt { margin-top: 6px; }
}

