/* Maya Chatbot Styles */
:root {
    --maya-primary: #007cba;
    --maya-secondary: #ffffff;
    --maya-text: #333333;
    --maya-primary-text: #ffffff; /* Default white text on primary background */
    --maya-secondary-text: #000000; /* Default black text on secondary background */
    --maya-font-family: inherit;
    --maya-border-radius: 8px;
    --maya-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    --maya-transition: all 0.3s ease;
}

/* Ionicons global styling for Maya widget */
.maya-chatbot-widget ion-icon {
    display: inline-block;
    vertical-align: middle;
}

/* Main widget container */
.maya-chatbot-widget {
    position: fixed;
    z-index: 9999;
    font-family: var(--maya-font-family);
    font-size: 14px;
    line-height: 1.4;
}

.maya-chatbot-widget.maya-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.maya-chatbot-widget.maya-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

.maya-chatbot-widget.maya-position-top-right {
    top: 20px;
    right: 20px;
}

.maya-chatbot-widget.maya-position-top-left {
    top: 20px;
    left: 20px;
}

/* Chat toggle button */
.maya-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--maya-primary);
    color: var(--maya-primary-text);
    border: none;
    cursor: pointer;
    box-shadow: var(--maya-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: var(--maya-transition);
    text-decoration: none;
    position: relative;
    overflow: hidden;
}

.maya-chat-toggle ion-icon {
    font-size: 28px;
    color: var(--maya-secondary);
    width: 28px;
    height: 28px;
}

.maya-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.maya-chat-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.2);
    border: 2px solid var(--maya-primary);
}

.maya-chat-toggle.maya-chat-active {
    background-color: #dc3545;
}

/* Chat window */
.maya-chat-window {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 350px;
    height: 500px;
    background: var(--maya-secondary);
    border-radius: var(--maya-border-radius);
    box-shadow: var(--maya-shadow);
    display: none;
    flex-direction: column;
    border: 2px solid var(--maya-primary);
    overflow: hidden;
    transition: var(--maya-transition);
}

.maya-chat-window.maya-chat-open {
    display: flex;
}

.maya-chat-window.maya-chat-minimized {
    height: 50px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .maya-chat-window {
        width: 300px;
        height: 450px;
        bottom: 70px;
        right: -10px;
    }
    
    .maya-chatbot-widget.maya-position-bottom-left .maya-chat-window {
        left: -10px;
        right: auto;
    }
}

@media (max-width: 480px) {
    .maya-chat-window {
        width: 280px;
        height: 400px;
    }
}

/* Chat header */
.maya-chat-header {
    background-color: var(--maya-primary);
    color: var(--maya-primary-text);
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 20px;
}

.maya-chat-title {
    font-weight: bold;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.maya-chat-controls {
    display: flex;
    gap: 5px;
}

.maya-chat-minimize,
.maya-chat-close,
.maya-clear-chat {
    background: none;
    border: none;
    color: var(--maya-primary-text);
    cursor: pointer;
    padding: 5px;
    border-radius: 3px;
    font-size: 14px;
    transition: var(--maya-transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.maya-chat-minimize:hover,
.maya-chat-close:hover,
.maya-clear-chat:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.maya-chat-minimize ion-icon,
.maya-chat-close ion-icon,
.maya-clear-chat ion-icon {
    font-size: 16px;
}

/* Messages container */
.maya-chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: var(--maya-secondary);
    display: none;
}

.maya-chat-window.maya-chat-open .maya-chat-messages {
    display: block;
}

.maya-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.maya-chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

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

/* Message styles */
.maya-message {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.maya-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    overflow: hidden;
    background-color: var(--maya-primary);
    color: var(--maya-primary-text);
}

.maya-message-avatar img {
    width: 32px !important;
    height: 32px !important;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    max-width: 32px !important;
    max-height: 32px !important;
}

.maya-message-avatar ion-icon {
    font-size: 18px;
}

.maya-chat-title .maya-avatar {
    width: 28px !important;
    height: 28px !important;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.2);
    margin-right: 8px;
    display: block;
    max-width: 28px !important;
    max-height: 28px !important;
}

.maya-message-content {
    flex: 1;
    min-width: 0;
}

.maya-message-name {
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 3px;
    color: var(--maya-text);
    opacity: 0.7;
}

.maya-message-text {
    padding: 10px 12px;
    border-radius: var(--maya-border-radius);
    word-wrap: break-word;
    line-height: 1.4;
}

/* User message styles */
.maya-user-message {
    flex-direction: row-reverse;
}

.maya-user-message .maya-message-text {
    background-color: var(--maya-primary);
    color: var(--maya-primary-text);
    margin-left: 20px;
}

.maya-user-message .maya-message-name {
    text-align: right;
}

/* Bot message styles */
.maya-bot-message .maya-message-text {
    background-color: var(--maya-secondary);
    color: var(--maya-secondary-text);
    border: 1px solid #e0e0e0;
    margin-right: 20px;
}

/* Text formatting in messages */
.maya-message-text strong {
    font-weight: bold;
}

.maya-message-text em {
    font-style: italic;
}

.maya-message-text code {
    background-color: rgba(0, 0, 0, 0.1);
    padding: 2px 4px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 12px;
}

/* Typing indicator */
.maya-typing-indicator .maya-message-text {
    background-color: var(--maya-secondary);
    border: 1px solid #e0e0e0;
}

.maya-typing-dots {
    display: flex;
    gap: 3px;
    padding: 5px 0;
}

.maya-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--maya-primary);
    animation: maya-typing-bounce 1.4s infinite ease-in-out;
}

