﻿/* ===== 全局 (完全保留原始样式) ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #f3f4f6;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

.chat-container {
    max-width: 820px;
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    background: #ffffff;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== 头部 (flex 布局：左中右) ===== */
.chat-header {
    padding: 14px 20px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    background: #fff;
}

    .chat-header .logo {
        flex-shrink: 0;
        display: flex;
        align-items: center;
        gap: 6px;
        font-size: 18px;
        font-weight: 700;
        color: #0a0a0a;
    }

        .chat-header .logo a {
            display: flex;
            align-items: center;
            text-decoration: none;
        }

        .chat-header .logo img {
            height: 28px;
            width: auto;
            display: block;
        }

    .chat-header .session-name-display {
        flex: 1;
        text-align: left;
        font-size: 15px;
        font-weight: 500;
        color: #1e293b;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        padding: 0 8px;
        min-width: 0;
    }

    .chat-header .header-actions {
        flex-shrink: 0;
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .chat-header .sidebar-toggle-btn {
        background: none;
        border: none;
        color: #64748b;
        cursor: pointer;
        font-size: 18px;
        padding: 6px 8px;
        border-radius: 6px;
        transition: background 0.2s, color 0.2s;
        display: flex;
        align-items: center;
        gap: 4px;
        font-weight: 500;
        min-height: 36px;
    }

        .chat-header .sidebar-toggle-btn:hover {
            background: #f1f5f9;
            color: #0f172a;
        }

    .chat-header .new-chat-btn {
        background: none;
        border: none;
        color: #64748b;
        cursor: pointer;
        font-size: 20px;
        padding: 6px 10px;
        border-radius: 6px;
        transition: background 0.2s, color 0.2s;
        min-height: 36px;
        font-weight: 500;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1;
    }

        .chat-header .new-chat-btn:hover {
            background: #f1f5f9;
            color: #2563eb;
        }

        .chat-header .new-chat-btn:active {
            transform: scale(0.92);
        }

/* ===== 消息列表 ===== */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

    .messages::-webkit-scrollbar {
        width: 4px;
    }

    .messages::-webkit-scrollbar-track {
        background: transparent;
    }

    .messages::-webkit-scrollbar-thumb {
        background: #d1d5db;
        border-radius: 10px;
    }

.message {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-items: flex-end;
}

.message.assistant {
    align-items: flex-start;
}

.message .avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: #4b5563;
    user-select: none;
}

.message.user .avatar {
    background: #2563eb;
    color: #fff;
}

.message.assistant .avatar {
    background: #e5e7eb;
    color: #4b5563;
}

.message .bubble {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    padding: 10px 14px;
    border-radius: 14px;
    line-height: 1.6;
    word-break: break-word;
    font-size: 15px;
    color: #1e293b;
    background: #f3f4f6;
    border-bottom-left-radius: 4px;
}

.message.user .bubble {
    background: #2563eb;
    color: #fff;
    border-bottom-left-radius: 14px;
    border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
    background: #f8fafc;
    border: 1px solid #f0f2f5;
    border-bottom-left-radius: 4px;
}

.message .bubble .time {
    align-self: flex-end;
    font-size: 10px;
    color: #9ca3af;
    margin-top: 4px;
    display: block;
}

.message.user .bubble .time {
    color: rgba(255, 255, 255, 0.7);
}

.message.assistant .bubble .markdown-content {
    width: 100%;
    font-size: 15px;
    line-height: 1.7;
    text-align: left;
}

    .message.assistant .bubble .markdown-content h1,
    .message.assistant .bubble .markdown-content h2,
    .message.assistant .bubble .markdown-content h3 {
        margin: 0.8em 0 0.3em;
        font-weight: 600;
    }

    .message.assistant .bubble .markdown-content h1 {
        font-size: 1.4em;
        border-bottom: 1px solid #e5e7eb;
        padding-bottom: 0.2em;
    }

    .message.assistant .bubble .markdown-content h2 {
        font-size: 1.2em;
    }

    .message.assistant .bubble .markdown-content h3 {
        font-size: 1.05em;
    }

    .message.assistant .bubble .markdown-content p {
        margin: 0.5em 0;
    }

    .message.assistant .bubble .markdown-content ul,
    .message.assistant .bubble .markdown-content ol {
        padding-left: 1.6em;
        margin: 0.4em 0;
    }

    .message.assistant .bubble .markdown-content blockquote {
        border-left: 4px solid #3b82f6;
        padding: 0.4em 1em;
        background: #f1f5f9;
        border-radius: 0 6px 6px 0;
        margin: 0.6em 0;
    }

    .message.assistant .bubble .markdown-content table {
        border-collapse: collapse;
        width: 100%;
        font-size: 0.9em;
        margin: 0.8em 0;
    }

    .message.assistant .bubble .markdown-content th,
    .message.assistant .bubble .markdown-content td {
        border: 1px solid #d1d5db;
        padding: 6px 10px;
        text-align: left;
    }

    .message.assistant .bubble .markdown-content th {
        background: #f1f5f9;
        font-weight: 600;
    }

    .message.assistant .bubble .markdown-content tr:nth-child(even) {
        background: #fafbfc;
    }

    .message.assistant .bubble .markdown-content code {
        background: #f1f5f9;
        padding: 0.15em 0.4em;
        border-radius: 4px;
        font-size: 0.9em;
    }

    .message.assistant .bubble .markdown-content pre {
        background: #1e293b;
        color: #e2e8f0;
        padding: 1em;
        border-radius: 8px;
        overflow-x: auto;
        margin: 0.8em 0;
    }

        .message.assistant .bubble .markdown-content pre code {
            background: transparent;
            color: inherit;
            padding: 0;
        }

    .message.assistant .bubble .markdown-content hr {
        border: none;
        border-top: 2px dashed #d1d5db;
        margin: 1.5em 0;
    }

