/* ══════════════════════════════════════════════════════════════
   KACHAI · Chat v2 — Estación de trabajo
   Estilos del rediseño (papel/tinta, acentos azul y rojo).
   Solo lo usa chat.html; el resto del sitio sigue con kachai.css.
   ══════════════════════════════════════════════════════════════ */

/* ── Tokens ─────────────────────────────────────────────────────
   La paleta vive en kachai-tokens.css (bandera de Chile + papel Fable).
   Aquí sólo se alían los nombres históricos de esta hoja, de modo que el
   chat hereda el modo oscuro y cualquier ajuste de marca sin duplicar
   literales de color. */
:root {
  --panel: var(--superficie);
  --rojo: var(--cl-rojo);
  --azul: var(--cl-azul);
  --linea-suave: var(--linea);
  --gris: var(--tinta-3);
  --gris-suave: var(--tinta-4);
  --gris-tenue: var(--tinta-4);
  --texto: var(--tinta);
  --texto-suave: var(--tinta-2);
  --hover: var(--superficie-hover);
  --verde: var(--exito);
  --sans: var(--fuente);
  --serif: var(--fuente-serif);
  --mono: var(--fuente-mono);
}

/* ── Base ───────────────────────────────────────────────────── */
html, body {
  margin: 0;
  padding: 0;
  background: var(--papel);
  color: var(--tinta);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
a {
  color: var(--tinta);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}
a:hover { color: var(--rojo); }
button, input, textarea, select { font-family: inherit; }

.ms {
  font-family: 'Material Symbols Rounded';
  font-weight: 400;
  font-style: normal;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, .18);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, .4); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

@keyframes kSweep { 0% { transform: translateX(-120%); } 100% { transform: translateX(320%); } }
@keyframes kRise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes kSpin { to { transform: rotate(360deg); } }
@keyframes kPulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ══════════════════════════════════════════════════════════════
   Estructura general + franja tricolor
   ══════════════════════════════════════════════════════════════ */
.chat-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--papel);
  overflow: hidden;
}
.franja { flex: 0 0 auto; display: flex; height: 5px; width: 100%; }
.franja__azul { flex: 0 0 84px; background: var(--azul); }
.franja__blanco { flex: 1; background: var(--superficie); }
.franja__rojo { flex: 1; background: var(--rojo); }

.chat-body { flex: 1; min-height: 0; display: flex; position: relative; }

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(0, 0, 0, .32);
}
.backdrop.is-open { display: block; }

/* ══════════════════════════════════════════════════════════════
   Sidebar
   ══════════════════════════════════════════════════════════════ */
.sidebar {
  width: 258px;
  flex: 0 0 258px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--linea);
  min-height: 0;
  z-index: 40;
  transition: margin-left .24s ease, transform .24s ease;
}
.sidebar.is-hidden { margin-left: -258px; }

.brand {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--linea-suave);
}
.brand__logo {
  position: relative;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  background: var(--acento);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  font-family: var(--mono);
}
.brand__logo::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--azul) 0 34%, #fff 34% 67%, var(--rojo) 67%);
}
.brand__text { min-width: 0; flex: 1; }
.brand__name { font-size: 15px; font-weight: 700; letter-spacing: .02em; }
.brand__sub {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .1em;
  color: var(--gris);
  text-transform: uppercase;
}

.side-actions { padding: 12px 14px 10px; display: flex; gap: 7px; }
.btn-primary {
  flex: 1;
  height: 36px;
  border: 1px solid var(--linea-2);
  background: var(--acento);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--rojo); border-color: var(--rojo); }
.btn-square {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--linea);
  background: var(--superficie);
  color: var(--tinta);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.btn-square:hover { border-color: var(--acento); }

.side-list { flex: 1; min-height: 0; overflow-y: auto; padding: 2px 10px 8px; }
.side-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .14em;
  color: var(--gris-suave);
  padding: 8px 6px 6px;
}
.conv-list { display: flex; flex-direction: column; gap: 1px; }
.conv-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 8px;
  border: none;
  border-left: 2px solid transparent;
  background: transparent;
  color: var(--tinta-2);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}
.conv-item:hover { background: var(--hover); color: var(--tinta); }
.conv-item.is-active { background: var(--hover); border-left-color: var(--rojo); }
.conv-item__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-item__del {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: var(--gris-tenue);
  cursor: pointer;
  padding: 2px;
  display: grid;
  place-items: center;
  opacity: 0;
}
.conv-item:hover .conv-item__del,
.conv-item.is-active .conv-item__del { opacity: 1; }
.conv-item__del:hover { color: var(--rojo); }
.side-empty { padding: 14px; font-size: 12px; color: var(--gris-suave); text-align: center; }

.side-foot { border-top: 1px solid var(--linea-suave); padding: 12px 14px; }
.ctx-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .1em;
  color: var(--gris-suave);
  margin-bottom: 6px;
}
.ctx-head__value { color: var(--tinta); }
.ctx-track { height: 5px; background: var(--linea-suave); overflow: hidden; }
.ctx-fill { height: 100%; width: 0; background: var(--azul); transition: width .3s ease; }
.ctx-fill.is-hot { background: var(--rojo); }
.ctx-note {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--gris-tenue);
  margin-top: 5px;
}

