/* ==========================================================
   🌙 الوضع الليلي (Dark mode)
   - بيشتغل لما <html data-theme="dark"> (السكربت الصغير في <head> بيحطها قبل ما الصفحة تترسم:
     اختيار الزائر المحفوظ في localStorage 'orsozoxi_theme'، ولو مفيش: إعداد الجهاز).
   - style.css زي ما هو (الوضع النهاري)؛ الملف ده بس بيغيّر الألوان فوقه.
   - ستايلات كتير مكتوبة جوه HTML (style="...")، فبنغلبها بـ !important وبمحددات [style*="..."].
   ========================================================== */

html[data-theme="dark"] {
    color-scheme: dark; /* أزرار ومربعات اختيار وسكرول المتصفح نفسه بتبقى غامقة */
    --primary-color: #3e2723;
    --text-color: #e8e2dc;
    --bg-color: #15100e;
    --chat-bg-user: #1d2a1f;
    --chat-bg-ai: #1f1916;
    --dm-surface: #241d1a;     /* النوافذ وصندوق الكتابة */
    --dm-surface-2: #1a1512;   /* مربعات جوه النوافذ */
    --dm-border: #3d332d;
    --dm-text: #e8e2dc;
    --dm-muted: #b3a89f;
    --dm-heading: #ffcc80;
}

/* --- الخلفية: نفس الخشب، بطبقة أغمق --- */
html[data-theme="dark"] body {
    background-image:
        linear-gradient(rgba(16, 11, 9, 0.88), rgba(10, 13, 18, 0.95)),
        url('/images/background.png');
}

