/**
 * Chatbot Widget Styles
 * Floating chat interface for SCORM courses
 *
 * Author: Médéric (Académie des Étoiles)
 * Date: 2025-11-25
 */

/* ==================================================
   Floating Button
   ================================================== */

.chatbot-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: white;
    border: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 9998;
    padding: 8px;
    overflow: hidden;
}

/* Responsive: Move chatbot above audio player */
@media (max-width: 1100px) {
    .chatbot-button {
        bottom: 100px;  /* Above audio (which is at bottom 24px + 54px height + gap) */
    }

    .chatbot-modal {
        bottom: 180px;  /* Above chatbot button */
    }

    .chatbot-modal__content {
        width: calc(100% - 48px);
        max-width: 500px;
        height: 600px;
        max-height: calc(100vh - 200px);
    }
}

.chatbot-button img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.chatbot-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(255, 99, 30, 0.4);
}

.chatbot-button.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

/* ==================================================
   Modal Container
   ================================================== */

.chatbot-modal {
    position: fixed;
    bottom: 100px;
    right: 24px;
    z-index: 9999;
    display: none;
}

.chatbot-modal.open {
    display: block;
}

.chatbot-modal__overlay {
    display: none;
}

.chatbot-modal__content {
    position: relative;
    width: 550px;
    height: 700px;
    background: white;
    border-radius: 0;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==================================================
   Modal Header
   ================================================== */

.chatbot-modal__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: linear-gradient(135deg, #ff631e 0%, #e55a1a 100%);
    color: white;
    flex-shrink: 0;
}

.chatbot-modal__title {
    font-size: 18px;
    font-weight: 600;
}

.chatbot-modal__close {
    margin-left: auto;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: white;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chatbot-modal__close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ==================================================
   Mode Switcher (Course vs Training)
   ================================================== */

.chatbot-mode-switch {
    display: flex;
    gap: 4px;
    background: rgba(255, 255, 255, 0.15);
    padding: 4px;
    border-radius: 0;
}

.chatbot-mode-btn {
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    font-size: 13px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    font-weight: 500;
}

.chatbot-mode-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.chatbot-mode-btn.active {
    background: white;
    color: #ff631e;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ==================================================
   Messages Container
   ================================================== */

.chatbot-modal__messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f7f8fa;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chatbot-modal__messages::-webkit-scrollbar {
    width: 8px;
}

.chatbot-modal__messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-modal__messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

.chatbot-modal__messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* ==================================================
   Messages
   ================================================== */

.chatbot-message {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.chatbot-message--user {
    flex-direction: row-reverse;
}

.chatbot-message__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 1.25rem;
}

.chatbot-message__avatar--bot {
    background: #f7fafc;
    padding: 4px;
}

.chatbot-message__avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.chatbot-message__avatar--user {
    background: linear-gradient(135deg, #ff631e 0%, #e55a1a 100%);
    color: white;
}

.chatbot-message__content {
    flex: 1;
    background: white;
    padding: 12px 16px;
    border-radius: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    max-width: 75%;
}

.chatbot-message--user .chatbot-message__content {
    background: linear-gradient(135deg, #ff631e 0%, #e55a1a 100%);
    color: white;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
}

.chatbot-message__content p {
    margin: 0 0 8px 0;
    line-height: 1.5;
}

.chatbot-message__content p:last-child {
    margin-bottom: 0;
}

.chatbot-message__content strong {
    font-weight: 600;
}

.chatbot-message__content em {
    font-style: italic;
}

.chatbot-message__content code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.chatbot-message--user .chatbot-message__content code {
    background: rgba(255, 255, 255, 0.2);
}

.chatbot-message__content a {
    color: #ff631e;
    text-decoration: underline;
}

.chatbot-message--user .chatbot-message__content a {
    color: white;
}

.chatbot-message__content ul,
.chatbot-message__content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.chatbot-message__content li {
    margin: 4px 0;
    line-height: 1.5;
}

.chatbot-message__content li.checkbox-item {
    list-style: none;
    margin-left: -24px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chatbot-message__content li.checkbox-item input[type="checkbox"] {
    margin: 0;
    cursor: default;
}

.chatbot-message__content h1,
.chatbot-message__content h2,
.chatbot-message__content h3 {
    margin: 12px 0 8px 0;
    font-weight: 600;
}

.chatbot-message__content h1 { font-size: 1.5em; }
.chatbot-message__content h2 { font-size: 1.3em; }
.chatbot-message__content h3 { font-size: 1.1em; }

.chatbot-message__content pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.chatbot-message__content pre code {
    background: none;
    padding: 0;
}

.chatbot-message__content .markdown-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 14px;
}

.chatbot-message__content .markdown-table th {
    background: #f7f8fa;
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    border: 1px solid #e2e8f0;
}

.chatbot-message__content .markdown-table td {
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
}

.chatbot-message__content .markdown-table tr:nth-child(even) {
    background: #f7f8fa;
}

/* ==================================================
   System Messages
   ================================================== */

.chatbot-message--system {
    justify-content: center;
}

.chatbot-message--system .chatbot-message__content {
    background: #e2e8f0;
    color: #4a5568;
    font-size: 13px;
    font-style: italic;
    text-align: center;
    max-width: 90%;
    box-shadow: none;
}

/* ==================================================
   Loading State
   ================================================== */

.chatbot-message--loading .chatbot-message__content {
    padding: 16px;
}

.chatbot-loading-dots {
    display: flex;
    gap: 6px;
    align-items: center;
}

.chatbot-loading-dots span {
    width: 8px;
    height: 8px;
    background: #cbd5e0;
    border-radius: 50%;
    animation: pulse 1.4s infinite ease-in-out;
}

.chatbot-loading-dots span:nth-child(1) {
    animation-delay: 0s;
}

.chatbot-loading-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-loading-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pulse {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(1);
    }
    40% {
        opacity: 1;
        transform: scale(1.3);
    }
}

/* ==================================================
   Error State
   ================================================== */

.chatbot-message--error .chatbot-message__content {
    background: #fed7d7;
    color: #c53030;
    border-left: 4px solid #fc8181;
}

/* ==================================================
   Sources/Citations (matches standalone version)
   ================================================== */

.chatbot-message-sources {
    margin-top: 0.75rem;
    font-size: 0.875rem;
}

.chatbot-message-sources details {
    background: rgba(0, 0, 0, 0.02);
    border-radius: 0;
    padding: 0.5rem;
}

.chatbot-message-sources summary {
    cursor: pointer;
    font-weight: 500;
    color: #ff631e;
    padding: 0.25rem;
    user-select: none;
    list-style: none;
}

.chatbot-message-sources summary::-webkit-details-marker {
    display: none;
}

.chatbot-message-sources summary:hover {
    color: #e55a1a;
}

.chatbot-source-item {
    margin: 0.75rem 0;
    padding: 0.75rem;
    background: white;
    border-radius: 6px;
    border-left: 3px solid #ff631e;
}

.chatbot-source-badge {
    display: inline-block;
    background: #ff631e;
    color: white;
    padding: 2px 8px;
    border-radius: 0;
    font-size: 0.75rem;
    font-weight: 600;
    margin-right: 0.5rem;
}

.chatbot-source-excerpt {
    margin-top: 0.5rem;
    color: #718096;
    font-size: 0.85em;
    font-style: italic;
    white-space: pre-wrap;
}

/* ==================================================
   Input Area
   ================================================== */

.chatbot-modal__input {
    display: flex;
    gap: 8px;
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.chatbot-modal__input input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 15px;
    outline: none;
    transition: all 0.2s;
}

.chatbot-modal__input input:focus {
    border-color: #ff631e;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chatbot-modal__input input::placeholder {
    color: #a0aec0;
}

.chatbot-modal__input button {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #ff631e 0%, #e55a1a 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chatbot-modal__input button:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.chatbot-modal__input button:active {
    transform: scale(0.95);
}

/* ==================================================
   Responsive Design
   ================================================== */

@media (max-width: 640px) {
    /* Keep modal sizing from 1100px query */

    /* Slightly smaller button on very small screens */
    .chatbot-button {
        width: 56px;
        height: 56px;
    }

    .chatbot-mode-switch {
        display: none;
    }

    .chatbot-message__content {
        max-width: 85%;
    }
}

@media (max-width: 400px) {
    .chatbot-modal__messages {
        padding: 12px;
    }

    .chatbot-message__avatar {
        width: 32px;
        height: 32px;
    }

    .chatbot-message__content {
        font-size: 14px;
    }
}

/* ==================================================
   Print Styles (Hide widget when printing)
   ================================================== */

@media print {
    .chatbot-button,
    .chatbot-modal {
        display: none !important;
    }
}

/* Hide chatbot when audio player is expanded on mobile */
@media (max-width: 1100px) {
    .audio-player:not(.audio-player--minimized) ~ .chatbot-button,
    .audio-player:not(.audio-player--minimized) ~ .chatbot-modal {
        display: none !important;
    }
}