/* Cuota mensual real del plan, servida por el backend. Se separa del
   medidor de contexto con una línea para que no se lean como lo mismo. */
.ctx-quota {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--linea-suave);
}
.ctx-quota[hidden] { display: none; }

.side-links { display: flex; gap: 14px; margin-top: 12px; font-size: 12px; }

.user-card {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--linea-suave);
}
.user-card__avatar {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  background: var(--linea-suave);
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--texto-suave);
  text-transform: uppercase;
}
.user-card__info { flex: 1; min-width: 0; }
.user-card__name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-card__plan {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--gris);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-card__logout {
  flex: 0 0 auto;
  border: none;
  background: none;
  color: var(--gris-suave);
  cursor: pointer;
  padding: 4px;
  display: grid;
  place-items: center;
}
.user-card__logout:hover { color: var(--rojo); }

/* ══════════════════════════════════════════════════════════════
   Columna principal + barra superior
   ══════════════════════════════════════════════════════════════ */
.chat-main {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--papel);
}
.brain-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.workspace {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}
.chat-col { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 10px 18px;
  min-height: 54px;
  border-bottom: 1px solid var(--linea-suave);
  background: var(--superficie-fuerte);
}
.topbar__group { display: flex; align-items: center; gap: 9px; min-width: 0; }
.topbar__group--end { flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.icon-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid var(--linea);
  background: var(--superficie);
  color: var(--tinta);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--acento); }

.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--linea);
  background: var(--superficie);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--texto-suave);
  white-space: nowrap;
  overflow: hidden;
}
.status-pill__dot { flex: 0 0 auto; width: 6px; height: 6px; border-radius: 50%; background: var(--gris-suave); }
.status-pill__dot.is-busy { background: var(--azul); animation: kPulse 1.1s ease-in-out infinite; }
.status-pill__text { overflow: hidden; text-overflow: ellipsis; }

