/* تعريف متغيرات الألوان عشان يبقى سهل نعدل */
:root {
    --bg-main: #f0f2f5; /* خلفية فاتحة جداً للصفحة */
    --bg-chat: #ffffff; /* خلفية منطقة الشات */
    --text-primary: #202124; /* لون النص الأساسي الداكن */
    --text-secondary: #5f6368; /* لون نص ثانوي */
    --accent-color: #1a73e8; /* الأزرق المميز لجوجل/جيمناي */
    --user-msg-bg: #e8f0fe; /* خلفية رسالة المستخدم (أزرق فاتح جداً) */
    --bot-msg-bg: #ffffff; /* خلفية رسالة البوت (أبيض) */
    --input-shadow: 0 1px 6px 0 rgba(32, 33, 36, 0.28); /* ظل منطقة الإدخال */
    --border-radius-large: 24px;
    --border-radius-small: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Roboto', sans-serif; /* استخدام خط Roboto */
}

body, html {
    height: 100%;
    background-color: var(--bg-main);
    color: var(--text-primary);
}

/* الحاوية الرئيسية - Flexbox عشان تاخد الطول كله */
.main-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1000px; /* أقصى عرض عشان الشاشة الكبيرة */
    margin: 0 auto; /* توسيط في الشاشة */
    background-color: var(--bg-chat);
    box-shadow: 0 0 20px rgba(0,0,0,0.05);
}

/* --- Header --- */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
    border-bottom: 1px solid #e0e0e0;
    background: var(--bg-chat);
}

.header-title {
    font-size: 1.2rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sparkle-icon {
    font-size: 1.4rem;
}

/* زرار نيو شات الجديد */
.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 8px; /* مسافة بين الأيقونة والكلمة */
    background-color: #dde3ea; /* رمادي مزرق فاتح جداً */
    color: #444746; /* لون النص رصاصي غامق */
    border: none;
    padding: 10px 20px; /* مساحة داخلية مريحة */
    border-radius: 24px; /* كبسولة كاملة الاستدارة */
    font-family: 'Roboto', sans-serif;
    font-size: 0.9rem;
    font-weight: 500; /* خط سميك سنة */
    cursor: pointer;
    transition: all 0.2s ease;
}

.new-chat-btn:hover {
    background-color: #c2c7cf; /* يغمق سنة لما تقف عليه */
    color: #1f1f1f; /* النص يسود */
    box-shadow: 0 1px 3px rgba(0,0,0,0.1); /* ظل خفيف */
}

.new-chat-btn:active {
    transform: scale(0.96); /* حركة ضغطة صغيرة */
}

.new-chat-btn svg {
    fill: currentColor; /* الأيقونة تاخد نفس لون الكلام */
}

/* --- Chat Area --- */
.chat-area {
    flex-grow: 1; /* ياخد باقي المساحة المتاحة */
    overflow-y: auto; /* سكرول للرسائل */
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

/* --- Messages --- */
.message {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    max-width: 85%; /* الرسالة متفرشش ع الآخر */
    animation: fadeIn 0.3s ease-in;
}

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

/* محتوى الرسالة */
.message-content {
    padding: 14px 18px;
    border-radius: var(--border-radius-large);
    font-size: 1rem;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
}

/* ستايل رسالة المستخدم */
.user-message {
    align-self: flex-end; /* تيجي على اليمين */
    flex-direction: row-reverse; /* نعكس عشان الأفاتار */
}

.user-message .message-content {
    background-color: var(--user-msg-bg);
    color: var(--text-primary);
    border-bottom-right-radius: 4px; /* حركة جيمناي في الزاوية */
}

/* ستايل رسالة البوت */
.bot-message {
    align-self: flex-start; /* تيجي على الشمال */
}

.bot-message .message-content {
    background-color: var(--bot-msg-bg);
    color: var(--text-primary);
    border: 1px solid #e0e0e0; /* بوردر خفيف للبوت */
    border-bottom-left-radius: 4px;
}

/* الأفاتار */
.avatar-container {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 1.2rem;
}

.bot-avatar { color: var(--accent-color); }
.user-avatar { color: var(--text-secondary); }

/* رسالة الترحيب */
.welcome-message .message-content {
    background: transparent;
    border: none;
    padding-left: 0;
}
.welcome-message h3 {
    margin-bottom: 8px;
    color: var(--accent-color);
}

/* --- Input Area (Floating Pill) --- */
.input-area {
    padding: 20px 25px 30px; /* مساحة تحت عشان الموبايل */
    background: var(--bg-chat);
    position: sticky;
    bottom: 0;
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: var(--bg-chat);
    border-radius: 30px; /* شكل الكبسولة */
    padding: 8px 15px;
    box-shadow: var(--input-shadow); /* الظل العائم */
    border: 1px solid #e0e0e0;
    transition: box-shadow 0.3s;
}

.input-wrapper:focus-within {
    box-shadow: 0 2px 12px rgba(26, 115, 232, 0.2);
    border-color: var(--accent-color);
}

textarea#user-input {
    flex-grow: 1;
    border: none;
    background: none;
    resize: none; /* منع تكبير المربع */
    padding: 8px;
    font-size: 1rem;
    max-height: 150px;
    outline: none;
    font-family: 'Roboto', sans-serif;
}

.send-button {
    background: var(--accent-color);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-left: 8px;
    fill: white;
}

.send-button:hover:not(:disabled) {
    background-color: #1557b0;
    transform: scale(1.05);
}

.send-button:disabled {
    background-color: #e0e0e0;
    fill: #a0a0a0;
    cursor: default;
}

/* --- Markdown Styling for Bot Responses --- */
/* تنسيق القوائم والنصوص العريضة داخل رد البوت */
.bot-message .message-content ul, .bot-message .message-content ol {
    margin-left: 25px;
    margin-top: 10px;
}
.bot-message .message-content li {
    margin-bottom: 5px;
}
.bot-message .message-content strong {
    font-weight: 700;
    color: var(--accent-color);
}

/* --- Loading/Thinking Indicator --- */
.thinking {
    display: flex;
    gap: 5px;
    padding: 10px 0;
}
.dot {
    width: 8px;
    height: 8px;
    background: var(--accent-color);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
    opacity: 0.7;
}
.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.0); }
}