/* 1. Design Tokens & Variables */
:root {
    /* Fixed Colors */
    --primary-green: #006621;
    
    /* Themeable Colors (Default Light) */
    --dark-green: #004d19;
    --light-bg: #f4f7f6;
    --card-bg: #ffffff;
    --text-dark: #2d3436;
    --text-muted: #636e72;
    --border-color: #e1e8e7;
    
    /* Typography */
    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --font-bengali: 'Noto Serif Bengali', serif;

    /* Component Specific Colors */
    --floating-btn-bg: var(--primary-green);
    --floating-btn-shadow: rgba(0, 0, 0, 0.3);
}

/* Dark Theme Tokens */
[data-theme="dark"] {
    --light-bg: #121212;
    --card-bg: #1e1e1e;
    --text-dark: #e0e0e0;
    --text-muted: #a0a0a0;
    --border-color: #333333;
    --primary-green: #27ae60; /* Softened from #2ecc71 */
    --dark-green: #219150;    /* Muted forest green */
    
    /* Component Specific Colors for Dark Mode */
    --floating-btn-bg: #219150; /* Softer, darker green for eye comfort */
    --floating-btn-shadow: rgba(0, 0, 0, 0.6);
}

/* Sepia Theme Tokens */
[data-theme="sepia"] {
    --light-bg: #f4ecd8;
    --card-bg: #fcf5e5;
    --text-dark: #5b4636;
    --text-muted: #8c786a;
    --border-color: #e2d7bf;
    --dark-green: #435c2b; /* A deep olive that complements sepia */
}

/* 2. Global Resets */
html {
    /* scroll-behavior: smooth; -> DO NOT ADD: This conflicts with the JS momentum scroll */
}

* {
    box-sizing: border-box;
}

a {
    text-decoration: none;
    color: inherit;
}

body {
    font-family: var(--font-main);
    background-color: var(--light-bg);
    color: var(--text-dark);
    margin: 0;
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

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

/* 3. Navigation Bar */
.navbar {
    background: var(--card-bg);
    padding: 1rem 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
    /* Smooth theme transition */
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
    text-decoration: none;
    color: var(--text-dark);
    transition: color 0.3s ease;
    display: inline-flex;
    align-items: center;
}

.logo img {
    height: 35px;
    width: auto;
    margin-right: 8px;
}

.logo span {
    color: var(--primary-green);
    transition: color 0.3s ease;
}

.nav-links a {
    text-decoration: none;
    color: var(--text-dark);
    margin-left: 15px; /* Reduced slightly for better fit */
    font-weight: 500;
    transition: color 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap; /* Prevents text from wrapping awkwardly */
}

.nav-links a:hover {
    color: var(--primary-green);
}

/* Public Navigation Icons */
.public-nav-icon {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    vertical-align: middle;
}

/* Custom adjustment for mobile header spacing */
@media (max-width: 600px) {
    .navbar .container {
        flex-direction: column; /* Stack logo and nav links */
        gap: 15px;
    }

    .nav-links {
        width: 100%;
        justify-content: center;
        display: flex;
        flex-wrap: wrap; /* Allows buttons to wrap if they are too long */
        gap: 10px;
    }

    .nav-links a {
        margin-left: 0; /* Remove side margin in favor of gap */
        font-size: 0.85rem; /* Slightly smaller text for mobile */
    }
    
    .logo {
        font-size: 1.3rem; /* Smaller logo for mobile */
    }
}

/* Navigation Buttons (Theme & Language Toggles) */
.nav-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-dark);
    padding: 6px 12px;
    margin-left: 15px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 600;
    transition: all 0.3s ease;
}

.nav-btn:hover {
    border-color: var(--primary-green);
    color: var(--primary-green);
    background: rgba(0, 102, 33, 0.05);
}

/* Public Context Menu Styling (Theme/Lang Options) */
.public-ctx-menu {
    display: none;
    position: fixed;
    z-index: 3000;
    background: var(--card-bg);
    min-width: 200px;
    max-width: 90vw;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    border-radius: 12px;
    padding: 8px 0;
    border: 1px solid var(--border-color);
    animation: publicCtxFade 0.2s ease;
    overflow: hidden;
}

#lang-toggle-public, #lang-toggle-mobile {
    border: 1px solid var(--primary-green) !important;
    color: var(--primary-green) !important;
    font-weight: bold !important;
}

.public-ctx-menu div {
    padding: 10px 20px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-dark);
    transition: background 0.2s, color 0.2s;
}