.mode-switch {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--linea);
  background: var(--superficie);
  height: 34px;
}
.mode-switch__btn {
  height: 32px;
  padding: 0 11px;
  border: none;
  background: transparent;
  color: var(--gris);
  font-family: var(--mono);
  font-size: 11.5px;
  white-space: nowrap;
  cursor: pointer;
}
.mode-switch__btn + .mode-switch__btn { border-left: 1px solid var(--linea); }
.mode-switch__btn.is-on { background: var(--acento); color: #fff; }

.btn-workshop {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--linea-2);
  background: var(--superficie);
  color: var(--tinta);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.btn-workshop.is-on { background: var(--acento); color: #fff; }

/* Aviso de autenticación (?auth=required) */
.auth-notice {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  background: var(--peligro-suave);
  border-bottom: 1px solid var(--rojo);
  font-size: 13px;
  color: var(--texto);
}
.auth-notice__text { flex: 1; min-width: 0; }
.auth-notice__close {
  border: none;
  background: none;
  color: var(--gris);
  cursor: pointer;
  padding: 2px;
  display: grid;
  place-items: center;
}
.auth-notice__close:hover { color: var(--rojo); }

/* ══════════════════════════════════════════════════════════════
   Thread: estado vacío, mensajes, código, acciones
   ══════════════════════════════════════════════════════════════ */
.thread {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 0 10px;
}

/* ── Bienvenida (estilo Claude Code) ─────────────────────────
   Una tarjeta compacta con el estado real de la sesión y los atajos,
   en vez de un titular grande con tarjetas de sugerencia. */
.empty { max-width: 840px; margin: 0 auto; padding: 40px 28px 8px; }

.welcome {
  border: 1px solid var(--linea);
  border-radius: var(--r-md);
  background: var(--superficie);
  padding: 18px 20px;
  max-width: 560px;
}

.welcome__head { display: flex; align-items: baseline; gap: 9px; }
.welcome__spark { color: var(--azul); font-size: 15px; line-height: 1; }
.welcome__title { font-size: 15px; color: var(--texto); }
.welcome__title b { font-weight: 600; letter-spacing: .01em; }

.welcome__meta {
  display: flex; flex-wrap: wrap; gap: 6px 22px;
  margin: 12px 0 0; padding: 0;
  font-family: var(--mono); font-size: 11.5px;
}
.welcome__meta > div { display: flex; gap: 7px; min-width: 0; }
.welcome__meta dt { color: var(--gris-suave); letter-spacing: .06em; }
.welcome__meta dt::after { content: ':'; }
.welcome__meta dd { margin: 0; color: var(--texto-suave); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.welcome__hint {
  margin: 14px 0 0; padding-top: 12px;
  border-top: 1px solid var(--linea);
  font-size: 12.5px; color: var(--gris); text-wrap: pretty;
}
.welcome__hint b {
  font-family: var(--mono); font-weight: 600;
  color: var(--texto); background: var(--papel-3);
  border: 1px solid var(--linea); border-radius: var(--r-xs);
  padding: 1px 5px;
}

.welcome__cta { margin: 12px 0 0; font-size: 13.5px; color: var(--texto-suave); }

@media (max-width: 640px) {
  .empty { padding: 26px 18px 8px; }
  .welcome { padding: 15px 16px; }
}

.msg { max-width: 840px; margin: 0 auto; padding: 0 28px; animation: kRise .24s ease both; }
.msg__row { display: flex; gap: 0; border-bottom: 1px solid var(--linea-suave); }
.msg__meta {
  flex: 0 0 76px;
  padding: 20px 12px 20px 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
}
.msg__turn {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .1em;
  color: var(--gris-suave);
}
.msg__time { font-family: var(--mono); font-size: 10.5px; color: var(--gris-tenue); }
.msg__body {
  flex: 1;
  min-width: 0;
  padding: 20px 0 22px;
  border-left: 2px solid var(--azul);
  padding-left: 18px;
}
.msg--assistant .msg__body { border-left-color: var(--rojo); }
.msg__head { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; }
.msg__name {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .14em;
  color: var(--azul);
  font-weight: 600;
}
.msg--assistant .msg__name { color: var(--rojo); }
.msg__badge {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .08em;
  padding: 2px 6px;
  background: var(--acento);
  color: #fff;
}
.msg__text {
  font-size: 15.5px;
  line-height: 1.72;
  color: var(--texto);
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 66ch;
}
.msg__error { color: var(--rojo); font-size: 14px; }

.code-card { margin: 13px 0; border: 1px solid var(--code-linea); background: var(--code-fondo); }
.code-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 11px;
  border-bottom: 1px solid var(--code-linea);
}
.code-card__lang {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .1em;
  color: var(--tinta-3);
}
.code-card__actions { display: flex; gap: 6px; flex: 0 0 auto; }
.code-card__btn {
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--texto-suave);
  background: transparent;
  color: var(--linea-2);
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}
.code-card__btn:hover { border-color: #fff; color: #fff; }
.code-card__btn--open {
  border-color: #fff;
  background: var(--superficie);
  color: var(--tinta);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.code-card__btn--open:hover { background: var(--rojo); color: #fff; border-color: var(--rojo); }
.code-card__pre {
  margin: 0;
  padding: 13px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.62;
  color: var(--papel-3);
  white-space: pre;
}

.msg__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin-top: 15px;
  border: 1px solid var(--linea);
  width: fit-content;
  max-width: 100%;
}
.msg__action {
  height: 30px;
  padding: 0 11px;
  border: none;
  border-right: 1px solid var(--linea);
  background: var(--superficie);
  color: var(--texto-suave);
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.msg__action:last-child { border-right: none; }
.msg__action:hover { background: var(--acento); color: #fff; }

/* Barra de streaming */
.stream-bar {
  flex: 0 0 auto;
  max-width: 840px;
  width: 100%;
  margin: 0 auto;
  padding: 0 28px 9px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.stream-bar__track {
  flex: 1;
  min-width: 0;
  height: 3px;
  background: var(--linea-suave);
  overflow: hidden;
  position: relative;
}
.stream-bar__fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 30%;
  background: linear-gradient(90deg, var(--azul), var(--rojo));
  animation: kSweep 1.3s linear infinite;
}
.stream-bar__label {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--gris);
  white-space: nowrap;
}
.stream-bar__stop {
  flex: 0 0 auto;
  height: 27px;
  padding: 0 10px;
  border: 1px solid var(--rojo);
  background: var(--superficie);
  color: var(--rojo);
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.stream-bar__stop:hover { background: var(--rojo); color: #fff; }

/* ══════════════════════════════════════════════════════════════
   Composer + menús / y @
   ══════════════════════════════════════════════════════════════ */
.composer { flex: 0 0 auto; padding: 0 28px 16px; position: relative; }
.composer__inner { max-width: 840px; margin: 0 auto; position: relative; }

.comp-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 264px;
  overflow-y: auto;
  background: var(--superficie);
  border: 1px solid var(--linea-2);
  box-shadow: 6px 6px 0 rgba(0, 0, 0, .1);
  z-index: 30;
}
.comp-menu__title {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .14em;
  color: var(--gris-suave);
  padding: 9px 12px 7px;
  border-bottom: 1px solid var(--linea-suave);
}
.comp-menu__item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border: none;
  border-bottom: 1px solid var(--papel-3);
  background: transparent;
  color: var(--texto);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}
.comp-menu__item:hover { background: var(--acento); color: #fff; }
.comp-menu__icon { flex: 0 0 auto; font-size: 17px; color: var(--azul); }
.comp-menu__name { font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.comp-menu__desc { font-size: 13px; opacity: .7; }
.comp-menu__empty { padding: 14px; font-size: 13px; color: var(--gris-suave); }

.composer__box {
  background: var(--superficie);
  border: 1px solid var(--linea-2);
  box-shadow: 5px 5px 0 rgba(0, 0, 0, .08);
}
.composer__input {
  display: block;
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--tinta);
  font-size: 15.5px;
  line-height: 1.6;
  padding: 12px 13px 6px;
  min-height: 70px;
  max-height: 200px;
  overflow-y: auto;
}
.composer__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 8px 8px;
  border-top: 1px solid var(--papel-3);
}
.composer__tools { display: flex; align-items: center; gap: 1px; flex-wrap: wrap; }
.tool-btn {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--gris);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.tool-btn:hover { background: var(--acento); color: #fff; }
.tool-btn--text { font-family: var(--mono); font-size: 16px; font-weight: 600; }
.composer__sep { flex: 0 0 auto; width: 1px; height: 18px; background: var(--linea-suave); margin: 0 7px; }
.composer__counter {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--gris-suave);
  white-space: nowrap;
}
.composer__right { display: flex; align-items: center; gap: 9px; }
.composer__hint {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--gris-tenue);
  white-space: nowrap;
}
.btn-send {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--linea-2);
  background: var(--acento);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.btn-send:hover { background: var(--rojo); border-color: var(--rojo); }
.btn-send.is-stop { background: var(--rojo); border-color: var(--rojo); }
.composer__note { text-align: center; color: var(--gris-suave); font-size: 12px; margin: 9px 0 0; }

/* ══════════════════════════════════════════════════════════════
   Taller (visor de artefactos HTML)
   ══════════════════════════════════════════════════════════════ */
.ws-handle { flex: 0 0 5px; cursor: col-resize; background: var(--linea); z-index: 61; }

.workshop {
  display: none;
  flex-direction: column;
  background: var(--papel);
  border-left: 1px solid var(--tinta);
}
.workshop.is-open {
  display: flex;
  flex: 0 0 46%;
  width: 46%;
  min-width: 300px;
}
.workshop.is-full {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  width: 100%;
  min-width: 0;
}

.ws-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  padding: 9px 11px;
  background: var(--panel);
  border-bottom: 1px solid var(--linea);
}
.ws-flag {
  flex: 0 0 auto;
  width: 3px;
  height: 18px;
  background: linear-gradient(180deg, var(--azul) 0 34%, var(--linea-suave) 34% 67%, var(--rojo) 67%);
}
.ws-title {
  flex: 0 1 auto;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--tinta);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}
.ws-tabs { display: flex; flex: 0 0 auto; border: 1px solid var(--linea); background: var(--superficie); }
.ws-tab {
  flex: 0 0 auto;
  height: 26px;
  padding: 0 9px;
  border: none;
  background: transparent;
  color: var(--gris);
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
}
.ws-tab + .ws-tab { border-left: 1px solid var(--linea); }
.ws-tab.is-on { background: var(--acento); color: #fff; }
.ws-devices { display: flex; flex: 0 0 auto; border: 1px solid var(--linea); background: var(--superficie); }
.ws-dev {
  flex: 0 0 auto;
  width: 27px;
  height: 26px;
  border: none;
  background: transparent;
  color: var(--gris);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.ws-dev + .ws-dev { border-left: 1px solid var(--linea); }
.ws-dev.is-on { background: var(--acento); color: #fff; }
.ws-spacer { flex: 1; min-width: 8px; }
.ws-versions {
  flex: 0 0 auto;
  height: 26px;
  border: 1px solid var(--linea);
  background: var(--superficie);
  color: var(--texto);
  font-family: var(--mono);
  font-size: 11px;
  padding: 0 4px;
  outline: none;
}
.ws-btn {
  flex: 0 0 auto;
  width: 28px;
  height: 26px;
  border: 1px solid var(--linea);
  background: var(--superficie);
  color: var(--texto-suave);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.ws-btn:hover { background: var(--acento); color: #fff; }
.ws-btn--close:hover { background: var(--rojo); color: #fff; border-color: var(--rojo); }

/* Diagnóstico del artefacto: error de JavaScript o recurso bloqueado por la
   política de seguridad. Sin esto, un fallo del artefacto era un lienzo en
   blanco sin ninguna explicación. */
.ws-alert {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--aviso) 28%, transparent);
  background: color-mix(in srgb, var(--aviso) 9%, transparent);
  color: var(--aviso);
  font-size: 11.5px;
  line-height: 1.5;
}
.ws-alert[hidden] { display: none; }
.ws-alert .ms { flex: none; margin-top: 1px; }
.ws-alert__text { flex: 1; word-break: break-word; font-family: var(--mono); font-size: 10.5px; }
.ws-alert__close {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px; height: 20px;
  border: none; border-radius: 4px;
  background: transparent; color: inherit;
  cursor: pointer; opacity: .65;
}
.ws-alert__close:hover { opacity: 1; background: color-mix(in srgb, var(--aviso) 16%, transparent); }

.ws-body { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--papel-2); }
.ws-stage { flex: 1; min-height: 0; display: flex; justify-content: center; overflow: auto; }
.ws-stage--pad { padding: 16px; }
/* El artefacto es contenido independiente: se previsualiza sobre lienzo
   blanco, como en un navegador. Heredar el tema oscuro de la aplicación
   dejaba el visor en negro cuando el HTML no declaraba su propio fondo. */
.ws-frame {
  width: 100%; max-width: 100%; height: 100%;
  border: 0;
  background: #FFFFFF;
  color-scheme: light;
}
.ws-frame--dev { box-shadow: 0 14px 40px -18px rgba(0, 0, 0, .5); }
.ws-code {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 15px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--papel-3);
  background: var(--acento);
  white-space: pre;
}
.ws-note { padding: 24px; color: var(--gris); font-size: 13px; }

.ws-diff { flex: 1; min-height: 0; overflow: auto; background: var(--superficie); }
.ws-diff__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--linea-suave);
  background: var(--panel);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--texto-suave);
  position: sticky;
  top: 0;
}
.ws-diff__file { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-diff__add { flex: 0 0 auto; color: var(--verde); }
.ws-diff__del { flex: 0 0 auto; color: var(--rojo); }
.diff-line { display: flex; font-family: var(--mono); font-size: 12px; line-height: 1.6; }
.diff-line--add { background: rgba(62, 230, 160, .10); }
.diff-line--del { background: var(--peligro-suave); }
.diff-line__n {
  flex: 0 0 44px;
  text-align: right;
  padding: 0 9px 0 0;
  color: var(--gris-tenue);
  user-select: none;
}
.diff-line__mark { flex: 0 0 16px; user-select: none; }
.diff-line--add .diff-line__mark { color: var(--verde); }
.diff-line--del .diff-line__mark { color: var(--rojo); }
.diff-line__mark--ctx { color: var(--gris-tenue); }
.diff-line__text {
  flex: 1;
  min-width: 0;
  color: var(--texto);
  white-space: pre-wrap;
  word-break: break-word;
  padding-right: 12px;
}

.ws-console {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--acento);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.console-line { display: flex; gap: 9px; font-family: var(--mono); font-size: 11.5px; line-height: 1.55; }
.console-line__time { flex: 0 0 auto; color: var(--tinta-4); }
.console-line__tag { flex: 0 0 auto; text-transform: uppercase; font-size: 10px; padding-top: 1px; }
.console-line__tag--err { color: var(--cl-rojo-claro); }
.console-line__tag--adv { color: var(--aviso); }
.console-line__tag--log { color: var(--cl-azul-claro); }
.console-line__text {
  flex: 1;
  min-width: 0;
  color: var(--linea-2);
  word-break: break-word;
  white-space: pre-wrap;
}
.console-caret {
  display: flex;
  gap: 8px;
  align-items: center;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--gris);
  padding-top: 4px;
}
.console-caret__prompt { color: var(--rojo); }
.console-caret__blink { width: 7px; height: 13px; background: var(--papel-3); animation: kPulse 1s steps(1) infinite; }