.typing-indicator {
    display: flex;
    gap: 6px;
    padding: 6px 0;
}

    .typing-indicator span {
        display: inline-block;
        width: 8px;
        height: 8px;
        background: #9ca3af;
        border-radius: 50%;
        animation: typing 1.4s infinite both;
    }

        .typing-indicator span:nth-child(2) {
            animation-delay: 0.2s;
        }

        .typing-indicator span:nth-child(3) {
            animation-delay: 0.4s;
        }

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.4;
    }

    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

.input-area {
    padding: 12px 16px 20px;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
    display: flex;
    gap: 10px;
    background: #ffffff;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}

    .input-area textarea {
        flex: 1;
        resize: none;
        padding: 10px 14px;
        border: 1px solid #e2e8f0;
        border-radius: 20px;
        font-family: inherit;
        font-size: 15px;
        outline: none;
        transition: border-color 0.2s;
        min-height: 44px;
        max-height: 120px;
        line-height: 1.5;
        background: #fafbfc;
    }

        .input-area textarea:focus {
            border-color: #3b82f6;
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
        }

    .input-area .send-btn {
        align-self: flex-end;
        padding: 0 20px;
        background: #2563eb;
        color: #fff;
        border: none;
        border-radius: 40px;
        font-size: 15px;
        font-weight: 600;
        cursor: pointer;
        transition: background 0.2s;
        white-space: nowrap;
        height: 44px;
        min-width: 60px;
    }

        .input-area .send-btn:hover {
            background: #1d4ed8;
        }

        .input-area .send-btn:active {
            transform: scale(0.96);
        }

        .input-area .send-btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
        }

@media (max-width: 600px) {
    .chat-container {
        border-radius: 0;
        height: 100vh;
        max-height: 100vh;
    }

    .chat-header {
        padding: 12px 16px;
        gap: 6px;
    }

        .chat-header .logo {
            font-size: 16px;
        }

            .chat-header .logo img {
                height: 24px;
            }

        .chat-header .session-name-display {
            font-size: 14px;
            padding: 0 4px;
        }

        .chat-header .sidebar-toggle-btn {
            font-size: 16px;
            padding: 4px 6px;
            min-height: 32px;
        }

        .chat-header .new-chat-btn {
            font-size: 14px;
            padding: 4px 8px;
            min-height: 32px;
        }

    .messages {
        padding: 12px 12px 8px;
        gap: 12px;
    }

    .message .avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .message .bubble {
        font-size: 14px;
        padding: 8px 12px;
        border-radius: 12px;
    }

    .message.assistant .bubble .markdown-content {
        font-size: 14px;
    }

        .message.assistant .bubble .markdown-content table {
            font-size: 12px;
        }

        .message.assistant .bubble .markdown-content th,
        .message.assistant .bubble .markdown-content td {
            padding: 4px 6px;
        }

    .input-area {
        padding: 10px 12px 16px;
        gap: 8px;
    }

        .input-area textarea {
            font-size: 14px;
            min-height: 40px;
            padding: 8px 12px;
        }

        .input-area .send-btn {
            height: 40px;
            font-size: 14px;
            padding: 0 16px;
            min-width: 50px;
        }

    .typing-indicator span {
        width: 6px;
        height: 6px;
    }

    /* 移动端侧边栏标题适配 — 与主页标题栏一致 */
    .sidebar-header {
        padding: 12px 16px !important;
    }

        .sidebar-header h3 {
            font-size: 16px !important;
        }

            .sidebar-header h3 .sidebar-icon {
                font-size: 16px !important;
                /* 与主页 sidebar-toggle-btn 移动端一致 */
            }

        .sidebar-header .close-btn {
            font-size: 16px !important;
            padding: 4px 6px !important;
            min-height: 32px !important;
        }
}

