/* --- Color Variables & Dark Mode --- */
:root {
    --body-bg: #f8f9fa;
    --body-color: #333;
    --card-bg: #fff;
    --card-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    --border-color: #dee2e6;
    --text-muted: #6c757d;
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --navbar-bg: #0f172a;
    --navbar-color: #fff;
    --dark-bg: #212529;
    --ads-bg: #f1f1f1;
    --link-color: #0d6efd;
    --link-hover-color: #0a58ca;
    --hero-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    --bs-primary-rgb: 37, 99, 235;
}

html.dark-mode {
    --body-bg: #18191a;
    --body-color: #e4e6eb;
    --card-bg: #242526;
    --card-shadow: 0 2px 4px rgba(0,0,0,0.3);
    --border-color: #3a3b3c;
    --text-muted: #adb5bd;
    --primary-color: #3b82f6;
    --primary-hover: #60a5fa;
    --navbar-bg: #242526;
    --navbar-color: #e4e6eb;
    --dark-bg: #242526;
    --ads-bg: #242526;
    --link-color: #60a5fa;
    --link-hover-color: #93c5fd;
    --hero-gradient: linear-gradient(135deg, #1e293b 0%, #242526 100%);
    --bs-primary-rgb: 59, 130, 246;
}

/* --- General & Fixes --- */
html, body {
    overflow-x: hidden; /* Prevents horizontal scroll on mobile */
    position: relative; /* Required for overflow-x to work reliably */
    background-color: var(--body-bg);
    color: var(--body-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* --- Global Styles --- */
.hero-section { background: var(--hero-gradient); color: var(--navbar-color); padding: 60px 0; }
.navbar { background-color: var(--navbar-bg); transition: background-color 0.3s ease; }
.navbar-brand, .navbar-nav .nav-link { color: var(--navbar-color) !important; transition: color 0.3s ease; }
.navbar-toggler { border-color: rgba(255,255,255,0.1); }
/* إجبار أيقونة القائمة (الهامبرغر) على أن تكون بيضاء دائماً لأن الهيدر داكن في الوضعين */
.navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.7%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") !important;
}
.ads-container { background: var(--ads-bg); padding: 10px; text-align: center; margin: 20px 0; border-radius: 8px; min-height: 90px; overflow: hidden; }
.transition { transition: all .3s ease; }
.transition-all { transition: all 0.3s ease; }

/* --- Hover Effects --- */
.hover-white:hover { color: #fff !important; }
.hover-warning:hover { color: #ffc107 !important; padding-right: 5px; }
.hover-border-warning:hover { border-color: #ffc107 !important; color: #fff !important; }
.hover-card { transition: transform 0.3s ease, box-shadow 0.3s ease; }
.hover-card:hover { transform: translateY(-5px); box-shadow: 0 .5rem 1rem rgba(0,0,0,.15)!important; }
.transition-hover { transition: transform 0.3s; }
.transition-hover:hover { transform: translateY(-5px); }
.zoom-img { transition: transform 0.3s; }
.card:hover .zoom-img { transform: scale(1.05); }

/* --- Index Page --- */
.ticker-wrapper { width: 100%; background: var(--dark-bg); }
.ticker-content { display: inline-block; white-space: nowrap; padding-left: 100%; animation: ticker 30s linear infinite; }
.ticker-content:hover { animation-play-state: paused; }
@keyframes ticker {
    0% { transform: translate3d(0, 0, 0); }
    100% { transform: translate3d(-100%, 0, 0); }
}
.categories-section { background-color: var(--body-bg); background-image: radial-gradient(var(--border-color) 1px, transparent 1px); background-size: 20px 20px; }
.fade-in-up { opacity: 1; transform: translateY(0); transition: opacity 0.8s ease-out, transform 0.8s ease-out; }
.fade-in-up.visible { opacity: 1; transform: translateY(0); }

/* --- Book & Post Pages --- */
.star-rating input, .rating-stars input { display: none; }
.star-rating label, .rating-stars label { font-size: 2rem; color: #ddd; cursor: pointer; transition: color 0.2s; }
.star-rating input:checked ~ label, .star-rating label:hover, .star-rating label:hover ~ label,
.rating-stars input:checked ~ label, .rating-stars label:hover, .rating-stars label:hover ~ label { color: #ffc107; }
.rating-stars { display: flex; flex-direction: row-reverse; justify-content: center; }
#progress-container { position: fixed; top: 0; left: 0; width: 100%; height: 5px; background: transparent; z-index: 9999; }
#progress-bar { height: 100%; background: var(--link-color); width: 0%; transition: width 0.1s; }
.article-content img { max-width: 100%; height: auto; border-radius: 8px; }

/* --- About Page --- */
.team-card { transition: transform 0.3s ease, box-shadow 0.3s ease; }
.team-card:hover { transform: translateY(-10px); box-shadow: 0 1rem 3rem rgba(0,0,0,.175)!important; }
.fade-in-right { animation: fadeInRight 1s ease-out; }
.fade-in-left { animation: fadeInLeft 1s ease-out; }
.backdrop-blur { backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: transform 0.3s ease, background 0.3s; }
.backdrop-blur:hover { transform: translateY(-5px); background: rgba(255, 255, 255, 0.15); }
.hover-scale { transition: transform 0.3s; }
.hover-scale:hover { transform: scale(1.05); }
@keyframes fadeInRight { from { opacity: 0; transform: translateX(50px); } to { opacity: 1; transform: translateX(0); } }
@keyframes fadeInLeft { from { opacity: 0; transform: translateX(-50px); } to { opacity: 1; transform: translateX(0); } }

/* --- WhatsApp Button --- */
.whatsapp-float {
    position: fixed;
    width: 60px;
    height: 60px;
    bottom: 20px;
    right: 20px;
    background-color: #25d366;
    color: #FFF;
    border-radius: 50px;
    text-align: center;
    font-size: 30px;
    box-shadow: 2px 2px 3px #999;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all 0.3s ease;
}
.whatsapp-float:hover {
    background-color: #128C7E;
    color: #FFF;
    transform: scale(1.1);
}
.whatsapp-message {
    position: fixed;
    bottom: 30px;
    right: 90px;
    background-color: var(--card-bg);
    color: var(--body-color);
    padding: 10px 15px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 999;
    display: flex;
    align-items: center;
    font-size: 14px;
    font-weight: bold;
    border: 1px solid var(--border-color);
    animation: fadeInRight 0.5s ease-out 3s forwards; /* Appears after 3 seconds */
    opacity: 0;
}
.whatsapp-message::after {
    content: '';
    position: absolute;
    right: -8px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-left: 8px solid var(--card-bg);
}

/* --- Print Styles --- */
@media print {
    .navbar, footer, .d-print-none { display: none !important; }
    .col-md-8 { width: 100% !important; flex: 0 0 100% !important; max-width: 100% !important; }
    body, #bookContent, #articleText { background-color: white !important; color: black !important; border: none !important; }
}

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    .whatsapp-float {
        width: 50px;
        height: 50px;
        font-size: 24px;
        bottom: 15px;
        right: 15px;
    }
    .whatsapp-message {
        right: 15px;
        bottom: 75px; /* Position above the button */
        font-size: 12px;
        max-width: 250px;
    }
    .whatsapp-message::after {
        /* Change arrow to point down */
        right: 20px;
        top: auto;
        bottom: -8px;
        border-left: 8px solid transparent;
        border-right: 8px solid transparent;
        border-top: 8px solid var(--card-bg);
        border-bottom: none;
    }
}

/* --- Back to Top Button --- */
.back-to-top {
    position: fixed;
    bottom: 20px;
    left: 20px; /* يسار الشاشة لتجنب زر الواتساب */
    width: 50px;
    height: 50px;
    background-color: var(--primary-color);
    color: var(--navbar-color);
    border-radius: 50%;
    text-align: center;
    line-height: 50px;
    font-size: 24px;
    z-index: 9999;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease-in-out;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    text-decoration: none;
}
.back-to-top:hover { background-color: var(--primary-hover); color: var(--navbar-color); transform: translateY(-3px); }
.back-to-top.show { opacity: 1; visibility: visible; }

/* --- Dark Mode Component Overrides --- */
html.dark-mode .bg-light { background-color: var(--card-bg) !important; }
html.dark-mode .bg-white { background-color: var(--card-bg) !important; }
html.dark-mode .text-dark { color: var(--body-color) !important; }
html.dark-mode .text-muted { color: var(--text-muted) !important; }
html.dark-mode .border, html.dark-mode .border-bottom, html.dark-mode .border-top, html.dark-mode .border-start, html.dark-mode .border-end { border-color: var(--border-color) !important; }
html.dark-mode .card { background-color: var(--card-bg); border-color: var(--border-color); box-shadow: var(--card-shadow); }
html.dark-mode .list-group-item { background-color: var(--card-bg); border-color: var(--border-color); color: var(--body-color); }
html.dark-mode .list-group-item-action:hover { background-color: rgba(255, 255, 255, 0.05); }
html.dark-mode .modal-content { background-color: var(--card-bg); color: var(--body-color); }
html.dark-mode .modal-header, html.dark-mode .modal-footer { border-color: var(--border-color); }
html.dark-mode .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }
html.dark-mode .form-control, html.dark-mode .form-select {
    background-color: #3a3b3c;
    color: var(--body-color);
    border-color: #4d4e4f;
}
html.dark-mode .form-control:focus, html.dark-mode .form-select:focus {
    background-color: #3a3b3c;
    color: var(--body-color);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.25);
}
html.dark-mode .form-control::placeholder { color: #8a8d91; }
html.dark-mode .table { color: var(--body-color); }
html.dark-mode .table-striped>tbody>tr:nth-of-type(odd)>* { --bs-table-accent-bg: rgba(255, 255, 255, 0.05); }
html.dark-mode .breadcrumb-item a { color: var(--link-color); }
html.dark-mode .breadcrumb-item.active { color: var(--text-muted); }
html.dark-mode .btn-outline-dark { color: var(--body-color); border-color: var(--border-color); }
html.dark-mode .btn-outline-dark:hover { background-color: var(--body-color); color: var(--body-bg); }
html.dark-mode .btn-outline-secondary { color: var(--text-muted); border-color: var(--text-muted); }
html.dark-mode .btn-outline-secondary:hover { background-color: var(--text-muted); color: var(--body-bg); }

/* --- Mobile Menu Animation --- */
@media (max-width: 991.98px) {
    .navbar-collapse.show .nav-item {
        animation: fadeInUpMenu 0.4s ease forwards;
        opacity: 0;
    }
    .navbar-collapse.show .d-flex { /* حاوية الأزرار (اللغة والدخول) */
        animation: fadeInUpMenu 0.4s ease forwards;
        opacity: 0;
        animation-delay: 0.3s;
    }
    /* تأخير زمني لكل عنصر لعمل تأثير التتابع */
    .navbar-collapse.show .nav-item:nth-child(1) { animation-delay: 0.05s; }
    .navbar-collapse.show .nav-item:nth-child(2) { animation-delay: 0.1s; }
    .navbar-collapse.show .nav-item:nth-child(3) { animation-delay: 0.15s; }
    .navbar-collapse.show .nav-item:nth-child(4) { animation-delay: 0.2s; }
    .navbar-collapse.show .nav-item:nth-child(5) { animation-delay: 0.25s; }
    .navbar-collapse.show .nav-item:nth-child(6) { animation-delay: 0.3s; }
}

@keyframes fadeInUpMenu {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Chatbot Styles --- */
#guest-chatbot-btn { position: fixed; bottom: 20px; left: 20px; width: 60px; height: 60px; z-index: 1060; transition: transform 0.2s; }
#guest-chatbot-btn:hover { transform: scale(1.1); }
#guest-chatbot-container { position: fixed; bottom: 90px; left: 20px; width: 350px; z-index: 1060; }
.typing-dots span { animation: typing 1.4s infinite ease-in-out both; font-size: 20px; margin: 0 1px; }
.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* --- Rating Gate --- */
.rating-gate-form .star-rating label { font-size: 3rem; }

/* --- Utilities --- */
.z-1 { z-index: 1; }