:root {
    --bg-color: #0a0e17;
    --text-color: #e0e6ed;
    --primary-color: #007bff;
    --primary-glow: #00bfff;
    --stop-color: #dc3545; /* لون زر الإيقاف */
    --stop-glow: #ff6b6b;
    --user-message-bg: rgba(0, 123, 255, 0.4);
    --ai-message-bg: rgba(44, 62, 80, 0.5);
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --overlay-bg: rgba(0, 0, 0, 0.7);
    --msg-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Cairo', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden; /* منع التمرير العام للصفحة */
    height: 100vh;
}

/* Glassmorphism Class */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid var(--glass-border);
    border-radius: 15px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

/* Main Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    margin: 10px 10px 5px 10px;
    flex-shrink: 0; /* منع الهيدر من التقلص */
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.1rem;
}

.logo img {
    height: 30px;
}

.btn-view-platform {
    color: #ccc;
    text-decoration: none;
    font-size: 0.85rem;
    transition: 0.3s;
    padding: 5px 10px;
}

.btn-view-platform:hover {
    color: var(--primary-glow);
    text-shadow: 0 0 5px var(--primary-glow);
}

.header-left {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn-new-chat, #sendBtn, .btn-confirm-delete {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 18px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.btn-new-chat:hover, #sendBtn:hover:not(.generating), .btn-confirm-delete:hover {
    background-color: var(--primary-glow);
    box-shadow: 0 0 12px var(--primary-glow);
}

/* تنسيق زر الإيقاف */
#sendBtn.generating {
    background-color: var(--stop-color);
    box-shadow: 0 0 5px var(--stop-glow);
}

#sendBtn.generating:hover {
    background-color: #bd2130;
    box-shadow: 0 0 12px var(--stop-glow);
}

.mobile-menu-toggle {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.4rem;
    cursor: pointer;
    display: none;
    padding: 5px;
}

/* Main Content Area */
.main-content {
    display: flex;
    flex: 1;
    padding: 5px 10px 10px 10px;
    overflow: hidden; /* مهم للتمرير الداخلي */
    position: relative;
}

/* Sidebar */
.sidebar {
    width: 280px;
    display: flex;
    flex-direction: column;
    margin-left: 10px;
    height: 100%;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 15px;
    border-bottom: 1px solid var(--glass-border);
}

.sidebar-header h3 {
    font-size: 1rem;
    color: #aaa;
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

/* تحسين شريط التمرير */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.2);
}

.conversation-item {
    background: rgba(255, 255, 255, 0.01);
    padding: 10px 12px;
    margin-bottom: 6px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: 0.2s;
    border: 1px solid transparent;
}

.conversation-item:hover {
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--glass-border);
}

.conversation-item.active {
    background: rgba(0, 123, 255, 0.1);
    border-color: rgba(0, 123, 255, 0.3);
}

.conversation-item span {
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 85%;
    color: #ccc;
}

.btn-delete-conv {
    background: none;
    border: none;
    color: #ff4d4d;
    cursor: pointer;
    font-size: 1.1rem;
    opacity: 0;
    transition: 0.2s;
    padding: 0 5px;
}

.conversation-item:hover .btn-delete-conv {
    opacity: 1;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--glass-border);
    text-align: center;
}

.about-us-link {
    color: #888;
    text-decoration: none;
    font-size: 0.8rem;
    transition: 0.3s;
}
.about-us-link:hover {
    color: #fff;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px 10px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

/* تنسيق فقاعة الرسالة العام */
.chat-bubble-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    position: relative;
    animation: fadeIn 0.3s ease;
}

.chat-bubble {
    padding: 10px 15px;
    border-radius: 15px;
    font-size: 0.9rem;
    line-height: 1.6;
    box-shadow: var(--msg-shadow);
}

/* زر النسخ */
.msg-copy-btn {
    position: absolute;
    top: 5px;
    background: rgba(0, 0, 0, 0.3);
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    padding: 4px 7px;
    border-radius: 5px;
    font-size: 0.75rem;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 10;
}

.msg-copy-btn:hover {
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
}

