#webchat-page {
  --bg:#eef1f5; --surface:#fff; --ink:#18212b; --muted:#5a6675; --line:#d9dfe6;
  --accent:#1f5fbf; --accent-soft:#e3ecf9; --accent-glow:rgba(31,95,191,.35); --on-accent:#fff;
  --teal:#1b7f7a; --teal-soft:#e2f3f1;
  --user:#1f5fbf; --user-ink:#fff; --bot:#f1f4f8;
  --good:#1e7a4f; --good-soft:#e2f3ea; --bad:#b23a2e; --bad-soft:#f8e6e3; --warn:#9a6a00; --warn-soft:#fbf0d6;
  --paper:var(--bg); --card:var(--surface); --soft:var(--accent-soft); --olive:var(--accent);
  color-scheme:light;
}
@media (prefers-color-scheme: dark){
  #webchat-page {
    --bg:#0f141a; --surface:#1a2129; --ink:#e7ecf2; --muted:#9aa7b6; --line:#2e3844;
    --accent:#6fa3ff; --accent-soft:#1d2d47; --accent-glow:rgba(111,163,255,.45); --on-accent:#0f141a;
    --teal:#4fc3bb; --teal-soft:#153331;
    --user:#2f6fd0; --bot:#232c37;
    --good:#5cc68f; --good-soft:#163326; --bad:#ff8a7d; --bad-soft:#3a1e1b; --warn:#e8b64a; --warn-soft:#3a2f14;
    color-scheme:dark;
  }
  #webchat-page .brand-logo{background:#eef1f5;border-radius:8px}
  #webchat-page .site-header .lupa-nav:not(:hover){color:var(--ink)}
}
#webchat-page .site-header .organizaciones-nav[aria-current="page"]{background:var(--accent);color:var(--on-accent)}
.context-webchat {
  --font-display:"Source Serif 4", Georgia, serif; --font-body:"IBM Plex Sans", system-ui, sans-serif;
  display:grid; gap:18px; padding-bottom:40px;
  font:16px/1.5 var(--font-body);
}
.context-webchat :is(.page-intro,.simulator,.key) :is(h1,h2,p){margin:0}
.context-webchat h1{font:700 clamp(1.75rem,4.2vw,2.5rem)/1.2 var(--font-display);text-wrap:balance}
.context-webchat .page-intro{display:grid;gap:8px;margin:0}
.context-webchat .page-intro .eyebrow{color:var(--accent)}
.context-webchat .lead{color:var(--muted);max-width:78ch}
.context-webchat button{font:inherit;color:inherit;cursor:pointer}
.context-webchat :is(button,[tabindex]):focus-visible{outline:3px solid var(--accent);outline-offset:2px}
.context-webchat .simulator{display:grid;gap:12px}
.context-webchat .simulator[hidden]{display:none}
/* Recorrido */
.context-webchat .route{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:6px}
.context-webchat .sec{min-height:52px;border:1px solid var(--line);background:var(--surface);border-radius:10px;padding:8px 10px;text-align:left;display:flex;flex-direction:column;gap:2px;transition:all .3s;position:relative;overflow:hidden}
.context-webchat .sec small{font-size:11.5px;color:var(--muted);letter-spacing:.04em}
.context-webchat .sec span{font-size:13px;font-weight:600;line-height:1.25}
.context-webchat .sec:hover{border-color:var(--accent)}
.context-webchat .sec.on{border-color:var(--accent);background:var(--accent-soft)}
.context-webchat .sec.on small{color:var(--accent)}
.context-webchat .sec.on::after{content:"";position:absolute;left:0;right:0;bottom:0;height:3px;background:var(--accent);animation:webchat-grow .5s ease}
.context-webchat .sec.done{border-color:var(--good)}
.context-webchat .sec.done small{color:var(--good)}
@keyframes webchat-grow{from{transform:scaleX(0);transform-origin:left}}

