:root {
    --bg-color: #0f172a;
    --sidebar-bg: #1e293b;
    --chat-bg: #0f172a;
    --accent-color: #38bdf8;
    --accent-hover: #0ea5e9;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --msg-user-bg: #334155;
    --msg-ai-bg: #1e293b;
    --border-color: #334155;
    --meta-color: #64748b;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.light-mode {
    --bg-color: #f8fafc;
    --sidebar-bg: #ffffff;
    --chat-bg: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --msg-user-bg: #e2e8f0;
    --msg-ai-bg: #ffffff;
    --border-color: #e2e8f0;
}


* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    overflow: hidden;
}

/* App Container */
#app {
    display: flex;
    width: 100%;
    height: 100%;
}

/* Sidebar */
aside {
    width: 280px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 2rem;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent-color);
}

.model-selector {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.model-selector label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

select {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem;
    border-radius: 0.75rem;
    outline: none;
    cursor: pointer;
    transition: var(--transition);
}

select:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

/* Main Chat Area */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: var(--chat-bg);
}

#chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
}

/* Message Bubbles */
.message {
    max-width: 85%;
    padding: 1rem 1.25rem;
    border-radius: 1rem;
    line-height: 1.6;
    position: relative;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-content {
    word-wrap: break-word;
    transition: all 0.2s ease;
}

.message.user {
    align-self: flex-end;
    background-color: var(--msg-user-bg);
    border-bottom-right-radius: 0.25rem;
}

.message.ai {
    align-self: flex-start;
    background-color: var(--msg-ai-bg);
    border-bottom-left-radius: 0.25rem;
    border: 1px solid var(--border-color);
}

.message ol {
    margin-left: 20px;
}

.message ul {
    margin-left: 20px;
}

.message-header {
    font-size: 0.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.user .message-header {
    color: var(--accent-color);
}

.ai .message-header {
    color: #10b981;
}

.message-footer {
    display: flex;
    gap: 1rem;
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.7rem;
    color: var(--meta-color);
    font-weight: 600;
}

.message-footer span {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.theme-toggle-corner {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    width: 40px;
    height: 40px;
    background-color: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    z-index: 100;
    box-shadow: var(--shadow-md);
    color: var(--text-primary);
}

.theme-toggle-corner:hover {
    border-color: var(--accent-color);
    transform: scale(1.1);
}

/* Input Area */


.input-container {
    padding: 2rem;
    background: linear-gradient(to top, var(--chat-bg) 80%, transparent);
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    background-color: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 0.75rem;
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.input-wrapper:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1);
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 0.5rem;
    resize: none;
    max-height: 200px;
    outline: none;
    font-family: inherit;
    font-size: 1rem;
}

#send-btn,
#stop-btn {
    background-color: var(--accent-color);
    color: var(--bg-color);
    border: none;
    padding: 0.6rem;
    border-radius: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

#stop-btn {
    background-color: #ef4444;
}

#send-btn:hover,
#stop-btn:hover {
    transform: scale(1.05);
}

#stop-btn:hover {
    background-color: #dc2626;
}


#send-btn:disabled {
    background-color: var(--text-secondary);
    cursor: not-allowed;
    transform: none;
}

/* Markdown styling inside messages */
.message-content code {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 0.2rem 0.4rem;
    border-radius: 0.375rem;
    font-family: 'Fira Code', 'Cascadia Code', Consolas, monospace;
    font-size: 0.9em;
    color: var(--accent-color);
}

.message-content pre {
    background: #282c34 !important;
    /* Specific Atom One Dark color */
    padding: 1rem;
    border-radius: 0.75rem;
    overflow-x: auto;
    margin: 1rem 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.06);
}

.message-content pre code {
    background: transparent !important;
    padding: 0;
    color: #abb2bf;
    /* Default text for Atom One Dark */
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Light mode specific code styling */
body.light-mode .message-content code {
    background-color: rgba(0, 0, 0, 0.05);
    color: #e11d48;
}

body.light-mode .message-content pre {
    background: #282c34 !important;
    /* Keep dark for code even in light mode for better contrast */
    border-color: #334155;
}


/* Typing Indicator */
.typing {
    display: flex;
    gap: 0.3rem;
    padding: 0.5rem;
}

.dot {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.dot:nth-child(1) {
    animation-delay: -0.32s;
}

.dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

/* Mobile Header */
.mobile-header {
    display: none;
    height: 60px;
    background-color: var(--sidebar-bg);
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

#mobile-menu-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
}

.mobile-logo {
    font-weight: 700;
    color: var(--accent-color);
    font-size: 1.2rem;
}

#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1100;
    animation: fadeIn 0.3s ease;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }

    aside {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        z-index: 1200;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 10px 0 15px -3px rgba(0, 0, 0, 0.1);
    }

    aside.active {
        transform: translateX(280px);
    }

    #sidebar-overlay.active {
        display: block;
    }

    main {
        padding-top: 60px;
    }

    #chat-history {
        padding: 1rem;
    }

    .message {
        max-width: 95%;
    }

    .input-container {
        padding: 1rem;
    }

    .theme-toggle-corner {
        top: 4.5rem;
        /* Drop below fixed mobile header */
        right: 1rem;
        width: 35px;
        height: 35px;
    }
}

@media (max-width: 480px) {
    .logo-area span {
        font-size: 1rem;
    }

    .message-content {
        font-size: 0.95rem;
    }
}