/* widget.css — globus del xat de femturisme.cat
   Branding: vermell corporatiu @coral (#CD5E5F), el mateix de ft.less.
   La posicio respecte .ft-fab-group i el sticky CTA s'ajusta a ft.less. */

#ft-chat-root {
    /* Tokens de marca del widget: tot el widget viu dins d'aquest node. */
    --ft-chat-brand: #cd5e5f;
    --ft-chat-brand-hover: #b84e4f;
    --ft-chat-brand-shadow: rgba(205, 94, 95, 0.35);
    --ft-chat-user-bg: #fdf3f3;
    --ft-chat-user-border: #eec7c7;
    --ft-chat-ok: #2f9e6e;

    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 9999;
    font-family: 'Segoe UI', system-ui, sans-serif;
}

/* Botó tancat: el cercle vermell el continua dibuixant el CSS, com abans;
   la il·lustració d'en Tonet (ell + el globus de punts, fons transparent) hi
   flota a sobre, una mica més gran que el cercle perque el cap i el globus
   sobresurtin del seu fons, com a l'exemple. */
#ft-chat-toggle {
    position: relative;
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    border: none;
    background: var(--ft-chat-brand);
    cursor: pointer;
    box-shadow: 0 8px 24px var(--ft-chat-brand-shadow);
}

#ft-chat-toggle:hover {
    background: var(--ft-chat-brand-hover);
}

#ft-chat-toggle img {
    position: absolute;
    top: 40%;
    left: 50%;
    width: 140%;
    height: 140%;
    /* ft.css imposa "img { max-width: 100%; height: auto }" a tot el portal;
       cal desactivar-ho aqui perque la imatge pugui ser mes gran que el boto. */
    max-width: none;
    max-height: none;
    transform: translate(-50%, -50%);
    object-fit: contain;
    pointer-events: none;
}

/* Backdrop: enfosqueix la pagina mentre el panell es obert i bloqueja els clics
   al contingut de darrere. Decisio de disseny provisional.
   El z-index del contenidor amb .is-open s'ajusta a ft.less (escala del portal). */
#ft-chat-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1;
    background: rgba(0, 0, 0, 0.45);
    cursor: pointer;
}

#ft-chat-backdrop[hidden] {
    display: none !important;
}

/* Amb el panell obert el globus no ha de flotar per sobre de l'overlay. */
#ft-chat-root.is-open #ft-chat-toggle {
    opacity: 0;
    pointer-events: none;
}

#ft-chat-panel {
    position: absolute;
    z-index: 2;
    right: 0;
    bottom: 4.25rem;
    width: min(30rem, calc(100vw - 2rem));
    max-height: min(32rem, calc(100vh - 6rem));
    background: #fff;
    border-radius: 1rem;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
    display: flex;
    flex-direction: column;
    /* visible, no hidden: deixa que en Tonet de la capçalera sobresurti per
       sobre de la vora arrodonida del panell (.ft-chat-header-art). L'arrodonit
       del panell el reprodueixen .ft-chat-header i .chat-input-area. */
    overflow: visible;
}

#ft-chat-panel[hidden] {
    display: none !important;
}

.ft-chat-header {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.85rem 1rem 0.85rem 5.4rem;
    background: var(--ft-chat-brand);
    color: #fff;
    border-radius: 1rem 1rem 0 0;
    overflow: visible;
}

/* En Tonet sobresurt per sobre de la franja vermella. */
.ft-chat-header-art {
    position: absolute;
    left: 0.5rem;
    top: -1.35rem;
    width: 5rem;
    height: 5rem;
    pointer-events: none;
}

.ft-chat-header-art img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.25));
}

.ft-chat-header-text {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    line-height: 1.25;
}

#ft-chat-title {
    font-weight: 600;
    font-size: 0.95rem;
}

#ft-chat-subtitle {
    font-size: 0.72rem;
    font-weight: 400;
    opacity: 0.9;
}

