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

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --sidebar-width: 320px;
    --navbar-height: 64px;
    --gradient-primary: linear-gradient(135deg, #4f46e5, #7c3aed);
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --border-color: #334155;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.4);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: all 0.3s ease;
}

/* Navbar */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--navbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
    backdrop-filter: blur(10px);
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.4rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-brand i {
    font-size: 1.8rem;
    -webkit-text-fill-color: var(--primary-color);
}

.nav-links {
    display: flex;
    gap: 24px;
    align-items: center;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    transition: all 0.3s ease;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--primary-color);
    background: rgba(79, 70, 229, 0.1);
}

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

.theme-toggle,
.hamburger {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.3s ease;
}

.theme-toggle:hover,
.hamburger:hover {
    background: var(--bg-tertiary);
}

.hamburger {
    display: none;
}

/* Main Container */
.main-container {
    display: flex;
    margin-top: var(--navbar-height);
    height: calc(100vh - var(--navbar-height));
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

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

.sidebar-header h3 {
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-new-chat {
    background: var(--gradient-primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.btn-new-chat:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.model-selector {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.model-selector label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.model-selector select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    margin-bottom: 4px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-item:hover {
    background: var(--bg-tertiary);
}

.history-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.history-title i {
    margin-right: 8px;
    color: var(--text-tertiary);
}

.history-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.history-item:hover .history-actions {
    opacity: 1;
}

.history-actions button {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.history-actions button:hover {
    color: var(--primary-color);
    background: rgba(79, 70, 229, 0.1);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-tertiary);
}

.sidebar-footer a {
    color: var(--primary-color);
    text-decoration: none;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.welcome-message {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.welcome-message i {
    color: var(--primary-color);
    margin-bottom: 20px;
}

.welcome-message h2 {
    font-size: 1.8rem;
    margin-bottom: 12px;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-message p {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.recommend {
    margin-top: 16px;
    padding: 12px 24px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    display: inline-block;
}

.recommend a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

/* Message Styles */
.message {
    margin-bottom: 20px;
    animation: fadeIn 0.3s ease;
}

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

.message-content {
    max-width: 80%;
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    line-height: 1.6;
    font-size: 0.95rem;
}

.message.user .message-content {
    background: var(--gradient-primary);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

.message.typing .message-content::after {
    content: '▊';
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Code Block Styles */
.code-block {
    position: relative;
    background: #1e293b;
    border-radius: var(--radius-md);
    margin: 12px 0;
    overflow: hidden;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: #334155;
    color: #94a3b8;
    font-size: 0.85rem;
}

.copy-btn {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.copy-btn:hover {
    color: white;
    background: rgba(255,255,255,0.1);
}

.code-block pre {
    padding: 16px;
    margin: 0;
    overflow-x: auto;
}

.code-block code {
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.9rem;
}

/* Input Area */
.input-area {
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.template-suggestions {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.template-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

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

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.input-wrapper textarea {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.95rem;
    resize: none;
    transition: border-color 0.2s ease;
}

.input-wrapper textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.btn-send {
    background: var(--gradient-primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-send:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.input-footer {
    display: flex;
    gap: 12px;
    margin-top: 12px;
}

.btn-export,
.btn-share {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.btn-export:hover,
.btn-share:hover {
    background: var(--bg-tertiary);
    color: var(--primary-color);
}

/* Footer */
.footer {
    text-align: center;
    padding: 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    color: var(--text-tertiary);
    font-size: 0.85rem;
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
}

/* Admin Styles */
.admin-container {
    max-width: 1200px;
    margin: 80px auto 40px;
    padding: 0 24px;
}

.admin-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}

.admin-section h2 {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.admin-form .form-group {
    margin-bottom: 20px;
}

.json-editor {
    width: 100%;
    font-family: 'Fira Code', monospace;
    font-size: 0.9rem;
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    resize: vertical;
}

.btn-save {
    background: var(--gradient-primary);
    color: white;
    border: none;
    padding: 12px 32px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.btn-save:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.stat-card {
    background: var(--bg-primary);
    padding: 24px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
}

.stat-card i {
    font-size: 2rem;
    color: var(--primary-color);
}

.stat-info h3 {
    font-size: 1.8rem;
    margin-bottom: 4px;
}

.stat-info p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Login Page */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
}

.login-container {
    background: var(--bg-primary);
    padding: 40px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header i {
    color: var(--primary-color);
    margin-bottom: 16px;
}

.login-header h2 {
    font-size: 1.6rem;
}

.login-form .form-group {
    margin-bottom: 20px;
}

.login-form label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.login-form input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
}

.btn-login {
    width: 100%;
    background: var(--gradient-primary);
    color: white;
    border: none;
    padding: 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.3s ease;
}

.btn-login:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.login-footer {
    text-align: center;
    margin-top: 20px;
}

.login-footer a {
    color: var(--primary-color);
    text-decoration: none;
}

/* Alert Styles */
.alert {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 0.95rem;
}

.alert-error {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: #16a34a;
    border: 1px solid #bbf7d0;
}

/* Page Styles */
.page-container {
    max-width: 800px;
    margin: 80px auto 40px;
    padding: 0 24px;
}

.page-content {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 40px;
    box-shadow: var(--shadow-sm);
}

.page-content h1 {
    font-size: 2rem;
    margin-bottom: 24px;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.page-content h2 {
    font-size: 1.4rem;
    margin: 24px 0 16px;
}

.page-content p {
    margin-bottom: 16px;
    color: var(--text-secondary);
    line-height: 1.8;
}

/* Responsive */
@media (max-width: 768px) {
    .nav-links {
        display: none;
    }
    
    .nav-links.active {
        display: flex;
        flex-direction: column;
        position: absolute;
        top: var(--navbar-height);
        left: 0;
        right: 0;
        background: var(--bg-secondary);
        padding: 16px;
        border-bottom: 1px solid var(--border-color);
    }
    
    .hamburger {
        display: block;
    }
    
    .sidebar {
        position: fixed;
        left: -100%;
        top: var(--navbar-height);
        height: calc(100vh - var(--navbar-height));
        transition: left 0.3s ease;
        z-index: 99;
    }
    
    .sidebar.active {
        left: 0;
    }
    
    .main-container {
        flex-direction: column;
    }
    
    .message-content {
        max-width: 90%;
    }
    
    .template-suggestions {
        overflow-x: auto;
        flex-wrap: nowrap;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .nav-container {
        padding: 0 16px;
    }
    
    .chat-messages {
        padding: 16px;
    }
    
    .input-area {
        padding: 16px;
    }
    
    .page-content {
        padding: 24px;
    }
}