/* Recuerdos Impresos - interfaz de chat para el formulario público
   Este archivo es aditivo: reutiliza las variables y tokens visuales
   definidos en app.css (colores, radios, sombras, tipografía) y no
   modifica ninguna regla existente allí. Solo agrega las clases
   necesarias para presentar el formulario como una conversación. */

.chat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin-bottom: 20px;
}

.chat-log {
    padding: 22px 18px 10px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 120px;
}

/* Fila de mensaje: alinea burbuja + avatar según el emisor */
.chat-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 100%;
    opacity: 0;
    transform: translateY(6px);
    animation: chat-msg-in 0.28s ease forwards;
}

@keyframes chat-msg-in {
    to { opacity: 1; transform: translateY(0); }
}

.chat-row.bot { justify-content: flex-start; }
.chat-row.user { justify-content: flex-end; }

.chat-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--accent-soft);
    border: 1px solid var(--border);
}
.chat-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.chat-bubble {
    max-width: 78%;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.96rem;
    line-height: 1.48;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

.chat-row.bot .chat-bubble {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.chat-row.user .chat-bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-row.user .chat-bubble a { color: #fff; text-decoration: underline; }

.chat-bubble .required-mark { color: #e08b85; }
.chat-row.bot .chat-bubble .required-mark { color: var(--danger); }

.chat-bubble-title {
    font-family: var(--font-serif);
    font-size: 1.15rem;
    margin: 0 0 4px;
}

/* Miniaturas de archivos dentro de una burbuja del usuario */
.chat-file-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}
.chat-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.18);
    border-radius: 999px;
    padding: 4px 10px 4px 4px;
    font-size: 0.8rem;
}
.chat-row.bot .chat-file-chip {
    background: var(--pill-bg);
    color: var(--tag-text);
}
.chat-file-chip .thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    overflow: hidden;
    background: rgba(255,255,255,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.7rem;
}
.chat-file-chip .thumb img { width: 100%; height: 100%; object-fit: cover; }

/* Indicador de "escribiendo..." */
.chat-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 14px 16px;
}
.chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    opacity: 0.5;
    animation: chat-typing-bounce 1.1s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Área de entrada, fija al pie de la tarjeta de chat */
.chat-input-area {
    border-top: 1px solid var(--border);
    background: var(--surface-alt);
    padding: 14px 16px;
    display: none;
}
.chat-input-area.visible {
    display: block;
    animation: chat-msg-in 0.25s ease forwards;
}

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}
.chat-input-row .chat-input-control { flex: 1; min-width: 0; }

.chat-send-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 1.1rem;
    transition: background 0.15s ease, transform 0.1s ease;
}
.chat-send-btn:hover { background: var(--accent-hover); }
.chat-send-btn:active { transform: scale(0.94); }
.chat-send-btn[disabled] { opacity: 0.4; cursor: not-allowed; }

.chat-skip-row {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}
.chat-skip-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.82rem;
    cursor: pointer;
    text-decoration: underline;
    padding: 4px 2px;
}
.chat-skip-btn:hover { color: var(--accent); }

/* Opciones tipo "chips" para select/checkbox dentro del área de input */
.chat-option-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.chat-option-chip {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 999px;
    padding: 9px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}
.chat-option-chip:hover { border-color: var(--accent); color: var(--accent); }
.chat-option-chip.selected {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.chat-file-drop {
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    padding: 18px;
    text-align: center;
    background: var(--surface);
    cursor: pointer;
}
.chat-file-drop:hover { border-color: var(--accent); }
.chat-file-preview-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}
.chat-file-preview {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 5px 10px 5px 5px;
    font-size: 0.8rem;
}
.chat-file-preview .thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--accent-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.chat-file-preview .thumb img { width: 100%; height: 100%; object-fit: cover; }
.chat-file-preview .remove-file {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    padding: 2px;
}
.chat-file-preview .remove-file:hover { color: var(--danger); }

.chat-error-text {
    color: var(--danger);
    font-size: 0.83rem;
    margin: 6px 2px 0;
}

.chat-progress {
    padding: 10px 16px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.chat-progress-track {
    flex: 1;
    height: 6px;
    border-radius: 999px;
    background: var(--border);
    overflow: hidden;
}
.chat-progress-fill {
    height: 100%;
    background: var(--gold);
    border-radius: 999px;
    transition: width 0.35s ease;
}
.chat-progress-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.chat-hidden-form {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.chat-log::-webkit-scrollbar { width: 6px; }
.chat-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }

/* ------------------------------------------------------------------
   Layout de viewport fijo para la experiencia de chat: la página no
   scrollea, solo el historial de mensajes dentro de la tarjeta blanca.
   Header, barra de progreso, controles de entrada y footer quedan
   siempre visibles. Esto solo aplica a la vista pública del chat
   (body.chat-page-body) y no afecta ninguna otra pantalla del sitio. */
html:has(body.chat-page-body) {
    height: 100%;
}

body.chat-page-body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body.chat-page-body .topbar {
    position: static;
    flex-shrink: 0;
}

body.chat-page-body .chat-page,
body.chat-page-body .chat-page-footer {
    padding-top: 0;
}

body.chat-page-body .chat-page {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    padding: 14px 16px;
    min-width: 0;
}

body.chat-page-body .chat-page-footer {
    flex-shrink: 0;
    padding: 10px 16px;
}

body.chat-page-body .chat-card {
    flex: 1;
    min-height: 0;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
}

body.chat-page-body .chat-log {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

body.chat-page-body .chat-progress,
body.chat-page-body .chat-input-area {
    flex-shrink: 0;
}

/* Botón de "continuar" tras el mensaje final, para que el usuario pueda
   leerlo antes de que la conversación termine y se envíe el formulario. */
.chat-continue-row {
    display: flex;
    justify-content: center;
    padding: 4px 2px 2px;
}

@media (max-width: 560px) {
    .chat-bubble { max-width: 86%; font-size: 0.94rem; }
    .chat-log { padding: 16px 12px 8px; }
    .chat-input-area { padding: 12px; }
}
