/* ==========================================================================
   Jobs&Sea · CRM · Agente (Inicio)
   Interfaz portada del Agente Joe (demosjero.com, bonesan-ui.css): cabecera
   oscura con avatar de ojos, conversación, compositor y Preview plegable.
   Misma estructura y medidas; paleta del CRM de Jobs&Sea (noche + azul).
   Marcado: partials/admin-agent.ejs · Lógica: admin-agent.js · Ojos: agent-eyes.js
   ========================================================================== */

.admin-main--dashboard {
  --ag-pad: clamp(0.75rem, 1.4vw, 1.25rem);
  width: 100%;
  max-width: none;
  padding: var(--ag-pad);
}

.crm-agent {
  --ag-night: #0b182b;
  --ag-night-2: #102239;
  --ag-night-3: #18304d;
  --ag-night-4: #21406a;
  --ag-night-line: rgba(255, 255, 255, 0.08);
  --ag-ink: #eef4fa;
  --ag-muted: #9fb1c5;
  --ag-primary: #1f63b1;
  --ag-primary-300: #7fb2ea;
  --ag-primary-soft: #e8f0fb;
  --ag-primary-soft-2: #cfe0f5;
  --ag-primary-grad: linear-gradient(135deg, #2f7fd6 0%, #1f63b1 48%, #184f93 100%);
  --ag-eye: #4fd1d9;
  --ag-coral: #d9506b;
  --ag-surface: #ffffff;
  --ag-surface-2: #f6f8fb;
  --ag-surface-3: #edf1f6;
  --ag-line: #e2e8f0;
  --ag-line-2: #cbd5e1;
  --ag-text: #0f1f33;
  --ag-text-2: #2a3d55;
  --ag-text-muted: #62758b;
  --ag-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ag-ring: 0 0 0 4px rgba(31, 99, 177, 0.22);
  --ag-col: 820px;

  display: grid;
  min-width: 0;
  height: calc(100vh - var(--crm-topbar-h) - 2 * var(--ag-pad));
  height: calc(100svh - var(--crm-topbar-h) - 2 * var(--ag-pad));
  min-height: 480px;
  grid-template-columns: minmax(360px, var(--ag-chat-w, 46%)) 16px minmax(340px, 1fr);
}

.crm-agent[data-canvas="closed"] {
  grid-template-columns: minmax(0, 1fr);
}

.crm-agent[data-canvas="closed"] .crm-agent__split,
.crm-agent[data-canvas="closed"] .crm-agent__canvas {
  display: none;
}

.crm-agent [hidden] {
  display: none !important;
}

/* ---------- Columna del agente ---------- */

.crm-agent__chat,
.crm-agent__canvas {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--ag-line);
  border-radius: 26px;
  box-shadow: 0 1px 3px rgba(15, 31, 51, 0.05), 0 12px 32px rgba(15, 31, 51, 0.08);
}

.crm-agent__chat {
  border-color: transparent;
  background: var(--ag-night);
  color: var(--ag-ink);
}

/* Cabecera oscura con el avatar protagonista */
.crm-agent__head {
  position: relative;
  z-index: 2;
  display: flex;
  min-width: 0;
  min-height: 100px;
  flex: 0 0 auto;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--ag-night-line);
  background: linear-gradient(180deg, var(--ag-night-3), var(--ag-night-2));
  box-shadow: 0 10px 22px -14px rgba(0, 0, 0, 0.7);
}

.crm-agent__id {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 4px;
}

.crm-agent__name {
  overflow: hidden;
  color: var(--ag-ink);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-agent__status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ag-muted);
  font-size: 14px;
}

.crm-agent__status::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--ag-eye);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
  transition: background-color 0.2s;
}

.crm-agent__status[data-state="thinking"]::before,
.crm-agent__status[data-state="writing"]::before,
.crm-agent__status[data-state="transcribing"]::before {
  animation: crm-agent-pulse 1.2s ease-in-out infinite;
}

.crm-agent__status[data-state="listening"]::before {
  background: #8f9cff;
  animation: crm-agent-pulse 1.2s ease-in-out infinite;
}

.crm-agent__status[data-state="error"]::before {
  background: var(--ag-coral);
}

