/* Asistente (carril F4): capa sobre cualquier pantalla (hoja inferior en móvil, lateral en tableta, panel fijo en
   escritorio), mensajes, recibos, propuestas, sugerencias y grabación. Solo tokens de base.css: claro y Noche. */

/* ---------- Hoja: el cuerpo no se desplaza; dentro, la conversación sí ---------- */
.sheet.asheet:not(.has-foot) .sheet-body { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.sheet-layer[data-mode="bottom"] .sheet.asheet .sheet-head { min-height: 44px; padding-top: 0; padding-bottom: 0; }
.as-expand { color: var(--ink-2); }
.sheet-layer:not([data-mode="bottom"]) .as-expand { display: none; }
/* Velo más suave que el de las fichas: la pantalla de debajo se sigue leyendo. */
.as-layer.open .sheet-backdrop { opacity: .5; }
/* Con el teclado abierto (móvil), la hoja ocupa lo visible encima de él. */
.sheet-layer[data-mode="bottom"] .sheet.asheet.as-kb { bottom: var(--as-kb, 0px); height: calc(var(--as-vvh, 60vh) - 8px); max-height: none; transition: none; }
.sheet.asheet.as-kb .as-composer { padding-bottom: 10px; }
.sheet.asheet.as-kb .as-sugg { display: none; } /* con el teclado, todo el sitio para la conversación */

/* ---------- Panel fijo (escritorio) ---------- */
.as-phead { flex: none; display: flex; align-items: center; gap: 8px; padding: 18px 20px 8px; }
.as-phead-ico { color: var(--peach-ink); }
.as-ptitle { font-size: 20px; font-weight: 800; color: var(--ink); letter-spacing: -.01em; }

/* ---------- Superficie (común al panel y a la hoja) ---------- */
.as-surface { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; background: var(--surface); }
.as-surface [hidden] { display: none !important; }

/* «Sobre: …» */
.as-ctx { flex: none; display: flex; padding: 0 16px 8px; }
.as-on-panel .as-ctx { padding: 0 20px 8px; }
.as-about { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 32px; padding: 0 12px 0 10px; border-radius: 999px; background: var(--sunk); color: var(--ink-2); font-size: 13px; font-weight: 700; line-height: 1.2; }
.as-about > .ico { flex: none; }
.as-about-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.as-about.is-pinned { background: var(--sage-soft); color: var(--sage-ink); font-weight: 800; padding-right: 0; }
.as-about-x { flex: none; width: 44px; height: 44px; margin: -6px -4px -6px -8px; display: grid; place-items: center; border-radius: 50%; color: var(--sage-ink); transition: background .2s; }
.as-about-x:hover { background: color-mix(in srgb, var(--sage) 22%, transparent); }

/* Conversación */
.as-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 4px; padding: 0 16px 14px; border-bottom: 1px solid var(--line); }
.as-on-panel .as-list { padding: 0 20px 14px; }
.as-list > :first-child { margin-top: auto; }
.as-list:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; border-radius: 12px; }

.as-day { display: flex; align-items: center; gap: 10px; margin: 14px 0 0; font-size: 13px; font-weight: 800; color: var(--ink-2); }
.as-day::before, .as-day::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.as-older { display: flex; justify-content: center; padding-top: 6px; }

