/* ==========================================================
   CRM Ivan Ivanovich Academy — sistema de diseño "SaaS con color"
   inspirado en Kommo / HubSpot: base clara y limpia, un acento
   indigo para acciones y navegación, y un segundo acento cálido
   (naranja) para llamados a la acción y elementos vivos.
   Tipografía: Inter (texto) + Lexend (títulos), con fallback al
   stack del sistema si el CDN de fuentes no carga.
   ========================================================== */

:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: 'Lexend', var(--font);

  --bg: #f3f4fa;
  --bg-shell: #eceefa;
  --card: #ffffff;
  --border: #e6e8f2;
  --border-strong: #d7dae8;
  --text: #171a2e;
  --text-secondary: #6b7086;

  /* Acento principal (navegación, acciones primarias, foco) */
  --primary: #4f46e5;
  --primary-dark: #4034c7;
  --primary-light: #eef0ff;
  --primary-rgb: 79, 70, 229;

  /* Acento cálido (CTAs destacados, urgencia, promo) */
  --accent: #ff6a3d;
  --accent-dark: #e2531e;
  --accent-light: #fff1ea;

  /* Compat: el resto del código usa --blue como alias del acento principal */
  --blue: var(--primary);
  --blue-dark: var(--primary-dark);

  --green: #16a34a;
  --green-light: #e6f9ee;
  --orange: #d97706;
  --orange-light: #fff4e0;
  --red: #e0332f;
  --red-light: #fdecec;
  --purple: #8b5cf6;
  --purple-light: #f2edfe;
  --gray: #94a0b8;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --radius-pill: 980px;

  --shadow-xs: 0 1px 2px rgba(23,26,46,0.05);
  --shadow: 0 1px 2px rgba(23,26,46,0.04), 0 6px 20px rgba(23,26,46,0.06);
  --shadow-hover: 0 4px 10px rgba(23,26,46,0.06), 0 16px 36px rgba(23,26,46,0.10);
  --shadow-primary: 0 6px 16px rgba(var(--primary-rgb), 0.28);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Fondo con un leve degradado radial detrás del contenido, para que la app no se sienta plana
   incluso en las páginas con poco color propio (Configuración, Notas, etc.). */
body {
  background-image:
    radial-gradient(900px 420px at 8% -8%, rgba(var(--primary-rgb), 0.06), transparent 60%),
    radial-gradient(700px 380px at 100% 0%, rgba(255,106,61,0.05), transparent 55%);
  background-attachment: fixed;
}

a { color: var(--primary); text-decoration: none; }

::selection { background: rgba(var(--primary-rgb), 0.22); }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Barra lateral izquierda (nav principal) ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px; flex-shrink: 0;
  background: linear-gradient(180deg, #1a1338 0%, #171233 55%, #14102b 100%);
  border-right: 1px solid rgba(255,255,255,0.06);
  display: flex; flex-direction: column; gap: 10px;
  padding: 18px 12px 14px; position: sticky; top: 0; height: 100vh; z-index: 50;
}

.sidebar-nav {
  display: flex; flex-direction: column; gap: 2px; flex: 1;
  width: 100%; overflow-y: auto;
}