.crm-agent__spacer {
  flex: 1;
}

.crm-agent__iconbtn {
  display: inline-flex;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--ag-night-line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ag-ink);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.14s, border-color 0.14s, color 0.14s;
}

.crm-agent__iconbtn:hover,
.crm-agent__iconbtn[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.14);
}

.crm-agent__iconbtn--light {
  border-color: var(--ag-line);
  border-radius: 13px;
  background: var(--ag-surface-2);
  color: var(--ag-primary);
}

.crm-agent__iconbtn--light:hover {
  border-color: var(--ag-primary-soft-2);
  background: var(--ag-primary-soft);
}

.crm-agent__iconbtn .admin-icon,
.crm-agent__composer .admin-icon {
  width: 20px;
  height: 20px;
}

/* ---------- Avatar de ojos (igual que Joe) ---------- */

.crm-agent__avatar.eyes-frame {
  position: relative;
  width: 76px;
  height: 76px;
  flex: 0 0 76px;
  overflow: hidden;
  border-radius: 22px;
  background: linear-gradient(155deg, #2e3d48 0%, #14222c 52%, #0a1218 100%);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08), 0 12px 26px -10px rgba(0, 0, 0, 0.75);
  cursor: pointer;
  transition: box-shadow 0.24s var(--ag-ease);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.crm-agent__avatar.eyes-frame.speaking {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1), 0 0 0 6px var(--ag-eye), 0 10px 30px rgba(79, 209, 217, 0.3);
}

.crm-agent__avatar.eyes-frame.listening {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1), 0 0 0 6px #8f9cff, 0 10px 30px rgba(110, 124, 255, 0.35);
}

.crm-agent__avatar .eyes-screen {
  position: absolute;
  inset: 7%;
  overflow: hidden;
  border-radius: 18px;
  background: radial-gradient(120% 95% at 50% 38%, #0f1b24 0%, #070c11 60%, #030507 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05), inset 0 8px 20px rgba(0, 0, 0, 0.7);
}

.crm-agent__avatar .eyes-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(158deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0) 36%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.022) 0 1px, transparent 1px 3px);
}

.crm-agent__avatar .agent-eyes {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- Conversación ---------- */

.crm-agent__conversation {
  display: flex;
  min-height: 0;
  flex: 1 1 0;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 18px 28px;
  background:
    radial-gradient(120% 70% at 100% 0%, rgba(47, 127, 214, 0.2) 0%, transparent 58%),
    radial-gradient(90% 55% at 0% 100%, rgba(200, 53, 114, 0.12) 0%, transparent 65%),
    var(--ag-night);
  color: var(--ag-ink);
  scrollbar-width: thin;
  scrollbar-color: rgba(159, 177, 197, 0.35) transparent;
}

.admin-body .crm-agent__conversation:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(127, 178, 234, 0.6);
}

.crm-agent__empty {
  display: flex;
  max-width: 440px;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: auto;
  padding: 24px 8px;
  color: var(--ag-muted);
  font-size: 15px;
  line-height: 1.5;
  text-align: center;
}

.crm-agent__empty strong {
  color: #fff;
  font-size: 22px;
  font-weight: 780;
  letter-spacing: -0.02em;
}

.crm-agent__empty p {
  margin: 0;
  font-size: 16px;
}

.crm-agent__empty small {
  margin-top: 10px;
  padding: 8px 14px;
  border: 1px solid var(--ag-night-line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ag-muted);
  font-size: 13px;
  line-height: 1.45;
}

.crm-msg {
  display: flex;
  max-width: min(88%, 720px);
  flex-direction: column;
  margin-block: 6px 18px;
  animation: crm-agent-fade-up 0.28s var(--ag-ease) both;
}

.crm-msg--user {
  width: fit-content;
  min-width: 120px;
  align-self: flex-end;
}

.crm-msg--assistant {
  align-self: flex-start;
}

