:root {
  --bg: #f5f4ef;
  --surface: #fbfaf7;
  --field: #ffffff;
  --ink: #1f1e1b;
  --ink-2: #5f5c55;
  --ink-3: #96928a;
  --line: #e4e1d8;
  --line-2: #d6d2c7;
  --hover: #ecebe4;
  --accent: #1f1e1b;
  --accent-ink: #ffffff;
  --rojo: #c8412f;
  --amarillo: #c48a12;
  --verde: #2f8a55;
  --gris: #b5b1a7;
  --code: #efeee8;
  --shadow: 0 1px 2px rgba(31, 30, 27, .04), 0 8px 28px rgba(31, 30, 27, .06);
  --radius: 22px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1b19; --surface: #22211e; --field: #2a2926; --ink: #eceae4; --ink-2: #b4b0a6; --ink-3: #807c73;
    --line: #34332f; --line-2: #45433e; --hover: #2c2b28; --accent: #eceae4; --accent-ink: #1c1b19; --code: #2c2b27;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1b19; --surface: #22211e; --field: #2a2926; --ink: #eceae4; --ink-2: #b4b0a6; --ink-3: #807c73;
  --line: #34332f; --line-2: #45433e; --hover: #2c2b28; --accent: #eceae4; --accent-ink: #1c1b19; --code: #2c2b27;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.6 var(--font); -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; overflow-x: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.oculto { display: none !important; }

/* ---------- barra superior ---------- */
.barra { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); }
.marca { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -.01em; }
.marca .punto { width: 10px; height: 10px; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ink) 10%, transparent); }
.marca small { font-weight: 400; color: var(--ink-3); }
.nav { display: flex; gap: 2px; align-items: center; }
.nav button { display: inline-flex; align-items: center; gap: 7px; border: 0; background: transparent; padding: 7px 11px; border-radius: 10px; color: var(--ink-2); font-size: 14px; }
.nav button:hover { background: var(--hover); color: var(--ink); }
.nav svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--rojo); color: #fff; font-size: 11px; font-weight: 600; display: inline-grid; place-items: center; }
.estado-wa { width: 8px; height: 8px; border-radius: 50%; background: var(--gris); }
.estado-wa.open { background: var(--verde); }

/* ---------- columna principal ---------- */
main { max-width: 780px; margin: 0 auto; padding: 18px 20px 120px; }
.saludo { text-align: center; margin: 7vh 0 22px; }
.saludo h1 { font-size: 30px; font-weight: 500; letter-spacing: -.02em; margin: 0; }
.saludo p { color: var(--ink-3); margin: 6px 0 0; }
.con-mensajes .saludo { display: none; }

.hilo-fila { display: flex; justify-content: space-between; align-items: center; margin: 0 6px 8px; font-size: 13px; color: var(--ink-3); min-height: 22px; }
.hilo-fila button { border: 0; background: none; color: var(--ink-3); padding: 2px 6px; border-radius: 8px; font-size: 13px; }
.hilo-fila button:hover { color: var(--ink); background: var(--hover); }

.composer { position: relative; background: var(--field); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 14px 10px 18px; transition: border-color .15s; }
.composer:focus-within { border-color: var(--line-2); }
.composer textarea { width: 100%; border: 0; outline: 0; resize: none; background: transparent; font-size: 16px; line-height: 1.5; min-height: 26px; max-height: 260px; padding: 0; }
.composer textarea::placeholder { color: var(--ink-3); }
.composer .pie { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.composer .pista { font-size: 12px; color: var(--ink-3); }
.btn-enviar { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; transition: opacity .15s; }
.btn-enviar:disabled { opacity: .25; cursor: default; }
.btn-enviar svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.menciones { position: absolute; left: 12px; top: calc(100% + 6px); z-index: 30; background: var(--field); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 6px; min-width: 260px; max-height: 280px; overflow: auto; }
.menciones div { padding: 7px 10px; border-radius: 9px; cursor: pointer; display: flex; gap: 8px; align-items: center; font-size: 14px; }
.menciones div.activa, .menciones div:hover { background: var(--hover); }
.menciones small { color: var(--ink-3); margin-left: auto; }

.sugerencias { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 16px 0 0; }
.sugerencias button { border: 1px solid var(--line); background: transparent; color: var(--ink-2); border-radius: 999px; padding: 7px 14px; font-size: 13.5px; }
.sugerencias button:hover { background: var(--hover); color: var(--ink); }
.con-mensajes .sugerencias { display: none; }

/* pulso: una franja con un punto por cliente */
.pulso { margin: 14px 6px 0; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--ink-3); }
.pulso .puntos { display: flex; flex-wrap: wrap; gap: 5px; }
.pulso .p { width: 11px; height: 11px; border-radius: 50%; border: 0; padding: 0; background: var(--gris); position: relative; }
.pulso .p:hover { transform: scale(1.35); }
.p.rojo, .dot.rojo { background: var(--rojo); }
.p.amarillo, .dot.amarillo { background: var(--amarillo); }
.p.verde, .dot.verde { background: var(--verde); }
.pulso .resumen button { border: 0; background: none; color: var(--ink-3); text-decoration: underline; text-underline-offset: 3px; padding: 0; font-size: 13px; }
.pulso .resumen button:hover { color: var(--ink); }

