/* Aztrobits Connecta · panel.
   Idea: una central de atención. Cada conversación es una línea con una luz:
   ámbar = el cliente espera a tu equipo, violeta = atiende el asistente, turquesa = atiende un asesor.
   La luz ámbar es lo único que se mueve. */

/* Colores y tipografía de la guía de marca (BRAND.md · aztrobits-connecta-brand/colores.json).
   El ámbar no es de la marca: es la señal funcional de "cliente esperando". */
@font-face {
  font-family: "Sora";
  src: url("fonts/Sora-Variable.ttf") format("truetype");
  font-weight: 100 800;
  font-display: swap;
}
:root {
  --az-night: #08061a; --az-violet: #6c4dff; --az-lilac: #8b73ff; --az-teal: #2ee6d3; --az-teal-dark: #13b3a3;
  --az-fog: #b7b0da; --az-ink: #4a4466; --az-paper: #f6f5fb;
  --az-gradient: linear-gradient(90deg, var(--az-violet), var(--az-teal));
  --ink: var(--az-night);
  --ink-soft: var(--az-ink);
  --ink-faint: #8a84a8;
  --paper: var(--az-paper);
  --surface: #ffffff;
  --sunk: #ecebf6;
  --line: #e0ddee;
  --bot: var(--az-violet);
  --bot-tint: #eeeaff;
  --human: var(--az-teal-dark);
  --human-ink: #0b7f74;
  --human-tint: #e0f6f3;
  --wait: #e8a317;
  --wait-tint: #fdf2d6;
  --wait-ink: #7a5300;
  --danger: #c2372e;
  --focus: var(--az-violet);
  --rail: var(--az-night);
  --rail-ink: var(--az-fog);
  --rail-active: #1b1640;
  --display: "Sora", ui-sans-serif, system-ui, sans-serif;
  --text: "Sora", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f1eefc; --ink-soft: var(--az-fog); --ink-faint: #7e77a3;
    --paper: var(--az-night); --surface: #110d29; --sunk: #1b1638; --line: #2a2350;
    --bot: var(--az-lilac); --bot-tint: #231a52; --human: var(--az-teal); --human-ink: var(--az-teal); --human-tint: #0d2c31;
    --wait: #f2b632; --wait-tint: #3a2c0e; --wait-ink: #ffd88a; --danger: #ff7a70; --focus: var(--az-lilac);
    --rail: #050411; --rail-ink: var(--az-fog); --rail-active: #1b1638;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #f1eefc; --ink-soft: var(--az-fog); --ink-faint: #7e77a3;
  --paper: var(--az-night); --surface: #110d29; --sunk: #1b1638; --line: #2a2350;
  --bot: var(--az-lilac); --bot-tint: #231a52; --human: var(--az-teal); --human-ink: var(--az-teal); --human-tint: #0d2c31;
  --wait: #f2b632; --wait-tint: #3a2c0e; --wait-ink: #ffd88a; --danger: #ff7a70; --focus: var(--az-lilac);
  --rail: #050411; --rail-ink: var(--az-fog); --rail-active: #1b1638;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 14.5px/1.55 var(--text); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: -0.025em; margin: 0; line-height: 1.15; }
h1 { font-size: 26px; }
h2 { font-size: 18px; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Controles ---------- */
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--az-violet); color: #fff; border-radius: 10px; padding: 9px 18px; font-weight: 600; }
.primary:hover { background: #5a3cf0; }
.ghost { border: 1.5px solid var(--line); border-radius: 10px; padding: 7px 14px; font-weight: 600; background: var(--surface); }
.ghost:hover { border-color: var(--ink-faint); }
.link { color: var(--bot); padding: 0; font-weight: 600; }
.link:hover { text-decoration: underline; }
input, select, textarea {
  width: 100%; font: inherit; font-weight: 400; color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 11px;
}
input:focus, select:focus, textarea:focus { border-color: var(--bot); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--bot) 20%, transparent); }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 14px; }
label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 400; }
label.check input { width: 18px; height: 18px; }
.hint { color: var(--ink-soft); font-size: 13.5px; font-weight: 400; margin: 0; }
.status { color: var(--ink-soft); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 0; }

/* ---------- Luces ---------- */
.lamp { width: 11px; height: 11px; border-radius: 50%; flex: none; display: inline-block; background: var(--ink-faint); }
.lamp.bot { background: var(--bot); }
.lamp.human { background: var(--human); }
.lamp.wait { background: var(--wait); box-shadow: 0 0 0 0 color-mix(in srgb, var(--wait) 55%, transparent); animation: glow 1.8s ease-out infinite; }
.lamp.big { width: 18px; height: 18px; }
@keyframes glow { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--wait) 55%, transparent); } 100% { box-shadow: 0 0 0 9px transparent; } }
@media (prefers-reduced-motion: reduce) { .lamp.wait { animation: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--wait) 35%, transparent); } }

/* ---------- Entrada ----------
   La órbita del logo, en grande: cada negocio es un satélite con su luz de estado.
   Es el único momento con movimiento propio: la órbita se dibuja una vez al cargar. */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); background: var(--paper); }