.crm-msg__role {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 4px 7px;
  color: var(--ag-muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.02em;
}

.crm-msg--user .crm-msg__role {
  justify-content: flex-end;
}

/* Mini «cara» del Agente junto a su nombre */
.crm-msg__eyes {
  display: inline-flex;
  width: 24px;
  height: 24px;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-radius: 7px;
  background: radial-gradient(120% 95% at 50% 38%, #10202a 0%, #060b10 100%);
  box-shadow: 0 0 0 2px rgba(108, 198, 203, 0.45);
}

.crm-msg__eyes i {
  display: block;
  width: 5px;
  height: 8px;
  border-radius: 2.5px;
  background: var(--ag-eye);
  box-shadow: 0 0 4px rgba(79, 209, 217, 0.85);
  animation: crm-agent-mini-blink 6.5s infinite;
}

.crm-msg__bubble {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  column-gap: 8px;
  padding: 14px 16px 10px;
  border-radius: 22px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  font-size: 15.5px;
  line-height: 1.55;
}

.crm-msg--user .crm-msg__bubble {
  border-top-right-radius: 8px;
  background: var(--ag-primary-grad);
  color: #fff;
}

.crm-msg--assistant .crm-msg__bubble {
  border-top-left-radius: 8px;
  background: #f5f8fb;
  color: var(--ag-text);
}

.crm-msg__text {
  min-width: 0;
  flex: 1 1 auto;
  overflow-wrap: anywhere;
}

.crm-msg__text > :first-child {
  margin-top: 0;
}

.crm-msg__text > :last-child {
  margin-bottom: 0;
}

.crm-msg__text p {
  margin: 0 0 0.7em;
}

.crm-msg__text ul,
.crm-msg__text ol {
  margin: 0 0 0.7em;
  padding-left: 1.3em;
}

.crm-msg__text li + li {
  margin-top: 0.25em;
}

.crm-msg--assistant .crm-msg__text strong {
  color: #12304f;
  font-weight: 780;
}

.crm-msg__acts {
  display: flex;
  flex: 0 0 auto;
  justify-content: flex-end;
  gap: 4px;
  margin: 0 -6px -4px auto;
}

.crm-msg__act {
  position: relative;
  display: inline-flex;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.14s, background-color 0.14s;
}

.crm-msg__act::before {
  content: "";
  position: absolute;
  inset: -5px;
}

.crm-msg__act:hover,
.crm-msg__act.is-done {
  background: rgba(15, 31, 51, 0.08);
  opacity: 1;
}

.crm-msg--user .crm-msg__act:hover,
.crm-msg--user .crm-msg__act.is-done {
  background: rgba(255, 255, 255, 0.16);
}

.crm-msg__act .admin-icon {
  width: 16px;
  height: 16px;
}

/* Esperando la primera palabra */
.crm-msg__typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 1.55em;
}

.crm-msg__typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7d8fa5;
  animation: crm-agent-typing 1.1s ease-in-out infinite;
}

.crm-msg__typing i:nth-child(2) { animation-delay: 0.15s; }
.crm-msg__typing i:nth-child(3) { animation-delay: 0.3s; }

.crm-msg__note {
  flex: 1 1 100%;
  margin-top: 8px;
  color: var(--ag-text-muted);
  font-size: 13px;
}

.crm-agent__turn-error {
  display: flex;
  max-width: min(88%, 720px);
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  align-self: flex-start;
  margin-block: 0 18px;
  padding: 10px 14px;
  border: 1px solid rgba(217, 80, 107, 0.45);
  border-radius: 16px;
  background: rgba(217, 80, 107, 0.16);
  color: #ffe1e7;
  font-size: 14px;
  line-height: 1.45;
}

.crm-agent__turn-error a {
  color: #fff;
  font-weight: 700;
}

.crm-agent__retry {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
}

.crm-agent__retry:hover {
  background: rgba(255, 255, 255, 0.12);
}

.crm-agent__retry .admin-icon {
  width: 14px;
  height: 14px;
}

/* ---------- Compositor ---------- */

.crm-agent__console {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--ag-night-line);
  background: var(--ag-night);
}

.crm-agent__composer {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px 44px;
  align-items: end;
  gap: 6px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 18px;
  background: var(--ag-surface);
  box-shadow: 0 10px 28px -14px rgba(0, 0, 0, 0.8);
  transition: border-color 0.14s, box-shadow 0.14s;
}

