:root {
    --bg: #f8f9fa;
    --bg-gradient: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    --sidebar-bg: rgba(255, 255, 255, 0.85);
    --container-bg: rgba(255, 255, 255, 0.85);
    --text: #343a40;
    --text-light: #6c757d;
    --border: #e3e6ea;
    --bubble-user: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
    --bubble-assistant: rgba(255, 255, 255, 0.95);
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --radius: 18px;
    --shadow: 0 8px 32px rgba(59, 130, 246, 0.12);
    --history-bg: #e9ecef;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Microsoft YaHei", "微软雅黑", "Segoe UI", "PingFang SC", sans-serif;
    background: var(--bg-gradient);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

.app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.btn-primary {
    padding: 10px 22px;
    border: 1px solid #d4d8dd;
    border-radius: 14px;
    background: #f8f9fa;
    color: #343a40;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: background 0.2s, border-color 0.2s, transform 0.15s, box-shadow 0.15s;
}

.btn-primary:hover {
    background: #e9ecef;
    border-color: #c8cdd2;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.5);
    flex-shrink: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.5px;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-light);
}

.model-selector select {
    padding: 8px 12px;
    border: 1px solid #d4d8dd;
    border-radius: 10px;
    background: #f8f9fa;
    color: #343a40;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.model-selector select:focus {
    border-color: rgba(59, 130, 246, 0.5);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 28px 7%;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.message {
    display: flex;
    gap: 14px;
    max-width: 82%;
    animation: fadeInUp 0.35s ease;
}

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

.message.assistant {
    align-self: flex-start;
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.message.user .avatar {
    background: #dbeafe;
    color: #343a40;
}

.message.assistant .avatar {
    background: #e9ecef;
    color: #343a40;
}

.bubble {
    padding: 16px 20px;
    border-radius: var(--radius);
    line-height: 1.7;
    font-size: 15px;
    word-break: break-word;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.message.user .bubble {
    background: #e9ecef;
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-right-radius: 4px;
}

.message.user .bubble p {
    color: var(--text);
}

.message.user .bubble :not(pre) > code {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text);
}

.message.assistant .bubble {
    background: var(--bubble-assistant);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

/* Markdown 样式 */
.bubble p {
    margin: 0 0 10px;
    color: inherit;
}

.bubble p:last-child {
    margin-bottom: 0;
}

.bubble h1, .bubble h2, .bubble h3, .bubble h4, .bubble h5, .bubble h6 {
    margin: 18px 0 10px;
    font-weight: 700;
    color: var(--text);
}

.bubble h1 { font-size: 1.5em; }
.bubble h2 { font-size: 1.3em; }
.bubble h3 { font-size: 1.15em; }

.bubble ul, .bubble ol {
    margin: 10px 0;
    padding-left: 22px;
}

.bubble li {
    margin-bottom: 4px;
}

.bubble pre {
    background: #0f172a;
    border-radius: 12px;
    padding: 14px;
    overflow-x: auto;
    margin: 12px 0;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05);
}

.bubble code {
    font-family: "Microsoft YaHei", "微软雅黑", "SFMono-Regular", Consolas, monospace;
    font-size: 13px;
}

.bubble pre code {
    background: transparent;
    padding: 0;
}

.bubble :not(pre) > code {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent);
    padding: 3px 7px;
    border-radius: 6px;
    font-weight: 500;
}

.bubble blockquote {
    border-left: 4px solid var(--accent);
    margin: 12px 0;
    padding: 8px 16px;
    color: var(--text-light);
    background: rgba(59, 130, 246, 0.05);
    border-radius: 0 10px 10px 0;
}

.bubble table {
    border-collapse: collapse;
    margin: 12px 0;
    width: 100%;
    border-radius: 10px;
    overflow: hidden;
}

.bubble th, .bubble td {
    border: 1px solid var(--border);
    padding: 8px 12px;
}

.bubble th {
    background: rgba(59, 130, 246, 0.08);
    font-weight: 600;
}

.bubble a {
    color: var(--accent);
    text-decoration: none;
}

.bubble a:hover {
    text-decoration: underline;
}

.input-area {
    display: flex;
    gap: 12px;
    padding: 18px 6%;
    border-top: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.6);
    align-items: flex-end;
}

#input {
    flex: 1;
    resize: none;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 14px 20px;
    font-size: 15px;
    font-family: "Microsoft YaHei", "微软雅黑", "Segoe UI", "PingFang SC", sans-serif;
    background: rgba(255, 255, 255, 0.9);
    color: var(--text);
    outline: none;
    max-height: 160px;
    min-height: 52px;
    line-height: 1.5;
    box-shadow: inset 0 2px 6px rgba(59, 130, 246, 0.06);
    transition: border-color 0.2s, box-shadow 0.2s;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#input::-webkit-scrollbar {
    display: none;
}

#input::placeholder {
    color: #adb5bd;
}

#input:focus {
    border-color: rgba(59, 130, 246, 0.5);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12), inset 0 2px 6px rgba(59, 130, 246, 0.06);
}

.btn-send {
    width: 52px;
    height: 52px;
    border: 1px solid #d4d8dd;
    border-radius: 50%;
    background: #f8f9fa;
    color: #343a40;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: background 0.2s, transform 0.15s, box-shadow 0.15s;
    flex-shrink: 0;
}

.btn-send:hover {
    background: #e9ecef;
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.btn-send:disabled {
    background: #e9ecef;
    border-color: #e3e6ea;
    color: #adb5bd;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.loading {
    display: inline-flex;
    gap: 5px;
    align-items: center;
    height: 20px;
}

.loading span {
    width: 7px;
    height: 7px;
    background: #adb5bd;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading span:nth-child(1) { animation-delay: -0.32s; }
.loading span:nth-child(2) { animation-delay: -0.16s; }

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

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

/* 滚动条美化 */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.25);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(59, 130, 246, 0.4);
}

/* 移动端适配 */
@media (max-width: 768px) {
    .chat-header {
        padding: 12px 16px;
    }

    .messages,
    .input-area {
        padding-left: 16px;
        padding-right: 16px;
    }

    .message {
        max-width: 92%;
    }
}
