:root {
    --chat-bg: #f7f8fc;
    --panel-bg: #ffffff;
    --border: #e5e7eb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --brand: #4f46e5;
    --brand-fade: rgba(79, 70, 229, 0.08);
    --danger: #ef4444;
    font-family: "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    background: var(--chat-bg);
    color: var(--text-primary);
    margin: 0;
}

.chat-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 24px;
    padding: 24px;
    padding-top: 120px; /* 为固定头部留出足够空间，确保不重叠（头部高度约100-110px） */
    max-width: 1400px;
    margin: 0 auto;
    margin-top: 0; /* 确保顶部没有额外边距 */
    min-height: calc(100vh - 120px); /* 减去头部高度 */
    transition: grid-template-columns 0.3s ease;
}

.chat-layout.sidebar-collapsed {
    grid-template-columns: 72px 1fr;
}

.chat-sidebar {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.05);
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: sticky;
    top: 110px;
    height: fit-content;
    transition: width 0.3s ease, padding 0.3s ease;
    overflow: hidden;
}

.chat-sidebar.collapsed {
    width: 72px;
    padding: 16px 8px;
    align-items: center;
}

.sidebar-toggle {
    position: absolute;
    top: 8px;
    right: 12px;
    background: #f3f4f6;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    color: var(--text-secondary);
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
    z-index: 10;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

.sidebar-toggle:hover {
    background: var(--brand-fade);
    color: var(--brand);
}

.chat-sidebar.collapsed .sidebar-toggle svg {
    transform: rotate(180deg);
}

.sidebar-content {
    margin-top: 40px;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.chat-sidebar.collapsed .sidebar-content {
    opacity: 1;
    transform: translateX(0);
}

.chat-sidebar.collapsed .sidebar-section {
    align-items: center;
}

.chat-sidebar.collapsed #conversationEmpty,
.chat-sidebar.collapsed #conversationList,
.chat-sidebar.collapsed #historyNotice {
    display: none;
}

.chat-sidebar.collapsed #newConversationBtn {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-section.muted p {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 0;
}

.conversation-empty {
    font-size: 13px;
    color: var(--text-secondary);
    background: #f9fafb;
    border: 1px dashed var(--border);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    margin-bottom: 12px;
}

.conversation-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

.conversation-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.conversation-section .section-title {
    margin-bottom: 0;
}

.conversation-section .topic-list {
    gap: 4px;
}

.conversation-section .topic-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    border: 1px solid transparent;
}

.conversation-item {
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 10px;
    transition: border 0.2s, background 0.2s;
}

.conversation-item:hover {
    border-color: var(--border);
    background: #f9fafb;
}

.conversation-item.active {
    border-color: var(--brand);
    background: var(--brand-fade);
    color: var(--brand);
}

.conversation-item small {
    font-size: 11px;
    color: var(--text-secondary);
}

.section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.topic-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.topic-list li {
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.topic-list li:hover {
    background: var(--brand-fade);
    color: var(--brand);
}

.chat-main {
    display: flex;
    flex-direction: column;
    gap: 18px; /* 确保 chat-board 和 chat-input-card 之间有间距，不重叠 */
    min-height: calc(100vh - 120px); /* 减去头部高度，让内容自然延伸 */
    position: relative;
}

.chat-hero {
    display: flex;
    gap: 16px;
    padding: 20px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: linear-gradient(120deg, #f5f3ff, #eef2ff);
    align-items: center;
}

.hero-icon {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}

.chat-hero h1 {
    margin: 0;
    font-size: 24px;
}

.chat-hero p {
    margin: 4px 0 0;
    color: var(--text-secondary);
    font-size: 14px;
}

.chat-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 20px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--panel-bg);
    flex-wrap: wrap;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.toolbar-label {
    font-size: 14px;
    font-weight: 600;
}

.model-selector {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.model-select-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.model-selector select {
    min-width: 220px;
    flex: 1;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    font-size: 14px;
}

.model-search {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    max-width: 420px;
}

.model-search input {
    width: 100%;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    font-size: 14px;
}

.model-search input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.search-hint {
    font-size: 12px;
    color: var(--text-secondary);
}

.ghost-btn {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 12px;
    padding: 8px 14px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    transition: border 0.2s, color 0.2s;
}

.ghost-btn:hover {
    border-color: var(--brand);
    color: var(--brand);
}

.temperature-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.temperature-control label {
    font-size: 13px;
    color: var(--text-secondary);
}

#temperatureRange {
    accent-color: var(--brand);
}

.status-chip {
    background: var(--brand-fade);
    color: var(--brand);
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
}

.scroll-area {
    overflow-y: auto;
    overflow-x: hidden;
}

.scroll-area::-webkit-scrollbar {
    width: 6px;
}

.scroll-area::-webkit-scrollbar-track {
    background: transparent;
}

.scroll-area::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.scroll-area::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.chat-board {
    flex: 1;
    min-height: 400px; /* 最小高度，确保有足够空间 */
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--panel-bg);
    padding: 20px;
    padding-bottom: 5px; /* 正常内边距 */
    margin-bottom: 0; /* 确保底部没有额外边距，由 gap 控制间距 */
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.02);
    overflow-y: auto;
    overflow-x: hidden;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.quick-prompts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
}

