:root {
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --page-bg: #FFFFFF;
    --primary-text-color: #333333;
    --secondary-text-color: #6c6c6c;
    --border-color: #eee;
    --user-message-bg: #eee;
    --ai-message-bg: #FDF5E6;
    --sidebar-hover-bg: #F0E8DD;
    --primary-accent: #333;
    --highlight-bg: #fff2a8;
    --sidebar-width: 280px;
}

html,
body {
    height: 100%;
    width: 100vw;
    margin: 0;
    overflow: hidden;
    font-family: var(--font-family);
    background-color: var(--page-bg);
    color: var(--primary-text-color);
}

#app-container {
    display: flex;
    height: 100dvh;
    width: 100%;
}



/* ========== 侧边栏 ========== */
#sidebar {
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    border-right: 1px solid var(--border-color);
    padding: 12px;
    flex-shrink: 0;
    height: 100%;
    box-sizing: border-box;
    transition: margin-left 0.3s ease-in-out;
    gap: 0;
}
#app-container.sidebar-collapsed #sidebar {
    margin-left: calc(-1 * var(--sidebar-width));
}

/* 网站标题（已去除下划线） */
#site-title {
    font-size: 1.3em;
    font-weight: 600;
    color: var(--primary-accent);
    margin-bottom: 12px;
    padding: 4px 8px;
    letter-spacing: 0.5px;
    text-align: center;
    flex-shrink: 0;
    text-decoration: none;
    display: block;
}

/* New Chat 按钮 */
#new-chat-button {
    width: 100%;
    background-color: transparent;
    border: 1px solid var(--secondary-text-color);
    color: var(--primary-text-color);
    padding: 9px 14px;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s;
    flex-shrink: 0;
}
#new-chat-button:hover {
    background-color: #eee;
    border-color: var(--primary-accent);
}
#new-chat-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sidebar-section {
    margin-top: 10px;
    flex-shrink: 0;
}
.sidebar-section label {
    display: block;
    font-size: 0.78em;
    color: var(--secondary-text-color);
    margin-bottom: 5px;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

#model-selector {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 7px;
    padding: 8px 10px;
    font-size: 0.9em;
    background-color: #fff;
    color: var(--primary-text-color);
    box-sizing: border-box;
    cursor: pointer;
    transition: border-color 0.2s;
}
#model-selector:hover {
    border-color: #ccc;
}
#model-selector:focus {
    outline: none;
    border-color: var(--primary-accent);
    box-shadow: 0 0 0 2px rgba(51, 51, 51, 0.08);
}

.search-section {
    position: relative;
    margin-top: 10px;
}
.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}
#search-input {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 7px;
    padding: 8px 30px 8px 10px;
    font-size: 0.88em;
    background-color: #fff;
    color: var(--primary-text-color);
    box-sizing: border-box;
    transition: border-color 0.2s;
}
#search-input:focus {
    outline: none;
    border-color: var(--primary-accent);
    box-shadow: 0 0 0 2px rgba(51, 51, 51, 0.08);
}
#search-input::placeholder {
    color: #bbb;
}
#clear-search-btn {
    position: absolute;
    right: 8px;
    font-size: 1.3em;
    cursor: pointer;
    color: var(--secondary-text-color);
    display: none;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 50%;
    transition: background-color 0.15s;
    user-select: none;
    z-index: 5;
}
#clear-search-btn:hover {
    background-color: #e0e0e0;
}

#search-results-overlay {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    max-height: 45vh;
    overflow-y: auto;
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    z-index: 50;
    margin-top: 4px;
    box-sizing: border-box;
}
.search-result-item {
    padding: 10px 13px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
}
.search-result-item:hover {
    background-color: #f5f5f5;
}
.search-result-item:last-child {
    border-bottom: none;
}
.search-result-title {
    font-weight: 600;
    font-size: 0.85em;
    color: var(--primary-accent);
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.search-result-snippet {
    font-size: 0.8em;
    color: var(--secondary-text-color);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.search-result-snippet mark {
    background-color: var(--highlight-bg);
    color: #333;
    padding: 1px 2px;
    border-radius: 2px;
}

#conversation-list {
    list-style: none;
    padding: 0;
    margin: 10px 0 0 0;
    overflow-y: auto;
    flex-grow: 1;
    min-height: 0;
}
#conversation-list li {
    padding: 10px 13px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.88em;
    transition: background-color 0.2s;
    color: var(--secondary-text-color);
    position: relative;
}
#conversation-list li:hover {
    background-color: #eee;
}
#conversation-list li.active {
    background-color: #eee;
    color: var(--primary-accent);
    font-weight: 500;
}