.sidebar-link {
  position: relative; width: 100%; height: 40px; border-radius: 10px;
  display: flex; align-items: center; gap: 12px; padding: 0 12px;
  color: rgba(255,255,255,0.62); transition: background .15s ease, color .15s ease;
  flex-shrink: 0; font-size: 13.5px; font-weight: 600;
}
.sidebar-icon { width: 19px; height: 19px; flex-shrink: 0; }
.sidebar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-link:hover { background: rgba(255,255,255,0.07); color: #fff; }
.sidebar-link.active {
  background: linear-gradient(90deg, rgba(var(--primary-rgb),0.35), rgba(var(--primary-rgb),0.12));
  color: #fff;
}
.sidebar-link.active::before {
  content: ''; position: absolute; left: -12px; top: 6px; bottom: 6px; width: 3px;
  border-radius: 0 4px 4px 0; background: linear-gradient(180deg, var(--accent), var(--primary));
}

.sidebar-link .nav-badge { margin-left: auto; flex-shrink: 0; }

.sidebar-footer {
  display: flex; flex-direction: column; gap: 2px;
  padding-top: 10px; border-top: 1px solid rgba(255,255,255,0.08); width: 100%; flex-shrink: 0;
}

/* ---------- Barra superior (logo grande a la izquierda, usuario a la derecha) ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; background: rgba(255,255,255,0.85);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(23,26,46,0.02);
  position: sticky; top: 0; z-index: 40;
}
.topbar-logo img { height: 44px; max-width: 260px; object-fit: contain; display: block; }
.topbar-logo-fallback { font-family: var(--font-display); font-size: 19px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; display: block; }
.topbar-logo-fallback span { display: block; font-size: 11px; font-weight: 500; color: var(--text-secondary); letter-spacing: 0; font-family: var(--font); }
.topbar-user { display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--text-secondary); flex-shrink: 0; }
.topbar-user-name { font-weight: 600; color: var(--text); }
.topbar-user a { color: var(--gray); font-weight: 600; }

/* ---------- Campanita de notificaciones (assets/js/notifications.js) ---------- */
.notif { position: relative; }
.notif-bell {
  position: relative; display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--card); color: var(--text-secondary); cursor: pointer; padding: 0;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.notif-bell:hover, .notif-bell[aria-expanded="true"] { background: var(--primary-light); color: var(--primary); }
.notif-bell:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.25); }
.notif-bell-icon { width: 20px; height: 20px; }
.notif-badge {
  position: absolute; top: -4px; right: -5px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: var(--radius-pill); background: var(--red); color: #fff; border: 2px solid var(--card);
  font-size: 10.5px; font-weight: 700; line-height: 14px; text-align: center; box-sizing: border-box;
}
.notif-badge[hidden] { display: none; }
.notif-ring .notif-bell-icon { animation: notif-ring .9s ease; transform-origin: 50% 10%; }
@keyframes notif-ring {
  0%, 100% { transform: rotate(0); }
  15% { transform: rotate(14deg); } 30% { transform: rotate(-12deg); }
  45% { transform: rotate(8deg); } 60% { transform: rotate(-5deg); } 75% { transform: rotate(2deg); }
}
.notif-dropdown {
  position: absolute; top: calc(100% + 10px); right: 0; width: 360px; max-width: calc(100vw - 24px);
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-hover); z-index: 60; overflow: hidden; color: var(--text);
}
.notif-dropdown[hidden] { display: none; }
.notif-head, .notif-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 14px;
}
.notif-head { border-bottom: 1px solid var(--border); font-size: 14px; }
.notif-foot { border-top: 1px solid var(--border); flex-wrap: wrap; }
.notif-link {
  background: none; border: 0; padding: 0; font: inherit; font-size: 12px; font-weight: 600;
  color: var(--primary); cursor: pointer;
}
.notif-link:hover { text-decoration: underline; }
.notif-link:disabled { color: var(--gray); cursor: default; text-decoration: none; }
.notif-link[hidden] { display: none; }
.notif-list { max-height: min(420px, 60vh); overflow-y: auto; }
.notif-empty { padding: 26px 18px; text-align: center; font-size: 13px; color: var(--text-secondary); }
.notif-item {
  display: flex; gap: 10px; width: 100%; text-align: left; padding: 11px 14px;
  background: none; border: 0; border-bottom: 1px solid var(--border); font: inherit; color: inherit; cursor: pointer;
}
.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: #f7f8fc; }
.notif-item.unread { background: var(--primary-light); }
.notif-item.unread:hover { background: #e4e7ff; }
.notif-dot { flex-shrink: 0; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: transparent; }
.notif-item.unread .notif-dot { background: var(--red); }
.notif-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.notif-title { font-size: 13px; font-weight: 600; color: var(--text); }
.notif-item:not(.unread) .notif-title { font-weight: 500; }
.notif-body {
  font-size: 12.5px; color: var(--text-secondary); white-space: pre-line; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.notif-time { font-size: 11.5px; color: var(--gray); }

.main-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- Layout ---------- */
.page {
  padding: 24px 28px 60px;
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
}

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

.page-header h1 {
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .15s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: var(--shadow-primary);
}
.btn-primary:hover { box-shadow: 0 8px 20px rgba(var(--primary-rgb), 0.36); transform: translateY(-1px); }
.btn-secondary { background: #eef0f7; color: var(--text); }
.btn-secondary:hover { background: #e2e5f2; }
.btn-danger { background: var(--red-light); color: var(--red); }
.btn-danger:hover { background: #fbdada; }
.btn-accent { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); color: #fff; box-shadow: 0 6px 16px rgba(255,106,61,0.28); }
.btn-accent:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(255,106,61,0.36); }
.btn-sm { padding: 5px 12px; font-size: 12.5px; border-radius: 8px; }
.btn-icon {
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: #eef0f7; border: none; cursor: pointer; color: var(--text);
  transition: background .15s ease, transform .12s ease;
}
.btn-icon:hover { background: #e2e5f2; }
.btn-icon:active { transform: scale(.94); }

/* ---------- Cards / panels ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.stat-card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: box-shadow .18s ease, transform .18s ease;
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}
.stat-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.stat-card .label { font-size: 12.5px; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-family: var(--font-display); font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; color: var(--text); }
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
/* Ciclo de color sutil en el borde superior de cada tarjeta de estadística, para que la fila se
   sienta viva sin necesidad de tocar el HTML de cada página que las usa. */
.stats-row .stat-card:nth-child(4n+2)::before { background: linear-gradient(90deg, var(--green), #4fd88a); }
.stats-row .stat-card:nth-child(4n+3)::before { background: linear-gradient(90deg, var(--orange), #fbbf24); }
.stats-row .stat-card:nth-child(4n+4)::before { background: linear-gradient(90deg, var(--purple), #c4b5fd); }

/* ---------- Course tabs ---------- */
.course-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.course-tab {
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  background: #fff;
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all .15s ease;
}
.course-tab:hover { border-color: var(--primary); color: var(--primary); }
.course-tab.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-primary);
}

/* ---------- Kanban board ---------- */
.kanban-board {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 20px;
}

.kanban-column {
  flex: 0 0 280px;
  background: #e9eaf3;
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 260px);
  border: 1px solid transparent;
  transition: background .15s ease, border-color .15s ease;
}

.kanban-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 12px;
}

.kanban-column-header .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 8px; box-shadow: 0 0 0 3px rgba(0,0,0,0.05); }
.kanban-column-header .title { font-family: var(--font-display); font-size: 13.5px; font-weight: 700; letter-spacing: -0.01em; }
.kanban-column-header .count {
  font-size: 11.5px; color: var(--text-secondary); background: rgba(23,26,46,0.06);
  padding: 2px 8px; border-radius: var(--radius-pill); font-weight: 700;
}

.kanban-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  min-height: 40px;
  flex: 1;
}

.lead-card {
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 14px;
  box-shadow: var(--shadow-xs);
  cursor: grab;
  border: 1px solid var(--border);
  transition: box-shadow .15s ease, transform .12s ease, border-color .15s ease;
}
.lead-card:hover { box-shadow: var(--shadow-hover); border-color: var(--border-strong); transform: translateY(-1px); }
.lead-card.dragging { opacity: 0.4; }
.lead-card .name { font-size: 14px; font-weight: 700; margin-bottom: 2px; color: var(--text); }
.lead-card .phone { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.lead-card .meta-row { display: flex; align-items: center; justify-content: space-between; font-size: 11.5px; color: var(--text-secondary); }
.lead-card .amount { font-weight: 700; color: var(--green); }
.lead-card .tags { display:flex; gap:4px; flex-wrap:wrap; margin-top:6px; }
.lead-card-preview {
  font-size: 12px; color: var(--text-secondary); line-height: 1.4; margin: 6px 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.lead-card .tag { background: var(--primary-light); color: var(--primary); font-size:10.5px; font-weight:700; padding:2px 8px; border-radius:var(--radius-pill); }

.kanban-column.drag-over { background: var(--primary-light); border-color: rgba(var(--primary-rgb),0.35); }

/* ---------- Iconos de acción rápida en la tarjeta del lead (estilo HubSpot) ---------- */
.lead-card-actions { display: flex; gap: 4px; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.lead-quick-icon {
  width: 26px; height: 26px; border-radius: 8px; border: none; background: #f2f3f9;
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px;
  cursor: pointer; transition: background .12s ease, transform .12s ease; padding: 0; flex-shrink: 0;
}
.lead-quick-icon:hover { background: var(--primary-light); transform: translateY(-1px); }
.lead-quick-icon.ai-quick-icon:hover { background: var(--purple-light); }

.ai-popover {
  position: absolute; bottom: calc(100% + 6px); left: 0; width: 240px; z-index: 60;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: 0 10px 30px rgba(23,26,46,.18); padding: 10px 12px; font-size: 12px; color: var(--text);
}
.ai-popover-row { margin-bottom: 6px; line-height: 1.4; }
.ai-popover-row:last-child { margin-bottom: 0; }
.ai-popover-row b { color: var(--purple); }

/* ---------- Lead detail panel (slide-over) ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.25);
  display: none; z-index: 100;
}
.overlay.open { display: block; }

.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 460px;
  background: #fff; box-shadow: -8px 0 40px rgba(0,0,0,0.15);
  transform: translateX(100%); transition: transform .25s ease;
  z-index: 101; display: flex; flex-direction: column;
}
.panel.open { transform: translateX(0); }

.panel-header {
  padding: 20px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; justify-content: space-between;
}
.panel-header h2 { margin: 0 0 2px; font-size: 18px; font-weight: 700; }
.panel-header .sub { font-size: 13px; color: var(--text-secondary); }

.panel-tabs { display: flex; gap: 4px; padding: 10px 22px 0; border-bottom: 1px solid var(--border); }
.panel-tabs button {
  background: none; border: none; padding: 8px 14px; font-size: 13px; font-weight: 600;
  color: var(--text-secondary); cursor: pointer; border-bottom: 2px solid transparent;
}
.panel-tabs button.active { color: var(--blue); border-color: var(--blue); }

.panel-body { flex: 1; overflow-y: auto; padding: 18px 22px; }
.panel-section { margin-bottom: 20px; }
.panel-section label { display:block; font-size: 11.5px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }

/* Campos de formulario: todos los tipos de texto comparten el mismo estilo (antes email, password,
   url, date y time quedaban con el estilo nativo del navegador). */
select, textarea, input:not([type]),
input[type=text], input[type=number], input[type=email], input[type=password], input[type=url],
input[type=search], input[type=tel], input[type=date], input[type=time], input[type=datetime-local] {
  width: 100%; min-height: 40px; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow-xs);
  font-family: var(--font); font-size: 13.5px; line-height: 1.4; background: #fbfbfe; color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}
select:hover, textarea:hover, input:not([type]):hover,
input[type=text]:hover, input[type=number]:hover, input[type=email]:hover, input[type=password]:hover, input[type=url]:hover,
input[type=search]:hover, input[type=tel]:hover, input[type=date]:hover, input[type=time]:hover, input[type=datetime-local]:hover {
  border-color: var(--gray); background: #fff;
}
select:focus, textarea:focus, input:not([type]):focus,
input[type=text]:focus, input[type=number]:focus, input[type=email]:focus, input[type=password]:focus, input[type=url]:focus,
input[type=search]:focus, input[type=tel]:focus, input[type=date]:focus, input[type=time]:focus, input[type=datetime-local]:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.16); background: #fff;
}
/* Solo se marca en rojo después de que el usuario tocó el campo, no al cargar la página. */
select:user-invalid, textarea:user-invalid, input:user-invalid {
  border-color: var(--red); box-shadow: 0 0 0 3px rgba(224, 51, 47, 0.12);
}
input::placeholder, textarea::placeholder { color: var(--gray); opacity: 1; }
select:disabled, textarea:disabled, input:disabled, textarea[readonly], input[readonly] {
  background: var(--bg); color: var(--text-secondary); border-color: var(--border); box-shadow: none; cursor: not-allowed;
}
select:not([multiple]) {
  appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7086' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 12px;
}
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
input[type=checkbox], input[type=radio] { accent-color: var(--primary); cursor: pointer; }
input[type=file] { font-family: var(--font); font-size: 13px; color: var(--text-secondary); }
input[type=file]::file-selector-button {
  margin-right: 10px; padding: 7px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--card); color: var(--text); font-family: var(--font); font-weight: 600; cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}
input[type=file]::file-selector-button:hover { border-color: var(--primary); background: var(--primary-light); }

/* ---------- Chat ---------- */
.chat-window { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 12px; }
/* Envuelve cada burbuja para poder anclar el emoji de reacción en su esquina, sin mover el
   alineado (izquierda/derecha) que antes vivía directo en .bubble. */
.bubble-row { display: flex; position: relative; max-width: 100%; }
.bubble-row.in { align-self: flex-start; }
.bubble-row.out { align-self: flex-end; }
.bubble {
  max-width: 100%; padding: 6px 7px 8px 9px; border-radius: 7.5px;
  font-size: 14.2px; line-height: 19px; white-space: pre-wrap; word-wrap: break-word;
}
.bubble::after { content: ''; display: table; clear: both; }
.bubble.in { background: #e3e5f0; border-bottom-left-radius: 2px; }
.bubble.out { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; border-bottom-right-radius: 2px; }
/* Hipervínculos dentro de los mensajes: subrayados para que se note que son clicables, y en blanco
   sobre las burbujas azules (salientes) para que se sigan leyendo bien. */
.bubble a { color: var(--blue); text-decoration: underline; word-break: break-all; }
.bubble.out a { color: #fff; }

/* Color de selección de texto dentro de los mensajes, para que se note claramente qué se está
   seleccionando (por ejemplo, para copiar). Mismo tono en ambos tipos de burbuja para que resalte
   igual de bien sobre el fondo claro (mensajes recibidos) y el fondo azul (mensajes enviados). */
.bubble.in::selection, .bubble.in *::selection { background: #ffd43b; color: #1a1a1a; }
.bubble.out::selection, .bubble.out *::selection { background: #ffd43b; color: #1a1a1a; }

/* Tarjeta de vista previa de un link (imagen arriba, texto abajo, simétrica), clicable. */
.link-preview-card {
  margin-top: 6px; border-radius: 10px; overflow: hidden; cursor: pointer;
  background: rgba(0,0,0,.045); width: 100%; max-width: 280px;
}
.bubble.out .link-preview-card { background: rgba(255,255,255,.16); }
.link-preview-card:empty { display: none; }
.link-preview-img { width: 100%; height: 160px; object-fit: cover; display: block; }
.link-preview-body { padding: 10px 12px; text-align: left; }
.link-preview-title { font-size: 13px; font-weight: 700; line-height: 1.35; }
.link-preview-desc {
  font-size: 12px; opacity: .8; margin-top: 4px; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.link-preview-site { font-size: 11.5px; color: var(--blue); margin-top: 5px; }
.bubble.out .link-preview-site { color: #cfe0ff; }
/* Los stickers se ven sin fondo de burbuja, igual que en WhatsApp. */
.bubble.sticker { background: transparent; padding: 0; }
.bubble.sticker .time { background: #fff; padding: 1px 6px; border-radius: 8px; float: right; margin-top: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
/* Igual que WhatsApp: la hora "flota" a la derecha pegada al final del último renglón de texto,
   en vez de ocupar su propio renglón completo debajo del mensaje. */
.bubble .time { float: right; margin: 4px 0 -4px 10px; font-size: 11px; opacity: .6; line-height: 1; white-space: nowrap; }
/* Emoji de reacción, anclado a la esquina inferior de la burbuja como en WhatsApp. */
.msg-reaction {
  position: absolute; bottom: -9px; background: #fff; border-radius: 999px; padding: 1px 5px;
  font-size: 13px; line-height: 1.3; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.bubble-row.in .msg-reaction { right: -6px; }
.bubble-row.out .msg-reaction { left: -6px; }
/* Nuestra propia reacción (la que nosotros enviamos), en la esquina opuesta para no encimarse
   con la del lead si ambos reaccionaron al mismo mensaje. */
.msg-reaction-mine { bottom: -9px; }
.bubble-row.in .msg-reaction-mine { left: -6px; }
.bubble-row.out .msg-reaction-mine { right: -6px; }
/* Sentimiento del mensaje del cliente (Jev): emoji pequeño y discreto en la esquina superior de las
   burbujas entrantes; las reacciones viven en las esquinas inferiores, así que no se enciman. */
.msg-sentiment {
  position: absolute; top: -7px; right: -6px; background: #fff; border-radius: 999px; padding: 0 3px;
  font-size: 11px; line-height: 1.45; opacity: .85; box-shadow: 0 1px 2px rgba(0,0,0,.18); cursor: default;
}
.msg-sentiment:hover { opacity: 1; }

/* Cita de un mensaje al que se le contestó ("Responder"), dentro de la burbuja. */
.quoted-msg {
  background: rgba(0,0,0,.06); border-left: 3px solid var(--blue); border-radius: 6px;
  padding: 4px 8px; margin-bottom: 4px; font-size: 12.5px; max-width: 260px;
}
.bubble.out .quoted-msg { background: rgba(255,255,255,.18); border-left-color: #fff; }
.quoted-msg .who { font-weight: 700; font-size: 11.5px; }
.quoted-msg .txt { opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Franja de "respondiendo a…" arriba del campo de texto del chat. */
.reply-preview { display: none; align-items: stretch; gap: 8px; padding: 8px 22px 0; }
.reply-preview-bar { width: 3px; border-radius: 2px; background: var(--blue); flex-shrink: 0; }
.reply-preview-content { flex: 1; background: #f5f5f7; border-radius: 8px; padding: 6px 10px; font-size: 12.5px; color: var(--text-secondary); min-width: 0; }
.reply-preview-content b { color: var(--text); }
.reply-preview-close { align-self: center; cursor: pointer; color: var(--text-secondary); font-size: 16px; padding: 0 6px; }
.reply-preview-close:hover { color: var(--text); }

/* Botón de "más opciones" por burbuja (aparece al pasar el mouse) y su menú, con la misma
   estética clara que el resto del CRM (no oscura, a diferencia del menú nativo de WhatsApp). */
.bubble-menu-btn {
  position: absolute; top: 2px; opacity: 0; transition: opacity .15s;
  width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.08); color: var(--text-secondary); font-size: 12px; cursor: pointer; z-index: 5;
}
.bubble-row:hover .bubble-menu-btn { opacity: 1; }
.bubble-row.in .bubble-menu-btn { right: -28px; }
.bubble-row.out .bubble-menu-btn { left: -28px; }

.bubble-menu {
  position: absolute; top: 26px; z-index: 50; background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: 0 6px 20px rgba(0,0,0,.15); min-width: 190px;
  padding: 6px; display: none;
}
.bubble-row.in .bubble-menu { right: -28px; }
.bubble-row.out .bubble-menu { left: -28px; }
.bubble-menu-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px;
  cursor: pointer; font-size: 13px; color: var(--text); white-space: nowrap;
}
.bubble-menu-item:hover { background: #f0f4fb; }
.bubble-menu-item.danger { color: var(--red); }
.bubble-menu-sep { height: 1px; background: var(--border); margin: 4px 0; }
.bubble-reaction-row { display: flex; gap: 4px; padding: 4px 6px 6px; }
.bubble-reaction-row span { font-size: 19px; cursor: pointer; padding: 2px 4px; border-radius: 6px; line-height: 1; }
.bubble-reaction-row span:hover { background: #f0f4fb; }

.chat-input-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 22px; border-top: 1px solid var(--border); align-items: center; }
.chat-input-row input { flex: 1; }
/* El cuadro de texto va arriba y ocupa TODO el ancho de la fila; los botones y opciones
   (plantilla, respuestas rápidas, emoji, imagen, adjuntar, enviar) quedan en su propia fila
   justo debajo, porque el textarea se saca del flujo horizontal con flex-basis:100%. */
.chat-input-row textarea {
  order: -1; flex: 1 1 100%; width: 100%; min-width: 0;
  /* "vertical" deja la asa de arrastre nativa en la esquina inferior derecha, para que el
     usuario pueda agrandar el cuadro de texto a mano cuando escribe mensajes largos. */
  resize: vertical; font-family: inherit; font-size: 13.5px; line-height: 1.4;
  height: 90px; min-height: 38px; max-height: 400px; overflow-y: auto; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: #fff;
}
/* Todo lo demás (select, botones, qr/emoji) forma la fila de opciones debajo del cuadro de texto,
   sin encogerse hasta desaparecer. */
.chat-input-row > *:not(textarea) { flex-shrink: 0; }
.chat-input-row select[id$="TemplateSelect"] { max-width: 150px; flex: 1 1 auto; }

/* Botón de micrófono e indicador de grabación de notas de voz */
.chat-input-row button.mic-recording { background: var(--red); border-color: var(--red); color: #fff; }
.mic-rec-indicator {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary);
  background: #fff0f0; border: 1px solid #ffd6d6; border-radius: var(--radius-sm); padding: 5px 8px;
}
.mic-rec-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--red);
  animation: mic-pulse 1s ease-in-out infinite;
}
.mic-rec-indicator #micTimer-panel, .mic-rec-indicator #micTimer-main { min-width: 30px; font-variant-numeric: tabular-nums; }
.mic-rec-indicator .btn-icon { padding: 0 2px; font-size: 13px; line-height: 1; color: var(--red); }
@keyframes mic-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* ---------- Chat: página estilo WhatsApp Web ---------- */
.chat-layout {
  display: flex;
  height: calc(100vh - 73px);
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
}
.chat-sidebar {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-right: 1px solid var(--border);
}
.chat-resize-handle {
  width: 6px;
  flex-shrink: 0;
  cursor: col-resize;
  background: var(--border);
  position: relative;
}
.chat-resize-handle:hover, .chat-resize-handle.dragging { background: var(--blue); }
.chat-resize-handle::after {
  content: '';
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 3px; height: 28px; border-radius: 3px; background: rgba(0,0,0,.15);
}
.chat-sidebar-header { padding: 14px; border-bottom: 1px solid var(--border); }
.chat-list { flex: 1; overflow-y: auto; }
.chat-list-item {
  display: flex; flex-direction: column; gap: 6px; padding: 12px 16px;
  cursor: pointer; border-bottom: 1px solid var(--border); transition: background .1s ease;
}
.chat-list-item:hover { background: #f6f6fb; }
.chat-list-item.active { background: var(--primary-light); box-shadow: inset 3px 0 0 var(--primary); }
.chat-list-top { display: flex; align-items: center; gap: 12px; width: 100%; }
.chat-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; font-weight: 700; font-size: 15px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.chat-list-info { flex: 1; min-width: 0; }
.chat-list-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list-sub { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list-time { font-size: 11px; color: var(--text-secondary); flex-shrink: 0; }
.chat-list-stage {
  width: 100%; margin-left: 52px; max-width: calc(100% - 52px);
  font-size: 11.5px; padding: 3px 6px; border-radius: 6px;
  border: 1px solid var(--border); background: #fafafa; color: var(--text-secondary);
  cursor: pointer;
}
.chat-list-stage:hover { border-color: var(--blue); color: var(--text-primary); }

.chat-list-item.needs-followup { background: #fff5f2; border-left: 3px solid #e0522f; }
.chat-list-item.needs-followup:hover { background: #ffece5; }
.chat-list-alert {
  margin-left: 52px; font-size: 11px; font-weight: 600; color: #c0442a;
}

/* Mensajes sin leer: nombre en negrita + puntito azul, estilo WhatsApp */
.chat-list-item.unread .chat-list-name { font-weight: 800; color: var(--text-primary); }
.chat-list-item.unread .chat-list-sub { color: var(--text-primary); font-weight: 600; }
.unread-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--blue, #2f6fed);
  flex-shrink: 0; margin-left: 6px;
}

.color-picker { display: inline-flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.color-swatch {
  width: 22px; height: 22px; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; cursor: pointer;
  border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.color-swatch input { position: absolute; opacity: 0; width: 0; height: 0; }
.color-swatch:has(input:checked) { border-color: #1d1d1f; box-shadow: 0 0 0 2px #fff inset, 0 0 0 3px #1d1d1f; }
.color-swatch:hover { transform: scale(1.12); }

.qr-wrap { position: relative; display: inline-block; }
.qr-trigger {
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 6px; font-size: 15px; line-height: 1;
  color: var(--text-secondary); cursor: pointer; padding: 0;
}
.qr-trigger:hover { background: #f0f0f2; color: var(--text-primary); }
.qr-menu {
  position: absolute; bottom: calc(100% + 6px); left: 0; width: 280px; max-height: 320px;
  overflow-y: auto; background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,.14); z-index: 50; padding: 6px;
}
.qr-item { padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.qr-item:hover { background: #f0f4fb; }
.qr-item-title { font-size: 12.5px; font-weight: 600; margin-bottom: 2px; }
.qr-shortcut { color: var(--blue); font-weight: 700; }
.qr-item-preview { font-size: 11.5px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qr-empty { padding: 10px; font-size: 12px; color: var(--text-secondary); }

/* Selector de emojis estilo picker nativo (fondo oscuro, buscador, secciones por categoría,
   "Recientes" guardado en localStorage, y barra inferior de categorías para saltar de sección). */
.emoji-picker {
  position: absolute; bottom: calc(100% + 6px); left: 0; width: 300px; height: 360px;
  background: #1e1e20; border: 1px solid #333; border-radius: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.4);
  z-index: 50; flex-direction: column; overflow: hidden;
}
.emoji-picker-search { padding: 10px 10px 6px; }
.emoji-picker-search input {
  width: 100%; background: #2c2c2e; border: 1px solid #3a3a3c; border-radius: 8px;
  color: #fff; padding: 7px 10px; font-size: 12.5px;
}
.emoji-picker-search input::placeholder { color: #8e8e93; }
.emoji-picker-scroll { flex: 1; overflow-y: auto; padding: 0 10px; }
.emoji-picker-heading {
  font-size: 11px; font-weight: 700; color: #8e8e93; text-transform: uppercase; letter-spacing: .04em;
  margin: 10px 0 6px; position: sticky; top: 0; background: #1e1e20; padding: 4px 0;
}
.emoji-picker-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.emoji-picker-grid .emoji-item {
  width: 100%; height: 30px; display: flex; align-items: center; justify-content: center;
  font-size: 18px; border-radius: 6px; cursor: pointer;
}
.emoji-picker-grid .emoji-item:hover { background: #3a3a3c; }
.emoji-picker-tabs {
  display: flex; border-top: 1px solid #333; padding: 4px 2px; flex-shrink: 0;
}
.emoji-picker-tabs button {
  flex: 1; background: none; border: none; color: #8e8e93; font-size: 15px;
  padding: 6px 2px; cursor: pointer; border-radius: 6px;
}
.emoji-picker-tabs button:hover { background: #2c2c2e; }

.field-label {
  display: block; font-size: 11px; font-weight: 600; color: var(--text-secondary);
  margin-bottom: 5px; text-transform: uppercase; letter-spacing: .04em;
}
#addRuleForm input, #addRuleForm select { width: 100%; }
#addRuleForm select + select, #addRuleForm select + input { margin-top: 6px; }

.nav-badge {
  display: inline-block; background: var(--accent); color: #fff; font-size: 10.5px;
  font-weight: 700; border-radius: 10px; padding: 1px 6px; margin-left: 3px;
  vertical-align: 2px;
}

.chat-view-tabs {
  display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px;
}
.chat-view-tab {
  font-size: 12px; font-weight: 600; color: var(--text-secondary);
  background: #f0f1f8; border-radius: 8px; padding: 5px 9px;
  text-decoration: none; white-space: nowrap; transition: all .15s ease;
}
.chat-view-tab:hover { background: #e4e6f3; }
.chat-view-tab.active { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; }
.chat-view-tab.active .nav-badge { background: rgba(255,255,255,.35); }

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-shell);
  min-width: 0;
}
.chat-main-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; background: #fff; border-bottom: 1px solid var(--border);
}
.chat-main-header .who { display: flex; align-items: center; gap: 12px; }
.chat-main-header .name { font-size: 14.5px; font-weight: 700; }
.chat-main-header .sub { font-size: 12px; color: var(--text-secondary); }
.chat-main-body { flex: 1; overflow-y: auto; padding: 20px 22px; }
.chat-main .chat-window { max-width: 720px; margin: 0 auto; }
.chat-main .chat-input-row { background: #fff; }

/* ---------- Logo en la barra superior ---------- */
.brand-logo { height: 28px; max-width: 160px; object-fit: contain; display: block; }

/* ---------- Asistente de IA ---------- */
.ai-badge {
  display: inline-block; font-size: 10px; font-weight: 700; background: rgba(255,255,255,0.25);
  padding: 1px 7px; border-radius: 980px; margin-bottom: 4px;
}
.bubble.in .ai-badge { background: var(--purple-light); color: var(--purple); }
.ai-suggestion {
  background: var(--purple-light); border: 1px solid #ded0fc; border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 12.5px; margin-bottom: 16px;
}

/* ---------- Notas del equipo (post-its) ---------- */
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.sticky-note {
  border-radius: var(--radius-md); padding: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 140px;
}
.sticky-yellow { background: #fff9db; }
.sticky-blue { background: #e7f3ff; }
.sticky-green { background: #e6f9ec; }
.sticky-pink { background: #ffeef3; }
.sticky-header { display: flex; align-items: center; margin-bottom: 8px; }
.sticky-title { font-weight: 700; font-size: 13.5px; }
.sticky-pin { background: none; border: none; cursor: pointer; font-size: 14px; }
.sticky-body { flex: 1; font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
.sticky-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: 11px; color: var(--text-secondary); }
.sticky-delete { background: none; border: none; cursor: pointer; color: var(--text-secondary); font-size: 12px; }
.sticky-delete:hover { color: var(--red); }

/* ---------- Calendar ---------- */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.calendar-day-name { text-align: center; font-size: 11.5px; font-weight: 700; color: var(--text-secondary); padding-bottom: 6px; }
.calendar-cell {
  background: #fff; border-radius: var(--radius-sm); border: 1px solid var(--border);
  min-height: 100px; padding: 8px; font-size: 12px; transition: background .1s ease, border-color .1s ease;
}
.calendar-cell .day-num { font-weight: 700; margin-bottom: 6px; }
.calendar-cell.today { border-color: var(--blue); }
.calendar-cell.has-day:hover { background: #eef4ff; border-color: var(--blue); }
.calendar-cell.has-day.selected { background: #dceaff; border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue) inset; }
.reminder-chip {
  background: #fff3e0; color: #b25c00; font-size: 10.5px; font-weight: 600;
  padding: 3px 6px; border-radius: 6px; margin-bottom: 3px; cursor: pointer;
}
.reminder-chip.done { background: #e6f7ea; color: #1a7a35; text-decoration: line-through; }

/* ---------- Tables (settings, templates) ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-secondary); font-weight: 700; padding: 11px 14px; border-bottom: 1px solid var(--border); background: #fafafe; }
td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: #fafafe; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1100px 560px at 12% 8%, rgba(var(--primary-rgb), 0.16), transparent 60%),
    radial-gradient(900px 520px at 90% 90%, rgba(255,106,61,0.14), transparent 55%),
    var(--bg-shell);
}
.login-card { width: 360px; padding: 40px 32px; text-align: center; }
.login-card h1 { font-family: var(--font-display); font-size: 21px; margin-bottom: 4px; }
.login-card p { color: var(--text-secondary); font-size: 13px; margin-bottom: 24px; }
.login-card input { margin-bottom: 12px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 8px; }
.login-error { color: var(--red); font-size: 12.5px; margin-bottom: 10px; }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: var(--radius-pill); }
.badge-approved { background: var(--green-light); color: #157a3d; }
.badge-pending { background: var(--orange-light); color: #a15c06; }
.badge-rejected { background: var(--red-light); color: var(--red); }

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

.comment-card.unanswered { border: 1.5px solid #f3b9b9; background: #fffaf9; }
.comment-card.replied { opacity: .7; }

/* ---------- Constructor visual de flujos (estilo Kommo Salesbot) ---------- */
.flows-layout { display: flex; gap: 20px; align-items: flex-start; }
.flows-sidebar { width: 300px; flex-shrink: 0; }
.flow-card {
  padding: 14px 16px; margin-bottom: 10px; cursor: pointer; border: 1.5px solid transparent;
}
.flow-card:hover { border-color: var(--blue); }
.flow-card.active { border-color: var(--blue); background: #f5f9ff; }
.flow-card.inactive { opacity: .55; }
.flow-card .flow-card-name { font-weight: 700; font-size: 14px; margin-bottom: 3px; }
.flow-card .flow-card-sub { font-size: 11.5px; color: var(--text-secondary); }
.flow-card .flow-card-actions { display: flex; gap: 6px; margin-top: 8px; }

.flow-canvas-wrap {
  flex: 1; min-height: 500px; background: #fafafa; border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 32px 20px 60px; overflow-x: auto;
}
.flow-canvas-empty { text-align: center; padding: 100px 20px; color: var(--text-secondary); }
.flow-chain { display: flex; flex-direction: column; align-items: center; }
.flow-connector { width: 2px; height: 26px; background: #c7c7cc; }
.flow-trigger-box, .flow-step-box {
  width: 280px; background: #fff; border: 1.5px solid var(--border); border-radius: var(--radius-md);
  padding: 12px 14px; box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.flow-trigger-box { border-color: var(--blue); background: #f5f9ff; }
.flow-step-box.condition { border-color: #b25c00; background: #fffaf3; }
.flow-step-row { display: flex; align-items: flex-start; gap: 10px; }
.flow-step-icon { font-size: 18px; flex-shrink: 0; }
.flow-step-title { font-weight: 700; font-size: 13px; }
.flow-step-summary { font-size: 12px; color: var(--text-secondary); margin-top: 2px; white-space: pre-wrap; }
.flow-step-actions { display: flex; gap: 4px; margin-left: auto; flex-shrink: 0; }
.flow-step-actions button {
  border: none; background: transparent; cursor: pointer; font-size: 13px; color: var(--text-secondary);
  padding: 2px 4px; border-radius: 6px;
}
.flow-step-actions button:hover { background: #eee; color: var(--text); }

.flow-add-btn {
  width: 28px; height: 28px; border-radius: 50%; border: 1.5px dashed #a9a9ad; background: #fff;
  color: var(--text-secondary); font-size: 16px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center; margin: 2px 0;
}
.flow-add-btn:hover { border-color: var(--blue); color: var(--blue); }

.flow-branches { display: flex; gap: 40px; align-items: flex-start; margin-top: 4px; }
.flow-branch-col { display: flex; flex-direction: column; align-items: center; }
.flow-branch-label {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-secondary); background: #ececef; padding: 2px 10px; border-radius: 980px; margin-bottom: 6px;
}

.flow-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center;
  justify-content: center; z-index: 500;
}
.flow-modal {
  width: 380px; max-height: 80vh; overflow-y: auto; background: #fff; border-radius: var(--radius-lg);
  padding: 22px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.flow-modal h3 { font-size: 15px; margin-bottom: 14px; }
.flow-modal label { display: block; font-size: 11.5px; font-weight: 600; color: var(--text-secondary); margin: 12px 0 5px; text-transform: uppercase; letter-spacing: .04em; }
.flow-modal label:first-of-type { margin-top: 0; }
.flow-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.flow-palette-list { display: flex; flex-direction: column; gap: 6px; }
.flow-palette-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); cursor: pointer; font-size: 13px; font-weight: 600;
}
.flow-palette-item:hover { border-color: var(--blue); background: #f5f9ff; }

/* ---------- Utilidades de grid reutilizables (para que los media queries de abajo puedan
   convertirlas a una sola columna en móvil sin pelear con grid-template-columns inline) ---------- */
.grid-2col { display: grid; grid-template-columns: 1fr 1fr; }
.grid-3col { display: grid; grid-template-columns: repeat(3, 1fr); }

/* Botón "←" para volver de la conversación a la lista de chats: solo existe visualmente en móvil. */
.chat-back-btn {
  display: none; background: none; border: none; font-size: 20px; line-height: 1;
  color: var(--text); cursor: pointer; padding: 4px 8px 4px 0; flex-shrink: 0;
}

/* ==========================================================
   Responsive: tablets y pantallas grandes (<=1024px)
   ========================================================== */
@media (max-width: 1024px) {
  .page { max-width: 100%; }
  .chat-layout, .flows-layout { max-width: 100%; }
  .panel { width: min(460px, 100vw); }
  .flow-modal { width: min(380px, 92vw); }
}

/* ==========================================================
   Responsive: tablets angostas y móviles en horizontal (<=900px)
   ========================================================== */
@media (max-width: 900px) {
  /* La barra lateral se colapsa a solo íconos (sin el nombre) para no robarle espacio al contenido. */
  .sidebar { width: 56px; padding: 12px 6px; align-items: center; }
  .sidebar-link { width: 40px; height: 40px; justify-content: center; padding: 0; }
  .sidebar-label { display: none; }
  .sidebar-link .nav-badge { position: absolute; top: -2px; right: -2px; margin-left: 0; }
  .sidebar-link.active::before { left: 50%; top: -4px; bottom: auto; width: 18px; height: 3px; transform: translateX(-50%); border-radius: 4px 4px 0 0; background: linear-gradient(90deg, var(--accent), var(--primary)); }

  .topbar { padding: 10px 16px; }
  .topbar-logo img { height: 32px; }
  .topbar-logo-fallback { font-size: 15px; }
  .topbar-logo-fallback span { display: none; }
  .topbar-user-name { display: none; }
  .notif-bell { width: 34px; height: 34px; }

  .page { padding: 16px 14px 40px; }
  .page-header { flex-wrap: wrap; gap: 10px; }
  .page-header h1 { font-size: 21px; }

  .grid-2col, .grid-3col { grid-template-columns: 1fr; }

  .flows-layout { flex-direction: column; }
  .flows-sidebar { width: 100%; }

  .kanban-column { flex: 0 0 240px; }
}

/* ==========================================================
   Responsive: teléfonos (<=640px)
   ========================================================== */
@media (max-width: 640px) {
  .page { padding: 12px 10px 32px; }
  .page-header h1 { font-size: 19px; }
  .stats-row { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }

  /* Tablas: en vez de reventar el layout, se hacen scrolleables horizontalmente dentro de su card. */
  .card:has(table) { overflow-x: auto; }
  .card:has(table) table { min-width: 480px; }

  /* Ficha de lead (slide-over): ocupa toda la pantalla en vez de un panel angosto a la derecha. */
  .panel { width: 100vw; }

  /* Campanita: el menú se ancla a la pantalla para no salirse por la izquierda. */
  .notif-dropdown { position: fixed; top: 58px; left: 12px; right: 12px; width: auto; max-width: none; }

  /* Login */
  .login-card { width: 92vw; max-width: 360px; padding: 32px 22px; }

  /* Calendario: se mantiene en 7 columnas pero permite scroll horizontal si no caben cómodas. */
  .calendar-grid { overflow-x: auto; }

  /* Constructor de flujos: el modal ya no fuerza min-width, y las cajas del canvas se acomodan. */
  .flow-modal { padding: 18px 16px; }

  /* ---- Chat: una sola columna a la vez (lista de chats o conversación abierta) ---- */
  .chat-layout { height: calc(100vh - 53px); position: relative; overflow: hidden; }
  .chat-sidebar {
    width: 100% !important; max-width: 100%;
    position: absolute; inset: 0; z-index: 2;
    transition: transform .2s ease;
  }
  .chat-resize-handle { display: none; }
  .chat-main {
    position: absolute; inset: 0; z-index: 1;
    transform: translateX(100%); transition: transform .2s ease;
  }
  .chat-layout.chat-mobile-open .chat-sidebar { transform: translateX(-100%); }
  .chat-layout.chat-mobile-open .chat-main { transform: translateX(0); z-index: 3; }
  .chat-back-btn { display: inline-block; }
  .chat-main .chat-window { max-width: 100%; }
  .link-preview-card { max-width: 100%; }
}

/* Borrador en vivo del agente (app.js > agentLive): vista previa mientras el servicio redacta.
   No es un mensaje enviado: se ve más tenue y con borde punteado. */
.agent-draft-row { max-width: 75%; }
.bubble.out.agent-draft {
  background: var(--purple-light, #efe9fb); color: var(--text, #1d1d1f);
  border: 1px dashed var(--purple, #7e57c2); opacity: .92;
}
.agent-draft-head { display: block; font-size: 11.5px; font-weight: 600; color: var(--purple, #7e57c2); margin-bottom: 3px; }
.agent-draft-text { white-space: pre-wrap; word-wrap: break-word; }
.agent-draft-status { font-size: 12px; font-style: italic; color: var(--text-secondary, #6e6e73); margin-top: 3px; }

/* ---------- Chat de prueba del agente (agent.php > botón "Probar el agente", <dialog> nativo) ---------- */
.playground-dialog {
  width: min(1000px, 95vw); height: 85vh; max-width: 95vw; max-height: 95vh; padding: 0;
  border: none; border-radius: var(--radius-lg); background: var(--card); color: var(--text);
  box-shadow: 0 20px 60px rgba(0,0,0,.25); overflow: hidden;
}
.playground-dialog[open] { display: flex; flex-direction: column; }
.playground-dialog::backdrop { background: rgba(0,0,0,.35); }
.playground-dialog-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 16px 20px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.playground-dialog-head h3 { margin: 0 0 4px; font-size: 15px; }
.playground-dialog-note { margin: 0; color: var(--text-secondary); font-size: 12.5px; }
.playground-close {
  flex-shrink: 0; width: 32px; height: 32px; border: none; border-radius: var(--radius-sm); background: transparent;
  font-size: 22px; line-height: 1; color: var(--text-secondary); cursor: pointer;
}
.playground-close:hover { background: var(--primary-light); color: var(--text); }
.playground-dialog-body { flex: 1; min-height: 0; padding: 14px 20px 18px; }
.playground-unavailable {
  padding: 12px 14px; background: #fff6e5; border: 1px solid #f3d29b; color: #7a4b00; font-size: 13px; border-radius: 8px;
}
.playground { display: grid; grid-template-columns: minmax(0, 1fr) 290px; grid-template-rows: minmax(0, 1fr); gap: 16px; }
.playground-chat {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; background: var(--card);
}
.playground-toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.playground-conversation { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
/* Solo la lista de mensajes se desplaza; la caja de texto queda fija abajo. */
.playground-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px; background: var(--bg); }
.playground-messages .bubble-row { max-width: 80%; }
.playground-empty { text-align: center; color: var(--text-secondary); font-size: 13px; padding: 40px 10px; }
.playground-notice {
  align-self: center; max-width: 90%; font-size: 12.5px; color: var(--text-secondary);
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 10px;
  white-space: pre-wrap; word-wrap: break-word;
}
.playground-notice.error { color: var(--red); background: var(--red-light); border-color: #f3b9b9; }
.playground-notice.warn { color: var(--orange); background: var(--orange-light); border-color: #f3d29b; }
.playground-input { padding: 12px 14px; flex-shrink: 0; }
.playground-input textarea { height: 64px; }
.playground-details {
  border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px 14px; font-size: 12.5px;
  background: var(--card); min-width: 0; overflow-y: auto;
}
.playground-details-title { font-weight: 700; font-size: 13.5px; margin-bottom: 8px; cursor: pointer; }
.playground-block { border-top: 1px solid var(--border); padding: 10px 0 4px; }
.playground-block-title {
  font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase;
  letter-spacing: .04em; margin-bottom: 6px;
}
.playground-dl { margin: 0; }
.playground-dl-row { display: flex; gap: 8px; justify-content: space-between; padding: 2px 0; }
.playground-dl-row dt { color: var(--text-secondary); flex-shrink: 0; }
.playground-dl-row dd { margin: 0; text-align: right; font-weight: 600; word-break: break-word; }
.playground-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.playground-list li.ok .playground-action-type { color: var(--green); font-weight: 600; }
.playground-list li.rejected .playground-action-type { color: var(--red); font-weight: 600; }
.playground-action-detail { color: var(--text-secondary); margin-top: 1px; word-break: break-word; }
.playground-code { margin-left: 6px; font-size: 11px; color: var(--text-secondary); }
.playground-muted { color: var(--text-secondary); }
/* Celular: modal a pantalla completa; Detalles va debajo del chat y se puede plegar. */
@media (max-width: 900px) {
  .playground-dialog { width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; border-radius: 0; }
  .playground-dialog-head { padding: 12px 14px 10px; }
  .playground-dialog-body { padding: 10px 12px 12px; }
  .playground { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .playground-details { max-height: 40vh; }
}

/* ---------- Agente: interruptor global en el encabezado ---------- */
.agent-header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.agent-toggle-form { display: flex; align-items: center; gap: 10px; margin: 0; }
.agent-status {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius-pill);
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.agent-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.agent-status.is-on { background: var(--green-light); color: var(--green); }
.agent-status.is-off { background: var(--red-light); color: var(--red); }
@media (max-width: 640px) {
  .agent-header-actions, .agent-toggle-form { width: 100%; justify-content: flex-start; }
}