.context-webchat .stage{display:grid;grid-template-columns:minmax(0,1.3fr) minmax(320px,.95fr);gap:16px;align-items:stretch}

/* chat */
.context-webchat .chat{background:var(--surface);border:1px solid var(--line);border-radius:16px;display:flex;flex-direction:column;height:clamp(360px,68vh,700px);overflow:hidden;box-shadow:0 20px 50px -30px var(--accent-glow)}
.context-webchat .chat-head{display:flex;align-items:center;gap:10px;padding:11px 14px;border-bottom:1px solid var(--line)}
.context-webchat .tabs{display:flex;gap:6px;flex:1;min-width:0;overflow-x:auto}
.context-webchat .tab{flex:none;padding:6px 12px;border-radius:8px;border:1px solid var(--line);font-size:13px;color:var(--muted);white-space:nowrap;background:var(--bg);transition:all .3s;display:inline-flex;gap:6px;align-items:center}
.context-webchat .tab.active{max-width:100%;white-space:normal;flex-wrap:wrap;background:var(--accent-soft);border-color:var(--accent);color:var(--accent);font-weight:600}
.context-webchat .tab .space{font-size:10.5px;padding:1px 6px;border-radius:999px;background:var(--teal-soft);color:var(--teal);font-weight:600;letter-spacing:.03em}
.context-webchat .dots{display:flex;gap:5px}
.context-webchat .dots i{width:9px;height:9px;border-radius:50%;background:var(--line)}
.context-webchat .msgs{flex:1;overflow-y:auto;padding:16px 14px;display:flex;flex-direction:column;gap:12px}
.context-webchat .msg{flex:none;min-width:0;max-width:86%;overflow-wrap:anywhere;display:flex;flex-direction:column;gap:6px;animation:webchat-pop .35s cubic-bezier(.2,.7,.2,1)}
@keyframes webchat-pop{from{transform:translateY(10px) scale(.98);opacity:0}}
.context-webchat .msg.user{align-self:flex-end;align-items:flex-end}
.context-webchat .msg.bot{align-self:flex-start}
.context-webchat .bubble{overflow-x:auto;padding:10px 13px;border-radius:14px;font-size:14.5px;line-height:1.45}
.context-webchat .user .bubble{background:var(--user);color:var(--user-ink);border-bottom-right-radius:4px;white-space:pre-wrap}
.context-webchat .bot .bubble{background:var(--bot);border-bottom-left-radius:4px}
.context-webchat .bubble b{font-weight:600}
.context-webchat .bubble table{border-collapse:collapse;margin-top:6px;font-size:13px;font-variant-numeric:tabular-nums}
.context-webchat .bubble td, .context-webchat .bubble th{border:1px solid var(--line);padding:3px 8px;text-align:left}
.context-webchat .bubble th{background:var(--surface)}
.context-webchat .bubble .flag{color:var(--bad);font-weight:600;text-decoration:underline wavy var(--bad);text-underline-offset:3px}
.context-webchat .bubble .cite{color:var(--muted);font-size:12.5px}
.context-webchat .bubble ul, .context-webchat .bubble ol{margin:4px 0 0;padding-left:18px}
.context-webchat .attach{display:flex;flex-wrap:wrap;gap:6px;justify-content:flex-end}
.context-webchat .chip{display:inline-flex;align-items:center;gap:6px;font-size:12.5px;padding:4px 10px;border-radius:999px;border:1px solid var(--line);background:var(--accent-soft);color:var(--accent)}
.context-webchat .chip svg{flex:none;width:13px;height:13px}
.context-webchat .meta{font-size:11.5px;color:var(--muted)}
.context-webchat .divider{align-self:center;font-size:12.5px;color:var(--muted);padding:4px 12px;border:1px dashed var(--line);border-radius:999px;animation:webchat-pop .35s;text-align:center}
.context-webchat .typing{align-self:flex-start;background:var(--bot);border-radius:14px;border-bottom-left-radius:4px;padding:10px 14px;display:flex;gap:5px;animation:webchat-pop .3s}
.context-webchat .typing i{width:7px;height:7px;border-radius:50%;background:var(--muted);animation:webchat-bounce 1s infinite}
.context-webchat .typing i:nth-child(2){animation-delay:.15s}
.context-webchat .typing i:nth-child(3){animation-delay:.3s}
@keyframes webchat-bounce{30%{transform:translateY(-5px);opacity:1}0%,60%,100%{opacity:.5}}
.context-webchat .composer{border-top:1px solid var(--line);padding:10px 12px;display:flex;gap:8px;align-items:flex-end}
.context-webchat .input{flex:1;min-height:42px;max-height:110px;overflow:hidden;border:1px solid var(--line);border-radius:12px;padding:10px 12px;font-size:14px;color:var(--ink);background:var(--bg);white-space:pre-wrap;word-break:break-word}
.context-webchat .input.empty::before{content:"El guion escribe aquí…";color:var(--muted)}
.context-webchat .input:not(.empty)::after{content:"";display:inline-block;width:2px;height:1em;background:var(--ink);vertical-align:-2px;animation:webchat-blink .8s steps(1) infinite}
.context-webchat .simulator:not(.playing) .typing i,
.context-webchat .simulator:not(.playing) .input::after{animation-play-state:paused}
@keyframes webchat-blink{50%{opacity:0}}
.context-webchat .send{width:42px;height:42px;border-radius:12px;border:none;background:var(--accent);color:var(--on-accent);display:grid;place-items:center}
.context-webchat .send.fire{animation:webchat-fire .35s}
@keyframes webchat-fire{40%{transform:scale(1.15) rotate(-10deg)}}

