/**
 * CHAT WIDGET STYLES - Bottom Bar Design
 * 
 * A bottom bar chat widget that allows users to ask AI questions about content.
 * Include this CSS file and chat_widget_vue.js to use the widget.
 */

/* =======================================================================
   CHAT WIDGET CONTAINER - Floating bottom bar (centered, not full width)
   ======================================================================= */

.chat-widget {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 40px);
    max-width: 600px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* =======================================================================
   BOTTOM BAR (collapsed state)
   ======================================================================= */

.chat-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 14px 24px;
    background: linear-gradient(135deg, #4A90E2 0%, #3d7bc7 100%);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(74, 144, 226, 0.3);
    border-radius: 50px;
}

.chat-bar:hover {
    background: linear-gradient(135deg, #5CA1F0 0%, #4A90E2 100%);
    box-shadow: 0 6px 25px rgba(74, 144, 226, 0.4);
    transform: translateY(-2px);
}

.chat-bar-icon {
    font-size: 1.2rem;
}

.chat-bar-text {
    font-size: 0.9rem;
    font-weight: 500;
}

.chat-bar-cta {
    background: rgba(255, 255, 255, 0.25);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.2s;
}

.chat-bar:hover .chat-bar-cta {
    background: rgba(255, 255, 255, 0.35);
}

/* Hide bar when chat is open */
.chat-widget.open .chat-bar {
    display: none;
}

/* =======================================================================
   CHAT PANEL (expanded state)
   ======================================================================= */

.chat-panel {
    display: none;
    flex-direction: column;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
    height: 50vh;  /* Default for larger screens */
    overflow: hidden;
}

.chat-widget.open .chat-panel {
    display: flex;
    animation: chatSlideUp 0.3s ease;
}

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

/* =======================================================================
   FULLSCREEN MODE
   ======================================================================= */

/* Container fullscreen mode */
#chat-widget-container.fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 99999 !important;
}

#chat-widget-container.fullscreen .chat-widget {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: none !important;
    height: 100% !important;
    transform: none !important;
    background: white !important;
}

#chat-widget-container.fullscreen .chat-panel {
    display: flex !important;
    max-height: none !important;
    height: 100% !important;
    width: 100% !important;
    border: none !important;
    border-radius: 0 !important;
}

#chat-widget-container.fullscreen .chat-header {
    border-radius: 0 !important;
}

#chat-widget-container.fullscreen .chat-messages {
    flex: 1;
    max-height: none !important;
    min-height: 0;
    overflow-y: auto;
}

#chat-widget-container.fullscreen .chat-input-container {
    flex-shrink: 0;
    border-radius: 0 !important;
}

.chat-widget.fullscreen .chat-message-bubble {
    max-width: 70%;
}

/* Larger text in fullscreen for readability */
.chat-widget.fullscreen .chat-header-title {
    font-size: 1.1rem;
}

.chat-widget.fullscreen .chat-message-bubble {
    font-size: 1rem;
    padding: 14px 18px;
}

.chat-widget.fullscreen .chat-input {
    font-size: 1rem;
    padding: 14px 16px;
}

.chat-widget.fullscreen .chat-welcome {
    padding: 40px;
}

.chat-widget.fullscreen .chat-welcome p:first-child {
    font-size: 1.2rem;
}

/* Fullscreen button icon rotation when active */
.chat-widget.fullscreen .chat-fullscreen-btn {
    background: rgba(255, 255, 255, 0.35);
}

/* =======================================================================
   CHAT HEADER
   ======================================================================= */

.chat-header {
    padding: 14px 20px;
    background: linear-gradient(135deg, #4A90E2 0%, #3d7bc7 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 16px 16px 0 0;
}

.chat-header-title {
    font-weight: 600;
    font-size: 0.95rem;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-fullscreen-btn,
.chat-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s;
}

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

/* =======================================================================
   CHAT MESSAGES AREA
   ======================================================================= */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    min-height: 0;  /* Allow flex to shrink */
    background: #f8fafc;
}

/* Welcome message */
.chat-welcome {
    text-align: center;
    color: #64748b;
    font-size: 0.9rem;
    padding: 10px;
}

.chat-welcome p {
    margin-bottom: 8px;
}

.chat-welcome-examples {
    font-weight: 600;
    color: #475569;
    margin-top: 12px !important;
    font-size: 0.85rem;
}

