/**
 * Mediapilote AI Chatbot Client - Frontend Styles
 */

:root {
    --mediapilote-chat-primary: #007bff;
    --mediapilote-chat-primary-dark: #0056b3;
    --mediapilote-chat-bg: #ffffff;
    --mediapilote-chat-border: #e0e0e0;
    --mediapilote-chat-text: #333333;
    --mediapilote-chat-text-light: #666666;
    --mediapilote-chat-user-bg: var(--mediapilote-chat-primary);
    --mediapilote-chat-bot-bg: #f5f5f5;
    --mediapilote-chat-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* Allow customization via CSS variables from PHP */
#mediapilote-chatbot-widget {
    --mediapilote-chat-primary: var(--mpai-primary-color, #007bff);
    --mediapilote-chat-primary-dark: var(--mpai-primary-dark, #0056b3);
    --mediapilote-chat-user-bg: var(--mpai-primary-color, #007bff);
    --mediapilote-chat-btn-text: var(--mpai-text-color, #ffffff);
    /* Police système moderne */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    /* Hidden by default, JS will show after status check */
    display: none;
}

/* Chat Button */
.mediapilote-chat-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--mediapilote-chat-primary);
    border: none;
    cursor: pointer;
    box-shadow: var(--mediapilote-chat-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, background-color 0.3s ease;
    z-index: 9999999;
}

.mediapilote-chat-button:hover {
    transform: scale(1.1);
    background: var(--mediapilote-chat-primary-dark);
}

.mediapilote-chat-button svg {
    width: 28px;
    height: 28px;
    fill: var(--mediapilote-chat-btn-text, white);
}

.mediapilote-chat-button.active .chat-icon {
    display: none;
}

.mediapilote-chat-button.active .close-icon {
    display: block;
}

.mediapilote-chat-button .close-icon {
    display: none;
}

/* Chat Window */
.mediapilote-chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 520px;
    max-height: calc(100vh - 150px);
    background: var(--mediapilote-chat-bg);
    border-radius: 16px;
    box-shadow: var(--mediapilote-chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999998;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    /* Police système moderne - isolation du thème WP */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

.mediapilote-chat-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Chat Header */
.mediapilote-chat-header {
    background: var(--mediapilote-chat-primary);
    color: var(--mediapilote-chat-btn-text, white);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.mediapilote-chat-header-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.mediapilote-chat-header-avatar svg,
.mediapilote-chat-header-avatar img {
    width: 32px;
    height: 32px;
    fill: var(--mediapilote-chat-primary);
    background: #fff;
    border-radius: 50%;
    padding: 2px;
    object-fit: cover;
}

.mediapilote-chat-header-avatar svg {
    width: 24px;
    height: 24px;
    fill: white;
}

.mediapilote-chat-header-info h4 {
    margin: 0 0 2px 0;
    font-size: 16px;
    font-weight: 600;
}

.mediapilote-chat-header-info p {
    margin: 0;
    font-size: 12px;
    opacity: 0.8;
}

.mediapilote-chat-header-info {
    flex: 1;
}

/* Close Button (in header, mobile only) */
.mediapilote-chat-close {
    display: none; /* Hidden on desktop */
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.mediapilote-chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.mediapilote-chat-close svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* New Conversation Button */
.mediapilote-chat-new {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.mediapilote-chat-new:hover {
    background: rgba(255, 255, 255, 0.3);
}

.mediapilote-chat-new svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Chat Messages */
.mediapilote-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.mediapilote-chat-message {
    max-width: 85%;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mediapilote-chat-message.user {
    align-self: flex-end;
}

.mediapilote-chat-message.bot {
    align-self: flex-start;
}

.mediapilote-chat-message-content {
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 14px;
}

.mediapilote-chat-message.user .mediapilote-chat-message-content {
    background: var(--mediapilote-chat-user-bg);
    color: var(--mediapilote-chat-btn-text, white);
    border-bottom-right-radius: 4px;
}

.mediapilote-chat-message.bot .mediapilote-chat-message-content {
    background: var(--mediapilote-chat-bot-bg);
    color: var(--mediapilote-chat-text);
    border-bottom-left-radius: 4px;
}

/* Typing cursor effect */
.mediapilote-chat-message-content.typing::after {
    content: '|';
    display: inline;
    animation: blink-cursor 0.8s infinite;
    color: var(--mediapilote-chat-primary);
    font-weight: 300;
    margin-left: 2px;
}

@keyframes blink-cursor {

    0%,
    50% {
        opacity: 1;
    }

    51%,
    100% {
        opacity: 0;
    }
}

/* Message Content Styling */
.mediapilote-chat-message-content p {
    margin: 0 0 8px 0;
}

.mediapilote-chat-message-content p:last-child {
    margin-bottom: 0;
}

.mediapilote-chat-message-content ul,
.mediapilote-chat-message-content ol {
    margin: 0 0 8px 0;
    padding-left: 20px;
}

.mediapilote-chat-message-content li {
    margin-bottom: 4px;
}

.mediapilote-chat-message-content h3,
.mediapilote-chat-message-content h4 {
    margin: 16px 0 8px 0;
    font-size: 1.1em;
    font-weight: 600;
}

.mediapilote-chat-message-content h3:first-child,
.mediapilote-chat-message-content h4:first-child {
    margin-top: 0;
}

.mediapilote-chat-message-content a {
    color: var(--mediapilote-chat-primary);
    text-decoration: underline;
}

.mediapilote-chat-message.user .mediapilote-chat-message-content a {
    color: var(--mediapilote-chat-btn-text, white);
}

/* Custom Button */
a.mediapilote-chat-custom-button {
    display: inline-block;
    padding: 8px 16px;
    background-color: var(--mediapilote-chat-primary);
    color: #ffffff !important;
    border-radius: 20px;
    text-decoration: none !important;
    margin-top: 10px;
    font-weight: 500;
    transition: background 0.2s, transform 0.1s;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

a.mediapilote-chat-custom-button:hover {
    background-color: var(--mediapilote-chat-primary-dark);
    text-decoration: none !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
}

a.mediapilote-chat-custom-button:active {
    transform: translateY(1px);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Markdown code */
.mediapilote-chat-message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: monospace;
}

/* Sources */
.mediapilote-chat-sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--mediapilote-chat-border);
    font-size: 12px;
}

.mediapilote-chat-sources-title {
    font-weight: 600;
    color: var(--mediapilote-chat-text-light);
    margin-bottom: 6px;
}

.mediapilote-chat-sources-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mediapilote-chat-sources-list a {
    color: var(--mediapilote-chat-primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 4px;
}

.mediapilote-chat-sources-list a:hover {
    text-decoration: underline;
}

.mediapilote-chat-sources-list a svg {
    width: 12px;
    height: 12px;
    fill: currentColor;
    flex-shrink: 0;
}

/* Typing Indicator */
.mediapilote-chat-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--mediapilote-chat-bot-bg);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.mediapilote-chat-typing-dots {
    display: flex;
    gap: 4px;
}

.mediapilote-chat-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--mediapilote-chat-text-light);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.mediapilote-chat-typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.mediapilote-chat-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.mediapilote-chat-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-6px);
    }
}

/* Chat Input */
.mediapilote-chat-input-container {
    padding: 16px 20px;
    border-top: 1px solid var(--mediapilote-chat-border);
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.mediapilote-chat-input {
    flex: 1;
    border: 1px solid var(--mediapilote-chat-border);
    border-radius: 24px;
    padding: 12px 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s ease;
    resize: none;
    max-height: 100px;
    font-family: inherit;
}

.mediapilote-chat-input:focus {
    border-color: var(--mediapilote-chat-primary);
}

.mediapilote-chat-input::placeholder {
    color: var(--mediapilote-chat-text-light);
}

.mediapilote-chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--mediapilote-chat-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.mediapilote-chat-send:hover {
    background: var(--mediapilote-chat-primary-dark);
}

.mediapilote-chat-send:active {
    transform: scale(0.95);
}

.mediapilote-chat-send:disabled {
    background: var(--mediapilote-chat-border);
    cursor: not-allowed;
}

.mediapilote-chat-send svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Microphone Button */
.mediapilote-chat-mic {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: transparent;
    border: 2px solid var(--mediapilote-chat-border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.mediapilote-chat-mic svg {
    width: 20px;
    height: 20px;
    fill: var(--mediapilote-chat-text-light);
    transition: fill 0.3s ease;
}

.mediapilote-chat-mic:hover {
    border-color: var(--mediapilote-chat-primary);
}

.mediapilote-chat-mic:hover svg {
    fill: var(--mediapilote-chat-primary);
}

.mediapilote-chat-mic.recording {
    background: #dc3545;
    border-color: #dc3545;
    animation: pulse-recording 1.5s infinite;
}

.mediapilote-chat-mic.recording svg {
    fill: white;
}

.mediapilote-chat-mic.recording .mic-icon {
    display: none;
}

.mediapilote-chat-mic.recording .stop-icon {
    display: block !important;
}

.mediapilote-chat-mic.transcribing {
    background: var(--mediapilote-chat-primary);
    border-color: var(--mediapilote-chat-primary);
    opacity: 0.7;
    pointer-events: none;
}

.mediapilote-chat-mic.transcribing svg {
    fill: white;
    animation: spin 1s linear infinite;
}

@keyframes pulse-recording {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4);
    }

    50% {
        box-shadow: 0 0 0 10px rgba(220, 53, 69, 0);
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Message Content with Space for Speaker Button */
.mediapilote-chat-message.bot .mediapilote-chat-message-content {
    position: relative;
    padding-bottom: 36px;
    min-width: 60px;
}

/* TTS Speak Button */
.mediapilote-chat-speak {
    position: absolute;
    bottom: 4px;
    right: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--mediapilote-chat-border);
    cursor: pointer;
    margin: 0;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.mediapilote-chat-speak svg {
    width: 14px;
    height: 14px;
    fill: var(--mediapilote-chat-text-light);
    transition: fill 0.2s ease;
}

.mediapilote-chat-speak:hover {
    border-color: var(--mediapilote-chat-primary);
    background: rgba(0, 123, 255, 0.1);
}

.mediapilote-chat-speak:hover svg {
    fill: var(--mediapilote-chat-primary);
}

.mediapilote-chat-speak.playing {
    background: var(--mediapilote-chat-primary);
    border-color: var(--mediapilote-chat-primary);
}

.mediapilote-chat-speak.playing svg {
    fill: white;
}

.mediapilote-chat-speak.loading {
    opacity: 0.6;
    pointer-events: none;
}

.mediapilote-chat-speak.loading svg {
    animation: spin 1s linear infinite;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .mediapilote-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .mediapilote-chat-button {
        bottom: 16px;
        right: 16px;
    }

    /* Hide floating button when chat is open on mobile */
    .mediapilote-chat-button.active {
        display: none !important;
    }

    .mediapilote-chat-header {
        padding: 20px;
    }

    /* Show close button in header on mobile */
    .mediapilote-chat-close {
        display: flex;
    }
}

/* Scrollbar styling */
.mediapilote-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.mediapilote-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.mediapilote-chat-messages::-webkit-scrollbar-thumb {
    background: var(--mediapilote-chat-border);
    border-radius: 3px;
}

.mediapilote-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--mediapilote-chat-text-light);
}

/* Rating Buttons */
.mediapilote-chat-rating {
    display: flex;
    gap: 4px;
    margin-top: 6px;
}

.mediapilote-chat-rate {
    background: transparent;
    border: 1px solid var(--mediapilote-chat-border);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    opacity: 0.5;
    padding: 0;
    line-height: 1;
}

.mediapilote-chat-rate:hover {
    opacity: 1;
    transform: scale(1.1);
}

.mediapilote-chat-rate.selected {
    opacity: 1;
    border-color: var(--mediapilote-chat-primary);
    background: rgba(0, 123, 255, 0.1);
}

.mediapilote-chat-rate.selected[data-rating="up"] {
    border-color: #10B981;
    background: rgba(16, 185, 129, 0.1);
}

.mediapilote-chat-rate.selected[data-rating="down"] {
    border-color: #EF4444;
    background: rgba(239, 68, 68, 0.1);
}

/* Conversation Rating Banner */
.mediapilote-chat-conv-rating {
    text-align: center;
    padding: 12px;
    border-top: 1px solid var(--mediapilote-chat-border);
    background: var(--mediapilote-chat-bot-bg);
    border-radius: 12px;
    margin-top: 8px;
}