/* ══════════════════════════════════════════════════════════════
   Barra superior: auto-aprobar
   ══════════════════════════════════════════════════════════════ */
.auto-approve {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--linea);
  background: var(--superficie);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--texto-suave);
  cursor: pointer;
  white-space: nowrap;
}
.auto-approve input {
  accent-color: var(--rojo);
  width: 14px;
  height: 14px;
  margin: 0;
}
.auto-approve .ms { color: var(--azul); }

/* ══════════════════════════════════════════════════════════════
   Composer: adjuntos + micrófono
   ══════════════════════════════════════════════════════════════ */
.attach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 9px 10px 3px;
}
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  max-width: 100%;
  height: 27px;
  padding: 0 6px 0 9px;
  border: 1px solid var(--linea);
  background: var(--panel);
  color: var(--texto);
  font-family: var(--mono);
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
}
.attach-chip__icon { flex: 0 0 auto; font-size: 15px; color: var(--azul); }
.attach-chip__name { overflow: hidden; text-overflow: ellipsis; }
.attach-chip__remove {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: var(--gris-suave);
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
}
.attach-chip__remove:hover { color: var(--rojo); }

.tool-btn--mic.is-listening { background: var(--rojo); color: #fff; }

/* ══════════════════════════════════════════════════════════════
   Mensajes: checkpoint / rewind (v2)
   ══════════════════════════════════════════════════════════════ */
.msg__checkpoint {
  margin-top: 2px;
  border: 1px solid var(--linea);
  background: var(--superficie);
  color: var(--gris);
  font-family: var(--mono);
  font-size: 10px;
  padding: 3px 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.msg__checkpoint:hover { border-color: var(--rojo); color: var(--rojo); }

/* Plan de trabajo (modo agente) */
.plan-card {
  border: 1px solid var(--linea);
  background: var(--superficie);
  margin-bottom: 14px;
}
.plan-card__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--linea-suave);
  background: var(--panel);
}
.plan-card__head .ms { font-size: 16px; color: var(--azul); }
.plan-card__title {
  flex: 1;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .1em;
  color: var(--texto-suave);
}
.plan-card__progress {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--gris-suave);
}
.plan-card__steps { display: flex; flex-direction: column; }
.plan-step { border-bottom: 1px solid var(--papel-3); }
.plan-step:last-child { border-bottom: none; }
.plan-step__btn {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.plan-step__btn:hover { background: var(--superficie); }
.plan-step__btn.is-running { background: var(--panel); }
.plan-step__icon { flex: 0 0 auto; font-size: 17px; margin-top: 1px; }
.plan-step__icon--done { color: var(--verde); }
.plan-step__icon--running { color: var(--azul); animation: kSpin 1s linear infinite; }
.plan-step__icon--denied { color: var(--rojo); }
.plan-step__icon--pending { color: var(--gris-tenue); }
.plan-step__icon--collapse { color: var(--gris-tenue); font-size: 16px; }
.plan-step__info { flex: 1; min-width: 0; }
.plan-step__title { display: block; font-size: 13.5px; color: var(--tinta); text-wrap: pretty; }
.plan-step__detail {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--gris-suave);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.plan-step__output {
  margin: 0;
  padding: 11px 12px 13px 39px;
  background: var(--acento);
  color: var(--papel-3);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.65;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Bloque de aprobación */
.approval {
  border: 1px solid var(--rojo);
  background: var(--peligro-suave);
  padding: 13px 14px;
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
.approval__icon { flex: 0 0 auto; font-size: 19px; color: var(--rojo); }
.approval__text { flex: 1; min-width: 180px; font-size: 13.5px; color: var(--tinta); text-wrap: pretty; }
.approval__actions { display: flex; gap: 7px; flex: 0 0 auto; }
.approval__allow {
  height: 32px;
  padding: 0 13px;
  border: 1px solid var(--linea-2);
  background: var(--acento);
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.approval__allow:hover { background: var(--rojo); border-color: var(--rojo); }
.approval__deny {
  height: 32px;
  padding: 0 13px;
  border: 1px solid var(--linea);
  background: var(--superficie);
  color: var(--texto-suave);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.approval__deny:hover { border-color: var(--acento); color: var(--tinta); }

/* ══════════════════════════════════════════════════════════════
   Paleta de comandos (Ctrl+K)
   ══════════════════════════════════════════════════════════════ */
/* ── Acceso (entrar / crear cuenta) ─────────────────────────
   Vive dentro del chat para no perder la conversación en curso.
   Hereda la estética de la portada: superficie plana, sombra dura y
   la franja tricolor como sello. */
.auth-modal {
  position: absolute;
  inset: 0;
  z-index: 140;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, .42);
  overflow-y: auto;
}
.auth-modal[hidden] { display: none; }

.auth-modal__box {
  position: relative;
  width: min(392px, 100%);
  padding: 22px 24px 20px;
  background: var(--superficie);
  border: 1px solid var(--linea-2);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, .18);
}
/* Franja tricolor: el sello de la marca en toda superficie propia. */
.auth-modal__box::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg,
    var(--azul) 0 33.33%, #fff 33.33% 66.66%, var(--rojo) 66.66% 100%);
}

.auth-modal__head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
}
.auth-modal__spark { color: var(--azul); font-size: 15px; }
.auth-modal__brand {
  flex: 1;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .22em;
  color: var(--tinta);
}
.auth-modal__close {
  display: grid; place-items: center;
  width: 26px; height: 26px;
  border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--gris-suave);
  cursor: pointer;
}
.auth-modal__close:hover { border-color: var(--linea); color: var(--tinta); }

