/* ===========================
   CSS Variables & Reset
   =========================== */
:root {
    /* Light Mode Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f8;
    --bg-tertiary: #ececf1;
    --text-primary: #0d0d0d;
    --text-secondary: #565869;
    --border-color: #d9d9e3;
    --user-msg-bg: #2563eb;
    --user-msg-text: #ffffff;
    --ai-msg-bg: #f7f7f8;
    --ai-msg-text: #0d0d0d;
    --input-bg: #ffffff;
    --input-border: #d9d9e3;
    --input-focus: #2563eb;
    --btn-hover: #ececf1;
    --shadow: rgba(0, 0, 0, 0.1);
    --code-bg: #1e1e1e;
    --scrollbar-thumb: #d9d9e3;
    --scrollbar-track: transparent;
}

[data-theme="dark"] {
    /* Dark Mode Colors */
    --bg-primary: #0d0d0d;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #2a2a2a;
    --text-primary: #ececf1;
    --text-secondary: #b4b4b4;
    --border-color: #3a3a3a;
    --user-msg-bg: #2563eb;
    --user-msg-text: #ffffff;
    --ai-msg-bg: #2a2a2a;
    --ai-msg-text: #ececf1;
    --input-bg: #1a1a1a;
    --input-border: #3a3a3a;
    --input-focus: #2563eb;
    --btn-hover: #2a2a2a;
    --shadow: rgba(0, 0, 0, 0.3);
    --code-bg: #1e1e1e;
    --scrollbar-thumb: #3a3a3a;
    --scrollbar-track: transparent;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow: hidden;
}

/* ===========================
   App Container
   =========================== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 100%;
    margin: 0 auto;
}

/* ===========================
   Header
   =========================== */