.public-ctx-menu div:hover {
    background: var(--light-bg);
    color: var(--primary-green);
}

@keyframes publicCtxFade {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}
/* 4. Hero & Headers */
.hero-section, .category-header, .search-header {
    text-align: center;
    padding: 60px 0;
}

.hero-section h1, .category-header h1, .search-header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    color: var(--primary-green);
    /* Added color transition */
    transition: color 0.3s ease;
}

.dua-header {
    text-align: center;
    margin-bottom: 40px;
}

.description {
    color: var(--text-muted);
    font-style: italic;
    max-width: 700px;
    margin: 10px auto;
    /* Added color transition */
    transition: color 0.3s ease;
}

/* 5. Category Grid & Dua Lists */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
    margin-bottom: 50px;
}

.category-card {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    border-bottom: 4px solid var(--primary-green);
    transition: transform 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
    text-decoration: none;
    display: block;
}

.category-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.category-card h2 {
    margin: 0;
    color: var(--text-dark);
    font-size: 1.4rem;
    transition: color 0.3s ease;
}

.dua-list {
    list-style: none;
    padding: 0;
    margin-bottom: 50px;
}

.dua-list li {
    margin-bottom: 15px;
}

.dua-list a {
    background: var(--card-bg);
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-decoration: none;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    transition: 0.2s;
}

.dua-list a:hover {
    border-color: var(--primary-green);
    background: rgba(0, 102, 33, 0.05);
}

.dua-title-en { 
    font-weight: bold; 
    color: var(--text-dark); 
    /* Added color transition */
    transition: color 0.3s ease; 
}
.dua-title-bn { 
    font-family: var(--font-bengali); 
    color: var(--primary-green); 
    /* Added color transition */
    transition: color 0.3s ease; 
}

/* 6. Translation View (view-dua.php) */
.translation-table {
    margin: 40px 0;
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    border: 1px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* Base Desktop Grid: Default 3 columns */
.translation-row {
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr;
    border-bottom: 1px solid var(--border-color);
    transition: border-color 0.3s ease;
}

/* Ensure borders only appear between visible columns */
.translation-row > div + div {
    border-left: 1px solid var(--border-color);
}
.translation-row:last-child {
    border-bottom: none;
}
.translation-row > div {
    padding: 25px 30px;
    display: block;
    line-height: 1.8;
}

.arabic-text {
    font-size: 2rem;
    font-family: 'Traditional Arabic', serif;
    /* Replaced hardcoded #fafdfb with themeable variable */
    background-color: var(--light-bg);
    text-align: right;
    direction: rtl;
    /* Replaced hardcoded #1a1a1a with themeable variable */
    color: var(--text-dark);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.bengali-translation {
    font-family: var(--font-bengali);
    font-size: 1.15rem;
    /* Removed right border, left border acts as the divider */
    border-left: 1px solid var(--border-color);
    color: var(--dark-green);
    transition: border-color 0.3s ease, color 0.3s ease;
}

.english-translation {
    font-size: 1.05rem;
    color: var(--text-dark);
    /* Added a left border here too for when Bengali is hidden */
    border-left: 1px solid var(--border-color);
    transition: color 0.3s ease, border-color 0.3s ease;
}

.english-translation {
    font-size: 1.05rem;
    color: var(--text-dark);
    transition: color 0.3s ease;
}

/* 7. Search Page Components */
.search-container {
    min-height: 70vh;
}

.search-input-wrapper {
    max-width: 600px;
    margin: 0 auto;
    position: relative;
}

.search-input {
    width: 100%;
    padding: 15px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 1.1rem;
    outline: none;
    transition: 0.3s;
    background: var(--card-bg);
    color: var(--text-dark);
}

.search-input:focus {
    border-color: var(--primary-green);
    box-shadow: 0 0 10px rgba(0, 102, 33, 0.1);
}

#liveSearchResults {
    margin-top: 10px;
}

.search-result-item {
    background: var(--card-bg);
    padding: 15px;
    margin-bottom: 10px;
    text-decoration: none;
    display: block;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: 0.2s;
}

.search-result-item:hover {
    border-color: var(--primary-green);
    transform: translateX(5px);
}

.search-result-item h4 { margin: 0; color: var(--text-dark); }
.search-result-item small { color: var(--text-muted); }

.no-results {
    padding: 20px;
    color: var(--text-muted);
    font-style: italic;
}

/* 8. Typography Helpers */
.bengali-text {
    font-family: var(--font-bengali);
    display: block;
    font-size: 1.2rem;
    color: var(--primary-green);
    margin-top: 10px;
}

/* Adjust Bengali title when it's the primary heading in view-dua.php & category.php */
.bn-only-view .cat-title-bn {
    font-size: 2.5rem; /* Matches the main English title size */
    margin-top: 40px; /* Added spacing to prevent clashing with navbar */
    line-height: 1.2;
}

/* 9. Footer */
.footer {
    text-align: center;
    padding: 40px 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
    margin-top: 50px;
}

/* 10. Responsive Adjustments */
@media (max-width: 900px) {
    .translation-row {
        /* Forces 1 column regardless of JS calculations on mobile */
        grid-template-columns: 1fr !important;
    }
    
    .translation-row > div {
        border: none !important;
        padding: 20px;
        text-align: center;
        justify-content: center;
        border-bottom: 1px solid var(--border-color) !important;
    }

    /* Remove bottom border from the very last visible element in a row */
    .translation-row > div:last-child {
        border-bottom: none !important;
    }

    /* Order for Stacked View */
    .arabic-text { order: 1; }
    .bengali-translation { order: 2; }
    .english-translation { order: 3; }

    /* Arabic Section: Neutral Theme Background */
    .arabic-text {
        background-color: var(--light-bg) !important;
        font-size: 1.8rem;
    }

    /* Bengali Section: Very Light Green Tint */
    .bengali-translation {
        background-color: rgba(46, 204, 113, 0.08) !important;
    }

    /* English Section: Standard Card Background */
    .english-translation {
        background-color: var(--card-bg) !important;
    }

    .dua-list a {
        flex-direction: column;
        text-align: center;
        gap: 5px;
    }
}

/* 11. Back to Top Button - Merged & Centered */
#backToTop {
    display: none; /* Controlled by script */
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 1001;
    background-color: rgba(0, 102, 33, 0.85); /* Matches new floating buttons */
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: none;
    outline: none;
    cursor: pointer;
    
    /* Crucial RESET: Removes all hidden browser spacing */
    padding: 0 !important;
    margin: 0 !important;
    line-height: 0 !important;
    
    /* New Sleeker Dimensions */
    width: 44px;
    height: 44px;
    border-radius: 50%;
    
    /* Flexbox Centering */
    display: flex;
    align-items: center;
    justify-content: center;
    
    box-shadow: 0 4px 15px var(--floating-btn-shadow);
    transition: transform 0.3s ease, background-color 0.3s ease, opacity 0.3s ease;
    opacity: 0.9;
}