.crm-agent__composer:focus-within {
  border-color: var(--ag-primary);
  box-shadow: var(--ag-ring), 0 10px 28px -14px rgba(0, 0, 0, 0.8);
}

.crm-agent__input {
  position: relative;
  min-width: 0;
}

.crm-agent__input textarea {
  display: block;
  width: 100%;
  height: 44px;
  min-height: 44px;
  max-height: calc(6 * 1.5em + 20px);
  box-sizing: border-box;
  margin: 0;
  padding: 10px 44px 10px 8px;
  overflow-y: auto;
  border: 0;
  border-radius: 12px;
  background: var(--ag-surface);
  color: var(--ag-text);
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
  resize: none;
}

.admin-body .crm-agent__input textarea:focus,
.admin-body .crm-agent__input textarea:focus-visible {
  outline: none;
  box-shadow: none;
}

.crm-agent__input textarea::placeholder {
  color: #94a4b6;
}

.crm-agent__plus,
.crm-agent__clear,
.crm-agent__record,
.crm-agent__send {
  display: inline-flex;
  width: 44px;
  height: 44px;
  min-width: 44px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition: background-color 0.14s, border-color 0.14s, color 0.14s, box-shadow 0.14s;
}

.crm-agent__plus {
  border-color: var(--ag-line);
  background: var(--ag-surface);
  color: var(--ag-text-2);
}

.crm-agent__plus:hover,
.crm-agent__plus[aria-expanded="true"] {
  background: var(--ag-surface-3);
}

.crm-agent__clear {
  position: absolute;
  top: 0;
  right: 0;
  background: transparent;
  color: #94a4b6;
}

.crm-agent__clear:hover {
  background: var(--ag-surface-3);
  color: var(--ag-text);
}

.crm-agent__record {
  background: var(--ag-night-3);
  color: #fff;
}

.crm-agent__record:hover {
  background: var(--ag-night-4);
}

.crm-agent__record[aria-pressed="true"] {
  background: var(--ag-coral);
  animation: crm-agent-ring 1.4s infinite;
}

.crm-agent__send {
  background: var(--ag-primary-grad);
  box-shadow: 0 6px 18px rgba(31, 99, 177, 0.32);
  color: #fff;
}

.crm-agent__send:hover {
  background: linear-gradient(135deg, #2a74c6 0%, #1b589e 50%, #154683 100%);
}

.crm-agent__send .crm-agent__stop-icon {
  display: none;
  fill: currentColor;
  stroke: none;
}

.crm-agent__send.is-stopping {
  background: var(--ag-coral);
  box-shadow: 0 6px 18px rgba(217, 80, 107, 0.32);
}

.crm-agent__send.is-stopping .crm-agent__send-icon {
  display: none;
}

.crm-agent__send.is-stopping .crm-agent__stop-icon {
  display: block;
}

.crm-agent__record:disabled,
.crm-agent__send:disabled {
  cursor: default;
  opacity: 0.55;
}

.crm-agent__menu {
  position: absolute;
  z-index: 20;
  bottom: calc(100% - 8px);
  left: 16px;
  display: flex;
  width: 290px;
  max-width: calc(100% - 32px);
  box-sizing: border-box;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  border: 1px solid var(--ag-line);
  border-radius: 14px;
  background: var(--ag-surface);
  box-shadow: 0 12px 32px rgba(8, 18, 34, 0.35);
}

.crm-agent__menu > button,
.crm-agent__menu > a {
  display: flex;
  width: 100%;
  min-height: 44px;
  box-sizing: border-box;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 0;
  border-radius: 9px;
  background: var(--ag-surface);
  color: var(--ag-text);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  text-align: left;
  text-decoration: none;
}

.crm-agent__menu > button:hover,
.crm-agent__menu > a:hover {
  background: var(--ag-surface-3);
}

.crm-agent__menu .admin-icon {
  width: 20px;
  height: 20px;
  color: var(--ag-text-muted);
}

/* Con el Preview cerrado, todo se centra en una columna cómoda de lectura. */
.crm-agent[data-canvas="closed"] .crm-agent__head,
.crm-agent[data-canvas="closed"] .crm-agent__console {
  padding-inline: max(20px, calc((100% - var(--ag-col)) / 2));
}

.crm-agent[data-canvas="closed"] .crm-agent__conversation {
  padding-inline: max(18px, calc((100% - var(--ag-col)) / 2));
}

.crm-agent[data-canvas="closed"] .crm-agent__menu {
  left: max(20px, calc((100% - var(--ag-col)) / 2));
}

/* ---------- Divisor ---------- */

.crm-agent__split {
  position: relative;
  width: 16px;
  min-width: 16px;
  background: transparent;
  cursor: col-resize;
  touch-action: none;
}

.crm-agent__split::after {
  content: "";
  position: absolute;
  top: calc(50% - 22px);
  left: 6px;
  width: 4px;
  height: 44px;
  border-radius: 4px;
  background: var(--ag-line-2);
  transition: background-color 0.14s;
}

.crm-agent__split:hover::after,
.crm-agent__split.is-dragging::after,
.crm-agent__split:focus-visible::after {
  background: var(--ag-primary);
}

.admin-body .crm-agent__split:focus-visible {
  box-shadow: none;
}

/* ---------- Preview ---------- */

.crm-agent__canvas {
  background: var(--ag-surface);
}

.crm-agent__canvas-head {
  display: flex;
  min-height: 70px;
  flex: 0 0 auto;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--ag-line);
  background: var(--ag-surface);
}