/* ========== 聊天容器 ========== */
#chat-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
}

/* 工具栏：左侧切换按钮，右侧操作按钮 */
#chat-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    flex-shrink: 0;
    min-height: 44px;
    box-sizing: border-box;
}

#sidebar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
#sidebar-toggle:hover {
    background-color: #e9e9e9;
}
#sidebar-toggle svg {
    width: 22px;
    height: 22px;
    fill: var(--secondary-text-color);
}

/* 登录/管理/退出按钮容器 */
.toolbar-right {
    display: flex;
    align-items: center;
}

/* 简洁按钮：无边框，纯文字，悬停时显示浅色背景 */
.btn-auth {
    display: inline-block;
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.9em;
    color: var(--secondary-text-color);
    background: transparent;
    transition: all 0.2s;
    white-space: nowrap;
    line-height: 1.4;
}
.btn-auth:hover {
    background-color: #f0f0f0;
    color: var(--primary-accent);
}

/* 管理按钮使用 WordPress 蓝色文字 */
.btn-admin {
    color: #0073aa;
}
.btn-admin:hover {
    background-color: #f0f8ff;
    color: #005a87;
}

#chat-window {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
}

.message-wrapper {
    display: flex;
    margin-bottom: 10px;
    max-width: 768px;
    margin: 0 auto;
    position: relative;
    padding-bottom: 30px;
}
.message-wrapper.user {
    justify-content: flex-end;
}
.message-wrapper.ai {
    justify-content: flex-start;
}

.message {
    padding: 12px 18px;
    border-radius: 18px;
    margin: 0;
    font-size: 1rem;
    color: #3a4f66;
    overflow-wrap: break-word;
    line-height: 1.5;
}
.message p {
    margin-block-start: 0.5em;
    margin-block-end: 0.5em;
    margin: 10px 0;
    line-height: 1.5;
    white-space: pre-line;
}
.user .message {
    background-color: var(--user-message-bg);
}
.ai .message {}

.ai pre {
    margin: 12px 0;
    border-radius: 8px;
    overflow-x: auto;
    background-color: #f6f8fa;
    font-size: 14px;
}
.ai pre code.hljs {
    background-color: unset;
}
.ai code:not(pre code) {
    font-family: "Courier New", monospace;
    font-size: 0.9em;
    background-color: var(--border-color);
    padding: 2px 5px;
    border-radius: 4px;
}

/* 复制按钮样式 */
.copy-btn {
    position: absolute;
    bottom: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s, background-color 0.2s;
    background-color: rgba(255,255,255,0.8);
    backdrop-filter: blur(4px);
    z-index: 5;
}
.user  .copy-btn{
    right: 8px;
}
.ai  .copy-btn{
    left: 8px;
}
.message-wrapper:hover .copy-btn {
    opacity: 1;
}
.copy-btn:hover {
    background-color: #e9e9e9;
}
.copy-btn svg {
    width: 16px;
    height: 16px;
    fill: var(--secondary-text-color);
}
.copy-btn.copied svg {
    fill: #10a37f;
}

/* 输入区域 */
#chat-form-container {
    padding: 16px 24px;
    flex-shrink: 0;
}
#chat-form {
    display: flex;
    flex-direction: column;
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    max-width: 678px;
    margin: 0 auto;
}
#prompt-input-wrapper {
    display: flex;
    align-items: flex-end;
}
#prompt-input {
    flex-grow: 1;
    border: none;
    background-color: transparent;
    padding: 10px 15px;
    font-size: 1em;
    resize: none;
    min-height: 24px;
    max-height: 200px;
    overflow-y: auto;
    line-height: 1.5;
    color: var(--primary-text-color);
    outline: none;
    font-family: var(--font-family);
}
.form-buttons {
    display: flex;
    align-items: center;
    padding-right: 5px;
    flex-shrink: 0;
}
.icon-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    transition: background-color 0.2s;
}
.icon-button:hover {
    background-color: #e9e9e9;
}
.icon-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.icon-button svg {
    width: 24px;
    height: 24px;
    fill: var(--secondary-text-color);
}
#send-button svg {
    fill: var(--primary-accent);
}

#image-preview-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 0 15px 8px;
}
#image-preview-container:empty {
    display: none;
}
.img-preview-wrapper {
    position: relative;
    display: inline-block;
}
.img-preview-wrapper img {
    height: 70px;
    width: 70px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}
