/**
 * @file
 * Styles for Dify Widget JS floating chatbot.
 */

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

/* Skip link for keyboard accessibility (RGAA/WCAG) */
.dify-skip-link {
    position: absolute;
    z-index: 10000;
    top: -100px;
    left: 50%;
    padding: 12px 24px;
    transition: top 0.2s ease;
    transform: translateX(-50%);
    text-decoration: none;
    color: #fff;
    border-radius: 0 0 8px 8px;
    background: var(--dify-primary-color, #2563eb);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    font-weight: 600;
}

.dify-skip-link:focus {
    top: 0;
    outline: 3px solid var(--dify-primary-light, #3b82f6);
    outline-offset: 2px;
}

/* Focus visible styles for accessibility */
.dify-open-button:focus-visible,
.dify-close-button:focus-visible {
    outline: 3px solid var(--dify-primary-light);
    outline-offset: 2px;
    box-shadow: 0 0 0 6px rgb(37, 99, 235, 0.3);
}

.dify-chatbot button:focus-visible {
    outline: 2px solid var(--dify-primary-light);
    outline-offset: 2px;
}

.dify-chatbot .message-input,
.dify-chatbot .message-input:focus {
    border: none;
    outline: none;
    box-shadow: none;
}

.dify-chatbot .suggestion-button:focus-visible {
    border-color: var(--dify-primary-color);
    outline: 2px solid var(--dify-primary-light);
    outline-offset: 2px;
}

/* Open Button - Completely separate */
.dify-open-button {
    position: fixed;
    z-index: 9999;
    right: 20px;
    bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    padding: 0;
    cursor: pointer;
    border: none;
    border-radius: 50%;
    background: var(--dify-primary-color);
    box-shadow: 0 4px 16px rgb(0, 0, 0, 0.3);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.dify-open-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgb(0, 0, 0, 0.4);
}

/* Close Button - Completely separate */
.dify-close-button {
    position: fixed;
    z-index: 9999;
    right: 20px;
    bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    padding: 0;
    cursor: pointer;
    border: none;
    border-radius: 50%;
    background: var(--dify-primary-color);
    box-shadow: 0 4px 16px rgb(0, 0, 0, 0.3);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.dify-close-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgb(0, 0, 0, 0.4);
}

.bubble-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    color: white;
    border-radius: 50%;
    background: var(--dify-notification-color);
    font-size: 12px;
    font-weight: bold;
}

/* Chatbot Container - Fade + Scale animation */
.dify-chatbot {
    position: fixed;
    z-index: 9998;
    right: 20px;
    bottom: 90px;
    display: flex;
    overflow: hidden;
    flex-direction: column;
    width: 550px;
    height: 550px;
    transition: transform 250ms ease-out,
    opacity 250ms ease-out;
    transform: scale(0.8);
    transform-origin: bottom right;
    opacity: 0;
    border-radius: 12px;
    background: var(--dify-background-main);
    box-shadow: 0 8px 32px rgb(0, 0, 0, 0.4);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.4;
}

/* Resize handle in top-left corner */
.dify-chatbot .resize-handle {
    position: absolute;
    z-index: 10;
    top: 0;
    left: 0;
    width: 15px;
    height: 15px;
    cursor: nw-resize;
    transition: opacity 200ms ease;
    opacity: 0;
    border-radius: 0 0 8px 0;
    background: rgb(255, 255, 255, 0.1);
}

.dify-chatbot:hover .resize-handle {
    opacity: 1;
}

.dify-chatbot .resize-handle:hover {
    background: rgb(255, 255, 255, 0.2);
}

/* Animation states */
.dify-chatbot.opening {
    transform: scale(1);
    opacity: 1;
}

.dify-chatbot.closing {
    transition: transform 200ms ease-in,
    opacity 200ms ease-in;
    transform: scale(0.9);
    opacity: 0;
}

/* No animations needed - buttons are separate */

/* Header */
.dify-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    user-select: none;
    color: var(--dify-text-primary);
    background: var(--dify-primary-color);
}

