* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #f59e0b;
    --primary-hover: #d97706;
    --secondary-color: #fbbf24;
    --accent-color: #f97316;
    --bg-dark: #1c1917;
    --bg-card: #292524;
    --bg-input: #44403c;
    --text-primary: #fafaf9;
    --text-secondary: #a8a29e;
    --text-muted: #78716c;
    --border-color: #44403c;
    --user-msg-bg: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
    --ai-msg-bg: #292524;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --radius: 16px;
    --radius-sm: 8px;
}

body {
    font-family: 'Segoe UI', 'Microsoft YaHei', system-ui, -apple-system, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
    max-width: 1400px;
    margin: 0 auto;
}

.sidebar {
    width: 280px;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 16px;
    color: var(--text-secondary);
}

.btn-new-chat {
    background: var(--primary-color);
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: background 0.2s;
}

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

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conversation-list::-webkit-scrollbar {
    width: 4px;
}

.conversation-list::-webkit-scrollbar-track {
    background: transparent;
}

.conversation-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.conversation-item {
    background: transparent;
    border: none;
    width: 100%;
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
    transition: background 0.2s;
    margin-bottom: 4px;
}

.conversation-item:hover {
    background: var(--bg-input);
}

.conversation-item.active {
    background: var(--primary-color);
    color: white;
}

.conversation-item.active .conversation-date {
    color: rgba(255, 255, 255, 0.7);
}

.conversation-title {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-date {
    font-size: 12px;
    color: var(--text-muted);
}

.conversation-item.active .conversation-title {
    color: white;
}

.conversation-item.active .conversation-date {
    color: rgba(255, 255, 255, 0.7);
}

.conversation-item .delete-btn {
    float: right;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.conversation-item:hover .delete-btn {
    opacity: 1;
}

.conversation-item.active .delete-btn {
    color: rgba(255, 255, 255, 0.7);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
}

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

.logo-img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary-color);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.logo-text h1 {
    font-size: 24px;
    font-weight: 700;
    background: linear-gradient(135deg, #f59e0b 0%, #f97316 50%, #fbbf24 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    background: var(--bg-input);
    border: none;
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--primary-color);
    color: white;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar {
    width: 6px;
}

.chat-container::-webkit-scrollbar-track {
    background: transparent;
}

.chat-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
    animation: fadeIn 0.5s ease;
}

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

.welcome-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.welcome-message h2 {
    font-size: 28px;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.welcome-message p {
    color: var(--text-secondary);
    max-width: 500px;
    line-height: 1.6;
    margin-bottom: 30px;
}

.mobile-sidebar-hint {
    display: none;
    font-size: 13px;
    color: var(--primary-color) !important;
    background: rgba(245, 158, 11, 0.12);
    padding: 8px 16px;
    border-radius: 20px;
    margin-bottom: 20px !important;
}

.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

.chip {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 12px 20px;
    border-radius: 50px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
}

.chip:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

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

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

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

.message-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.message.ai .message-avatar {
    background: linear-gradient(135deg, #f59e0b, #f97316);
}

.message.user .message-avatar {
    background: var(--bg-input);
}

.message-content {
    max-width: 70%;
    padding: 16px 20px;
    border-radius: var(--radius);
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.message.ai .message-content {
    background: var(--ai-msg-bg);
    border: 1px solid var(--border-color);
    border-top-left-radius: 4px;
}

.message.user .message-content {
    background: var(--user-msg-bg);
    border-top-right-radius: 4px;
}

.message-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 8px 0;
}

.message-content pre code {
    background: transparent;
    padding: 0;
}

.message-content ul, .message-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-content li {
    margin: 4px 0;
}

.typing-indicator {
    display: flex;
    gap: 6px;
    padding: 16px 20px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

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

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

.input-area {
    padding: 16px 24px 12px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    display: flex;
    gap: 12px;
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 4px;
    transition: all 0.2s;
}

.input-wrapper:focus-within {
    box-shadow: 0 0 0 2px var(--primary-color);
}

#userInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 12px 16px;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 150px;
    line-height: 1.5;
}

#userInput:focus {
    outline: none;
}

#userInput::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 48px;
    height: 48px;
    background: var(--primary-color);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    transform: none;
}

.api-status {
    text-align: center;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.api-status.error {
    color: #ef4444;
}

.api-status.success {
    color: #22c55e;
}

.settings-fab {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 56px;
    height: 56px;
    background: var(--primary-color);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: all 0.3s;
    z-index: 100;
}

.settings-fab:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
}

.settings-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 380px;
    height: 100vh;
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
    transition: right 0.3s ease;
    z-index: 200;
    display: flex;
    flex-direction: column;
}

.settings-panel.open {
    right: 0;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.settings-header h3 {
    font-size: 18px;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
}

.btn-close:hover {
    color: var(--text-primary);
}

.settings-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.setting-group {
    margin-bottom: 24px;
}

.setting-group label {
    display: block;
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 8px;
}

.setting-group input[type="password"],
.setting-group input[type="text"],
.setting-group select {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
}

.setting-group input:focus,
.setting-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.setting-group input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    -webkit-appearance: none;
    appearance: none;
}

.setting-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
}