.auth-tabs { display: flex; gap: 0; margin-bottom: 18px; border-bottom: 1px solid var(--linea); }
.auth-tab {
  flex: 1;
  padding: 9px 4px;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: transparent;
  color: var(--gris-suave);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .16em;
  cursor: pointer;
  transition: color var(--transicion), border-color var(--transicion);
}
.auth-tab:hover { color: var(--tinta); }
.auth-tab.is-on { color: var(--tinta); border-bottom-color: var(--azul); }

.auth-form { display: flex; flex-direction: column; gap: 13px; }
.auth-field { display: flex; flex-direction: column; gap: 5px; }
.auth-field[hidden] { display: none; }
.auth-field__label {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--gris-suave);
}
.auth-field input {
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--linea);
  border-radius: var(--r-sm);
  background: var(--panel);
  color: var(--tinta);
  font-size: 13.5px;
  outline: none;
  transition: border-color var(--transicion);
}
.auth-field input:focus { border-color: var(--azul); }
.auth-field input::placeholder { color: var(--gris-tenue); }

.auth-error, .auth-ok {
  margin: 0;
  padding: 8px 11px;
  border-radius: var(--r-sm);
  font-size: 12px;
  line-height: 1.45;
}
.auth-error[hidden], .auth-ok[hidden] { display: none; }
.auth-error {
  color: var(--rojo);
  background: color-mix(in srgb, var(--rojo) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--rojo) 26%, transparent);
}
.auth-ok {
  color: var(--azul);
  background: color-mix(in srgb, var(--azul) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--azul) 26%, transparent);
}

