/* CSS Variables */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #8b5cf6;
    --accent-color: #06b6d4;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --sidebar-width: 280px;
    --header-height: 60px;
    --input-height: 80px;
    --transition: all 0.3s ease;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

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

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

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

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: var(--radius-md);
    color: white;
    font-weight: 600;
    font-size: 16px;
}

.logo i {
    font-size: 24px;
}

.new-chat-btn {
    width: 100%;
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
}

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

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.chat-history {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.history-section h3 {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding-left: 12px;
}

.history-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
    font-size: 14px;
    color: var(--text-secondary);
}

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

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

.history-item i {
    font-size: 14px;
    opacity: 0.7;
}

.history-item-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-delete {
    opacity: 0;
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 4px;
    transition: var(--transition);
}

.history-item:hover .history-item-delete {
    opacity: 0.7;
}

.history-item-delete:hover {
    opacity: 1 !important;
    color: #ef4444;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.theme-toggle,
.clear-btn {
    width: 100%;
    padding: 10px 12px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
}

.theme-toggle:hover,
.clear-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.clear-btn:hover {
    color: #ef4444;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
}

/* Header */
.main-header {
    height: var(--header-height);
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.sidebar-toggle:hover {
    background: var(--bg-tertiary);
}

.header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.header-title i {
    font-size: 24px;
    color: var(--primary-color);
}

.header-title h1 {
    font-size: 18px;
    font-weight: 600;
}

.badge {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

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

.header-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

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

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
}

/* Welcome Screen */
.welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px;
}

.welcome-content {
    text-align: center;
    max-width: 900px;
}

.welcome-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 24px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.welcome-icon i {
    font-size: 36px;
    color: white;
}

.welcome-content h2 {
    font-size: 32px;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-content p {
    color: var(--text-secondary);
    font-size: 16px;
    margin-bottom: 40px;
}

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

.feature-card {
    padding: 24px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.feature-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.feature-card i {
    font-size: 24px;
    color: var(--primary-color);
    margin-bottom: 12px;
}

.feature-card h3 {
    font-size: 16px;
    margin-bottom: 6px;
}

.feature-card p {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
}

/* Messages Container */
.messages-container {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.message {
    display: flex;
    gap: 16px;
    animation: fadeIn 0.3s ease;
}

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

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

.message.user .message-avatar {
    background: linear-gradient(135deg, #10b981, #059669);
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
}

.message-avatar i {
    font-size: 16px;
    color: white;
}

.message-content {
    flex: 1;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 16px;
    border: 1px solid var(--border-color);
}

.message.user .message-content {
    background: var(--primary-color);
    color: white;
    border: none;
}

.message-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.message-sender {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
}

.message.user .message-sender {
    color: rgba(255, 255, 255, 0.8);
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
}

.message.user .message-time {
    color: rgba(255, 255, 255, 0.7);
}

.message-body {
    font-size: 15px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-body p {
    margin-bottom: 12px;
}

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

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

.message-body li {
    margin-bottom: 6px;
}

.message-body code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 14px;
}

.message.user .message-body code {
    background: rgba(255, 255, 255, 0.2);
}

.message-body pre {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 16px;
    overflow-x: auto;
    margin: 12px 0;
}

.message-body pre code {
    background: none;
    padding: 0;
    font-size: 13px;
    line-height: 1.5;
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-tertiary);
    padding: 8px 16px;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    border: 1px solid var(--border-color);
    border-bottom: none;
}

.code-lang {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.copy-code-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: var(--transition);
}

.copy-code-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.message-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    opacity: 0;
    transition: var(--transition);
}

.message:hover .message-actions {
    opacity: 1;
}

.message-action-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: var(--transition);
}

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

.message.user .message-actions {
    justify-content: flex-end;
}

.message.user .message-action-btn {
    border-color: rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.8);
}

.message.user .message-action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-color: rgba(255, 255, 255, 0.5);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

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

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
}

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

.input-container {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 12px;
    transition: var(--transition);
}

.input-container:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.input-actions-left,
.input-actions-right {
    display: flex;
    gap: 4px;
}

.attach-btn,
.voice-btn,
.send-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.attach-btn,
.voice-btn {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.attach-btn:hover,
.voice-btn:hover {
    background: var(--primary-color);
    color: white;
}

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

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

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

.input-wrapper {
    flex: 1;
}

#messageInput {
    width: 100%;
    border: none;
    background: none;
    resize: none;
    font-size: 15px;
    font-family: inherit;
    color: var(--text-primary);
    max-height: 150px;
    line-height: 1.5;
    padding: 8px 0;
}

#messageInput:focus {
    outline: none;
}

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

.input-footer {
    text-align: center;
    margin-top: 8px;
}

.input-footer p {
    font-size: 12px;
    color: var(--text-muted);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: modalSlide 0.3s ease;
}

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

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

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

.close-modal {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: var(--transition);
}

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

.modal-body {
    padding: 20px;
}

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

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

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

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

.setting-group textarea {
    resize: vertical;
    min-height: 100px;
}

.setting-group input[type="range"] {
    width: 100%;
    margin-top: 8px;
    accent-color: var(--primary-color);
}

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

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

/* About Modal */
.about-modal {
    max-width: 400px;
}

.about-content {
    text-align: center;
}

.about-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 16px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.about-icon i {
    font-size: 36px;
    color: white;
}

.about-content h3 {
    font-size: 20px;
    margin-bottom: 4px;
}

.about-content > p {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 16px;
}

.about-desc {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.about-features {
    text-align: left;
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}

.about-features h4 {
    font-size: 14px;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.about-features ul {
    list-style: none;
    padding: 0;
}

.about-features li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.about-features li i {
    color: #10b981;
    font-size: 12px;
}

.copyright {
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.copyright p {
    font-size: 13px;
    color: var(--text-muted);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        z-index: 200;
    }

    .sidebar.active {
        left: 0;
    }

    .sidebar-toggle {
        display: block;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 150;
    }

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

    .feature-cards {
        grid-template-columns: 1fr;
    }

    .welcome-content h2 {
        font-size: 24px;
    }

    .header-title h1 {
        font-size: 14px;
    }

    .badge {
        display: none;
    }
}

/* Message attachment preview */
.attachment-preview {
    margin-top: 12px;
    padding: 10px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 10px;
}

.attachment-preview i {
    font-size: 20px;
    color: var(--primary-color);
}

.attachment-info {
    flex: 1;
}

.attachment-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.attachment-size {
    font-size: 11px;
    color: var(--text-muted);
}

/* Loading animation */
.loading-dots {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.loading-dot {
    width: 6px;
    height: 6px;
    background: var(--primary-color);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.loading-dot:nth-child(1) { animation-delay: 0s; }
.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* Error message */
.error-message {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    color: #dc2626;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 8px 0;
}

[data-theme="dark"] .error-message {
    background: #451a1a;
    border-color: #7f1d1d;
    color: #fca5a5;
}

/* Quick actions */
.quick-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.quick-action-btn {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

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