/* CareOS v2 — Main stylesheet */

:root {
  --primary: #00377b;
  --primary-light: #004a9e;
  --accent: #10b981;
  --accent-light: #059669;
  --success: #059669;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #3b82f6;
  --bg: #f4f6f9;
  --bg-card: #ffffff;
  --bg-header: #001f44;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.12);
  --radius: 10px;
  --radius-sm: 6px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition: .2s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

/* ── Header ───────────────────────────────────────────────── */

header {
  background: var(--bg-header);
  color: #fff;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  overflow: hidden;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.header-left h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.header-left .version {
  font-size: 11px;
  background: var(--accent);
  color: #fff;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 600;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

.live-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%,100% { opacity: 1; }
  50% { opacity: .4; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

#global-trunk-select,
#global-org-select {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.2);
  color: #fff;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
}

.user-info {
  font-size: 13px;
  opacity: .85;
}

.btn-logout {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.2);
  color: #fff;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: background var(--transition);
}

.btn-logout:hover { background: rgba(255,255,255,.2); }

/* ── Container & Tabs ─────────────────────────────────────── */

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px 40px;
  overflow-x: hidden;
}

.tab-nav {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: 16px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tab-nav::-webkit-scrollbar { display: none; }

.tab-nav::after {
  content: '';
  min-width: 1px;
  flex-shrink: 0;
}

.tab-btn {
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.tab-btn svg { width: 16px; height: 16px; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Cards ────────────────────────────────────────────────── */

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

.card:hover { box-shadow: var(--shadow-lg); }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-header h3 {
  font-size: 16px;
  font-weight: 600;
}

/* ── KPI Grid ─────────────────────────────────────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}

.kpi-card .kpi-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.kpi-card .kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Tables ───────────────────────────────────────────────── */

.table-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.table-card table {
  min-width: 600px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  background: #f8fafc;
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}

tbody tr {
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background var(--transition);
}

tbody tr:hover { background: #f8fafc; }
tbody tr:last-child { border-bottom: none; }

tbody td {
  padding: 10px 14px;
  font-size: 13px;
}

/* ── Badges ───────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-neutral { background: #f1f5f9; color: #475569; }

/* ── Buttons ──────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; }
.btn-danger { background: var(--danger); color: #fff; }
.card-peligro { border-color: #fecaca; background: #fff7f7; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-outline:hover { background: #f8fafc; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon {
  padding: 6px;
  width: 32px;
  height: 32px;
  justify-content: center;
}

.btn:disabled, .btn.btn-loading {
  opacity: .6;
  pointer-events: none;
}

/* ── Forms ────────────────────────────────────────────────── */

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

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  transition: border-color var(--transition);
  outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
}

.form-group.has-error input,
.form-group.has-error select {
  border-color: var(--danger);
}

.form-group.has-success input,
.form-group.has-success select {
  border-color: var(--success);
}

.form-group .error-msg {
  color: var(--danger);
  font-size: 11px;
  margin-top: 2px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* Un elemento de grid o de flex no encoge por debajo de su contenido salvo
   que se le diga: su min-width vale «auto». Basta un campo con un texto de
   ayuda largo para que su columna crezca y empuje hacia fuera todo lo que
   viene detrás, que es lo que desplazaba la configuración avanzada del
   asistente a partir de las palabras de despedida.

   Va sobre todo lo que hay dentro de una pestaña o de un modal, y no sólo
   sobre .form-row y .flex, porque medio panel declara sus rejillas con
   style= en el propio HTML y esas no heredarían la regla. En un elemento
   que no sea hijo de grid o flex esto no cambia nada: su min-width ya
   valía cero. Y donde hace falta un ancho mínimo de verdad —los botones de
   paginación, los filtros— la regla propia es más específica y manda. */
.tab-content *,
.modal-body * {
  min-width: 0;
}

.form-group input,
.form-group select,
.form-group textarea {
  max-width: 100%;
}

/* ── Modals ───────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
  /* Sin esto, un campo ancho o una tabla larga sacaban el diálogo de la
     pantalla y no había forma de llegar al botón de guardar. */
  overflow-x: hidden;
  box-shadow: var(--shadow-lg);
  transform: scale(.95) translateY(12px);
  transition: transform .25s;
}

.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}

.modal.wide { max-width: 1000px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}

.modal-header h3 { font-size: 16px; font-weight: 600; }

.close-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-muted);
  transition: background var(--transition);
}

