/* ---
    Minimalist Chat UI (v3)
    --- */

/* ====== 1. Global Variables & Base Styles ====== */
:root {
    --bg-color: #1c1c1c;          /* A slightly softer black */
    --input-bg-color: #252525;    /* Input bar background */
    --bubble-bg-color: #333333;   /* User message bubble */
    --text-primary: #e8e8e8;      /* Primary text for readability */
    --text-secondary: #888888;    /* Muted text for placeholders */
    --border-color: #3a3a3a;      /* Subtle borders */
    --accent-color: #007aff;      /* Standard blue accent for the button */
    
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-family-monospace: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', monospace; /* New monospace font */
    --border-radius-md: 12px;
    --border-radius-lg: 20px;
    --transition-fast: 0.2s ease;
}

/* Base HTML and Body setup */
html {
    box-sizing: border-box;
    /* Default font size for desktop */
    font-size: 16px; 
}

*, *::before, *::after {
    box-sizing: inherit;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-family);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
    height: var(--vh, 100vh);
}

/* ====== 2. Main Layout & App Container ====== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 820px;
    margin: 0 auto;
}

/* ====== 3. Chat Box & Messages ====== */
#chatBox {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem; /* Space between messages */
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

#chatBox::-webkit-scrollbar { width: 6px; }
#chatBox::-webkit-scrollbar-track { background: transparent; }
#chatBox::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 3px; }

.message-wrapper {
    display: flex;
    max-width: 90%;
    animation: fadeIn 0.4s var(--transition-fast) both;
}

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

/* User message with bubble, aligned right */
.user-wrapper {
    align-self: flex-end;
    justify-content: flex-end;
}
.user-bubble {
    background-color: var(--bubble-bg-color);
    padding: 0.6rem 1.1rem;
    border-radius: var(--border-radius-lg);
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: break-word;
    cursor: pointer;
}

/* MODIFICATION: Assistant message is now a flex column container */
.assistant-wrapper {
    flex-direction: column;
    align-self: flex-start;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: break-word;
}
.assistant-wrapper > span { display: block; }


/* Typing indicator for assistant */
.assistant-wrapper.typing::after {
    content: '▋';
    display: inline-block;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}


/* === START: NEW STYLES for code blocks === */
.code-block-container {
    background-color: #101010;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    margin: 0.5rem 0;
    overflow: hidden;
    width: 100%;
}
.code-block-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0.4rem 0.6rem;
    background-color: #2a2a2a;
    border-bottom: 1px solid var(--border-color);
}
.copy-button {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background-color: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.copy-button:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}
.copy-button svg {
    width: 14px;
    height: 14px;
}
.assistant-wrapper pre {
    margin: 0;
    padding: 1rem;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}
.assistant-wrapper pre::-webkit-scrollbar { height: 6px; }
.assistant-wrapper pre::-webkit-scrollbar-track { background: transparent; }
.assistant-wrapper pre::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 3px; }

.assistant-wrapper code {
    font-family: var(--font-family-monospace);
    font-size: 0.9rem;
    color: #d1d5db;
    white-space: pre;
}
/* === END: NEW STYLES for code blocks === */


/* ====== 4. Input Area (Fixed at Bottom) ====== */
#inputContainer {
    padding: 1rem 1.5rem 1.5rem;
    background-color: var(--bg-color); /* Match body background */
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    background-color: var(--input-bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
}

#inputBox {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 1rem;
    line-height: 1.5;
    padding: 0.25rem;
    resize: none;
    overflow-y: hidden;
    max-height: calc(1.5em * 5 + 0.5rem);
    scrollbar-width: none;
}
#inputBox::-webkit-scrollbar { display: none; }
#inputBox::placeholder { color: var(--text-secondary); }

#sendBtn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background-color: var(--accent-color);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    transition: opacity var(--transition-fast);
    flex-shrink: 0;
}
#sendBtn svg { width: 18px; height: 18px; transform: rotate(45deg) translate(-1px, 1px); }
#sendBtn:hover { opacity: 0.85; }

/* ====== 5. Context Menu ====== */
.context-menu {
    position: absolute;
    display: none;
    min-width: 180px;
    background-color: rgba(40, 40, 40, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: var(--border-radius-md);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    padding: 0.5rem;
    z-index: 1000;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity var(--transition-fast), transform var(--transition-fast);
}
.context-menu.visible { opacity: 1; transform: scale(1); }
.context-menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 8px;
    user-select: none;
    transition: background-color var(--transition-fast);
}
.context-menu-item:hover { background-color: var(--accent-color); color: white; }
.context-menu-item svg { width: 16px; height: 16px; }
.context-menu-separator { height: 1px; background-color: var(--border-color); margin: 0.5rem 0; }

/* ====== 6. Responsive Design (Mobile First) ====== */
@media (max-width: 768px) {
    /* MODIFICATION: Set a larger base font size only for mobile devices */
    html {
        font-size: 22px;
    }

    #chatBox { padding: 1rem; }
    #inputContainer { padding: 0.5rem 1rem 1rem; }
    .input-wrapper { padding: 0.4rem 0.4rem 0.4rem 0.8rem; }
}

/* ====== 7. Desktop Layout with Sidebar (Final Version) ====== */
/* These styles only apply to screens wider than 768px */
@media (min-width: 769px) {
    #desktop-wrapper {
        display: flex;
        height: 100vh;
    }

    #sidebar {
        flex: 0 0 calc(100% / 6);
        max-width: 260px;
        background-color: #151515;
        border-right: 1px solid var(--border-color);
        padding: 1rem;
        display: flex;
        flex-direction: column;
        gap: 0.1rem; 
        overflow-y: auto;
    }

    .app-container {
        flex: 1;
        max-width: none;
    }

    /* --- Sidebar Item Styling --- */
    .sidebar-item {
        display: flex;
        align-items: center;
        padding: 0.4rem 1rem; 
        color: var(--text-primary);
        text-decoration: none;
        border-radius: var(--border-radius-md);
        font-weight: 500;
        position: relative;
        overflow: hidden;
        cursor: pointer;
        user-select: none;
        transition: color 0.2s ease, background-color 0.2s ease;
    }

    .sidebar-item .icon {
        margin-right: 0.5rem;
        font-size: 1.2rem;
        display: inline-block;
        width: 24px;
        text-align: center;
    }
    
    .sidebar-item:hover {
        background-color: rgba(255, 255, 255, 0.04);
    }

    /* Style for icon-only items */
    .sidebar-item.icon-only {
        padding: 0.4rem 1rem;
    }
    .sidebar-item.icon-only .icon {
        margin-right: 0;
        font-size: 1.5rem; 
    }

    /* Style for the spacer (blank line) */
    .sidebar-spacer {
        height: 0.2rem;
    }
}

