/* Chat con IA de Pierre Chimen (public/js/asistente.js). CSS propio con prefijo .pca- (no depende de Tailwind). */
.pca {
    --pca-bg: #14110f;
    --pca-bg-2: #1e1a17;
    --pca-line: rgba(241, 236, 227, 0.1);
    --pca-text: #f1ece3;
    --pca-mist: #9c9188;
    --pca-accent: #e08a3c;
    --pca-deep: #a5401c;
    --pca-ember: #ff6a2b;
    --pca-online: #3ccf7a;
    position: fixed;
    right: max(16px, env(safe-area-inset-right));
    bottom: var(--pca-bottom, 16px);
    z-index: 9990;
    font-family: 'Inter', ui-sans-serif, system-ui, sans-serif;
    color: var(--pca-text);
    pointer-events: none;
}
.pca, .pca *, .pca *::before, .pca *::after { box-sizing: border-box; }
.pca > * { pointer-events: auto; }
.pca[hidden] { display: none; }

/* ---------- Botón ---------- */
.pca-launcher {
    position: relative;
    display: block;
    width: 60px;
    height: 60px;
    margin-left: auto;
    padding: 0;
    border: 2px solid rgba(241, 236, 227, 0.92);
    border-radius: 50%;
    background: var(--pca-bg-2);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    opacity: 0;
    transform: translateY(16px) scale(0.85);
    transition: opacity 0.35s ease, transform 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.3);
    visibility: hidden;
}
.pca.is-on .pca-launcher { opacity: 1; transform: none; visibility: visible; }
.pca-launcher:hover { transform: scale(1.06); }
.pca-launcher:focus-visible { outline: 3px solid var(--pca-accent); outline-offset: 3px; }
.pca.is-open .pca-launcher { display: none; }

.pca-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: 50%;
    background: radial-gradient(circle at 50% 85%, var(--pca-ember), var(--pca-deep) 75%);
}
.pca-avatar svg { width: 58%; height: 58%; display: block; }
.pca-avatar--head { flex: none; width: 42px; height: 42px; }

.pca-dot {
    position: absolute;
    right: 1px;
    bottom: 1px;
    width: 14px;
    height: 14px;
    border: 2px solid var(--pca-bg);
    border-radius: 50%;
    background: var(--pca-online);
}