.close-btn:hover { background: #f1f5f9; }

.modal-body { padding: 20px; }

.modal-info {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  padding: 16px 20px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.modal-info .info-item label {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
}

.modal-info .info-item span {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}

.modal-info .info-item {
  min-width: 0;
  overflow: hidden;
}

/* ── Login overlay ────────────────────────────────────────── */

.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, var(--bg-header) 0%, #003366 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.login-overlay.hidden { display: none; }

.login-box {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 40px;
  width: 380px;
  max-width: 90vw;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-box h2 {
  font-size: 22px;
  margin-bottom: 6px;
  color: var(--primary);
}

.login-box .subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 24px;
}

.login-box input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 12px;
  outline: none;
}

.login-box input:focus { border-color: var(--primary); }

.login-box .btn-login {
  width: 100%;
  padding: 10px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}

.login-box .btn-login:hover { background: var(--primary-light); }

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
  display: none;
}
.login-aviso { color: #16a34a; font-size: 13px; margin-top: 10px; display: none; }
.login-box .btn-proveedor { margin-bottom: 10px; }
.login-box .btn-secundario { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.login-box .btn-secundario:hover { background: #f0f5fb; }
.login-box .entrada-o { color: var(--text-muted); font-size: 12px; margin: 6px 0 12px; }
.login-box .enlace-pie { display: block; margin-top: 12px; font-size: .8rem; color: #64748b; text-decoration: none; }
.login-box .enlace-marca { margin-top: 8px; font-size: .75rem; color: #94a3b8; }

/* ── Pipeline / CRM ───────────────────────────────────────── */

.pipeline-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.pipeline-card {
  text-align: center;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition);
}

.pipeline-card:hover { border-color: var(--primary); }
.pipeline-card.active { border-color: var(--primary); background: #eef4ff; }

.pipeline-card .count {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
}

.pipeline-card .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ── Campaign cards ───────────────────────────────────────── */

.campaign-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.campaign-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all var(--transition);
}

.campaign-card:hover { box-shadow: var(--shadow-lg); }

.campaign-card .campaign-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
}

.campaign-card .campaign-stats {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── WhatsApp ─────────────────────────────────────────────── */

.wa-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  min-height: 500px;
}

.wa-conversations {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  overflow-y: auto;
  max-height: 70vh;
}

.wa-conv-item {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background var(--transition);
}

.wa-conv-item:hover, .wa-conv-item.active { background: #eef4ff; }

.wa-conv-item .wa-name { font-weight: 600; font-size: 13px; }
.wa-conv-item .wa-preview { font-size: 12px; color: var(--text-muted); }

.wa-chat {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
}

.wa-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  max-height: 60vh;
}

.wa-msg {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 12px;
  margin-bottom: 8px;
  font-size: 13px;
  line-height: 1.4;
}

.wa-msg.user {
  background: #dcfce7;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.wa-msg.assistant {
  background: #f1f5f9;
  margin-right: auto;
  border-bottom-left-radius: 4px;
}

/* ── Timeline ─────────────────────────────────────────────── */

.timeline {
  position: relative;
  padding-left: 24px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  padding-bottom: 16px;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -20px;
  top: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--bg-card);
}

.timeline-item.voice::before { background: var(--accent); }
.timeline-item.whatsapp::before { background: #25d366; }
.timeline-item.email::before { background: var(--info); }
.timeline-item.campaign::before { background: var(--warning); }

.timeline-item .tl-time {
  font-size: 11px;
  color: var(--text-muted);
}

.timeline-item .tl-content {
  font-size: 13px;
  margin-top: 2px;
}

/* ── Charts ───────────────────────────────────────────────── */

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.chart-card h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Los cuatro gráficos miden lo mismo. Sin esto, la rosquilla crece hasta
   ser cuadrada —tan alta como ancha la tarjeta— y empuja su leyenda fuera
   de la pantalla: un gráfico enorme que no dice de qué es cada trozo. */
.chart-card .grafico {
  position: relative;
  height: 240px;
}

/* ── En qué punto está una capacidad ─────────────────────── */

.decl-estado {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  font-size: 11.5px;
}

.decl-cond { white-space: nowrap; }
.decl-cond.bien  { color: var(--text-muted); }
.decl-cond.falta { color: var(--danger); font-weight: 600; }

.decl-estado a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.decl-estado a:hover { text-decoration: underline; }

/* ── Listado editable ─────────────────────────────────────── */

/* Una casilla de la tabla, no un formulario: sin marco propio, para que la
   tabla siga leyéndose como una tabla. El marco aparece al enfocarla, que es
   cuando hace falta saber dónde se está escribiendo. */
.lst-celda {
  width: 100%;
  min-width: 90px;
  padding: 4px 6px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
}

.lst-celda:hover { border-color: var(--border); }

.lst-celda:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-card);
}

.lst-tabla td { padding: 4px 6px; }

/* El buscador, con la misma pinta que cualquier campo del panel: los de
   .form-group van dentro de un grupo con etiqueta, y éste no la lleva. */
.lst-buscar {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
}

.lst-buscar:focus { border-color: var(--primary); }

/* ── Toast ────────────────────────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn .3s ease;
  max-width: 350px;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
.toast.info { background: var(--info); }

@keyframes toastIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Filter bar ───────────────────────────────────────────── */

.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-bar select,
.filter-bar input {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
}

.filter-bar select:focus,
.filter-bar input:focus {
  border-color: var(--primary);
}

/* ── Pagination ───────────────────────────────────────────── */

.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.pagination .btn { min-width: 36px; justify-content: center; }

/* ── Org selector ─────────────────────────────────────────── */

.org-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.org-selector select {
  padding: 6px 12px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.1);
  color: #fff;
  font-size: 13px;
  outline: none;
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .pipeline-grid { grid-template-columns: repeat(3, 1fr); }
  .wa-layout { grid-template-columns: 1fr; }
  .wa-conversations { max-height: 250px; }
  .campaign-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
}

