/* ==========================================================================
   Kitab Asbabun Nuzul Online Digital - Stylesheet
   Version: 2.3 (Native Ad Responsive Grid Fix)
   Compatible with: Tailwind CSS v3.x
   ========================================================================== */

/* --- 1. CSS Variables & Reset (Tailwind Compatible) --- */
:root {
    --primary-bg: #fdfdfd; 
    --secondary-bg: #f1f5f9; 
    --card-bg: #ffffff;
    --text-primary: #1e293b; 
    --text-secondary: #64748b; 
    --accent-green: #10b981; 
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.dark {
    --primary-bg: #0f172a; 
    --secondary-bg: #1e293b; 
    --card-bg: #111827; 
    --text-primary: #f1f5f9; 
    --text-secondary: #94a3b8; 
    --accent-green: #34d399; 
    --border-color: #334155;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
}

body.dark-mode {
    background-color: var(--primary-bg);
    color: var(--text-primary);
}

/* --- 2. Base Typography & Global Styles --- */
h1, h2, h3, h4, .font-sans {
    font-family: 'Plus Jakarta Sans', sans-serif !important;
}

.main-title h1 {
    background: linear-gradient(to right, #059669, #10b981);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.dark .main-title h1 {
    background: linear-gradient(to right, #34d399, #10b981);
    -webkit-background-clip: text;
    background-clip: text;
}

p.text-muted {
    color: var(--text-secondary);
}

/* --- 3. Navigation (Customizations over Tailwind) --- */
.nav-link {
    transition: all 0.3s ease;
}

.nav-link:hover:not(.text-primary) {
    background-color: rgba(16, 185, 129, 0.05);
}

.dark .nav-link:hover:not(.text-primary) {
    background-color: rgba(52, 211, 153, 0.1);
}

#mobile-menu {
    transition: all 0.3s ease-in-out;
    box-shadow: var(--shadow-md);
}

/* --- 4. Main Components --- */

/* Download PDF Button */
.btn-download {
    background: linear-gradient(to bottom right, #be1e2d, #a01825);
    color: white !important;
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 15px;
    box-shadow: 0 4px 15px rgba(190, 30, 45, 0.25);
    transition: all 0.3s ease;
}

.btn-download:hover {
    box-shadow: 0 6px 20px rgba(190, 30, 45, 0.35);
    transform: translateY(-1px);
}

/* Search Bar */
#main-search-input {
    transition: border-color 0.3s, box-shadow 0.3s;
}

#main-search-input:focus {
    border-color: #10b981;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.15);
}

.dark #main-search-input:focus {
    border-color: #34d399;
    box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.2);
}

/* --- 5. Surah List Grid --- */
#surah-list {
    display: grid;
    grid-template-columns: repeat(1, minmax(0, 1fr));
    gap: 1rem;
}