/* ---------- conversación (lo más nuevo arriba) ---------- */
.feed { margin-top: 26px; }
.turno { padding: 22px 6px 24px; border-top: 1px solid var(--line); animation: entra .25s ease-out; }
@keyframes entra { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.pregunta { color: var(--ink-2); font-size: 14.5px; white-space: pre-wrap; margin-bottom: 12px; }
.pregunta .quien { display: block; font-size: 12px; color: var(--ink-3); margin-bottom: 2px; }
.pregunta .quien b { font-weight: 600; color: var(--ink-2); }
.actividad { margin: 0 0 12px; font-size: 13px; color: var(--ink-3); }
.actividad .resumen-act { border: 0; background: none; padding: 0; color: var(--ink-3); font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.actividad .resumen-act:hover { color: var(--ink); }
.actividad ul { list-style: none; margin: 6px 0 0; padding: 0 0 0 2px; border-left: 2px solid var(--line); }
.actividad li { padding: 2px 0 2px 12px; display: flex; gap: 8px; align-items: center; }
.actividad li .ms { margin-left: auto; font-variant-numeric: tabular-nums; }
.actividad li.error { color: var(--rojo); }
.actividad li .nota { font-style: italic; }
.giro { width: 11px; height: 11px; border: 1.6px solid var(--line-2); border-top-color: var(--ink-2); border-radius: 50%; animation: gira .8s linear infinite; display: inline-block; flex: none; }
@keyframes gira { to { transform: rotate(360deg); } }
.ok-ic { color: var(--verde); flex: none; }
.pensando { display: inline-flex; gap: 8px; align-items: center; color: var(--ink-3); font-size: 14px; }

.respuesta { font-size: 15.5px; line-height: 1.68; overflow-wrap: anywhere; }
.respuesta > :first-child { margin-top: 0; }
.respuesta > :last-child { margin-bottom: 0; }
.respuesta p { margin: 0 0 .8em; }
.respuesta h1, .respuesta h2, .respuesta h3 { font-size: 1.05em; margin: 1.2em 0 .4em; font-weight: 650; }
.respuesta ul, .respuesta ol { padding-left: 1.3em; margin: 0 0 .8em; }
.respuesta li { margin: .2em 0; }
.respuesta code { font-family: var(--mono); font-size: .86em; background: var(--code); padding: .12em .38em; border-radius: 6px; }
.respuesta pre { background: var(--code); padding: 12px 14px; border-radius: 12px; overflow: auto; }
.respuesta pre code { background: none; padding: 0; }
.respuesta table { border-collapse: collapse; width: 100%; margin: .4em 0 1em; font-size: 14px; display: block; overflow-x: auto; }
.respuesta th, .respuesta td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.respuesta th { font-weight: 600; color: var(--ink-2); font-size: 13px; }
.respuesta img { max-width: min(100%, 360px); border-radius: 12px; border: 1px solid var(--line); display: block; margin: 8px 0; }
.respuesta blockquote { margin: 0 0 .8em; padding-left: 14px; border-left: 3px solid var(--line-2); color: var(--ink-2); }
.respuesta a { text-underline-offset: 3px; }
.respuesta .cursor { display: inline-block; width: 7px; height: 1.05em; background: var(--ink-2); vertical-align: text-bottom; animation: parpadeo 1s steps(1) infinite; margin-left: 1px; }
@keyframes parpadeo { 50% { opacity: 0; } }
.meta { margin-top: 12px; font-size: 12px; color: var(--ink-3); display: flex; gap: 10px; flex-wrap: wrap; }
.meta button { border: 0; background: none; color: var(--ink-3); padding: 0; font-size: 12px; }
.meta button:hover { color: var(--ink); }
.mas-viejo { display: block; margin: 18px auto 0; border: 1px solid var(--line); background: transparent; color: var(--ink-2); border-radius: 999px; padding: 7px 16px; font-size: 13px; }

/* ---------- panel lateral ---------- */
.velo { position: fixed; inset: 0; background: rgba(20, 19, 17, .18); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .2s; }
.velo.on { opacity: 1; pointer-events: auto; }
.panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--surface); border-left: 1px solid var(--line); z-index: 50; transform: translateX(102%); transition: transform .22s ease; display: flex; flex-direction: column; }
.panel.on { transform: none; }
.panel header { display: flex; align-items: center; gap: 10px; padding: 16px 18px 12px; border-bottom: 1px solid var(--line); }
.panel header h2 { font-size: 16px; margin: 0; font-weight: 600; flex: 1; }
.panel header button { border: 0; background: none; color: var(--ink-3); font-size: 22px; line-height: 1; padding: 2px 8px; border-radius: 8px; }
.panel header button:hover { background: var(--hover); color: var(--ink); }
.panel .cuerpo { overflow: auto; padding: 14px 18px 40px; flex: 1; }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 600; margin: 22px 0 8px; }
.panel h3:first-child { margin-top: 4px; }
.fila { display: flex; gap: 10px; align-items: flex-start; padding: 10px 8px; border-radius: 12px; cursor: pointer; }
.fila:hover { background: var(--hover); }
.fila .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gris); margin-top: 7px; flex: none; }
.fila .txt { flex: 1; min-width: 0; }
.fila .t1 { font-weight: 550; display: flex; gap: 8px; align-items: baseline; }
.fila .t1 small { font-weight: 400; color: var(--ink-3); }
.fila .t2 { font-size: 13px; color: var(--ink-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chip { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2); }
.boton { border: 1px solid var(--line-2); background: var(--field); border-radius: 10px; padding: 7px 13px; font-size: 13.5px; }
.boton:hover { background: var(--hover); }
.boton.primario { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.boton.primario:hover { opacity: .88; }
.boton.peligro { color: var(--rojo); }
.acciones-fila { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.campo { display: block; margin: 0 0 12px; }
.campo span { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 4px; }
.campo input, .campo textarea, .campo select { width: 100%; border: 1px solid var(--line); background: var(--field); border-radius: 10px; padding: 8px 10px; font-size: 14px; outline: 0; }
.campo textarea { min-height: 120px; resize: vertical; line-height: 1.5; font-family: var(--font); }
.campo input:focus, .campo textarea:focus, .campo select:focus { border-color: var(--line-2); }
.nota-gris { font-size: 12.5px; color: var(--ink-3); margin: 4px 0 10px; }
.tarjeta { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 0 0 10px; background: var(--field); }
.tarjeta .t1 { font-weight: 550; display: flex; gap: 8px; align-items: center; }
.tarjeta .t2 { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.tarjeta details { margin-top: 8px; font-size: 13px; }
.tarjeta details summary { cursor: pointer; color: var(--ink-3); }
.switch { margin-left: auto; position: relative; width: 34px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: var(--line-2); border-radius: 20px; transition: .2s; }
.switch i::after { content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + i { background: var(--verde); }
.switch input:checked + i::after { transform: translateX(14px); }
.ficha-md { font-size: 14px; }
.ficha-md table { font-size: 13px; }
.ficha-md td { white-space: normal; }
.qr { display: grid; place-items: center; padding: 14px; background: #fff; border-radius: 16px; border: 1px solid var(--line); margin: 8px 0; min-height: 120px; }
.qr img { width: 250px; height: 250px; image-rendering: pixelated; }
.codigo { font: 600 26px/1 var(--mono); letter-spacing: .14em; text-align: center; padding: 14px; border: 1px dashed var(--line-2); border-radius: 14px; margin: 8px 0; }
.historia-pulso { display: flex; gap: 4px; margin: 4px 0 10px; }
.historia-pulso span { width: 14px; height: 14px; border-radius: 4px; background: var(--gris); }
.historia-pulso span.rojo { background: var(--rojo); } .historia-pulso span.amarillo { background: var(--amarillo); } .historia-pulso span.verde { background: var(--verde); }
.tabs { display: flex; gap: 4px; margin: 0 0 12px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 5px 12px; font-size: 13px; color: var(--ink-2); }
.tabs button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.aviso { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 12px; font-size: 14px; z-index: 80; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }

@media (max-width: 720px) {
  .barra { padding: 10px 12px; }
  .nav button span.lbl { display: none; }
  .nav button { padding: 8px; }
  main { padding: 10px 16px 100px; }
  .saludo { margin: 4vh 0 16px; }
  .saludo h1 { font-size: 24px; }
  .composer textarea { font-size: 16px; }
  .composer .pista { display: none; }
  .respuesta { font-size: 15px; }
}

/* colores del semáforo en listas (van al final para ganarle a .fila .dot) */
.fila .dot.rojo, .menciones .dot.rojo { background: var(--rojo); }
.fila .dot.amarillo, .menciones .dot.amarillo { background: var(--amarillo); }
.fila .dot.verde, .menciones .dot.verde { background: var(--verde); }
.menciones .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gris); flex: none; }
.btn-enviar { margin-left: auto; }

.aviso-ia { margin: 4px 0 14px; padding: 11px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.5; color: var(--ink); background: color-mix(in srgb, var(--rojo) 9%, var(--bg)); border: 1px solid color-mix(in srgb, var(--rojo) 30%, var(--bg)); }
.aviso-ia b { font-weight: 600; }

.barras { display: flex; align-items: flex-end; gap: 5px; margin-top: 12px; height: 78px; }
.barras div { display: flex; flex-direction: column; align-items: center; gap: 3px; flex: 1; min-width: 0; }
.barras i { display: block; width: 100%; max-width: 22px; background: var(--ink-2); border-radius: 4px 4px 1px 1px; opacity: .75; }
.barras small { font-size: 10.5px; color: var(--ink-3); }

/* bloques por cliente dentro de la conversación */
.bloque { border-top: 1px solid var(--line); padding: 16px 0 4px; animation: entra .25s ease-out; }
.bloque > .turno { border-top: 0; padding-top: 10px; }
.bloque-cab { display: flex; align-items: center; gap: 8px; margin: 0 6px; font-size: 13.5px; }
.bloque-cab .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gris); flex: none; }
.bloque-cab .dot.rojo { background: var(--rojo); } .bloque-cab .dot.amarillo { background: var(--amarillo); } .bloque-cab .dot.verde { background: var(--verde); }
.bloque-nombre { border: 0; background: none; padding: 0; font-weight: 600; color: var(--ink); font-size: 14px; }
.bloque-nombre:hover { text-decoration: underline; text-underline-offset: 3px; }
.bloque-cab .n { color: var(--ink-3); font-size: 12px; background: var(--hover); padding: 1px 9px; border-radius: 999px; }
.ver-anteriores { display: block; margin: -8px 6px 14px; border: 0; background: none; padding: 0; color: var(--ink-3); font-size: 13px; }
.ver-anteriores:hover { color: var(--ink); }
.anteriores { margin: 0 0 14px 8px; padding-left: 16px; border-left: 2px solid var(--line); }
.anteriores .turno { padding: 14px 0 16px; border-top: 1px dashed var(--line); animation: none; }
.anteriores .turno:first-child { border-top: 0; padding-top: 4px; }

/* revisión en vivo */
.progreso { margin: 0 0 12px; font-size: 13px; color: var(--ink-2); }
.barra-prog { height: 4px; background: var(--hover); border-radius: 4px; overflow: hidden; margin-bottom: 8px; }
.barra-prog i { display: block; height: 100%; background: var(--ink-2); transition: width .4s; }
.txt-prog { display: inline-flex; gap: 8px; align-items: center; }
.lista-revision li { align-items: flex-start; padding: 6px 0 6px 12px; }
.lista-revision li > .giro, .lista-revision li > .dot { margin-top: 5px; }
.lista-revision .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gris); flex: none; }
.lista-revision .dot.rojo { background: var(--rojo); } .lista-revision .dot.amarillo { background: var(--amarillo); } .lista-revision .dot.verde { background: var(--verde); }
.lista-revision .pasos { font-size: 12.5px; color: var(--ink-3); line-height: 1.5; }
.lista-revision .alerta { color: var(--ink); }