.maya-typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.maya-typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes maya-typing-bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Streaming loading dots - shown while waiting for first response */
.maya-streaming-dots {
    display: flex;
    gap: 4px;
    padding: 8px 0;
    align-items: center;
}

.maya-streaming-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--maya-primary);
    animation: maya-streaming-pulse 1.5s infinite ease-in-out;
}

.maya-streaming-dots span:nth-child(1) {
    animation-delay: -0.4s;
}

.maya-streaming-dots span:nth-child(2) {
    animation-delay: -0.2s;
}

.maya-streaming-dots span:nth-child(3) {
    animation-delay: 0s;
}

@keyframes maya-streaming-pulse {
    0%, 60%, 100% {
        transform: scale(0.8);
        opacity: 0.4;
    }
    30% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* Chat input area */
.maya-chat-form {
    padding: 15px;
    border-top: 1px solid #e0e0e0;
    background: var(--maya-primary);
    display: none;
}

.maya-chat-window.maya-chat-open .maya-chat-form {
    display: block;
}

.maya-chat-input-container {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.maya-chat-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--maya-border-radius);
    font-family: var(--maya-font-family);
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    min-height: 20px;
    max-height: 100px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--maya-primary-text);
    transition: var(--maya-transition);
}

.maya-chat-input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1);
}

.maya-chat-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.maya-chat-submit {
    padding: 10px 15px;
    background-color: var(--maya-primary);
    color: var(--maya-primary-text);
    border: none;
    border-radius: var(--maya-border-radius);
    cursor: pointer;
    font-size: 14px;
    transition: var(--maya-transition);
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    align-self: flex-end;
}

.maya-chat-submit:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.maya-chat-submit:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.2);
}

.maya-chat-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.maya-chat-submit ion-icon {
    font-size: 16px;
}

/* Loading states */
.maya-chatbot-loading {
    opacity: 0.7;
    pointer-events: none;
}

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

.maya-message {
    animation: maya-fade-in 0.3s ease;
}

/* Error states */
.maya-error-message .maya-message-text {
    background-color: #fee;
    border-color: #fcc;
    color: #c33;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .maya-chat-window {
        border-width: 3px;
    }
    
    .maya-message-text {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support - only when not using custom colors */
@media (prefers-color-scheme: dark) {
    :root:not(.maya-custom-colors) {
        --maya-secondary: #2d3748;
        --maya-text: #e2e8f0;
        --maya-secondary-text: #e2e8f0;
    }
    
    .maya-chatbot-widget:not(.maya-custom-colors) .maya-chat-messages {
        background: #1a202c;
    }
    
    .maya-chatbot-widget:not(.maya-custom-colors) .maya-chat-input {
        background: #2d3748;
        color: #e2e8f0;
        border-color: #4a5568;
    }
    
    .maya-chatbot-widget:not(.maya-custom-colors) .maya-bot-message .maya-message-text {
        background-color: #2d3748;
        border-color: #4a5568;
    }
}

/* Tool use message styles */
.maya-tool-message .maya-message-text {
    background-color: transparent !important;
    border: none !important;
    padding: 0 !important;
}

.maya-tool-call {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: var(--maya-border-radius);
    padding: 12px;
    margin-right: 20px;
}

.maya-tool-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: bold;
    color: var(--maya-primary);
    margin-bottom: 8px;
    font-size: 13px;
}

.maya-tool-header ion-icon {
    font-size: 16px;
    color: var(--maya-primary);
}

.maya-tool-args {
    font-size: 12px;
    color: #6c757d;
    margin-bottom: 8px;
    font-style: italic;
}

.maya-tool-success {
    color: #28a745;
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 6px;
}

.maya-tool-error {
    color: #dc3545;
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 6px;
}

.maya-tool-preview {
    background-color: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 8px;
    font-size: 11px;
    line-height: 1.3;
    margin-top: 4px;
}

.maya-tool-item {
    margin-bottom: 4px;
    color: #495057;
}

.maya-tool-item:last-child {
    margin-bottom: 0;
}

.maya-tool-more {
    color: #6c757d;
    font-style: italic;
    margin-top: 4px;
}

/* Dark mode support for tool messages */
@media (prefers-color-scheme: dark) {
    .maya-chatbot-widget:not(.maya-custom-colors) .maya-tool-call {
        background-color: #374151;
        border-color: #4b5563;
    }
    
    .maya-chatbot-widget:not(.maya-custom-colors) .maya-tool-args {
        color: #9ca3af;
    }
    
    .maya-chatbot-widget:not(.maya-custom-colors) .maya-tool-preview {
        background-color: #1f2937;
        border-color: #374151;
    }
    
    .maya-chatbot-widget:not(.maya-custom-colors) .maya-tool-item {
        color: #d1d5db;
    }
    
    .maya-chatbot-widget:not(.maya-custom-colors) .maya-tool-more {
        color: #9ca3af;
    }
    
    .maya-chatbot-widget:not(.maya-custom-colors) .maya-tool-indicator {
        background-color: #1e3a8a;
        color: #93c5fd;
    }
}

/* Tool indicator for streaming */
.maya-tool-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background-color: #e3f2fd;
    color: #1976d2;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    margin: 4px 0;
    animation: maya-pulse 1.5s ease-in-out infinite;
}

.maya-tool-indicator ion-icon {
    font-size: 14px;
}

@keyframes maya-pulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}