:root {
    --primary: #2d5016;
    --primary-light: #4a7c2a;
    --primary-dark: #1a3009;
    --secondary: #d4af37;
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --border: #e0e0e0;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-lg: rgba(0, 0, 0, 0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

@font-face {
    font-family: 'Jameel Noori';
    src: url('./fonts/JameelNoori-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
    unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}

body {
    font-family: 'Jameel Noori', 'Amiri', serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.8;
    direction: rtl;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 2rem 0;
    box-shadow: 0 4px 6px var(--shadow);
}

.header-content {
    text-align: center;
    margin-bottom: 1.5rem;
}

.logo {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.subtitle {
    font-size: 1.2rem;
    opacity: 0.9;
    font-weight: 500;
}

.nav {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.nav-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.75rem 2rem;
    border-radius: 50px;
    font-size: 1.1rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.nav-btn.active {
    background: var(--secondary);
    border-color: var(--secondary);
    color: var(--primary-dark);
    font-weight: 600;
}

/* Main */
.main {
    padding: 3rem 0;
    min-height: calc(100vh - 400px);
}

.view {
    display: none;
}

.view.active {
    display: block;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Search Section */
.search-section {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 4px 12px var(--shadow);
    margin-bottom: 2rem;
}

.search-box {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.search-input {
    flex: 1;
    padding: 1rem 1.5rem;
    border: 2px solid var(--border);
    border-radius: 50px;
    font-size: 1.1rem;
    font-family: inherit;
    transition: all 0.3s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(45, 80, 22, 0.1);
}

.search-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.search-btn:hover {
    background: var(--primary-light);
    transform: scale(1.05);
}

.filter-chips {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

.chip {
    background: var(--bg-primary);
    border: 2px solid var(--border);
    padding: 0.5rem 1.5rem;
    border-radius: 50px;
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
}

.chip:hover {
    border-color: var(--primary);
    background: rgba(45, 80, 22, 0.05);
}

.chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Stats Section */
.stats-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.stat-card {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    padding: 2rem;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 4px 12px var(--shadow);
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
}

.stat-number {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.stat-label {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Results Section */
.results-section {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 4px 12px var(--shadow);
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border);
}

.section-title {
    font-size: 2rem;
    color: var(--primary);
    font-weight: 700;
}

.results-count {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.results-grid {
    display: grid;
    gap: 1.5rem;
}

.fatwa-card {
    background: var(--bg-primary);
    padding: 1.5rem;
    border-radius: 15px;
    border-right: 4px solid var(--primary);
    transition: all 0.3s ease;
    cursor: pointer;
}

.fatwa-card:hover {
    transform: translateX(-5px);
    box-shadow: 0 6px 16px var(--shadow-lg);
    border-right-color: var(--secondary);
}

.fatwa-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 1rem;
}

.fatwa-id {
    background: var(--primary);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
}

.fatwa-chapter {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.fatwa-topic {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--primary-dark);
    margin-bottom: 0.75rem;
    line-height: 1.6;
}

.fatwa-question {
    color: var(--text-secondary);
    line-height: 1.7;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Loading */
.loading {
    text-align: center;
    padding: 3rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid var(--border);
}

.pagination-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 2rem;
    border-radius: 50px;
    font-size: 1.1rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--primary-light);
    transform: scale(1.05);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-info {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

/* Chapters Grid */
.chapters-section {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 4px 12px var(--shadow);
}

.chapters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.chapter-card {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    padding: 2rem;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.chapter-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px var(--shadow-lg);
}

.chapter-number {
    font-size: 3rem;
    font-weight: 700;
    opacity: 0.3;
    margin-bottom: 0.5rem;
}

.chapter-name {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.chapter-count {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* About Section */
.about-section {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 4px 12px var(--shadow);
}

.about-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.about-card {
    background: var(--bg-primary);
    padding: 2rem;
    border-radius: 15px;
    border-top: 4px solid var(--primary);
}

.about-card h3 {
    color: var(--primary);
    font-size: 1.3rem;
    margin-bottom: 1rem;
}

.about-card p {
    color: var(--text-secondary);
    line-height: 1.7;
    font-size: 1.1rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    margin: 20px;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.modal-close {
    position: sticky;
    top: 0;
    left: 20px;
    background: var(--primary);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 10;
    margin: 20px;
    transition: all 0.3s ease;
}

.modal-close:hover {
    background: var(--primary-dark);
    transform: rotate(90deg);
}

.modal-body {
    padding: 2rem;
}

.modal-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border);
}

.modal-id {
    background: var(--primary);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    display: inline-block;
    margin-bottom: 1rem;
}

.modal-topic {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 0.5rem;
}

.modal-chapter {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.modal-section {
    margin-bottom: 2rem;
}

.modal-section h3 {
    color: var(--primary);
    font-size: 1.5rem;
    margin-bottom: 1rem;
    padding-right: 1rem;
    border-right: 4px solid var(--secondary);
}

.modal-section p {
    line-height: 2;
    font-size: 1.15rem;
    color: var(--text-primary);
}

.references-list {
    list-style: none;
}

.references-list li {
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: 10px;
    margin-bottom: 0.75rem;
    line-height: 1.8;
    border-right: 3px solid var(--secondary);
    transition: background-color 0.3s ease;
}

/* Answer Content with Paragraphs */
.answer-content {
    line-height: 1.9;
}

.answer-paragraph {
    margin-bottom: 1.2rem;
    line-height: 1.9;
}

.answer-paragraph:last-child {
    margin-bottom: 0;
}

/* Reference Links */
.ref-link {
    color: var(--primary);
    text-decoration: none;
    cursor: pointer;
    font-size: 0.75em;
    vertical-align: super;
    padding: 2px 4px;
    margin: 0 2px;
    border-radius: 3px;
    transition: all 0.2s ease;
    display: inline-block;
    font-weight: 600;
}

.ref-link:hover {
    color: var(--primary-dark);
    background-color: rgba(45, 80, 22, 0.15);
    text-decoration: none;
    transform: scale(1.1);
}

.ref-link:active {
    transform: scale(0.95);
}

/* Reference Popup */
.ref-popup {
    position: fixed;
    z-index: 10000;
    animation: popupFadeIn 0.2s ease;
    max-width: 500px;
    min-width: 300px;
}

@keyframes popupFadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ref-popup-content {
    background: var(--bg-secondary);
    border: 2px solid var(--primary);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    position: relative;
}

.ref-popup-header {
    background: var(--primary);
    color: white;
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 1.1rem;
}

.ref-popup-body {
    padding: 1.2rem;
    line-height: 1.8;
    color: var(--text-primary);
    font-size: 1rem;
    max-height: 400px;
    overflow-y: auto;
}

.ref-popup-close {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.ref-popup-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* Footer */
.footer {
    background: var(--primary-dark);
    color: white;
    text-align: center;
    padding: 2rem 0;
    margin-top: 4rem;
}

/* Responsive */
@media (max-width: 768px) {
    .logo {
        font-size: 1.8rem;
    }
    
    .subtitle {
        font-size: 1rem;
    }
    
    .nav {
        gap: 0.5rem;
    }
    
    .nav-btn {
        padding: 0.6rem 1.5rem;
        font-size: 1rem;
    }
    
    .search-box {
        flex-direction: column;
    }
    
    .stat-number {
        font-size: 2rem;
    }
    
    .results-header {
        flex-direction: column;
        align-items: start;
        gap: 0.5rem;
    }
    
    .modal-content {
        margin: 10px;
        max-height: 95vh;
    }
    
    .modal-topic {
        font-size: 1.5rem;
    }
}
