/* Chat de búsqueda de coches (chat.html). Pantalla completa tipo ChatGPT bajo la barra de navegación. */

.chat-page {
    --chat-max: 780px;
    --chat-blue: #004aad;
    --chat-border: #d9dfe8;
    --chat-muted: #6b7280;
    --chat-user-bg: #eef3fb;
    background: #ffffff;
    overflow: hidden;
}

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.chat-main {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 70px);
    height: calc(100dvh - 70px);
}

.chat-scroll {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.chat-inner {
    max-width: var(--chat-max);
    margin: 0 auto;
    padding: 24px 16px 8px;
}

/* ── Bienvenida ───────────────────────────────────────────────────────────── */
.chat-welcome[hidden] { display: none; }
.chat-welcome {
    text-align: center;
    padding: 6vh 0 16px;
}
.chat-welcome-fox {
    display: block;
    width: 84px;
    height: auto;
    margin: 0 auto 12px;
}
.chat-welcome h1 {
    font-family: 'Readex Pro', 'Poppins', sans-serif;
    font-size: clamp(1.8rem, 4vw, 2.4rem);
    color: #1a1a1a;
    margin: 0 0 10px;
}
.chat-welcome p {
    color: #1a1a1a;
    max-width: 560px;
    margin: 0 auto 24px;
    line-height: 1.55;
}
.chat-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}
.chat-chip {
    font: inherit;
    font-size: 0.92rem;
    color: #1a1a1a;
    background: #fff;
    border: 1px solid var(--chat-border);
    border-radius: 999px;
    padding: 9px 16px;
    cursor: pointer;
    transition: border-color .2s, color .2s, box-shadow .2s;
}
.chat-chip:hover, .chat-chip:focus-visible {
    border-color: var(--chat-blue);
    color: var(--chat-blue);
    box-shadow: 0 2px 10px rgba(0, 74, 173, .12);
    outline: none;
}

/* ── Nueva conversación ──────────────────────────────────────────────────── */
.chat-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 16px;
}
.chat-toolbar[hidden] { display: none; }
.chat-new {
    font: inherit;
    font-size: .85rem;
    color: var(--chat-muted);
    background: #fff;
    border: 1px solid var(--chat-border);
    border-radius: 999px;
    padding: 6px 14px;
    cursor: pointer;
    transition: color .2s, border-color .2s;
}
.chat-new:hover, .chat-new:focus-visible {
    color: var(--chat-blue);
    border-color: var(--chat-blue);
    outline: none;
}

