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

body {
    font-family: 'Outfit', sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    color: #e2e8f0;
    height: 100vh;
    height: 100dvh;
    /* Dynamic container for mobile bars */
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Glassmorphism Container */
.main-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px);
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: rgba(0, 0, 0, 0.3);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 30px;
    padding: 0 10px;
}

.logo {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.brand span {
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.history-nav {
    flex: 1;
    overflow-y: auto;
}

.history-nav h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #94a3b8;
    margin-bottom: 15px;
    padding-left: 10px;
    letter-spacing: 1px;
}

#history-list {
    list-style: none;
}

#history-list li {
    padding: 12px 15px;
    margin-bottom: 5px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #cbd5e1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.chat-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.delete-btn {
    opacity: 0;
    color: #94a3b8;
    font-weight: bold;
    font-size: 1.1rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

#history-list li:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    color: #ef4444;
    /* Red */
    background: rgba(239, 68, 68, 0.1);
}

#history-list li:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(3px);
}

#history-list li.active {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border-left: 3px solid #60a5fa;
}

.new-chat-btn {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.2), transparent) !important;
    color: #60a5fa !important;
    font-weight: 500;
    margin-bottom: 15px !important;
    border: 1px solid rgba(59, 130, 246, 0.2);
    text-align: center;
}

.settings {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.9rem;
    color: #94a3b8;
    cursor: pointer;
    text-align: center;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-header {
    padding: 20px 30px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(0, 0, 0, 0.1);
}

.chat-header h1 {
    font-size: 1.5rem;
    margin-bottom: 5px;
    background: linear-gradient(to right, #ffffff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.chat-header p {
    color: #64748b;
    font-size: 0.9rem;
}

.messages-container {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    gap: 15px;
    max-width: 800px;
    opacity: 0;
    animation: fadeIn 0.3s forwards;
}

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

.message.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

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

.ai-message .avatar {
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: white;
}

.user-message .avatar {
    background: #475569;
    color: #e2e8f0;
}

.content {
    background: rgba(255, 255, 255, 0.05);
    padding: 15px 20px;
    border-radius: 12px;
    line-height: 1.6;
    font-size: 1rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.user-message .content {
    background: #2563eb;
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-message .content {
    border-top-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin-top: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

/* Input Area */
.input-area {
    padding: 30px;
    background: rgba(0, 0, 0, 0.2);
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

.input-wrapper:focus-within {
    border-color: #60a5fa;
    box-shadow: 0 0 15px rgba(96, 165, 250, 0.2);
}

#user-input {
    width: 100%;
    background: transparent;
    border: none;
    padding: 12px 15px;
    color: white;
    font-size: 1rem;
    outline: none;
    font-family: inherit;
}

#send-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: #3b82f6;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

#send-btn:hover {
    background: #2563eb;
    transform: translateY(-50%) scale(1.05);
}

/* Markdown Styles */
.content h1,
.content h2 {
    margin-top: 10px;
    margin-bottom: 8px;
    color: #f1f5f9;
}

.content p {
    margin-bottom: 10px;
}

.content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: monospace;
    color: #cbd5e1;
}

.content pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
}

.content table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
}

.content th,
.content td {
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px 12px;
    text-align: left;
}

.content th {
    background: rgba(255, 255, 255, 0.05);
}

/* --- Mobile Responsiveness --- */

/* Hide mobile menu button by default (desktop) */
.mobile-menu-btn {
    display: none;
    background: transparent;
    border: none;
    color: #e2e8f0;
    cursor: pointer;
    position: absolute;
    top: 20px;
    left: 15px;
    z-index: 20;
    /* Above header content */
    padding: 5px;
}

@media (max-width: 768px) {
    /* Stack sidebar and chat? No, Sidebar Drawer pattern */

    .sidebar {
        position: fixed;
        left: -280px;
        /* Hide off-screen */
        top: 0;
        bottom: 0;
        z-index: 100;
        transition: left 0.3s ease;
        background: #0f172a;
        /* Solid background for drawer */
        width: 250px;
        box-shadow: 2px 0 15px rgba(0, 0, 0, 0.5);
    }

    .sidebar.open {
        left: 0;
        /* Slide in */
    }

    .mobile-menu-btn {
        display: block;
    }

    /* Make delete buttons always visible on touch devices */
    .delete-btn {
        opacity: 1 !important;
        color: #ef4444 !important;
        /* Always red on mobile to show it's active */
        padding: 8px 12px;
        /* Large touch target */
        margin-left: 10px;
        background: rgba(255, 255, 255, 0.05);
        /* Slight background */
        border-radius: 6px;
    }

    .chat-header {
        padding-left: 50px;
        /* Space for menu button */
    }

    .chat-header h1 {
        font-size: 1.2rem;
    }

    .chat-header p {
        font-size: 0.8rem;
    }

    /* Fix message container height */
    .chat-area {
        width: 100%;
        height: 100vh;
    }

    .messages-container {
        padding: 15px;
        /* Reduce padding */
    }

    /* Fix Input area being squished or hidden */
    .input-area {
        padding: 15px;
        background: #0f172a;
        /* Ensure background opacity doesn't show weirdness */
    }

    .input-wrapper {
        padding: 5px;
    }

    #user-input {
        font-size: 16px;
        /* Prevent iOS zoom */
    }

    /* Overlay for when sidebar is open */
    .overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 90;
        display: none;
    }

    .overlay.active {
        display: block;
    }
}