.login-story {
  position: relative; overflow: hidden; color: #fff; display: flex; flex-direction: column; gap: 14px;
  padding: 40px clamp(28px, 5vw, 80px) 52px;
  background: radial-gradient(60rem 36rem at 30% 38%, #1a1446 0%, transparent 62%), var(--az-night);
}
.login-story .logo { width: 188px; height: auto; display: block; }
.orbit { position: relative; margin: 18px 0 10px; width: min(100%, 580px); aspect-ratio: 520 / 360; }
.orbit-art { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.orbit-ring { fill: none; stroke: url(#orbitStroke); stroke-width: 2.4; stroke-dasharray: 1; stroke-dashoffset: 1; animation: orbit-draw 1.6s cubic-bezier(.6, .05, .2, 1) .1s forwards; }
.orbit-ghost { fill: none; stroke: #2a2350; stroke-width: 1; stroke-dasharray: 2 7; }
.orbit-hub { position: absolute; left: 50%; top: 52.8%; width: 17%; height: auto; translate: -50% -50%; }
.orbit-node {
  position: absolute; display: grid; grid-template-columns: auto auto; column-gap: 9px; align-items: center; white-space: nowrap;
  padding: 7px 13px 8px 11px; border: 1px solid #2c2560; border-radius: 12px; background: rgba(8, 6, 26, .86);
  font-size: 13px; line-height: 1.35; opacity: 0; animation: node-in .45s ease-out forwards;
}
.orbit-node b { font-weight: 600; }
.orbit-node em { grid-column: 2; font-style: normal; color: var(--az-fog); font-size: 12px; }
.orbit-node .lamp { width: 9px; height: 9px; grid-row: span 2; }
.orbit-node .lamp.bot { background: var(--az-lilac); }
.orbit-node .lamp.human { background: var(--az-teal); }
.orbit-node.n1 { left: 8.5%; top: 41%; translate: -18% -50%; animation-delay: .9s; }
.orbit-node.n2 { left: 72%; top: 24%; translate: -50% -50%; animation-delay: 1.05s; }
.orbit-node.n3 { left: 91.5%; top: 64%; translate: -82% -50%; animation-delay: 1.2s; }
.orbit-node.n4 { left: 35%; top: 84%; translate: -50% -50%; animation-delay: 1.35s; }
@keyframes orbit-draw { to { stroke-dashoffset: 0; } }
@keyframes node-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .orbit-ring { animation: none; stroke-dashoffset: 0; } .orbit-node { animation: none; opacity: 1; } }
.login-story h1 { font-size: clamp(34px, 3.7vw, 54px); font-weight: 700; letter-spacing: -0.038em; line-height: 1.04; max-width: 15ch; }
.login-story .lede { color: var(--az-fog); font-size: 17px; max-width: 44ch; margin: 0; }
.login-form { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px; padding: 32px 20px; }
.login-form form { width: min(360px, 100%); display: flex; flex-direction: column; gap: 16px; }
.login-form h2 { font-size: 28px; letter-spacing: -0.03em; margin-bottom: 4px; }
.login-form .primary { padding: 12px; font-size: 16px; }
.login-legal { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 18px; margin: 0; font-size: 13px; }
.login-legal a, .legal-links a { color: var(--ink-soft); }
.login-legal a:hover, .legal-links a:hover { color: var(--ink); }
.brand { margin: 0; }
.brand img { display: block; height: auto; }

/* ---------- Estructura ---------- */
/* Menú lateral: siempre en la noche de la marca, también con tema claro. Dos grupos con nombre
   (lo que hace el equipo a diario y la configuración) y abajo quién eres y las herramientas. */
#app { display: grid; grid-template-columns: 252px minmax(0, 1fr); height: 100vh; }
.rail {
  background: var(--rail); color: var(--rail-ink); display: flex; flex-direction: column; gap: 14px;
  padding: 20px 12px 12px; min-height: 0; overflow-y: auto; border-right: 1px solid #1c1740; scrollbar-width: thin;
}
.rail .brand { padding: 2px 12px 6px; }
.rail .brand img { width: 158px; }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-group { margin: 16px 12px 6px; font-size: 12.5px; font-weight: 600; color: #7d77a8; }
.nav-group:first-child { margin-top: 2px; }
.nav button, .rail-btn {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px; border-radius: 10px;
  color: var(--rail-ink); text-align: left; font-weight: 500; position: relative;
}
.nav button svg { color: #7d77a8; }
.nav button:hover, .rail-btn:hover { background: #141036; color: #fff; }
.nav button:hover svg { color: var(--rail-ink); }
.nav button.active { background: #1c1750; color: #fff; }
.nav button.active svg { color: var(--az-teal); }
/* El satélite: un punto turquesa en el borde, como los nodos de la órbita del logo. */
.nav button.active::before {
  content: ""; position: absolute; left: -12px; top: 50%; width: 8px; height: 8px; border-radius: 50%;
  translate: 0 -50%; background: var(--az-teal); box-shadow: 0 0 0 4px rgba(46, 230, 211, .16);
}
.nav button span:first-of-type { flex: 1; }
.count { background: var(--wait); color: #2b1d00; font-weight: 600; font-size: 12.5px; min-width: 22px; height: 22px; border-radius: 11px; display: grid; place-items: center; padding: 0 6px; }
.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid #1c1740; }
.who { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 6px 10px; margin: 0; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff;
  background: linear-gradient(var(--rail), var(--rail)) padding-box, var(--az-gradient) border-box; border: 2px solid transparent;
}
.who-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.who-text b { color: #fff; font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-text small { color: #8a84b3; font-size: 12px; }
.live { width: 8px; height: 8px; border-radius: 50%; background: #4b4675; flex: none; }
.live.on { background: var(--az-teal); }
.rail-tools { display: flex; flex-direction: column; gap: 1px; }
.rail-tools .rail-btn { padding: 8px 12px; font-size: 13.5px; }
.rail-tools .rail-btn svg { width: 18px; height: 18px; color: #7d77a8; }
a.rail-btn { text-decoration: none; }
.rail-btn[aria-pressed="true"] { color: #fff; }
.rail-btn[aria-pressed="true"] svg { color: var(--wait); }
.work { min-width: 0; min-height: 0; overflow: hidden; }
.tab { height: 100%; }
.page { overflow: auto; padding: 28px clamp(16px, 3vw, 40px) 40px; display: flex; flex-direction: column; gap: 20px; }
.page > * { max-width: 1180px; width: 100%; flex-shrink: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.intro { color: var(--ink-soft); max-width: 68ch; margin: 0; font-size: 16px; }

/* ---------- Bandeja ---------- */
.inbox { display: grid; grid-template-columns: 340px minmax(0, 1fr); }
.lines { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.lines-head { padding: 20px 16px 14px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line); }
.lines-head h1 { margin-bottom: 4px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--sunk); border-radius: 10px; padding: 3px; }
.seg label { display: block; font-weight: 600; font-size: 13.5px; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: block; text-align: center; padding: 6px 4px; border-radius: 8px; color: var(--ink-soft); cursor: pointer; }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px color-mix(in srgb, var(--ink) 18%, transparent); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); }
.filters-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.line-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.line-list li { display: grid; grid-template-columns: 11px minmax(0, 1fr) auto; column-gap: 12px; row-gap: 2px; align-items: baseline; padding: 13px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.line-list li:hover { background: var(--paper); }
.line-list li.sel { background: var(--bot-tint); }
.line-list li.waiting { background: color-mix(in srgb, var(--wait-tint) 60%, var(--surface)); }
.line-list li.waiting.sel { background: var(--wait-tint); }
.line-list .lamp { align-self: center; grid-row: 1; }
.line-list .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-list time { color: var(--ink-faint); font-size: 12.5px; }
.line-list .snippet { grid-column: 2 / 4; color: var(--ink-soft); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-list .snippet b { color: var(--ink); font-weight: 600; }
.line-list .meta { grid-column: 2 / 4; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 4px; font-size: 12.5px; color: var(--ink-soft); }
.line-list .empty-list { display: block; cursor: default; color: var(--ink-soft); padding: 28px 16px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--sunk); color: var(--ink-soft); font-size: 12.5px; font-weight: 600; }
.who-chip { color: var(--human-ink); font-weight: 600; }

.conv { display: grid; grid-template-columns: minmax(0, 1fr) 300px; min-height: 0; height: 100%; }
.conv.empty { display: grid; grid-template-columns: 1fr; place-items: center; }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; color: var(--ink-soft); max-width: 34ch; }
.conv-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.conv-head { display: flex; align-items: center; gap: 14px; padding: 14px 22px; border-bottom: 1px solid var(--line); background: var(--surface); }
.conv-head .back { display: none; padding: 6px; border-radius: 8px; }
.conv-head .title { flex: 1; min-width: 0; }
.conv-head h2 { font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.state { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: 14px; }
.conv-head .buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.handoff { margin: 0; padding: 11px 22px; background: var(--wait-tint); color: var(--wait-ink); border-bottom: 1px solid var(--line); font-size: 14.5px; }
.handoff b { font-weight: 600; }

.messages { flex: 1; overflow: auto; padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: min(76%, 62ch); padding: 9px 13px 7px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.msg .by { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 2px; }
.msg time { display: block; font-size: 12px; color: var(--ink-faint); margin-top: 3px; text-align: right; }
.msg.customer { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.bot { align-self: flex-end; background: var(--bot-tint); border-bottom-right-radius: 4px; }
.msg.bot .by { color: var(--bot); }
.msg.human { align-self: flex-end; background: var(--human-tint); border-bottom-right-radius: 4px; }
.msg.human .by { color: var(--human-ink); }
.msg.system { align-self: center; background: none; border: 1.5px dashed var(--line); color: var(--ink-soft); font-size: 14px; max-width: 90%; }
.placeholder { color: var(--ink-soft); margin: auto; text-align: center; max-width: 40ch; }

.composer { border-top: 1px solid var(--line); background: var(--surface); padding: 12px 22px 14px; display: flex; flex-direction: column; gap: 8px; }
.composer textarea { min-height: 56px; }
.composer-actions { display: flex; align-items: center; gap: 12px; }
.composer-actions .primary { margin-left: auto; }
.composer details summary { cursor: pointer; color: var(--ink-soft); font-size: 14px; font-weight: 600; }
.composer details[open] summary { margin-bottom: 8px; }
.template-row { display: grid; grid-template-columns: minmax(0, 2fr) 70px minmax(0, 3fr) auto; gap: 8px; }

.side { border-left: 1px solid var(--line); background: var(--surface); overflow: auto; display: flex; flex-direction: column; }
.side section { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.side h3 { font-size: 15px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 14px; }
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.notes-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.notes-list li { border-left: 3px solid var(--wait); padding: 2px 0 2px 10px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.notes-list .by { display: block; color: var(--ink-faint); font-size: 12.5px; margin-top: 2px; }
.side form { display: flex; flex-direction: column; gap: 8px; }
.side .grow { flex: 1; }

/* ---------- Probar asistente ---------- */
.playground { display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); }
.pg-config { padding: 26px 22px; display: flex; flex-direction: column; gap: 14px; overflow: auto; border-right: 1px solid var(--line); background: var(--surface); }
.pg-chat { display: flex; flex-direction: column; min-height: 0; }
.pg-vars { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.pg-vars legend { font-weight: 700; padding: 0 6px; }
.var-list { display: flex; flex-direction: column; gap: 10px; }
.var-list label small { font-weight: 400; color: var(--ink-soft); font-size: 12.5px; }
.var-list code, .pg-texts code { font-size: 12px; }
.pg-texts { display: flex; flex-direction: column; gap: 12px; }
.pg-texts summary { cursor: pointer; font-weight: 700; }
.pg-texts[open] > *:not(summary) { margin-top: 12px; }
.tools { margin-top: 8px; padding-top: 6px; border-top: 1px dashed color-mix(in srgb, var(--bot) 35%, transparent); font-size: 13px; color: var(--ink-soft); white-space: normal; }
.tools details summary { cursor: pointer; }
.tools pre { white-space: pre-wrap; word-break: break-all; margin: 4px 0 6px; font: 12px/1.45 ui-monospace, Menlo, monospace; background: var(--surface); border-radius: 8px; padding: 8px; }
.actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

/* ---------- Métricas y tablas ---------- */
.range { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.range label { font-size: 13px; }
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.figure { background: var(--surface); padding: 18px 20px; display: flex; flex-direction: column; gap: 2px; }
.figure strong { font-family: var(--display); font-size: 32px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.figure span { color: var(--ink-soft); font-size: 14px; }
.figure.wait strong { color: var(--wait-ink); }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; font-size: 14.5px; }
tr:last-child td { border-bottom: 0; }
th { font-size: 13px; color: var(--ink-soft); font-weight: 600; background: var(--paper); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .row-actions { display: flex; gap: 14px; }
.pill { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; }

.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 22px; }
.form h2, .form .wide { grid-column: 1 / -1; }

/* ---------- Celular ---------- */
@media (max-width: 900px) {
  .conv { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .side { border-left: 0; border-top: 1px solid var(--line); max-height: 45vh; }
}
@media (max-width: 760px) {
  .login { grid-template-columns: 1fr; }
  .login-story { padding: 36px 20px 28px; }
  .login-story h1 { font-size: 36px; }
  .login-story .lede { font-size: 16px; }
  .orbit { margin: 6px 0 2px; }
  .orbit-node { font-size: 11.5px; padding: 5px 9px; }
  .orbit-node em { display: none; }
  .login-form { padding: 28px 20px 36px; }
  #app { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .rail { order: 2; flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); gap: 0; }
  .rail .brand, .rail-foot .who, .nav-group { display: none; }
  .rail-foot { border-top: 0; padding-top: 0; }
  .rail-tools { flex-direction: row; }
  .nav { flex-direction: row; flex: 1; overflow-x: auto; scrollbar-width: none; }
  .nav button, .rail-btn { flex-direction: column; gap: 3px; font-size: 11px; padding: 6px 4px; width: auto; min-width: 68px; text-align: center; position: relative; }
  .nav button.active::before { left: 50%; top: 2px; translate: -50% 0; width: 6px; height: 6px; box-shadow: none; }
  .nav button span:first-of-type { flex: none; }
  .count { position: absolute; top: 0; right: 4px; min-width: 18px; height: 18px; font-size: 11px; }
  .rail-foot { margin: 0; flex-direction: row; }
  .work { overflow: hidden; }
  .inbox { grid-template-columns: 1fr; }
  .inbox.show-conv .lines { display: none; }
  .inbox:not(.show-conv) .conv { display: none; }
  .lines { border-right: 0; }
  .conv-head { padding: 10px 12px; gap: 8px; }
  .conv-head .back { display: inline-flex; }
  .conv-head .buttons .ghost, .conv-head .buttons .primary { padding: 7px 10px; font-size: 14px; }
  .messages { padding: 14px 12px; }
  .msg { max-width: 88%; }
  .composer { padding: 10px 12px; }
  .template-row { grid-template-columns: 1fr 64px; }
  .template-row > :nth-child(3), .template-row > :nth-child(4) { grid-column: 1 / -1; }
  .playground { grid-template-columns: 1fr; grid-template-rows: auto minmax(60vh, 1fr); overflow: auto; }
  .pg-config { border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .form { grid-template-columns: 1fr; padding: 16px; }
  .page { padding: 20px 14px 28px; }
}

/* Ficha del cliente: en pantallas angostas se abre encima del chat con el botón "Ficha". */
.conv-head .info { display: none; }
.conv { position: relative; }
@media (max-width: 900px) {
  .conv { grid-template-rows: minmax(0, 1fr); }
  .conv-head .info { display: inline-flex; }
  .side { display: none; position: absolute; inset: 0; z-index: 5; max-height: none; border-top: 0; }
  .conv.show-side .side { display: flex; }
  .side .close-side { display: inline-flex; }
}
.close-side { display: none; align-self: flex-start; margin: 12px 18px 0; }
@media (max-width: 760px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .rail { overflow-x: auto; scrollbar-width: none; }
  .nav { overflow: visible; flex: none; }
  .rail-foot .rail-btn { min-width: 68px; }
}
.figure strong, td.num { font-family: var(--display); }
td.num { font-weight: 500; }
@media (max-width: 760px) {
  .conv-head { flex-wrap: wrap; }
  .conv-head .title { flex: 1 1 calc(100% - 52px); }
  .conv-head .buttons { width: 100%; justify-content: flex-start; padding-left: 44px; }
}

/* Ajustes para el ancho de Sora y el espacio libre del logo (BRAND.md). */
.filters-row { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
.conv { grid-template-columns: minmax(0, 1fr) 320px; }
.facts { font-size: 13.5px; }
@media (max-width: 900px) { .conv { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Conectar WhatsApp ----------
   Dos extremos, el celular del negocio y Connecta, unidos por un tramo de órbita
   que cambia con el estado: punteado en espera, en marcha al conectar, sólido al quedar conectado. */
.connect > .pairing, .connect > .switch, .connect > .steps, .connect > .pair-status { max-width: 720px; }
.pairing { display: grid; grid-template-columns: 170px minmax(90px, 1fr) 170px; align-items: start; margin-top: 10px; }
.pair-node { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; }
.pair-node b { font-size: 15px; margin-top: 10px; }
.pair-node > span:last-child { color: var(--ink-soft); font-size: 13.5px; overflow-wrap: anywhere; }
.pair-icon {
  width: 68px; height: 68px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-soft);
  background: var(--surface); border: 1.5px solid var(--line); transition: border-color .3s, color .3s, box-shadow .3s;
}
.pair-icon svg { width: 28px; height: 28px; }
.pair-hub .pair-icon { background: var(--az-night); border-color: #2c2560; }
.pair-arc { width: calc(100% + 100px); height: 46px; margin: -12px -50px 0; overflow: visible; position: relative; z-index: 0; }
.pair-node { position: relative; z-index: 1; }
.arc-track, .arc-line { fill: none; vector-effect: non-scaling-stroke; }
.arc-track { stroke: var(--ink-faint); stroke-width: 2; stroke-dasharray: 3 7; transition: stroke .3s; }
.arc-line { stroke: url(#arcStroke); stroke-width: 3; opacity: 0; transition: opacity .6s ease; }
.pairing[data-state="loading"] .arc-track, .pairing[data-state="connecting"] .arc-track { stroke: var(--bot); animation: arc-march .9s linear infinite; }
.pairing[data-state="success"] .arc-line { opacity: 1; }
.pairing[data-state="success"] .arc-track { stroke: transparent; }
.pairing[data-state="success"] .pair-icon { border-color: var(--human); color: var(--human); box-shadow: 0 0 0 5px color-mix(in srgb, var(--human) 14%, transparent); }
.pairing[data-state="cancel"] .arc-track { stroke: var(--wait); }
.pairing[data-state="error"] .arc-track { stroke: var(--danger); }
@keyframes arc-march { to { stroke-dashoffset: -20; } }
@media (prefers-reduced-motion: reduce) { .pairing .arc-track { animation: none !important; } }
.pair-status { margin: 0; font-size: 15px; font-weight: 600; color: var(--ink); }
.pair-status[data-state="success"] { color: var(--human-ink); }
.pair-status[data-state="cancel"] { color: var(--wait-ink); }
.pair-status[data-state="error"] { color: var(--danger); }
.switch {
  flex-direction: row; align-items: flex-start; gap: 14px; font-weight: 400; cursor: pointer;
  padding: 16px 18px; border: 1.5px solid var(--line); border-radius: 14px; background: var(--surface);
}
.switch input {
  appearance: none; flex: none; width: 44px; height: 26px; margin: 1px 0 0; padding: 0; border: 0; border-radius: 13px;
  background: var(--ink-faint); position: relative; cursor: pointer; transition: background .2s;
}
.switch input::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: translate .2s;
}
.switch input:checked { background: var(--az-violet); }
.switch input:checked::before { translate: 18px 0; }
.switch input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; box-shadow: none; }
.switch-text { display: flex; flex-direction: column; gap: 3px; }
.switch-text b { font-weight: 600; font-size: 15px; }
.switch-text small { color: var(--ink-soft); font-size: 13.5px; max-width: 60ch; }
.primary.fb { display: inline-flex; align-items: center; gap: 10px; padding: 12px 22px; font-size: 15.5px; background: #1877f2; }
.primary.fb:hover { background: #0f68dc; }
.primary.fb svg { width: 20px; height: 20px; }
.steps { counter-reset: step; list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 12px; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 12px; align-items: baseline; color: var(--ink-soft); font-size: 15px; }
.steps li::before {
  content: counter(step); width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; align-self: start;
  font-size: 13px; font-weight: 700; color: var(--ink); border: 1.5px solid var(--line); background: var(--surface);
}
.steps li:last-child::before { border-color: var(--human); color: var(--human-ink); }
.legal-links { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0; font-size: 13.5px; }
@media (max-width: 760px) {
  .pairing { grid-template-columns: 110px minmax(40px, 1fr) 110px; }
  .pair-icon { width: 56px; height: 56px; }
  .pair-arc { margin: -16px -30px 0; width: calc(100% + 60px); }
  .primary.fb { width: 100%; justify-content: center; }
}

/* Accesos por cliente en Usuarios / Tu equipo */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips .tag { display: inline-flex; align-items: center; gap: 4px; }
.tag.role-superadmin { background: color-mix(in srgb, var(--bot) 22%, transparent); }
.tag.role-gestor { background: color-mix(in srgb, var(--bot) 14%, transparent); }
.chip-x { border: 0; background: none; padding: 0 2px; cursor: pointer; color: inherit; font-size: 15px; line-height: 1; }
.grant { margin-top: 6px; }
.grant summary { cursor: pointer; font-size: 13px; color: var(--ink-soft); }
.grant-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.grant-row select { width: auto; }
#cnTenantWrap { max-width: 360px; }

/* Arranque: fondo de la marca y el ícono mientras se confirma la sesión y la sección de la URL. */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--paper); z-index: 50; }
.boot img { width: 56px; height: 56px; opacity: .85; animation: boot-breathe 1.6s ease-in-out infinite; }
@keyframes boot-breathe { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .boot img { animation: none; } }
/* Invitaciones y registro */
.invite-link { display: flex; gap: 8px; }
.invite-link input { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.section-title { font-size: 18px; margin: 28px 0 10px; }
.form-details { margin-top: 24px; }
.form-details > summary { cursor: pointer; font-weight: 600; color: var(--ink-soft); margin-bottom: 12px; }
#cnBusinessWrap { max-width: 360px; }

/* ---------- Accesos ----------
   Cada persona es una órbita: una línea que pasa por todos los clientes. Donde tiene acceso, el nodo se enciende con el
   color de su rol (como los nodos de clientes en la órbita del logo) y un trazo con el degradado de la marca une sus
   clientes. Es lo único llamativo de la pantalla; el resto queda sobrio. */
.access { --name-col: 260px; --cell: 92px; }
.access .page-head .intro { margin-top: 6px; }
.ax-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
.ax-filter { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--sunk); }
.ax-filter label { display: block; }
.ax-filter input { position: absolute; opacity: 0; pointer-events: none; }
.ax-filter span { display: block; padding: 6px 14px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--ink-soft); cursor: pointer; }
.ax-filter input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 0 var(--line); }
.ax-filter input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }
#axSearch { width: min(280px, 100%); }
.ax-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 0 auto; padding: 0; list-style: none; font-size: 13px; color: var(--ink-soft); }
.ax-legend li { display: inline-flex; align-items: center; gap: 7px; }

/* Nodos: el mismo vocabulario en la leyenda, la matriz y el selector de clientes. */
.node { --c: var(--line); display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); box-shadow: inset 0 0 0 2px var(--c); flex-shrink: 0; }
.node.gestor { --c: var(--az-violet); background: var(--az-violet); box-shadow: 0 0 0 4px color-mix(in srgb, var(--az-violet) 22%, transparent); }
.node.propietario { --c: var(--human); background: var(--human); box-shadow: 0 0 0 4px color-mix(in srgb, var(--human) 22%, transparent); }
.node.asesor { --c: var(--ink-faint); background: var(--ink-faint); }
.node.invited { --c: var(--az-lilac); background: transparent; box-shadow: none; border: 2px dashed var(--az-lilac); }

.ax-scroll { overflow: auto; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.ax-grid { min-width: max-content; }
.ax-row { position: relative; display: grid; grid-template-columns: var(--name-col) repeat(var(--cols), var(--cell)); align-items: center; min-height: 64px; border-top: 1px solid var(--line); }
.ax-row:first-child { border-top: 0; }
.ax-head { min-height: 0; padding: 14px 0 10px; position: sticky; top: 0; z-index: 2; background: var(--surface); border-bottom: 1px solid var(--line); }
.ax-head + .ax-row { border-top: 0; }
.ax-head .ax-tenant { font-size: 12.5px; font-weight: 600; line-height: 1.25; text-align: center; padding: 0 6px; color: var(--ink-soft);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; hyphens: auto; align-self: end; }
.ax-who { position: sticky; left: 0; z-index: 1; align-self: stretch; display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-right: 1px solid var(--line); min-width: 0; }
.ax-head .ax-who { font-size: 13px; color: var(--ink-faint); font-weight: 600; }
.ax-who .avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--sunk); color: var(--ink); font-weight: 700; font-size: 13px; flex-shrink: 0; }
.ax-who b { display: block; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ax-who small { display: block; color: var(--ink-faint); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ax-who .ax-span { color: var(--ink-soft); }
.ax-row.pending .ax-who b { color: var(--ink-soft); font-weight: 600; }

/* La órbita de cada persona: una línea tenue a lo ancho y un trazo con degradado entre su primer y su último cliente. */
.ax-track, .ax-lit { grid-row: 1; height: 2px; margin: 0 calc(var(--cell) / 2); pointer-events: none; }
.ax-track { grid-column: 2 / -1; background: var(--line); }
.ax-lit { background: var(--az-gradient); border-radius: 2px; }
.ax-row.pending .ax-lit { background: repeating-linear-gradient(90deg, var(--az-lilac) 0 6px, transparent 6px 11px); }

.ax-cell { grid-row: 1; position: relative; z-index: 1; justify-self: center; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; }
.ax-cell .node { width: 12px; height: 12px; }
.ax-cell .node.gestor, .ax-cell .node.propietario { width: 16px; height: 16px; }
.ax-cell:not(:disabled):hover { background: var(--sunk); }
.ax-cell:not(:disabled):hover .node:not(.gestor):not(.propietario):not(.asesor):not(.invited) { box-shadow: inset 0 0 0 2px var(--az-violet); }
.ax-cell:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; }
.ax-cell:disabled { cursor: default; opacity: 1; }
.ax-cell.just { animation: ax-lit .5s ease-out; }
@keyframes ax-lit { from { transform: scale(1.6); } to { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .ax-cell.just { animation: none; } }

.ax-empty { color: var(--ink-soft); margin: 0; }
.page > .ax-menu { position: fixed; z-index: 30; width: max-content; max-width: 280px; min-width: 220px; padding: 6px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 18px 40px -18px rgba(8, 6, 26, .45); }
.ax-menu p { margin: 6px 10px 8px; font-size: 13px; color: var(--ink-soft); }
.ax-menu p b { color: var(--ink); }
.ax-menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 9px; text-align: left; font-weight: 600; font-size: 14px; }
.ax-menu button:hover, .ax-menu button:focus-visible { background: var(--sunk); outline: none; }
.ax-menu button[aria-checked="true"]::after { content: "Actual"; margin-left: auto; font-size: 12px; font-weight: 500; color: var(--ink-faint); }
.ax-menu .danger { color: var(--danger); border-top: 1px solid var(--line); border-radius: 0 0 9px 9px; margin-top: 4px; }

/* Panel lateral para dar acceso a varios clientes de una vez. */
.ax-drawer { position: fixed; inset: 0 0 0 auto; width: min(440px, 100%); z-index: 40; background: var(--surface); border-left: 1px solid var(--line); box-shadow: -24px 0 60px -30px rgba(8, 6, 26, .5); display: flex; }
.ax-drawer form { display: flex; flex-direction: column; gap: 18px; padding: 22px 22px 18px; width: 100%; min-height: 0; }
.ax-drawer header { display: flex; align-items: center; justify-content: space-between; }
.ax-drawer h2 { font-size: 22px; letter-spacing: -0.02em; }
.ax-close { font-size: 26px; line-height: 1; width: 36px; height: 36px; border-radius: 10px; color: var(--ink-soft); }
.ax-close:hover { background: var(--sunk); }
.ax-drawer fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.ax-drawer legend { font-weight: 600; font-size: 14px; padding: 0; margin-bottom: 8px; }
#axRoles { display: flex; flex-wrap: wrap; gap: 8px; }
#axRoles label { flex-direction: row; align-items: center; gap: 8px; padding: 8px 12px; border: 1.5px solid var(--line); border-radius: 10px; font-weight: 600; cursor: pointer; }
#axRoles input { position: absolute; opacity: 0; pointer-events: none; }
#axRoles label:has(input:checked) { border-color: var(--az-violet); background: var(--bot-tint); }
#axRoles label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 1px; }
.ax-pick { flex: 1; min-height: 120px; }
.ax-count { font-weight: 500; color: var(--ink-faint); }
.ax-tenants { overflow: auto; flex: 1; border: 1px solid var(--line); border-radius: 12px; }
.ax-tenants label { flex-direction: row; align-items: center; gap: 12px; padding: 11px 14px; border-top: 1px solid var(--line); font-weight: 500; cursor: pointer; }
.ax-tenants label:first-child { border-top: 0; }
.ax-tenants input { position: absolute; opacity: 0; pointer-events: none; }
.ax-tenants label:has(input:checked) .node { --c: var(--az-violet); background: var(--az-violet); }
.ax-tenants label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: -2px; }
.ax-tenants small { margin-left: auto; color: var(--ink-faint); font-size: 12.5px; }
.ax-foot { display: flex; flex-direction: column; gap: 10px; }
.ax-foot .status { margin: 0; }

@media (max-width: 760px) {
  .access { --name-col: 168px; --cell: 64px; }
  .ax-legend { margin-left: 0; }
  .ax-who .avatar { display: none; }
}

/* ---------- Clientes ----------
   Lista y detalle. Cada cliente lleva su puesta en marcha como una ruta de cuatro pasos (número, fuente de datos,
   asistente, atiende). Lleno = listo, medio = falta algo, vacío = apagado. La misma ruta, grande, es el índice del detalle. */
.dot { --c: var(--line); display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; box-shadow: inset 0 0 0 2px var(--c); background: var(--surface); }
.dot.on { --c: var(--human); background: var(--human); }
.dot.half { --c: var(--az-violet); background: linear-gradient(90deg, var(--az-violet) 50%, var(--surface) 50%); }
.dot.off { --c: var(--ink-faint); }

.clients { display: grid; grid-template-columns: 340px minmax(0, 1fr); }
.cl-list { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; padding: 20px 16px 0; min-height: 0; }
.cl-list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cl-filter { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--sunk); border-radius: 10px; padding: 3px; }
.cl-filter label { display: block; font-weight: 600; font-size: 13px; }
.cl-filter input { position: absolute; opacity: 0; pointer-events: none; }
.cl-filter span { display: block; text-align: center; padding: 6px 4px; border-radius: 8px; color: var(--ink-soft); cursor: pointer; }
.cl-filter input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px color-mix(in srgb, var(--ink) 18%, transparent); }
.cl-filter input:focus-visible + span { outline: 2px solid var(--focus); }
.cl-items { list-style: none; margin: 4px -16px 0; padding: 0; overflow: auto; flex: 1; border-top: 1px solid var(--line); }
.cl-items .empty-list { color: var(--ink-soft); padding: 28px 16px; }
.cl-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; width: 100%; padding: 13px 16px; text-align: left; border-bottom: 1px solid var(--line); }
.cl-item:hover { background: var(--paper); }
.cl-item.sel { background: var(--bot-tint); }
.cl-item:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.cl-item b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.cl-item small { grid-column: 1 / -1; color: var(--ink-soft); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cl-dots { display: inline-flex; align-items: center; gap: 0; }
.cl-dots .dot + .dot { margin-left: 10px; position: relative; }
.cl-dots .dot + .dot::before { content: ""; position: absolute; right: 100%; top: 50%; width: 10px; height: 2px; translate: 0 -50%; background: var(--line); }

.cl-detail { overflow: auto; min-height: 0; display: flex; flex-direction: column; padding: 0 clamp(16px, 3vw, 40px); container-type: inline-size; }
.cl-detail > * { max-width: 920px; width: 100%; }
.cl-head { display: flex; align-items: center; gap: 14px; padding: 26px 0 18px; }
.cl-head .back { display: none; padding: 6px; border-radius: 8px; }
.cl-head .back svg { width: 22px; height: 22px; }
.cl-title { flex: 1; min-width: 0; }
.cl-title h2 { font-size: clamp(22px, 2.4vw, 28px); letter-spacing: -0.03em; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cl-title .hint { margin-top: 4px; }
.cl-switch { flex-direction: row; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.cl-switch input { appearance: none; width: 42px; height: 24px; border-radius: 99px; background: var(--sunk); border: 0; padding: 0; position: relative; cursor: pointer; box-shadow: inset 0 0 0 1.5px var(--line); transition: background .15s; }
.cl-switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgba(8, 6, 26, .3); transition: translate .15s; }
.cl-switch input:checked { background: var(--human); box-shadow: none; }
.cl-switch input:checked::after { translate: 18px 0; }
.cl-switch input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* La ruta: cuatro pasos unidos por una línea que se llena con el degradado hasta el último paso listo. */
.cl-route { list-style: none; margin: 0 0 8px; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); position: relative; }
.cl-route li { position: relative; min-width: 0; }
.cl-route li + li::before { content: ""; position: absolute; top: 19px; right: calc(100% - 13px); width: calc(100% - 18px); height: 2px; background: var(--line); }
.cl-route li:has(.cl-step.on) + li:has(.cl-step.on)::before { background: var(--az-gradient); }
.cl-step { display: grid; grid-template-columns: auto; justify-items: start; gap: 6px; padding: 12px 10px 12px 6px; text-align: left; border-radius: 12px; width: 100%; }
.cl-step:hover { background: var(--sunk); }
.cl-step:focus-visible { outline: 2px solid var(--focus); }
.cl-step .dot { width: 16px; height: 16px; margin-left: 1px; }
.cl-step .dot.on { box-shadow: 0 0 0 5px color-mix(in srgb, var(--human) 20%, transparent); }
.cl-step b { font-size: 14px; }
.cl-step small { font-size: 13px; color: var(--ink-soft); line-height: 1.35; }
.cl-step.half small { color: var(--ink); }

.cl-sec { padding: 22px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 14px; }
.cl-sec h3 { font-size: 18px; letter-spacing: -0.015em; }
.cl-sec > .hint { margin-top: -8px; }
.cl-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.cl-grid .wide { grid-column: 1 / -1; }
.cl-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.cl-meta { display: flex; flex-direction: column; gap: 12px; padding: 14px; border-radius: 12px; background: var(--paper); }
.cl-meta-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.cl-meta-row .hint { max-width: 52ch; }
.cl-inline { display: flex; gap: 8px; }
.cl-inline input { flex: 1; }
.cl-checks { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 0; }
.cl-checks dt { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.cl-checks dd { margin: 0; font-size: 14px; color: var(--ink-soft); }
.cl-checks .cl-fix { grid-column: 1 / -1; }
.cl-sources { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.cl-source { gap: 4px; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--surface); }
.cl-source input { position: absolute; opacity: 0; pointer-events: none; }
.cl-source small { font-weight: 400; color: var(--ink-soft); font-size: 12.5px; line-height: 1.35; }
.cl-source:has(input:checked) { border-color: var(--az-violet); background: var(--bot-tint); }
.cl-source:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 1px; }
.cl-result { margin: 0; padding: 12px 14px; border-radius: 12px; background: var(--paper); font-size: 13px; white-space: pre-wrap; max-height: 260px; overflow: auto; border-left: 3px solid var(--line); }
.cl-result.ok { border-left-color: var(--human); }
.cl-result.bad { border-left-color: var(--danger); }
.cl-texts { display: flex; flex-direction: column; gap: 12px; }
.cl-texts summary { cursor: pointer; font-weight: 600; color: var(--ink-soft); }
.cl-texts[open] > label { margin-top: 12px; }
.cl-save { position: sticky; bottom: 0; display: flex; align-items: center; justify-content: flex-end; gap: 14px; padding: 14px 0 18px; margin-top: auto;
  background: linear-gradient(to top, var(--paper) 70%, transparent); }
.clients .cl-detail { background: var(--paper); }

/* En detalles angostos la ruta pasa a dos filas de dos pasos. */
@container (max-width: 620px) {
  .cl-route { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cl-route li:nth-child(3)::before { display: none; }
  .cl-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .clients { grid-template-columns: 1fr; }
  .clients.show-detail .cl-list { display: none; }
  .clients:not(.show-detail) .cl-detail { display: none; }
  .cl-list { border-right: 0; }
  .cl-head .back { display: inline-flex; }
  .cl-head { flex-wrap: wrap; }
  .cl-grid { grid-template-columns: 1fr; }
}

/* ---------- Equipo / Usuarios ----------
   Directorio agrupado por rol. La invitación es una frase con huecos («Invitar a … como … en …»): se lee como se dice. */
.team .page-head .intro { margin-top: 6px; }
.tm-invite { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; display: flex; flex-direction: column; gap: 8px; }
.tm-sentence { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.tm-sentence > span, #iTenantWrap, #iPassWrap { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tm-sentence input, .tm-sentence select { width: auto; font-size: 15px; font-weight: 500; }
.tm-sentence input[type=email] { min-width: min(260px, 100%); flex: 1 1 220px; }
.tm-sentence .primary { margin-left: auto; }
.tm-mode { margin: 0; }
.tm-mode .link { font-size: 14px; font-weight: 500; color: var(--ink-soft); }
.tm-invite .status:empty { display: none; }
.tm-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
#uSearch { width: min(300px, 100%); }
.tm-filter { width: min(330px, 100%); }
.tm-groups { display: flex; flex-direction: column; gap: 26px; }
.tm-group header { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.tm-group h2 { font-size: 18px; letter-spacing: -0.015em; }
.tm-n { display: inline-block; min-width: 22px; padding: 0 7px; border-radius: 99px; background: var(--sunk); color: var(--ink-soft); font-size: 13px; font-weight: 600; text-align: center; vertical-align: 2px; }
.tm-group ul { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); overflow: hidden; }
.tm-group li + li { border-top: 1px solid var(--line); }
.tm-row { display: grid; grid-template-columns: 40px minmax(0, 1.2fr) minmax(0, 1fr) auto; align-items: center; gap: 14px; width: 100%; padding: 12px 16px; text-align: left; }
button.tm-row:hover { background: var(--paper); }
button.tm-row:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.tm-row.off { color: var(--ink-faint); }
.tm-avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--sunk); color: var(--ink); font-weight: 700; font-size: 14px; }
.tm-group:not(.pending) .tm-avatar { box-shadow: inset 0 0 0 2px var(--line); }
.tm-row.pending .tm-avatar { background: transparent; border: 2px dashed var(--az-lilac); }
.tm-who { min-width: 0; display: flex; flex-direction: column; }
.tm-who b, .tm-who small, .tm-where { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tm-who small { color: var(--ink-soft); font-size: 13px; }
.tm-where { color: var(--ink-soft); font-size: 14px; }
.tm-flag { font-size: 12.5px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--sunk); color: var(--ink-soft); }
.tm-acts { display: inline-flex; gap: 14px; }
.tm-empty { color: var(--ink-soft); margin: 0; }

.tm-person { display: flex; flex-direction: column; gap: 16px; padding: 22px; width: 100%; overflow: auto; }
.tm-person header { display: flex; align-items: center; gap: 14px; }
.tm-person header div { flex: 1; min-width: 0; }
.tm-person header h2 { font-size: 21px; letter-spacing: -0.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tm-person header .tm-avatar { width: 48px; height: 48px; font-size: 16px; }
.tm-person h3 { font-size: 15px; }
.tm-access { list-style: none; margin: -6px 0 0; padding: 0; display: flex; flex-direction: column; }
.tm-access li { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto auto; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.tm-access li.hint, .tm-access .tm-access-all { display: flex; border-bottom: 0; }
.tm-access b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14.5px; }
.tm-access select { width: auto; }
.danger-link { color: var(--danger); }
.tm-super:not(:empty) { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 0; border-top: 1px solid var(--line); }
.tm-super .hint { margin: 0; }
.tm-since { display: block; color: var(--ink-soft); font-size: 13px; margin-top: 2px; }
.tm-grant-title { margin: 0 0 8px; font-weight: 600; font-size: 14px; }
.tm-person-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 14px; border-top: 1px solid var(--line); margin-top: auto; }
.tm-person-foot .hint { margin: 0; }

@media (max-width: 760px) {
  .tm-row { grid-template-columns: 40px minmax(0, 1fr) auto; }
  .tm-where { grid-column: 2 / -1; grid-row: 2; margin-top: -6px; }
  .tm-sentence .primary { margin-left: 0; width: 100%; }
}

/* ---------- Bandeja ----------
   Ordenada por urgencia: quienes esperan a tu equipo arriba (la espera más larga primero), con el tiempo de espera en ámbar,
   que sigue siendo el único color que llama. El hilo se lee como un chat real: días, autor solo cuando cambia y el traspaso
   del asistente como un evento en su momento. */
.search-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.filters-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; }
.filters-btn[aria-expanded="true"] { border-color: var(--az-violet); }
.f-count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--az-violet); color: #fff; font-size: 11.5px; display: inline-grid; place-items: center; }
.filters-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; padding: 12px; border-radius: 12px; background: var(--paper); }
.filters-panel label { font-size: 13px; }
.filters-panel #fTenantWrap { grid-column: 1 / -1; }
.filters-panel .link { justify-self: start; font-size: 13px; }
.line-list .group-head { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 1; cursor: default;
  padding: 8px 16px; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); background: var(--sunk); border-bottom: 1px solid var(--line); }
.line-list .group-head span { font-weight: 600; color: var(--ink-faint); }
.line-list .group-head.wait { color: var(--wait-ink); background: color-mix(in srgb, var(--wait-tint) 80%, var(--surface)); }
.line-list .group-head:hover { background: var(--sunk); }
.line-list .group-head.wait:hover { background: color-mix(in srgb, var(--wait-tint) 80%, var(--surface)); }
.line-list time.waited { color: var(--wait-ink); font-weight: 600; }
.line-list li:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

.window-chip { margin-left: 10px; padding: 1px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.window-chip.open { background: var(--human-tint); color: var(--human-ink); }
.window-chip.closing { background: var(--wait-tint); color: var(--wait-ink); }
.window-chip.closed { background: var(--sunk); color: var(--ink-soft); }

.messages { gap: 4px; }
.messages .day { align-self: center; margin: 14px 0 8px; padding: 3px 12px; border-radius: 99px; background: var(--sunk); color: var(--ink-soft); font-size: 12.5px; font-weight: 600; }
.messages .day:first-child { margin-top: 0; }
.msg.first { margin-top: 8px; }
.msg:not(.first).customer { border-top-left-radius: 6px; }
.msg:not(.first).bot, .msg:not(.first).human { border-top-right-radius: 6px; }
.event { align-self: center; display: flex; align-items: flex-start; gap: 10px; max-width: min(90%, 70ch); margin: 12px 0; padding: 10px 14px; border-radius: 12px; font-size: 14px; }
.handoff-event { background: var(--wait-tint); color: var(--wait-ink); }
.handoff-event .lamp { margin-top: 5px; flex-shrink: 0; }
.handoff-event b { font-weight: 600; }

.composer.closed { gap: 10px; }
.closed-note { margin: 0; font-size: 14px; color: var(--ink-soft); }
.closed-note b { color: var(--ink); font-weight: 600; }
@media (max-width: 760px) {
  .window-chip { display: block; width: fit-content; margin: 4px 0 0; }
}
/* La ficha depende del ancho de la Bandeja, no de la ventana: si no caben lista, chat y ficha, la ficha se abre encima. */
.inbox { container: inbox / inline-size; }
@container inbox (max-width: 1080px) {
  .conv { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .conv-head .info { display: inline-flex; }
  .side { display: none; position: absolute; inset: 0 0 0 auto; width: min(360px, 100%); z-index: 5; max-height: none; border-top: 0; box-shadow: -18px 0 40px -24px rgba(8, 6, 26, .5); }
  .conv.show-side .side { display: flex; }
  .side .close-side { display: inline-flex; }
}
.handoff-event time { margin-left: 8px; font-size: 12.5px; opacity: .8; }
.handoff-event .reason { display: block; margin-top: 2px; }
.conv-head { flex-wrap: wrap; row-gap: 8px; }
.conv-head .title { flex: 1 1 240px; }
.conv-head .state { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.conv-head .state .window-chip { margin-left: 4px; }
@container inbox (max-width: 1080px) {
  .template-row { grid-template-columns: minmax(0, 1fr) 64px; }
  .template-row > :nth-child(3), .template-row > :nth-child(4) { grid-column: 1 / -1; }
}

.agent .readonly textarea { background: var(--sunk); }
.pg-mode { display: grid; grid-template-columns: 1fr 1fr; background: var(--sunk); border-radius: 10px; padding: 3px; }
.pg-mode label { display: block; font-weight: 600; font-size: 13.5px; }
.pg-mode input { position: absolute; opacity: 0; pointer-events: none; }
.pg-mode span { display: block; text-align: center; padding: 6px 4px; border-radius: 8px; color: var(--ink-soft); cursor: pointer; }
.pg-mode input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px color-mix(in srgb, var(--ink) 18%, transparent); }
.pg-mode input:focus-visible + span { outline: 2px solid var(--focus); }
.pg-summary blockquote { margin: 4px 0 0; padding: 10px 12px; border-left: 3px solid var(--az-violet); background: var(--paper); border-radius: 0 10px 10px 0; white-space: pre-wrap; font-size: 14px; color: var(--ink-soft); }

/* Conocimiento: capa de datos curados por el negocio (borde punteado como los datos externos, con el turquesa de la marca). */
.ag-sec.know { gap: 12px; }
.kb-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.kb-mode { font-size: 12.5px; font-weight: 600; padding: 2px 10px; border-radius: 99px; background: var(--human-tint); color: var(--human-ink); }
.kb-docs { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.kb-docs li + li { border-top: 1px solid var(--line); }
.kb-docs .hint { padding: 12px 14px; }
.kb-doc { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; width: 100%; padding: 11px 14px; text-align: left; }
.kb-doc:hover { background: var(--paper); }
.kb-doc.sel { background: var(--human-tint); }
.kb-doc small { color: var(--ink-faint); font-size: 12.5px; white-space: nowrap; }
.kb-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.kb-file { flex-direction: row; cursor: pointer; font-size: 14px; }
.kb-file input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.kb-file:focus-within { outline: 2px solid var(--focus); border-radius: 4px; }
.kb-editor { display: flex; flex-direction: column; gap: 12px; padding: 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.kb-chunks summary { cursor: pointer; font-weight: 600; color: var(--ink-soft); }
.kb-chunks ol, .kb-hits { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.kb-chunks li, .kb-hits li { padding: 10px 12px; border-radius: 10px; background: var(--paper); border-left: 3px solid var(--human); }
.kb-chunks p, .kb-hits p { margin: 4px 0 0; font-size: 13.5px; color: var(--ink-soft); white-space: pre-wrap; max-height: 9em; overflow: hidden; }
.kb-chunks small { color: var(--ink-faint); font-size: 12px; }
.kb-try-row { display: flex; gap: 8px; }
.kb-try-row input { flex: 1; }
.kb-k input { width: 90px; }

/* Herramientas y accesos */
.tl-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.tl-tool { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; padding: 10px 14px; }
.tl-tool + .tl-tool { border-top: 1px solid var(--line); }
.tl-tool.off b { color: var(--ink-faint); text-decoration: line-through; }
.tl-switch { flex-direction: row; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.tl-switch input { width: 18px; height: 18px; }
.tl-switch code { font-size: 12px; color: var(--ink-faint); font-weight: 400; }
.tl-tool details summary { cursor: pointer; font-size: 13px; color: var(--ink-soft); }
.tl-tool details textarea { margin-top: 6px; font-size: 13.5px; }
.tl-limits { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 18px; }
.tl-limits input { width: 90px; }
.tl-unit { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.tl-schedule, .tl-handoff { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.tl-schedule legend, .tl-handoff legend { font-weight: 600; font-size: 14px; padding: 0; margin-bottom: 4px; }
.tl-days { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 6px 14px; }
.tl-days li { display: grid; grid-template-columns: 120px auto auto auto; align-items: center; gap: 8px; }
.tl-days input[type=time] { width: auto; padding: 4px 6px; }
.tl-days.disabled { opacity: .5; }
.tl-handoff ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
@media (max-width: 760px) { .tl-limits { grid-template-columns: 1fr; } }

/* Seguridad */
.gd-flow { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; counter-reset: gd; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.gd-flow li { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; font-size: 13.5px; counter-increment: gd; }
.gd-flow li + li { border-left: 1px solid var(--line); }
.gd-flow b::before { content: counter(gd) ". "; color: var(--ink-faint); }
.gd-flow span { color: var(--ink-soft); }
.guard-note { color: var(--wait-ink); font-weight: 600; }
@media (max-width: 760px) { .gd-flow { grid-template-columns: 1fr; } .gd-flow li + li { border-left: 0; border-top: 1px solid var(--line); } }

/* Observabilidad y evaluaciones */
.traces .trace-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.traces .trace-list li { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 10px; background: var(--paper); font-size: 13px; }
.trace-top { display: flex; align-items: baseline; gap: 8px; }
.trace-top time { margin-left: auto; color: var(--ink-faint); font-size: 12px; }
.traces small { color: var(--ink-soft); font-size: 12.5px; }
.traces small.bad, .ev-list small.bad { color: var(--danger); }
.ev-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.ev-list > li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 10px 14px; }
.ev-list > li + li { border-top: 1px solid var(--line); }
.ev-list > li.hint { display: block; }
.ev-list .dot { margin-top: 5px; }
.ev-list small { display: block; color: var(--ink-soft); font-size: 12.5px; }
.ev-list details summary { cursor: pointer; font-size: 12.5px; color: var(--ink-soft); }
.ev-list details p { margin: 4px 0 0; font-size: 13px; white-space: pre-wrap; }
.ev-acts { display: inline-flex; gap: 12px; }
.ev-form { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.ev-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
@media (max-width: 760px) { .ev-row { grid-template-columns: 1fr; } }

/* ---------- Agente: tablero ----------
   Cabecera fija con la identidad del agente (negocio, versión en WhatsApp y acciones), índice de secciones con una línea
   de estado cada una y una sección a la vez. El alto lo da el flex: la pestaña ocupa toda la ventana y solo la sección
   desplaza. Las capas del prompt quedan como un diagrama corto y plegable bajo el índice. */
.agent { display: flex; flex-direction: column; height: 100%; min-height: 0; background: var(--paper); }
.ag-top { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap;
  padding: 16px clamp(16px, 3vw, 32px); background: var(--surface); border-bottom: 1px solid var(--line); }
.ag-id { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "title sel" "state state"; align-items: center; gap: 4px 14px; min-width: 0; }
.ag-id h1 { grid-area: title; font-size: 24px; letter-spacing: -0.03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ag-id select { grid-area: sel; width: auto; max-width: 260px; justify-self: start; font-size: 14px; padding: 5px 8px; }
.ag-state { grid-area: state; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0; font-size: 13.5px; color: var(--ink-soft); }
.ag-chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 99px; font-weight: 600; font-size: 12.5px; background: var(--sunk); color: var(--ink-soft); }
.ag-chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.ag-chip.pub { background: var(--human-tint); color: var(--human-ink); }
.ag-chip.draft { background: var(--bot-tint); color: var(--bot); }
.ag-chip.dirty { background: var(--wait-tint); color: var(--wait-ink); }
.ag-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.ag-actions .status { font-size: 13px; max-width: 34ch; }
.ag-publish { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.ag-publish small { font-size: 12px; color: var(--ink-faint); }
.ag-publish small:empty { display: none; }

.ag-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 290px minmax(0, 1fr); }
.ag-nav { overflow: auto; padding: 18px 14px; border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; gap: 18px; }
.ag-nav ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.ag-nav li button { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px; border-left: 3px solid transparent; }
.ag-nav li button:hover { background: var(--paper); }
.ag-nav li.sel button { background: var(--bot-tint); border-left-color: var(--az-violet); }
.ag-nav li button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.ag-nav b { font-size: 14.5px; }
.ag-nav small { font-size: 12.5px; color: var(--ink-soft); line-height: 1.35; }
.ag-nav small.warn { color: var(--wait-ink); }

/* Diagrama de capas: cinco pasos alineados sobre una línea; el del negocio resaltado. */
.ag-layers { border-top: 1px solid var(--line); padding-top: 14px; }
.ag-layers summary { cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--ink-soft); }
.ag-layers ol { counter-reset: layer; margin-top: 12px; position: relative; gap: 10px; }
.ag-layers ol::before { content: ""; position: absolute; left: 10px; top: 10px; bottom: 10px; width: 2px; background: var(--line); }
.ag-layers li { position: relative; display: grid; grid-template-columns: 22px minmax(0, 1fr); column-gap: 10px; counter-increment: layer; font-size: 12.5px; }
.ag-layers li::before { content: counter(layer); grid-row: span 2; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700;
  background: var(--surface); box-shadow: inset 0 0 0 2px var(--line); color: var(--ink-soft); position: relative; z-index: 1; }
.ag-layers li.own::before { background: var(--az-violet); box-shadow: none; color: #fff; }
.ag-layers li.know::before { box-shadow: inset 0 0 0 2px var(--human); color: var(--human-ink); }
.ag-layers li.data::before { box-shadow: none; border: 2px dashed var(--ink-faint); }
.ag-layers li b { font-size: 13px; }
.ag-layers li span { color: var(--ink-soft); }

.ag-main { overflow: auto; min-height: 0; padding: 24px clamp(16px, 3vw, 40px) 48px; }
.ag-sec { display: flex; flex-direction: column; gap: 16px; max-width: 860px; }
.ag-sec[hidden] { display: none; }
.ag-sec-head { display: flex; flex-direction: column; gap: 4px; margin-bottom: 4px; }
.ag-sec-head h2 { font-size: 22px; letter-spacing: -0.025em; }
.ag-sec > .hint, .ag-sec-head .hint { max-width: 68ch; }
.ag-vars, .ag-examples { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.ag-vars legend, .ag-examples legend { font-weight: 600; font-size: 14px; padding: 0; margin-bottom: 4px; }
.ag-vars .var-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.ag-examples ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.ag-examples li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) auto; gap: 10px; align-items: start; padding: 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.ag-examples li .link { margin-top: 26px; }
.agent .readonly textarea, .agent .readonly input:not(#kbQuery) { background: var(--sunk); }

/* Versiones: línea de tiempo. */
.ag-timeline { list-style: none; margin: 0; padding: 0 0 0 4px; position: relative; display: flex; flex-direction: column; }
.ag-timeline::before { content: ""; position: absolute; left: 11px; top: 14px; bottom: 14px; width: 2px; background: var(--line); }
.ag-timeline:empty { display: none; }
.ag-timeline .ver { position: relative; display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 12px 0; }
.ag-timeline .node { width: 16px; height: 16px; border-radius: 50%; background: var(--surface); box-shadow: inset 0 0 0 2px var(--ink-faint); position: relative; z-index: 1; }
.ag-timeline .publicado .node { background: var(--human); box-shadow: 0 0 0 5px color-mix(in srgb, var(--human) 22%, transparent); }
.ag-timeline .borrador .node { background: linear-gradient(90deg, var(--az-violet) 50%, var(--surface) 50%); box-shadow: inset 0 0 0 2px var(--az-violet); }
.ag-timeline b { display: block; font-size: 15px; }
.ag-timeline .ver-label { font-size: 13.5px; color: var(--ink-soft); }
.ag-timeline .publicado .ver-label { color: var(--human-ink); font-weight: 600; }
.ag-timeline small { display: block; font-size: 12.5px; color: var(--ink-faint); }
.ag-empty { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 22px; border-radius: 14px; border: 1.5px dashed var(--line); background: var(--surface); }
.ag-empty b { font-size: 16px; }
.ag-fold { border-top: 1px solid var(--line); padding-top: 12px; }
.ag-fold summary { cursor: pointer; font-weight: 600; color: var(--ink-soft); font-size: 14px; }
.ag-fold pre { white-space: pre-wrap; font-size: 12.5px; background: var(--sunk); padding: 12px 14px; border-radius: 10px; max-height: 420px; overflow: auto; margin: 10px 0 0; }

/* Ancho medio: el índice pasa a una fila de pestañas que se desplaza. */
@media (max-width: 1100px) {
  .ag-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .ag-nav { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line); gap: 8px; scrollbar-width: thin; }
  .ag-nav ol { flex-direction: row; gap: 4px; }
  .ag-nav li button { white-space: nowrap; padding: 8px 12px; border-left: 0; border-bottom: 3px solid transparent; border-radius: 8px 8px 0 0; }
  .ag-nav li.sel button { border-bottom-color: var(--az-violet); }
  .ag-nav small { display: none; }
  .ag-layers { display: none; }
}
@media (max-width: 760px) {
  .ag-top { position: static; padding: 14px 16px; }
  .ag-id h1 { font-size: 20px; }
  .ag-actions { width: 100%; justify-content: flex-start; }
  .ag-actions { gap: 8px; }
  .ag-actions .ghost, .ag-actions .primary { padding: 7px 12px; font-size: 14px; }
  .ag-actions .link { order: 8; font-size: 13.5px; }
  .ag-actions .status { order: 9; width: 100%; max-width: none; }
  .ag-actions .status:empty { display: none; }
  .ag-state { font-size: 12.5px; }
  .ag-publish { align-items: flex-start; }
  .agent { overflow: auto; height: 100%; }
  .ag-body { flex: none; display: block; }
  .ag-main { overflow: visible; }
  .ag-vars .var-list { grid-template-columns: 1fr; }
  .ag-examples li { grid-template-columns: 1fr; }
  .ag-examples li .link { margin-top: 0; }
}

/* El panel ocupa exactamente la ventana (#app: 100vh) y cada sección desplaza su propio contenido. El documento no debe
   desplazarse: si lo hacía (por ejemplo con un scrollIntoView), el panel quedaba corrido hacia arriba y con un hueco abajo. */
html:has(body > #app:not(.hidden)), body:has(> #app:not(.hidden)) { height: 100%; overflow: hidden; }
/* Las filas de los grids ocupan exactamente el alto disponible: sin esto, una fila «auto» crece con el contenido (una
   columna larga) y empuja el documento más allá de la ventana. */
#app:not(.hidden) { grid-template-rows: minmax(0, 1fr); }
.ag-body { grid-template-rows: minmax(0, 1fr); }
.tab { min-height: 0; }
@media (max-width: 1100px) { .ag-body { grid-template-rows: auto minmax(0, 1fr); } }
@media (max-width: 760px) { #app:not(.hidden) { grid-template-rows: minmax(0, 1fr) auto; } .ag-body { grid-template-rows: none; } }

/* ---------- Cuenta de WhatsApp (administración de la WABA) ---------- */
.waacc #waBody { display: flex; flex-direction: column; gap: 32px; }
.waacc .section-title { margin: 0 0 10px; }
.wa-block { display: flex; flex-direction: column; gap: 12px; }
.wa-block-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.wa-head-tools { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.wa-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1px; margin: 0; background: var(--line); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.wa-facts > div { background: var(--surface); padding: 14px 16px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.wa-facts dt { color: var(--ink-soft); font-size: 13px; }
.wa-facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.wa-sub { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.wa-sub .lamp { align-self: center; }
.wa-sub > span:nth-child(2) { flex: 1 1 260px; }
.wa-state { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--sunk); }
.wa-state.ok { background: var(--human-tint); color: var(--human-ink); }
.wa-state.wait { background: var(--wait-tint); color: var(--wait-ink); }
.wa-state.bad { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.wa-quality { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--ink-faint); margin-right: 6px; }
.wa-quality.GREEN { background: #22a861; } .wa-quality.YELLOW { background: var(--wait); } .wa-quality.RED { background: var(--danger); }
#waTemplates td.wrap { white-space: normal; min-width: 240px; max-width: 420px; color: var(--ink-soft); font-size: 13.5px; }
.wa-tpl { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.wa-vars { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.wa-vars:empty { display: none; }
.wa-preview { position: sticky; top: 0; display: flex; flex-direction: column; gap: 8px; }
.wa-chat { background: #e9e1d6; border-radius: 16px; padding: 18px 14px; min-height: 180px; display: flex; flex-direction: column; gap: 6px; }
.wa-bubble { background: #fff; color: #111; border-radius: 4px 12px 12px 12px; padding: 8px 10px 6px; box-shadow: 0 1px 1px rgba(0, 0, 0, .12); max-width: 100%; font-size: 14px; }
.wa-bubble b { display: block; margin-bottom: 4px; }
.wa-bubble b:empty, .wa-bubble small:empty { display: none; }
.wa-bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.wa-bubble small { display: block; color: #667; font-size: 12.5px; margin-top: 4px; }
.wa-replies { display: flex; flex-direction: column; gap: 4px; }
.wa-replies span { background: #fff; color: #0a7cff; text-align: center; border-radius: 10px; padding: 7px; font-size: 14px; font-weight: 600; }
.wa-profile-top { display: flex; align-items: center; gap: 14px; }
.wa-profile-top img { border-radius: 50%; object-fit: cover; }
.wa-profile-top div { display: flex; flex-direction: column; }
@media (max-width: 900px) { .wa-tpl { grid-template-columns: 1fr; } .wa-preview { position: static; } }
/* Esqueleto mientras se consulta Meta. */
.sk { display: inline-block; height: 12px; max-width: 100%; border-radius: 6px; vertical-align: middle;
  background: linear-gradient(90deg, var(--sunk) 0%, color-mix(in srgb, var(--sunk) 55%, var(--surface)) 50%, var(--sunk) 100%);
  background-size: 200% 100%; animation: sk-shimmer 1.3s ease-in-out infinite; }
.wa-facts dt .sk { height: 10px; }
.wa-loading #waProfile :is(input, textarea, select) { background: var(--sunk); color: transparent; }
.wa-loading button:disabled, .wa-head-tools :disabled { opacity: .55; cursor: progress; }
@keyframes sk-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } }

/* Eliminar cliente: zona de peligro al final del detalle. */
.cl-danger h3 { color: var(--danger); }
.ghost.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.primary.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.primary.danger:disabled { opacity: .45; cursor: not-allowed; }
.cl-delete { display: flex; flex-direction: column; gap: 12px; max-width: 460px; padding: 16px; border: 1.5px solid color-mix(in srgb, var(--danger) 45%, var(--line)); border-radius: 12px; }

/* Negocio y módulos (contrato v2) */
.bz-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.bz-checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.bz-checks small { color: var(--ink-faint); }

/* Solicitudes */
.rq-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
@media (min-width: 1100px) { .rq-layout:has(.rq-detail:not(.hidden)) { grid-template-columns: minmax(0, 1fr) 360px; } }
.rq-row { cursor: pointer; }
.rq-row.sel, .rq-row:hover { background: var(--surface-2, rgba(127,127,127,.08)); }
.rq-status { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; border: 1px solid var(--line); }
.rq-status.nueva { color: #b26a00; border-color: currentColor; }
.rq-status.confirmada { color: #0f8a6b; border-color: currentColor; }
.rq-status.rechazada, .rq-status.cancelada { color: var(--ink-faint); }
.rq-detail { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.rq-detail header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rq-detail h2 { margin: 0; font-size: 18px; }
.rq-facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 12px; margin: 0; font-size: 14px; }
.rq-facts div { display: contents; }
.rq-facts dt { color: var(--ink-soft); }
.rq-facts dd { margin: 0; overflow-wrap: anywhere; }
.rq-detail .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
