/* ============================================================
   Captación de facturación electrónica (prefijo .fe-)
   Bienvenida, asistente, formulario de llamada, aviso de salida
   y barra de contacto móvil. Marcado: includes/fe-captacion.php
   Usa los colores del tema (modern-theme.css) con respaldo propio.
   ============================================================ */
:root {
    --fe-primary: var(--primary, #2563eb);
    --fe-primary-d: var(--primary-dark, #1d4ed8);
    --fe-wa: #128c4a;          /* verde WhatsApp oscurecido: contraste AA con texto blanco */
    --fe-wa-d: #0f7a40;
    --fe-text: #111827;
    --fe-muted: #4b5563;
    --fe-border: #d1d5db;
    --fe-err: #b91c1c;
    --fe-ok: #047857;
    --fe-mbar-h: 60px;
}

/* ---------- Botones ---------- */
.fe-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    min-height: 44px; padding: .65rem 1.1rem; border-radius: 10px; border: 2px solid transparent;
    font: 600 .95rem/1.2 'Inter', system-ui, sans-serif; text-decoration: none; cursor: pointer;
    transition: background-color .15s, border-color .15s, color .15s;
}
.fe-btn:focus-visible, .fe-link:focus-visible, .fe-opt:focus-visible, .fe-chip:focus-visible,
.fe-mbar__btn:focus-visible, .fe-launcher:focus-visible, .fe-dialog__close:focus-visible,
.fe-offer__opt:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
.fe-btn--sm { min-height: 44px; padding: .5rem .9rem; font-size: .9rem; }
.fe-btn--block { display: flex; width: 100%; }
.fe-btn--primary { background: var(--fe-primary); color: #fff; }
.fe-btn--primary:hover { background: var(--fe-primary-d); color: #fff; }
.fe-btn--primary[disabled] { opacity: .7; cursor: progress; }
.fe-btn--wa { background: var(--fe-wa); color: #fff; }
.fe-btn--wa:hover { background: var(--fe-wa-d); color: #fff; }
.fe-btn--line { background: #fff; color: var(--fe-text); border-color: var(--fe-border); }
.fe-btn--line:hover { border-color: var(--fe-primary); color: var(--fe-primary-d); }
.fe-btn--ghost { background: transparent; color: var(--fe-muted); border-color: transparent; }
.fe-btn--ghost:hover { color: var(--fe-text); text-decoration: underline; }
.fe-link {
    background: none; border: 0; padding: .6rem .25rem; min-height: 44px; cursor: pointer;
    color: var(--fe-muted); font: 500 .9rem 'Inter', system-ui, sans-serif; text-decoration: underline; text-underline-offset: 2px;
}
.fe-link:hover { color: var(--fe-text); }

/* ---------- Acceso manual ---------- */
.fe-launcher {
    position: fixed; left: 24px; bottom: 24px; z-index: 990;
    display: inline-flex; align-items: center; gap: .5rem; min-height: 44px;
    padding: .65rem 1.05rem; border-radius: 999px; border: 1px solid var(--fe-border);
    background: #fff; color: var(--fe-text); box-shadow: 0 6px 20px rgba(15, 23, 42, .15);
    font: 600 .9rem 'Inter', system-ui, sans-serif; cursor: pointer;
}
.fe-launcher i { color: var(--fe-primary); }
.fe-launcher:hover { border-color: var(--fe-primary); }
.fe-launcher[hidden] { display: none; }

/* ---------- Animación de entrada ---------- */
@media (prefers-reduced-motion: no-preference) {
    @keyframes feSube { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
    @keyframes fePulso { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }
}

/* ---------- Diálogos ---------- */
.fe-dialog {
    border: 0; padding: 0; border-radius: 16px; width: 420px; max-width: calc(100vw - 32px);
    max-height: calc(100dvh - 32px); color: var(--fe-text); background: #fff;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .3); font-family: 'Inter', system-ui, sans-serif;
    overflow: hidden;
}
.fe-dialog[open] { display: flex; flex-direction: column; }
/* El reset global del tema (* { margin: 0 }) anula el centrado nativo de <dialog>. */
.fe-dialog { margin: auto; }
.fe-dialog::backdrop { background: rgba(15, 23, 42, .5); }
.fe-dialog__head {
    display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem;
    padding: 1rem 1rem .75rem 1.25rem; border-bottom: 1px solid #e5e7eb;
}
.fe-dialog__title { margin: 0; font-weight: 700; font-size: 1.02rem; line-height: 1.3; }
.fe-dialog__sub { margin: .25rem 0 0; font-size: .85rem; color: var(--fe-muted); line-height: 1.45; }
.fe-dialog__close {
    flex: none; width: 44px; height: 44px; border: 0; border-radius: 10px; background: #f3f4f6;
    color: var(--fe-muted); cursor: pointer; font-size: 1.05rem;
}
.fe-dialog__close:hover { background: #e5e7eb; color: var(--fe-text); }
.fe-dialog__close--abs { position: absolute; top: .6rem; right: .6rem; }
.fe-dialog__body { padding: 1rem 1.25rem; overflow-y: auto; flex: 1 1 auto; }
.fe-dialog__foot { padding: .85rem 1.25rem 1rem; border-top: 1px solid #e5e7eb; background: #f9fafb; }
.fe-foot__row { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-top: .5rem; }
@media (prefers-reduced-motion: no-preference) {
    .fe-dialog[open] { animation: feSube .22s ease-out; }
}

/* Asistente: en escritorio, anclado abajo a la izquierda como un panel */
@media (min-width: 769px) {
    .fe-dialog--assistant[open] { position: fixed; inset: auto auto 24px 24px; margin: 0; max-height: min(640px, calc(100dvh - 48px)); }
    .fe-dialog--assistant::backdrop { background: rgba(15, 23, 42, .25); }
}

.fe-q { font-size: 1.05rem; font-weight: 700; margin: 0 0 .75rem; line-height: 1.35; outline: none; color: var(--fe-text); }
.fe-view p { color: #374151; font-size: .94rem; line-height: 1.6; margin: 0 0 .75rem; }
.fe-note { font-size: .82rem !important; color: var(--fe-muted) !important; }
.fe-note a { color: var(--fe-primary-d); }
.fe-opts { display: flex; flex-direction: column; gap: .5rem; }
.fe-opt {
    display: flex; align-items: center; gap: .65rem; width: 100%; min-height: 48px; text-align: left;
    padding: .7rem .9rem; border: 1.5px solid #e5e7eb; border-radius: 12px; background: #fff; cursor: pointer;
    font: 500 .95rem 'Inter', system-ui, sans-serif; color: var(--fe-text);
}
.fe-opt i { color: var(--fe-primary); width: 20px; text-align: center; }
.fe-opt:hover { border-color: var(--fe-primary); background: #eff6ff; }
.fe-opt--muted { color: var(--fe-muted); }
.fe-chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .75rem; }
.fe-chip {
    min-height: 44px; padding: .5rem .9rem; border-radius: 999px; border: 1.5px solid #e5e7eb; background: #fff;
    font: 500 .9rem 'Inter', system-ui, sans-serif; color: #374151; cursor: pointer;
}
.fe-chip:hover, .fe-chip[aria-pressed="true"] { border-color: var(--fe-primary); background: #eff6ff; color: var(--fe-primary-d); }
.fe-nav { display: flex; justify-content: space-between; margin-top: .5rem; }
.fe-list { margin: 0 0 .75rem; padding-left: 1.1rem; }
.fe-list li { margin-bottom: .35rem; font-size: .94rem; }
.fe-list a { color: var(--fe-primary-d); }

/* Aviso de salida */
.fe-dialog--exit { position: relative; }
.fe-exit { padding: 1.6rem 1.5rem 1.25rem; }
.fe-exit__brand { margin: 0 0 .75rem; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; font-weight: 600; color: var(--fe-muted); }
.fe-exit__brand i { color: var(--fe-primary); margin-right: .3rem; }
.fe-exit__title { margin: 0 2.5rem .5rem 0; font-size: 1.25rem; line-height: 1.3; outline: none; }
.fe-exit__text { margin: 0 0 1.1rem; color: #374151; line-height: 1.55; }
.fe-exit__later { display: block; margin: .6rem auto 0; }

/* ---------- Formulario ---------- */
.fe-form { font-family: 'Inter', system-ui, sans-serif; }
.fe-field { margin: 0 0 .85rem; border: 0; padding: 0; min-width: 0; }
.fe-field[hidden] { display: none; }
.fe-field > label, .fe-franja legend { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .3rem; color: var(--fe-text); padding: 0; }
.fe-input {
    width: 100%; min-height: 44px; padding: .6rem .75rem; border: 1px solid #9ca3af; border-radius: 8px;
    font: 400 1rem 'Inter', system-ui, sans-serif; color: var(--fe-text); background: #fff; box-sizing: border-box;
}
.fe-input:focus { outline: none; border-color: var(--fe-primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .25); }
.fe-input[aria-invalid="true"] { border-color: var(--fe-err); background: #fef2f2; }
.fe-hint { margin: .3rem 0 0; font-size: .8rem; color: var(--fe-muted); }
.fe-err { margin: .3rem 0 0; font-size: .82rem; font-weight: 600; color: var(--fe-err); }
.fe-err[hidden] { display: none; }
.fe-franja__opts { display: flex; flex-wrap: wrap; gap: .25rem 1rem; }
.fe-radio { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; font-size: .92rem; cursor: pointer; color: var(--fe-text); }
.fe-radio input, .fe-check input { width: 20px; height: 20px; accent-color: var(--fe-primary); margin: 0; flex: none; }
.fe-check { display: grid; grid-template-columns: 20px 1fr; gap: .6rem; align-items: start; }
.fe-check label { font-size: .86rem; line-height: 1.5; color: #374151; cursor: pointer; }
.fe-check label a { color: var(--fe-primary-d); }
.fe-check .fe-err { grid-column: 2; }
.fe-hp { position: absolute !important; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.fe-form__status { margin-top: .75rem; font-size: .92rem; line-height: 1.5; outline: none; }
.fe-form__status:empty { display: none; }
.fe-form__status--ok { padding: .85rem 1rem; border-radius: 10px; background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.fe-form__status--error { padding: .85rem 1rem; border-radius: 10px; background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.fe-form__status--error a { color: #991b1b; font-weight: 700; }
.fe-form__alt { margin: .75rem 0 0; font-size: .86rem; color: var(--fe-muted); }
.fe-form__alt a { color: var(--fe-wa-d); font-weight: 600; }

/* ---------- Barra de contacto móvil ---------- */
.fe-mbar { display: none; }
@media (max-width: 768px) {
    .fe-mbar {
        display: grid; grid-template-columns: repeat(3, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 980;
        background: #fff; border-top: 1px solid #e5e7eb; box-shadow: 0 -4px 16px rgba(15, 23, 42, .08);
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)); gap: 6px;
    }
    .fe-mbar__btn {
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
        min-height: 48px; border-radius: 10px; border: 0; background: #f3f4f6; color: var(--fe-text);
        font: 600 .78rem 'Inter', system-ui, sans-serif; text-decoration: none; cursor: pointer;
    }
    .fe-mbar__btn i { font-size: 1.1rem; color: var(--fe-primary); }
    .fe-mbar__btn--wa { background: var(--fe-wa); color: #fff; }
    .fe-mbar__btn--wa i { color: #fff; }
    html:not(.fe-js) .fe-mbar { grid-template-columns: repeat(2, 1fr); }
    html:not(.fe-js) .fe-mbar button { display: none; }
    body { padding-bottom: calc(var(--fe-mbar-h) + env(safe-area-inset-bottom, 0px)); }

    /* Controles flotantes existentes: la barra los sustituye o se elevan por encima de ella */
    .wa__btn_popup, .wa__popup_chat_box, .fe-launcher { display: none !important; }
    .stats-widget { bottom: calc(var(--fe-mbar-h) + 16px + env(safe-area-inset-bottom, 0px)) !important; }
    .back-to-top { bottom: calc(var(--fe-mbar-h) + 16px + env(safe-area-inset-bottom, 0px)) !important; }

    /* Diálogos como hoja inferior */
    .fe-dialog[open] { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 16px 16px 0 0; max-height: 92dvh; }
    .fe-dialog__body { padding: 1rem; }
    .fe-dialog__foot { padding: .75rem 1rem calc(.85rem + env(safe-area-inset-bottom, 0px)); }
}
/* Con teclado en pantalla o un diálogo abierto, ocultar controles flotantes redundantes */
html.fe-typing .fe-mbar, html.fe-dialog-open .fe-mbar,
html.fe-dialog-open .fe-launcher, html.fe-dialog-open .wa__btn_popup { display: none !important; }
@media (max-width: 768px) {
    html.fe-typing body { padding-bottom: 0; }
}

/* ---------- Modal de oferta de facturación electrónica ---------- */
.fe-dialog--offer { width: 820px; padding: 0; }
.fe-offer { display: grid; grid-template-columns: 40% 1fr; min-height: 100%; }
.fe-offer__media { background: linear-gradient(160deg, #e0edff 0%, #f5f3ff 100%); display: flex; align-items: center; justify-content: center; padding: 1.25rem; }
.fe-offer__media img { width: 100%; height: auto; display: block; border-radius: 12px; }
.fe-offer__body { padding: 1.75rem 1.75rem 1.25rem; overflow-y: auto; max-height: calc(100dvh - 32px); }
.fe-offer__close { background: rgba(255, 255, 255, .9); z-index: 2; }
.fe-offer__ribbon {
    display: inline-flex; align-items: center; gap: .4rem; margin: 0 0 .75rem; padding: .35rem .8rem; border-radius: 999px;
    background: linear-gradient(135deg, #f59e0b, #ef4444); color: #fff; font-weight: 800; font-size: .78rem;
    letter-spacing: .06em; text-transform: uppercase; box-shadow: 0 6px 16px rgba(239, 68, 68, .3);
}
.fe-offer__title { margin: 0 2.5rem .35rem 0; font-size: 1.55rem; line-height: 1.2; font-weight: 800; color: var(--fe-text); outline: none; }
.fe-offer__price { display: block; margin-top: .35rem; font-size: 1.05rem; font-weight: 600; color: var(--fe-muted); }
.fe-offer__price strong {
    font-size: 2.6rem; line-height: 1; font-weight: 900; letter-spacing: -.02em;
    background: linear-gradient(135deg, #1d4ed8, #7c3aed); -webkit-background-clip: text; background-clip: text; color: transparent;
    display: inline-block; margin-left: .3rem;
}
.fe-offer__price small { font-size: 1rem; font-weight: 700; color: var(--fe-text); margin-left: .15rem; }
@media (prefers-reduced-motion: no-preference) {
    .fe-dialog--offer[open] .fe-offer__price strong { animation: fePulso 1.6s ease-in-out 2; }
}
.fe-offer__note { margin: 0 0 .9rem; font-size: .8rem; color: var(--fe-muted); }
.fe-offer__list { list-style: none; padding: 0; margin: 0 0 1.1rem; display: grid; gap: .35rem; }
.fe-offer__list li { display: flex; gap: .5rem; align-items: flex-start; font-size: .93rem; color: #374151; line-height: 1.45; }
.fe-offer__list i { color: var(--fe-ok); margin-top: .2rem; }
.fe-offer__step { border-top: 1px solid #e5e7eb; padding-top: 1rem; }
.fe-offer__step[hidden] { display: none; }
.fe-offer__q { margin: 0 0 .7rem; font-weight: 700; font-size: 1.02rem; color: var(--fe-text); outline: none; }
.fe-offer__opts { display: grid; gap: .5rem; }
.fe-offer__opt {
    display: flex; align-items: center; gap: .65rem; width: 100%; min-height: 48px; padding: .7rem .95rem; text-align: left;
    border: 1.5px solid #e5e7eb; border-radius: 12px; background: #fff; cursor: pointer;
    font: 600 .95rem 'Inter', system-ui, sans-serif; color: var(--fe-text); transition: border-color .15s, background-color .15s;
}
.fe-offer__opt i { color: var(--fe-primary); width: 20px; text-align: center; }
.fe-offer__opt:hover { border-color: var(--fe-primary); background: #eff6ff; }
.fe-offer__resp { margin: 0 0 .9rem; color: #374151; line-height: 1.55; font-size: .95rem; }
.fe-offer__resp[hidden] { display: none; }
.fe-offer__cta { min-height: 52px; font-size: 1rem; }
.fe-offer__later { display: block; margin: .6rem auto 0; }
@media (max-width: 768px) {
    .fe-dialog--offer[open] { max-height: 94dvh; }
    .fe-offer { grid-template-columns: 1fr; }
    .fe-offer__media { display: none; }
    .fe-offer__body { padding: 1.25rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px)); max-height: 94dvh; }
    .fe-offer__title { font-size: 1.3rem; }
    .fe-offer__price strong { font-size: 2.2rem; }
}

/* Precio de la oferta en el aviso de salida */
.fe-exit__oferta { margin: 0 0 .85rem; padding: .6rem .85rem; border-radius: 10px; background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; font-size: .95rem; }
.fe-exit__oferta i { color: #ea580c; }
.fe-exit__oferta strong { font-size: 1.15rem; }
.fe-exit__oferta span { display: block; font-size: .78rem; color: #9a3412; opacity: .85; }