.auth-submit { width: 100%; justify-content: center; height: 40px; }
.auth-submit:disabled { opacity: .55; cursor: progress; }

.auth-link {
  border: none;
  background: transparent;
  color: var(--gris-suave);
  font-size: 11.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.auth-link:hover { color: var(--tinta); }
.auth-link[hidden] { display: none; }

.auth-sep {
  display: flex; align-items: center; gap: 10px;
  margin: 16px 0 12px;
  font-family: var(--mono); font-size: 10px; color: var(--gris-tenue);
}
.auth-sep[hidden] { display: none; }
.auth-sep::before, .auth-sep::after {
  content: ''; flex: 1; height: 1px; background: var(--linea);
}

.auth-google {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px;
  border: 1px solid var(--linea);
  border-radius: var(--r-sm);
  color: var(--texto);
  font-size: 13px;
  text-decoration: none;
  transition: border-color var(--transicion);
}
.auth-google:hover { border-color: var(--linea-fuerte); }
.auth-google[hidden] { display: none; }

.auth-note {
  margin: 16px 0 0;
  font-size: 11px;
  line-height: 1.55;
  color: var(--gris-tenue);
}

/* La tarjeta de usuario pasó a ser un botón: abre el acceso o la cuenta.
   Al cambiar de <div> a <button> hay que anular el fondo y el borde que el
   navegador da por defecto, o la tarjeta se ve como un botón gris del
   sistema sobre el panel oscuro. El borde superior se vuelve a declarar
   porque `border: 0` también lo habría borrado. */
.user-card {
  width: 100%;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-top: 1px solid var(--linea-suave);
  -webkit-appearance: none;
  appearance: none;
}
.user-card.is-guest .user-card__plan { color: var(--azul); }

.palette {
  position: absolute;
  inset: 0;
  z-index: 120;
  background: rgba(0, 0, 0, .32);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 80px 20px 20px;
}
.palette__box {
  width: min(560px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--superficie);
  border: 1px solid var(--linea-2);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, .18);
}
.palette__input {
  flex: 0 0 auto;
  width: 100%;
  height: 48px;
  border: none;
  border-bottom: 1px solid var(--tinta);
  outline: none;
  padding: 0 15px;
  font-size: 15.5px;
  background: transparent;
  color: var(--tinta);
}
.palette__items { flex: 1; min-height: 0; overflow-y: auto; }
.palette__item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 15px;
  border: none;
  border-bottom: 1px solid var(--papel-3);
  background: transparent;
  color: var(--texto);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.palette__item:hover { background: var(--acento); color: #fff; }
.palette__icon { flex: 0 0 auto; font-size: 18px; color: var(--azul); }
.palette__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette__hint { flex: 0 0 auto; font-family: var(--mono); font-size: 10.5px; color: var(--gris-suave); }
.palette__empty { padding: 16px; font-size: 13px; color: var(--gris-suave); }

/* ══════════════════════════════════════════════════════════════
   Responsive
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    max-width: 82vw;
    transform: translateX(-105%);
    box-shadow: 12px 0 40px rgba(0, 0, 0, .25);
    margin-left: 0;
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar.is-hidden { margin-left: 0; }
  .empty__title { font-size: 36px; }
  .msg__meta { flex: 0 0 52px; }
  .composer__hint { display: none; }
  .ws-handle { display: none; }
  .workshop.is-open {
    position: fixed;
    inset: 0;
    z-index: 150;
    width: 100%;
    min-width: 0;
    border-left: none;
  }
}

/* ══════════════════════════════════════════════════════════════
   Markdown de las respuestas
   Jerarquía editorial: los títulos usan la serif de marca y el
   cuerpo mantiene una medida cómoda de lectura.
   ══════════════════════════════════════════════════════════════ */
.msg__text.md { line-height: 1.68; font-size: 15px; color: var(--texto); }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }

.md p { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { font-family: var(--serif); font-weight: 400; letter-spacing: -.01em; line-height: 1.25; color: var(--tinta); margin: 22px 0 10px; }
.md h1 { font-size: 27px; }
.md h2 { font-size: 23px; }
.md h3 { font-size: 19px; }
.md h4, .md h5, .md h6 { font-size: 16px; font-family: var(--sans); font-weight: 600; }
.md h2, .md h3 { padding-bottom: 6px; border-bottom: 1px solid var(--linea); }

.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md ul li, .md ol li { margin: 5px 0; }
.md ul li::marker, .md ol li::marker { color: var(--azul); }
.md ol li::marker { font-variant-numeric: tabular-nums; font-weight: 600; }

.md blockquote {
  margin: 0 0 14px; padding: 2px 0 2px 16px;
  border-left: 3px solid var(--azul);
  color: var(--texto-suave); background: var(--acento-suave);
  border-radius: 0 var(--r-xs) var(--r-xs) 0;
}
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6r { border: 0; border-top: 1px solid var(--linea); margin: 20px 0; }

.md code {
  font-family: var(--mono); font-size: .88em;
  background: var(--papel-3); color: var(--tinta);
  padding: 2px 6px; border-radius: var(--r-xs);
  border: 1px solid var(--linea);
  overflow-wrap: anywhere;
}
.md a { color: var(--azul); text-decoration-color: color-mix(in srgb, var(--azul) 40%, transparent); }
.md a:hover { color: var(--rojo); }

/* Marcador de evidencia [E1] que emite el backend */
.md .md-cite {
  display: inline-block; font-family: var(--mono); font-size: 11px;
  background: var(--acento-suave); color: var(--azul);
  border: 1px solid color-mix(in srgb, var(--azul) 30%, transparent);
  border-radius: 999px; padding: 0 6px; margin: 0 1px; vertical-align: 1px;
}

.md .md-task { display: inline-flex; align-items: baseline; gap: 7px; }
.md .md-task::before {
  content: '○'; color: var(--gris); font-size: 13px;
}
.md .md-task.is-done::before { content: '●'; color: var(--verde); }
.md .md-task.is-done { color: var(--texto-suave); text-decoration: line-through; text-decoration-color: var(--linea-fuerte); }

/* Tablas: siempre con scroll propio, nunca desbordan el hilo */
.md .markdown-table { display: block; overflow-x: auto; max-width: 100%; margin: 0 0 14px; border: 1px solid var(--linea); border-radius: var(--r-sm); }
.md .markdown-table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.md .markdown-table th, .md .markdown-table td { padding: 9px 13px; border-bottom: 1px solid var(--linea); }
.md .markdown-table thead th {
  background: var(--papel-2); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .06em; color: var(--texto-suave);
  position: sticky; top: 0;
}
.md .markdown-table tbody tr:last-child td { border-bottom: 0; }
.md .markdown-table tbody tr:hover { background: var(--hover); }

/* ── Resaltado de sintaxis ─────────────────────────────────── */
.code-card__pre .tok--kw      { color: var(--tok-kw); }
.code-card__pre .tok--string  { color: var(--tok-string); }
.code-card__pre .tok--number  { color: var(--tok-number); }
.code-card__pre .tok--comment { color: var(--tok-comment); font-style: italic; }
.code-card__pre .tok--fn      { color: var(--tok-fn); }
.code-card__pre .tok--tag     { color: var(--tok-tag); }
.code-card__pre .tok--attr    { color: var(--tok-attr); }

.code-card__meta { font-family: var(--mono); font-size: 10.5px; color: var(--gris-suave); margin-right: 4px; }

/* ── Aviso de respuesta truncada ───────────────────────────── */
.msg__trunc {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px; padding: 9px 13px;
  font-size: 12.5px; color: var(--aviso);
  background: color-mix(in srgb, var(--aviso) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--aviso) 26%, transparent);
  border-radius: var(--r-sm);
}