/* panel */
.context-webchat .side{display:flex;flex-direction:column;gap:12px;min-width:0}
.context-webchat .card{background:var(--surface);border:1px solid var(--line);border-radius:14px;padding:14px 16px;display:flex;flex-direction:column;gap:10px}
.context-webchat .card h2{font-size:12.5px;letter-spacing:.07em;text-transform:uppercase;color:var(--muted);font-family:var(--font-body);font-weight:600;display:flex;justify-content:space-between;gap:8px}
.context-webchat .card h2 em{font-style:normal;color:var(--accent);text-transform:none;letter-spacing:0;font-weight:500}
.context-webchat .layers{display:flex;flex-direction:column;gap:6px}
.context-webchat .layer{display:grid;grid-template-columns:26px 1fr auto;gap:10px;align-items:center;padding:7px 10px;border:1px solid var(--line);border-radius:9px;transition:all .35s;background:var(--bg)}
.context-webchat .layer .n{width:26px;height:26px;border-radius:50%;display:grid;place-items:center;font-size:12.5px;font-weight:600;background:var(--line);color:var(--muted);transition:all .35s}
.context-webchat .layer .t{font-size:13.5px;font-weight:600}
.context-webchat .layer .d{font-size:12px;color:var(--muted);display:block;font-weight:400}
.context-webchat .layer .c{font-size:11px;padding:2px 8px;border-radius:999px;background:var(--surface);border:1px solid var(--line);color:var(--muted);white-space:nowrap}
.context-webchat .layer.on{border-color:var(--accent);background:var(--accent-soft);box-shadow:0 0 0 3px var(--accent-soft)}
.context-webchat .layer.on .n{background:var(--accent);color:var(--on-accent);animation:webchat-ping .8s}
@keyframes webchat-ping{40%{transform:scale(1.25)}}
.context-webchat .layer.bad{border-color:var(--bad);background:var(--bad-soft)}
.context-webchat .layer.bad .n{background:var(--bad);color:var(--on-accent)}
.context-webchat .layer-state{display:block;font-size:11px;font-weight:600;color:var(--accent)}
.context-webchat .layer.bad .layer-state{color:var(--bad)}
.context-webchat .layer-state:empty{display:none}

