/* ==========================================================================
   Cola de contacto — Paquetes Flex
   Consola operativa: densidad alta, color semántico, monoespaciada para
   identificadores que se comparan dígito a dígito contra la pantalla de Flex.
   ========================================================================== */

/* --- Tokens ------------------------------------------------------------- */

:root {
  color-scheme: light dark;

  --font-ui: 'Segoe UI Variable Text', 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Mono', 'Cascadia Code', Consolas, 'SF Mono', Menlo, monospace;

  --bg: oklch(97.2% 0.004 265);
  --surface: oklch(100% 0 0);
  --surface-2: oklch(98.6% 0.003 265);
  --surface-3: oklch(96.4% 0.005 265);
  --border: oklch(91.5% 0.006 265);
  --border-soft: oklch(94.5% 0.005 265);
  --border-strong: oklch(84% 0.009 265);

  --text: oklch(24% 0.014 265);
  --text-2: oklch(50% 0.012 265);
  /* 55%: el mínimo que mantiene AA (4.5:1) en la línea de zona/cadete a 12px. */
  --text-3: oklch(55% 0.012 265);

  --accent: oklch(52% 0.17 265);
  --accent-ink: oklch(100% 0 0);
  --ok: oklch(56% 0.13 155);
  --ok-soft: oklch(95.5% 0.035 155);
  --danger: oklch(55% 0.2 25);
  --danger-soft: oklch(96% 0.03 25);

  /* Prioridad — el color es información, no decoración */
  --t1: oklch(56% 0.2 25);
  --t1-soft: oklch(95.5% 0.035 25);
  --t2: oklch(62% 0.15 62);
  --t2-soft: oklch(96% 0.05 75);
  --t3: oklch(55% 0.14 245);
  --t3-soft: oklch(96% 0.035 245);
  --t4: oklch(58% 0.02 265);
  --t4-soft: oklch(96.5% 0.004 265);

  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 14px;

  --shadow-sm: 0 1px 2px oklch(20% 0.02 265 / 0.05);
  --shadow-md: 0 1px 2px oklch(20% 0.02 265 / 0.06), 0 4px 12px oklch(20% 0.02 265 / 0.06);
  --shadow-lg: 0 2px 4px oklch(20% 0.02 265 / 0.06), 0 12px 32px oklch(20% 0.02 265 / 0.12);

  --ease: cubic-bezier(0.2, 0, 0.15, 1);
  --fast: 130ms;
  --slow: 260ms;

  --toolbar-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(17.5% 0.012 265);
    --surface: oklch(21.5% 0.014 265);
    --surface-2: oklch(24% 0.015 265);
    --surface-3: oklch(27% 0.016 265);
    --border: oklch(30% 0.016 265);
    --border-soft: oklch(26% 0.014 265);
    --border-strong: oklch(38% 0.018 265);

    --text: oklch(95% 0.006 265);
    --text-2: oklch(72% 0.012 265);
    --text-3: oklch(63% 0.012 265);

    --accent: oklch(68% 0.16 265);
    --accent-ink: oklch(16% 0.02 265);
    --ok: oklch(72% 0.15 155);
    --ok-soft: oklch(28% 0.05 155);
    --danger: oklch(70% 0.17 25);
    --danger-soft: oklch(29% 0.06 25);

    --t1: oklch(70% 0.17 25);
    --t1-soft: oklch(29% 0.06 25);
    --t2: oklch(76% 0.14 72);
    --t2-soft: oklch(30% 0.05 72);
    --t3: oklch(70% 0.13 245);
    --t3-soft: oklch(29% 0.05 245);
    --t4: oklch(68% 0.02 265);
    --t4-soft: oklch(28% 0.008 265);

    --shadow-sm: 0 1px 2px oklch(0% 0 0 / 0.3);
    --shadow-md: 0 1px 2px oklch(0% 0 0 / 0.3), 0 4px 12px oklch(0% 0 0 / 0.35);
    --shadow-lg: 0 2px 4px oklch(0% 0 0 / 0.3), 0 12px 32px oklch(0% 0 0 / 0.45);
  }
}

/* --- Base --------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
}

.shell {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 24px 64px;
}

:where(button, input, select, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* --- Masthead ----------------------------------------------------------- */

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 32px 0 24px;
}