#ft-chat-close {
    border: none;
    background: transparent;
    color: #fff;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.4rem;
    padding-top: 0.5rem;
    padding-left: 0.1rem;
    background: #f8fafc;
}

.message {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    margin-bottom: 0.85rem;
}

.message-assistant {
    gap: 0rem;
}

.message-user {
    flex-direction: row-reverse;
    padding-left: 0.4rem;
}

.message-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--ft-chat-brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.85rem;
}

.message-user .message-avatar {
    background: #64748b;
}

/* Avatars d'en Tonet (benvinguda, respostes, errors): la il·lustració flota
   directament, sense cercle de color, perquè no es retalli cara ni braços. */
.message-avatar.message-avatar--tonet {
    width: 4.5rem;
    height: 4.5rem;
    background: transparent;
    border-radius: 0;
}

.message-avatar.message-avatar--tonet img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.message-bubble {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 0.65rem 0.85rem;
    font-size: 0.92rem;
    line-height: 1.45;
    max-width: 100%;
}

.message-user .message-bubble {
    background: var(--ft-chat-user-bg);
    border-color: var(--ft-chat-user-border);
}

.tool-indicator {
    font-size: 0.82rem;
    color: #475569;
    margin: 0.35rem 0 0.65rem 2.65rem;
}

.tool-indicator i {
    color: var(--ft-chat-ok);
}

.typing-indicator {
    display: flex;
    gap: 0.25rem;
    margin: 0 0 0.75rem 2.65rem;
}

.typing-dot {
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
    background: #94a3b8;
    animation: ft-bounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes ft-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40% { transform: translateY(-4px); opacity: 1; }
}

.chat-input-area {
    border-top: 1px solid #e2e8f0;
    padding: 0.75rem;
    background: #fff;
}

#chat-input {
    width: 100%;
    resize: none;
    border: 1px solid #cbd5e1;
    border-radius: 0.65rem;
    padding: 0.55rem 0.7rem;
    font-size: 0.92rem;
    margin-bottom: 0.5rem;
}

.ft-chat-actions {
    display: flex;
    gap: 0.5rem;
}

#btn-send,
#btn-reset {
    border: none;
    border-radius: 0.5rem;
    padding: 0.45rem 0.85rem;
    font-size: 0.85rem;
    cursor: pointer;
}

#btn-send {
    background: var(--ft-chat-brand);
    color: #fff;
    flex: 1;
}

#btn-send:hover:not(:disabled) {
    background: var(--ft-chat-brand-hover);
}

#btn-send:disabled {
    opacity: 0.6;
    cursor: default;
}

#btn-reset {
    background: #f1f5f9;
    color: #334155;
}

#btn-reset:hover {
    background: #e2e8f0;
}

/* Focus visible amb el color de marca (abans no n'hi havia cap d'explicit). */
#ft-chat-toggle:focus-visible,
#ft-chat-close:focus-visible,
#btn-send:focus-visible,
#btn-reset:focus-visible,
#chat-input:focus-visible {
    outline: 2px solid var(--ft-chat-brand);
    outline-offset: 2px;
}

#chat-input:focus {
    border-color: var(--ft-chat-brand);
    outline: none;
}

.ft-error-bubble {
    border-color: #fecaca !important;
    color: #991b1b;
}

.ft-chat-config-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: 0.5rem;
    padding: 0.75rem;
    max-width: 16rem;
    font-size: 0.85rem;
}

@media (max-width: 480px) {
    #ft-chat-panel {
        width: calc(100vw - 1.5rem);
        right: -0.5rem;
    }

    .ft-chat-header {
        padding-left: 4.4rem;
    }

    .ft-chat-header-art {
        width: 3.9rem;
        height: 3.9rem;
        top: -1rem;
    }

    .message-avatar.message-avatar--tonet {
        width: 3.6rem;
        height: 3.6rem;
    }

    #ft-chat-toggle {
        width: 3.2rem;
        height: 3.2rem;
    }
}