@media (max-width: 400px) {
    .chat-header .session-name-display {
        font-size: 14px;
    }

    .chat-header .logo {
        font-size: 14px;
    }

        .chat-header .logo img {
            height: 20px;
        }
}

@media (min-width: 601px) {
    body {
        padding: 20px;
        background: #f3f4f6;
    }

    .chat-container {
        border-radius: 24px;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
        height: 90vh;
        max-height: 760px;
    }
}

/* ===== 侧边栏样式 ===== */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    z-index: 99;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 360px;
    max-width: 88vw;
    height: 100%;
    background: #ffffff;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.08);
    border-right: 1px solid #f0f0f0;
}

    .sidebar.open {
        transform: translateX(0);
    }

/* ===== 侧边栏头部 — 与主页标题栏样式完全统一 ===== */
.sidebar-header {
    padding: 14px 20px;
    /* 与 .chat-header 一致 */
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background: #ffffff;
}

    /* 标题文字：与 .chat-header .logo 完全一致 (18px/700/#0a0a0a) */
    .sidebar-header h3 {
        font-size: 18px;
        font-weight: 700;
        color: #0a0a0a;
        display: flex;
        align-items: center;
        gap: 6px;
        margin: 0;
        padding: 0;
    }

        /* 💬 图标大小：与主页 sidebar-toggle-btn 中的 💬 完全一致 (18px) */
        .sidebar-header h3 .sidebar-icon {
            font-size: 18px;
            line-height: 1;
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }

    /* 关闭按钮：与主页 .sidebar-toggle-btn / .new-chat-btn 风格一致 */
    .sidebar-header .close-btn {
        background: none;
        border: none;
        color: #64748b;
        cursor: pointer;
        font-size: 18px;
        padding: 6px 8px;
        border-radius: 6px;
        transition: background 0.2s, color 0.2s;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 500;
        min-height: 36px;
        line-height: 1;
    }

        .sidebar-header .close-btn:hover {
            background: #f1f5f9;
            color: #0f172a;
        }

        .sidebar-header .close-btn:active {
            transform: scale(0.92);
        }

/* ---- 侧边栏列表 ---- */
.sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

    .sidebar-list::-webkit-scrollbar {
        width: 4px;
    }

    .sidebar-list::-webkit-scrollbar-track {
        background: transparent;
    }

    .sidebar-list::-webkit-scrollbar-thumb {
        background: #d1d5db;
        border-radius: 10px;
    }

/* ---- 会话项 ---- */
.session-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
    background: transparent;
    min-height: 44px;
}

    .session-item:hover {
        background: #f1f5f9;
    }

    .session-item.active {
        background: #eff6ff;
    }

        .session-item.active .session-name {
            color: #1d4ed8;
            font-weight: 600;
        }

    .session-item .session-name {
        flex: 1;
        font-size: 14px;
        color: #1e293b;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        min-width: 0;
    }

    .session-item .star-btn {
        flex-shrink: 0;
        background: none;
        border: none;
        font-size: 17px;
        cursor: pointer;
        padding: 2px 4px;
        border-radius: 6px;
        transition: background 0.15s, transform 0.15s;
        line-height: 1;
        color: #cbd5e1;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 28px;
        height: 28px;
    }

        .session-item .star-btn:hover {
            background: #e2e8f0;
            transform: scale(1.12);
        }

        .session-item .star-btn.starred {
            color: #f59e0b;
        }

            .session-item .star-btn.starred:hover {
                color: #d97706;
            }

    .session-item .session-msg-count {
        font-size: 12px;
        color: #94a3b8;
        background: #f1f5f9;
        padding: 1px 8px;
        border-radius: 12px;
        flex-shrink: 0;
    }

    .session-item .session-actions {
        display: flex;
        gap: 2px;
        flex-shrink: 0;
        opacity: 1;
    }

        .session-item .session-actions button {
            background: none;
            border: none;
            padding: 4px 5px;
            border-radius: 6px;
            cursor: pointer;
            font-size: 14px;
            color: #94a3b8;
            transition: background 0.15s, color 0.15s;
            line-height: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            width: 28px;
            height: 28px;
        }

            .session-item .session-actions button:hover {
                background: #e2e8f0;
                color: #0f172a;
            }

        .session-item .session-actions .rename-btn:hover {
            color: #2563eb;
        }

        .session-item .session-actions .delete-btn:hover {
            color: #ef4444;
            background: #fef2f2;
        }