.dify-widget-title {
    margin: 0;
    color: var(--dify-text-primary);
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
}

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

.new-conversation-button,
.minimize-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    color: var(--dify-text-primary);
    border: none;
    border-radius: 4px;
    background: none;
    font-size: 16px;
}

.new-conversation-button:hover,
.minimize-button:hover {
    background-color: rgb(255, 255, 255, 0.1);
}

.reset-icon {
    font-size: 14px;
    width: 17px;
}

/* Messages Container */
.dify-widget-messages {
    overflow-x: hidden;
    overflow-y: auto;
    flex: 1;
    padding: 16px;
    background: var(--dify-background-secondary);
    scroll-behavior: smooth;
    /* Enhanced scrolling properties */
    scroll-padding-bottom: 16px;
    overscroll-behavior: contain;
}

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

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

.dify-widget-messages::-webkit-scrollbar-thumb {
    transition: background-color 0.2s ease;
    border-radius: 3px;
    background: rgb(255, 255, 255, 0.2);
}

.dify-widget-messages::-webkit-scrollbar-thumb:hover {
    background: rgb(255, 255, 255, 0.3);
}

/* Firefox scrollbar styling */
.dify-widget-messages {
    scrollbar-width: thin;
    scrollbar-color: rgb(255, 255, 255, 0.2) transparent;
}

/* Messages */
.message {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    margin-bottom: 16px;
    gap: 8px;
}

.bot-message {
    margin-bottom: 24px;
}

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

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

/* Avatar */
.message-avatar {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 16px;
    line-height: 1;
}

.bot-avatar {
    color: var(--dify-text-primary);
    background: var(--dify-background-tertiary);
}

.user-avatar {
    color: var(--dify-text-primary);
    background: var(--dify-user-message-bg);
}

/* Message body wrapper */
.message-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 80%;
}

.message-content {
    position: relative;
    padding: 10px 14px;
    border-radius: 18px;
    overflow-wrap: break-word;
}

.user-message .message-content {
    color: var(--dify-text-primary);
    background: var(--dify-user-message-bg);
}

.bot-message .message-content {
    color: var(--dify-text-primary);
    border: 1px solid var(--dify-border-color);
    background: var(--dify-bot-message-bg);
}

/* GitHub Markdown styling for bot messages */
.bot-message .message-content.markdown-body {
    padding: 16px;
    color: var(--dify-text-primary);
    background: var(--dify-bot-message-bg);
    font-size: 14px;
    line-height: 1.5;
}

/* Override some GitHub markdown styles for better integration */
.bot-message .message-content.markdown-body h1,
.bot-message .message-content.markdown-body h2,
.bot-message .message-content.markdown-body h3,
.bot-message .message-content.markdown-body h4,
.bot-message .message-content.markdown-body h5,
.bot-message .message-content.markdown-body h6 {
    margin-top: 0;
    margin-bottom: 8px;
}

.bot-message .message-content.markdown-body p {
    margin-top: 0;
    margin-bottom: 8px;
}

.bot-message .message-content.markdown-body p:last-child {
    margin-bottom: 0;
}

/* Fix lists display */
.bot-message .message-content.markdown-body ul,
.bot-message .message-content.markdown-body ol {
    margin-top: 0;
    margin-bottom: 8px;
    padding-left: 2em !important;
    list-style: inherit !important;
}

.bot-message .message-content.markdown-body ul {
    list-style-type: disc !important;
}

.bot-message .message-content.markdown-body ol {
    list-style-type: decimal !important;
}

.bot-message .message-content.markdown-body li {
    display: list-item !important;
    margin: 4px 0;
}

.bot-message .message-content.markdown-body pre {
    margin-top: 0;
    margin-bottom: 8px;
}

.bot-message .message-content.markdown-body blockquote {
    margin: 0 0 8px 0;
    padding: 0 16px;
    border-left: 4px solid var(--dify-primary-color);
}

/* Style for links */
.bot-message .message-content.markdown-body a {
    transition: all 0.2s ease;
    text-decoration: none;
    color: var(--dify-primary-color);
    border-bottom: 1px solid transparent;
}