.header {
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    transition: all 0.3s ease;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 900px;
    margin: 0 auto;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.logo-icon {
    width: 28px;
    height: 28px;
    color: #2563eb;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    background: transparent;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
    color: var(--text-secondary);
}

.icon-btn:hover {
    background-color: var(--btn-hover);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

/* Theme Toggle Icons */
[data-theme="light"] .moon-icon {
    display: none;
}

[data-theme="dark"] .sun-icon {
    display: none;
}

/* ===========================
   Chat Container
   =========================== */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1.5rem;
    background-color: var(--bg-primary);
    scroll-behavior: smooth;
    position: relative;
}

.chat-container::-webkit-scrollbar {
    width: 8px;
}

.chat-container::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

.chat-container::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ===========================
   Welcome Screen
   =========================== */
.welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.welcome-screen.hidden {
    display: none !important;
}

.welcome-content {
    text-align: center;
    max-width: 600px;
}

.welcome-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.welcome-icon svg {
    width: 40px;
    height: 40px;
    color: white;
}

.welcome-content h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.welcome-content p {
    font-size: 1.125rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.example-prompts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
    margin-top: 2rem;
}

.example-prompt {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    color: var(--text-primary);
    text-align: left;
}

.example-prompt:hover {
    background-color: var(--bg-tertiary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

/* ===========================
   Messages
   =========================== */
.messages {
    max-width: 900px;
    margin: 0 auto;
    display: flex !important;
    flex-direction: column;
    gap: 1.5rem;
    min-height: 50px;
}

.message {
    display: flex;
    gap: 1rem;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 600;
    font-size: 0.875rem;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: white;
}

.message.ai .message-avatar {
    background: linear-gradient(135deg, #10b981, #06b6d4);
    color: white;
}

.message-content {
    flex: 1;
    max-width: 70%;
}

.message.user .message-content {
    display: flex;
    justify-content: flex-end;
}

.message-bubble {
    padding: 1rem 1.25rem;
    border-radius: 18px;
    line-height: 1.6;
    word-wrap: break-word;
    position: relative;
}

.message.user .message-bubble {
    background-color: var(--user-msg-bg);
    color: var(--user-msg-text);
    border-bottom-right-radius: 4px;
}

.message.ai .message-bubble {
    background-color: var(--ai-msg-bg);
    color: var(--ai-msg-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-color);
}

.message-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.message:hover .message-actions {
    opacity: 1;
}

.message-action-btn {
    background: transparent;
    border: none;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.25rem;
    transition: all 0.2s ease;
}

.message-action-btn:hover {
    background-color: var(--btn-hover);
    color: var(--text-primary);
}

.message-action-btn svg {
    width: 14px;
    height: 14px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 0.25rem;
    padding: 1rem;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-secondary);
    animation: typingAnimation 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingAnimation {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-8px);
    }
}

/* ===========================
   Markdown Styling
   =========================== */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4,
.message-bubble h5,
.message-bubble h6 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.message-bubble h1 { font-size: 1.5rem; }
.message-bubble h2 { font-size: 1.25rem; }
.message-bubble h3 { font-size: 1.125rem; }

.message-bubble p {
    margin-bottom: 0.75rem;
}

.message-bubble ul,
.message-bubble ol {
    margin-left: 1.5rem;
    margin-bottom: 0.75rem;
}

.message-bubble li {
    margin-bottom: 0.25rem;
}

.message-bubble code {
    background-color: var(--code-bg);
    color: #e5e5e5;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
}

.message-bubble pre {
    background-color: var(--code-bg);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.75rem 0;
    position: relative;
}

.message-bubble pre code {
    background: transparent;
    padding: 0;
    color: #e5e5e5;
    display: block;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background-color: #2a2a2a;
    border-radius: 8px 8px 0 0;
    margin-bottom: -0.5rem;
}

.code-language {
    font-size: 0.75rem;
    color: #b4b4b4;
    text-transform: uppercase;
}

.copy-code-btn {
    background: transparent;
    border: 1px solid #3a3a3a;
    color: #b4b4b4;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.2s ease;
}

.copy-code-btn:hover {
    background-color: #3a3a3a;
    color: #ffffff;
}

.message-bubble blockquote {
    border-left: 3px solid var(--input-focus);
    padding-left: 1rem;
    margin: 0.75rem 0;
    color: var(--text-secondary);
    font-style: italic;
}

.message-bubble a {
    color: #2563eb;
    text-decoration: underline;
}

.message-bubble a:hover {
    text-decoration: none;
}

/* ===========================
   Input Area
   =========================== */
.input-area {
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    position: sticky;
    bottom: 0;
}

.input-container {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    background-color: var(--input-bg);
    border: 2px solid var(--input-border);
    border-radius: 24px;
    padding: 0.75rem 1rem;
    transition: border-color 0.2s ease;
}

.input-container:focus-within {
    border-color: var(--input-focus);
}

#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    font-size: 1rem;
    color: var(--text-primary);
    font-family: inherit;
    max-height: 200px;
    line-height: 1.5;
}

#messageInput::placeholder {
    color: var(--text-secondary);
}

.send-btn {
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: scale(1);
}

.send-btn svg {
    width: 20px;
    height: 20px;
    color: white;
}

.input-footer {
    max-width: 900px;
    margin: 0.5rem auto 0;
    display: flex;
    justify-content: flex-end;
}

.char-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* ===========================
   Loading Overlay
   =========================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===========================
   Responsive Design
   =========================== */
@media (max-width: 768px) {
    .header {
        padding: 0.75rem 1rem;
    }

    .logo {
        font-size: 1.125rem;
    }

    .chat-container {
        padding: 1rem;
    }

    .message-content {
        max-width: 85%;
    }

    .welcome-content h2 {
        font-size: 1.5rem;
    }

    .welcome-content p {
        font-size: 1rem;
    }

    .example-prompts {
        grid-template-columns: 1fr;
    }

    .input-area {
        padding: 0.75rem 1rem;
    }

    .message-bubble {
        padding: 0.875rem 1rem;
    }
}

@media (max-width: 480px) {
    .message-content {
        max-width: 90%;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.75rem;
    }

    .welcome-icon {
        width: 60px;
        height: 60px;
    }

    .welcome-icon svg {
        width: 30px;
        height: 30px;
    }
}

/* ===========================
   Utility Classes
   =========================== */
.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.slide-up {
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
