/* ===== FLOATING CHATBOT WIDGET ===== */

:root {
    --chatbot-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --chatbot-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
    --chatbot-border-radius: 16px;
    --chatbot-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --chatbot-z-index: 9999;
}

/* ===== FLOATING BUTTON ===== */
.floating-chatbot-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: var(--chatbot-primary);
    border: none;
    border-radius: 50%;
    box-shadow: var(--chatbot-shadow);
    cursor: pointer;
    z-index: 10000;
    transition: var(--chatbot-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.floating-chatbot-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(102, 126, 234, 0.4);
}

.floating-chatbot-button.active {
    transform: scale(0.9);
}

.floating-chatbot-button i {
    color: white;
    font-size: 24px;
    transition: var(--chatbot-transition);
}

.floating-chatbot-button.minimized i:before {
    content: "\f086"; /* fa-comments */
}

.floating-chatbot-button.expanded i:before {
    content: "\f00d"; /* fa-times */
}

/* Pulse animation for new messages */
.floating-chatbot-button.has-new-message {
    animation: chatbot-pulse 2s infinite;
}

@keyframes chatbot-pulse {
    0% { box-shadow: var(--chatbot-shadow); }
    50% { box-shadow: 0 8px 32px rgba(102, 126, 234, 0.6), 0 0 0 10px rgba(102, 126, 234, 0.2); }
    100% { box-shadow: var(--chatbot-shadow); }
}

/* ===== CHAT WIDGET ===== */
.floating-chatbot-widget {
    position: fixed;
    bottom: 100px;
    right: 24px;
    background: white;
    border-radius: var(--chatbot-border-radius);
    box-shadow: var(--chatbot-shadow);
    z-index: 9999;
    transition: var(--chatbot-transition);
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    visibility: hidden;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
}

/* Full mode specific styling */
.floating-chatbot-widget.size-full {
    border-radius: 20px;
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.95);
}

.floating-chatbot-widget.size-full .chatbot-header {
    border-radius: 20px 20px 0 0;
}

.floating-chatbot-widget.size-full .chatbot-messages {
    height: calc(100% - 200px);
}

.floating-chatbot-widget.size-full .chatbot-input-area {
    min-height: 120px;
    max-height: 200px;
}

/* ===== EXPANDED WIDGET FEATURES ===== */

/* Model Selector for Full Mode */
.chatbot-model-selector {
    display: none;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #f8f9fa;
}

.floating-chatbot-widget.size-full .chatbot-model-selector {
    display: block;
}

.model-select-button {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: white;
    font-size: 14px;
    color: #374151;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.model-select-button:hover {
    border-color: var(--accent-purple);
    background: #f8f9fa;
}

.model-select-button:focus {
    outline: none;
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.model-select-button .model-info {
    text-align: left;
}

.model-select-button .model-name {
    font-weight: 500;
    margin-bottom: 2px;
}

.model-select-button .model-description {
    font-size: 12px;
    color: #6b7280;
}

.model-select-button i {
    color: var(--accent-purple);
}

/* Attachment Area for Full Mode */
.chatbot-attachment-area {
    display: none;
    padding: 8px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #f8f9fa;
}

.floating-chatbot-widget.size-full .chatbot-attachment-area {
    display: block;
}

.attachment-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.attachment-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 12px;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s ease;
}

.attachment-btn:hover {
    background: #f3f4f6;
    border-color: var(--accent-purple);
}

.attachment-btn i {
    font-size: 14px;
}

.chatbot-attachments {
    margin-top: 8px;
    display: none;
}

.chatbot-attachments.has-files {
    display: block;
}

.chatbot-attachment-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    margin-bottom: 4px;
    font-size: 12px;
}

.attachment-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.attachment-icon {
    color: var(--accent-purple);
}

.attachment-details {
    display: flex;
    flex-direction: column;
}

.attachment-name {
    font-weight: 500;
    color: #374151;
}

.attachment-size {
    color: #6b7280;
    font-size: 11px;
}