.img-preview-remove-btn {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 20px;
    height: 20px;
    background-color: rgba(0,0,0,0.7);
    color: white;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1;
}

.ai-loader {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    height: 44px;
}
.ai-loader .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #333;
    margin: 0 5px;
    animation: pulse 1.5s ease-in-out infinite;
}
.ai-loader .dot:nth-child(2) {
    animation-delay: 0.3s;
}
.ai-loader .dot:nth-child(3) {
    animation-delay: 0.6s;
}
@keyframes pulse {
    0%, 60%, 100% {
        transform: scale(1);
        opacity: 0.6;
    }
    30% {
        transform: scale(1.3);
        opacity: 1;
    }
}

/* 移动端适配：侧边栏滑入，聊天容器平移不压缩 */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 100;
        width: 260px;
        background: #fff;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        margin: 0;
    }
    #app-container.sidebar-collapsed #sidebar {
        transform: translateX(-100%);
    }
    #app-container:not(.sidebar-collapsed) #sidebar {
        transform: translateX(0);
    }
    #chat-container {
        width: 100vw;
        min-width: 100vw;
        transition: transform 0.3s ease;
        will-change: transform;
    }
    #app-container:not(.sidebar-collapsed) #chat-container {
        transform: translateX(260px);
    }
    body, #app-container {
        overflow-x: hidden;
    }
    #chat-toolbar {
        padding: 6px 10px;
        position: relative;   /* 为 z-index 生效 */
        z-index: 101;         /* 高于侧边栏的 100，防止被遮挡 */
    }
    #chat-form-container {
        padding: 10px 12px;
    }
    .toolbar-right {
        gap: 8px;
    }
    .btn-auth {
        padding: 5px 10px;
        font-size: 0.85em;
    }
}

/* ========== 欢迎信息与智能体卡片 ========== */
#welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #888;
    user-select: none;
    text-align: center;
    padding: 20px;
}
#welcome-message h1 {
    font-size: 2.4em;
    margin-bottom: 12px;
    font-weight: 600;
    color: var(--primary-accent);
}
#welcome-message p {
    font-size: 1.1em;
    opacity: 0.7;
    margin: 0 0 30px 0;
}

/* 登录提示 */
.login-notice {
    margin-top: 20px;
    margin-bottom: 20px;
    padding: 12px 20px;
    background: #f8f8f8;
    border-radius: 12px;
    font-size: 0.95em;
}
.login-notice a {
    color: var(--primary-accent);
    font-weight: 500;
}

/* 智能体容器 */
.roles-grid {
    width: 100%;
    max-width: 800px;
    margin-top: 10px;
}

/* 卡片流式布局：flex wrap，居中，每项宽度自适应 */
.role-cards {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    padding: 0 10px;
}

/* 单个智能体卡片：宽度由内容决定 */
.role-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 12px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    white-space: nowrap;
    flex: none;
}
.role-card:hover {
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
    transform: translateY(-3px);
}
.role-card .role-name {
    color: var(--primary-accent);
    margin: 0;
    line-height: 1.4;
}

/* 描述文字样式（备用） */
.role-card .role-desc {
    font-size: 0.88em;
    color: #64748b;
    line-height: 1.5;
    margin-top: 10px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* 有对话时隐藏智能体区域 */
#welcome-message.has-conversation .roles-grid {
    display: none;
}

/* 未登录/禁用状态（后备样式） */
.role-card.disabled,
.role-card[style*="pointer-events: none"] {
    opacity: 0.6;
    pointer-events: none;
    filter: grayscale(30%);
}

/* 当聊天窗口内有其他消息时，自动隐藏欢迎信息 */
#chat-window:not(:empty) #welcome-message:not(:only-child) {
    display: none;
}

/* 移动端智能体卡片优化 */
@media (max-width: 480px) {
    .role-cards {
        gap: 12px;
    }
    .role-card {
        padding: 12px 18px;
    }
    .role-card .role-name {
        font-size: 1em;
    }
}

/* 删除按钮 - 样式与复制按钮完全一致 */
.delete-btn {
    position: absolute;
    bottom: 4px;
    left: 32px;   /* 与复制按钮并排 */
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s, background-color 0.2s;
    background-color: rgba(255,255,255,0.8);
    backdrop-filter: blur(4px);
    z-index: 5;
}
.ai .delete-btn {
    left: 32px;
}
.message-wrapper:hover .delete-btn {
    opacity: 1;
}
.delete-btn:hover {
    background-color: #e9e9e9;
}
.delete-btn svg {
    width: 16px;
    height: 16px;
    fill: var(--secondary-text-color);
}