/**
 * Disseny estètic premium per al widget de xat frontal de PidiXat AI
 */

:root {
    --pidixat-primary: #6366f1;
    --pidixat-primary-hover: #4f46e5;
    --pidixat-bg-header: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
    --pidixat-bg-window: #ffffff;
    --pidixat-bg-user: #6366f1;
    --pidixat-bg-bot: #f1f5f9;
    --pidixat-color-user: #ffffff;
    --pidixat-color-bot: #1e293b;
    --pidixat-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --pidixat-radius: 16px;
}

/* Contenidor flotant */
#pidixat-root {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    line-height: 1.5;
}

/* Botó disparador (Trigger) */
.pidixat-trigger {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
}

.pidixat-trigger:hover {
    transform: scale(1.08) rotate(5deg);
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.5);
}

.pidixat-trigger.active {
    transform: rotate(90deg);
}

.pidixat-trigger-icon {
    font-size: 28px;
    color: #ffffff;
    display: block;
    line-height: 1;
}

/* Finestra de xat */
.pidixat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 360px;
    height: 560px;
    max-height: calc(100vh - 120px);
    background-color: var(--pidixat-bg-window);
    border-radius: var(--pidixat-radius);
    box-shadow: var(--pidixat-shadow);
    border: 1px solid rgba(226, 232, 240, 0.8);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 1;
    transform: translateY(0);
}

.pidixat-window.pidixat-hidden {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
}

/* Capçalera del Widget */
.pidixat-widget-header {
    background: var(--pidixat-bg-header);
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #ffffff;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.pidixat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pidixat-header-avatar {
    font-size: 24px;
    background: rgba(255, 255, 255, 0.15);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pidixat-header-title {
    font-size: 15px;
    font-weight: 700;
    margin: 0;
    color: #ffffff;
    line-height: 1.2;
}

.pidixat-header-status {
    font-size: 11px;
    color: #a5b4fc;
    display: block;
    margin-top: 2px;
}

.pidixat-header-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
    line-height: 0.5;
    transition: color 0.15s ease;
}

.pidixat-header-close:hover {
    color: #ffffff;
}

/* Cos dels Missatges */
.pidixat-messages-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Scrollbar Personalitzat */
.pidixat-messages-body::-webkit-scrollbar {
    width: 6px;
}
.pidixat-messages-body::-webkit-scrollbar-track {
    background: transparent;
}
.pidixat-messages-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 9999px;
}
.pidixat-messages-body::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Bombolles de Missatge */
.pidixat-message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 14px;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    word-wrap: break-word;
    animation: pidixat-fade-in 0.25s ease-out;
}

@keyframes pidixat-fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.pidixat-msg-user {
    align-self: flex-end;
    background-color: var(--pidixat-bg-user);
    color: var(--pidixat-color-user);
    border-bottom-right-radius: 2px;
}

.pidixat-msg-assistant {
    align-self: flex-start;
    background-color: var(--pidixat-bg-bot);
    color: var(--pidixat-color-bot);
    border-bottom-left-radius: 2px;
    border: 1px solid rgba(226, 232, 240, 0.8);
}

.pidixat-msg-system {
    align-self: center;
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fee2e2;
    font-size: 12.5px;
    border-radius: 8px;
    max-width: 90%;
    text-align: center;
}

.pidixat-message-content p {
    margin: 0 0 10px 0;
}
.pidixat-message-content p:last-child {
    margin-bottom: 0;
}
.pidixat-message-content strong {
    font-weight: 700;
}
.pidixat-message-content code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}
.pidixat-msg-user .pidixat-message-content code {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}
.pidixat-message-content ul {
    margin: 5px 0;
    padding-left: 20px;
}
.pidixat-message-content li {
    margin-bottom: 3px;
}

.pidixat-link {
    color: #4f46e5;
    text-decoration: underline;
    font-weight: 600;
}
.pidixat-msg-user .pidixat-link {
    color: #ffffff;
}

/* Temps de missatge */
.pidixat-message-time {
    display: block;
    font-size: 9px;
    opacity: 0.6;
    text-align: right;
    margin-top: 4px;
}
.pidixat-msg-user .pidixat-message-time {
    color: rgba(255, 255, 255, 0.8);
}

/* Indicador d'escriptura (Typing) */
.pidixat-typing-indicator {
    align-self: flex-start;
    background-color: var(--pidixat-bg-bot);
    padding: 10px 16px;
    border-radius: 14px;
    border-bottom-left-radius: 2px;
    margin-left: 20px;
    margin-bottom: 10px;
    display: flex;
    gap: 4px;
    align-items: center;
}

.pidixat-typing-indicator .dot {
    width: 6px;
    height: 6px;
    background-color: #94a3b8;
    border-radius: 50%;
    animation: pidixat-bounce 1.4s infinite ease-in-out both;
}

.pidixat-typing-indicator .dot:nth-child(1) { animation-delay: -0.32s; }
.pidixat-typing-indicator .dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes pidixat-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

.pidixat-hidden {
    display: none !important;
}

/* Peu de pàgina (Footer) i Formulari */
.pidixat-widget-footer {
    padding: 15px 20px;
    background-color: #ffffff;
    border-top: 1px solid #e2e8f0;
}

.pidixat-chat-form {
    display: flex;
    gap: 10px;
    align-items: center;
}

.pidixat-input-field {
    flex: 1;
    border: 1px solid #cbd5e1;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 13.5px;
    color: #1e293b;
    outline: none;
    transition: all 0.2s ease;
    background-color: #f8fafc;
}

.pidixat-input-field:focus {
    border-color: var(--pidixat-primary);
    background-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.pidixat-submit-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background-color: var(--pidixat-primary);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.pidixat-submit-btn:hover:not(:disabled) {
    background-color: var(--pidixat-primary-hover);
    transform: scale(1.05);
}

.pidixat-submit-btn:disabled {
    background-color: #cbd5e1;
    cursor: not-allowed;
}

/* Avís de Xat Bloquejat */
.pidixat-blocked-notice {
    padding: 8px 12px;
    background-color: #fee2e2;
    border: 1px solid #fca5a5;
    color: #991b1b;
    border-radius: 8px;
    font-size: 12px;
    text-align: center;
    font-weight: 500;
}

/* Adaptació Responsiva Mòbil completa */
@media (max-width: 768px) {
    #pidixat-root {
        bottom: 20px;
        right: 20px;
    }
    
    .pidixat-window {
        position: fixed;
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        height: calc(var(--vh, 1vh) * 100);
        max-height: 100%;
        border-radius: 0;
        z-index: 9999999;
    }
    
    .pidixat-trigger.active {
        display: none; /* Amaguem el trigger quan el xat mòbil està a pantalla completa */
    }
}