.remove-attachment-btn {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.remove-attachment-btn:hover {
    background: #fef2f2;
}

/* Enhanced Input Area for Full Mode */
.floating-chatbot-widget.size-full .chatbot-input-container {
    flex-direction: row;
    gap: 12px;
    align-items: flex-end;
}

.floating-chatbot-widget.size-full .chatbot-input {
    min-height: 60px;
    max-height: 120px;
    resize: vertical;
    flex: 1;
}

.floating-chatbot-widget.size-full .chatbot-send-btn {
    flex-shrink: 0;
}

.input-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.input-options {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Hide power mode toggle in full mode */
.floating-chatbot-widget.size-full .power-mode-toggle {
    display: none;
}

.power-mode-toggle {
    display: flex;
    background: #f3f4f6;
    border-radius: 6px;
    padding: 2px;
}

.power-mode-toggle button {
    padding: 4px 8px;
    border: none;
    background: none;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.power-mode-toggle button.active {
    background: var(--accent-purple);
    color: white;
}

.floating-chatbot-widget.visible {
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;
}

/* Widget size modes */
.floating-chatbot-widget.size-compact {
    width: 380px;
    height: 550px;
}

.floating-chatbot-widget.size-standard {
    width: 450px;
    height: 680px;
}

.floating-chatbot-widget.size-large {
    width: 520px;
    height: 780px;
}

.floating-chatbot-widget.size-full {
    width: 900px;
    height: 90vh;
    max-height: 900px;
    bottom: 5vh;
    right: 2vw;
}

/* Responsive full mode */
@media (max-width: 1024px) {
    .floating-chatbot-widget.size-full {
        width: 95vw;
        height: 90vh;
        right: 2.5vw;
        left: 2.5vw;
    }
}

/* ===== WIDGET HEADER ===== */
.chatbot-header {
    background: var(--chatbot-primary);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--chatbot-border-radius) var(--chatbot-border-radius) 0 0;
}

.chatbot-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.chatbot-avatar {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.chatbot-title {
    font-weight: 600;
    font-size: 15px;
    margin: 0;
}

.chatbot-status {
    font-size: 12px;
    opacity: 0.9;
    margin: 0;
}

.chatbot-header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chatbot-power-mode {
    display: flex;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    overflow: hidden;
    font-size: 11px;
    margin-right: 8px;
}

.power-mode-btn {
    background: none;
    border: none;
    color: white;
    padding: 4px 8px;
    cursor: pointer;
    transition: var(--chatbot-transition);
    font-size: 11px;
    font-weight: 500;
}

.power-mode-btn.active {
    background: rgba(255, 255, 255, 0.3);
}

.power-mode-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chatbot-control-btn {
    background: none;
    border: none;
    color: white;
    padding: 6px;
    cursor: pointer;
    border-radius: 4px;
    transition: var(--chatbot-transition);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.chatbot-control-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ===== CHAT MESSAGES ===== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

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

.chatbot-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.chat-message {
    display: flex;
    gap: 8px;
    animation: slideInMessage 0.3s ease-out;
}

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

.chat-message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.message-avatar.user {
    background: #e5e7eb;
    color: #374151;
}

.message-avatar.ai {
    background: var(--chatbot-primary);
    color: white;
}

.message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.4;
    font-size: 14px;
    word-wrap: break-word;
}

.message-content.user {
    background: var(--chatbot-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-content.ai {
    background: white;
    color: #374151;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}

.message-content.ai h1,
.message-content.ai h2,
.message-content.ai h3,
.message-content.ai h4,
.message-content.ai h5,
.message-content.ai h6 {
    margin: 8px 0 4px 0;
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
}

.message-content.ai p {
    margin: 4px 0;
    font-size: 14px;
    line-height: 1.4;
}

.message-content.ai ul,
.message-content.ai ol {
    margin: 4px 0;
    padding-left: 16px;
}

.message-content.ai li {
    font-size: 14px;
    line-height: 1.4;
    margin: 2px 0;
}

.message-content.ai strong {
    font-weight: 600;
    color: #1f2937;
}

.message-content.ai code {
    background: #f3f4f6;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 12px;
}

.message-timestamp {
    font-size: 11px;
    color: #6b7280;
    text-align: center;
    margin: 4px 0;
    opacity: 0.7;
}

/* ===== TYPING INDICATOR ===== */
.typing-indicator {
    display: flex;
    gap: 8px;
    padding: 16px;
}

.typing-indicator .message-avatar {
    background: var(--chatbot-primary);
    color: white;
}

.typing-dots {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ===== INPUT AREA ===== */
.chatbot-input-area {
    padding: 16px 16px 26px 16px;
    background: white;
    border-top: 1px solid #e5e7eb;
    border-radius: 0 0 var(--chatbot-border-radius) var(--chatbot-border-radius);
    flex-shrink: 0;
}

.chatbot-input-container {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chatbot-input {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    min-height: 20px;
    max-height: 80px;
    font-family: inherit;
    transition: var(--chatbot-transition);
}

.chatbot-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chatbot-send-btn {
    background: var(--chatbot-primary);
    border: none;
    border-radius: 12px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--chatbot-transition);
    color: white;
    font-size: 16px;
}

.chatbot-send-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== EMPTY STATE ===== */
.chatbot-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #6b7280;
}

.chatbot-empty-state i {
    font-size: 48px;
    color: #d1d5db;
    margin-bottom: 16px;
}

.chatbot-empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: #374151;
}

.chatbot-empty-state p {
    font-size: 14px;
    margin: 0;
    line-height: 1.4;
}

/* ===== SIDEBAR COMPATIBILITY ===== */
/* Ensure chatbot appears above any sidebars */
.floating-chatbot-button,
.floating-chatbot-widget {
    position: fixed !important;
    z-index: 10001 !important;
}

/* Make sure button is always on the right side */
.floating-chatbot-button {
    right: 24px !important;
    left: auto !important;
}

/* Account for sidebar expanded state on desktop */
@media (min-width: 769px) {
    body.history-sidebar-expanded .floating-chatbot-button {
        right: 24px !important; /* Keep on right side regardless of sidebar */
    }
    
    body.history-sidebar-expanded .floating-chatbot-widget {
        right: 24px !important; /* Keep on right side regardless of sidebar */
    }
}

/* ===== MOBILE RESPONSIVENESS ===== */
@media (max-width: 768px) {
    .floating-chatbot-widget {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100% !important;
        height: 100% !important;
        border-radius: 0;
        z-index: 99999;
    }
    
    .floating-chatbot-widget.visible {
        transform: translateY(0) scale(1);
    }
    
    .chatbot-header {
        border-radius: 0;
        padding: 20px 16px 16px 16px;
        padding-top: env(safe-area-inset-top, 20px);
    }
    
    .chatbot-messages {
        flex: 1;
        padding: 16px;
        min-height: 0;
    }
    
    .chatbot-input-area {
        border-radius: 0;
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
    
    .floating-chatbot-button {
        bottom: calc(24px + env(safe-area-inset-bottom, 0px));
        right: 16px !important;
        left: auto !important;
    }
}

@media (max-width: 480px) {
    .chatbot-power-mode {
        display: none;
    }
    
    .chatbot-title {
        font-size: 14px;
    }
    
    .chatbot-status {
        font-size: 11px;
    }
    
    .message-content {
        max-width: 85%;
        font-size: 14px;
        padding: 10px 14px;
    }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
    .floating-chatbot-button,
    .floating-chatbot-widget,
    .chat-message,
    .chatbot-control-btn,
    .chatbot-send-btn {
        transition: none;
        animation: none;
    }
    
    .floating-chatbot-button.has-new-message {
        animation: none;
    }
    
    .typing-dot {
        animation: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .floating-chatbot-widget {
        border: 2px solid #000;
    }
    
    .message-content.ai {
        border: 2px solid #000;
    }
    
    .chatbot-input {
        border: 2px solid #000;
    }
}