/* CSS Variables */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f8;
    --bg-tertiary: #ececf1;
    --bg-sidebar: #f9f9f9;
    --text-primary: #1a1a1a;
    --text-secondary: #6b6b6b;
    --text-tertiary: #8e8e8e;
    --border-color: #e5e5e5;
    --accent-color: #6366f1;
    --accent-hover: #4f46e5;
    --accent-light: #eef2ff;
    --user-bubble: #6366f1;
    --user-text: #ffffff;
    --bot-bubble: #f4f4f5;
    --bot-text: #1a1a1a;
    --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);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --transition: all 0.2s ease;
}

[data-theme="dark"] {
    --bg-primary: #0d0d0d;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #2a2a2a;
    --bg-sidebar: #171717;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-tertiary: #6b6b6b;
    --border-color: #2a2a2a;
    --accent-light: #1e1b4b;
    --bot-bubble: #262626;
    --bot-text: #ffffff;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

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

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

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

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

.logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent-color), #8b5cf6);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.logo-icon svg {
    width: 20px;
    height: 20px;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-color), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.new-chat-btn {
    margin: 16px;
    padding: 12px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
}

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

.new-chat-btn svg {
    width: 18px;
    height: 18px;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 8px 16px;
}

.history-section {
    margin-bottom: 8px;
}

.history-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 0;
    display: block;
}

.history-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: var(--transition);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

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

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.avatar {
    width: 32px;
    height: 32px;
    background: var(--bg-tertiary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.avatar svg {
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
}

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

/* Chat Header */
.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg-primary);
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
}

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

.menu-toggle svg {
    width: 24px;
    height: 24px;
}

.chat-header h1 {
    font-size: 1.125rem;
    font-weight: 600;
    flex: 1;
}

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

.theme-toggle {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

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

.theme-toggle svg {
    width: 20px;
    height: 20px;
}

.moon-icon {
    display: none;
}

[data-theme="dark"] .sun-icon {
    display: none;
}

[data-theme="dark"] .moon-icon {
    display: block;
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

/* Welcome Screen */
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    max-width: 640px;
    margin: 0 auto;
    padding: 40px 20px;
}

.welcome-screen.hidden {
    display: none;
}

.welcome-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--accent-color), #8b5cf6);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.welcome-icon svg {
    width: 40px;
    height: 40px;
    color: white;
}

.welcome-screen h2 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-screen p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.suggestion-chips {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
}

.chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
    text-align: left;
    transition: var(--transition);
}

.chip:hover {
    background: var(--accent-light);
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.chip svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Messages */
.messages {
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-width: 800px;
    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: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--accent-color), #8b5cf6);
    color: white;
}

.message.bot .message-avatar {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.message-avatar svg {
    width: 20px;
    height: 20px;
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.message-sender {
    font-weight: 600;
    font-size: 0.9rem;
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.message-text {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-primary);
}

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

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

.message-text code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 0.85em;
}

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

.message-text pre code {
    background: none;
    padding: 0;
}

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

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

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

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

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

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

.input-container {
    max-width: 800px;
    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 16px;
    transition: var(--transition);
}

.input-container:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-light);
}

textarea {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-primary);
    resize: none;
    max-height: 200px;
    line-height: 1.5;
}

textarea::placeholder {
    color: var(--text-tertiary);
}

.send-btn {
    width: 40px;
    height: 40px;
    background: var(--accent-color);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

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

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.send-btn svg {
    width: 18px;
    height: 18px;
}

.disclaimer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 12px;
}

/* Mobile Styles */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100%;
        z-index: 1000;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        left: 0;
    }

    .menu-toggle {
        display: block;
    }

    .suggestion-chips {
        grid-template-columns: 1fr;
    }

    .chat-container {
        padding: 16px;
    }

    .input-area {
        padding: 12px 16px 20px;
    }

    .welcome-screen h2 {
        font-size: 1.5rem;
    }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

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

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

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

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

/* Code Block Styling */
.code-block {
    position: relative;
}

.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-tertiary);
    padding: 8px 12px;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.copy-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    transition: var(--transition);
}

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