* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: #0A1121;
    color: #fff;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    display: flex;
    position: relative;
}

/* ===== 星空背景 ===== */
.stars {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}
.stars .dot {
    position: absolute;
    background: #FFF;
    border-radius: 50%;
}

.bg-glow-1 {
    position: fixed;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(59,130,246,0.06) 0%, transparent 70%);
    top: -50px;
    right: 250px;
    pointer-events: none;
    z-index: 0;
}
.bg-glow-2 {
    position: fixed;
    width: 320px;
    height: 320px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(139,92,246,0.06) 0%, transparent 70%);
    bottom: -80px;
    right: 100px;
    pointer-events: none;
    z-index: 0;
}

/* ===== 左侧边栏 ===== */
.sidebar {
    position: relative;
    z-index: 1;
    width: 260px;
    min-width: 52px;
    height: 100vh;
    background: rgba(15, 23, 41, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    padding: 16px 14px;
    overflow: hidden;
    flex-shrink: 0;
    transition: padding 0.2s;
}

/* 侧边栏收起/展开按钮 */
.btn-toggle-sidebar {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    height: 36px;
    border-radius: 8px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.05);
    color: #939EAB;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    padding: 0 12px;
    font-size: 13px;
    margin-top: auto;
}
.btn-toggle-sidebar:hover {
    background: rgba(255,255,255,0.06);
    color: #c4ccd4;
}
.btn-toggle-sidebar svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    transition: transform 0.25s;
}

.sidebar.narrow .btn-toggle-sidebar {
    justify-content: center;
    padding: 0;
    width: 32px;
    height: 32px;
    margin-left: auto;
    margin-right: auto;
    border-radius: 6px;
}
.sidebar.narrow .btn-toggle-sidebar span {
    display: none;
}
.sidebar.narrow .btn-toggle-sidebar svg {
    transform: rotate(180deg);
}

/* ===== 拖拽手柄 ===== */
.resize-handle {
    position: relative;
    z-index: 2;
    width: 4px;
    height: 100vh;
    cursor: col-resize;
    flex-shrink: 0;
    background: transparent;
    transition: background 0.2s;
}
.resize-handle::after {
    content: '';
    position: absolute;
    left: 1px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: rgba(59,130,246,0);
    transition: background 0.2s;
}
.resize-handle:hover::after,
.resize-handle.dragging::after {
    background: rgba(59,130,246,0.6);
}

/* 拖拽时禁止选中文本 */
body.resizing {
    user-select: none;
    -webkit-user-select: none;
    cursor: col-resize;
}

.btn-new-chat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    height: 44px;
    background: linear-gradient(135deg, #3B82F6, #2563EB);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}
.btn-new-chat:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(59,130,246,0.35);
}
.btn-new-chat svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}
.btn-new-chat .chevron-left,
.btn-new-chat .chevron-right {
    width: 8px;
    height: 8px;
    opacity: 0.6;
}

.sidebar-divider {
    height: 1px;
    background: rgba(255,255,255,0.06);
    margin: 14px 0;
    flex-shrink: 0;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 10px;
    color: #939EAB;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}
.nav-item:hover {
    background: rgba(255,255,255,0.04);
    color: #c4ccd4;
}
.nav-item.active {
    background: rgba(59,130,246,0.15);
    color: #3B82F6;
}
.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sidebar-label {
    font-size: 11px;
    color: rgba(147,158,171,0.5);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 14px 4px;
    font-weight: 600;
    flex-shrink: 0;
}

/* 窄侧栏模式 */
.sidebar.narrow .btn-new-chat span,
.sidebar.narrow .btn-new-chat .chevron-left,
.sidebar.narrow .btn-new-chat .chevron-right,
.sidebar.narrow .nav-item span,
.sidebar.narrow .sidebar-label,
.sidebar.narrow .chat-history-list,
.sidebar.narrow .sidebar-divider:last-of-type {
    display: none;
}
.sidebar.narrow {
    padding: 10px 6px;
    width: 52px !important;
    min-width: 52px;
}
.sidebar.narrow .nav-item {
    justify-content: center;
    padding: 8px;
    border-radius: 8px;
}
.sidebar.narrow .nav-item svg {
    width: 18px;
    height: 18px;
}
.sidebar.narrow .btn-new-chat {
    justify-content: center;
    padding: 0;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    margin: 0 auto;
}
.sidebar.narrow .btn-new-chat svg {
    width: 16px;
    height: 16px;
}
.sidebar.narrow .btn-new-chat svg:not(.chevron-left):not(.chevron-right) {
    display: block;
}
.sidebar.narrow .sidebar-divider {
    margin: 10px 0;
}
.sidebar.narrow .sidebar-nav {
    gap: 4px;
}

/* 历史列表滚动条 */
.chat-history-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    margin-top: 6px;
    min-height: 0;
}
.chat-history-list::-webkit-scrollbar {
    width: 3px;
}
.chat-history-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
}
.history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    border-radius: 8px;
    color: #939EAB;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.history-item:hover {
    background: rgba(255,255,255,0.04);
    color: #c4ccd4;
}
.history-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.5;
}
.history-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}
.history-item-time {
    font-size: 11px;
    opacity: 0.5;
    flex-shrink: 0;
}

