/**
 * UE Toolkit AI 助手
 * 与公共站点共用深色工具面板视觉语言。
 */

:root {
    --dify-bg: #0b1117;
    --dify-panel: #101820;
    --dify-panel-raised: #141f29;
    --dify-line: #263746;
    --dify-line-strong: #38546c;
    --dify-text: #edf4fa;
    --dify-muted: #8fa2b3;
    --dify-blue: #3aa0f3;
    --dify-blue-soft: #1d6fae;
}

/* 悬浮客服按钮 */
.dify-chat-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 58px;
    height: 58px;
    padding: 0;
    color: #75bcf4;
    background: #101922;
    border: 1px solid #35516a;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.44), inset 0 1px 0 rgba(255, 255, 255, 0.04);
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    z-index: 9998;
}

.dify-chat-button:hover {
    transform: translateY(-2px);
    background: #14212c;
    border-color: #4a7496;
}

.dify-chat-button:focus-visible,
.dify-chat-close:focus-visible,
.dify-quick-card:focus-visible,
.dify-chat-send:focus-visible {
    outline: 2px solid #63b7f7;
    outline-offset: 3px;
}

.dify-chat-button-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 22px;
    height: 18px;
    padding: 0 5px;
    border: 2px solid #081017;
    border-radius: 6px;
    background: #3a9be8;
    color: #06101a;
    font-family: "Segoe UI", sans-serif;
    font-size: 9px;
    font-weight: 800;
    line-height: 14px;
    letter-spacing: 0.08em;
}

/* 聊天窗口 */
.dify-chat-window {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 388px;
    height: 610px;
    max-height: calc(100vh - 48px);
    color: var(--dify-text);
    background: var(--dify-bg);
    border: 1px solid var(--dify-line);
    border-radius: 14px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.58), 0 4px 14px rgba(0, 0, 0, 0.28);
    display: flex;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
}

/* 移动端适配 */
@media (max-width: 480px) {
    .dify-chat-window {
        width: auto;
        height: calc(100dvh - 24px);
        max-height: calc(100dvh - 24px);
        bottom: 12px;
        left: 12px;
        right: 12px;
    }

    .dify-chat-button {
        bottom: 16px;
        right: 16px;
    }
}

/* 聊天窗口头部 */
.dify-chat-header {
    min-height: 68px;
    box-sizing: border-box;
    background: #111a22;
    color: var(--dify-text);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    border-bottom: 1px solid var(--dify-line);
}

.dify-chat-identity {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dify-chat-identity-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border: 1px solid #31506a;
    border-radius: 9px;
    background: #142330;
    color: #6ab6f1;
}

.dify-chat-identity-copy {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 3px;
}

.dify-chat-identity-copy strong {
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.01em;
}

.dify-chat-identity-copy small {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--dify-muted);
    font-size: 11px;
    line-height: 1.2;
}

.dify-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #5ac79a;
}

.dify-chat-close {
    background: transparent;
    border: 1px solid transparent;
    color: #8da0b1;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.dify-chat-close:hover {
    color: #eef5fb;
    background: #18242e;
    border-color: var(--dify-line);
}

/* 消息区域 */
.dify-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 18px;
    background: var(--dify-bg);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 自定义滚动条 */
.dify-chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

.dify-chat-messages::-webkit-scrollbar-thumb {
    background: #334b5e;
    border-radius: 3px;
}

.dify-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #476a84;
}

/* 欢迎消息 */
.dify-welcome-message {
    padding: 4px 0 0;
}

.dify-welcome-eyebrow {
    margin: 0 0 10px;
    color: #5fa9e2;
    font-family: Consolas, "Courier New", monospace;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.13em;
}

.dify-welcome-title {
    margin: 0 0 7px;
    color: var(--dify-text);
    font-size: 16px;
    font-weight: 700;
    line-height: 1.4;
}

.dify-welcome-subtitle {
    margin: 0 0 18px;
    color: var(--dify-muted);
    font-size: 13px;
    line-height: 1.65;
}

/* 快捷问题卡片 */
.dify-quick-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
}

.dify-quick-card {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    min-height: 54px;
    padding: 10px 11px;
    background: #101921;
    border: 1px solid var(--dify-line);
    border-radius: 9px;
    color: #c8d4de;
    font-size: 12px;
    cursor: pointer;
    transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
    text-align: left;
    font-family: inherit;
}

.dify-quick-card:hover {
    background: #15232e;
    border-color: #3e607a;
    color: var(--dify-text);
}

.dify-quick-card:active {
    background: #192a37;
}

.dify-quick-icon {
    height: 30px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 30px;
    border: 1px solid #2e4b61;
    border-radius: 7px;
    background: #142532;
    color: #67b2ec;
}

.dify-quick-icon svg {
    width: 18px;
    height: 18px;
}

/* 消息气泡 */
.dify-message {
    display: flex;
    animation: fadeIn 0.3s ease;
}

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