.bot-message .message-content.markdown-body a:hover {
    text-decoration: none;
    color: var(--dify-primary-hover);
    border-bottom-color: var(--dify-primary-color);
}

.bot-message.error .message-content {
    color: var(--dify-error-text);
    background: var(--dify-error-bg);
}

/* Note: Streaming indicator is handled by .typing-indicator in JavaScript */

/* Typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    animation: typing 1.4s infinite ease-in-out;
    border-radius: 50%;
    background: var(--dify-text-muted);
}

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

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

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

/* Input Area */
.dify-widget-input {
    padding: 16px;
    border-top: 1px solid var(--dify-border-color);
    background: var(--dify-background-main);
}

.input-group {
    display: flex;
    align-items: flex-end;
    padding: 8px 12px;
    transition: border-color 0.2s ease;
    border: 1px solid var(--dify-border-color);
    border-radius: 20px;
    background: var(--dify-background-input);
    gap: 8px;
}

.input-group:focus-within {
    border-color: var(--dify-primary-color);
}

.message-input {
    overflow: hidden;
    flex: 1;
    min-height: 20px;
    max-height: 120px;
    padding: 4px 0;
    resize: none;
    transition: none;
    color: var(--dify-text-primary);
    border: none;
    outline: none;
    background: transparent;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
}

.message-input::placeholder {
    color: var(--dify-text-placeholder);
}

.send-button {
    position: relative;
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--dify-text-primary);
    border: none;
    border-radius: 50%;
    background: var(--dify-primary-color);
}

.send-button:hover:not(:disabled) {
    transform: scale(1.05);
    background: var(--dify-primary-hover);
}

.send-button:disabled {
    cursor: not-allowed;
    transform: none;
    color: var(--dify-text-muted);
    background: var(--dify-border-color);
}

.send-button .send-icon,
.send-button .loading-spinner {
    position: absolute;
    width: 16px;
    height: 16px;
}

.send-button .loading-spinner {
    display: none;
    animation: spin 1s linear infinite;
}

.send-button.is-loading .send-icon {
    display: none;
}

.send-button.is-loading .loading-spinner {
    display: block;
}

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

/* Footer */
.dify-widget-footer {
    padding: 8px 16px;
    text-align: center;
    border-top: 1px solid #e1e5e9;
    background: #f8f9fa;
}

/* Welcome message */
.dify-welcome-message {
    margin-bottom: 16px;
}

/* Responsive design */
@media (max-width: 768px) {
    .dify-chatbot {
        right: 0;
        bottom: 0;
        left: 0;
        width: 100% !important;
        height: 100% !important;
        max-height: 100vh;
        border-radius: 0;
    }

    .dify-chatbot.minimized {
        bottom: 0;
        width: 100% !important;
        height: 60px !important;
    }

    .message-body {
        max-width: 90%;
    }

    .dify-widget-header {
        padding: 16px;
    }

    .dify-widget-input {
        max-width: 87%;
        padding: 16px;
    }

    .dify-close-button,
    .dify-open-button {
        bottom: 17px;
    }
}

@media (max-width: 480px) {
    .dify-widget-input {
        max-width: 80%;
    }
}

/* Conversation suggestions */
.suggestions-message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 16px;
}

.suggestions-content {
    display: flex;
    flex-wrap: wrap;
    max-width: 100%;
    margin-top: 8px;
    gap: 6px;
}

.suggestion-button {
    overflow: hidden;
    flex-shrink: 0;
    padding: 6px 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--dify-text-secondary);
    border: 1px solid var(--dify-border-color);
    border-radius: 16px;
    background: var(--dify-background-input);
    font-size: 12px;
    line-height: 1.3;
}

.suggestion-button:hover {
    transform: translateY(-1px);
    border-color: var(--dify-background-secondary);
    background: var(--dify-border-color);
    box-shadow: 0 2px 8px rgb(88, 166, 255, 0.15);
}

.suggestion-button:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgb(88, 166, 255, 0.1);
}
