/* 继承全局变量，不再重复定义 :root */

/* ============================================================
   LAYOUT
   ============================================================ */
body {
    margin: 0;
    padding: 0;
    overflow: hidden; /* 防止整个页面滚动 */
    background-color: var(--bg-base);
    color: var(--fg0);
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

.chat-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
    position: relative;
    overflow: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    width: 260px;
    background-color: #000000; /* 更深的背景 */
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    transition: transform 0.3s ease;
    z-index: 100;
    padding: 16px;
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 0 8px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    color: var(--fg0);
    text-decoration: none;
}

.brandMark {
    height: 24px;
    width: auto;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background-color: var(--card); /* 半透明背景 */
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--fg0);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
    text-align: left;
    margin-bottom: 20px;
}

.new-chat-btn:hover {
    background-color: var(--card2);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    margin-right: -8px; /* 滚动条向右移 */
    padding-right: 8px;
}

/* 自定义滚动条 */
.history-list::-webkit-scrollbar {
    width: 4px;
}
.history-list::-webkit-scrollbar-thumb {
    background-color: var(--border);
    border-radius: 4px;
}

.group-title {
    font-size: 12px;
    color: var(--fg2);
    margin: 16px 8px 8px;
    font-weight: 500;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--fg1);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.2s;
    position: relative; /* For actions positioning if needed */
}

.history-item svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.history-item span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item:hover, .history-item.active {
    background-color: var(--card2);
    color: var(--fg0);
}

.session-actions {
    display: none;
    gap: 4px;
}

.history-item:hover .session-actions,
.history-item.active .session-actions {
    display: flex;
}

.edit-session, .delete-session {
    background: none;
    border: none;
    color: var(--fg2);
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
    border-radius: 4px;
    line-height: 1;
}

.edit-session:hover, .delete-session:hover {
    background-color: rgba(255,255,255,0.1);
    color: var(--fg0);
}

.sidebar-footer {
    padding-top: 16px;
    border-top: 1px solid var(--border);
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sidebar-btn-secondary {
    display: flex;
    align-items: center;
    justify-content: center; /* Center content or left align? "new-chat-btn" is left aligned. Let's align left for consistency or center for distinct action? User said "asymmetrical". Left align matches other items. */
    justify-content: flex-start; /* Consistent with new-chat-btn */
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background-color: transparent; /* Cleaner look, maybe just border */
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--fg0);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.sidebar-btn-secondary:hover {
    background-color: var(--card2);
    border-color: var(--border-hi);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--fg0);
    transition: background 0.2s;
}

.user-profile:hover {
    background-color: var(--card2);
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    background-color: var(--blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #fff;
}

.user-info {
    font-size: 13px;
    line-height: 1.2;
}

.user-info .name {
    font-weight: 500;
}

.user-info .status {
    font-size: 11px;
    color: var(--fg2);
}

/* 移动端隐藏侧边栏 */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: -100%;
        height: 100%;
        width: 80%;
        max-width: 300px;
        box-shadow: 10px 0 20px rgba(0,0,0,0.5);
    }
    .sidebar.open {
        transform: translateX(100%);
        left: -80%; /* 修正定位 */
    }
    /* 使用 transform 移动 */
    .sidebar {
        left: 0;
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
}

/* ============================================================
   MAIN CHAT AREA
   ============================================================ */
.main-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: var(--bg-base); /* 主背景 */
}

/* HEADER */
.chat-header {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    /* border-bottom: 1px solid var(--border); */ /* 保持极简，可去掉底边框 */
    z-index: 10;
}

.model-select {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 600;
    color: var(--fg1);
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 8px;
    transition: background 0.2s;
}

.model-select:hover {
    background-color: var(--card);
}

.badge {
    font-size: 11px;
    background-color: rgba(79, 120, 255, 0.2);
    color: var(--blue);
    padding: 2px 6px;
    border-radius: 4px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--fg2);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background-color: var(--card);
    color: var(--fg0);
}

.menu-btn {
    display: none;
}
.close-sidebar-btn {
    display: none;
}

@media (max-width: 768px) {
    .menu-btn { display: flex; }
    .close-sidebar-btn { display: flex; }
}

/* MESSAGES CONTAINER */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    position: relative;
}

/* WELCOME SCREEN */
.welcome-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    width: 100%;
    max-width: 720px;
    padding: 20px;
}

.welcome-logo img {
    width: 100px;
    height: auto;
    max-height: 100px;
    margin-bottom: 20px;
    opacity: 0.9;
    filter: drop-shadow(0 0 20px rgba(79, 120, 255, 0.4));
    object-fit: contain;
}

