/* ---------- Reset & Variables ----------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Roboto', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-color: #131314;
    --surface-color: #1E1F20;
    --text-primary: #E3E3E3;
    --text-secondary: #A4A4A4;
    --accent-blue: #A8C7FA;
    --user-bubble: #282A2C;
    --input-bg: #1E1F20;
    --hover-bg: #2D2E2F;
    --border-radius: 24px;
}

body.light-mode {
    --bg-color: #FFFFFF;
    --surface-color: #F0F4F9;
    --text-primary: #1F1F1F;
    --text-secondary: #444746;
    --accent-blue: #0B57D0;
    --user-bubble: #F0F4F9;
    --input-bg: #F0F4F9;
    --hover-bg: #D3E3FD;
}

body {
    background: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden; 
}

/* ---------- Top Nav ---------- */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    flex-shrink: 0;
    z-index: 10;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-secondary);
}

#model-select {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 0.95rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    outline: none;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover { background: var(--hover-bg); color: var(--text-primary); }

/* ---------- Main Container ---------- */
.container {
    flex: 1; 
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
}

/* ---------- Welcome Screen ---------- */
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    
    /* 👇 Changed back to center so content floats in the middle */
    justify-content: center; 
    
    text-align: center;
    padding: 2rem 1rem;
    width: 100%;
    overflow-y: auto;
}

/* Header Wrapper */
.welcome-header-content {
    margin-bottom: 3rem; /* Just simple spacing */
}