.context-webchat .board{min-height:150px}
.context-webchat .board .inner{display:flex;flex-direction:column;gap:8px;font-size:13.5px}
.context-webchat .tri{display:grid;grid-template-columns:repeat(3,1fr);gap:6px}
.context-webchat .tri div{border:1px solid var(--line);border-radius:8px;padding:8px;font-size:12.5px;color:var(--muted);display:flex;flex-direction:column;gap:3px;min-height:74px;transition:all .3s}
.context-webchat .tri div b{font-size:13px;color:var(--ink)}
.context-webchat .tri div.filled{border-color:var(--accent);background:var(--accent-soft)}
.context-webchat .tri div.filled.ok{border-color:var(--good);background:var(--good-soft)}
.context-webchat .tri div.filled.ko{border-color:var(--warn);background:var(--warn-soft)}
.context-webchat .chain{display:grid;grid-template-columns:repeat(4,1fr);gap:4px;align-items:stretch}
.context-webchat .chain div{border:1px solid var(--line);border-radius:8px;padding:7px 6px;font-size:12px;text-align:center;color:var(--muted);transition:all .3s}
.context-webchat .chain div b{display:block;font-size:12.5px;color:var(--ink)}
.context-webchat .chain div.err{border-color:var(--bad);background:var(--bad-soft)}
.context-webchat .chain div.err b{color:var(--bad)}
.context-webchat .chain div.fix{border-color:var(--good);background:var(--good-soft)}
.context-webchat .chain div.fix b{color:var(--good)}
.context-webchat .kv{display:grid;grid-template-columns:auto 1fr;gap:4px 10px;font-size:13px}
.context-webchat .kv b{font-weight:600}
.context-webchat .kv span{color:var(--muted)}
.context-webchat .kv .new{animation:webchat-glow 1.2s}
@keyframes webchat-glow{0%{background:var(--good-soft)}100%{background:transparent}}
.context-webchat .two{display:grid;grid-template-columns:1fr 1fr;gap:6px;font-size:12.5px}
.context-webchat .two div{border:1px solid var(--line);border-radius:8px;padding:8px}
.context-webchat .two b{display:block;font-size:11.5px;letter-spacing:.05em;text-transform:uppercase;margin-bottom:4px}
.context-webchat .two .a b{color:var(--accent)}
.context-webchat .two .b b{color:var(--teal)}
.context-webchat .two ul{margin:0;padding-left:14px}
.context-webchat .doc{border:1px solid var(--line);border-radius:8px;padding:8px 10px;background:var(--bg);font-size:12.5px}
.context-webchat .doc b{display:block;color:var(--teal);font-size:11.5px;letter-spacing:.05em;text-transform:uppercase}
.context-webchat .doc p{margin-bottom:5px}
.context-webchat .check{display:flex;flex-direction:column;gap:5px}
.context-webchat .check > div{display:grid;grid-template-columns:22px minmax(0,1fr);gap:8px;align-items:start;font-size:13px;padding:6px 8px;border-radius:8px;border:1px solid var(--line);transition:all .35s}
.context-webchat .check i{font-style:normal;width:22px;height:22px;border-radius:50%;display:grid;place-items:center;font-size:12px;background:var(--line);color:var(--muted)}
.context-webchat .check div.ok{border-color:var(--good);background:var(--good-soft)}
.context-webchat .check div.ok i{background:var(--good);color:var(--on-accent)}
.context-webchat .check div.ko{border-color:var(--bad);background:var(--bad-soft)}
.context-webchat .check div.ko i{background:var(--bad);color:var(--on-accent)}
.context-webchat .check div.wa{border-color:var(--warn);background:var(--warn-soft)}
.context-webchat .check div.wa i{background:var(--warn);color:var(--on-accent)}
.context-webchat .check span{color:var(--muted);font-size:12px;display:block}