/* ===== 主区域 ===== */
.main-area {
    position: relative;
    z-index: 1;
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: rgba(13, 20, 36, 0.4);
    min-width: 320px;
}

/* ===== 顶部栏 ===== */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 20px;
    background: rgba(15, 23, 41, 0.7);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255,255,255,0.04);
    flex-shrink: 0;
}
.top-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.tab-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(15, 23, 41, 0.8);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    padding: 6px 16px;
    font-size: 14px;
    color: #fff;
    cursor: pointer;
    transition: border-color 0.2s;
}
.tab-selector:hover {
    border-color: rgba(59,130,246,0.3);
}
.tab-selector svg {
    width: 16px;
    height: 16px;
}
.tab-selector .globe-icon {
    color: #3B82F6;
}
.tab-selector .chevron {
    color: #939EAB;
    width: 12px;
    height: 12px;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}
.btn-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.06);
    color: #939EAB;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-icon:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}
.btn-icon svg {
    width: 18px;
    height: 18px;
}

.btn-settings {
    height: 32px;
    padding: 0 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 6px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.06);
    color: #939EAB;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn-settings:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}
.btn-settings svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}
.btn-settings .chevron-down {
    width: 10px;
    height: 10px;
    opacity: 0.5;
    transition: transform 0.2s;
}
.model-selector.open .chevron-down {
    transform: rotate(180deg);
}

/* 模型选择器下拉 */
.model-selector {
    position: relative;
}
.model-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 180px;
    background: rgba(20, 28, 48, 0.98);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    padding: 6px;
    z-index: 100;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.model-selector.open .model-dropdown {
    display: block;
    animation: dropdownIn 0.15s ease-out;
}
@keyframes dropdownIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
.model-dropdown {
    min-width: 220px;
    max-width: 320px;
    max-height: 360px;
    overflow-y: auto;
}
.model-dropdown::-webkit-scrollbar { width: 3px; }
.model-dropdown::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
.model-option {
    padding: 10px 12px;
    font-size: 13px;
    color: #939EAB;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}
.model-option:hover {
    background: rgba(59,130,246,0.12);
    color: #fff;
}
.model-option.active {
    background: rgba(59,130,246,0.18);
    color: #3B82F6;
}
.model-option-name {
    font-weight: 600;
    font-size: 13px;
}
.model-option-desc {
    font-size: 11px;
    color: rgba(147,158,171,0.6);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.model-option.active .model-option-desc {
    color: rgba(59,130,246,0.6);
}

/* ===== 聊天区域 ===== */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: 0;
}
.chat-area::-webkit-scrollbar {
    width: 4px;
}
.chat-area::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
}

/* 欢迎区域 */
.welcome-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 400px;
}
.welcome-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, rgba(59,130,246,0.2), rgba(139,92,246,0.2));
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}
.welcome-icon svg {
    width: 32px;
    height: 32px;
    color: #3B82F6;
}
.welcome-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}
.welcome-subtitle {
    color: rgba(255,255,255,0.4);
    font-size: 15px;
    margin-bottom: 32px;
}

