:root {
    --primary-color: #008080;
    --secondary-color: #005f5f;
    --background-color: #f4f7f6;
    --text-color: #333;
    --light-text-color: #f9f9f9;
    --arabic-font: 'Amiri', serif;
    --body-font: 'Poppins', sans-serif;
    --shadow-light: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 8px 20px rgba(0, 0, 0, 0.15);
}

/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--body-font);
    color: var(--text-color);
    background-color: var(--background-color);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    text-decoration: none;
    color: var(--primary-color);
}

a:hover {
    text-decoration: underline;
}

/* ----------------------------------------------------------
            LOADING OVERLAY & TRANSISI KONTEN
            ---------------------------------------------------------- */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--background-color);
    z-index: 10002;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease-out;
    opacity: 1;
}

.spinner {
    border: 8px solid rgba(0, 0, 0, 0.1);
    border-top: 8px solid var(--primary-color);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Wrapper Konten Utama */
#main-wrapper {
    flex-grow: 1;
    min-height: 100vh;
    transition: opacity 0.5s ease-in;
}

/* Awal: Konten tersembunyi total (Visibility hidden mencegah flicker) */
.content-hidden-initial {
    opacity: 0;
    visibility: hidden;
}

/* Setelah di-load: Konten terlihat */
.content-visible {
    opacity: 1;
    visibility: visible;
}


/* ----------------------------------------------------------
            Header and Nav
            ---------------------------------------------------------- */
.header {
    background-color: var(--primary-color);
    padding: 15px 30px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    flex-wrap: nowrap;
}

.logo a {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--light-text-color);
}

.search-bar {
    display: flex;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 20px;
    padding: 5px 15px;
    margin-left: 20px;
    width: 250px;
    transition: width 0.3s;
}

.search-bar:focus-within {
    width: 300px;
}

.search-bar input {
    border: none;
    outline: none;
    padding: 5px;
    font-size: 1rem;
    width: 100%;
    background: transparent;
}

.search-bar i {
    color: var(--primary-color);
    margin-right: 5px;
}

.nav-links {
    display: flex;
    list-style: none;
    margin-left: auto;
}

.nav-links li a {
    color: var(--light-text-color);
    padding: 8px 15px;
    margin-left: 10px;
    border-radius: 5px;
    transition: background-color 0.2s;
    font-weight: 500;
    text-decoration: none;
}

.nav-links li a:hover,
.nav-links li a.active {
    background-color: var(--secondary-color);
    text-decoration: none;
}

.menu-toggle {
    display: none;
    font-size: 1.5rem;
    color: var(--light-text-color);
    cursor: pointer;
    margin-left: 15px;
}

/* ----------------------------------------------------------
            Main Content & Layout
            ---------------------------------------------------------- */
.main-content {
    max-width: 1200px;
    margin: 40px auto;
    padding: 0 30px;
    flex-grow: 1;
}

.hero {
    text-align: center;
    margin-bottom: 60px;
    padding: 40px 20px;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: var(--shadow-light);
}

.hero h1 {
    font-size: 2.8rem;
    color: var(--primary-color);
    margin-bottom: 10px;
    font-weight: 700;
}

/* Collection Cards (Level 1) */
.hadith-collections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
}

.collection-card {
    background-color: #fff;
    padding: 25px;
    border-radius: 10px;
    box-shadow: var(--shadow-light);
    text-align: center;
    transition: transform 0.3s, box-shadow 0.3s;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-top: 4px solid var(--primary-color);
}

.collection-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
}

.arabic-name {
    font-family: var(--arabic-font);
    font-size: 2.2rem;
    color: var(--secondary-color);
    margin-bottom: 5px;
    font-weight: 700;
}

.latin-name {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 5px;
}

.imam-name {
    font-size: 0.9rem;
    color: #888;
    margin-bottom: 20px;
}

.kitab-button {
    display: block;
    background-color: var(--primary-color);
    color: var(--light-text-color);
    padding: 10px 20px;
    border-radius: 25px;
    font-weight: 600;
    transition: background-color 0.3s;
    border: none;
    cursor: pointer;
    text-transform: uppercase;
}

.kitab-button:hover {
    background-color: var(--secondary-color);
    text-decoration: none;

}

/* Kitab List (Level 2) */
.koleksi-header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: var(--shadow-light);
}

.koleksi-header h2 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 5px;
}

.koleksi-header h3 {
    font-family: var(--arabic-font);
    font-size: 3rem;
    color: var(--secondary-color);
    direction: rtl;
    margin-top: 10px;
}

.list-kitab a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #fff;
    padding: 18px 25px;
    margin-bottom: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    transition: background-color 0.2s, transform 0.1s;
    border-left: 5px solid var(--primary-color);
}

.list-kitab a:hover {
    background-color: #e6f3f3;
    text-decoration: none;
    transform: translateX(5px);
}

.kitab-title strong {
    font-size: 1.1rem;
}

.kitab-count {
    color: #555;
    font-size: 0.9rem;
    font-weight: 500;
}