.context-webchat .note{background:var(--accent-soft);border-left:4px solid var(--accent);border-radius:10px;padding:12px 14px;min-height:96px;font-size:14px}
.context-webchat .note b{display:block;color:var(--accent);font-size:12.5px;letter-spacing:.06em;text-transform:uppercase;margin-bottom:4px}
.context-webchat .note.good{background:var(--good-soft);border-color:var(--good)}
.context-webchat .note.good b{color:var(--good)}
.context-webchat .note.warn{background:var(--warn-soft);border-color:var(--warn)}
.context-webchat .note.warn b{color:var(--warn)}
.context-webchat .note.bad{background:var(--bad-soft);border-color:var(--bad)}
.context-webchat .note.bad b{color:var(--bad)}

/* controles */
.context-webchat .controls{display:flex;flex-wrap:wrap;gap:10px;align-items:center;justify-content:space-between;background:var(--surface);border:1px solid var(--line);border-radius:14px;padding:12px 14px}
.context-webchat .controls .group{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
.context-webchat .btn{min-height:42px;border:1px solid var(--line);background:var(--surface);border-radius:9px;padding:8px 14px;font-weight:500;display:inline-flex;align-items:center;gap:6px;transition:transform .15s,border-color .15s}
.context-webchat .btn:hover:not(:disabled){border-color:var(--accent);color:var(--accent);transform:translateY(-1px)}
.context-webchat .btn.primary{background:var(--accent);border-color:var(--accent);color:var(--on-accent)}
.context-webchat .btn.primary:hover:not(:disabled){color:var(--on-accent);filter:brightness(1.08)}
.context-webchat .btn:disabled{opacity:.4;cursor:default}
.context-webchat .seg{display:inline-flex;border:1px solid var(--line);border-radius:9px}
.context-webchat .seg button{min-height:40px;border:0;border-radius:8px;background:transparent;padding:7px 12px;font-size:13.5px;color:var(--muted)}
.context-webchat .seg button[aria-pressed="true"]{background:var(--accent-soft);color:var(--accent);font-weight:600}
.context-webchat .progress{flex-basis:100%;width:100%;height:4px;border:0;background:var(--line);border-radius:4px;overflow:hidden;appearance:none}
.context-webchat .progress::-webkit-progress-bar{background:var(--line)}
.context-webchat .progress::-webkit-progress-value{background:var(--accent)}
.context-webchat .progress::-moz-progress-bar{background:var(--accent)}
.context-webchat .counter{font-size:13px;color:var(--muted);font-variant-numeric:tabular-nums}

.context-webchat .key{background:var(--ink);color:var(--bg);border-radius:14px;padding:22px 26px;display:flex;flex-direction:column;gap:8px}
.context-webchat .key .eyebrow{margin:0;color:inherit;opacity:.85}
.context-webchat .key p{font-family:var(--font-display);font-size:19px;line-height:1.4;max-width:66ch}

@media (max-width:940px){
  .context-webchat .controls{position:sticky;top:6px;z-index:2;box-shadow:0 3px 10px var(--accent-glow)}
  .context-webchat .stage{grid-template-columns:minmax(0,1fr)}
  .context-webchat .chat{height:clamp(350px,55vh,560px)}
  .context-webchat .route{grid-template-columns:repeat(3,minmax(0,1fr))}
}
@media (max-width:480px){
  .context-webchat .route{grid-template-columns:repeat(2,minmax(0,1fr))}
  .context-webchat .chat .msg{max-width:95%}
  .context-webchat .chain{grid-template-columns:repeat(2,minmax(0,1fr))}
  .context-webchat .layer{grid-template-columns:26px minmax(0,1fr);column-gap:8px;row-gap:3px}
  .context-webchat .layer .c{grid-column:2;justify-self:start}
}
@media (prefers-reduced-motion: reduce){
  .context-webchat *, .context-webchat *::before, .context-webchat *::after{animation:none!important;transition:none!important}
}