.quick-prompts button {
    border: 1px solid var(--border);
    background: transparent;
    padding: 10px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    transition: border 0.2s, color 0.2s;
}

.quick-prompts button:hover {
    border-color: var(--brand);
    color: var(--brand);
}

.sticky-bottom {
    /* 移除 sticky，改为正常流式布局 */
    margin-top: 0; /* 由父容器的 gap 控制间距，不重叠 */
    margin-bottom: 0;
    z-index: 10;
    background: var(--panel-bg);
}

.chat-input-card {
    
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--panel-bg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-shrink: 0;
}

.chat-input-card textarea {
    width: 100%;
    min-height: 50px;
    border: none;
}
.input-toolbar {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 12px 0;
    margin: 8px 0;
}

.hidden-input {
    display: none;
}

.attachment-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #f9fafb;
    font-size: 13px;
}

.attachment-chip button {
    border: none;
    background: transparent;
    cursor: pointer;
    color: #9ca3af;
}

.attachment-chip button:hover {
    color: var(--danger);
}
    border: none;
    resize: none;
    font-size: 15px;
    font-family: inherit;
    min-height: 100px;
    outline: none;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.input-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-secondary);
    
}

.model-label {
    color: var(--text-secondary);
    font-size: 13px;
}

.model-selector-inline {
    position: relative;
    display: inline-block;
}

.model-hint-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: border-color 0.2s, color 0.2s;
}

.model-hint-btn:hover {
    border-color: var(--brand);
    color: var(--brand);
}

.model-hint-btn svg {
    transition: transform 0.2s;
}

.model-dropdown-inline {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    width: 320px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.1);
    display: none;
    z-index: 20;
}

.model-dropdown-inline.show {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.model-dropdown-inline .model-search {
    max-width: 100%;
}

.model-dropdown-inline .model-select-wrapper {
    width: 100%;
}

.model-dropdown-inline .model-select-wrapper select {
    min-width: 0;
    width: 100%;
}

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

.action-icon-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.action-icon-btn:hover {
    border-color: var(--brand);
    color: var(--brand);
    background: var(--brand-fade);
}

.action-icon-btn.active {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
}

.action-icon-btn svg {
    width: 18px;
    height: 18px;
}

.web-search-provider,
.web-search-level {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
    background: #fff;
    cursor: pointer;
    transition: border-color 0.2s;
    margin-left: 4px;
}

.web-search-provider:focus,
.web-search-level:focus {
    outline: none;
    border-color: var(--brand);
}

.btn-primary {
    background: var(--brand);
    border: none;
    color: #fff;
    padding: 10px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 15px;
    transition: background 0.2s, box-shadow 0.2s;
}

.btn-primary:hover {
    background: #4338ca;
    box-shadow: 0 10px 20px rgba(79, 70, 229, 0.2);
}

.full-width {
    width: 100%;
}

.message {
    display: flex;
    gap: 12px;
    padding: 14px;
    border-radius: 16px;
    margin-bottom: 12px;
    border: 1px solid transparent;
}

.message-image-wrapper {
    margin: 8px 0;
    display: inline-block;
    max-width: 100%;
}

.message-image {
    max-width: 400px;
    max-height: 400px;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s;
    border: 1px solid var(--border);
}

.message-image:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.attachment-preview-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.75);
    z-index: 200;
    padding: 40px;
    cursor: pointer;
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.attachment-preview-modal img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    cursor: default;
}

.close-preview {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #111827;
    transition: background 0.2s;
    z-index: 201;
}

.close-preview:hover {
    background: #fff;
}

.message.user {
    flex-direction: row-reverse;
    background: #eef2ff;
    border-color: #c7d2fe;
}

.message.assistant {
    background: #fff;
    border-color: #e5e7eb;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 12px;
    background: var(--brand-fade);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--brand);
}

.message-content {
    flex: 1;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 15px;
}

.message-attachments {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.message-attachment {
    font-size: 12px;
    padding: 5px 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(79, 70, 229, 0.06);
}

.message-attachment img {
    max-width: 120px;
    max-height: 90px;
    border-radius: 8px;
    display: block;
}

.message-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 6px;
}