.as-row { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.as-row + .as-row { margin-top: 6px; }
.as-row.is-user { align-items: flex-end; }
.as-row.is-bot { align-items: stretch; }
.as-meta { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 13px; font-weight: 700; line-height: 1.2; color: var(--ink-2); }
.as-meta-name { color: var(--ink); font-weight: 800; }
.as-meta-ico { color: var(--peach-ink); }
.as-meta .avatar { margin-left: 2px; }

.as-bubble { max-width: min(86%, 560px); padding: 10px 14px; border-radius: 18px; font-size: 15px; line-height: 1.5; overflow-wrap: anywhere; }
.as-bubble.is-user { background: var(--as-tone, var(--sage-soft)); color: var(--ink); border-bottom-right-radius: 6px; }
.as-bubble.is-bot { align-self: flex-start; max-width: 100%; background: var(--bg); border: 1px solid var(--line); border-top-left-radius: 6px; color: var(--ink); }
.as-bubble.is-bot.prose { font-size: 15px; line-height: 1.55; }
.as-bubble.is-bot.prose a { font-weight: 800; }
.as-tone-salvia { --as-tone: var(--av-salvia-bg); }
.as-tone-melocoton { --as-tone: var(--av-melocoton-bg); }
.as-tone-arena { --as-tone: var(--av-arena-bg); }
.as-tone-cielo { --as-tone: var(--av-cielo-bg); }
.as-tone-lavanda { --as-tone: var(--av-lavanda-bg); }
.as-utext { white-space: pre-wrap; }
.as-row.is-sending .as-bubble { opacity: .7; }
.as-row.is-sending .as-meta-time { font-style: italic; }
.as-voice { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 800; color: var(--ink); }
.as-heard { margin-top: 4px; }
.as-heard-k { font-weight: 800; }
.as-msg-ctx { display: flex; align-items: center; gap: 4px; max-width: 86%; font-size: 13px; font-weight: 700; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.as-msg-ctx .ico { flex: none; color: var(--sage-strong); }

/* Recibos (antes → después) y Deshacer */
.as-receipts { display: flex; flex-direction: column; gap: 8px; }
.as-rc-title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 800; color: var(--sage-ink); }
.as-rc-title .ico { color: var(--sage-strong); }
.as-receipts.is-undone .as-rc-title, .as-receipts.is-undone .as-rc-title .ico { color: var(--ink-2); }
.as-rc-list { display: flex; flex-direction: column; gap: 8px; }
.as-rc-list .receipt + .receipt { margin-top: 0; }
.as-receipts .receipt-note { display: none; }
.as-receipts .receipt-title { flex: 1; min-width: 0; }
.as-rc-open { flex: none; display: inline-flex; align-items: center; gap: 2px; min-height: 44px; margin: -12px -10px -12px 0; padding: 0 6px 0 10px; border-radius: 10px; color: var(--sage-ink); font-size: 14px; font-weight: 800; }
.as-rc-open:hover { background: var(--sage-wash); }
/* Deshecho: lo que se había puesto, tachado y apagado; lo de antes vuelve a leerse normal. */
.as-receipts.is-undone .as-rc-title { color: var(--ink); }
.as-receipts.is-undone .receipt-after { color: var(--ink-2); font-weight: 600; text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--ink-2) 60%, transparent); }
.as-receipts.is-undone .receipt-before { color: var(--ink); font-weight: 700; text-decoration: none; }
.as-receipts.is-undone .as-chg-after { color: var(--ink-2); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--ink-2) 60%, transparent); }
.as-rc .receipt-title { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
/* Campo largo (notas, textos): «Notas: cambiadas · Ver» y, desplegado, el antes y el después en dos líneas. */
.as-chg-long dd { align-items: center; }
.as-chg-sum { color: var(--ink); font-weight: 700; }
.as-chg-btn { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; margin: -12px 0; padding: 0 8px; border-radius: 10px; color: var(--sage-ink); font-size: 14px; font-weight: 800; }
.as-chg-btn:hover { background: var(--sage-wash); }
.as-chg-detail { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; margin: 2px 0 4px; padding: 10px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.as-chg-k { font-weight: 800; color: var(--ink-2); }
.as-undo { align-self: flex-start; margin: -2px 0 0 -8px; }
.as-more { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; min-height: 44px; margin-left: -8px; padding: 0 8px; border-radius: 10px; color: var(--sage-ink); font-size: 14px; font-weight: 800; }
.as-more:hover { background: var(--sage-wash); }

/* Propuesta: «Voy a hacer 3 cambios» + [Descartar] [Aplicar] */
.as-prop { display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow-1); }
.as-prop .proposal-title { margin-bottom: 0; }
.as-prop .proposal-foot { margin-top: 2px; flex-wrap: wrap; }
.as-prop .proposal-foot .btn-primary { min-width: 128px; }
.as-prop .proposal-status { margin-top: 0; }
.as-prop.is-descartada, .as-prop.is-caducada { border-style: dashed; border-color: var(--line-2); box-shadow: none; background: transparent; }
.as-prop.is-descartada .proposal-title, .as-prop.is-caducada .proposal-title { color: var(--ink-2); }
.as-prop.is-descartada .receipt-after, .as-prop.is-caducada .receipt-after { font-weight: 700; }
/* Aún no hecho: el icono de cada cambio, neutro (el verde es para lo aplicado). */
.as-prop .receipt-ico { color: var(--ink-3); }
.as-prop-sum { font-size: 14px; line-height: 1.5; }
.as-prop-note { padding: 10px 12px; border-radius: 12px; background: var(--now-bg); color: var(--now-ink); font-size: 14px; font-weight: 700; }

/* Pregunta con botones, urgencias y fuentes */
/* Pregunta del asistente: las respuestas van dentro de su burbuja, en botones anchos con flecha. */
.as-bubble.has-answers { width: 100%; max-width: 100%; }
.as-answers { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.as-answer { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 14px; background: var(--surface); border: 1.5px solid var(--sage-strong); color: var(--sage-ink); font-size: 15px; font-weight: 800; line-height: 1.3; text-align: left; transition: background .2s, transform .14s var(--ease); }
.as-answer:hover:not(:disabled) { background: var(--sage-wash); }
.as-answer:active:not(:disabled) { transform: scale(.985); }
.as-answer .ico { flex: none; }
.as-retry { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.as-retry-btn { min-height: 44px; }
.as-retry-x { font-size: 13px; color: var(--ink-2); }
/* Alarma: adónde ir, con ruta, y el acceso a SOS (sin botón del 112). */
.as-urgent { display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; border-radius: 16px; background: var(--peach-wash); border: 1px solid var(--peach-soft); }
.as-urgent-head { display: flex; align-items: flex-start; gap: 10px; }
.as-urgent-ico { color: var(--peach-ink); margin-top: 1px; }
.as-urgent-text { flex: 1; min-width: 0; }
.as-urgent-t { font-size: 15px; font-weight: 800; color: var(--ink); }
.as-urgent-x { margin-top: 2px; font-size: 14px; color: var(--ink-2); }
.as-urgent-act { display: flex; flex-wrap: wrap; gap: 8px; }
.as-urgent-act .btn { flex: 1 1 140px; }
.as-sources { display: flex; flex-direction: column; gap: 6px; margin-top: 2px; }
.as-sources-t { font-size: 13px; font-weight: 800; color: var(--ink-2); }
.as-sources-list { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }
.as-sources-list li { min-width: 0; max-width: 100%; }
.as-source { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 44px; padding: 0 14px; border-radius: 999px; background: var(--sunk); color: var(--sage-ink); font-size: 13px; font-weight: 800; text-decoration: none; }
.as-source > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.as-source .ico { flex: none; }
a.as-source:hover { box-shadow: inset 0 0 0 1.5px var(--line-2); }

/* «Pensando»: tres puntos que respiran */
.as-thinking { align-self: flex-start; display: inline-flex; align-items: center; gap: 10px; min-height: 44px; margin-top: 8px; padding: 10px 16px; border-radius: 18px; border-top-left-radius: 6px; background: var(--bg); border: 1px solid var(--line); }
.as-dots { display: inline-flex; align-items: center; gap: 5px; }
.as-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sage-strong); animation: asBreathe 1.4s ease-in-out infinite; }
.as-dot:nth-child(2) { animation-delay: .2s; }
.as-dot:nth-child(3) { animation-delay: .4s; }
@keyframes asBreathe { 0%, 100% { opacity: .28; transform: scale(.75); } 45% { opacity: 1; transform: scale(1); } }
.as-thinking-text { font-size: 14px; font-weight: 700; color: var(--ink-2); }
.as-thinking-text:empty { display: none; }

/* Error humano con «Reintentar» */
.as-fail { display: flex; align-items: flex-start; gap: 10px; margin-top: 8px; padding: 12px 14px; border-radius: 16px; background: var(--peach-wash); border: 1px solid var(--peach-soft); }
.as-fail-ico { color: var(--peach-ink); margin-top: 1px; }
.as-fail-body { flex: 1; min-width: 0; }
.as-fail-t { font-size: 15px; font-weight: 800; color: var(--ink); }
.as-fail-x { margin-top: 2px; font-size: 14px; color: var(--ink-2); }
.as-fail-act { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 -4px -2px; }

/* Bienvenida (chat vacío) */
.as-welcome { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 18px 8px 10px; }
.as-welcome-art { width: 96px; height: 74px; margin-bottom: 10px; }
.as-welcome-t { font-size: 17px; font-weight: 800; color: var(--sage-ink); }
.as-welcome-x { margin-top: 6px; max-width: 330px; font-size: 14px; line-height: 1.5; color: var(--ink-2); }

/* Avisos: sin conexión, sin asistente, micrófono */
.as-notice-slot { flex: none; padding: 8px 16px 0; }
.as-on-panel .as-notice-slot { padding: 8px 20px 0; }
.as-notice { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: 14px; background: var(--now-bg); color: var(--now-ink); }
.as-notice-ico { margin-top: 1px; }
.as-notice-text { flex: 1; min-width: 0; }
.as-notice-t { font-size: 14px; font-weight: 800; line-height: 1.35; }
.as-notice-x { margin-top: 2px; font-size: 13px; font-weight: 700; line-height: 1.4; }
.as-notice .btn { flex: none; margin: -8px -6px -8px 0; color: var(--now-ink); }

/* Sugerencias (siempre a la vista, desplazables) */
.as-sugg { flex: none; display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px 2px; scrollbar-width: none; scroll-snap-type: x proximity; scroll-padding: 0 16px; }
.as-sugg::-webkit-scrollbar { display: none; }
/* Escritorio: con ratón no se desplaza en horizontal, así que las tres se colocan en líneas. */
.as-on-panel .as-sugg { flex-wrap: wrap; overflow: visible; padding: 10px 20px 2px; }
.as-on-panel .as-chip { max-width: 100%; white-space: normal; text-align: left; line-height: 1.25; padding: 8px 14px; }
.as-on-panel .as-chip > span { overflow: visible; }
/* Sugerencias: discretas (contorno, sin relleno) para no confundirse con las respuestas a una pregunta. */
.as-chip { flex: none; display: inline-flex; align-items: center; gap: 6px; max-width: min(78vw, 320px); scroll-snap-align: start; min-height: 44px; padding: 0 14px; border-radius: 999px; background: transparent; color: var(--ink); border: 1px solid var(--line-2); font-size: 14px; font-weight: 700; white-space: nowrap; transition: border-color .2s, background .2s, transform .14s var(--ease); }
.as-chip > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.as-chip .ico { flex: none; color: var(--ink-2); }
.as-chip:hover:not(:disabled) { border-color: var(--sage); background: var(--sage-wash); }
.as-chip:active:not(:disabled) { transform: scale(.97); }

/* Campo: [texto] [+] [micro | enviar] */
.as-composer { flex: none; padding: 8px 12px calc(10px + var(--safe-b)); background: var(--surface); }
.as-on-panel .as-composer { padding: 8px 16px 16px; }
.as-compose-row { display: flex; align-items: flex-end; gap: 8px; }
/* Panel de escritorio con «¿Puedo comer esto?»: cuatro controles en 380 px; todos a 44 px (base.css hace los
   icon-btn) para que el campo no se parta. */
.as-compose-row:has(> .comer-btn) > .as-send { width: 44px; height: 44px; }
.as-compose-row:has(> .comer-btn) .as-input { min-height: 44px; padding-top: 10px; padding-bottom: 10px; }
.as-field { flex: 1; min-width: 0; }
.as-input { display: block; width: 100%; min-height: 48px; max-height: 136px; padding: 12px 16px; resize: none; overflow-y: auto; border-radius: 24px; border: 1.5px solid var(--line-2); background: var(--bg); color: var(--ink); font: inherit; font-size: 16px; font-weight: 600; line-height: 1.4; transition: border-color .2s, box-shadow .2s; -webkit-appearance: none; appearance: none; }
.as-input::placeholder { color: var(--ink-3); opacity: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.as-input:focus { outline: none; border-color: var(--sage-strong); box-shadow: 0 0 0 4px color-mix(in srgb, var(--sage) 25%, transparent); }
.as-compose-row > .icon-btn { width: 48px; height: 48px; border-radius: 50%; color: var(--sage-ink); }
.as-send { flex: none; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--sage-ink); color: var(--on-sage); box-shadow: 0 6px 16px rgba(63, 94, 72, .2); transition: transform .14s var(--ease), background .2s; }
.as-send:hover:not(:disabled) { background: var(--sage-ink-hover); }
.as-send:active:not(:disabled) { transform: scale(.94); }
.as-send:focus-visible { outline-offset: 3px; border-radius: 50%; }
html[data-theme="noche"] .as-send { box-shadow: none; }

/* Grabando: contador, onda, cancelar (o deslizar) y enviar */
.as-rec { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; min-height: 48px; border-radius: 26px; background: var(--peach-wash); touch-action: pan-y; -webkit-user-select: none; user-select: none; }
.as-rec-cancel { color: var(--ink-2); border-radius: 50%; }
.as-rec-slide { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; transition: transform .2s var(--ease), opacity .2s; }
.as-rec-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--peach-ink); animation: asPulse 1.2s ease-in-out infinite; }
@keyframes asPulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.as-rec-time { flex: none; min-width: 38px; font-size: 15px; font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; }
.as-wave { flex: 1; min-width: 0; height: 30px; display: flex; align-items: center; justify-content: space-between; gap: 2px; overflow: hidden; padding-right: 6px; }
.as-wave span { flex: 1 1 0; min-width: 2px; max-width: 4px; height: 100%; border-radius: 2px; background: var(--peach-strong); transform: scaleY(.14); transition: transform .09s linear; }
.as-rec-hint { margin: 6px 4px 0; font-size: 13px; font-weight: 700; color: var(--ink-2); text-align: center; }

