* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #667eea;
    --secondary: #764ba2;
    --bg-light: #ffffff;
    --bg-dark: #121212;
    --text-light: #333333;
    --text-dark: #f0f0f0;
    --border-light: #e0e0e0;
    --border-dark: #3a3a3a;
    --user-bubble: #e3f2fd;
    --ai-bubble: #f5f5f5;
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-dark: 0 4px 12px rgba(0,0,0,0.25);
    --success: #4caf50;
    --error: #f44336;
    --warning: #ff9800;
}

[data-theme="dark"] {
    --bg: var(--bg-dark);
    --text: var(--text-dark);
    --border: var(--border-dark);
    --shadow: var(--shadow-dark);
    --user-bubble: #1e293b;
    --ai-bubble: #252525;
}

[data-theme="light"] {
    --bg: var(--bg-light);
    --text: var(--text-light);
    --border: var(--border-light);
    --shadow: var(--shadow);
    --user-bubble: var(--user-bubble);
    --ai-bubble: var(--ai-bubble);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: var(--text);
    min-height: 100vh;
    transition: background 0.3s ease;
}

.container {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
    padding: 20px;
    max-width: 100%;
    height: 100vh;
}

header {
    grid-column: 1 / -1;
    background: var(--bg);
    padding: 20px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 15px;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
}

.logo {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: white;
    padding: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: -0.5px;
}

.api-key-section {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.api-key-section input {
    flex: 1;
    min-width: 250px;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 1rem;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.3s;
}

.api-key-section input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.api-key-section button {
    padding: 14px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.api-key-section button:hover {
    background: #5a6fd8;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.controls {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.model-selector label {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
}

.model-selector select {
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    min-width: 160px;
}

.theme-btn {
    padding: 10px 18px;
    background: var(--bg);
    color: var(--text);
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s;
}

.theme-btn:hover {
    border-color: var(--primary);
    background: rgba(102, 126, 234, 0.1);
}

.chat-container {
    background: var(--bg);
    border-radius: 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 220px);
    overflow: hidden;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.message {
    max-width: 85%;
    padding: 16px 20px;
    border-radius: 20px;
    line-height: 1.6;
    animation: fadeIn 0.3s ease-out;
    word-wrap: break-word;
    position: relative;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    background: var(--user-bubble);
    margin-left: auto;
    border-bottom-right-radius: 6px;
    border-top-right-radius: 20px;
}

.message.assistant {
    background: var(--ai-bubble);
    margin-right: auto;
    border-bottom-left-radius: 6px;
    border-top-left-radius: 20px;
}

.input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    background: var(--bg);
}

.input-area textarea {
    flex: 1;
    padding: 16px;
    border: 2px solid var(--border);
    border-radius: 16px;
    resize: none;
    font-family: inherit;
    font-size: 1.05rem;
    background: var(--bg);
    color: var(--text);
    min-height: 60px;
    max-height: 200px;
    transition: border-color 0.3s;
    line-height: 1.5;
}

.input-area textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.input-area button {
    width: 56px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 16px;
    font-size: 1.4rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.input-area button:hover {
    background: #5a6fd8;
    transform: scale(1.05);
}

.input-area button:active {
    transform: scale(0.95);
}

.history-panel {
    background: var(--bg);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 220px);
}

.history-panel h3 {
    font-size: 1.4rem;
    margin-bottom: 16px;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-right: 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.history-item {
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg);
    color: var(--text);
    text-align: left;
}

.history-item:hover {
    border-color: var(--primary);
    transform: translateX(4px);
    background: rgba(102, 126, 234, 0.08);
}

.history-item.active {
    background: rgba(102, 126, 234, 0.15);
    border-color: var(--primary);
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.2);
}

.history-item .title {
    font-weight: 600;
    margin-bottom: 4px;
    display: block;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item .preview {
    font-size: 0.85rem;
    color: #aaa;
    margin-top: 2px;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.clear-btn {
    padding: 12px;
    background: var(--error);
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 12px;
    transition: background 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.clear-btn:hover {
    background: #d32f2f;
}

.loading {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--primary);
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
    margin: 8px auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error-banner {
    background: rgba(244, 67, 54, 0.15);
    color: #c62828;
    padding: 14px 20px;
    border-radius: 12px;
    margin: 12px 0;
    border-left: 4px solid var(--error);
    font-weight: 500;
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background: #888;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: #555;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: #777;
}

/* 响应式设计 - 标准媒体查询 */
@media (max-width: 1024px) {
    .container {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        padding: 15px;
        gap: 15px;
    }
    
    .chat-container {
        height: 45vh;
        order: 2;
    }
    
    .history-panel {
        height: auto;
        max-height: 45vh;
        order: 3;
    }
    
    header {
        padding: 16px;
        margin-bottom: 10px;
    }
    
    .logo {
        width: 40px;
        height: 40px;
    }
    
    header h1 {
        font-size: 1.5rem;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
        gap: 10px;
    }
    
    header {
        padding: 14px;
        margin-bottom: 8px;
    }
    
    .logo {
        width: 36px;
        height: 36px;
    }
    
    header h1 {
        font-size: 1.35rem;
    }
    
    .api-key-section {
        flex-direction: column;
        gap: 10px;
    }
    
    .api-key-section input {
        min-width: auto;
        width: 100%;
    }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .model-selector {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .chat-container, .history-panel {
        height: auto;
        max-height: 40vh;
        border-radius: 14px;
    }
    
    .chat-history, .input-area {
        padding: 16px;
    }
    
    .input-area textarea {
        padding: 14px;
        min-height: 50px;
        font-size: 1rem;
    }
    
    .input-area button {
        width: 50px;
        font-size: 1.3rem;
    }
    
    .history-panel h3 {
        font-size: 1.25rem;
        margin-bottom: 12px;
    }
    
    .history-item {
        padding: 12px 14px;
    }
    
    .clear-btn {
        padding: 10px;
        font-size: 0.95rem;
    }
}

@media (max-width: 480px) {
    .logo-section {
        gap: 12px;
    }
    
    .logo {
        width: 32px;
        height: 32px;
    }
    
    header h1 {
        font-size: 1.2rem;
    }
    
    .api-key-section button {
        padding: 12px 18px;
        font-size: 0.9rem;
    }
    
    .theme-btn {
        padding: 8px 14px;
        font-size: 0.9rem;
    }
    
    .message {
        max-width: 92%;
        padding: 14px 16px;
        font-size: 0.95rem;
    }
    
    .input-area {
        padding: 12px;
        gap: 8px;
    }
    
    .input-area textarea {
        padding: 12px;
        min-height: 48px;
    }
    
    .input-area button {
        width: 48px;
        font-size: 1.25rem;
    }
}