#backToTop:hover {
    background-color: var(--dark-green);
    transform: translateY(0px) scale(1.1);
    opacity: 1;
}

/* Centering the SVG image inside the flex container */
#backToTop img {
    display: block;
    width: 20px; /* Reduced from 24px to match smaller button */
    height: 20px;
    margin: 0;
    pointer-events: none;
}

/* Dark Mode visibility override */
[data-theme="dark"] #backToTop {
    background-color: rgba(33, 145, 80, 0.85);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

/* 15. Floating Settings Panel & Arabic Fonts */
@font-face {
    font-family: 'Indopak';
    src: url('/assets/fonts/arabic/Indopak.ttf') format('truetype');
}

@font-face {
    font-family: 'Me Quran';
    src: url('/assets/fonts/arabic/Me%20Quran.ttf') format('truetype');
}

@font-face {
    font-family: 'Najed';
    src: url('/assets/fonts/arabic/Najed.ttf') format('truetype');
}

@font-face {
    font-family: 'Uthman Taha';
    src: url('/assets/fonts/arabic/Uthman%20Taha.ttf') format('truetype');
}

@font-face {
    font-family: 'Shonar Bangla';
    src: url('/assets/fonts/bengali/Shonar%20Bangla.ttf') format('truetype');
}

@font-face {
    font-family: 'SolaimanLipi';
    src: url('/assets/fonts/bengali/SolaimanLipi.ttf') format('truetype');
}