.crm-agent__canvas-head h2 {
  flex: 1;
  margin: 0 0 0 2px;
  color: var(--ag-text);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.025em;
}

.crm-agent__canvas-body {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  overflow-y: auto;
  padding: 18px 18px 48px;
  background: #f3f5f8;
  scrollbar-width: thin;
  scrollbar-color: var(--ag-line-2) transparent;
}

.crm-agent__canvas-empty {
  display: flex;
  max-width: 360px;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: auto;
  color: var(--ag-text-muted);
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
}

.crm-agent__canvas-empty-icon {
  display: grid;
  width: 64px;
  height: 64px;
  margin-bottom: 4px;
  place-items: center;
  border-radius: 22px;
  background: var(--ag-surface);
  box-shadow: 0 1px 2px rgba(15, 31, 51, 0.05), 0 2px 10px rgba(15, 31, 51, 0.05);
  color: var(--ag-primary-300);
}

.crm-agent__canvas-empty-icon .admin-icon {
  width: 26px;
  height: 26px;
}

.crm-agent__canvas-empty strong {
  color: var(--ag-text-2);
  font-size: 15px;
  font-weight: 700;
}

.crm-agent__canvas-empty p {
  margin: 0;
}

/* En escritorio el Preview se cierra con el botón de la cabecera del chat. */
#canvasCloseBtn {
  display: none;
}

/* ---------- Sugerencias del estado vacío ---------- */

.crm-agent__suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}

.crm-agent__suggestions button {
  min-height: 38px;
  padding: 6px 14px;
  border: 1px solid rgba(127, 178, 234, 0.35);
  border-radius: 999px;
  background: rgba(47, 127, 214, 0.14);
  color: #dbe9fb;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  transition: background-color 0.14s, border-color 0.14s;
}

.crm-agent__suggestions button:hover {
  border-color: rgba(127, 178, 234, 0.7);
  background: rgba(47, 127, 214, 0.28);
}

/* ---------- Fichas de vista dentro del chat (una línea; abren el Preview) ---------- */

.crm-msg__cards {
  display: grid;
  width: 100%;
  max-width: 560px;
  flex: 1 1 100%;
  gap: 8px;
  margin-top: 12px;
}

.crm-msg__text:empty + .crm-msg__cards {
  margin-top: 0;
}

.crm-msg__bubble:has(.crm-msg__cards) {
  min-width: min(100%, 340px);
}

.crm-card {
  position: relative;
  display: flex;
  width: 100%;
  min-height: 60px;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 9px 10px 9px 9px;
  overflow: hidden;
  border: 1px solid var(--ag-line);
  border-radius: 16px;
  background: #fff;
  color: var(--ag-text);
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: border-color 0.14s, background-color 0.14s, box-shadow 0.14s, transform 0.14s;
}

.crm-card:hover {
  border-color: var(--ag-primary-soft-2);
  box-shadow: 0 1px 2px rgba(15, 31, 51, 0.06);
}

