/* ===== متغيرات التصميم ===== */
:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-tertiary: #1a2233;
    --bg-card: #151d2e;
    --bg-hover: #1e293b;
    --bg-input: #0f1624;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-glow: 0 0 20px rgba(59, 130, 246, 0.3);
    --accent-gradient: linear-gradient(135deg, #3b82f6, #8b5cf6);
    --border: #1e293b;
    --success: #10b981;
    --error: #ef4444;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --font-ar: 'Segoe UI', Tahoma, Arial, sans-serif;
    --font-code: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

/* ===== إعادة تعيين ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-ar);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    direction: rtl;
    line-height: 1.6;
}

/* ===== شريط التمرير ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== حركات ===== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

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

@keyframes dotBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ===== هيكل الصفحة ===== */
.app-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ===== الهيدر ===== */
.app-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-icon {
    width: 44px;
    height: 44px;
    background: var(--accent-gradient);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    color: white;
    box-shadow: var(--accent-glow);
    font-family: var(--font-code);
}

.brand-text h1 {
    font-size: 20px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.brand-text p {
    font-size: 12px;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-btn {
    padding: 8px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font-ar);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.header-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--text-primary);
}

/* ===== المحتوى الرئيسي ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 20px;
}

/* ===== أوضاع العمل ===== */
.modes-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
    flex-wrap: wrap;
    justify-content: center;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text-secondary);
    font-family: var(--font-ar);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.mode-btn.active {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: var(--accent-glow);
}

.mode-btn .mode-icon {
    font-size: 18px;
}

/* ===== منطقة المحادثة ===== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 24px;
    min-height: 300px;
}

/* ===== شاشة الترحيب ===== */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    animation: fadeInUp 0.6s ease;
    text-align: center;
}

.welcome-icon {
    font-size: 56px;
    margin-bottom: 20px;
    animation: pulse 2.5s ease-in-out infinite;
}

.welcome-title {
    font-size: 30px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
}

.welcome-desc {
    color: var(--text-secondary);
    font-size: 16px;
    max-width: 500px;
    margin-bottom: 36px;
    line-height: 1.8;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    max-width: 520px;
    width: 100%;
}

.feature-card {
    padding: 20px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
    cursor: pointer;
    transition: all 0.25s ease;
}

.feature-card:hover {
    border-color: var(--accent);
    transform: translateY(-3px);
    box-shadow: var(--accent-glow);
    background: var(--bg-hover);
}

.feature-card .f-icon {
    font-size: 28px;
    margin-bottom: 10px;
}

.feature-card .f-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.feature-card .f-desc {
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== فقاعات الرسائل ===== */
.message {
    display: flex;
    gap: 12px;
    animation: slideIn 0.3s ease;
}

.message.user {
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 18px;
}

.message.user .msg-avatar {
    background: var(--accent-gradient);
}

.message.assistant .msg-avatar {
    background: var(--bg-hover);
    border: 1px solid var(--border);
}

.msg-body {
    max-width: 80%;
    min-width: 0;
}

.msg-bubble {
    padding: 16px 20px;
    border-radius: var(--radius);
    line-height: 1.8;
    font-size: 14px;
    word-wrap: break-word;
}

.message.user .msg-bubble {
    background: var(--accent);
    color: white;
    border-top-left-radius: 4px;
}

.message.assistant .msg-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border);
}

.msg-bubble p { margin-bottom: 10px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { padding-right: 20px; margin-bottom: 10px; }
.msg-bubble li { margin-bottom: 4px; }
.msg-bubble strong { color: #60a5fa; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
    margin: 14px 0 8px;
    color: var(--text-primary);
}
.msg-bubble h1:first-child, .msg-bubble h2:first-child, .msg-bubble h3:first-child {
    margin-top: 0;
}

/* ===== بلوكات الكود ===== */
.code-block {
    margin: 12px 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
    background: #0d1117;
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
}

.code-lang {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-code);
}

.copy-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-family: var(--font-ar);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}

.copy-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.copy-btn.copied {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.code-block pre {
    margin: 0;
    padding: 16px;
    overflow-x: auto;
    direction: ltr;
    text-align: left;
}

.code-block code {
    font-family: var(--font-code);
    font-size: 13px;
    line-height: 1.6;
    color: #e6edf3;
}

/* كود داخل السطر */
.msg-bubble code:not(.code-block code) {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-code);
    font-size: 12px;
    color: var(--accent);
    direction: ltr;
    display: inline;
}

.msg-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    padding: 0 4px;
}

.message.user .msg-body {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

/* ===== مؤشر الكتابة ===== */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    animation: fadeInUp 0.3s ease;
}

.typing-indicator .msg-avatar {
    background: var(--bg-hover);
    border: 1px solid var(--border);
}

.typing-dots {
    display: flex;
    gap: 5px;
    padding: 16px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
}

.typing-dots span:nth-child(1) { animation: dotBounce 1.2s infinite 0s; }
.typing-dots span:nth-child(2) { animation: dotBounce 1.2s infinite 0.15s; }
.typing-dots span:nth-child(3) { animation: dotBounce 1.2s infinite 0.3s; }

/* ===== منطقة الإدخال ===== */
.input-area {
    position: sticky;
    bottom: 0;
    background: var(--bg-primary);
    padding: 16px 0 8px;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: var(--accent-glow);
}

.input-wrapper textarea {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-ar);
    font-size: 15px;
    resize: none;
    max-height: 150px;
    min-height: 24px;
    line-height: 1.6;
    direction: rtl;
}

.input-wrapper textarea::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    background: var(--accent-gradient);
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: var(--accent-glow);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.input-hint {
    text-align: center;
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
}

/* ===== الفوتر ===== */
.app-footer {
    text-align: center;
    padding: 16px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}

.app-footer a {
    color: var(--accent);
    text-decoration: none;
}

.app-footer a:hover {
    text-decoration: underline;
}

/* ===== استجابة الشاشات الصغيرة ===== */
@media (max-width: 768px) {
    .app-header {
        padding: 12px 16px;
    }

    .brand-text h1 {
        font-size: 16px;
    }

    .main-content {
        padding: 16px 12px;
    }

    .modes-bar {
        gap: 6px;
    }

    .mode-btn {
        padding: 8px 14px;
        font-size: 12px;
    }

    .features-grid {
        grid-template-columns: 1fr;
    }

    .msg-body {
        max-width: 90% !important;
    }

    .welcome-title {
        font-size: 24px;
    }
}