.dify-message-content {
    max-width: 82%;
    padding: 11px 13px;
    border-radius: 10px;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* 用户消息 */
.dify-message-user {
    justify-content: flex-end;
}

.dify-message-user .dify-message-content {
    background: #1f6fae;
    color: #f5faff;
    border: 1px solid #2a7fbd;
    border-bottom-right-radius: 4px;
}

/* 助手消息 */
.dify-message-assistant {
    justify-content: flex-start;
}

.dify-message-assistant .dify-message-content {
    max-width: 90%;
    background: var(--dify-panel);
    color: #dce7ef;
    border: 1px solid var(--dify-line);
    border-left-color: #3d8bc5;
    border-bottom-left-radius: 4px;
    white-space: normal;
}

.dify-message-assistant .dify-message-content > :first-child {
    margin-top: 0;
}

.dify-message-assistant .dify-message-content > :last-child {
    margin-bottom: 0;
}

.dify-message-assistant .dify-message-content p,
.dify-message-assistant .dify-message-content ul,
.dify-message-assistant .dify-message-content ol,
.dify-message-assistant .dify-message-content blockquote,
.dify-message-assistant .dify-message-content pre,
.dify-message-assistant .dify-message-content table {
    margin: 0 0 10px;
}

.dify-message-assistant .dify-message-content h1,
.dify-message-assistant .dify-message-content h2,
.dify-message-assistant .dify-message-content h3,
.dify-message-assistant .dify-message-content h4 {
    margin: 14px 0 8px;
    color: #f4f7fa;
    font-weight: 700;
    line-height: 1.35;
}

.dify-message-assistant .dify-message-content h1,
.dify-message-assistant .dify-message-content h2 {
    font-size: 17px;
}

.dify-message-assistant .dify-message-content h3,
.dify-message-assistant .dify-message-content h4 {
    font-size: 15px;
}

.dify-message-assistant .dify-message-content ul,
.dify-message-assistant .dify-message-content ol {
    padding-left: 20px;
}

.dify-message-assistant .dify-message-content li + li {
    margin-top: 4px;
}

.dify-message-assistant .dify-message-content blockquote {
    padding: 8px 10px;
    border-left: 3px solid #3f94cf;
    border-radius: 4px;
    background: #13212b;
    color: #c8d4dc;
}

.dify-message-assistant .dify-message-content code {
    padding: 2px 5px;
    border-radius: 4px;
    background: rgba(3, 8, 13, 0.72);
    color: #9bdcf0;
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.9em;
}

.dify-message-assistant .dify-message-content pre {
    max-width: 100%;
    overflow-x: auto;
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    background: rgba(3, 8, 13, 0.82);
    white-space: pre;
}

.dify-message-assistant .dify-message-content pre code {
    padding: 0;
    background: transparent;
    color: #d9edf5;
}

.dify-message-assistant .dify-message-content a {
    color: #69b5ed;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.dify-message-assistant .dify-message-content hr {
    margin: 12px 0;
    border: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.dify-message-assistant .dify-message-content table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    font-size: 12px;
}

.dify-message-assistant .dify-message-content th,
.dify-message-assistant .dify-message-content td {
    padding: 6px 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    text-align: left;
}

.dify-message-assistant .dify-message-content th {
    background: rgba(255, 255, 255, 0.06);
}

/* 加载动画 */
.dify-loading .dify-message-content {
    position: relative;
    padding-right: 40px;
    white-space: pre-wrap;
}

.dify-loading .dify-message-content::after {
    content: '';
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid #314658;
    border-top-color: #4da6e7;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: translateY(-50%) rotate(360deg);
    }
}

/* 输入区域 */
.dify-chat-input-container {
    padding: 14px;
    background: #0e161d;
    border-top: 1px solid var(--dify-line);
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-shrink: 0;
}

.dify-chat-input {
    flex: 1;
    min-height: 42px;
    box-sizing: border-box;
    border: 1px solid #2b3d4c;
    background: #091016;
    color: var(--dify-text);
    border-radius: 9px;
    padding: 10px 12px;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
    max-height: 120px;
    overflow-y: auto;
}

.dify-chat-input:focus {
    border-color: #4b8dbd;
    box-shadow: 0 0 0 3px rgba(61, 139, 197, 0.14);
}

.dify-chat-input::placeholder {
    color: #6b7280;
}

/* 输入框滚动条 */
.dify-chat-input::-webkit-scrollbar {
    width: 4px;
}

.dify-chat-input::-webkit-scrollbar-track {
    background: transparent;
}

.dify-chat-input::-webkit-scrollbar-thumb {
    background: #334b5e;
    border-radius: 2px;
}

/* 发送按钮 */
.dify-chat-send {
    width: 42px;
    height: 42px;
    background: #2f8fd7;
    border: 1px solid #49a0df;
    border-radius: 9px;
    color: #06121c;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.dify-chat-send:hover {
    transform: translateY(-1px);
    background: #47a5e9;
    border-color: #69b6ed;
}

.dify-chat-send:active {
    transform: translateY(0);
}

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

@media (max-width: 360px) {
    .dify-quick-actions {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    .dify-chat-button,
    .dify-chat-close,
    .dify-quick-card,
    .dify-chat-send,
    .dify-message {
        animation: none;
        transition: none;
    }
}
