/* Dify-Inspired Chat UI - Keeping Nanglucso Theme Colors */

:root {
    --chat-primary: #667eea;
    --chat-primary-dark: #5568d3;
    --chat-secondary: #764ba2;
    --chat-bg-light: #f7f8fa;
    --chat-bg-white: #ffffff;
    --chat-border: #e5e7eb;
    --chat-text-primary: #1f2937;
    --chat-text-secondary: #6b7280;
    --chat-text-light: #9ca3af;
    --chat-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --chat-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Main Chat Container - Dify Style */
.dify-chat-wrapper {
    height: 100vh;
    max-height: 83vh;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg-light);
}

.dify-chat-header {
    background: var(--chat-bg-white);
    border-bottom: 1px solid var(--chat-border);
    padding: 0.5rem 0.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--chat-shadow);
    z-index: 10;
}

.dify-chat-header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.dify-agent-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--chat-primary);
}

.dify-agent-info h5 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--chat-text-primary);
}

.dify-agent-info p {
    margin: 0;
    font-size: 0.75rem;
    color: var(--chat-text-secondary);
}

.dify-chat-actions {
    display: flex;
    gap: 0.5rem;
}

.dify-action-btn {
    background: transparent;
    border: none;
    color: var(--chat-text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.2s;
}

.dify-action-btn:hover {
    background: var(--chat-bg-light);
    color: var(--chat-primary);
}

/* Messages Container */
.dify-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.dify-messages-wrapper {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

/* Welcome Screen */
.dify-welcome {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--chat-text-secondary);
}

.dify-welcome-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-secondary));
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 2.5rem;
}

.dify-welcome h3 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--chat-text-primary);
    margin-bottom: 0.5rem;
}

.dify-welcome p {
    font-size: 0.95rem;
    color: var(--chat-text-secondary);
    max-width: 500px;
    margin: 0 auto;
}

.dify-suggested-prompts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 0.75rem;
    margin-top: 2rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.dify-prompt-card {
    background: var(--chat-bg-white);
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.dify-prompt-card:hover {
    border-color: var(--chat-primary);
    box-shadow: var(--chat-shadow);
    transform: translateY(-2px);
}

.dify-prompt-card i {
    color: var(--chat-primary);
    margin-bottom: 0.5rem;
    font-size: 1.25rem;
}

.dify-prompt-card p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--chat-text-primary);
}

/* Message Bubbles - Dify Style */
.dify-message {
    display: flex;
    gap: 0.75rem;
    animation: messageSlideIn 0.3s ease-out;
}

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

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

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

/* Hide user avatar */
.dify-message.user .dify-message-avatar {
    display: none;
}

.dify-message.agent .dify-message-avatar {
    border: 2px solid var(--chat-border);
}

.dify-message.agent .dify-message-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.dify-message-content {
    display: inline-block;
    max-width: min(600px, 75%); /* Dynamic width with max constraint */
}

.dify-message.user .dify-message-content {
    max-width: min(600px, 80%); /* User messages can be slightly wider */
}

.dify-message-bubble {
    padding: 0.875rem 1.125rem;
    border-radius: 12px;
    word-wrap: break-word;
    line-height: 1.6;
    display: inline-block; /* Makes bubble fit content width */
    width: fit-content;
    max-width: 100%;
    opacity: 0;
    animation: fadeInMessage 0.3s ease-out forwards;
}

@keyframes fadeInMessage {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.dify-message.user .dify-message-bubble {
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-secondary));
    color: white;
    border-radius: 18px 18px 4px 18px; /* Rounded corners except bottom-right */
}

.dify-message.agent .dify-message-bubble {
    background: var(--chat-bg-white);
    border: 1px solid var(--chat-border);
    color: var(--chat-text-primary);
    border-radius: 18px 18px 18px 4px; /* Rounded corners except bottom-left */
}

/* Streaming state - subtle glow animation */
.dify-message.agent .dify-message-bubble.streaming {
    animation: fadeInMessage 0.3s ease-out forwards, streamingGlow 1.5s ease-in-out infinite;
}

@keyframes streamingGlow {
    0%, 100% {
        box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
    }
    50% {
        box-shadow: 0 2px 16px rgba(102, 126, 234, 0.2), 0 0 20px rgba(118, 75, 162, 0.1);
    }
}

.dify-message-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.375rem;
    font-size: 0.75rem;
    color: var(--chat-text-light);
}

.dify-message.user .dify-message-meta {
    justify-content: flex-end;
}

/* Markdown Content Styling */
.dify-message-bubble h1,
.dify-message-bubble h2,
.dify-message-bubble h3,
.dify-message-bubble h4 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.dify-message-bubble h1 { font-size: 1.5rem; }
.dify-message-bubble h2 { font-size: 1.25rem; }
.dify-message-bubble h3 { font-size: 1.1rem; }
.dify-message-bubble h4 { font-size: 1rem; }

.dify-message-bubble p {
    margin-bottom: 0.75rem;
}

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

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

.dify-message-bubble li {
    margin-bottom: 0.25rem;
}

.dify-message-bubble code {
    background: rgba(0, 0, 0, 0.05);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-size: 0.875em;
    font-family: 'Consolas', 'Monaco', monospace;
}

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

.dify-message-bubble pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.75rem 0;
}

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

.dify-message-bubble blockquote {
    border-left: 3px solid var(--chat-primary);
    padding-left: 1rem;
    margin: 0.75rem 0;
    color: var(--chat-text-secondary);
    font-style: italic;
}