/* ── Galería de la búsqueda visual ─────────────────────────── */
.img-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.img-card {
  position: relative;
  display: block;
  overflow: hidden;
  border: 1px solid var(--linea);
  border-radius: var(--r-sm);
  background: var(--panel);
  text-decoration: none;
  transition: border-color var(--transicion);
}
.img-card:hover { border-color: var(--azul); }
.img-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}
.img-card__cap {
  display: block;
  padding: 5px 8px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: .06em;
  color: var(--gris-tenue);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Selector de especialidad ──────────────────────────────── */
.cap-select {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px;
  border: 1px solid var(--linea); border-radius: var(--r-sm);
  background: var(--panel); color: var(--texto-suave);
  font-size: 11.5px; cursor: pointer;
  transition: border-color var(--transicion);
}
.cap-select:hover { border-color: var(--linea-fuerte); }
.cap-select:focus-within { border-color: var(--azul); }
.cap-select select {
  border: 0; background: none; color: inherit;
  font-size: 11.5px; font-weight: 600; letter-spacing: .04em;
  cursor: pointer; outline: none; padding-right: 2px;
}

/* ── Arrastrar archivos sobre el hilo ──────────────────────── */
.thread.is-dropping {
  outline: 2px dashed var(--azul);
  outline-offset: -10px;
  background: var(--acento-suave);
}

/* ── Estados de los adjuntos ───────────────────────────────── */
.attach-chip.is-error { border-color: color-mix(in srgb, var(--rojo) 45%, transparent); color: var(--rojo); }
.attach-chip.is-loading { opacity: .65; }
.attach-chip.is-loading .attach-chip__icon { animation: kachai-pulso 1.1s ease-in-out infinite; }
@keyframes kachai-pulso { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }

/* Alineación de columnas que emite el renderizador */
.md .markdown-table-align-center { text-align: center; }
.md .markdown-table-align-right  { text-align: right; }

/* Bloques de código dentro del Markdown (fuera de las tarjetas del chat) */
.md pre {
  background: var(--code-fondo); color: var(--code-tinta);
  padding: 14px 16px; border-radius: var(--r-sm);
  overflow-x: auto; margin: 0 0 14px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
}
.md pre code { background: none; border: 0; padding: 0; color: inherit; font-size: inherit; }
.md pre .tok--kw { color: var(--tok-kw); }
.md pre .tok--string { color: var(--tok-string); }
.md pre .tok--number { color: var(--tok-number); }
.md pre .tok--comment { color: var(--tok-comment); font-style: italic; }
.md pre .tok--fn { color: var(--tok-fn); }
.md pre .tok--tag { color: var(--tok-tag); }
.md pre .tok--attr { color: var(--tok-attr); }
