/* --- GEMINI LIGHT THEME --- */
:root {
    --bg-main: #FFFFFF;
    --bg-input: #F0F4F9; /* Gemini's signature light gray */
    --bg-user-bubble: #F0F4F9;
    
    --text-primary: #1F1F1F;
    --text-secondary: #444746;
    --text-placeholder: #727775;
    
    --btn-bg: #E3E3E3;
    --btn-bg-active: #1F1F1F;
    --btn-text: #1F1F1F;
    --btn-text-active: #FFFFFF;

    --border-color: #E3E3E3;
    --card-bg: #F8F9FA;
    
    --font-en: 'Inter', sans-serif;
    --font-ar: 'Tajawal', sans-serif;
    --font-quran: 'Amiri', serif;
    
    --welcome-gradient: linear-gradient(74deg, #4285f4 0, #9b72cb 9%, #d96570 20%, #d96570 24%, #9b72cb 35%, #4285f4 44%, #9b72cb 50%, #d96570 56%, #1F1F1F 75%, #1F1F1F 100%);
}

/* --- GEMINI DARK THEME --- */
[data-theme="dark"] {
    --bg-main: #131314;
    --bg-input: #1E1F20;
    --bg-user-bubble: #1E1F20;
    
    --text-primary: #E3E3E3;
    --text-secondary: #C4C7C5;
    --text-placeholder: #8E918F;
    
    --btn-bg: #333537;
    --btn-bg-active: #E3E3E3;
    --btn-text: #E3E3E3;
    --btn-text-active: #131314;

    --border-color: #333537;
    --card-bg: #1E1F20;
    
    --welcome-gradient: linear-gradient(74deg, #4285f4 0, #9b72cb 9%, #d96570 20%, #d96570 24%, #9b72cb 35%, #4285f4 44%, #9b72cb 50%, #d96570 56%, #E3E3E3 75%, #E3E3E3 100%);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-en);
    display: block; /* Removed centering from body so layout handles it */
    transition: background-color 0.3s ease, color 0.3s ease;
}

body[dir="rtl"] {
    font-family: var(--font-ar);
}

/* --- DESKTOP LAYOUT --- */
.main-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 280px;
    background-color: var(--bg-input); 
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    border-right: 1px solid var(--border-color);
    transition: width 0.3s ease;
    z-index: 20;
}

body[dir="rtl"] .sidebar {
    border-right: none;
    border-left: 1px solid var(--border-color);
}

.new-chat-btn {
    background-color: var(--bg-main);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    border-radius: 30px; 
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background-color 0.2s;
}

.new-chat-btn:hover {
    background-color: var(--btn-bg);
}

.sidebar-title {
    font-size: 0.8rem;
    color: var(--text-placeholder);
    font-weight: 600;
    margin-left: 12px;
    margin-bottom: 12px;
}

body[dir="rtl"] .sidebar-title {
    margin-left: 0;
    margin-right: 12px;
}

.history-item {
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background-color 0.2s;
}

.history-item:hover {
    background-color: var(--btn-bg);
    color: var(--text-primary);
}

/* --- APP CONTAINER (Right Side) --- */
.app-container {
    flex: 1; /* Takes up all remaining space */
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: var(--bg-main);
}

/* --- HEADER --- */
.modern-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    width: 100%;
    background: transparent;
    z-index: 10;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
}

.logo-area h1 {
    font-size: 1.2rem;
    font-weight: 500;
    letter-spacing: -0.5px;
}

.header-actions {
    display: flex;
    gap: 4px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 10px;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
}

.icon-btn:hover {
    background: var(--bg-input);
    color: var(--text-primary);
}

/* --- CHAT AREA --- */
.chat-container {
    flex: 1;
    width: 100%;
    overflow-y: auto;
    padding: 24px 20px 140px 20px;
    display: flex;
    flex-direction: column;
    align-items: center; /* Perfectly centers messages */
    scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar {
    width: 0px; /* Hide scrollbar for a cleaner look */
}

/* Restrict the width of the text so it's easy to read */
.message, .welcome-screen {
    width: 100%;
    max-width: 850px;
}

/* --- WELCOME SCREEN (Gemini Style) --- */
.welcome-screen {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 0; /* Padding left/right handled by max-width centering */
    margin-top: 10vh;
    animation: fadeIn 0.8s ease;
}

.welcome-screen .greeting {
    font-size: 3.5rem;
    font-weight: 500;
    letter-spacing: -1.5px;
    margin-bottom: 8px;
    background: var(--welcome-gradient);
    background-size: 400% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-screen .sub-greeting {
    font-size: 3.5rem;
    font-weight: 500;
    letter-spacing: -1.5px;
    color: var(--text-secondary);
}

/* Smaller font for Arabic to fit nicely */
body[dir="rtl"] .welcome-screen .greeting,
body[dir="rtl"] .welcome-screen .sub-greeting {
    font-size: 2.8rem;
    font-weight: 600;
    letter-spacing: 0;
}

/* --- MESSAGES --- */
.message {
    display: flex;
    margin-bottom: 32px;
}

.user-message {
    justify-content: flex-end;
}

.user-message .message-content {
    background-color: var(--bg-user-bubble);
    color: var(--text-primary);
    padding: 14px 20px;
    border-radius: 24px;
    max-width: 80%;
    font-size: 1rem;
    line-height: 1.5;
}

.ai-message {
    justify-content: flex-start;
}

.ai-message .message-content {
    background-color: transparent;
    color: var(--text-primary);
    max-width: 95%;
    font-size: 1.05rem;
    line-height: 1.8;
}

/* --- CITATION CARDS --- */
.source-card {
    margin-top: 24px;
    background-color: var(--card-bg); 
    border-radius: 16px;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.source-card .source-title {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.source-card .source-text {
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.6;
}

/* --- BOTTOM INPUT AREA (FLAT PILL) --- */
.input-area {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center; /* Centers the input box */
    padding: 16px 20px;
    background: linear-gradient(to top, var(--bg-main) 70%, transparent);
}

.input-wrapper {
    width: 100%;
    max-width: 850px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.input-container {
    display: flex;
    align-items: flex-end;
    width: 100%;
    background-color: var(--bg-input); /* Flat background */
    border-radius: 32px; /* Perfect pill shape */
    padding: 12px 16px 12px 24px;
    transition: background-color 0.3s;
}

body[dir="rtl"] .input-container {
    padding: 12px 24px 12px 16px;
}

.input-container textarea {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1.05rem;
    resize: none;
    outline: none;
    padding: 8px 0;
    max-height: 200px;
    overflow-y: auto;
}

.input-container textarea::placeholder {
    color: var(--text-placeholder);
}

.send-btn {
    background-color: var(--btn-bg-active);
    color: var(--btn-text-active);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    margin-bottom: 2px;
    margin-left: 12px;
    transition: all 0.2s;
}

body[dir="rtl"] .send-btn {
    margin-left: 0;
    margin-right: 12px;
}

.send-btn:disabled {
    background-color: var(--btn-bg);
    color: var(--btn-text);
    cursor: not-allowed;
}

.send-btn:hover:not(:disabled) {
    opacity: 0.8;
}

.disclaimer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 16px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- MOBILE RESPONSIVENESS --- */
@media (max-width: 800px) {
    .sidebar {
        display: none; 
    }
    
    #mobile-menu-btn {
        display: inline-block !important; 
    }
    
    .welcome-screen .greeting, .welcome-screen .sub-greeting {
        font-size: 2.5rem;
    }

    body[dir="rtl"] .welcome-screen .greeting,
    body[dir="rtl"] .welcome-screen .sub-greeting {
        font-size: 2rem;
    }
}