.welcome-screen h1 {
    font-size: 24px;
    margin-bottom: 40px;
    color: var(--fg0);
}

.suggestion-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

@media (max-width: 600px) {
    .suggestion-grid {
        grid-template-columns: 1fr;
    }
}

.suggestion-card {
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.suggestion-card:hover {
    background-color: var(--card2);
    border-color: var(--border-hi);
    transform: translateY(-2px);
}

.suggestion-card .icon {
    font-size: 20px;
}

.suggestion-card .text {
    font-size: 14px;
    color: var(--fg1);
}

/* CHAT LIST */
.chat-list {
    max-width: 768px;
    margin: 0 auto;
    width: 100%;
    padding-bottom: 20px;
    display: none; /* 初始隐藏 */
}

.chat-list.has-messages {
    display: block;
}

.message {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    animation: fadeIn 0.3s ease;
}

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

.message .avatar {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    flex-shrink: 0;
    overflow: hidden;
}

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

.message.user .avatar {
    background-color: var(--fg2);
    color: #000;
}

.message.ai .avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.message-content {
    font-size: 15px;
    line-height: 1.6;
    color: var(--fg0);
    max-width: 80%;
    word-wrap: break-word;
    padding-top: 4px; /* 对齐头像 */
}

.message.user .message-content {
    background-color: var(--card2);
    padding: 10px 16px;
    border-radius: 12px;
    border-top-right-radius: 2px;
}

.message.ai .message-content {
    /* AI 消息一般不需要背景色，直接文字显示，或者给个极淡的背景 */
    padding: 0;
}

/* QUICK QUESTIONS (Chips above input) */
.quick-questions-container {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    padding: 0 20px 12px; /* 增加底部间距 */
    background-color: var(--bg-base);
    display: flex;
    flex-wrap: wrap; /* 允许换行 */
    justify-content: center; /* 居中对齐 */
    gap: 8px;
    /* 移除横向滚动相关样式 */
}
.quick-questions-container.is-hidden {
    display: none;
}

.quick-chip {
    background-color: var(--card);
    border: 1px solid var(--border);
    color: var(--fg1);
    padding: 8px 14px; /* 稍微加大内边距 */
    border-radius: 20px; /* 更圆润 */
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%; /* 防止溢出 */
    white-space: normal; /* 允许内部文字换行（如果真的太长） */
    line-height: 1.4;
    text-align: left;
}

.quick-chip:hover {
    background-color: var(--card2);
    border-color: var(--border-hi);
    color: var(--fg0);
    transform: translateY(-1px); /* 微动效 */
}

.quick-chip .icon {
    font-size: 14px;
}

/* INPUT AREA */
.input-area {
    padding: 20px;
    background-color: var(--bg-base); /* 遮挡底部内容 */
    /* border-top: 1px solid var(--border); */
    position: relative;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.input-wrapper {
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px; /* 圆角大一点 */
    padding: 8px 12px;
    display: flex;
    align-items: flex-end; /* 底部对齐 */
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--border-hi);
    box-shadow: 0 4px 20px rgba(79, 120, 255, 0.15);
}

.attach-btn {
    color: var(--fg2);
    padding-bottom: 10px; /* 对齐底部 */
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--fg0);
    font-family: inherit;
    font-size: 15px;
    resize: none;
    max-height: 200px;
    padding: 10px 0;
    line-height: 1.5;
}

textarea:focus {
    outline: none;
}

.send-btn {
    background-color: var(--fg2); /* 默认禁用色 */
    color: var(--bg-base);
    border: none;
    border-radius: 8px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: not-allowed;
    transition: all 0.2s;
    margin-bottom: 4px;
}

.send-btn:not(:disabled) {
    background-color: var(--blue); /* 激活色 */
    color: #fff;
    cursor: pointer;
}

.send-btn:not(:disabled):hover {
    background-color: var(--indigo);
}

.disclaimer {
    font-size: 11px;
    color: var(--fg2);
    text-align: center;
    margin-top: 8px;
}

/* MARKDOWN STYLES (Simple) */
.message-content p { margin-bottom: 10px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { margin-left: 20px; margin-bottom: 10px; }
.message-content code {
    background-color: rgba(0,0,0,0.3);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}
.message-content pre {
    background-color: #000;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 10px;
}
.message-content pre code {
    background-color: transparent;
    padding: 0;
}

/* LOADING ANIMATION */
.typing-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-right: 4px;
    background-color: var(--fg1);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0; }

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

/* FULL PAGE LOADER */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-base);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.loading-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--card);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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