/* Chat web de FACTURAPRE, estilo chat. Mobile-first: en el teléfono es una sola columna a
   pantalla completa; desde 900px aparece la columna de marca con el avance. */
:root {
  --navy: #072446;
  --ink: #0F1F2E;
  --meta: #5E6F7C;
  --icon: #54656F;
  --faint: #8696A0;
  --chat-bg: #ECEEE8;
  --in: #FFFFFF;
  --out: #D9F6E5;
  --line: #E9EDEF;
  --link: #0B5CAD;
  --check: #0B8F4E;
  --accent: #00E07B;
  --shadow: 0 1px .5px rgba(11, 20, 26, .13);
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--chat-bg); color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: 100%; }
button { font: inherit; color: inherit; }
a { color: var(--link); }
a:hover { color: #08427D; }
svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
svg.fill { fill: currentColor; stroke: none; }
button:focus-visible, a:focus-visible { outline: 2.5px solid #0B6BCB; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.only-desktop { display: none; }

.app { height: 100dvh; display: flex; overflow: hidden; }

/* ---------- columna de marca (desde 900px) ---------- */
.side { display: none; width: 340px; flex-shrink: 0; flex-direction: column; justify-content: space-between; gap: 32px; padding: 32px 32px 28px; overflow-y: auto; color: #fff; background: radial-gradient(120% 70% at 0% 0%, rgba(0, 224, 123, .18) 0%, rgba(0, 224, 123, 0) 55%), var(--navy); }
.side__top { display: flex; flex-direction: column; gap: 44px; }
.side__logo { height: 46px; width: auto; align-self: flex-start; }
.side__intro { display: flex; flex-direction: column; gap: 14px; }
.side h1 { margin: 0; font-size: 34px; line-height: 1.08; font-weight: 600; letter-spacing: -.03em; text-wrap: balance; }
.side p { margin: 0; font-size: 15px; line-height: 1.55; color: #AFC2D6; text-wrap: pretty; }
.eyebrow { font-size: 11.5px; font-weight: 600; letter-spacing: .1em; color: var(--accent); }
.vsteps { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
.vsteps li { position: relative; display: flex; gap: 14px; padding-bottom: 22px; }
.vsteps li:not(:last-child)::after { content: ""; position: absolute; left: 13px; top: 32px; bottom: 4px; width: 2px; border-radius: 2px; background: rgba(255, 255, 255, .14); transition: background-color .3s; }
.vsteps__dot { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; border: 1.5px solid rgba(255, 255, 255, .22); color: #8DA3BA; font: 600 12px var(--mono); transition: background-color .3s; }
.vsteps__text { display: flex; flex-direction: column; gap: 3px; padding-top: 4px; }
.vsteps__text strong { font-size: 15px; font-weight: 500; color: #AFC2D6; }
.vsteps__text small { font-size: 13px; color: #8DA3BA; }
.vsteps li.is-current .vsteps__dot { background: #fff; border-color: #fff; color: var(--navy); }
.vsteps li.is-current strong { color: #fff; font-weight: 600; }
.vsteps li.is-done .vsteps__dot { background: var(--accent); border-color: var(--accent); font-size: 0; }
.vsteps li.is-done .vsteps__dot::before { content: ""; width: 10px; height: 6px; border-left: 2.6px solid var(--navy); border-bottom: 2.6px solid var(--navy); transform: translateY(-1px) rotate(-45deg); }
.vsteps li.is-done strong { color: #fff; }
.vsteps li.is-done::after { background: var(--accent); }
.secure { display: flex; align-items: center; gap: 7px; font-size: 12px; color: #8DA3BA; }
.secure svg { width: 13px; height: 13px; stroke-width: 2.2; }

/* ---------- chat ---------- */
.chat { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar { flex-shrink: 0; min-height: 64px; padding: env(safe-area-inset-top) 12px 0; display: flex; align-items: center; gap: 11px; background: var(--navy); color: #fff; }
.topbar__avatar { width: 40px; height: 40px; border-radius: 50%; background: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.topbar__avatar img { width: 27px; height: 27px; object-fit: contain; }
.topbar__title { display: flex; flex-direction: column; gap: 2px; min-width: 0; line-height: 1.2; }
.topbar__title strong { font-size: 16.5px; font-weight: 600; }
.topbar__title span { font-size: 12.5px; color: #B9C9D9; }

.log { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #C3CDD6 transparent;
  background-color: var(--chat-bg); background-image: radial-gradient(rgba(7, 36, 70, .045) 1px, transparent 1.2px); background-size: 18px 18px; }
.log__pane { padding: 0 16px; }
.log__inner { max-width: 980px; margin: 0 auto; padding: 10px 0 12px; display: flex; flex-direction: column; gap: 2px; }

.chip { align-self: center; padding: 5px 12px; border-radius: 8px; background: #fff; color: var(--icon); font-size: 12.5px; box-shadow: var(--shadow); text-align: center; }
.chip--day { margin: 4px 0 10px; font-size: 12px; font-weight: 500; }
.chip--sys { margin: 8px 0; }

.msg { display: flex; flex-direction: column; align-items: flex-start; animation: fp-in .22s ease-out both; }
.msg--out { align-items: flex-end; }
.msg.is-first:not(:first-child) { margin-top: 10px; }
@keyframes fp-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg__col { position: relative; display: flex; flex-direction: column; gap: 2px; max-width: min(85%, 560px); min-width: 0; }
.msg--wide .msg__col { width: min(85%, 360px); }
.msg--interactive .msg__col { width: min(85%, 420px); }

.bubble { position: relative; background: var(--in); border-radius: 8px; padding: 6px 8px 7px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.msg--out .bubble { background: var(--out); }
.msg.is-first .bubble { border-top-left-radius: 0; }
.msg--out.is-first .bubble { border-top-left-radius: 8px; border-top-right-radius: 0; }
/* la colita: solo en el primer mensaje de cada grupo */
.msg.is-first .bubble::before { content: ""; position: absolute; top: 0; left: -8px; width: 8px; height: 13px; background: inherit; clip-path: polygon(0 0, 100% 0, 100% 100%); border-top-left-radius: 2px; }
.msg--out.is-first .bubble::before { left: auto; right: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); border-top-left-radius: 0; border-top-right-radius: 2px; }
.bubble--media { padding: 3px 3px 6px; }
.bubble--media .wa, .bubble--media .bubble__header { padding: 4px 6px 2px; }
.bubble__img { display: block; width: 100%; height: auto; max-height: 420px; object-fit: cover; border-radius: 6px; background: #E9EDEF; }
.bubble__video { display: block; width: 100%; border-radius: 6px; background: #000; }
.bubble__header { font-size: 15px; font-weight: 600; }
.bubble__footer { font-size: 13px; color: var(--meta); }

.wa { font-size: 15px; line-height: 1.42; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.wa strong { font-weight: 600; }
.wa code { font-family: var(--mono); font-size: .92em; }
.wa a { word-break: break-all; }
.wa .spacer { display: inline-block; width: 54px; height: 1px; }
.msg--out .wa .spacer { width: 72px; }

.bubble__content { position: relative; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.meta { position: absolute; right: 0; bottom: -1px; display: flex; align-items: center; gap: 3px; font-size: 11px; line-height: 1; color: var(--meta); white-space: nowrap; }
.bubble--media .meta { right: 6px; bottom: 0; }
.meta--flow, .bubble--media .meta--flow { position: static; align-self: flex-end; padding: 0 4px; }
.meta svg { width: 16px; height: 11px; stroke: var(--check); stroke-width: 1.6; }

.doc { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 6px; background: #F2F4F5; text-decoration: none; color: var(--ink); }
.msg--out .doc { background: rgba(7, 36, 70, .06); }
.doc__icon { position: relative; width: 30px; height: 38px; border-radius: 4px; background: #E5484D; flex-shrink: 0; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 5px; font-size: 8px; font-weight: 700; letter-spacing: .04em; color: #fff; }
.doc__icon::before { content: ""; position: absolute; top: 0; right: 0; width: 9px; height: 9px; background: rgba(255, 255, 255, .45); border-bottom-left-radius: 3px; }
.doc__icon--xml { background: #2F6FDE; }
.doc__text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.doc__name { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc__sub { font-size: 12px; color: var(--meta); }
.doc__go { width: 32px; height: 32px; border-radius: 50%; border: 1.5px solid var(--faint); color: var(--icon); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.doc__go svg { width: 15px; height: 15px; stroke-width: 2.3; }

/* acción dentro de la burbuja: "Ver opciones" o un link */
.bubble__action { margin: 6px -8px -7px; min-height: 44px; border: 0; border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; background: transparent; color: var(--link); font-size: 15px; font-weight: 500; text-decoration: none; display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; transition: background-color .14s; }
.bubble--media .bubble__action { margin: 6px -3px -6px; }
.bubble__action:hover { background: #F5F7F8; color: var(--link); }
.bubble__action[disabled] { color: #9AA7B3; cursor: default; background: transparent; }
.bubble__action svg { width: 17px; height: 17px; stroke-width: 2.1; }

/* botones de respuesta, cada uno en su caja debajo del mensaje */
.reply { min-height: 44px; padding: 8px 14px; border: 0; border-radius: 8px; background: #fff; box-shadow: var(--shadow); color: var(--link); font-size: 15px; font-weight: 500; display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; transition: background-color .14s; }
.reply:hover { background: #F5F7F8; }
.reply[disabled] { color: #9AA7B3; cursor: default; }
.reply svg { width: 16px; height: 16px; stroke-width: 2.1; }

.out-small { display: block; font-size: 13.5px; color: var(--meta); }
.user-photo { display: block; width: 220px; max-width: 100%; max-height: 300px; object-fit: cover; border-radius: 6px; }

.typing { position: relative; align-self: flex-start; margin-top: 2px; background: #fff; border-radius: 8px; padding: 12px 14px; display: flex; align-items: center; gap: 4px; box-shadow: var(--shadow); }
.typing.has-tail { margin-top: 10px; border-top-left-radius: 0; }
.typing.has-tail::before { content: ""; position: absolute; top: 0; left: -8px; width: 8px; height: 13px; background: #fff; clip-path: polygon(0 0, 100% 0, 100% 100%); }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); animation: fp-dot 1.1s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .16s; }
.typing span:nth-child(3) { animation-delay: .32s; }
.typing em { margin-left: 6px; font-style: normal; font-size: 13px; color: var(--meta); }
.typing em:empty { display: none; }
@keyframes fp-dot { 0%, 70%, 100% { transform: translateY(0); opacity: .35; } 35% { transform: translateY(-3px); opacity: 1; } }

/* ---------- caja de texto ---------- */
.composer { flex-shrink: 0; padding: 6px 8px calc(10px + env(safe-area-inset-bottom)); background: var(--chat-bg); display: flex; flex-direction: column; gap: 6px; }
.composer__error { padding: 9px 14px; border-radius: 8px; background: #FFE9E4; color: #A2321A; font-size: 13.5px; box-shadow: var(--shadow); }
.composer__row { display: flex; align-items: flex-end; gap: 6px; }
.pill { flex: 1; min-width: 0; display: flex; align-items: center; height: 48px; padding: 0 4px; background: #fff; border-radius: 24px; box-shadow: var(--shadow); }
.pill input { flex: 1; min-width: 0; height: 42px; border: 0; background: transparent; padding: 0 4px; font: 16px var(--sans); color: var(--ink); }
.pill input:focus { outline: none; }
.pill input::placeholder { color: #7D8B98; }
.icon-btn { width: 42px; height: 42px; border: 0; border-radius: 50%; background: transparent; color: var(--icon); display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; transition: transform .12s, opacity .16s; }
.icon-btn svg { width: 21px; height: 21px; stroke-width: 1.9; }
.icon-btn:active { transform: scale(.94); }
.icon-btn.is-busy { opacity: .45; cursor: progress; }
.send-btn { width: 48px; height: 48px; border: 0; border-radius: 50%; background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; box-shadow: 0 1px .5px rgba(11, 20, 26, .2); transition: transform .12s; }
.send-btn svg { width: 20px; height: 20px; }
.send-btn:active { transform: scale(.94); }

/* ---------- lista: hoja inferior en el teléfono, ventana en escritorio ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet__backdrop { position: absolute; inset: 0; border: 0; padding: 0; background: rgba(11, 20, 26, .4); cursor: pointer; animation: fp-fade .2s ease both; }
.sheet__panel { position: relative; max-height: 80dvh; display: flex; flex-direction: column; background: #fff; border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); animation: fp-up .3s cubic-bezier(.16, 1, .3, 1) both; }
.sheet__head { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.sheet__head h2 { flex: 1; margin: 0; padding-right: 42px; text-align: center; font-size: 16px; font-weight: 600; }
.sheet__body { overflow-y: auto; padding-bottom: 6px; }
.sheet__section { padding: 14px 20px 6px; font-size: 13px; font-weight: 500; color: var(--check); }
.sheet__row { width: 100%; min-height: 60px; padding: 10px 20px; border: 0; background: transparent; text-align: left; display: flex; align-items: center; gap: 14px; cursor: pointer; color: var(--ink); transition: background-color .14s; }
.sheet__row:hover { background: #F5F7F8; }
.sheet__row > span:first-child { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; padding-bottom: 10px; border-bottom: 1px solid #F0F2F3; }
.sheet__row strong { font-size: 15.5px; font-weight: 400; }
.sheet__row small { font-size: 13.5px; color: var(--meta); }
.radio { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--faint); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sheet__row[aria-checked="true"] .radio { border-color: var(--check); }
.sheet__row[aria-checked="true"] .radio::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--check); }
.sheet__foot { padding: 10px 16px 14px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; }
.sheet__send { width: 52px; height: 52px; border: 0; border-radius: 50%; background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: background-color .16s, transform .12s; }
.sheet__send svg { width: 21px; height: 21px; }
.sheet__send:active { transform: scale(.94); }
.sheet__send[disabled] { background: #C3CDD6; cursor: default; transform: none; }
@keyframes fp-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fp-fade { from { opacity: 0; } to { opacity: 1; } }

.gate { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--chat-bg); }
.gate__card { max-width: 380px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.gate__card h1 { margin: 8px 0 0; font-size: 22px; letter-spacing: -.02em; }
.gate__card p { margin: 0; color: var(--meta); line-height: 1.5; }

/* ---------- escritorio ---------- */
@media (min-width: 900px) {
  .side { display: flex; }
  .only-mobile { display: none; }
  .only-desktop { display: block; }
  .chat { border-left: 1px solid #D9DEDB; }
  .topbar { background: #F5F6F6; color: var(--ink); border-bottom: 1px solid #E1E5E3; padding: 0 16px; }
  .topbar__avatar { box-shadow: 0 0 0 1px rgba(11, 20, 26, .08); }
  .topbar__title strong { font-size: 16px; }
  .topbar__title span { color: var(--meta); font-size: 13px; }
  .log__pane { padding: 0 7%; }
  .log__inner { padding: 14px 0 16px; }
  .msg__col { max-width: min(62%, 560px); }
  .composer { padding: 10px 16px; background: #F5F6F6; border-top: 1px solid #E1E5E3; }
  .composer__row { align-items: center; gap: 8px; }
  .pill { height: 44px; padding: 0 4px 0 0; border-radius: 10px; box-shadow: none; }
  .pill input { font-size: 15.5px; padding: 0 10px; }
  .pill .icon-btn { order: -1; margin-right: 4px; background: transparent; }
  .send-btn { width: 44px; height: 44px; background: transparent; color: var(--faint); box-shadow: none; }
  .send-btn.is-ready { color: var(--navy); }
  .sheet { justify-content: center; align-items: center; padding: 24px; }
  .sheet__panel { width: 420px; max-width: 100%; border-radius: 14px; box-shadow: 0 24px 48px -20px rgba(11, 20, 26, .5); animation-name: fp-modal; }
  @keyframes fp-modal { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
