/**
 * Styles for GlobalChat AI placement.
 *
 * @package    aiplacement_globalchat
 * @copyright  2025 Excelencia Academy
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

/* Toggle button (floating) with avatar */
.globalchat-toggle-btn {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    background: #fff;
    border: 3px solid #6366f1;
    overflow: hidden;
    padding: 0;
    cursor: pointer;
}

.globalchat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(99, 102, 241, 0.5);
    border-color: #4f46e5;
}

.globalchat-toggle-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3), 0 6px 25px rgba(99, 102, 241, 0.5);
}

.globalchat-toggle-btn.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

/* Icon container */
.globalchat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    position: relative;
    width: 100%;
    height: 100%;
}

/* Avatar image in toggle button */
.globalchat-toggle-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    border-radius: 50%;
}

.globalchat-icon svg {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

/* Pulse animation ring */
.globalchat-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.4);
    animation: globalchat-pulse-ring 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
    z-index: 1;
}

@keyframes globalchat-pulse-ring {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }
    50% {
        transform: scale(1.4);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 0;
    }
}

/* Stop pulse on hover */
.globalchat-toggle-btn:hover .globalchat-pulse {
    animation: none;
    opacity: 0;
}

/* Subtle bounce animation for icon */
.globalchat-toggle-btn:not(:hover) .globalchat-icon {
    animation: globalchat-icon-bounce 3s ease-in-out infinite;
}

@keyframes globalchat-icon-bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-3px);
    }
}

/* Drawer container */
.globalchat-drawer {
    position: fixed;
    right: -420px;
    bottom: 20px;
    width: 380px;
    height: auto;
    max-height: calc(100vh - 100px);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.globalchat-drawer.open {
    right: 20px;
}

/* Chat box */
.globalchat-chat-box {
    background: #e0e7ff;
    border-radius: 22px;
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: calc(100vh - 100px);
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

/* Header */
.globalchat-header {
    position: relative;
    background: #fefefe;
    border-radius: 22px 22px 0 0;
    box-shadow: 0 4px 4px rgba(0, 0, 0, 0.1);
    height: 57px;
    display: flex;
    align-items: center;
    padding: 0 15px;
}

.globalchat-header-close {
    position: absolute;
    top: 16px;
    right: 14px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    color: #4f46e5;
    transition: color 0.2s ease;
}

.globalchat-header-close:hover {
    color: #333;
}

.globalchat-new-conversation {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #6366f1;
    border: none;
    border-radius: 10px;
    padding: 8px 15px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.globalchat-new-conversation:hover {
    background: #4f46e5;
}

.globalchat-new-conversation svg {
    color: #fff;
}

.globalchat-conversation-title {
    color: #fff;
    font-size: 12px;
    font-weight: 600;
}

/* Avatar section */
.globalchat-avatar-section {
    display: flex;
    justify-content: center;
    padding: 20px 0;
    background: #c7d2fe;
}

.globalchat-avatar-container {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    background: transparent;
}

.globalchat-avatar-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    object-position: center top;
}

/* Assistant info */
.globalchat-assistant-info {
    text-align: center;
    padding: 0 20px 15px;
    background: #c7d2fe;
}

.globalchat-assistant-info h2 {
    color: #4f46e5;
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 8px 0;
}

.globalchat-assistant-info hr {
    margin: 8px auto;
    border: none;
    border-top: 1px solid #4f46e5;
    width: 80%;
    opacity: 0.5;
}

.globalchat-assistant-info p {
    color: #9a9a9a;
    font-size: 11px;
    font-weight: 600;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Messages area */
.globalchat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #6366f1;
    min-height: 200px;
    max-height: 350px;
}

/* Individual message */
.globalchat-message {
    margin-bottom: 12px;
    animation: globalchat-fadeIn 0.3s ease;
}

@keyframes globalchat-fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.globalchat-message-content {
    padding: 10px 14px;
    border-radius: 13px;
    max-width: 90%;
    word-wrap: break-word;
    font-size: 12px;
    line-height: 1.5;
}

/* User message */
.globalchat-message-user {
    display: flex;
    justify-content: flex-end;
}

.globalchat-message-user .globalchat-message-content {
    background: rgba(255, 255, 255, 0.95);
    color: #333;
    border-bottom-right-radius: 4px;
}

/* Assistant message */
.globalchat-message-assistant {
    display: flex;
    justify-content: flex-start;
}

.globalchat-message-assistant .globalchat-message-content {
    background: #818cf8;
    color: #fff;
    border-bottom-left-radius: 4px;
}

/* Error message */
.globalchat-message-error .globalchat-message-content {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Thinking indicator */
.globalchat-message.thinking .globalchat-message-content {
    background: rgba(255, 255, 255, 0.8);
    color: #4f46e5;
    font-style: italic;
}

.globalchat-message.thinking .globalchat-message-content::after {
    content: '...';
    animation: globalchat-dots 1.5s steps(4, end) infinite;
}

@keyframes globalchat-dots {
    0%, 20% {
        content: '.';
    }
    40% {
        content: '..';
    }
    60%, 100% {
        content: '...';
    }
}

/* Message content formatting */
.globalchat-message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
}

.globalchat-message-content pre {
    background: rgba(0, 0, 0, 0.05);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.globalchat-message-content pre code {
    background: none;
    padding: 0;
}

.globalchat-message-content a {
    color: inherit;
    text-decoration: underline;
}

.globalchat-message-content strong {
    font-weight: 700;
}

/* Footer */
.globalchat-footer {
    background: #fff;
    border-radius: 0 0 22px 22px;
    padding: 10px 15px;
}

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

.globalchat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 12px;
    color: #333;
    resize: none;
    outline: none;
    min-height: 24px;
    max-height: 80px;
    padding: 0;
}

.globalchat-input::placeholder {
    color: #9a9a9a;
}

.globalchat-send-btn {
    background: #6366f1;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
    color: #fff;
    flex-shrink: 0;
}

.globalchat-send-btn:hover {
    background: #4f46e5;
    transform: scale(1.05);
}

.globalchat-send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .globalchat-drawer {
        width: calc(100% - 20px);
        right: -100%;
        bottom: 10px;
        max-height: calc(100vh - 60px);
    }

    .globalchat-drawer.open {
        right: 10px;
    }

    .globalchat-toggle-btn {
        bottom: 16px;
        right: 16px;
        width: 54px;
        height: 54px;
    }

    .globalchat-icon svg {
        width: 24px;
        height: 24px;
    }

    .globalchat-messages {
        max-height: 200px;
        min-height: 150px;
    }

    .globalchat-avatar-section {
        padding: 15px 0;
    }

    .globalchat-avatar-container {
        width: 80px;
        height: 80px;
    }

    .globalchat-chat-box {
        max-height: calc(100vh - 60px);
    }
}

/* Scrollbar styling */
.globalchat-messages::-webkit-scrollbar {
    width: 4px;
}

.globalchat-messages::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

.globalchat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.5);
    border-radius: 2px;
}

.globalchat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.7);
}

/* Accessibility improvements */
.globalchat-drawer:focus-within {
    outline: 2px solid #6366f1;
    outline-offset: 2px;
}

/* Visually hidden but accessible */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Force light theme for chat components - override any dark mode */
.globalchat-drawer,
.globalchat-drawer *,
.globalchat-toggle-btn {
    color-scheme: light;
}

.globalchat-chat-box {
    color: #333;
}

/* Ensure visibility over Moodle elements */
.globalchat-drawer,
.globalchat-toggle-btn {
    isolation: isolate;
}