/* Typing Indicator */
.dify-typing {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.dify-typing .dify-message-avatar {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border: 2px solid var(--chat-border);
    overflow: hidden;
}

.dify-typing .dify-message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.dify-typing-dots {
    background: var(--chat-bg-white);
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    display: flex;
    gap: 0.375rem;
    align-items: center;
}

.dify-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--chat-text-light);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.dify-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.dify-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Area - Dify Style */
.dify-input-wrapper {
    background: var(--chat-bg-white);
    border-top: 1px solid var(--chat-border);
    padding: 0.5rem 0.5rem;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.dify-input-container {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
}

.dify-input-box {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    background: #ffffff;
    border: 2px solid var(--chat-border);
    border-radius: 16px;
    padding: 0.75rem 1rem;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.dify-input-box:focus-within {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1), 0 2px 8px rgba(0, 0, 0, 0.1);
    background: #ffffff;
}

.dify-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 0.9375rem;
    line-height: 1.5;
    max-height: 120px;
    overflow-y: auto;
    padding: 0.25rem 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    color: #000000;
    background: transparent;
}

.dify-input::placeholder {
    color: #9ca3af;
    opacity: 0.8;
}

.dify-input-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.dify-attach-btn,
.dify-send-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.2s;
}

.dify-attach-btn {
    color: var(--chat-text-secondary);
}

.dify-attach-btn:hover {
    background: var(--chat-bg-light);
    color: var(--chat-primary);
}

.dify-send-btn {
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-secondary));
    color: white;
    width: 36px;
    height: 36px;
}

.dify-send-btn:hover {
    transform: scale(1.05);
    box-shadow: var(--chat-shadow-lg);
}

.dify-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.dify-input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--chat-text-light);
    padding: 0 0.5rem;
}

/* Scrollbar Styling */
.dify-messages-container::-webkit-scrollbar {
    width: 6px;
}

.dify-messages-container::-webkit-scrollbar-track {
    background: transparent;
}

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

.dify-messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--chat-text-light);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .dify-chat-header {
        padding: 0.75rem 1rem;
    }

    .dify-agent-avatar {
        width: 32px;
        height: 32px;
    }

    .dify-messages-container {
        padding: 1rem 0.75rem;
    }

    .dify-message-content {
        max-width: 100%;
    }

    .dify-input-wrapper {
        padding: 0.75rem 1rem;
    }

    .dify-suggested-prompts {
        grid-template-columns: 1fr;
    }
}

/* Function Call Indicator */
.function-call-indicator {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
    border-left: 3px solid var(--chat-primary);
    border-radius: 6px;
    margin: 0.5rem 0;
    font-size: 0.875rem;
    color: var(--chat-primary);
    font-weight: 500;
    animation: pulse 1.5s ease-in-out infinite;
}

.function-call-indicator i {
    animation: spin 2s linear infinite;
}

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

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Citation Styling */
.dify-message-bubble small {
    display: block;
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--chat-border);
    color: var(--chat-text-light);
    font-size: 0.75rem;
    font-style: italic;
    opacity: 0.8;
}

.dify-message-bubble small:first-child {
    border-top: none;
    padding-top: 0;
}

/* Dark Mode Support (Optional) */
@media (prefers-color-scheme: dark) {
    :root {
        --chat-bg-light: #0f172a;
        --chat-bg-white: #1e293b;
        --chat-border: #334155;
        --chat-text-primary: #f1f5f9;
        --chat-text-secondary: #cbd5e1;
        --chat-text-light: #64748b;
    }
}

/* Fullscreen Chat Overlay */
#difyFullscreenOverlay {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    background: var(--chat-bg-light);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dify-fullscreen-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg-light);
}

.dify-fullscreen-header {
    background: var(--chat-bg-white);
    border-bottom: 1px solid var(--chat-border);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--chat-shadow);
    z-index: 10;
}

.dify-fullscreen-header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.dify-fullscreen-actions {
    display: flex;
    gap: 0.5rem;
}

.dify-fullscreen-chat {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.dify-fullscreen-chat .dify-chat-wrapper {
    height: 100%;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
}

.dify-fullscreen-chat .dify-chat-header {
    display: flex !important; /* Keep header visible in fullscreen */
    background: var(--chat-bg-white);
    border-bottom: 1px solid var(--chat-border);
    padding: 1rem 1.5rem;
    box-shadow: var(--chat-shadow);
    z-index: 10;
}

.dify-fullscreen-chat .dify-chat-header .dify-chat-actions {
    display: flex;
    gap: 0.5rem;
}

.dify-fullscreen-chat .dify-chat-header .dify-chat-actions .dify-action-btn {
    background: transparent;
    border: none;
    color: var(--chat-text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.2s;
}

.dify-fullscreen-chat .dify-chat-header .dify-chat-actions .dify-action-btn:hover {
    background: var(--chat-bg-light);
    color: var(--chat-primary);
}

.dify-fullscreen-chat .dify-messages-container {
    flex: 1;
    max-height: calc(100vh - 140px);
}

/* Mobile adjustments for fullscreen */
@media (max-width: 768px) {
    .dify-fullscreen-header {
        padding: 0.75rem 1rem;
    }
    
    .dify-fullscreen-chat .dify-messages-container {
        max-height: calc(100dvh - 120px);
    }
}