/* ── Mensajes ─────────────────────────────────────────────────────────────── */
.chat-log {
    display: flex;
    flex-direction: column;
    gap: 22px;
}
.msg-user {
    align-self: flex-end;
    max-width: 82%;
    background: var(--chat-user-bg);
    color: #1a1a1a;
    border-radius: 20px 20px 4px 20px;
    padding: 10px 16px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.msg-bot {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    min-width: 0;
}
.msg-avatar {
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--chat-border);
    background: #fff url('../logo_fox.webp') center / 72% no-repeat;
}
.msg-body {
    flex: 1;
    min-width: 0;
    padding-top: 5px;
}
.msg-text {
    color: #1a1a1a;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.msg-text strong { font-weight: 600; }
.msg-error .msg-text { color: #b42318; }
.msg-retry {
    margin-top: 8px;
    font: inherit;
    font-size: .9rem;
    color: var(--chat-blue);
    background: none;
    border: 1px solid var(--chat-blue);
    border-radius: 999px;
    padding: 6px 14px;
    cursor: pointer;
}

/* Escribiendo… */
.typing {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--chat-muted);
    font-size: .95rem;
}
.typing-dots { display: inline-flex; gap: 4px; }
.typing-dots span {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--chat-blue);
    opacity: .3;
    animation: chat-dot 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes chat-dot {
    0%, 80%, 100% { opacity: .3; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

/* Sugerencias tras una respuesta */
.msg-body .chat-chips {
    justify-content: flex-start;
    margin-top: 12px;
}

/* ── Tarjetas de coches ───────────────────────────────────────────────────── */
.cars {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    margin-top: 14px;
    padding: 2px 2px 12px;
    scrollbar-width: thin;
}
.car {
    flex: 0 0 248px;
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #e5e9f0;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(15, 30, 60, .07);
}
.car-img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    background: #eef1f6;
    display: block;
}
.car-info {
    padding: 12px 14px 0;
    flex: 1;
}
.car-price {
    font-family: 'Readex Pro', 'Poppins', sans-serif;
    font-size: 1.25rem;
    font-weight: 600;
    color: #1a1a1a;
}
.car-deal {
    display: inline-block;
    margin-left: 6px;
    font-size: .72rem;
    font-weight: 600;
    color: #0f7a3d;
    background: #e5f6ec;
    border-radius: 6px;
    padding: 2px 6px;
    vertical-align: middle;
}
.car-title {
    font-size: .92rem;
    font-weight: 600;
    color: #1a1a1a;
    margin: 4px 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.car-meta, .car-place {
    font-size: .82rem;
    color: var(--chat-muted);
    line-height: 1.45;
}
.car-actions {
    display: flex;
    gap: 8px;
    padding: 12px 14px 14px;
}
.car-btn {
    flex: 1;
    text-align: center;
    font-size: .85rem;
    font-weight: 600;
    border-radius: 999px;
    padding: 8px 10px;
    text-decoration: none;
    white-space: nowrap;
}
.car-btn-outline {
    color: var(--chat-blue);
    border: 1px solid var(--chat-blue);
    background: #fff;
}
.car-btn-primary {
    color: #fff;
    background: var(--chat-blue);
    border: 1px solid var(--chat-blue);
}
.car-btn:hover { filter: brightness(1.08); }

/* ── Caja de escritura ────────────────────────────────────────────────────── */
.chat-composer-wrap {
    padding: 8px 16px calc(10px + env(safe-area-inset-bottom));
    background: #fff;
}
.chat-composer {
    max-width: var(--chat-max);
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #fff;
    border: 1px solid var(--chat-border);
    border-radius: 26px;
    padding: 8px 8px 8px 18px;
    box-shadow: 0 6px 24px rgba(15, 30, 60, .08);
    transition: border-color .2s;
}
.chat-composer:focus-within { border-color: var(--chat-blue); }
.chat-composer textarea {
    flex: 1;
    border: 0;
    outline: none;
    resize: none;
    font: inherit;
    font-size: 16px;            /* 16px: iOS no hace zoom al enfocar */
    line-height: 1.45;
    color: #1a1a1a;
    background: transparent;
    max-height: 180px;
    padding: 7px 0;
}
.chat-send {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 0;
    background: var(--chat-blue);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    transition: background .2s, opacity .2s;
}
.chat-composer.is-locked {
    background: #f3f5f8;
    box-shadow: none;
}
.chat-composer.is-locked textarea { cursor: not-allowed; }
.chat-composer.is-locked textarea::placeholder { color: #9aa3b2; }
.chat-chip:disabled {
    color: #9aa3b2;
    cursor: not-allowed;
    border-color: var(--chat-border);
    box-shadow: none;
}
.chat-send:disabled {
    background: #c9d2e0;
    cursor: default;
}
.chat-turnstile:empty { display: none; }
.chat-turnstile {
    display: flex;
    justify-content: center;
    margin-top: 8px;
}
.chat-legal {
    max-width: var(--chat-max);
    margin: 8px auto 0;
    text-align: center;
    font-size: 12px;
    color: var(--chat-muted);
}
.chat-legal a { color: inherit; text-decoration: underline; }

@media (max-width: 600px) {
    .chat-welcome { padding-top: 3vh; }
    .chat-welcome-fox { width: 64px; }
    .chat-chip { font-size: .86rem; padding: 8px 13px; }
    .msg-avatar { flex-basis: 28px; width: 28px; height: 28px; }
    .car { flex-basis: 224px; }
}

@media (prefers-reduced-motion: reduce) {
    .typing-dots span { animation: none; opacity: .6; }
}