.masthead__title {
  margin: 0;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.masthead__meta {
  margin: 3px 0 0;
  color: var(--text-3);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.masthead__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Controles ---------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  transition-property: transform, background-color, box-shadow, border-color, opacity;
  transition-duration: var(--fast);
  transition-timing-function: var(--ease);
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-sm);
}

.btn--primary:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }

.filepick {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  max-width: 300px;
  padding: 0 14px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  transition-property: border-color, color, background-color;
  transition-duration: var(--fast);
  transition-timing-function: var(--ease);
}

.filepick:hover { border-color: var(--accent); color: var(--text); }
.filepick:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.filepick input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.filepick__icon { width: 15px; height: 15px; flex: none; }
.filepick__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filepick.has-file { border-style: solid; border-color: var(--accent); color: var(--text); }

/* --- Stats -------------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(96px, 0.6fr)) minmax(220px, 2fr);
  gap: 10px;
  margin-bottom: 18px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.stat__value {
  font-size: 28px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat__label {
  color: var(--text-3);
  font-size: 11px;
  font-weight: 550;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stat--done .stat__value { color: var(--ok); }
.stat--pending .stat__value { color: var(--t2); }

.stat--progress { justify-content: space-between; }

.progress__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.progress__pct {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ok);
}

.progress__track {
  height: 8px;
  margin-top: 12px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.progress__fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ok), color-mix(in oklch, var(--ok), var(--accent) 35%));
  transition: width var(--slow) var(--ease);
}

/* --- Toolbar ------------------------------------------------------------ */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  min-height: var(--toolbar-h);
  padding: 10px 0;
  background: color-mix(in oklch, var(--bg), transparent 8%);
  backdrop-filter: blur(12px);
}

.toolbar::after {
  content: '';
  position: absolute;
  inset: auto 0 0;
  height: 1px;
  background: var(--border);
}

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-2);
}

.segmented__btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 13px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition-property: background-color, color, box-shadow;
  transition-duration: var(--fast);
  transition-timing-function: var(--ease);
}

.segmented__btn:hover { color: var(--text); }

.segmented__btn.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.segmented__count {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-3);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.segmented__btn.is-active .segmented__count {
  background: var(--accent);
  color: var(--accent-ink);
}

.tiers { display: flex; flex-wrap: wrap; gap: 6px; }

.tier-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition-property: background-color, color, border-color, transform;
  transition-duration: var(--fast);
  transition-timing-function: var(--ease);
}

.tier-chip:hover { border-color: var(--border-strong); color: var(--text); }
.tier-chip:active { transform: scale(0.97); }

.tier-chip.is-on {
  border-color: var(--tier);
  background: var(--tier-soft);
  color: var(--text);
}

.tier-chip__dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--tier);
}