/* 快捷入口卡片 */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-width: 660px;
    width: 100%;
}
.quick-card {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.25s;
    text-align: left;
    color: #fff;
    font-size: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.quick-card:hover {
    background: rgba(255,255,255,0.06);
    border-color: rgba(59,130,246,0.2);
    transform: translateY(-1px);
}
.quick-card-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.quick-card-icon.blue { background: rgba(59,130,246,0.15); color: #3B82F6; }
.quick-card-icon.purple { background: rgba(139,92,246,0.15); color: #8B5CF6; }
.quick-card-icon.green { background: rgba(34,197,94,0.15); color: #22C55E; }
.quick-card-title {
    font-weight: 600;
    font-size: 14px;
}
.quick-card-desc {
    color: rgba(255,255,255,0.35);
    font-size: 12px;
    line-height: 1.5;
}

/* 消息气泡 */
.message {
    display: flex;
    gap: 14px;
    max-width: 760px;
}
.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
    font-weight: 600;
}
.message-avatar.user {
    background: linear-gradient(135deg, #6366F1, #8B5CF6);
}
.message-avatar.ai {
    background: linear-gradient(135deg, #3B82F6, #06B6D4);
}
.message-content {
    flex: 1;
    min-width: 0;
}
.message-role {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
}
.message-text {
    color: rgba(255,255,255,0.78);
    font-size: 14px;
    line-height: 1.7;
}
.message.ai .message-text {
    background: rgba(255,255,255,0.03);
    border-radius: 0 12px 12px 12px;
    padding: 14px 18px;
    border: 1px solid rgba(255,255,255,0.05);
}
.message.user .message-text {
    padding: 14px 0;
}

/* ===== 输入区域 ===== */
.chat-input-area {
    padding: 8px 12px 12px;
    flex-shrink: 0;
    background: linear-gradient(180deg, transparent, rgba(15,23,41,0.3) 40%);
}
.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: rgba(15, 23, 41, 0.7);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px;
    padding: 8px 8px 8px 18px;
    backdrop-filter: blur(10px);
    transition: border-color 0.25s;
}
.input-wrapper:focus-within {
    border-color: rgba(59,130,246,0.35);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.08);
}
.input-wrapper textarea {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: #fff;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    padding: 6px 0;
    max-height: 120px;
    line-height: 1.5;
}
.input-wrapper textarea::placeholder {
    color: rgba(147,158,171,0.5);
}
.input-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.btn-input-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: none;
    border: none;
    color: #939EAB;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-input-icon:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}
.btn-send {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #3B82F6, #2563EB);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s;
    flex-shrink: 0;
}
.btn-send:hover {
    box-shadow: 0 4px 16px rgba(59,130,246,0.4);
}
.btn-send svg {
    width: 16px;
    height: 16px;
}
.input-footer {
    text-align: center;
    font-size: 11px;
    color: rgba(147,158,171,0.4);
    margin-top: 10px;
}

/* 打字动画 */
.typing-dots span {
    animation: blink 1.4s infinite both;
    font-size: 24px;
    line-height: 1;
    display: inline-block;
    margin: 0 1px;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
    0%, 20% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}

/* 代码块渲染 */
.message-text pre {
    background: rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    padding: 14px 16px;
    margin: 10px 0;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.6;
}
.message-text pre code {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    color: #e2e8f0;
}
.message-text code {
    background: rgba(59,130,246,0.12);
    color: #93c5fd;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}
.message-text pre code {
    background: none;
    padding: 0;
    color: #e2e8f0;
}
.message-text h1, .message-text h2, .message-text h3 {
    margin: 12px 0 6px;
    font-weight: 600;
}
.message-text h1 { font-size: 18px; }
.message-text h2 { font-size: 16px; }
.message-text h3 { font-size: 15px; }
.message-text ul, .message-text ol {
    margin: 6px 0;
    padding-left: 20px;
}
.message-text li { margin: 3px 0; }
.message-text strong { font-weight: 600; color: rgba(255,255,255,0.9); }
.message-text em { font-style: italic; }
.message-text blockquote {
    border-left: 3px solid rgba(59,130,246,0.4);
    padding-left: 12px;
    margin: 8px 0;
    color: rgba(255,255,255,0.5);
}

/* 错误消息 */
.message.ai.error .message-text {
    border-color: rgba(239, 68, 68, 0.3) !important;
    background: rgba(239, 68, 68, 0.06) !important;
    color: #fca5a5;
}
.message.ai.error .message-avatar.ai {
    background: linear-gradient(135deg, #EF4444, #DC2626);
}

/* 停止按钮 */
#btnStop {
    color: #EF4444;
}
#btnStop:hover {
    background: rgba(239,68,68,0.12);
    color: #f87171;
}

/* 流式输出光标 */
.streaming-cursor {
    display: inline-block;
    width: 2px;
    height: 16px;
    background: #3B82F6;
    margin-left: 1px;
    vertical-align: text-bottom;
    animation: cursorBlink 0.8s infinite;
}
@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ===== 移动端菜单按钮 ===== */
.btn-menu {
    display: none;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.06);
    color: #939EAB;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}
.btn-menu:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}
.btn-menu svg {
    width: 18px;
    height: 18px;
}

/* 侧边栏遮罩层 */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 3;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .chat-area {
        padding: 8px 8px;
    }
    .chat-input-area {
        padding: 6px 8px 10px;
    }
    .quick-actions {
        grid-template-columns: 1fr;
        max-width: 100%;
    }
    .top-bar {
        padding: 0 12px;
    }

    /* 显示菜单按钮 */
    .btn-menu {
        display: flex;
    }

    /* 移动端侧边栏变为覆盖式 */
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        width: 280px !important;
        height: 100vh;
        z-index: 4;
        transition: left 0.3s ease;
        box-shadow: 4px 0 24px rgba(0,0,0,0.4);
    }
    .sidebar.open {
        left: 0;
    }
    .sidebar.narrow {
        left: -280px !important;
    }

    /* 遮罩层显示 */
    .sidebar-overlay.visible {
        display: block;
    }

    /* 拖拽手柄在移动端隐藏 */
    .resize-handle {
        display: none;
    }
}