.chat-welcome ul {
    list-style: none;
    padding: 0;
    margin: 8px 0 0 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.chat-welcome li {
    background: #e2e8f0;
    padding: 8px 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
}

.chat-welcome li:hover {
    background: #4A90E2;
    color: white;
}

/* =======================================================================
   MESSAGE BUBBLES
   ======================================================================= */

.chat-message {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}

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

.chat-message.assistant {
    align-items: flex-start;
}

.chat-message-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-message.user .chat-message-bubble {
    background: linear-gradient(135deg, #4A90E2 0%, #3d7bc7 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant .chat-message-bubble {
    background: #ffffff;
    color: #374151;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}

/* Message action buttons container */
.chat-message-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
}

/* Copy button for assistant messages */
.chat-copy-btn,
.chat-action-btn {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 0.7rem;
    color: #6b7280;
    border-radius: 12px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.chat-copy-btn:hover,
.chat-action-btn:hover {
    background: #e5e7eb;
    color: #374151;
}

.chat-copy-btn:disabled,
.chat-action-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Copied state */
.chat-copy-btn.copied {
    background: #dcfce7;
    border-color: #86efac;
    color: #166534;
}

/* Action button specific styles - blue tint */
.chat-action-btn {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1d4ed8;
}

.chat-action-btn:hover {
    background: #dbeafe;
    color: #1e40af;
}

/* Action success state */
.chat-action-btn.action-success {
    background: #dcfce7;
    border-color: #86efac;
    color: #166534;
}

/* Markdown content within messages */
.chat-message-bubble p {
    margin: 0 0 0.5em 0;
}

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

.chat-message-bubble ul,
.chat-message-bubble ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.chat-message-bubble li {
    margin: 0.25em 0;
}

.chat-message-bubble strong {
    font-weight: 600;
}

.chat-message-bubble code {
    background: rgba(0, 0, 0, 0.08);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.chat-message.user .chat-message-bubble code {
    background: rgba(255, 255, 255, 0.2);
}

.chat-message-bubble pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.5em 0;
    font-size: 0.85em;
}

.chat-message-bubble pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.chat-message-bubble blockquote {
    border-left: 3px solid #4A90E2;
    margin: 0.5em 0;
    padding-left: 1em;
    color: #6b7280;
}

.chat-message-bubble h1,
.chat-message-bubble h2,
.chat-message-bubble h3,
.chat-message-bubble h4 {
    margin: 0.5em 0 0.25em 0;
    font-weight: 600;
    line-height: 1.3;
}

.chat-message-bubble h1 { font-size: 1.2em; }
.chat-message-bubble h2 { font-size: 1.1em; }
.chat-message-bubble h3 { font-size: 1em; }
.chat-message-bubble h4 { font-size: 0.95em; }

.chat-message-bubble hr {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 0.75em 0;
}

.chat-message-bubble a {
    color: #4A90E2;
    text-decoration: underline;
}

.chat-message.user .chat-message-bubble a {
    color: #c7d2fe;
}

/* =======================================================================
   TYPING INDICATOR
   ======================================================================= */

.chat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.chat-typing-dot {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.chat-typing-dot:nth-child(1) { animation-delay: 0s; }
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* =======================================================================
   CHAT INPUT AREA
   ======================================================================= */

.chat-input-container {
    padding: 12px 20px;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 10px;
    flex-shrink: 0;  /* Keep input at bottom */
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 0.9rem;
    resize: none;
    max-height: 80px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.chat-input:focus {
    border-color: #4A90E2;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.15);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: #4A90E2;
    color: white;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-send-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
}

.chat-send-btn:not(:disabled):hover {
    background: #3d7bc7;
    transform: scale(1.05);
}

/* =======================================================================
   ERROR MESSAGE
   ======================================================================= */

.chat-error {
    color: #dc2626;
    background: #fef2f2;
    border: 1px solid #fecaca;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 12px;
}

/* =======================================================================
   MOBILE RESPONSIVE STYLES
   ======================================================================= */

@media (max-width: 768px) {
    .chat-bar {
        padding: 10px 16px;
    }
    
    .chat-bar-text {
        font-size: 0.9rem;
    }
    
    .chat-panel {
        height: 65vh;  /* Taller on tablets */
    }
    
    .chat-messages {
        min-height: 0;
    }
    
    .chat-welcome ul {
        flex-direction: column;
    }
    
    .chat-welcome li {
        text-align: center;
    }
}

@media (max-width: 480px) {
    .chat-widget {
        width: calc(100% - 20px);
        bottom: 10px;
    }
    
    .chat-bar-cta {
        display: none;
    }
    
    .chat-panel {
        height: 75vh;  /* Even taller on phones */
        border-radius: 12px;
    }
    
    .chat-messages {
        min-height: 0;
        padding: 12px 16px;
    }
    
    .chat-input-container {
        padding: 10px 16px;
    }
    
    .chat-message-bubble {
        max-width: 90%;
    }
}

/* =======================================================================
   CONFIRMATION MODAL
   ======================================================================= */

.chat-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.chat-modal {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    animation: slideUp 0.2s ease;
}

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

.chat-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
}

.chat-modal-title {
    font-weight: 600;
    font-size: 1rem;
    color: #1f2937;
}

.chat-modal-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: color 0.2s;
}

.chat-modal-close:hover {
    color: #4b5563;
}

.chat-modal-body {
    padding: 20px;
}

.chat-modal-body p {
    margin: 0 0 8px 0;
    color: #374151;
    font-size: 0.95rem;
}

.chat-modal-body p:last-child {
    margin-bottom: 0;
}

.chat-modal-note {
    color: #6b7280 !important;
    font-size: 0.85rem !important;
}

.chat-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    border-radius: 0 0 12px 12px;
}

.chat-modal-btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-modal-btn-cancel {
    background: white;
    border: 1px solid #d1d5db;
    color: #374151;
}

.chat-modal-btn-cancel:hover {
    background: #f3f4f6;
}

.chat-modal-btn-confirm {
    background: #4A90E2;
    border: none;
    color: white;
}

.chat-modal-btn-confirm:hover {
    background: #3b7dd8;
}

.chat-modal-btn-confirm:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

/* =======================================================================
   TOAST NOTIFICATION
   ======================================================================= */

.chat-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1f2937;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 10002;
    font-size: 0.9rem;
}

.chat-toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.chat-toast.success {
    background: #059669;
}

.chat-toast.error {
    background: #dc2626;
}

.chat-toast-icon {
    font-size: 1.1rem;
}

.chat-toast-message {
    max-width: 300px;
}

/* Mobile: position toast higher when chat is open */
@media (max-width: 768px) {
    .chat-toast {
        bottom: 80px;
        width: calc(100% - 40px);
        max-width: 400px;
    }
}
