/* ==========================================================================
   تطبيق لمّاح (Lammah) - تصميم مخصص مبني فوق Bootstrap 5 RTL
   ========================================================================== */

:root {
    --font-sans: 'Tajawal', system-ui, -apple-system, sans-serif;
    --font-serif: 'Scheherazade New', Georgia, serif;
    
    /* المتغيرات العامة للإتاحة */
    --focus-ring-color: #ffeb3b;
    --focus-ring: 4px solid var(--focus-ring-color);
    --focus-outline-offset: 2px;
}

/* ==========================================================================
   تهيئة الخطوط والإتاحة
   ========================================================================== */
html, body {
    font-family: var(--font-sans);
    transition: background 0.3s ease, color 0.3s ease;
}

.text-gradient {
    background: linear-gradient(135deg, #0d6efd 0%, #0dcaf0 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* التخفي البصري مع الاحتفاظ بالقراءة الصوتية */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* رابط تخطي الملاحة للمكفوفين */
.skip-link {
    position: absolute;
    top: -120px;
    right: 1.5rem;
    background: var(--bs-primary);
    color: #ffffff;
    padding: 0.85rem 1.75rem;
    z-index: 9999;
    border-radius: 8px;
    font-weight: 800;
    text-decoration: none;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    transition: top 0.2s ease;
}
.skip-link:focus {
    top: 1.5rem;
    outline: var(--focus-ring);
}

/* حلقات التركيز لجميع عناصر لوحة المفاتيح */
:focus-visible {
    outline: var(--focus-ring) !important;
    outline-offset: var(--focus-outline-offset) !important;
    box-shadow: 0 0 0 5px rgba(255, 235, 59, 0.5) !important;
}

/* ==========================================================================
   الشريط الجانبي العائم (Floating Accessibility Bar)
   ========================================================================== */
.floating-accessibility-bar {
    position: fixed;
    top: 50%;
    left: 20px;
    transform: translateY(-50%);
    z-index: 1050;
    transition: all 0.3s ease;
}

.fab-container {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 24px;
    padding: 20px 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.1);
}

.theme-dark .fab-container {
    background: rgba(15, 23, 42, 0.85); /* Deep midnight blue */
    border-color: rgba(255,255,255,0.05);
    box-shadow: 0 15px 35px rgba(0,0,0,0.5);
}

.fab-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.fab-title {
    font-size: 0.8rem;
    font-weight: 800;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.theme-dark .fab-title { color: #94a3b8; }

.fab-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #475569;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

.theme-dark .fab-btn { color: #cbd5e1; }

.fab-btn:hover {
    background: rgba(13, 110, 253, 0.1);
    color: #0d6efd;
    transform: scale(1.1);
}

.fab-btn.active {
    background: linear-gradient(135deg, #196f3d 0%, #145a32 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(25, 111, 61, 0.4);
}

.fab-btn.fab-contrast:hover {
    background: #ffff00;
    color: #000;
}

.fab-divider {
    width: 100%;
    height: 2px;
    background: rgba(0,0,0,0.05);
    margin: 5px 0;
    border: none;
    border-radius: 2px;
}

.theme-dark .fab-divider { background: rgba(255,255,255,0.05); }

/* Responsive FAB */
@media (max-width: 768px) {
    .floating-accessibility-bar {
        top: auto;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        width: 90%;
    }
    .fab-container {
        flex-direction: row;
        justify-content: space-between;
        padding: 10px 20px;
    }
    .fab-section {
        flex-direction: row;
    }
    .fab-title { display: none; }
    .fab-divider { width: 2px; height: auto; margin: 0 10px; }
}


/* ==========================================================================
   المظاهر والأنماط البصرية (Themes) 
   ========================================================================== */

/* 1. النمط الداكن العصري الزجاجي (Modern Dark Glass) */
body.theme-dark {
    background-color: #0b0f19;
    color: #f8fafc;
}
body.theme-dark .card, 
body.theme-dark .app-header {
    background-color: rgba(18, 24, 38, 0.7) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.05) !important;
    color: #f8fafc !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}
body.theme-dark .bg-light,
body.theme-dark .bg-white {
    background-color: rgba(255, 255, 255, 0.02) !important;
}
body.theme-dark .text-dark {
    color: #f8fafc !important;
}
body.theme-dark .form-control, body.theme-dark .form-select, body.theme-dark .input-group-text {
    background-color: rgba(15, 23, 42, 0.8);
    color: #f8fafc;
    border-color: rgba(255, 255, 255, 0.1);
}
body.theme-dark .form-control:focus, body.theme-dark .form-select:focus {
    background-color: #0f172a;
    border-color: #d4af37;
    box-shadow: 0 0 0 0.25rem rgba(212, 175, 55, 0.25);
}
body.theme-dark .book-content-container, body.theme-dark .file-info-panel, body.theme-dark .reader-toolbar {
    background-color: rgba(11, 15, 25, 0.9) !important;
    color: #f1f5f9 !important;
    border-color: rgba(255, 255, 255, 0.05) !important;
}
body.theme-dark .card-header, body.theme-dark .card-body {
    border-color: rgba(255, 255, 255, 0.05) !important;
    background-color: transparent !important;
}
body.theme-dark .text-muted { color: #94a3b8 !important; }
body.theme-dark .drop-zone { background-color: rgba(255,255,255,0.02); border-color: rgba(255,255,255,0.15); }

/* 2. نمط التباين العالي (High Contrast Yellow on Black) */
body.theme-contrast {
    background-color: #000000 !important;
    color: #ffff00 !important;
}
body.theme-contrast * {
    color: #ffff00 !important;
    border-color: #ffff00 !important;
}
body.theme-contrast .card, body.theme-contrast .app-header, body.theme-contrast .form-control, body.theme-contrast .form-select, body.theme-contrast .book-content-container, body.theme-contrast .file-info-panel, body.theme-contrast .fab-container {
    background-color: #000000 !important;
    border: 2px solid #ffff00 !important;
}
body.theme-contrast .btn-primary, body.theme-contrast .btn-success, body.theme-contrast .btn-danger, body.theme-contrast .btn-warning, body.theme-contrast .btn-secondary, body.theme-contrast .badge, body.theme-contrast .fab-btn.active {
    background-color: #ffff00 !important;
    color: #000000 !important;
    font-weight: 900 !important;
}
body.theme-contrast .text-gradient { background: none; -webkit-text-fill-color: #ffff00; }
body.theme-contrast .progress-bar { background-color: #ffff00 !important; }

/* 3. نمط سيبيا הدافئ (Warm Sepia) */
body.theme-sepia {
    background-color: #f4ecd8;
    color: #433021;
}
body.theme-sepia .card, body.theme-sepia .app-header, body.theme-sepia .fab-container {
    background-color: #fdf8eb !important;
    border: 1px solid #dcc9af !important;
}
body.theme-sepia .form-control, body.theme-sepia .form-select, body.theme-sepia .input-group-text {
    background-color: #fcf6e6;
    color: #433021;
    border-color: #dcc9af;
}
body.theme-sepia .book-content-container, body.theme-sepia .file-info-panel, body.theme-sepia .reader-toolbar {
    background-color: #f8f1e1 !important;
    color: #2e1d0f !important;
    border-color: #dcc9af !important;
}
body.theme-sepia .card-header, body.theme-sepia .card-body {
    border-color: #dcc9af !important;
    background-color: transparent !important;
}
body.theme-sepia .btn-primary, body.theme-sepia .fab-btn.active {
    background-color: #8b4513 !important;
    border-color: #8b4513 !important;
    color: #ffffff !important;
}
body.theme-sepia .text-gradient { background: none; -webkit-text-fill-color: #8b4513; }
body.theme-sepia .drop-zone { background-color: rgba(139, 69, 19, 0.03); border-color: #c4a482; }

/* 4. النمط الفاتح العادي (Light Mode with Subtle Islamic Pattern) */
body.theme-light {
    background-color: #f8fafc;
    color: #0f172a;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 0l14 14-14 14L16 14zM0 30l14-14 14 14-14 14zM30 60L16 46l14-14 14 14zM60 30L46 44l-14-14 14-14z' fill='%23196f3d' fill-opacity='0.03' fill-rule='evenodd'/%3E%3C/svg%3E");
}
body.theme-light .card, body.theme-light .app-header {
    background-color: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.03);
}

/* أحجام الخطوط */
body.font-small { font-size: 1rem; }
body.font-medium { font-size: 1.15rem; }
body.font-large { font-size: 1.35rem; }
body.font-xlarge { font-size: 1.6rem; }

/* ==========================================================================
   عناصر ومكونات مخصصة
   ========================================================================== */

/* Drop Zone */
.drop-zone {
    border: 3px dashed var(--bs-primary);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    background-color: rgba(25, 111, 61, 0.02);
    position: relative;
    overflow: hidden;
}
.drop-zone::before {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 0; height: 0;
    background: radial-gradient(circle, rgba(25, 111, 61, 0.1) 0%, transparent 70%);
    transform: translate(-50%, -50%);
    transition: width 0.6s ease, height 0.6s ease;
    border-radius: 50%;
    z-index: 0;
}
.drop-zone:hover::before, .drop-zone.dragover::before {
    width: 200%;
    height: 200%;
}
.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--bs-primary);
    transform: scale(1.02);
    box-shadow: 0 15px 35px rgba(25, 111, 61, 0.15);
}
.drop-zone > * {
    position: relative;
    z-index: 1;
}

/* Book Content Rendering */
.book-content-container {
    font-family: var(--font-serif);
    font-size: 1.35em;
    line-height: 2.2;
}

.book-content-container h1, 
.book-content-container h2, 
.book-content-container h3 {
    font-family: var(--font-sans);
    font-weight: 800;
    margin-top: 2rem;
    margin-bottom: 1.25rem;
    color: var(--bs-primary);
}

.book-content-container p {
    margin-bottom: 1.5rem;
    text-align: justify;
}

.book-content-container ul, 
.book-content-container ol {
    margin-right: 2rem;
    margin-bottom: 1.5rem;
}

.book-content-container blockquote {
    border-right: 5px solid var(--bs-primary);
    padding: 1.5rem 2rem;
    margin: 2rem 0;
    background-color: rgba(25, 111, 61, 0.05);
    border-radius: 0.5rem;
    font-style: italic;
    font-size: 1.1em;
}

.book-content-container table {
    width: 100%;
    border-collapse: collapse;
    margin: 2rem 0;
}

.book-content-container th, 
.book-content-container td {
    border: 1px solid var(--bs-border-color);
    padding: 1rem;
    text-align: right;
}

.book-content-container th {
    font-family: var(--font-sans);
    font-weight: 800;
    background-color: rgba(0,0,0,0.05);
}

/* 👁️ כتل الوصف البصري الشامل للمكفوفين (Visual Descriptions) */
.book-content-container figure, 
.book-content-container .accessible-visual-block {
    margin: 2.5rem 0;
    background-color: rgba(13, 202, 240, 0.05);
    border: 2px solid var(--bs-info);
    padding: 1.75rem;
    border-radius: 1rem;
    box-shadow: 0 8px 25px rgba(0,0,0,0.05);
}

.book-content-container .visual-badge {
    font-family: var(--font-sans);
    font-size: 1.2rem;
    font-weight: 900;
    color: var(--bs-info);
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 2px dashed var(--bs-info);
    padding-bottom: 0.75rem;
}

.book-content-container figcaption {
    font-family: var(--font-serif);
    font-size: 1.1em;
    line-height: 2;
}

kbd {
    background-color: #1e293b;
    color: #fff;
    padding: 0.3rem 0.6rem;
    border-radius: 0.4rem;
    font-family: monospace;
    font-weight: bold;
    box-shadow: 0 2px 0 #0f172a;
}

/* ==========================================================================
   اللمسات الإسلامية (Islamic Theme Overrides)
   ========================================================================== */
.islamic-bg {
    background: linear-gradient(135deg, #196f3d 0%, #145a32 100%) !important;
}

.text-gradient-islamic {
    background: linear-gradient(135deg, #196f3d 0%, #d4af37 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.theme-dark .text-gradient-islamic {
    background: linear-gradient(135deg, #2ecc71 0%, #f1c40f 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Change Primary color accents to Islamic Green where possible */
.btn-primary {
    background-color: #196f3d !important;
    border-color: #196f3d !important;
    transition: all 0.3s ease;
}
.btn-primary:hover {
    background-color: #145a32 !important;
    box-shadow: 0 5px 15px rgba(25, 111, 61, 0.4);
    transform: translateY(-2px);
}
.btn-outline-primary {
    color: #196f3d !important;
    border-color: #196f3d !important;
}
.btn-outline-primary:hover {
    background-color: #196f3d !important;
    color: white !important;
}
.text-primary { color: #196f3d !important; }
.bg-primary { background-color: #196f3d !important; }
.progress-bar { background: linear-gradient(90deg, #196f3d, #27ae60) !important; }
.border-primary { border-color: #196f3d !important; }

/* القراءة الصوتية (تسليط الضوء على الفقرة المقروءة) */
.playing-paragraph {
    background-color: rgba(25, 111, 61, 0.1) !important;
    border-right: 4px solid #196f3d;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.theme-dark .playing-paragraph {
    background-color: rgba(212, 175, 55, 0.15) !important;
    border-right-color: #d4af37;
}

/* Animations */
@keyframes pulseGlow {
    0% { box-shadow: 0 0 0 0 rgba(25, 111, 61, 0.4); }
    70% { box-shadow: 0 0 0 15px rgba(25, 111, 61, 0); }
    100% { box-shadow: 0 0 0 0 rgba(25, 111, 61, 0); }
}
.btn-primary.pulse {
    animation: pulseGlow 2s infinite;
}

/* ==========================================================================
   نظام الإشعارات المخصص (Custom Toast Notifications)
   ========================================================================== */
#toast-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 15px;
    pointer-events: none;
}

.custom-toast {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: 20px;
    padding: 15px 20px;
    display: flex;
    align-items: flex-start;
    gap: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    min-width: 320px;
    max-width: 400px;
    pointer-events: auto;
    position: relative;
    overflow: hidden;
}

body.theme-dark .custom-toast {
    background: rgba(18, 24, 38, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    color: #f8fafc;
}

body.theme-contrast .custom-toast {
    background: #000;
    border: 2px solid #ff0;
    color: #ff0;
}

.toast-icon {
    font-size: 1.8rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.toast-success .toast-icon { color: #2ecc71; }
.toast-error .toast-icon { color: #e74c3c; }
.toast-warning .toast-icon { color: #f39c12; }

body.theme-contrast .toast-icon { color: #ff0 !important; }

.toast-content {
    flex-grow: 1;
}

.toast-title {
    font-family: var(--font-sans);
    font-weight: 800;
    font-size: 1.1rem;
    margin: 0 0 5px 0;
}

.toast-message {
    font-family: var(--font-sans);
    font-size: 0.95rem;
    margin: 0;
    opacity: 0.9;
}

.toast-close {
    background: transparent;
    border: none;
    color: inherit;
    opacity: 0.5;
    font-size: 1.2rem;
    cursor: pointer;
    transition: opacity 0.3s;
    padding: 0;
}
.toast-close:hover { opacity: 1; }

@media (max-width: 576px) {
    #toast-container {
        bottom: 20px;
        right: 15px;
        left: 15px;
        align-items: center;
    }
    .custom-toast {
        width: 100%;
        min-width: auto;
    }
}