@media (max-width: 768px) {
  header { padding: 0 12px; gap: 8px; }
  .header-left h1 { font-size: 15px; }
  .header-left img { height: 22px !important; }
  .header-left .version { font-size: 10px; padding: 1px 5px; }
  .container { padding: 0 10px 24px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi-card { padding: 12px; }
  .kpi-card .kpi-value { font-size: 22px; }
  .pipeline-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .pipeline-card { padding: 8px; }
  .pipeline-card .count { font-size: 18px; }
  .form-row { grid-template-columns: 1fr; }
  .modal { width: 96%; max-width: none; max-height: 95vh; }
  .modal.wide { max-width: none; }
  .modal-body { padding: 14px; }
  .modal-header { padding: 12px 14px; }
  .modal-info { grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 14px; }
  .live-badge, .user-info { display: none; }
  .header-right { gap: 8px; }
  .header-right select { font-size: 12px; padding: 4px 8px; max-width: 120px; }
  .btn-logout { padding: 4px 10px; font-size: 12px; }
  .campaign-grid { grid-template-columns: 1fr; }
  .filter-bar { gap: 8px; }
  .filter-bar select, .filter-bar input { font-size: 12px; padding: 6px 10px; }
  .tab-btn { padding: 8px 12px; font-size: 12px; }
  .tab-btn svg { width: 14px; height: 14px; }
  thead th { padding: 8px 10px; font-size: 11px; }
  tbody td { padding: 8px 10px; font-size: 12px; }
  .wa-msg { max-width: 85%; }
  .wizard-steps { gap: 2px; }
  .wizard-step { font-size: 11px; padding: 6px 2px; }
  #toast-container { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: 100%; }
}

@media (max-width: 480px) {
  header { height: 48px; }
  .header-left h1 { display: none; }
  .header-left .version { display: none; }
  .container { padding: 0 8px 20px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi-card .kpi-value { font-size: 20px; }
  .pipeline-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .pipeline-card .count { font-size: 16px; }
  .pipeline-card .label { font-size: 10px; }
  .modal-info { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .header-right .org-selector { display: none; }
  .header-right select { max-width: 100px; }
  .tab-label { display: none; }
  .tab-nav { gap: 0; }
  .tab-btn { padding: 8px 10px; }
  .login-box { padding: 24px 20px; }
  .btn { padding: 7px 12px; font-size: 12px; }
  h2 { font-size: 18px; }
  h3 { font-size: 16px; }
  .flex-between { flex-wrap: wrap; gap: 8px; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar input, .filter-bar select { width: 100%; min-width: 0 !important; }
  .campaign-card .campaign-name { font-size: 14px; }
  .tab-content { overflow-x: hidden; }
}

/* ── Empty state ──────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state svg { width: 48px; height: 48px; opacity: .5; margin-bottom: 12px; }
.empty-state h4 { font-size: 16px; margin-bottom: 6px; }
.empty-state p { font-size: 13px; }

/* ── Utility ──────────────────────────────────────────────── */

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.text-right { text-align: right; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Wizard steps ─────────────────────────────────────────── */

.wizard-steps {
  display: flex; gap: 4px; border-bottom: 2px solid var(--border); padding-bottom: 12px;
}
.wizard-step {
  flex: 1; text-align: center; padding: 8px 4px; font-size: 13px;
  color: var(--text-muted); border-radius: 6px 6px 0 0; position: relative;
}
.wizard-step .step-num {
  display: inline-block; width: 22px; height: 22px; line-height: 22px;
  border-radius: 50%; background: var(--border); font-size: 12px; font-weight: 600;
  margin-right: 4px;
}
.wizard-step.active { color: var(--primary); font-weight: 600; }
.wizard-step.active .step-num { background: var(--primary); color: #fff; }
.wizard-step.done { color: var(--success); cursor: pointer; }
.wizard-step.done .step-num { background: var(--success); color: #fff; }
.wizard-step.done:hover { background: var(--hover-bg); }

/* ── Details/summary styling ──────────────────────────────── */

details { border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; }
details summary { cursor: pointer; user-select: none; }
details[open] summary { margin-bottom: 8px; }

/* ── Template option ──────────────────────────────────────── */

.template-option:has(input:checked) { border-color: var(--primary) !important; background: rgba(0,55,123,.05); }

/* ── QA Badges ───────────────────────────────────────────── */

.badge-qa-verified { background: #d1fae5; color: #065f46; }
.badge-qa-flagged { background: #fee2e2; color: #991b1b; }
.badge-qa-needs_review { background: #fef3c7; color: #92400e; }
.badge-qa-none { background: #f1f5f9; color: #94a3b8; }
.badge-qa-pending { background: #dbeafe; color: #1e40af; }
.badge-qa-approved { background: #d1fae5; color: #065f46; }
.badge-qa-rejected { background: #fee2e2; color: #991b1b; }

/* ── Performance badges ──────────────────────────────────── */

.perf-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  margin-left: 4px;
}

.perf-good { background: #d1fae5; color: #065f46; }
.perf-warn { background: #fef3c7; color: #92400e; }
.perf-bad { background: #fee2e2; color: #991b1b; }

/* ── Table search / filter bar ───────────────────────────── */

.table-search {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.table-search input {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  flex: 1;
  min-width: 180px;
}

.table-search input:focus { border-color: var(--primary); }

.table-search select {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
}

/* ── Field summary grid ──────────────────────────────────── */

.field-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.field-summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 13px;
}

.field-summary-card h5 {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .3px;
}

.summary-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 12px;
}

.summary-bar .bar-track {
  flex: 1;
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
}

.summary-bar .bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .3s ease;
}

.summary-bar .bar-fill.green { background: var(--success); }
.summary-bar .bar-fill.red { background: var(--danger); }
.summary-bar .bar-fill.blue { background: var(--info); }
.summary-bar .bar-fill.yellow { background: var(--warning); }

.summary-tag {
  display: inline-block;
  padding: 2px 8px;
  margin: 2px;
  border-radius: 10px;
  font-size: 11px;
  background: #f1f5f9;
  color: var(--text);
}

/* ── Replay container ────────────────────────────────────── */

.replay-container {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: #fafbfc;
  margin-top: 12px;
}

.replay-step {
  padding: 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  opacity: 0.4;
  transition: opacity .3s ease, transform .3s ease;
}

.replay-step.active {
  opacity: 1;
  transform: scale(1.01);
}

.replay-bot {
  background: #f1f5f9;
  margin-right: 15%;
  border-bottom-left-radius: 4px;
}

.replay-user {
  background: #dcfce7;
  margin-left: 15%;
  border-bottom-right-radius: 4px;
}

.replay-extraction {
  background: #eff6ff;
  margin-left: 10%;
  margin-right: 10%;
  border-left: 3px solid var(--info);
  font-size: 12px;
}

.replay-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.replay-nav button {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}

.replay-nav button:hover { background: #f1f5f9; }
.replay-nav button:disabled { opacity: .4; cursor: default; }
.replay-nav .replay-counter { font-size: 12px; color: var(--text-muted); }

/* ── Audit log ───────────────────────────────────────────── */

.audit-log-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: 12px;
}

.audit-log-item:last-child { border-bottom: none; }

.audit-log-item .audit-action {
  font-weight: 600;
  color: var(--primary);
  min-width: 80px;
}

.audit-log-item .audit-time {
  color: var(--text-muted);
  min-width: 120px;
}

/* ── Callout ─────────────────────────────────────────────── */

.callout {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 8px;
}

.callout-warning {
  background: #fef3c7;
  border-left: 3px solid var(--warning);
  color: #92400e;
}

.callout-info {
  background: #eff6ff;
  border-left: 3px solid var(--info);
  color: #1e40af;
}

.callout-danger {
  background: #fef2f2;
  border-left: 3px solid var(--danger);
  color: #991b1b;
}


/* ── Que nada se salga de la pantalla ─────────────────────────
   Un formulario largo, una tabla ancha o un bloque de JSON no pueden
   desbordar el panel: si algo no cabe, que se ajuste o que ruede dentro de
   su propia caja, nunca arrastrando la página entera. */

.tab-content .card,
.modal-body .card {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.tab-content textarea,
.modal-body textarea,
.tab-content pre,
.modal-body pre {
  max-width: 100%;
  overflow-x: auto;
}

.tab-content table,
.modal-body table {
  max-width: 100%;
  display: block;
  overflow-x: auto;
}

/* Filas de campos hechas a mano: que se apilen en vez de desbordar. */
.campo-fila {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}

.campo-fila > input,
.campo-fila > select {
  flex: 1 1 140px;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
}

/* Cada declaración de lo que el asistente sabe hacer: una consulta, un
   listado, una herramienta. Tres bloques con la misma forma, así que también
   con el mismo estilo. */
.decl-fila {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
}

.decl-fila:hover { background: var(--bg-secondary); }

/* ── Consumo por periodo ─────────────────────────────────── */
.consumo { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.consumo-cab { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.consumo-cab h4 { margin: 0 0 2px; }
.consumo-rangos { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--bg); color: var(--text-muted);
  border-radius: 999px; padding: 5px 12px; font-size: 12.5px; font-weight: 500;
  cursor: pointer; transition: var(--transition); font-family: var(--font);
}
.chip:hover { color: var(--text); border-color: #cbd5e1; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.consumo-fechas { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--text-muted); }
.consumo-fechas label { display: inline-flex; align-items: center; gap: 6px; }
.consumo-fechas input[type=date] { padding: 5px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: var(--font); font-size: 13px; color: var(--text); background: var(--bg-card); }
.consumo-kpis { margin-top: 16px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.consumo-kpis .kpi-value { font-size: 22px; }
.consumo-limite { margin-top: 14px; padding: 12px 14px; background: var(--bg); border-radius: var(--radius-sm); display: grid; gap: 6px; }
.consumo-barra { height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; }
.consumo-barra i { display: block; height: 100%; border-radius: 4px; transition: width .4s ease; }
.consumo-grafica { position: relative; height: 220px; margin-top: 16px; }
.consumo-lineas { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; color: var(--text-muted); }
.consumo-tabla { margin-top: 14px; }
.consumo-tabla summary { cursor: pointer; color: var(--text-muted); padding: 6px 0; }
.consumo-tabla table { margin-top: 8px; }


/* ── El sistema del panel ───────────────────────────────────
   Una cabecera, una subnavegación, una ayuda, una tabla, y utilidades para
   lo que antes se escribía a mano en cada pantalla. */

.pantalla-cab { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin: 4px 0 16px; }
.pantalla-cab h2 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -.2px; }
.pantalla-expl { margin: 4px 0 0; font-size: 13.5px; color: var(--text-muted); max-width: 72ch; line-height: 1.5; }
.pantalla-accion { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pantalla-sub { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 0 12px; }
.pantalla-sub h3 { margin: 0; font-size: 16px; font-weight: 600; }

.subnav { margin-top: 0; }
.subnav .tab-btn { padding: 8px 12px; font-size: 13px; }

.ayuda { margin-top: 16px; border: 1px solid #dbeafe; background: #f0f7ff; border-radius: var(--radius); padding: 0; }
.ayuda summary { padding: 12px 16px; cursor: pointer; font-size: 13px; color: #2563eb; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
.ayuda summary::-webkit-details-marker { display: none; }
.ayuda-icono { font-size: 16px; }
.ayuda-pista { margin-left: auto; font-size: 11px; color: #94a3b8; font-weight: 500; }
.ayuda-cuerpo { padding: 0 16px 14px; font-size: 13px; color: #475569; line-height: 1.7; }
.ayuda-cuerpo ul { margin: 0; padding-left: 20px; }

.loading-indicator { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 32px; color: #64748b; font-size: 14px; }
.loading-indicator .spinner { width: 20px; height: 20px; border: 2px solid #e2e8f0; border-top-color: #2563eb; border-radius: 50%; animation: spin .6s linear infinite; }
th.ordenable { cursor: pointer; user-select: none; white-space: nowrap; }
.tabla-cuenta { font-size: 12px; color: #94a3b8; padding: 4px 8px; text-align: right; }
.marco-heredado { width: 100%; height: calc(100vh - 120px); border: 0; border-radius: 8px; }
.subvista { display: none; }
.subvista.active { display: block; }

/* utilidades: lo que antes iba en style="" */
.p-0 { padding: 0; } .p-8 { padding: 8px; } .p-12 { padding: 12px; } .p-16 { padding: 16px; }
.m-0 { margin: 0; } .mt-0 { margin-top: 0; } .mt-4 { margin-top: 4px; } .mt-6 { margin-top: 6px; } .mt-12 { margin-top: 12px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; }
.fs-10 { font-size: 10px; } .fs-11 { font-size: 11px; } .fs-12 { font-size: 12px; } .fs-13 { font-size: 13px; }
.lh-15 { line-height: 1.5; }
.flex-1 { flex: 1; }
.oculto { display: none; }
.text-danger { color: var(--danger); } .text-success { color: var(--success); } .text-warning { color: var(--warning); }
.text-primary { color: var(--primary); } .text-accent { color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.col-todo { grid-column: 1 / -1; }
.acciones-derecha { text-align: right; margin-top: 16px; }
.acciones-derecha-12 { text-align: right; margin-top: 12px; }
.flex-centro-8 { display: flex; align-items: center; gap: 8px; }
.etiqueta-suave { background: #dbeafe; padding: 2px 6px; border-radius: 4px; font-size: 11px; }
.codigo-suave { background: var(--bg); padding: 2px 4px; border-radius: 3px; }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }
.cita-suave { padding: 10px; background: var(--bg); border-radius: 6px; font-size: 13px; line-height: 1.5; margin: 0; }

/* ── Avisos de Inicio ─────────────────────────────────────── */
.avisos { display: grid; gap: 8px; margin-bottom: 16px; }
.aviso { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--border); border-left-width: 4px; background: var(--bg-card); }
/* «nivel-» delante: una clase «aviso» dentro de «.aviso» pintaba todos iguales. */
.aviso.nivel-atencion { border-left-color: var(--danger); }
.aviso.nivel-aviso { border-left-color: var(--warning); }
.aviso-texto { display: grid; gap: 2px; min-width: 0; }
.aviso-texto strong { font-size: 14px; }
.aviso-texto span { font-size: 13px; color: var(--text-muted); }
.avisos-vacio { font-size: 13px; color: var(--success); margin-bottom: 16px; }
.acciones-abajo { align-items: flex-end; }

/* Un correo tal como se escribió, y la propuesta de respuesta: texto corrido,
   con sus saltos, sin que una línea larga desborde el modal. */
.texto-correo { white-space: pre-wrap; word-break: break-word; font: inherit;
  background: var(--bg-alt, #f6f7f9); border-radius: 6px; padding: 10px 12px; margin: 0; }

/* ── Formularios desde el contrato (formulario.js) ─────────────
   Un solo estilo para cada campo: etiqueta, control, ayuda debajo y el error
   del contrato sobre el propio campo. Lo que sea un bloque o una lista se
   enmarca; lo que sea un elemento de lista se distingue del bloque que lo
   contiene. */

.frm-ayuda { display: block; font-size: 12px; color: var(--text-muted); line-height: 1.5; margin-top: 4px; }
.frm-oblig { color: var(--danger); font-weight: 700; }
.frm-error { font-size: 12px; color: var(--danger); font-weight: 600; margin-top: 4px; }
.frm-campo.con-error > input, .frm-campo.con-error > select, .frm-campo.con-error > textarea { border-color: var(--danger); }
.frm-campo.con-error > legend { color: var(--danger); }
.frm-bloque, .frm-lista { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px 4px; margin: 0 0 14px; min-width: 0; }
.frm-bloque > legend, .frm-lista > legend { font-size: 12px; font-weight: 600; color: var(--text-muted); padding: 0 6px; display: flex; align-items: center; gap: 10px; }
.frm-bloque > .frm-ayuda, .frm-lista > .frm-ayuda { margin: -4px 0 10px; }
.frm-bloque-cuerpo { padding-top: 6px; }
.frm-opcional { font-weight: 500; display: inline-flex; align-items: center; gap: 4px; margin-left: 4px; text-transform: none; }
.frm-cuenta { font-weight: 500; }
.frm-lista-items { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.frm-item { border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: var(--radius-sm); padding: 10px 12px 0; background: #fafbfd; }
.frm-item-cab { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.frm-item-titulo { font-size: 12px; font-weight: 600; color: var(--primary); font-family: ui-monospace, monospace; }
.frm-lista > .btn { margin-bottom: 10px; }
.frm-json, .frm-solo-lectura { font-family: ui-monospace, SFMono-Regular, monospace; font-size: 12px; }
.frm-solo-lectura { background: var(--bg); color: var(--text-muted); }
.frm-si-no label { font-weight: 500; color: var(--text); }
.form-group input[type="checkbox"] { width: auto; margin: 0; }
.frm-mas { margin: 4px 0 12px; }
.frm-mas > summary { cursor: pointer; font-size: 12px; color: var(--primary); font-weight: 600; list-style: none; padding: 4px 0; }
.frm-mas > summary::-webkit-details-marker { display: none; }
.frm-mas > summary::before { content: '▸ '; }
.frm-mas[open] > summary::before { content: '▾ '; }
.frm-mas-cuerpo { padding: 8px 0 0 12px; border-left: 2px solid var(--border); }
.frm .grid-2 { gap: 0 14px; }

/* ── El editor del asistente ───────────────────────────────── */
.ast-nav { margin-top: 0; }
.ast-bloque { padding: 16px 18px; }
.ast-bloque h4 { font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; }
.ast-textos { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 860px) { .grid-3, .ast-textos { grid-template-columns: 1fr; } }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.apagada { opacity: .6; }
.decl-no-contratado { margin: 0 0 12px; padding: 8px 10px; border: 1px dashed var(--border); border-radius: var(--radius-sm); font-size: 12.5px; color: var(--text-muted); }
.decl-vacio { text-align: center; padding: 20px 0; font-size: 13px; color: var(--text-muted); margin: 0; }
.decl-main { flex: 1; min-width: 0; }
.decl-titulo { font-weight: 500; font-size: 13px; margin-bottom: 2px; display: flex; align-items: center; gap: 6px; }
.decl-sub { font-size: 12px; color: var(--text-muted); }
.decl-acciones { flex-shrink: 0; display: flex; gap: 4px; align-items: center; }
.decl-barra { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.decl-problemas { margin: 8px 0; padding: 10px 12px; border: 1px solid #fecaca; background: #fef2f2; border-radius: var(--radius-sm); font-size: 12.5px; color: #991b1b; line-height: 1.6; }
.cc-campos { border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 10px 12px 0; margin: 6px 0 8px; }
.kb-cat { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--text-muted); letter-spacing: .5px; margin-bottom: 6px; padding-left: 2px; }
.kb-respuesta { font-size: 12px; color: var(--text); white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
