/* ---------- Apartado "Agente IA" (todas las clases empiezan con ag-) ---------- */
.ag-kpis { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.ag-kpis .kpi:hover { text-decoration: none; }
.ag-rows .ag-row { border-bottom: 1px solid var(--border); }
.ag-rows .ag-row:last-child { border-bottom: 0; }

.ag-row { display: flex; gap: 10px; padding: 10px 14px; color: var(--text); align-items: flex-start; }
.ag-row:hover { background: var(--surface-2); text-decoration: none; }
.ag-row.active { background: var(--primary-soft); }
.ag-row-main { flex: 1; min-width: 0; }
.ag-row-top { display: flex; align-items: center; gap: 6px; }
.ag-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-ellipsis, .ag-prev { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.ag-row-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; min-width: 0; }
.ag-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.ag-tags:empty { display: none; }
.ag-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex: none; }
.pill.ag-paused { background: #eceff3; color: #3d4a5a; }

/* Bandeja: lista a la izquierda, chat a la derecha */
.ag-chats { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 12px; padding: 16px 20px; height: calc(100vh - 48px); max-width: 1600px; margin: 0 auto; }
.ag-side, .ag-detail { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.ag-side-head { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--border); }
.ag-side-list { flex: 1; overflow-y: auto; }
.ag-side-list .ag-row { border-bottom: 1px solid var(--border); }
.ag-side-foot { padding: 6px 12px; border-top: 1px solid var(--border); }
.ag-empty { margin: auto; }

.ag-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.ag-head-main { flex: 1; min-width: 0; }
.ag-head-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14.5px; }
.ag-back { display: none; }

.ag-switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-weight: 500; white-space: nowrap; }
.ag-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ag-slider { position: relative; width: 38px; height: 22px; border-radius: 11px; background: #b9c2cd; transition: background .15s; flex: none; }
.ag-slider::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.ag-switch input:checked + .ag-slider { background: var(--success); }
.ag-switch input:checked + .ag-slider::after { transform: translateX(16px); }
.ag-switch input:focus-visible + .ag-slider { box-shadow: 0 0 0 3px rgba(11, 107, 222, .3); }
.ag-switch input:disabled + .ag-slider { opacity: .6; }

.ag-pause-box { margin: 8px 14px 0; padding: 8px 12px; border-radius: var(--radius); background: var(--warning-soft); color: #6d4300; font-size: 12.5px; }

.ag-msgs { flex: 1; overflow-y: auto; padding: 14px; background: #f0f2f5; display: flex; flex-direction: column; gap: 6px; }
.ag-day { text-align: center; margin: 6px 0; }
.ag-day span { background: #e1e5eb; color: #4a5565; font-size: 11.5px; padding: 2px 10px; border-radius: 10px; }
.ag-msg { display: flex; }
.ag-msg.bot, .ag-msg.humano { justify-content: flex-end; }
.ag-bubble { max-width: min(78%, 620px); padding: 6px 10px 4px; border-radius: 10px; background: #fff; box-shadow: 0 1px .5px rgba(16, 24, 40, .12); }
.ag-msg.entrante .ag-bubble { border-top-left-radius: 2px; }
.ag-msg.bot .ag-bubble { background: #dcf3e4; border-top-right-radius: 2px; }
.ag-msg.humano .ag-bubble { background: #dbe9fb; border-top-right-radius: 2px; }
.ag-who { font-size: 11.5px; font-weight: 600; margin-bottom: 1px; }
.ag-msg.bot .ag-who { color: var(--success); }
.ag-msg.humano .ag-who { color: var(--primary); }
.ag-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.4; }
.ag-meta { display: flex; justify-content: flex-end; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 2px; }
.ag-st-read { color: var(--primary); }
.ag-st-wait { font-style: italic; }
.ag-st-fail { color: var(--danger); font-weight: 600; }
.ag-err { font-size: 11.5px; color: var(--danger); margin-top: 3px; }

.ag-compose { display: grid; grid-template-columns: 1fr auto; gap: 6px 8px; padding: 10px 14px; border-top: 1px solid var(--border); align-items: end; }
.ag-compose textarea { min-height: 42px; max-height: 160px; resize: vertical; }
.ag-compose .btn { height: 42px; }
.ag-hint { grid-column: 1 / -1; }
.ag-closed { grid-column: 1 / -1; color: var(--muted); font-size: 12.5px; padding: 4px 0; }

@media (max-width: 800px) {
  .ag-chats { grid-template-columns: 1fr; padding: 10px 12px; height: calc(100vh - 48px); }
  .ag-chats.has-detail .ag-side { display: none; }
  .ag-chats:not(.has-detail) .ag-detail { display: none; }
  .ag-back { display: inline-flex; }
  .ag-head { flex-wrap: wrap; }
  .ag-switch span:last-child { font-size: 12.5px; }
  .ag-bubble { max-width: 88%; }
}