.header {
    font-size: 3rem;
    background: linear-gradient(74deg, #4285F4 0%, #9B72CB 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 0.5rem;
}

.sub-heading {
    font-size: 1.5rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* Suggestions Grid */
.suggestions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
}

.suggestions-item {
    background: var(--surface-color);
    padding: 1rem;
    width: 180px;
    height: 160px;
    border-radius: 16px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: background 0.2s;
}

.suggestions-item:hover { background: var(--hover-bg); }

/* ---------- Chat Area ---------- */
.chats-container {
    flex: 1; 
    overflow-y: auto; 
    padding: 2rem 1rem 1rem 1rem;
    display: none; /* Controlled by JS */
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
    min-height: 0;
}

/* Scrollbar Styling */
.chats-container::-webkit-scrollbar { width: 6px; }
.chats-container::-webkit-scrollbar-thumb { background: var(--surface-color); border-radius: 3px; }

/* Messages */
.message {
    display: flex;
    gap: 1rem;
    max-width: 100%;
    animation: fadeSlideUp 0.3s ease;
}

.user-message { justify-content: flex-end; }

.user-message .message-content {
    background: var(--user-bubble);
    padding: 10px 18px;
    border-radius: 20px;
    border-top-right-radius: 4px;
    max-width: 85%;
    word-break: break-word;
}

.bot-message { align-items: flex-start; width: 100%; }

.avatar { width: 30px; height: 30px; flex-shrink: 0; }
.bot-message.loading .avatar { animation: rotate 3s linear infinite; }

.bot-message .message-content {
    flex: 1;
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden; 
}

.bot-message p { margin-bottom: 0.8rem; }

/* Code Blocks */
.code-block-wrapper {
    background: #1e1e1e; 
    border-radius: 12px;
    margin: 12px 0;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.code-lang {
    font-size: 0.8rem;
    color: #A4A4A4;
    text-transform: uppercase;
    font-weight: 500;
}

.copy-btn {
    background: transparent;
    border: none;
    color: #A4A4A4;
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 6px;
}
.copy-btn:hover { color: #E3E3E3; }
.copy-btn.copied { color: #4caf50; }

.bot-message pre { margin: 0 !important; background: transparent !important; }
.bot-message code.hljs { padding: 16px; font-family: 'Courier New', monospace; font-size: 0.9rem; overflow-x: auto; }
.bot-message :not(pre) > code { background: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: 4px; font-family: 'Courier New', monospace; }

/* ---------- Input Area ---------- */
.prompt-container {
    padding: 0 1rem 1.5rem 1rem;
    background: var(--bg-color);
    flex-shrink: 0;
    z-index: 20;
}

.prompt-box {
    background: var(--input-bg);
    border-radius: var(--border-radius);
    padding: 8px 12px;
    transition: background 0.2s;
    border: 1px solid transparent;
}
.prompt-box:focus-within { background: var(--hover-bg); }

.input-wrapper { display: flex; align-items: center; gap: 10px; }

.prompt-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 1rem;
    padding: 10px 0;
}

.file-preview-container { display: none; padding: 10px; }
.file-preview-container.active { display: block; }
.file-preview-img { height: 60px; border-radius: 8px; border: 1px solid #444; }

/* Voice & Buttons */
#mic-btn { color: var(--text-secondary); transition: all 0.2s ease; }
#mic-btn:hover { color: var(--text-primary); background: var(--hover-bg); }
#mic-btn.listening { color: #ff4444; background: rgba(255, 68, 68, 0.1); animation: pulse 1.5s infinite; }

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.4); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(255, 68, 68, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 68, 68, 0); }
}

.speak-btn {
    background: transparent; border: none; color: var(--text-secondary); cursor: pointer;
    padding: 4px; margin-top: 8px; display: flex; align-items: center; gap: 5px; opacity: 0.7;
}
.speak-btn:hover { opacity: 1; background: var(--hover-bg); }

.send-btn { color: var(--text-secondary); transition: color 0.2s; }
.send-btn.active { color: var(--accent-blue); }

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

/* ---------- Footer ---------- */
.app-footer {
    width: 100%;
    padding: 10px 0;
    background-color: var(--bg-color); 
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    color: #9ca3af;
    font-size: 0.85rem;
    text-align: center;
    flex-shrink: 0; 
    z-index: 50;
}

.footer-content { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.footer-content strong { color: #e3e3e3; }
.social-links { display: flex; gap: 20px; }
.social-links a { color: #9ca3af; text-decoration: none; display: flex; align-items: center; gap: 6px; }
.social-links a:hover { color: #4da6ff; }

/* Animations */
@keyframes fadeSlideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes rotate { 100% { transform: rotate(360deg); } }


/* Mobile Optimizations */
@media screen and (max-width: 768px) {
    .container { 
        padding: 0.5rem; 
        min-height: 0; 
    }
    
    .header { font-size: 2rem; }

    .welcome-screen {
        width: 100%;

        flex: 1 1 auto; 
        justify-content: flex-start; 
        overflow-y: auto !important; 
        overflow-x: hidden !important; 
        padding-top: 1rem;
        padding-bottom: 100px; 
    }

    /* 2. FIX SUGGESTIONS (Horizontal Scroll) */
    .suggestions { 
        display: flex;
        flex-wrap: nowrap; 
        justify-content: flex-start;
        overflow-x: auto; 
        margin-bottom: 20px !important; 
        padding-bottom: 5px;
        width: 100vw; 
        margin-left: -1rem; 
        padding-left: 1rem; 
        padding-right: 1rem;
        flex-shrink: 0;
        scrollbar-width: none !important; 
        -ms-overflow-style: none; 
    }
    
    .suggestions::-webkit-scrollbar { 
        display: none !important; 
    }

    /* 3. FIX INPUT AREA */
    .prompt-box { padding: 8px 10px; }
    .input-wrapper { gap: 8px; }
    .prompt-input { min-width: 0; flex: 1; }
    #mic-btn, #send-prompt-btn, .file-actions { flex-shrink: 0; }
    
    /* 4. FOOTER MAGIC: Make footer appear at the bottom of the scroll */
    .app-footer {
        position: relative; 
        z-index: 10;
    }
}

/* 5. KEYBOARD OPEN STATE (Screen Height Shrinks) */
@media screen and (max-height: 500px) {
    
    .app-footer { display: none !important; }
    
    .welcome-screen {
        padding-top: 0;
        height: auto;
    }

    .welcome-header-content { margin-bottom: 0.5rem; }
    .header { font-size: 1.5rem; margin-bottom: 0.2rem; }
    .sub-heading { font-size: 1rem; margin-bottom: 0.5rem; }
    .suggestions { margin-bottom: 10px !important; min-height: 140px; }

    .chats-container {
        padding-top: 1rem !important; 
        padding-bottom: 1rem !important;
        height: 100%; 
        flex: 1;
    }
}