.btn-save {
    width: 100%;
    background: var(--primary-color);
    border: none;
    color: white;
    padding: 14px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-save:hover {
    background: var(--primary-hover);
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    z-index: 150;
}

.overlay.show {
    opacity: 1;
    visibility: visible;
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        height: 100dvh;
    }

    .main-content {
        height: auto !important;
        flex: 1;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100vh;
        z-index: 300;
        transition: left 0.3s ease;
        box-shadow: none;
    }

    .sidebar.open {
        left: 0;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 250;
    }

    .sidebar-overlay.show {
        display: block;
    }

    .header {
        padding: 8px 12px;
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
        background: var(--bg-card);
        border-bottom: 1px solid var(--border-color);
    }

    .chat-container {
        padding-top: 52px;
    }

    .logo {
        gap: 8px;
        flex-shrink: 1;
        min-width: 0;
    }

    .logo-img {
        width: 30px;
        height: 30px;
        flex-shrink: 0;
    }

    .logo-text h1 {
        font-size: 15px;
        white-space: nowrap;
    }

    .subtitle {
        font-size: 10px;
        display: block !important;
        max-width: none;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: var(--primary-color);
        font-weight: bold;
    }

    .header-actions {
        gap: 2px;
        flex-shrink: 0;
    }

    /* 汉堡菜单按钮更醒目 */
    #toggleSidebar {
        background: var(--primary-color) !important;
        color: white !important;
        width: 38px !important;
        height: 38px !important;
        border-radius: 8px !important;
    }

    .btn-icon {
        width: 36px;
        height: 36px;
        font-size: 16px;
        border-radius: 6px;
    }

    .mobile-sidebar-hint {
        display: block;
    }

    .chat-container {
        padding: 12px;
    }

    .message-content {
        max-width: 82%;
        padding: 12px 14px;
        font-size: 14px;
    }

    .message {
        gap: 8px;
        margin-bottom: 16px;
    }

    .message-avatar {
        width: 34px;
        height: 34px;
        font-size: 16px;
    }

    .welcome-message {
        padding: 30px 12px;
    }

    .welcome-icon {
        font-size: 42px;
    }

    .welcome-message h2 {
        font-size: 20px;
    }

    .welcome-message p {
        font-size: 14px;
        margin-bottom: 20px;
    }

    .suggestion-chips {
        gap: 6px;
    }

    .chip {
        padding: 8px 14px;
        font-size: 12px;
    }

    .input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        flex-shrink: 0;
    }

    .input-wrapper {
        gap: 8px;
        padding: 2px;
    }

    #userInput {
        padding: 10px 12px;
        font-size: 14px;
    }

    .send-btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    .api-status {
        font-size: 11px;
        margin-top: 4px;
    }

    .settings-panel {
        width: 100%;
        right: -100%;
    }

    .settings-fab {
        bottom: auto;
        top: 52px;
        right: 12px;
        width: 44px;
        height: 44px;
        font-size: 20px;
    }

    .payment-content {
        width: 95%;
        max-height: 90vh;
        overflow-y: auto;
    }

    .payment-header {
        padding: 16px 20px;
    }

    .payment-header h2 {
        font-size: 18px;
    }

    .payment-body {
        padding: 16px;
    }

    .payment-desc {
        font-size: 14px;
    }

    .payment-qr {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    .qr-option {
        width: 120px;
        padding: 10px;
    }

    .qr-option img {
        height: 120px;
    }

    .payment-notes {
        padding: 12px;
    }

    .payment-notes p {
        font-size: 12px;
    }

    .contact-info {
        font-size: 13px !important;
    }

    .payment-footer {
        padding: 12px 16px;
    }

    .payment-footer .btn-primary {
        padding: 12px;
        font-size: 14px;
    }
}

.payment-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    animation: fadeIn 0.3s ease;
}

.payment-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    width: 90%;
    max-width: 420px;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

.payment-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
}

.payment-header h2 {
    color: white;
    margin: 0;
    font-size: 20px;
}

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.payment-body {
    padding: 24px;
}

.payment-desc {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 16px;
    font-size: 15px;
}

.payment-options-hint {
    list-style: none;
    padding: 0;
    margin: 0 0 20px 0;
}

.payment-options-hint li {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 10px;
    font-size: 14px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.payment-qr {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 24px;
}

.qr-option {
    width: 150px;
    padding: 12px;
    border-radius: var(--radius);
    border: 2px solid var(--border-color);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.qr-option:hover {
    border-color: var(--primary-color);
}

.qr-option.active {
    border-color: var(--primary-color);
    background: rgba(245, 158, 11, 0.1);
}

.qr-option img {
    width: 100%;
    height: 150px;
    object-fit: contain;
    border-radius: 8px;
    margin-bottom: 8px;
}

.qr-option span {
    font-size: 13px;
    color: var(--text-primary);
}

.payment-notes {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 16px;
}

.payment-notes p {
    margin: 8px 0;
    color: var(--text-secondary);
    font-size: 14px;
}

.contact-info {
    color: var(--primary-color) !important;
    font-weight: bold;
    font-size: 15px !important;
}

.payment-footer {
    padding: 16px 24px;
    background: var(--bg-input);
}

.payment-footer .btn-primary {
    width: 100%;
    padding: 14px;
    font-size: 16px;
}

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