/* Agentes de WhatsApp · administración. Todo está bajo .ag para no chocar con los estilos del dashboard que lo incruste. */
.ag {
  --bg: #F5F6F4; --surface: #FFFFFF; --surface-2: #F0F2EF; --ink: #15201C; --muted: #66706B; --line: #E2E6E3;
  --accent: #0F7A63; --accent-ink: #FFFFFF; --accent-soft: #E1F3EC; --warn: #B45309; --warn-soft: #FEF3C7;
  --bad: #B42318; --bad-soft: #FDE8E7; --info: #2457C5; --info-soft: #E6EEFC;
  --bubble-in: #FFFFFF; --bubble-out: #DDF3E6; --bubble-asesor: #E6EEFC; --chat-bg: #EFEAE2;
  --radius: 12px; --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 1px 1px rgba(16, 24, 20, .04);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg); min-height: 100%;
}
@media (prefers-color-scheme: dark) {
  .ag:not([data-theme="light"]) {
    --bg: #0F1412; --surface: #161D1A; --surface-2: #1C2521; --ink: #E7ECE9; --muted: #95A19B; --line: #26302C;
    --accent: #34B48F; --accent-ink: #06130E; --accent-soft: #15362C; --warn: #F2B35B; --warn-soft: #3A2C12;
    --bad: #F2867D; --bad-soft: #3B1A18; --info: #8DB0F5; --info-soft: #1A2742;
    --bubble-in: #1F2925; --bubble-out: #19443A; --bubble-asesor: #1D2B48; --chat-bg: #111815;
  }
}
.ag[data-theme="dark"] {
  --bg: #0F1412; --surface: #161D1A; --surface-2: #1C2521; --ink: #E7ECE9; --muted: #95A19B; --line: #26302C;
  --accent: #34B48F; --accent-ink: #06130E; --accent-soft: #15362C; --warn: #F2B35B; --warn-soft: #3A2C12;
  --bad: #F2867D; --bad-soft: #3B1A18; --info: #8DB0F5; --info-soft: #1A2742;
  --bubble-in: #1F2925; --bubble-out: #19443A; --bubble-asesor: #1D2B48; --chat-bg: #111815;
}
.ag *, .ag *::before, .ag *::after { box-sizing: border-box; }
.ag button, .ag input, .ag select, .ag textarea { font: inherit; color: inherit; }
.ag h1, .ag h2, .ag h3, .ag h4, .ag p { margin: 0; }
.ag a { color: var(--accent); }
.ag code, .ag pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* ---------- Encabezado y pestañas ---------- */
.ag-top { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ag-brand { display: flex; align-items: center; gap: 10px; }
.ag-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; }
.ag-brand b { font-size: 15px; display: block; }
.ag-brand small { color: var(--muted); }
.ag-top .ag-sp { flex: 1; }
.ag-tabs { display: flex; gap: 2px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.ag-tabs button { border: 0; background: none; padding: 12px 12px; color: var(--muted); font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.ag-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.ag-tabs button:hover { color: var(--ink); }
.ag-main { padding: 20px 24px 40px; max-width: 1440px; margin: 0 auto; }

/* ---------- Piezas ---------- */
.ag-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.ag-card > header { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.ag-card > header h3 { font-size: 14px; font-weight: 600; }
.ag-card > header p { color: var(--muted); font-size: 13px; }
.ag-card > header .ag-sp { flex: 1; }
.ag-card > .ag-body { padding: 16px; }
.ag-grid { display: grid; gap: 16px; }
.ag-g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ag-g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ag-g-side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.ag-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ag-sp { flex: 1; }
.ag-muted { color: var(--muted); }
.ag-small { font-size: 12.5px; }
.ag-title { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.ag-title h2 { font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
.ag-title p { color: var(--muted); }

.ag-btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap; }
.ag-btn:hover { background: var(--surface-2); }
.ag-btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.ag-btn.primary:hover { filter: brightness(1.05); }
.ag-btn.ghost { border-color: transparent; background: none; }
.ag-btn.danger { color: var(--bad); }
.ag-btn.sm { height: 28px; padding: 0 10px; font-size: 13px; border-radius: 7px; }
.ag-btn:disabled { opacity: .5; cursor: not-allowed; }

.ag-pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 550; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.ag-pill.ok { background: var(--accent-soft); color: var(--accent); }
.ag-pill.warn { background: var(--warn-soft); color: var(--warn); }
.ag-pill.bad { background: var(--bad-soft); color: var(--bad); }
.ag-pill.info { background: var(--info-soft); color: var(--info); }
.ag-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }
.ag-count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--warn); color: #fff; font-size: 11.5px; font-weight: 600; display: inline-grid; place-items: center; }

.ag-seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.ag-seg button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; display: inline-flex; gap: 6px; align-items: center; }
.ag-seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.ag-field { display: grid; gap: 5px; }
.ag-field > span { font-size: 12.5px; font-weight: 550; color: var(--muted); }
.ag-field small { color: var(--muted); font-size: 12px; }
.ag-input, .ag-field input, .ag-field select, .ag-field textarea { width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); outline: none; }
.ag-field textarea { height: auto; min-height: 84px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
.ag-input:focus, .ag-field input:focus, .ag-field select:focus, .ag-field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ag-form { display: grid; gap: 14px; }
.ag-form .ag-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ag-form .ag-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

.ag-switch { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.ag-switch input { appearance: none; width: 34px; height: 20px; border-radius: 999px; background: var(--line); position: relative; flex: none; margin: 1px 0 0; cursor: pointer; transition: background .15s; }
.ag-switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.ag-switch input:checked { background: var(--accent); }
.ag-switch input:checked::after { transform: translateX(14px); }
.ag-switch b { display: block; font-weight: 550; }
.ag-switch small { color: var(--muted); }
.ag-checks { display: flex; flex-wrap: wrap; gap: 6px; }
.ag-checks label { display: inline-flex; gap: 6px; align-items: center; padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-size: 13px; }
.ag-checks label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.ag-checks input { accent-color: var(--accent); margin: 0; }

.ag-table { width: 100%; border-collapse: collapse; }
.ag-table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.ag-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.ag-table tr:last-child td { border-bottom: 0; }
.ag-table .ag-input { height: 30px; font-size: 13px; }
.ag-scroll { overflow-x: auto; }

.ag-empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.ag-note { padding: 10px 12px; border-radius: 9px; background: var(--surface-2); color: var(--muted); font-size: 13px; }
.ag-note.warn { background: var(--warn-soft); color: var(--warn); }
.ag-note.info { background: var(--info-soft); color: var(--info); }
.ag-note.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- Resumen ---------- */
.ag-kpis { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.ag-kpi { padding: 14px 16px; }
.ag-kpi span { color: var(--muted); font-size: 12.5px; font-weight: 550; }
.ag-kpi b { display: block; font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.ag-kpi small { font-size: 12px; color: var(--muted); }
.ag-kpi small.up { color: var(--accent); }
.ag-kpi small.down { color: var(--bad); }
.ag-chart { position: relative; height: 260px; }
.ag-bars { display: grid; gap: 10px; }
.ag-bar { display: grid; grid-template-columns: 140px 1fr 44px; gap: 10px; align-items: center; font-size: 13px; }
.ag-bar i { display: block; height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.ag-bar i em { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.ag-bar b { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.ag-funnel .ag-bar { grid-template-columns: 150px 1fr 90px; }
.ag-health { display: grid; gap: 8px; }
.ag-health div { display: flex; align-items: center; gap: 8px; font-size: 13px; }

/* ---------- Conversaciones ---------- */
.ag-inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr) 300px; height: calc(100vh - 180px); min-height: 560px; overflow: hidden; }
.ag-list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.ag-list-h { padding: 12px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.ag-filters { display: flex; gap: 4px; flex-wrap: wrap; }
.ag-filters button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 10px; font-size: 12.5px; cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }
.ag-filters button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.ag-filters button em { font-style: normal; opacity: .7; }
.ag-items { overflow-y: auto; flex: 1; }
.ag-item { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; gap: 10px; padding: 11px 12px; border: 0; border-bottom: 1px solid var(--line); background: none; width: 100%; text-align: left; cursor: pointer; }
.ag-item:hover { background: var(--surface-2); }
.ag-item[aria-current="true"] { background: var(--accent-soft); }
.ag-av { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 13px; color: #fff; }
.ag-item b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.ag-item p { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-item aside { display: grid; justify-items: end; gap: 4px; font-size: 11.5px; color: var(--muted); }

.ag-chat { display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); }
.ag-chat-h { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--line); }
.ag-chat-h b { display: block; }
.ag-msgs { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.ag-msg { max-width: min(520px, 78%); padding: 7px 10px 5px; border-radius: 10px; background: var(--bubble-in); box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word; align-self: flex-start; }
.ag-msg.out { align-self: flex-end; background: var(--bubble-out); }
.ag-msg.asesor { background: var(--bubble-asesor); }
.ag-msg .who { font-size: 11.5px; font-weight: 600; color: var(--accent); display: block; margin-bottom: 2px; }
.ag-msg.asesor .who { color: var(--info); }
.ag-msg img { display: block; width: 100%; max-width: 300px; aspect-ratio: 4/3; object-fit: cover; border-radius: 7px; margin: 2px 0 6px; background: var(--surface-2); }
.ag-msg time { display: block; text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; }
.ag-msg.fallido { outline: 1px solid var(--bad); }
.ag-sys { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface); padding: 3px 10px; border-radius: 8px; box-shadow: var(--shadow); max-width: 80%; text-align: center; }
.ag-sys.warn { color: var(--warn); }
.ag-day { align-self: center; font-size: 11.5px; color: var(--muted); background: var(--surface); padding: 2px 10px; border-radius: 8px; margin: 6px 0; }
.ag-compose { padding: 10px 12px; background: var(--surface); border-top: 1px solid var(--line); display: grid; gap: 8px; }
.ag-compose form { display: flex; gap: 8px; align-items: flex-end; }
.ag-compose textarea { flex: 1; min-height: 38px; max-height: 140px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); resize: none; outline: none; }
.ag-side { border-left: 1px solid var(--line); overflow-y: auto; padding: 14px; display: grid; gap: 14px; align-content: start; background: var(--surface); }
.ag-side h4 { font-size: 12px; text-transform: none; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.ag-kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: 13px; }
.ag-kv dt { color: var(--muted); }
.ag-kv dd { margin: 0; font-weight: 500; word-break: break-word; }
.ag-timeline { display: grid; gap: 8px; font-size: 12.5px; }
.ag-timeline div { display: grid; grid-template-columns: 8px 1fr; gap: 8px; }
.ag-timeline div::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line); margin-top: 5px; }
.ag-timeline div.ok::before { background: var(--accent); }
.ag-timeline div.warn::before { background: var(--warn); }
.ag-timeline div.bad::before { background: var(--bad); }
.ag-timeline small { color: var(--muted); display: block; }

/* ---------- Mapeo ---------- */
.ag-res { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.ag-res > header { display: flex; gap: 8px; align-items: center; padding: 8px 10px; background: var(--surface-2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ag-res pre { margin: 0; padding: 12px; max-height: 360px; overflow: auto; background: var(--surface); white-space: pre-wrap; word-break: break-word; }
.ag-map td:first-child { width: 170px; }
.ag-map td:nth-child(2) { width: 42%; }
.ag-map code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; }
.ag-req { color: var(--bad); font-weight: 700; }
.ag-ops { display: grid; gap: 10px; }
.ag-op { display: grid; grid-template-columns: 130px 90px minmax(0, 2fr) minmax(0, 1fr); gap: 8px; align-items: center; }
.ag-op > b { font-size: 13px; font-weight: 600; }
.ag-kvlist { display: grid; gap: 6px; }
.ag-kvlist > div { display: grid; grid-template-columns: 140px 1fr; gap: 8px; align-items: center; }
.ag-acc > summary { list-style: none; cursor: pointer; }
.ag-acc > summary::-webkit-details-marker { display: none; }
.ag-acc > summary::after { content: "▾"; color: var(--muted); margin-left: 6px; }
.ag-acc:not([open]) > summary::after { content: "▸"; }
.ag-acc:not([open]) > summary { border-bottom: 0; }

/* ---------- Simulador ---------- */
.ag-sim { display: grid; grid-template-columns: 400px minmax(0, 1fr); gap: 16px; align-items: start; }
.ag-phone { border-radius: 28px; border: 8px solid var(--ink); overflow: hidden; height: 680px; display: flex; flex-direction: column; background: var(--chat-bg); }
.ag-phone .ag-chat-h { background: #075E54; color: #fff; border: 0; }
.ag-phone .ag-chat-h small { color: rgba(255,255,255,.75); }
.ag-phone .ag-msg.in { align-self: flex-end; background: var(--bubble-out); }
.ag-phone .ag-msg.outb { align-self: flex-start; background: var(--bubble-in); }
.ag-log { display: grid; gap: 8px; max-height: 600px; overflow-y: auto; }
.ag-log article { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--surface); font-size: 13px; }
.ag-log article header { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.ag-log pre { margin: 6px 0 0; background: var(--surface-2); padding: 8px; border-radius: 7px; overflow-x: auto; max-height: 200px; }

.ag-toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-size: 13.5px; z-index: 9999; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: calc(100vw - 32px); }
.ag-toast.bad { background: var(--bad); color: #fff; }
.ag-login { max-width: 420px; margin: 10vh auto; padding: 28px; display: grid; gap: 14px; }
.ag-loading { padding: 60px; text-align: center; color: var(--muted); }
.ag-copy { display: flex; gap: 6px; }
.ag-copy input { font-family: ui-monospace, monospace; font-size: 12.5px; }

/* ---------- Pantallas chicas ---------- */
@media (max-width: 1180px) {
  .ag-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .ag-inbox { grid-template-columns: 280px minmax(0, 1fr); }
  .ag-inbox .ag-side { display: none; }
  .ag-sim { grid-template-columns: 1fr; }
  .ag-phone { max-width: 420px; }
  .ag-op { grid-template-columns: 1fr 90px; }
}
@media (max-width: 820px) {
  .ag-main { padding: 16px; }
  .ag-top { padding: 12px 16px; }
  .ag-g2, .ag-g3, .ag-g-side, .ag-form .ag-2, .ag-form .ag-3 { grid-template-columns: 1fr; }
  .ag-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ag-inbox { grid-template-columns: minmax(0, 1fr); height: auto; }
  .ag-chat-h { flex-wrap: wrap; }
  .ag-chat-h .ag-sp { flex-basis: 100%; height: 0; }
  .ag-inbox.abierta .ag-list { display: none; }
  .ag-inbox:not(.abierta) .ag-chat { display: none; }
  .ag-chat { height: 75vh; }
  .ag-bar { grid-template-columns: 100px 1fr 40px; }
  .ag-funnel .ag-bar { grid-template-columns: 110px 1fr 70px; }
  .ag-kvlist > div { grid-template-columns: 1fr; }
}

/* ---------- Agentes ---------- */
.ag-agchip { --c: #0F7A63; display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px 2px 2px; border-radius: 999px; font-size: 12px; font-weight: 550; background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); white-space: nowrap; }
.ag-agchip i { width: 16px; height: 16px; border-radius: 50%; background: var(--c); color: #fff; font-style: normal; font-size: 10px; display: grid; place-items: center; }
@media (prefers-color-scheme: dark) { .ag:not([data-theme="light"]) .ag-agchip { color: color-mix(in srgb, var(--c) 55%, #fff); } }
.ag[data-theme="dark"] .ag-agchip { color: color-mix(in srgb, var(--c) 55%, #fff); }
.ag-g-agentes { grid-template-columns: 340px minmax(0, 1fr); align-items: start; }
.ag-agentes { display: grid; gap: 10px; position: sticky; top: 12px; }
.ag-agcard { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 12px; padding: 14px; text-align: left; cursor: pointer; width: 100%; }
.ag-agcard:hover { border-color: var(--muted); }
.ag-agcard[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ag-agcard .ag-av { width: 40px; height: 40px; }
.ag-agcard b { display: block; font-size: 15px; }
.ag-agcard small { color: var(--muted); }
.ag-agcard aside { display: grid; justify-items: end; align-content: start; }
.ag-agcard aside b { font-size: 18px; font-variant-numeric: tabular-nums; }
.ag-card > header .ag-av { width: 34px; height: 34px; flex: none; }
@media (max-width: 1180px) { .ag-g-agentes { grid-template-columns: 1fr; } .ag-agentes { position: static; } }
.ag-field .ag-checks input { width: auto; height: auto; padding: 0; box-shadow: none; }
.ag-field .ag-switch input { width: 34px; height: 20px; padding: 0; }
.ag-agcard .ag-pill { white-space: normal; text-align: left; }