@font-face {
    font-family: 'BenSenHandwriting';
    src: url('../fonts/bengali/BenSenHandwriting.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Times New Roman';
    src: url('/assets/fonts/english/Times%20New%20Roman.ttf') format('truetype');
}

/* Floating Action Buttons Container */
.floating-actions-container {
    position: fixed;
    bottom: 90px;
    right: 30px;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.floating-menu-items {
    display: flex;
    flex-direction: column;
    gap: 15px;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.floating-action-btn {
    background-color: rgba(0, 102, 33, 0.85); /* Semi-transparent green */
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px var(--floating-btn-shadow);
    transition: all 0.3s ease;
    /* Added to match #backToTop transparency */
    opacity: 0.9;
}

[data-theme="dark"] .floating-action-btn {
    background-color: rgba(33, 145, 80, 0.85); /* Semi-transparent dark mode */
}

/* Desktop: Hide the trigger button, show items normally */
.trigger-btn {
    display: none !important;
}

/* Mobile Pop-out Logic */
@media (max-width: 600px) {
    .trigger-btn {
        display: flex !important;
        order: 2; /* Keep trigger at the bottom */
    }

    .floating-menu-items {
        order: 1;
        opacity: 0;
        visibility: hidden;
        transform: translateY(20px) scale(0.8);
        pointer-events: none;
        display: flex;
        flex-direction: column;
    }

    /* Force the Settings button to the TOP of the stack on mobile */
    #duaSettingsBtn {
        order: -1; 
    }

    /* When active, pop the menu items up */
    .floating-actions-container.active .floating-menu-items {
        opacity: 1;
        visibility: visible;
        transform: translateY(0) scale(1);
        pointer-events: auto;
    }

    /* Rotate the trigger icon when open */
    .floating-actions-container.active .trigger-btn {
        background-color: var(--dark-green);
        transform: rotate(45deg);
    }
}

.floating-action-btn:hover {
    transform: scale(1.1);
    background-color: var(--dark-green);
}

.dua-settings-modal {
    display: none; /* Hidden by default, toggled to 'flex' by JS */
    position: fixed;
    bottom: 150px;
    right: 30px;
    width: 320px;
    max-height: 60vh;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 1002;
    flex-direction: column;
    overflow: hidden; /* Keeps the rounded corners clean */
    animation: settingsFadeIn 0.3s ease forwards;
}

.settings-header {
    flex-shrink: 0; /* Prevents the header from collapsing */
    padding: 15px 20px;
    background: var(--light-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-body {
    flex-grow: 1;
    overflow-y: auto !important; /* Force enable vertical scrolling */
    -webkit-overflow-scrolling: touch; /* Smooth momentum for mobile */
    padding: 20px;
    /* Ensures the scrollbar is always visible when content overflows */
    scrollbar-width: thin;
    scrollbar-color: var(--primary-green) transparent;
}

/* For Chrome/Safari/Edge scrollbar visibility */
.settings-body::-webkit-scrollbar {
    width: 6px;
}
.settings-body::-webkit-scrollbar-thumb {
    background-color: var(--primary-green);
    border-radius: 10px;
}

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

.settings-header {
    padding: 15px 20px;
    background: var(--light-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-dark);
}

.close-settings {
    cursor: pointer;
    font-size: 24px;
    color: var(--text-muted);
}

.settings-body {
    padding: 20px;
}

.setting-item {
    margin-bottom: 25px;
}

.setting-item label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.setting-item select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--card-bg);
    color: var(--text-dark);
    font-family: inherit;
    outline: none;
}

.font-size-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--light-bg);
    padding: 6px;
    border-radius: 10px;
}

.font-size-controls button {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-dark);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: 0.2s;
}

.font-size-controls button:hover {
    border-color: var(--primary-green);
    color: var(--primary-green);
}

#fontSizeDisplay {
    font-weight: bold;
    color: var(--text-dark);
    font-size: 1rem;
}

/* Reset Button Styling */
.reset-settings-btn {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--primary-green);
    background: transparent;
    color: var(--primary-green);
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
}

/* The Glow Effect on Hover */
.reset-settings-btn:hover {
    background-color: var(--primary-green);
    color: white;
    box-shadow: 0 0 15px var(--primary-green); /* This creates the glow */
    transform: translateY(-1px);
}

.reset-settings-btn:active {
    transform: translateY(0);
    box-shadow: 0 0 5px var(--primary-green);
}

/* Download PDF Button Styling & Hover Effect */
.btn-download-pdf {
    background: var(--primary-green);
    color: white;
    border: none;
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-download-pdf:hover {
    background-color: var(--dark-green);
    box-shadow: 0 0 15px var(--primary-green);
    transform: translateY(-2px);
}

.btn-download-pdf:active {
    transform: translateY(0);
    box-shadow: 0 0 5px var(--primary-green);
}