.crm-card:active {
  transform: scale(0.99);
}

.crm-card.is-active {
  border-color: var(--ag-primary);
  background: var(--ag-primary-soft);
  box-shadow: 0 0 0 3px rgba(31, 99, 177, 0.12);
}

.crm-card__icon {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  border-radius: 12px;
  background: var(--ag-primary-soft);
  color: var(--ag-primary);
}

.crm-card.is-active .crm-card__icon {
  background: #fff;
}

.crm-card__icon .admin-icon {
  width: 20px;
  height: 20px;
}

.crm-card__copy {
  display: grid;
  min-width: 0;
  flex: 1 1 auto;
  gap: 2px;
}

.crm-card__title {
  overflow: hidden;
  color: var(--ag-text);
  font-size: 14px;
  font-weight: 750;
  letter-spacing: -0.01em;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-card__sub {
  overflow: hidden;
  color: var(--ag-text-muted);
  font-size: 13px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-card__go {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  place-items: center;
  color: var(--ag-text-muted);
  transition: color 0.14s, transform 0.14s;
}

.crm-card:hover .crm-card__go,
.crm-card.is-active .crm-card__go {
  color: var(--ag-primary);
  transform: translateX(2px);
}

/* ---------- Propuesta de acción: tarjeta de confirmación dentro del chat ---------- */

.crm-proposal {
  --pr-accent: #11766b;
  --pr-soft: #e2f3ef;
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--ag-line-2);
  border-radius: 16px;
  background: #fff;
  color: var(--ag-text);
}

.crm-proposal.is-warning {
  --pr-accent: #b7791f;
  --pr-soft: #fcf1dc;
}

.crm-proposal.is-danger {
  --pr-accent: #b7382f;
  --pr-soft: #fcebe9;
}

.crm-proposal__head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.crm-proposal__icon {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  border-radius: 12px;
  background: var(--pr-soft);
  color: var(--pr-accent);
}

.crm-proposal__icon .admin-icon {
  width: 20px;
  height: 20px;
}

.crm-proposal__titles {
  display: grid;
  min-width: 0;
  gap: 1px;
}

.crm-proposal__state {
  color: var(--pr-accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.crm-proposal__title {
  color: var(--ag-text);
  font-size: 15.5px;
  font-weight: 800;
  letter-spacing: -0.015em;
  line-height: 1.25;
}

.crm-proposal__subject {
  margin: 0;
  color: var(--ag-text);
  font-size: 14.5px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.crm-proposal__lines {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  color: var(--ag-text-2);
  font-size: 13.5px;
  line-height: 1.45;
  list-style: none;
}

.crm-proposal__note {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--ag-surface-2);
  color: var(--ag-text);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.crm-proposal__result {
  margin: 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: #fcebe9;
  color: #8f2a23;
  font-size: 13.5px;
  font-weight: 650;
  line-height: 1.45;
}

.crm-proposal__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.crm-proposal__confirm,
.crm-proposal__discard,
.crm-proposal__open {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 750;
  text-decoration: none;
  transition: background-color 0.14s, border-color 0.14s, opacity 0.14s;
}

.crm-proposal__confirm {
  background: var(--pr-accent);
  color: #fff;
}

.crm-proposal__confirm:hover {
  filter: brightness(0.92);
}

.crm-proposal__discard {
  border-color: var(--ag-line-2);
  background: #fff;
  color: var(--ag-text-2);
}

.crm-proposal__discard:hover {
  background: var(--ag-surface-3);
}

.crm-proposal__open {
  margin-left: auto;
  padding: 0 8px;
  color: var(--ag-primary);
}

.crm-proposal__open:hover {
  text-decoration: underline;
}

.crm-proposal__confirm:disabled,
.crm-proposal__discard:disabled {
  cursor: default;
  opacity: 0.6;
}

.crm-proposal.is-done {
  --pr-accent: #11766b;
  --pr-soft: #e2f3ef;
  background: #f4fbf9;
}

.crm-proposal.is-discarded,
.crm-proposal.is-closed {
  --pr-accent: #7d8fa5;
  --pr-soft: var(--ag-surface-3);
  background: var(--ag-surface-2);
}

.crm-proposal.is-discarded .crm-proposal__subject,
.crm-proposal.is-discarded .crm-proposal__lines,
.crm-proposal.is-discarded .crm-proposal__note {
  opacity: 0.6;
}

/* Resultado de una acción del Agente (misma tarjeta, sin botones). */
.crm-result.is-partial { --pr-accent: #b7791f; --pr-soft: #fcf1dc; background: #fffaf0; }
.crm-result__items { gap: 2px; }
.crm-result__items li { overflow-wrap: anywhere; }
.crm-result__items li::before { content: "· "; color: var(--pr-accent); font-weight: 800; }
.crm-result__more { color: var(--ag-text-muted); font-weight: 700; }
.crm-result .crm-proposal__open { margin-left: 0; padding: 0; min-height: 32px; }

/* Lo que hizo el gestor con una propuesta: línea de sistema, no una burbuja. */
.crm-agent__note-line {
  display: flex;
  justify-content: center;
  margin: 0 0 16px;
}

.crm-agent__note-line span {
  max-width: min(92%, 640px);
  padding: 6px 14px;
  border: 1px solid var(--ag-night-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ag-muted);
  font-size: 12.5px;
  line-height: 1.4;
  text-align: center;
}

/* ---------- Vistas del Preview ---------- */

.crm-agent__open {
  display: inline-flex;
  min-height: 38px;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  border: 1px solid var(--ag-line);
  border-radius: 999px;
  background: var(--ag-surface);
  color: var(--ag-text);
  font-size: 13.5px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.14s, border-color 0.14s;
}

.crm-agent__open:hover {
  border-color: var(--ag-primary-soft-2);
  background: var(--ag-primary-soft);
}

.crm-agent__open .admin-icon {
  width: 15px;
  height: 15px;
  color: var(--ag-primary);
}

.crm-view {
  display: grid;
  width: 100%;
  max-width: 980px;
  gap: 18px;
  margin: 0 auto;
  animation: crm-agent-fade-up 0.28s var(--ag-ease) both;
}

.crm-view__subtitle {
  margin: 0 2px -4px;
  color: var(--ag-text-muted);
  font-size: 14px;
}

.crm-view__block {
  display: grid;
  gap: 10px;
}

.crm-view__block-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 2px;
  color: var(--ag-text-2);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.crm-view__count {
  display: inline-grid;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  place-items: center;
  border-radius: 999px;
  background: var(--ag-surface-3);
  color: var(--ag-text-2);
  font-size: 12px;
  font-weight: 800;
}

.crm-view__stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
}

.crm-view__stat {
  display: grid;
  gap: 6px;
  padding: 14px 14px 12px;
  border: 1px solid var(--ag-line);
  border-radius: 16px;
  background: var(--ag-surface);
}

.crm-view__stat-label {
  color: var(--ag-text-muted);
  font-size: 12.5px;
  font-weight: 650;
  line-height: 1.3;
}

.crm-view__stat-value {
  color: var(--ag-text);
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.crm-view__stat.is-warning {
  border-color: #f0d9a4;
  background: #fdf6e6;
}

.crm-view__stat.is-warning .crm-view__stat-value {
  color: #8a5a0b;
}

.crm-view__stat.is-positive .crm-view__stat-value {
  color: #11766b;
}

.crm-view__list {
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--ag-line);
  border-radius: 16px;
  background: var(--ag-surface);
  list-style: none;
}

.crm-view__list li + li {
  border-top: 1px solid var(--ag-line);
}

.crm-view__row {
  display: flex;
  min-height: 60px;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 14px;
  color: inherit;
  text-decoration: none;
  transition: background-color 0.14s;
}

a.crm-view__row:hover {
  background: var(--ag-surface-2);
}

.crm-view__row-main {
  display: grid;
  min-width: 0;
  flex: 1 1 auto;
  gap: 3px;
}

.crm-view__row-head {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
}

.crm-view__row-title {
  min-width: 0;
  overflow: hidden;
  color: var(--ag-text);
  font-size: 14.5px;
  font-weight: 750;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-view__row-sub {
  overflow: hidden;
  color: var(--ag-text-muted);
  font-size: 13px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-view__row-meta {
  flex: 0 0 auto;
  color: var(--ag-text-muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.crm-view__row-go {
  display: grid;
  flex: 0 0 20px;
  place-items: center;
  color: #94a4b6;
  transition: color 0.14s, transform 0.14s;
}

.crm-view__row-go .admin-icon {
  width: 16px;
  height: 16px;
}

a.crm-view__row:hover .crm-view__row-go {
  color: var(--ag-primary);
  transform: translateX(2px);
}

.crm-view__badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--ag-surface-3);
  color: var(--ag-text-2);
  font-size: 11.5px;
  font-weight: 750;
  line-height: 1.5;
  white-space: nowrap;
}

.crm-view__badge.is-positive { background: #e2f3ef; color: #0d5f56; }
.crm-view__badge.is-warning { background: #fcf1dc; color: #7d5210; }
.crm-view__badge.is-danger { background: #fcebe9; color: #9c2f27; }
.crm-view__badge.is-info { background: var(--ag-primary-soft); color: #184f93; }

.crm-view__more,
.crm-view__note {
  margin: 0 2px;
  color: var(--ag-text-muted);
  font-size: 13.5px;
  line-height: 1.5;
}

.crm-view__note {
  padding: 16px;
  border: 1px dashed var(--ag-line-2);
  border-radius: 16px;
  background: var(--ag-surface);
  text-align: center;
}

@media (max-width: 560px) {
  .crm-view__row-meta {
    display: none;
  }

  .crm-agent__open span {
    display: none;
  }

  .crm-agent__open {
    width: 44px;
    min-height: 44px;
    justify-content: center;
    padding: 0;
  }
}

/* ---------- Animaciones ---------- */

@keyframes crm-agent-fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes crm-agent-mini-blink {
  0%, 95%, 100% { transform: scaleY(1); }
  97% { transform: scaleY(0.12); }
}

@keyframes crm-agent-typing {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

@keyframes crm-agent-pulse {
  50% { opacity: 0.35; }
}

@keyframes crm-agent-ring {
  0% { box-shadow: 0 0 0 0 rgba(217, 80, 107, 0.5); }
  70% { box-shadow: 0 0 0 10px rgba(217, 80, 107, 0); }
  100% { box-shadow: 0 0 0 0 rgba(217, 80, 107, 0); }
}

/* ---------- Pantallas estrechas ---------- */

@media (max-width: 900px) {
  .admin-main--dashboard {
    --ag-pad: 0px;
  }

  .crm-agent,
  .crm-agent[data-canvas="open"] {
    grid-template-columns: minmax(0, 1fr);
  }

  .crm-agent__chat {
    border: 0;
    border-radius: 0;
  }

  .crm-agent__split {
    display: none;
  }

  .crm-agent__head {
    min-height: 96px;
    gap: 12px;
    padding: 10px 14px;
  }

  .crm-agent[data-canvas="closed"] .crm-agent__head,
  .crm-agent[data-canvas="closed"] .crm-agent__console {
    padding-inline: 14px;
  }

  .crm-agent[data-canvas="closed"] .crm-agent__conversation {
    padding-inline: 14px;
  }

  .crm-agent[data-canvas="closed"] .crm-agent__menu {
    left: 14px;
  }

  .crm-agent__console {
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .crm-msg {
    max-width: 94%;
  }

  /* El Preview pasa a ser una hoja inferior. */
  .crm-agent[data-canvas="open"]::before {
    content: "";
    position: fixed;
    z-index: 46;
    inset: 0;
    background: rgba(8, 18, 34, 0.45);
  }

  .crm-agent[data-canvas="open"] .crm-agent__canvas {
    position: fixed;
    z-index: 47;
    right: 0;
    bottom: 0;
    left: 0;
    height: min(88dvh, 760px);
    border: 0;
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -24px 60px rgba(8, 18, 34, 0.35);
  }

  #canvasCloseBtn {
    display: inline-flex;
  }
}

@media (prefers-reduced-motion: reduce) {
  .crm-msg,
  .crm-msg__eyes i,
  .crm-msg__typing i,
  .crm-agent__status::before,
  .crm-agent__record[aria-pressed="true"] {
    animation: none;
  }
}