/* Tableta (hoja lateral): un poco más de aire */
.sheet-layer[data-mode="side"] .as-ctx, .sheet-layer[data-mode="side"] .as-list { padding-left: 20px; padding-right: 20px; }
.sheet-layer[data-mode="side"] .as-sugg { padding-left: 20px; padding-right: 20px; }

/* Sin movimiento: nada que respire ni lata; la onda queda quieta y el contador sigue. */
@media (prefers-reduced-motion: reduce) {
  .as-dot { animation: none; opacity: .65; transform: none; }
  .as-rec-dot { animation: none; }
  .as-wave span { transition: none; }
}
/* Hilos del asistente: «Hilo: X · Hilos» y la lista para volver al general o a uno anterior. */
.as-thr { padding: 4px 12px 0; min-width: 0; }
.as-thr-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; min-height: 36px; font-size: .88rem; color: var(--ink-2, inherit); }
.as-thr-t { flex: 1 1 calc(100% - 30px); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.as-thr-b { min-height: 36px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--surface); color: inherit; font: inherit; font-weight: 600; }
.as-thr-list { list-style: none; grid-template-columns: minmax(0, 1fr); margin: 4px 0 0; padding: 0; display: grid; gap: 4px; max-height: 40vh; overflow: auto; }
.as-thr-i { display: flex; justify-content: space-between; gap: 8px; width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: inherit; font: inherit; text-align: left; }
.as-thr-i.is-on { border-color: var(--sage-ink); font-weight: 700; }
/* Avisar de una respuesta de la IA (public/lib/reportar-ia.js): discreto bajo la burbuja; la hoja, con el motivo en lista. */
.as-report { display: flex; margin-top: 2px; }
.rep-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 10px; margin-left: -10px; border: 0; border-radius: 12px; background: transparent; color: var(--ink-3); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.rep-btn:hover:not(:disabled) { background: var(--sage-wash); color: var(--ink-2); }
.rep-btn:focus-visible { outline: 2px solid var(--sage-strong); outline-offset: 1px; }
.rep-btn[aria-disabled="true"], .rep-btn:disabled { opacity: .5; }
.rep-btn .ico { flex: none; }
.rin-tools .rep-btn { margin-left: 0; flex: 0 0 auto; }
.rep-lead { margin: 0 0 12px; font-size: 15px; line-height: 1.45; color: var(--ink-2); }
.rep-ops { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.rep-op { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 14px; border: 1.5px solid var(--line-2); border-radius: 13px; background: var(--surface); font-size: 16px; font-weight: 700; color: var(--ink); cursor: pointer; }
.rep-op input { width: 20px; height: 20px; margin: 0; accent-color: var(--sage-strong); flex: none; }
.rep-op:has(input:checked) { border-color: var(--sage-strong); background: var(--sage-wash); }
.rep-op:has(input:focus-visible) { box-shadow: 0 0 0 4px color-mix(in srgb, var(--sage) 25%, transparent); }

.as-thr-new { display: inline-flex; align-items: center; gap: 4px; }
.as-thr-n { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.as-thr-i small { flex: none; white-space: nowrap; }