/* ---- 空状态 ---- */
.empty-sessions {
    text-align: center;
    padding: 40px 20px;
    color: #94a3b8;
    font-size: 14px;
}

    .empty-sessions .icon-big {
        font-size: 40px;
        display: block;
        margin-bottom: 12px;
    }

/* ---- 侧边栏底部 ---- */
.sidebar-footer {
    padding: 14px 16px 20px;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
    background: #fafbfc;
}

    .sidebar-footer .new-session-btn {
        width: 100%;
        padding: 10px 0;
        background: #2563eb;
        color: #fff;
        border: none;
        border-radius: 12px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        transition: background 0.2s;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
    }

        .sidebar-footer .new-session-btn:hover {
            background: #1d4ed8;
        }

        .sidebar-footer .new-session-btn:active {
            transform: scale(0.97);
        }

/* ===== 重命名弹窗 ===== */
.rename-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

    .rename-modal-overlay.active {
        opacity: 1;
        visibility: visible;
    }

.rename-modal {
    background: #fff;
    border-radius: 16px;
    padding: 24px 28px 28px;
    width: 360px;
    max-width: 90vw;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.2);
    transform: scale(0.95) translateY(10px);
    transition: transform 0.25s ease;
}

.rename-modal-overlay.active .rename-modal {
    transform: scale(1) translateY(0);
}

.rename-modal h4 {
    font-size: 17px;
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 6px;
}

.rename-modal p {
    font-size: 14px;
    color: #64748b;
    margin-bottom: 16px;
}

.rename-modal input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

    .rename-modal input:focus {
        border-color: #3b82f6;
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
    }

.rename-modal .modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
    justify-content: flex-end;
}

    .rename-modal .modal-actions button {
        padding: 8px 20px;
        border: none;
        border-radius: 10px;
        font-size: 14px;
        font-weight: 500;
        cursor: pointer;
        transition: background 0.15s;
    }

    .rename-modal .modal-actions .cancel-btn {
        background: #f1f5f9;
        color: #475569;
    }

        .rename-modal .modal-actions .cancel-btn:hover {
            background: #e2e8f0;
        }

    .rename-modal .modal-actions .confirm-btn {
        background: #2563eb;
        color: #fff;
    }

        .rename-modal .modal-actions .confirm-btn:hover {
            background: #1d4ed8;
        }

        .rename-modal .modal-actions .confirm-btn:active {
            transform: scale(0.97);
        }

@media (min-width: 601px) {
    .sidebar {
        border-radius: 0 16px 16px 0;
    }
}

/* ---- 移动端适配 ---- */
@media (max-width: 480px) {
    .session-item .star-btn {
        font-size: 16px;
        width: 28px;
        height: 28px;
    }

    .session-item .session-actions button {
        font-size: 14px;
        width: 24px;
        height: 24px;
        padding: 2px 3px;
    }

    .session-item .session-msg-count {
        font-size: 12px;
        padding: 0 6px;
    }

    .session-item {
        padding: 6px 8px;
        min-height: 38px;
        gap: 4px;
    }

        .session-item .session-name {
            font-size: 14px;
        }
}

@media (max-width: 380px) {
    .session-item .star-btn {
        font-size: 16px;
        width: 24px;
        height: 24px;
    }

    .session-item .session-actions button {
        font-size: 14px;
        width: 24px;
        height: 24px;
    }

    .session-item .session-name {
        font-size: 14px;
    }
}

/* ===== toast 提示 ===== */
.toast-tip {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #fff;
    padding: 10px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    z-index: 300;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    transform: translateX(-50%) translateY(10px);
    pointer-events: none;
    white-space: nowrap;
}

    .toast-tip.show {
        opacity: 1;
        visibility: visible;
        transform: translateX(-50%) translateY(0);
    }

@media (max-width: 600px) {
    .toast-tip {
        bottom: 80px;
        font-size: 14px;
        padding: 8px 18px;
        white-space: normal;
        max-width: 85vw;
        text-align: center;
    }
}

.plus-icon {
    display: inline-block;
    width: 24px;
    height: 24px;
    background-color: transparent;
    /* 核心：两个线性渐变分别绘制横杠和竖杠 */
    background-image: linear-gradient(to top, currentColor, currentColor), linear-gradient(to top, currentColor, currentColor);
    /* 分别控制横杠和竖杠的尺寸 */
    background-size: 60% 2px, 2px 60%;
    background-position: center center;
    background-repeat: no-repeat;
}