@media (min-width: 768px) {
    #surah-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    #surah-list {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.surah-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.25rem;
    display: block;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.surah-card:hover {
    border-color: #10b981;
    transform: translateY(-3px);
    box-shadow: 0 10px 15px -3px rgba(16, 185, 129, 0.1), 0 4px 6px -2px rgba(16, 185, 129, 0.05);
}

.surah-card.has-asbab {
    border-left-width: 4px;
    border-left-color: #10b981;
}

.surah-header {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.surah-number {
    width: 3rem;
    height: 3rem;
    flex-shrink: 0;
    background-color: #ecfdf5; 
    color: #059669; 
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.125rem;
    transition: background-color 0.3s, color 0.3s;
}

.dark .surah-number {
    background-color: rgba(5, 150, 105, 0.2);
    color: #34d399;
}

.surah-card:hover .surah-number {
    background-color: #10b981;
    color: white;
}

.surah-info {
    flex-grow: 1;
}

.surah-info h3 {
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.surah-info p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.surah-card .surah-info p span {
    color: #10b981;
    font-weight: 500;
    margin-left: 0.25rem;
}

.surah-arabic {
    font-family: 'Amiri', serif !important;
    font-size: 1.5rem;
    color: #059669;
}

.dark .surah-arabic {
    color: #34d399;
}

/* --- 6. Verse Details Page & Sidebar --- */

.surah-info-box {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.surah-info-box h2 {
    font-size: 1.5rem;
    font-weight: 800;
    color: #059669;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-b: 2px solid var(--border-color);
}

.dark .surah-info-box h2 {
    color: #34d399;
}

.surah-info-box p {
    color: var(--text-primary);
    line-height: 1.6;
    margin-bottom: 1rem;
}

.surah-info-box p strong {
    font-weight: 600;
    color: #059669;
}

.dark .surah-info-box p strong {
    color: #34d399;
}

/* Sidebar surah info in details page */
.sidebar-surah-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background-color: var(--secondary-bg);
    border-radius: 12px;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
}

.sidebar-surah-info h3 {
    font-weight: 700;
    color: var(--text-primary);
}

.sidebar-surah-info p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.sidebar-surah-info .surah-arabic {
    margin-left: auto;
    font-size: 1.75rem;
}

/* View Mode Toggles in sidebar */
.mode-toggle-sidebar, .tafsir-toggle-sidebar {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.mode-toggle-sidebar p, .tafsir-toggle-sidebar p {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
}

#view-mode-toggle {
    display: flex;
    gap: 0.5rem;
}

.mode-btn {
    flex: 1;
    padding: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    background-color: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    border-color: #10b981;
    color: #10b981;
}

.mode-btn.active {
    background-color: #10b981;
    color: white;
    border-color: #10b981;
    font-weight: 600;
}

/* Tafsir Select */
#tafsir-select {
    width: 100%;
    padding: 0.625rem;
    background-color: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s;
}

#tafsir-select:focus {
    border-color: #10b981;
}

/* Verse List Items */
#verse-list-items {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

@media (min-width: 1024px) {
    #verse-list-items {
        max-height: calc(100vh - 450px);
    }
}

#verse-list-items::-webkit-scrollbar {
    width: 6px;
}

#verse-list-items::-webkit-scrollbar-track {
    background: transparent;
}

#verse-list-items::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.verse-list-item {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    border-radius: 8px;
    text-decoration: none !important;
    transition: all 0.2s ease;
    margin-bottom: 0.25rem;
    font-size: 0.9375rem;
}

.verse-list-item:hover {
    color: #10b981;
    background-color: rgba(16, 185, 129, 0.05);
}

.verse-list-item.has-asbab {
    position: relative;
    padding-right: 2.5rem; 
}

.verse-list-item.has-asbab::after {
    content: '\f02d'; 
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: #10b981;
    font-size: 12px;
    opacity: 0.7;
}

.verse-list-item.active {
    background-color: #10b981 !important;
    color: white !important;
    font-weight: 600;
}

.verse-list-item.active::after {
    color: white !important;
    opacity: 1;
}

/* --- 7. Verse Content Area --- */
.verse-item {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.verse-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
    border-b: 1px solid var(--border-color);
}

.verse-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-primary);
}

.header-buttons {
    display: flex;
    gap: 0.5rem;
}