/* --- القائمة الجانبية (غامقة أصلاً، بس أغمق شوية عشان تتساوى مع الخلفية) --- */
html[data-theme="dark"] .sidebar { background-color: #1f1512; }
html[data-theme="dark"] #user-profile-section { background: #1f1512 !important; }
html[data-theme="dark"] .mobile-header { background-color: #1a1210 !important; }

/* --- الرسائل --- */
html[data-theme="dark"] .message.ai { border-color: var(--dm-border); }
html[data-theme="dark"] .message.user { border: 1px solid #2c4030; }
html[data-theme="dark"] .message-content { color: var(--dm-text); }
html[data-theme="dark"] .message-content h1,
html[data-theme="dark"] .message-content h2,
html[data-theme="dark"] .message-content h3,
html[data-theme="dark"] .message-content h4 { color: var(--dm-heading); border-bottom-color: rgba(255, 204, 128, 0.35); }
html[data-theme="dark"] .message-content strong,
html[data-theme="dark"] .message-content b { color: #ff8a80 !important; }
html[data-theme="dark"] .message-content a { color: #90caf9; }
html[data-theme="dark"] .message-content a:visited { color: #ce93d8; }
html[data-theme="dark"] .message-content blockquote { border-inline-start: 3px solid rgba(255, 179, 0, 0.5); padding-inline-start: 10px; color: #d6ccc3; }
html[data-theme="dark"] .message-content code,
html[data-theme="dark"] .message-content pre { background: rgba(255, 255, 255, 0.06); border-radius: 4px; }
html[data-theme="dark"] .message-content hr { border-color: var(--dm-border); }
html[data-theme="dark"] .message-content table { border-collapse: collapse; }
html[data-theme="dark"] .message-content th,
html[data-theme="dark"] .message-content td { border: 1px solid var(--dm-border); padding: 4px 8px; }
html[data-theme="dark"] .typing-cursor::after { color: #ffb300; }
html[data-theme="dark"] .message-time { color: var(--dm-muted) !important; }
html[data-theme="dark"] .rating-buttons { border-color: var(--dm-border) !important; }
html[data-theme="dark"] .answer-sources { border-top-color: rgba(255, 255, 255, 0.12) !important; }
html[data-theme="dark"] .answer-sources > span { color: var(--dm-muted) !important; }
html[data-theme="dark"] .src-tag { background-color: #2a221e !important; color: #e0d6cc !important; border-color: var(--dm-border) !important; }
html[data-theme="dark"] .src-tag i { color: #d4a85a !important; }
html[data-theme="dark"] .suggestions-container button { color: var(--dm-text) !important; }

/* أزرار نسخ / PDF / نقل تحت الإجابة */
html[data-theme="dark"] .message-actions .copy-btn,
html[data-theme="dark"] .message-actions .pdf-btn,
html[data-theme="dark"] .message-actions .move-msg-btn {
    background: #2c2420; color: var(--dm-text); border: 1px solid var(--dm-border); border-radius: 4px;
}
html[data-theme="dark"] .message-actions .copy-btn:hover,
html[data-theme="dark"] .message-actions .pdf-btn:hover,
html[data-theme="dark"] .message-actions .move-msg-btn:hover { background: #3a302b; }

/* الصور والفيديو والصوت تحت الإجابة (media.js) */
html[data-theme="dark"] .answer-media { border-top-color: rgba(255, 255, 255, 0.12); }
html[data-theme="dark"] .om-head { color: var(--dm-muted); }
html[data-theme="dark"] .om-card { background: #2a221e; border-color: var(--dm-border); }
html[data-theme="dark"] .om-title { color: #e0d6cc; }

/* شاشة البداية */
html[data-theme="dark"] .starter-title { color: var(--dm-heading); }
html[data-theme="dark"] .starter-chip { color: var(--dm-text); }
html[data-theme="dark"] .starter-guest { color: #c8bdb3; border-top-color: rgba(255, 255, 255, 0.15); }
html[data-theme="dark"] .starter-login { background: #5d4037; }
html[data-theme="dark"] .starter-login:hover { background: #6d4c41; }

/* عنوان المحادثة فوق الشات */
html[data-theme="dark"] #chat-header-title {
    background-color: rgba(255, 179, 0, 0.12) !important; color: #ffb74d !important; border-color: rgba(255, 179, 0, 0.3) !important;
}

/* الإعلانات */
html[data-theme="dark"] .announcement-info { background: #10243a; color: #bbdefb; border-color: #1e4a73; }
html[data-theme="dark"] .announcement-success { background: #142a17; color: #c8e6c9; border-color: #2e5e33; }
html[data-theme="dark"] .announcement-warning { background: #33230d; color: #ffe0b2; border-color: #6b4a14; }
html[data-theme="dark"] #maintenance-alert { background-color: #3a1517 !important; color: #ffcdd2 !important; border-color: #7f2a2e !important; }

/* --- صندوق الكتابة + الكيبورد القبطي + "جارٍ تحضير الرد" --- */
html[data-theme="dark"] .input-box-container { background: var(--dm-surface) !important; box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5) !important; }
html[data-theme="dark"] .form-control,
html[data-theme="dark"] input[type="text"],
html[data-theme="dark"] textarea { color: var(--dm-text) !important; }
html[data-theme="dark"] ::placeholder { color: #8c8079 !important; }
html[data-theme="dark"] .send-btn:hover { background-color: #5d4037; }

html[data-theme="dark"] .coptic-keyboard { background-color: var(--dm-surface-2) !important; box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5); }
html[data-theme="dark"] .coptic-key { background-color: #2c2420 !important; color: #f3ebe3 !important; border-color: var(--dm-border) !important; box-shadow: none; }
html[data-theme="dark"] .coptic-key:active { background-color: #ffb300 !important; color: #1a1210 !important; }
html[data-theme="dark"] .coptic-key.control-key { background-color: #3a302b !important; color: var(--dm-heading) !important; }
html[data-theme="dark"] .coptic-key.kbd-tab { background-color: #2c2420 !important; color: #d7ccc8 !important; border-color: var(--dm-border) !important; }
html[data-theme="dark"] .coptic-key.kbd-tab.active { background-color: #5d4037 !important; color: #ffb300 !important; border-color: #5d4037 !important; }
html[data-theme="dark"] .kbd-tabs { background: var(--dm-surface-2); }

html[data-theme="dark"] #typing-indicator { background: rgba(36, 29, 26, 0.88) !important; color: #ffb74d !important; }
html[data-theme="dark"] #pull-to-refresh > div { background: var(--dm-surface) !important; }
html[data-theme="dark"] #refresh-icon { color: #ffb300 !important; }

/* --- النوافذ (modal) --- */
html[data-theme="dark"] .modal-content {
    background: var(--dm-surface) !important; color: var(--dm-text);
    border-color: var(--dm-border) !important; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6) !important;
}
html[data-theme="dark"] .modal h3,
html[data-theme="dark"] .modal h2,
html[data-theme="dark"] .modal-content [style*="color: #3e2723"]:not(button),
html[data-theme="dark"] .modal-content [style*="color:#3e2723"]:not(button) { color: var(--dm-heading) !important; }
html[data-theme="dark"] .modal-content [style*="color: #555"],
html[data-theme="dark"] .modal-content [style*="color: #666"],
html[data-theme="dark"] .modal-content [style*="color:#666"],
html[data-theme="dark"] .modal-content [style*="color: #777"],
html[data-theme="dark"] .modal-content [style*="color:#777"] { color: #c8bdb3 !important; }
html[data-theme="dark"] .modal-content strong[style*="color:#333"] { color: var(--dm-text) !important; }
html[data-theme="dark"] .modal input,
html[data-theme="dark"] .modal select,
html[data-theme="dark"] .modal textarea {
    background: var(--dm-surface-2) !important; color: var(--dm-text) !important; border: 1px solid #4a3f38 !important;
}
html[data-theme="dark"] .modal input[type="checkbox"] { accent-color: #ffb300 !important; }
html[data-theme="dark"] .modal-content label { color: var(--dm-text) !important; }
html[data-theme="dark"] .modal button:not([style*="background"]) { background: #5d4037; }
html[data-theme="dark"] .modal button:not([style*="background"]):hover { background: #6d4c41; }
html[data-theme="dark"] .modal button[style*="background:var(--primary-color)"],
html[data-theme="dark"] .modal button[style*="background: var(--primary-color)"] { background: #5d4037 !important; }
html[data-theme="dark"] .modal button[style*="#ccc"],
html[data-theme="dark"] .modal button[style*="#9e9e9e"] { background: #4a403a !important; color: #eee !important; }
html[data-theme="dark"] .switch-auth-link { color: #d7ccc8; }
html[data-theme="dark"] #forgot-link { color: #4db6ac !important; }
html[data-theme="dark"] .auth-lang-switch { color: #bcaaa4; }
html[data-theme="dark"] .auth-lang-switch:hover { color: var(--dm-heading); }
html[data-theme="dark"] .auth-or::before,
html[data-theme="dark"] .auth-or::after { border-top-color: var(--dm-border); }
html[data-theme="dark"] .modal #apple-btn { background: #fff; color: #000; } /* إرشادات Apple: زرار أبيض على الخلفية الغامقة */
html[data-theme="dark"] .modal #apple-btn:hover { background: #e8e8e8; }

/* مربعات رمادية/ملونة فاتحة جوه النوافذ */
html[data-theme="dark"] .modal-content [style*="background: #f9f9f9"],
html[data-theme="dark"] .modal-content [style*="background: #f5f5f5"] { background: var(--dm-surface-2) !important; }
/* (بالـ id: لما الجافاسكريبت يفتحها، المتصفح بيعيد كتابة style والألوان بتبقى rgb(...) فـ [style*=] مبتلقطهاش) */
html[data-theme="dark"] #sec-username,
html[data-theme="dark"] #sec-password,
html[data-theme="dark"] #sec-email { background: var(--dm-surface-2) !important; }
html[data-theme="dark"] #premium-dates { background: #2e2512 !important; color: #e0d6cc !important; }
html[data-theme="dark"] #sec-delete { background: #3a1517 !important; }
html[data-theme="dark"] .modal-content [style*="border-top: 1px solid #ddd"],
html[data-theme="dark"] .modal-header { border-color: var(--dm-border) !important; }

/* نافذة الملف الشخصي (style.css بيجبر النص بني غامق بـ !important) */
html[data-theme="dark"] #profile-modal .modal-content,
html[data-theme="dark"] #profile-modal p,
html[data-theme="dark"] #profile-modal span,
html[data-theme="dark"] #profile-modal strong,
html[data-theme="dark"] #profile-modal div { color: var(--dm-text) !important; }
html[data-theme="dark"] #profile-modal h3 { color: var(--dm-heading) !important; }
html[data-theme="dark"] #profile-modal button[style*="background: #eee"] { background: #3a302b !important; color: var(--dm-text) !important; }
html[data-theme="dark"] #profile-modal button[style*="background: #eee"] span { color: var(--dm-text) !important; }
html[data-theme="dark"] #profile-modal button[style*="background: #fff3e0"] { background: #33230d !important; }
html[data-theme="dark"] #profile-modal button[style*="background: #fff3e0"] span { color: #ffb74d !important; }
html[data-theme="dark"] #profile-modal button[style*="background: #ffebee"] { background: #3a1517 !important; }
html[data-theme="dark"] #profile-modal button[style*="background: #ffebee"] span,
html[data-theme="dark"] #sec-delete p { color: #ff8a80 !important; }
html[data-theme="dark"] #profile-modal input { color: var(--dm-text) !important; }

/* تفاصيل المحادثة (لوحة الإدارة جوه الموقع) */
html[data-theme="dark"] #chat-history-container { background: var(--dm-surface-2) !important; }
html[data-theme="dark"] .chat-msg.user { background-color: #10243a; color: var(--dm-text); }
html[data-theme="dark"] .chat-msg.ai { background-color: #1f1916; color: var(--dm-text); border-color: var(--dm-border); }
html[data-theme="dark"] .msg-label { color: var(--dm-muted); }

/* رسائل التنبيه/التأكيد + قائمة اللغات (script.js / translations.js) */
html[data-theme="dark"] .site-popup { background: var(--dm-surface); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6); }
html[data-theme="dark"] .site-popup-msg { color: var(--dm-text); }
html[data-theme="dark"] .site-popup-ok { background: #5d4037; }
html[data-theme="dark"] .site-popup-cancel { background: #3a302b; color: #eee; }
html[data-theme="dark"] .lang-picker-close:hover { color: #ddd; }

/* كارت "اشترك" اللي بيظهر في الشات لما الأسئلة تخلص */
html[data-theme="dark"] .chat-container [style*="background: #fff3e0"] { background: #33230d !important; }
html[data-theme="dark"] .chat-container [style*="background: #fff3e0"] [style*="color: #555"] { color: #c8bdb3 !important; }

/* تنبيه "الموقع في مرحلة التشغيل التجريبي" (أحمر مكتوب جوه script.js) */
html[data-theme="dark"] .message-content [style*="#dc3545"] { color: #ff6b6b !important; }

/* زرار "إيقاف التجديد التلقائي" + تنبيه "التجديد التلقائي متوقف" في الملف الشخصي (بيترسموا من script.js) */
html[data-theme="dark"] #profile-modal .stop-renew-btn { color: #ff8a80 !important; border-color: #ff8a80 !important; }
html[data-theme="dark"] #profile-modal .stop-renew-btn:hover { background: rgba(255, 138, 128, 0.12) !important; }
html[data-theme="dark"] #profile-modal .auto-renew-off { color: #ffca28 !important; }

/* 📊 قسم "نشاطك" في نافذة الملف الشخصي */
html[data-theme="dark"] #profile-modal .profile-stats { background: var(--dm-surface-2); }
html[data-theme="dark"] #profile-modal .stat-tile { background: var(--dm-surface); border-color: var(--dm-border); }
html[data-theme="dark"] #profile-modal .profile-stats h4,
html[data-theme="dark"] #profile-modal .stat-value { color: var(--dm-heading) !important; }
html[data-theme="dark"] #profile-modal .stat-label,
html[data-theme="dark"] #profile-modal .stat-value small,
html[data-theme="dark"] #profile-modal .stat-chart-title,
html[data-theme="dark"] #profile-modal .stat-dates b,
html[data-theme="dark"] #profile-modal .stats-note,
html[data-theme="dark"] #profile-modal .stats-empty { color: var(--dm-muted) !important; }
html[data-theme="dark"] #profile-modal .stat-bars { border-bottom-color: var(--dm-border); }
html[data-theme="dark"] #profile-modal .stat-bar span { background: #ffb300; }
html[data-theme="dark"] #profile-modal .stat-bar:hover span { background: #ffcc80; }
html[data-theme="dark"] #profile-modal .stat-lines i { color: #ffb300; }
html[data-theme="dark"] #profile-modal .stat-dates span.today b { color: #ffcc80 !important; }

/* 🧾 قسم "الاشتراكات" */
html[data-theme="dark"] #profile-modal .sub-event { background: var(--dm-surface-2); }
html[data-theme="dark"] #profile-modal .sub-event.sub-off { border-inline-start-color: var(--dm-border); }
html[data-theme="dark"] #profile-modal .sub-event > i { color: #ffb300; }
html[data-theme="dark"] #profile-modal .sub-event-title { color: var(--dm-heading) !important; }
html[data-theme="dark"] #profile-modal .sub-event-plan,
html[data-theme="dark"] #profile-modal .sub-event-period,
html[data-theme="dark"] #profile-modal .sub-event time { color: var(--dm-muted) !important; }

/* 🗂️ تبويبات نافذة الملف الشخصي */
html[data-theme="dark"] #profile-modal .profile-tabs { border-color: var(--dm-border); }
html[data-theme="dark"] #profile-modal .profile-tabs button { background: transparent !important; }   /* قاعدة ".modal button" بتلوّنها بني */
html[data-theme="dark"] #profile-modal .profile-tabs button,
html[data-theme="dark"] #profile-modal .profile-tabs button span { color: var(--dm-muted) !important; }
html[data-theme="dark"] #profile-modal .profile-tabs i { color: var(--dm-muted) !important; }
html[data-theme="dark"] #profile-modal .profile-tabs button:hover { background: rgba(255, 255, 255, 0.06) !important; }
html[data-theme="dark"] #profile-modal .profile-tabs button[aria-selected="true"] { background: #3a2e28 !important; }
html[data-theme="dark"] #profile-modal .profile-tabs button[aria-selected="true"],
html[data-theme="dark"] #profile-modal .profile-tabs button[aria-selected="true"] span { color: var(--dm-heading) !important; }
html[data-theme="dark"] #profile-modal .profile-tabs button[aria-selected="true"] i { color: #ffb300 !important; }
html[data-theme="dark"] #profile-modal button.profile-back,
html[data-theme="dark"] #profile-modal button.profile-back span { color: var(--dm-text) !important; }
@media (max-width: 640px) {
    html[data-theme="dark"] #profile-modal .profile-tabs button,
    html[data-theme="dark"] #profile-modal .profile-tabs button[aria-selected="true"] { background: var(--dm-surface-2) !important; }
    html[data-theme="dark"] #profile-modal .profile-tabs button[aria-selected="true"],
    html[data-theme="dark"] #profile-modal .profile-tabs button[aria-selected="true"] span { color: var(--dm-text) !important; }
    html[data-theme="dark"] #profile-modal .profile-tabs button[aria-selected="true"] i { color: var(--dm-muted) !important; }
    html[data-theme="dark"] #profile-modal button.profile-back:hover { background: rgba(255, 255, 255, 0.06) !important; }
}

/* 📱 قائمة الأجهزة */
html[data-theme="dark"] .device-row { background: var(--dm-surface); border-color: var(--dm-border); }
html[data-theme="dark"] label.device-row:has(input:checked) { background: #33281f; border-color: #ffb300; }
html[data-theme="dark"] .device-row > i { color: #ffb300 !important; }
html[data-theme="dark"] .device-info b { color: var(--dm-text) !important; }
html[data-theme="dark"] .device-info small,
html[data-theme="dark"] .device-note { color: var(--dm-muted) !important; }
html[data-theme="dark"] #profile-modal .device-current { color: #81c784 !important; }
html[data-theme="dark"] .modal button.device-remove,
html[data-theme="dark"] #profile-modal button.device-remove { color: #ff8a80 !important; border-color: #ff8a80 !important; }
/* القسم بيتفتح من JS (style بيتكتب من جديد كـ rgb()، فقاعدة [style*="#f5f5f5"] مابتمسكوش) */
html[data-theme="dark"] #sec-devices,
html[data-theme="dark"] #sec-2fa { background: var(--dm-surface-2) !important; }

/* 🔐 التحقق بخطوتين */
html[data-theme="dark"] #two-factor-modal h3 { color: var(--dm-heading) !important; }
html[data-theme="dark"] .modal input.tfa-code-input { background: var(--dm-surface-2); color: var(--dm-text) !important; border-color: var(--dm-border); }
html[data-theme="dark"] .tfa-trust { color: var(--dm-muted) !important; }
html[data-theme="dark"] .tfa-error { color: #ff8a80 !important; }
html[data-theme="dark"] .modal button.tfa-resend { color: #ffb300 !important; }
html[data-theme="dark"] .modal button.tfa-resend:disabled { color: var(--dm-muted) !important; }
html[data-theme="dark"] #profile-modal button.tfa-profile-btn { background: var(--dm-surface) !important; border-color: #ffb300 !important; color: var(--dm-text) !important; }
html[data-theme="dark"] #profile-modal button.tfa-profile-btn.tfa-primary,
html[data-theme="dark"] #profile-modal button.tfa-profile-btn.tfa-primary span { background: #8d6e63 !important; color: #fff !important; }
html[data-theme="dark"] .modal button.device-remove:hover { background: rgba(255, 138, 128, 0.12) !important; }
html[data-theme="dark"] .modal button.device-choice-cancel { background: #3a302b !important; color: var(--dm-text) !important; }
html[data-theme="dark"] #device-choice-modal h3 { color: var(--dm-heading) !important; }

/* 🔎 البحث في المحادثات */
html[data-theme="dark"] .chat-search { background: var(--dm-surface); border-color: var(--dm-border); }
html[data-theme="dark"] .chat-search-title, html[data-theme="dark"] .chat-search-conv { color: var(--dm-heading); }
html[data-theme="dark"] .chat-search-box input { background: var(--dm-surface-2); border-color: var(--dm-border); color: var(--dm-text); }
html[data-theme="dark"] .chat-search-scopes { background: var(--dm-surface-2); }
html[data-theme="dark"] .chat-search-scopes button { color: var(--dm-muted); }
html[data-theme="dark"] .chat-search-scopes button.active { background: var(--dm-surface); color: var(--dm-heading); }
html[data-theme="dark"] .chat-search-result { border-color: var(--dm-border); }
html[data-theme="dark"] .chat-search-result:hover, html[data-theme="dark"] .chat-search-result:focus-visible { background: var(--dm-surface-2); }
html[data-theme="dark"] .chat-search-note, html[data-theme="dark"] .chat-search-date, html[data-theme="dark"] .chat-search-question { color: var(--dm-muted); }
html[data-theme="dark"] .chat-search-snippet { color: var(--dm-text); }
html[data-theme="dark"] .chat-search-tag { background: var(--dm-surface-2); color: var(--dm-muted); }
html[data-theme="dark"] .chat-search-snippet mark { background: #8a6d1c; color: #fff; }
html[data-theme="dark"] .chat-search-close { color: var(--dm-muted); }
html[data-theme="dark"] .chat-search-close:hover, html[data-theme="dark"] .chat-search-close:focus-visible { background: var(--dm-surface-2); color: var(--dm-heading); }