.tier-chip__n {
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.tier-chip.is-on .tier-chip__n { color: var(--text-2); }

.search {
  position: relative;
  flex: 1 1 200px;
  min-width: 180px;
  max-width: 340px;
  margin-left: auto;
}

.search__icon {
  position: absolute;
  top: 50%;
  left: 11px;
  width: 15px;
  height: 15px;
  margin-top: -7.5px;
  color: var(--text-3);
  pointer-events: none;
}

.search__input {
  width: 100%;
  min-height: 38px;
  padding: 0 12px 0 34px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  transition-property: border-color, box-shadow;
  transition-duration: var(--fast);
  transition-timing-function: var(--ease);
}

.search__input::placeholder { color: var(--text-3); }
.search__input:hover { border-color: var(--border-strong); }

/* --- Tabla -------------------------------------------------------------- */

.tablewrap {
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  /* `clip` y no `hidden`: recorta las esquinas redondeadas sin volverse
     contenedor de scroll, que rompería el thead sticky. */
  overflow: clip;
}

.queue {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.th {
  position: sticky;
  top: var(--toolbar-h);
  z-index: 10;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-align: left;
  text-transform: uppercase;
}

.th--priority { width: 212px; }
.th--package  { width: 190px; }
.th--dest     { width: 30%; }
.th--note     { width: auto; }
.th--phone    { width: 200px; }

.row {
  --tier: var(--t4);
  --tier-soft: var(--t4-soft);
}

.row[data-tier="1"] { --tier: var(--t1); --tier-soft: var(--t1-soft); }
.row[data-tier="2"] { --tier: var(--t2); --tier-soft: var(--t2-soft); }
.row[data-tier="3"] { --tier: var(--t3); --tier-soft: var(--t3-soft); }

.cell {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
  transition: background-color var(--fast) var(--ease);
}

.row:last-child .cell { border-bottom: 0; }
.row:hover .cell { background: var(--surface-2); }

.cell--priority { box-shadow: inset 3px 0 0 var(--tier); }

/* Celdas compuestas: dos líneas apiladas. Van como bloques y no como flex,
   porque `display:flex` sobre un <td> lo saca del algoritmo de tabla y
   desalinea las filas. */
.cell--package > *,
.cell--dest > * { display: block; }

.ident {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.dest {
  font-weight: 550;
  line-height: 1.3;
  text-wrap: pretty;
}

.sub {
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  color: var(--text-2);
  font-size: 12.5px;
  line-height: 1.4;
  overflow: hidden;
  text-wrap: pretty;
}

.note:empty::before {
  content: 'sin observación';
  color: var(--text-3);
  font-style: italic;
}

/* Selector de prioridad */
.priority {
  width: 100%;
  min-height: 34px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background-color: var(--tier-soft);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='m3 4.5 3 3 3-3' fill='none' stroke='%23888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: right 8px center;
  background-repeat: no-repeat;
  background-size: 12px;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
  appearance: none;
  transition-property: border-color, background-color;
  transition-duration: var(--fast);
  transition-timing-function: var(--ease);
}

.priority:hover { border-color: var(--tier); }

/* Borde punteado = este valor lo fijó una persona, no el clasificador. */
.row.is-overridden .priority {
  border-style: dashed;
  border-color: var(--tier);
}

/* Teléfono — la acción principal de la pantalla */
.phone { position: relative; display: flex; align-items: center; }

.phone__input {
  width: 100%;
  min-height: 38px;
  padding: 0 32px 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  transition-property: border-color, background-color, box-shadow;
  transition-duration: var(--fast);
  transition-timing-function: var(--ease);
}

.phone__input::placeholder { color: var(--text-3); font-family: var(--font-ui); }
.phone__input:hover { border-color: var(--accent); }

.phone__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent), transparent 82%);
}

.phone__mark {
  position: absolute;
  right: 9px;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  color: var(--ok);
  opacity: 0;
  transform: scale(0.7);
  pointer-events: none;
  transition-property: opacity, transform;
  transition-duration: var(--fast);
  transition-timing-function: var(--ease);
}

.phone__mark svg { width: 100%; height: 100%; }

/* Estado: contactado — la fila retrocede visualmente */
.row.is-done .cell--package,
.row.is-done .cell--dest,
.row.is-done .cell--note { opacity: 0.55; }

.row.is-done .phone__mark { opacity: 1; transform: scale(1); }

.row.is-done .phone__input {
  border-color: color-mix(in oklch, var(--ok), transparent 55%);
  background: var(--ok-soft);
}

.row.is-saving .phone__input { border-color: var(--accent); }

.row.is-error .phone__input {
  border-color: var(--danger);
  background: var(--danger-soft);
}

@keyframes saved-flash {
  0%   { background-color: color-mix(in oklch, var(--ok), transparent 78%); }
  100% { background-color: transparent; }
}

.row.just-saved .cell { animation: saved-flash 900ms var(--ease); }

/* --- Placeholder / toast ------------------------------------------------ */

.placeholder { padding: 64px 24px; text-align: center; }

.placeholder__title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  text-wrap: balance;
}

.placeholder__body {
  margin: 0;
  color: var(--text-3);
  font-size: 13px;
  text-wrap: pretty;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 100;
  max-width: min(520px, calc(100vw - 48px));
  padding: 11px 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  font-weight: 500;
  translate: -50% 0;
}

.toast[hidden] { display: none; }

.toast.is-error { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.toast.is-ok { border-color: color-mix(in oklch, var(--ok), transparent 60%); background: var(--ok-soft); }

@keyframes toast-in {
  from { opacity: 0; translate: -50% 12px; }
  to   { opacity: 1; translate: -50% 0; }
}

.toast:not([hidden]) { animation: toast-in 200ms var(--ease); }

/* --- Responsive --------------------------------------------------------- */

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stat--progress { grid-column: 1 / -1; }
  .search { margin-left: 0; max-width: none; }
  .th { position: static; }
}