.share-btn, .copy-btn {
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.share-btn {
    background-color: rgba(16, 185, 129, 0.08);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.share-btn:hover {
    background-color: #10b981;
    color: white;
}

.copy-btn {
    background-color: var(--secondary-bg);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.copy-btn:hover {
    background-color: var(--text-secondary);
    color: var(--card-bg);
}

/* Arabic, translation, asbab styling */
.individual-ayah-title {
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    background-color: var(--secondary-bg);
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
}

/* 7a. Mode: Per Kata (WBW) */
.mode-wbw .word-by-word-container {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row-reverse; 
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.word-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    background-color: var(--card-bg);
    border-radius: 8px;
    min-width: 60px;
}

.word-group:hover {
    border-color: #10b981;
    box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.1);
}

.word-group.waqaf-sign {
    border: none;
    padding: 0;
    justify-content: center;
    background: transparent;
    color: #059669;
}

.arabic-word {
    font-family: 'Amiri', serif !important;
    font-size: 2.25rem;
    line-height: 1.3;
    color: var(--text-primary);
}

.translation-word {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    max-width: 100px;
}

/* Mode WBW: hide full arab, show wbw */
.mode-wbw .arabic-full-container { display: none; }
.mode-wbw .word-by-word-container { display: flex; }

/* 7b. Mode: Arab & Arti */
.arabic-full-container {
    font-family: 'Amiri', serif !important;
    font-size: 2.75rem;
    line-height: 1.8;
    color: var(--text-primary);
    text-align: right;
    margin-bottom: 1.5rem;
    direction: rtl;
}

.verse-number-badge {
    font-family: sans-serif;
    font-size: 1.25rem;
    color: #10b981;
    margin-right: 0.5rem;
    direction: ltr;
    display: inline-block;
}

/* Mode Full Arab: hide wbw, show full arab */
.mode-full-arab .word-by-word-container { display: none; }
.mode-full-arab .arabic-full-container { display: block; }


/* Translation Styling */
.verse-translation {
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.verse-translation b {
    color: #059669;
}

.dark .verse-translation b {
    color: #34d399;
}

.tafsir-text {
    text-align: justify;
}

/* Footnotes inside tafsir */
.verse-footnotes {
    font-size: 0.875rem;
    color: var(--text-secondary);
    background-color: var(--secondary-bg);
    padding: 1rem;
    border-radius: 8px;
    margin-top: 1rem;
    border: 1px solid var(--border-color);
}

.verse-footnotes h4 {
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.ayah-divider {
    border: 0;
    border-top: 2px dashed var(--border-color);
    margin: 2rem 0;
}

/* 7c. Asbabun Nuzul section */
.asbabun-nuzul {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.asbabun-nuzul h4 {
    font-size: 1.25rem;
    font-weight: 800;
    color: #be1e2d; 
    margin-bottom: 1rem;
}

.asbabun-nuzul p {
    font-size: 0.9375rem;
    line-height: 1.8;
    color: var(--text-primary);
    text-align: justify;
    margin-bottom: 1rem;
    position: relative;
    padding-left: 1.5rem;
}

.asbabun-nuzul p.riwayat-item::before {
    content: '\f10d'; 
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    left: 0;
    top: 5px;
    color: #f1f5f9; 
    font-size: 1rem;
}

.dark .asbabun-nuzul p.riwayat-item::before {
    color: #1e293b;
}

.asbabun-nuzul p strong {
    color: #a01825; 
}

.dark .asbabun-nuzul p strong {
    color: #f87171;
}

.no-history {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.9375rem;
}

/* --- 8. Modals (Copy & Comment Terms) --- */
#copy-modal-content, #comment-terms-modal {
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.copy-options-group {
    padding-bottom: 1rem;
}

.copy-options-group:not(:last-child) {
    border-b: 1px solid var(--border-color);
    margin-bottom: 1rem;
}

/* Toast */
#clipboard-toast {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

#clipboard-toast.show {
    transform: translate-y(0);
    opacity: 1;
}

/* ==========================================================================
   9. FIXED AD LAYOUT - Solusi Grid Iklan Native
   ========================================================================== */

/* Akar Masalah: Skrip Native Ad memerlukan kontainer polos untuk menghitung
   lebar secara akurat dan merender grid 4 kolom dengan benar. Padding dan border
   membuat skrip beralih ke mode 1 kolom (mobile).

   Solusi: Hapus padding, border, dan background pada kontainer iklan. 
   Biarkan skrip yang mengatur style internalnya sendiri.
*/

#ad-placeholder-home-top,
#ad-placeholder-home-bottom {
    margin: 1.5rem auto; 
    text-align: center;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 50px;
    overflow: visible; 
}

#ad-placeholder-home-top > *,
#ad-placeholder-home-bottom > * {
    max-width: 100% !important;
}

/* Kontainer Iklan Native (Di antara Ayat & Asbab) */
[id^="ad-placeholder-ayat-after-meaning-"],
[id^="ad-placeholder-ayat-after-asbab-"] {
    margin: 2rem 0; 
    width: 100%;
    min-height: 120px;
    
    /* PENTING: Dibuat completely transparan & tanpa padding agar grid iklan
       tidak rusak dan bisa berbaris menyamping. */
    background: transparent !important;
    padding: 0 !important;
    border: none !important;
    
    display: block;
    overflow: visible !important; 
}

/* Responsive adjustment untuk layar HP */
@media (max-width: 640px) {
    [id^="ad-placeholder-ayat-after-meaning-"],
    [id^="ad-placeholder-ayat-after-asbab-"] {
        margin: 1.5rem 0;
    }
}


/* --- 10. Footer --- */
footer a.text-muted:hover {
    color: #10b981 !important;
}

.dark footer a.text-muted:hover {
    color: #34d399 !important;
}