/* إظهار الزر عند الحوم على الحاوية */
.chat-bubble-wrapper:hover .msg-copy-btn {
    opacity: 1;
}

/* تنسيقات خاصة بالمستخدم */
.user-message-wrapper {
    align-self: flex-end;
}

.user-message-wrapper .chat-bubble {
    background-color: var(--user-message-bg);
    color: #fff;
    border-bottom-right-radius: 4px;
    border: 1px solid rgba(0, 123, 255, 0.2);
}

/* زر النسخ للمستخدم يسار الفقاعة */
.user-message-wrapper .msg-copy-btn {
    left: -35px;
}

/* تنسيقات خاصة بالذكاء الاصطناعي */
.ai-message-wrapper {
    align-self: flex-start;
}

.ai-message-wrapper .chat-bubble {
    background-color: var(--ai-message-bg);
    color: var(--text-color);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--glass-border);
}

/* زر النسخ للذكاء الاصطناعي يمين الفقاعة */
.ai-message-wrapper .msg-copy-btn {
    right: -35px;
}

.typing-indicator {
    color: #888;
    font-size: 0.75rem;
    margin-right: 15px;
    margin-top: -5px;
    animation: fadeIn 0.3s ease;
}

/* Input Section */
.input-section {
    margin: 5px 10px 10px 10px;
    padding: 5px 10px;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

#userInput {
    flex: 1;
    background: none;
    border: none;
    color: #fff;
    padding: 10px;
    font-size: 0.95rem;
    outline: none;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--overlay-bg);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    padding: 20px;
}

.modal-overlay.open {
    display: flex;
    opacity: 1;
}

.modal {
    width: 100%;
    max-width: 450px;
    padding: 25px;
    position: relative;
    animation: slideUp 0.3s ease;
    background: rgba(15, 20, 30, 0.9);
    backdrop-filter: blur(20px);
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    color: #888;
    font-size: 1.3rem;
    cursor: pointer;
    transition: 0.2s;
}
.close-modal:hover {
    color: #fff;
}

.modal h2 {
    margin-bottom: 15px;
    color: var(--primary-glow);
    font-size: 1.3rem;
}

.modal p {
    font-size: 0.9rem;
    line-height: 1.7;
    margin-bottom: 10px;
    color: #ccc;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.btn-cancel {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--glass-border);
    color: #ccc;
    padding: 8px 18px;
    border-radius: 20px;
    cursor: pointer;
    transition: 0.3s;
    font-size: 0.9rem;
}

.btn-cancel:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Mobile Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    backdrop-filter: blur(3px);
}

/* Responsive Design */
@media (max-width: 768px) {
    header {
        padding: 8px 15px;
        margin: 5px;
    }
    
    .logo span {
        display: none; /* إخفاء اسم المنصة بجانب اللوجو على الموبايل */
    }

    .mobile-menu-toggle {
        display: block;
    }
    
    .btn-new-chat {
        padding: 7px 15px;
        font-size: 0.8rem;
    }

    .sidebar {
        position: fixed;
        top: 0;
        right: -300px; /* مخفي قبالة الشاشة */
        z-index: 1000;
        height: 100vh;
        margin: 0;
        border-radius: 0;
        width: 280px;
        background: rgba(10, 14, 23, 0.95);
    }

    .sidebar.open {
        transform: translateX(-300px); /* تحريكه للداخل (الاتجاه لليسار لأن الـ dir=rtl) */
    }
    
    .sidebar.open + .sidebar-overlay {
        display: block;
    }

    .main-content {
        padding: 5px;
    }

    .chat-area {
        width: 100%;
    }

    .chat-bubble-wrapper {
        max-width: 85%;
    }

    /* جعل أيقونات النسخ تظهر دائماً على الموبايل لسهولة الوصول */
    .msg-copy-btn {
        opacity: 1;
        background: rgba(0, 0, 0, 0.2);
    }
    
    .user-message-wrapper .msg-copy-btn {
        left: 5px;
        top: -25px;
    }
    
    .ai-message-wrapper .msg-copy-btn {
        right: 5px;
        top: -25px;
    }
    
    .chat-messages {
        padding-top: 25px; /* مساحة للأيقونات العلوية */
    }
}