@media (max-width: 720px) {
  .shell { padding: 0 14px 48px; }
  .th--dest, .cell--dest, .th--note, .cell--note { display: none; }
}

/* ==========================================================================
   Ensayador — /ensayo.html
   Misma consola, otro trabajo: acá no se despacha, se mira decidir. La columna
   izquierda es la conversación tal como la vería el comprador; la derecha, lo
   que el agente eligió para llegar a cada mensaje. Nada de esto tiene paleta
   propia: todo sale de los tokens de arriba.
   ========================================================================== */

/* Botón secundario: el `.btn` pelado se pierde contra el fondo cuando no está
   al lado de un primario. Es un agregado, no un cambio de lo que ya usa la
   cola. */
.btn--quiet {
  border-color: var(--border-strong);
  color: var(--text-2);
  text-decoration: none;
}

.btn--quiet:hover { border-color: var(--accent); color: var(--text); }

/* --- Aviso -------------------------------------------------------------- */
/* Un solo renglón para todo lo que hay que decirle al operador. */

.aviso {
  margin: 0 0 14px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 13px;
  text-wrap: pretty;
}

.aviso.is-error { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.aviso.is-ok { border-color: color-mix(in oklch, var(--ok), transparent 60%); background: var(--ok-soft); }

/* --- Arranque ----------------------------------------------------------- */

.setup {
  padding: 22px 24px 24px;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.setup__title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.setup__lead {
  max-width: 68ch;
  margin: 5px 0 20px;
  color: var(--text-3);
  font-size: 13px;
  text-wrap: pretty;
}

.setup__grid {
  display: grid;
  grid-template-columns: minmax(240px, 1.4fr) minmax(200px, 1fr) auto;
  align-items: start;
  gap: 14px 18px;
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field--action { justify-content: start; padding-top: 23px; }

.field__label {
  color: var(--text-3);
  font-size: 11px;
  font-weight: 550;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.field__control {
  width: 100%;
  min-height: 40px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  transition-property: border-color, box-shadow;
  transition-duration: var(--fast);
  transition-timing-function: var(--ease);
}

.field__control:hover:enabled { border-color: var(--accent); }
.field__control:disabled { opacity: 0.55; cursor: not-allowed; }

.field__hint {
  margin: 0;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.35;
  text-wrap: pretty;
}

.abiertos {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border-soft);
}

.abiertos__title {
  margin: 0 0 10px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.abiertos__list { display: flex; flex-wrap: wrap; gap: 8px; }
/* Área de click cómoda: son la vía de vuelta a un ensayo que quedó abierto. */
.abiertos__list .tier-chip { min-height: 40px; font-variant-numeric: tabular-nums; }

/* --- Las dos columnas --------------------------------------------------- */

.ensayo {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  align-items: start;
  gap: 14px;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  overflow: clip;
}

.panel__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.panel__title {
  margin: 0;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.panel__meta {
  margin: 0;
  min-width: 0;
  color: var(--text-3);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Hilo --------------------------------------------------------------- */

.hilo {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  min-height: 260px;
  max-height: 54vh;
  margin: 0;
  padding: 18px 16px;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.burbuja {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: min(78%, 60ch);
  padding: 9px 12px 10px;
  border: 1px solid var(--border);
  /* Radio concéntrico: la esquina del lado de quien habla se achica al radio
     interior, así la burbuja apunta a su columna. */
  border-radius: var(--r-lg);
  background: var(--surface-2);
}

.burbuja--entrante { border-bottom-left-radius: var(--r-sm); }

.burbuja--saliente {
  align-self: flex-end;
  border-color: color-mix(in oklch, var(--accent), transparent 72%);
  border-bottom-right-radius: var(--r-sm);
  background: color-mix(in oklch, var(--accent), transparent 90%);
}

/* La plantilla no la escribió nadie: es un texto fijo aprobado por Meta con
   dos variables. Se lee distinto a propósito. */
.burbuja--plantilla {
  border-style: dashed;
  border-color: var(--border-strong);
  background: var(--surface-3);
}

.burbuja__meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 550;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.burbuja--saliente .burbuja__meta { justify-content: flex-end; }
.burbuja[data-quien="agente"] .burbuja__quien { color: var(--accent); }
.burbuja[data-quien="operador"] .burbuja__quien { color: var(--t2); }

.burbuja__hora {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-transform: none;
}

.burbuja__texto {
  font-size: 13.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  text-wrap: pretty;
  white-space: pre-wrap;
}

/* --- Composer ----------------------------------------------------------- */

.composer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* Los controles del ensayo se usan de a uno y con intención: 40px, no los
   32px densos de la toolbar de la cola. */
.composer .segmented { align-self: flex-start; }
.composer .segmented__btn { min-height: 40px; }

/* Radios concéntricos: 12 (marco) = 8 (textarea) + 4 (padding). */
.composer__box {
  padding: 4px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface);
  transition-property: border-color, box-shadow;
  transition-duration: var(--fast);
  transition-timing-function: var(--ease);
}

.composer__box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent), transparent 82%);
}

.composer__text {
  display: block;
  width: 100%;
  min-height: 68px;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  resize: vertical;
}

.composer__text:focus { outline: none; }
.composer__text::placeholder { color: var(--text-3); }
.composer__text:disabled { opacity: 0.55; }

.composer__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
}

.composer__hint {
  flex: 1 1 220px;
  margin: 0;
  color: var(--text-3);
  font-size: 12px;
  text-wrap: pretty;
}

.pensando {
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 550;
}

.pensando::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 7px;
  border-radius: 50%;
  background: currentColor;
  vertical-align: 1px;
  animation: latido 900ms var(--ease) infinite;
}

@keyframes latido {
  0%, 100% { opacity: 0.25; }
  50%      { opacity: 1; }
}

/* --- Decisiones --------------------------------------------------------- */

.decisiones {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 62vh;
  margin: 0;
  padding: 14px;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.decisiones:empty { padding: 0; }

/* El color de la herramienta es información: se lee antes que el texto. */
.decision {
  --tono: var(--t4);
  --tono-soft: var(--t4-soft);
  /* Radios concéntricos: 12 (tarjeta) = 6 (cuerpo) + 6 (padding). */
  padding: 6px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--tono);
  border-radius: var(--r-lg);
  background: var(--surface-2);
}

.decision[data-herramienta="confirmar_presencia"] { --tono: var(--ok); --tono-soft: var(--ok-soft); }
.decision[data-herramienta="reprogramar_proximo_dia"] { --tono: var(--t3); --tono-soft: var(--t3-soft); }
.decision[data-herramienta="escalar"] { --tono: var(--t1); --tono-soft: var(--t1-soft); }
.decision[data-herramienta="responder_texto"] { --tono: var(--accent); --tono-soft: var(--t3-soft); }

/* Un fallo de la API no es una decisión del agente: pierde el color de la
   herramienta -que sería mentira- y queda en gris, con su rótulo al lado. */
.decision[data-origen="falla_api"] { --tono: var(--text-3); --tono-soft: var(--surface-3); }

.chip-origen {
  padding: 3px 9px;
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
  color: var(--text-3);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.decision__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 8px;
}

.decision__turno {
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.chip-tool {
  padding: 3px 9px;
  border: 1px solid color-mix(in oklch, var(--tono), transparent 55%);
  border-radius: 999px;
  background: var(--tono-soft);
  color: var(--tono);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.decision__hora {
  margin-left: auto;
  color: var(--text-3);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.decision__cuerpo {
  padding: 10px 11px;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-sm);
  background: var(--surface);
}

.args { margin: 0; }

.args__par {
  display: grid;
  grid-template-columns: minmax(88px, auto) 1fr;
  gap: 4px 12px;
  padding: 3px 0;
}

.args__par + .args__par { border-top: 1px solid var(--border-soft); }

.args__clave {
  color: var(--text-3);
  font-size: 11.5px;
  font-weight: 550;
}

.args__valor {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.4;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

/* Lo único de la decisión que efectivamente le llegó al comprador. */
.cita {
  margin: 0;
  padding-left: 10px;
  border-left: 2px solid color-mix(in oklch, var(--tono), transparent 55%);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  text-wrap: pretty;
}

.args:not([hidden]) + .cita:not([hidden]) { margin-top: 9px; }

.decision__uso {
  display: block;
  margin-top: 9px;
  color: var(--text-3);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.cierre {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 11px 13px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-2);
}

.cierre__label {
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.cierre__texto {
  font-size: 12.5px;
  line-height: 1.45;
  text-wrap: pretty;
}

.vacio {
  margin: 0;
  padding: 40px 24px;
  color: var(--text-3);
  font-size: 13px;
  text-align: center;
  text-wrap: pretty;
}

/* --- Barra de estado ---------------------------------------------------- */

.barra {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  margin-top: 14px;
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: color-mix(in oklch, var(--surface), transparent 6%);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(12px);
}

.barra__stats { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; }

.dato { display: inline-flex; align-items: baseline; gap: 8px; }

.dato__label {
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Cifras tabulares: estos números cambian de valor y no tienen que bailar. */
.dato__valor {
  font-size: 13px;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
}

.estado-chip {
  --tono: var(--t4);
  --tono-soft: var(--t4-soft);
  padding: 3px 10px;
  border: 1px solid color-mix(in oklch, var(--tono), transparent 55%);
  border-radius: 999px;
  background: var(--tono-soft);
  color: var(--tono);
  font-size: 12px;
  font-weight: 600;
}

.barra[data-estado="activa"] .estado-chip { --tono: var(--accent); --tono-soft: var(--t3-soft); }
.barra[data-estado="resuelta"] .estado-chip { --tono: var(--ok); --tono-soft: var(--ok-soft); }
.barra[data-estado="escalada"] .estado-chip { --tono: var(--t1); --tono-soft: var(--t1-soft); }

.export { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.export__input {
  width: 220px;
  min-height: 40px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  transition-property: border-color, box-shadow;
  transition-duration: var(--fast);
  transition-timing-function: var(--ease);
}

.export__input::placeholder { color: var(--text-3); }
.export__input:hover { border-color: var(--accent); }

/* La advertencia de exportar ocupa su propia linea dentro de la barra: es el
   mismo .field__hint que ya se usa en el resto de la pantalla, solo forzado a
   ancho completo porque la barra es flex con wrap. */
.barra .field__hint { flex-basis: 100%; margin: 0; }

/* --- Alto de la ventana ------------------------------------------------- */
/* En pantalla ancha el ensayador ocupa el alto de la ventana y lo único que
   scrollea son las dos listas. Así el composer queda siempre abajo, la barra
   siempre a la vista, y la barra pegada al borde inferior nunca puede quedar
   tapando el botón de enviar mientras la página todavía no se scrolleó. */

@media (min-width: 1101px) {
  .shell--ensayo {
    display: flex;
    flex-direction: column;
    /* `height` y no `min-height`: sólo un alto definido hace que los hijos
       encojan. Con `min-height` el contenedor crece con el contenido, nadie
       encoge y la página vuelve a scrollear. */
    height: 100dvh;
    padding-bottom: 20px;
  }

  .shell--ensayo .ensayo {
    flex: 1 1 auto;
    align-items: stretch;
    min-height: 0;
  }

  /* `min-height: 0` explícito: un item de grid arranca con el mínimo
     automático de su contenido y sin esto el panel se niega a encoger, la
     página vuelve a scrollear y la barra pegada abajo tapa el composer. */
  .shell--ensayo .panel { max-height: 100%; min-height: 0; }

  .shell--ensayo .hilo,
  .shell--ensayo .decisiones {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
  }
}

/* --- Responsive del ensayador ------------------------------------------- */

@media (max-width: 1100px) {
  .ensayo { grid-template-columns: 1fr; }
  .setup__grid { grid-template-columns: 1fr 1fr; }
  .field--action { grid-column: 1 / -1; padding-top: 0; }
  .decisiones { max-height: 46vh; }
}

@media (max-width: 720px) {
  .setup__grid { grid-template-columns: 1fr; }
  .export__input { width: 100%; }
  .burbuja { max-width: 92%; }
}

/* Va al final de la hoja: gana por orden a los `display` de los componentes de
   arriba sin necesidad de `!important`. */
[hidden] { display: none; }

/* --- Accesibilidad de movimiento ---------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