/* Hadith Detail (Level 3) & Search Results (Level 4) */
.hadith-item {
    background-color: #fff;
    padding: 25px;
    margin-bottom: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.hadith-detail h2 {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: var(--shadow-light);
}

.search-result-kitab {
    font-size: 0.9em;
    color: #777;
    margin-bottom: 10px;
}

.hadith-arab {
    direction: rtl;
    font-family: var(--arabic-font);
    font-size: 1.8em;
    line-height: 2.2;
    margin-top: 15px;
    background-color: #e6f3f3;
    padding: 20px;
    border-radius: 8px;
    text-align: right;
    overflow-wrap: break-word;
    /* Penting untuk teks panjang */
}

.hadith-terjemah {
    margin-top: 15px;
    border-left: 5px solid var(--secondary-color);
    padding-left: 15px;
    font-size: 1em;
}

.highlight {
    background-color: yellow;
    font-weight: 600;
    padding: 1px 0;
}

.back-link {
    display: inline-block;
    margin-bottom: 20px;
    font-weight: 600;
    color: #555;
}

.back-link i {
    margin-right: 5px;
}

/* Pagination */
.pagination a,
.pagination span {
    padding: 6px 12px;
    /* sebelumnya 10px 18px */
    margin: 0 3px;
    /* sebelumnya 0 5px */
    border: 1px solid var(--primary-color);
    border-radius: 20px;
    /* bisa diperkecil juga */
    font-weight: 600;
    font-size: 0.85rem;
    /* tambahan untuk perkecil teks */
    text-transform: uppercase;
    display: inline-block;
}

.pagination span {
    color: #ccc;
    border-color: #ccc;
}

.pagination a {
    color: var(--primary-color);
}

.pagination a:hover {
    background-color: var(--primary-color);
    color: var(--light-text-color);
    text-decoration: none;
}


/* About Page */
.about-section {
    background-color: #fff;
    padding: 40px;
    border-radius: 10px;
    box-shadow: var(--shadow-light);
}

.about-section h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 2rem;
}

.person-card {
    display: flex;
    align-items: center;
    margin: 20px 0;
    padding: 20px;
    border: 1px solid #eee;
    border-radius: 8px;
    background-color: var(--background-color);
}

.person-card img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin-right: 20px;
    object-fit: cover;
    border: 3px solid var(--primary-color);
}

.person-info h3 {
    margin: 0 0 5px 0;
    color: var(--secondary-color);
    font-size: 1.2rem;
}

.person-info p {
    margin: 0;
    font-size: 0.9rem;
    color: #666;
}

/* Footer */
.footer {
    background-color: #333;
    color: var(--light-text-color);
    text-align: center;
    padding: 20px;
    margin-top: auto;
    /* Memaksa footer ke bagian paling bawah */
    font-size: 0.9rem;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    width: 100%;
}

.footer-logo {
    color: var(--primary-color);
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
}

/* ----------------------------------------------------------
            Riva Chatbot
            ---------------------------------------------------------- */

/* Tombol Toggle */
.rivachat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #008080;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 26px;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.rivachat-toggle:hover {
    transform: scale(1.1);
}

/* Overlay (background gelap) */
.rivachat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    z-index: 9998;
}

.rivachat-overlay.rivachat-active {
    opacity: 1;
    visibility: visible;
}

/* Popup */
.rivachat-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.85) translateY(40px);
    width: 90%;
    max-width: 400px;
    height: 80%;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.25);
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.45s cubic-bezier(0.25, 0.8, 0.25, 1),
        transform 0.45s cubic-bezier(0.25, 0.8, 0.25, 1),
        visibility 0.45s ease;
    z-index: 9999;
}

.rivachat-popup.rivachat-active {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1) translateY(0);
}

/* Tombol Close */
.rivachat-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 25px;
    font-weight: bold;
    color: #ffffff;
    cursor: pointer;
    transition: transform 0.3s ease;
    z-index: 10001;
}

.rivachat-close-btn:hover {
    transform: rotate(90deg);
}

/* ----------------------------------------------------------
            Responsive Adjustments
            ---------------------------------------------------------- */
@media (max-width: 768px) {

    * {
        font-size: 12px;
    }

    .header {
        padding: 15px 20px;
    }

    .navbar {
        flex-wrap: wrap;
        /* Tambahkan ini untuk wrapping di mobile */
    }

    .logo {
        flex-grow: 1;
    }

    /* >>> PERBAIKAN: Sembunyikan search bar secara default di mobile <<< */
    .search-bar {
        display: none;
        /* UBAH DARI display: flex; */
        order: 3;
        width: 100%;
        margin: 10px 0 10px 0;
    }

    .search-bar:focus-within {
        width: 100%;
    }

    .menu-toggle {
        display: block;
        order: 2;
    }

    /* >>> PERBAIKAN: Tampilkan search bar dan nav-links ketika navbar memiliki kelas 'active' <<< */
    .navbar.active .search-bar {
        display: flex;
    }

    /* Sembunyikan nav-links secara default di mobile */
    .nav-links {
        display: none;
        /* UBAH DARI display: flex; */
        flex-direction: column;
        width: 100%;
        order: 4;
        margin-left: 0;
        background-color: var(--primary-color);
        box-shadow: 0 5px 5px rgba(0, 0, 0, 0.1);
    }

    /* Tampilkan nav-links ketika navbar memiliki kelas 'active' */
    .navbar.active .nav-links {
        display: flex;
    }

    /* >>> AKHIR PERBAIKAN CSS <<< */

    .nav-links li {
        text-align: center;
        border-top: 1px solid var(--secondary-color);
    }

    .nav-links li:first-child {
        border-top: none;
    }

    .nav-links li a {
        display: block;
        margin: 0;
        padding: 15px;
    }

    .main-content {
        padding: 0 20px;
        margin: 20px auto;
    }

    .hadith-collections {
        grid-template-columns: 1fr;
    }

    .hadith-arab {
        font-size: 1.4em;
        padding: 15px;
        line-height: 1.8;
    }

    .koleksi-header h3 {
        font-size: 2.2rem;
    }

    .rivachat-toggle {
        font-size: 26px;
    }

    .rivachat-close-btn {
        font-size: 25px;
    }
}