/* ---------- Saludo ---------- */
.pca-bubble {
    position: absolute;
    right: 0;
    bottom: 74px;
    width: min(310px, calc(100vw - 32px));
    padding: 14px 18px 14px;
    border-radius: 18px 18px 4px 18px;
    background: #f1ece3;
    color: #0b0a09;
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
    cursor: pointer;
    opacity: 0;
    transform: translateY(10px) scale(0.96);
    transform-origin: bottom right;
    transition: opacity 0.3s ease, transform 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
    visibility: hidden;
}
.pca-bubble.is-on { opacity: 1; transform: none; visibility: visible; }
.pca-bubble-who { margin: 0 22px 4px 0; color: var(--pca-deep); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.pca-bubble-text { margin: 0 14px 12px 0; font-size: 0.95rem; line-height: 1.45; }
.pca-bubble-x {
    position: absolute;
    top: 6px;
    right: 8px;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #6b6259;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
}
.pca-bubble-x:hover { background: #e2d9cc; color: #0b0a09; }
.pca-bubble-x:focus-visible, .pca-chip:focus-visible { outline: 2px solid var(--pca-deep); outline-offset: 2px; }

.pca-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pca-chip {
    padding: 7px 13px;
    border: 1px solid var(--pca-deep);
    border-radius: 999px;
    background: transparent;
    color: var(--pca-deep);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
}
.pca-chip:first-child { background: var(--pca-deep); color: #fff; }
.pca-chip:hover { background: #7f2f13; border-color: #7f2f13; color: #fff; }

/* ---------- Panel ---------- */
.pca-panel {
    position: absolute;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    width: min(380px, calc(100vw - 32px));
    height: min(580px, calc(100dvh - var(--pca-bottom, 16px) - 16px));
    overflow: hidden;
    border: 1px solid var(--pca-line);
    border-radius: 20px;
    background: var(--pca-bg);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
    opacity: 0;
    transform: translateY(16px) scale(0.98);
    transform-origin: bottom right;
    transition: opacity 0.25s ease, transform 0.3s ease, visibility 0s linear 0.3s;
    visibility: hidden;
}
.pca.is-open .pca-panel {
    opacity: 1;
    transform: none;
    visibility: visible;
    transition: opacity 0.25s ease, transform 0.3s ease;
}

.pca-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 14px 14px 16px;
    border-bottom: 1px solid var(--pca-line);
    background: var(--pca-bg-2);
}
.pca-who { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.pca-who strong { display: flex; align-items: center; gap: 8px; font-size: 1rem; font-weight: 600; }
.pca-who span { display: flex; align-items: center; gap: 6px; color: var(--pca-mist); font-size: 0.78rem; }
.pca-who span::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--pca-online); }
.pca-test { padding: 1px 7px; border-radius: 999px; background: var(--pca-accent); color: #0b0a09; font-size: 0.68rem; font-style: normal; font-weight: 600; }
.pca-close {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--pca-mist);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
}
.pca-close:hover { background: rgba(241, 236, 227, 0.08); color: var(--pca-text); }
.pca-close:focus-visible { outline: 2px solid var(--pca-accent); outline-offset: 2px; }

.pca-list {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}
.pca-msg { display: flex; }
.pca-msg--me { justify-content: flex-end; }
.pca-text {
    max-width: 84%;
    padding: 9px 13px;
    border-radius: 16px;
    font-size: 0.92rem;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.pca-msg--her .pca-text { border: 1px solid var(--pca-line); border-bottom-left-radius: 4px; background: var(--pca-bg-2); }
.pca-msg--me .pca-text { border-bottom-right-radius: 4px; background: var(--pca-deep); color: #fff; }
.pca-text a { color: var(--pca-accent); text-decoration: underline; text-underline-offset: 2px; }
.pca-msg--me .pca-text a { color: #fff; }

.pca-typing .pca-text { display: flex; gap: 4px; padding: 13px 14px; }
.pca-typing i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--pca-mist);
    animation: pca-blink 1.2s infinite ease-in-out;
}
.pca-typing i:nth-child(2) { animation-delay: 0.15s; }
.pca-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes pca-blink {
    0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

.pca-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--pca-line);
}
.pca-input {
    flex: 1;
    min-height: 42px;
    max-height: 120px;
    padding: 10px 12px;
    border: 1px solid var(--pca-line);
    border-radius: 12px;
    background: var(--pca-bg-2);
    color: var(--pca-text);
    font: inherit;
    font-size: 16px; /* evita el zoom automático de iOS */
    line-height: 1.35;
    resize: none;
}
.pca-input::placeholder { color: var(--pca-mist); }
.pca-input:focus { outline: none; border-color: var(--pca-accent); }
.pca-send {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 12px;
    background: var(--pca-accent);
    color: #0b0a09;
    cursor: pointer;
}
.pca-send:hover { background: #ec9a4f; }
.pca-send:focus-visible { outline: 2px solid var(--pca-text); outline-offset: 2px; }
.pca-send:disabled { opacity: 0.5; cursor: wait; }
.pca-trap { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

.pca-foot {
    margin: 0;
    padding: 0 14px 10px;
    color: var(--pca-mist);
    font-size: 0.7rem;
    line-height: 1.4;
}
.pca-foot a { color: var(--pca-mist); text-decoration: underline; }

/* Abierto en el ordenador: baja hasta abajo (tapa el botón de WhatsApp mientras se chatea). */
.pca.is-open { bottom: max(16px, env(safe-area-inset-bottom)); }
.pca.is-open .pca-panel { height: min(600px, calc(100dvh - 32px)); }

/* Móvil: el chat ocupa la pantalla */
@media (max-width: 520px) {
    .pca-launcher { width: 56px; height: 56px; }
    .pca-bubble { bottom: 70px; }
    .pca.is-open { inset: 0; right: 0; bottom: 0; }
    .pca.is-open .pca-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100dvh;
        border: 0;
        border-radius: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .pca-launcher, .pca-bubble, .pca-panel { transition: none; }
    .pca-typing i { animation: none; }
}

@media print { .pca { display: none; } }