.message.pending .message-content::after {
    content: '...';
    animation: blink 1s steps(1) infinite;
    margin-left: 6px;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

@media (max-width: 1200px) {
    .chat-layout {
        grid-template-columns: 230px 1fr;
        padding: 16px;
    }
}

@media (max-width: 960px) {
    .chat-layout {
        grid-template-columns: 1fr;
        padding: 0;
        padding-top: 0px; /* 移动端为头部留出足够空间，确保不重叠 */
        gap: 0;
        margin-top: 0; /* 确保顶部没有额外边距 */
        min-height: calc(100vh - 100px); /* 减去头部高度 */
    }

    /* 移动端侧边栏默认隐藏 */
    .chat-sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 280px;
        height: 100vh;
        z-index: 1001;
        border-radius: 0;
        border-right: 1px solid var(--border);
        transition: left 0.3s ease, visibility 0.3s ease;
        overflow-y: auto;
        padding: 20px;
        background: var(--panel-bg);
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
        visibility: hidden;
        pointer-events: none;
    }

    .chat-sidebar.mobile-open {
        left: 0;
        visibility: visible;
        pointer-events: auto;
    }

    /* 遮罩层 */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        opacity: 0;
        transition: opacity 0.3s ease;
        pointer-events: none;
    }

    .sidebar-overlay.active {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    /* 移动端展开按钮 - 固定在左上角 */
    .mobile-sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 16px;
        left: 16px;
        width: 44px;
        height: 44px;
        background: var(--panel-bg);
        border: 1px solid var(--border);
        border-radius: 12px;
        cursor: pointer;
        z-index: 999;
        box-shadow: 0 2px 8px rgba(15, 23, 42, 0.1);
        transition: background 0.2s, box-shadow 0.2s;
    }

    .mobile-sidebar-toggle:hover {
        background: var(--brand-fade);
        box-shadow: 0 4px 12px rgba(15, 23, 42, 0.15);
    }

    .mobile-sidebar-toggle:active {
        transform: scale(0.95);
    }

    .mobile-sidebar-toggle svg {
        color: var(--text-primary);
    }

    .chat-main {
        width: 100%;
        padding: 0;
        margin-top: 0;
        min-height: calc(100vh - 100px); /* 减去头部高度，让内容自然延伸 */
        display: flex;
        flex-direction: column;
        gap: 0; /* 移动端可以设置为0，由具体元素控制间距 */
    }

    .chat-board {
        padding: 16px;
        padding-top: 20px; /* 移动端顶部内边距 */
        padding-bottom: 400px; /* 正常内边距 */
        margin-bottom: 0; /* 确保底部没有额外边距 */
        flex: 1;
        min-height: 300px; /* 最小高度 */
        overflow-y: auto;
        overflow-x: hidden;
    }

    .chat-input-card {
        border-radius: 0;
        border-left: none;
        border-right: none;
        padding: 16px;
        
        /* 移除 fixed，改为正常流式布局 */
        margin-top: 0; /* 确保顶部没有额外边距，不重叠 */
        margin-bottom: 0;
        z-index: 98;
        background: var(--panel-bg);
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    }

    /* 移动端隐藏桌面端的折叠按钮 */
    .sidebar-toggle {
        display: block;
    }

    /* 确保sticky-bottom在移动端也生效 */
    .sticky-bottom {
        position: fixed;
        
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 98;
    }

    /* 移动端侧边栏内容调整 */
    .chat-sidebar .sidebar-content {
        margin-top: 0;
    }

    .chat-sidebar .sidebar-toggle {
        position: absolute;
        top: 12px;
        right: 12px;
        background: #f3f4f6;
        border: none;
        cursor: pointer;
        padding: 8px;
        border-radius: 8px;
        color: var(--text-secondary);
        z-index: 10;
    }

    /* 移动端侧边栏展开时，强制显示所有内容 */
    .chat-sidebar.mobile-open {
        width: 280px !important;
        padding: 20px !important;
    }

    .chat-sidebar.mobile-open .sidebar-content {
        opacity: 1 !important;
        transform: translateX(0) !important;
        margin-top: 40px;
    }

    .chat-sidebar.mobile-open #conversationEmpty,
    .chat-sidebar.mobile-open #conversationList,
    .chat-sidebar.mobile-open #historyNotice {
        display: block !important;
    }

    .chat-sidebar.mobile-open #newConversationBtn {
        width: auto !important;
        height: auto !important;
        padding: 10px 16px !important;
        border-radius: 12px !important;
        font-size: 14px !important;
    }

    .chat-sidebar.mobile-open .sidebar-section {
        align-items: flex-start !important;
    }
}

/* 桌面端隐藏移动端按钮 */
@media (min-width: 961px) {
    .mobile-sidebar-toggle {
        display: none;
    }

    .sidebar-overlay {
        display: none !important;
    }
}

@media (max-width: 640px) {
    .chat-toolbar,
    .chat-hero {
        flex-direction: column;
        align-items: flex-start;
    }

    .toolbar-right {
        width: 100%;
        justify-content: space-between;
    }

    .model-selector,
    .model-select-wrapper,
    .model-selector select {
        width: 100%;
    }

    .model-select-wrapper {
        flex-direction: column;
        align-items: stretch;
    }

    .model-search {
        max-width: 100%;
    }

    .input-footer {
        flex-direction: column;
        align-items: flex-start;
    }

    .input-actions {
        width: 100%;
        justify-content: flex-end;
    }

}

