/* General Body Styles */
body {
    font-family: 'Noto Nastaliq Urdu', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #fdfaf6;
    /* Creamy background */
    color: #4a4a4a;
}

/* Login Page Styles */
.login-body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #e8e0d5;
}

.login-container {
    background: white;
    padding: 2.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    width: 350px;
    text-align: center;
}

/* --- Admin Panel Layout --- */
.admin-wrapper {
    display: flex;
}

.admin-sidebar {
    width: 250px;
    background-color: #2c3e50;
    /* Dark slate blue */
    color: #ecf0f1;
    height: 100vh;
    position: fixed;
    right: 0;
    overflow-y: auto;
}

.sidebar-header {
    padding: 1.5rem;
    text-align: center;
    background-color: #34495e;
    border-bottom: 1px solid #4a627a;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.8rem;
}

.sidebar-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav a {
    display: block;
    padding: 1rem 1.5rem;
    color: #ecf0f1;
    text-decoration: none;
    font-size: 1.2rem;
    transition: background-color 0.3s;
}

.sidebar-nav a:hover {
    background-color: #4a627a;
}

.admin-main {
    margin-right: 250px;
    /* Same as sidebar width */
    width: calc(100% - 250px);
    padding: 0;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background-color: #ffffff;
    border-bottom: 1px solid #e0e0e0;
}

.admin-header h1 {
    margin: 0;
    font-size: 1.8rem;
}

.logout-btn {
    background-color: #e74c3c;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 5px;
    text-decoration: none;
}

.admin-content {
    padding: 2rem;
}

/* Dashboard Widgets */
.dashboard-widgets {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.widget {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    text-align: center;
}

.widget h3 {
    margin-top: 0;
    font-size: 1.2rem;
    color: #34495e;
}

.widget p {
    font-size: 2.5rem;
    font-weight: bold;
    margin: 0;
    color: #2c3e50;
}

/* Dashboard Actions */
.dashboard-actions {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.action-buttons {
    display: flex;
    gap: 1rem;
}

/* Form Styles */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    /* Important */
    font-family: inherit;
    font-size: 1rem;
}

button {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 4px;
    background-color: #2980b9;
    color: white;
    font-size: 1.1rem;
    font-family: 'Noto Nastaliq Urdu', sans-serif;
    cursor: pointer;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #3498db;
}

.error {
    color: #e74c3c;
    text-align: center;
    margin-top: 1rem;
}

/* --- Form Messages --- */
#form-message {
    padding: 1rem;
    border-radius: 5px;
    margin-bottom: 1rem;
    font-size: 1rem;
    display: none;
    /* Hidden by default */
}

#form-message.success {
    display: block;
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

#form-message.error {
    display: block;
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.settings-form-container {
    max-width: 800px;
}

/* --- Books Management Page --- */
.card {
    background: white;
    padding: 1.5rem 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    margin-bottom: 2rem;
}

.add-book-form-container h3,
.book-list-container h3 {
    margin-top: 0;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
}

/* --- Book List Table --- */
.book-list-container table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.book-list-container th,
.book-list-container td {
    padding: 0.8rem 1rem;
    text-align: right;
    border-bottom: 1px solid #e0e0e0;
}

.book-list-container th {
    font-weight: bold;
    background-color: #f9f9f9;
}

.book-list-container tr:last-child td {
    border-bottom: none;
}

.small-btn {
    padding: 0.3rem 0.7rem;
    font-size: 0.9rem;
    background-color: #3498db;
}

.small-btn.danger {
    background-color: #e74c3c;
}

/* --- Public Site Styles --- */
.public-body {
    background-color: #e8e0d5;
    /* Warm beige background */
    font-size: 1.2rem;
    line-height: 1.8;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

.site-header {
    text-align: center;
    padding: 2rem 0;
    background-color: #2c3e50;
    color: white;
}

.site-header h1 {
    margin: 0;
    font-size: 3rem;
}

.site-footer {
    text-align: center;
    padding: 1rem 0;
    margin-top: 2rem;
    color: #555;
    font-size: 0.9rem;
}

/* Bookshelf Styles */
.bookshelf {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 2rem;
    justify-items: center;
}

.book {
    text-decoration: none;
    color: inherit;
}

.book-cover {
    width: 180px;
    height: 250px;
    background-color: #34495e;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1rem;
    border-radius: 5px 2px 2px 5px;
    box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    font-size: 1.5rem;
    font-weight: bold;
}

.book-cover::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 0;
    bottom: 0;
    width: 3px;
    background: rgba(0, 0, 0, 0.2);
}

.book:hover .book-cover {
    transform: translateY(-10px);
    box-shadow: 10px 15px 25px rgba(0, 0, 0, 0.3);
}

/* --- Book Viewer Styles --- */
.viewer-body {
    background-color: #d7c7b5;
    overflow: hidden;
}

.book-viewer {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.page {
    width: 80%;
    max-width: 800px;
    height: 90vh;
    background: url('https://media.freestocktextures.com/cache/e6/3b/e63bacc24974e699953c3c39aad98d88.jpg');
    /* Page texture */
    background-size: cover;
    padding: 3rem 4rem;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.4);
    overflow-y: auto;
    font-size: 1.8rem;
    line-height: 2.2;
    text-align: justify;
    color: #333;

    /* URDU ALIGNMENT FIXES */
    direction: rtl;
    text-align: right;
    font-family: 'Noto Nastaliq Urdu', serif;
}

.page .word {
    transition: background-color 0.2s;
}

.page .word:hover {
    background-color: rgba(255, 229, 153, 0.7);
    /* A gentle yellow highlight */
}

/* --- Dictionary Popup Container --- */
.meaning-popup {
    display: none;
    /* Hidden by default */
    position: fixed;
    /* Stays on screen */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    /* Dark overlay */
    justify-content: center;
    align-items: center;
    z-index: 99999;
    /* <-- THIS IS THE FIX */
}

.meaning-popup.visible {
    opacity: 1;
    visibility: visible;
}

#meaning-content {
    background-color: #fdfaf6;
    padding: 2rem;
    border-radius: 8px;
    max-width: 650px;
    /* Increased max-width */
    width: 90%;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    position: relative;
    font-family: 'Noto Nastaliq Urdu', sans-serif;
    color: #333;
    font-size: 1rem;
    /* Reduced font size */
    line-height: 1.8;
    /* Adjusted line height for smaller font */
}

#meaning-content h3 {
    margin-top: 0;
    font-size: 2rem;
    color: #2c3e50;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.close-popup {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2.5rem;
    color: #888;
    cursor: pointer;
}

.back-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.4);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 5px;
    text-decoration: none;
    font-family: sans-serif;
    font-size: 0.9rem;
    z-index: 100;
}

.back-btn:hover {
    background: rgba(0, 0, 0, 0.6);
}

/* --- Dictionary Manager Page --- */
.dictionary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.dictionary-controls {
    display: flex;
    gap: 1rem;
}

.dictionary-controls input,
.dictionary-controls select {
    padding: 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.status {
    padding: 0.2rem 0.5rem;
    border-radius: 10px;
    font-size: 0.8rem;
    color: white;
    font-weight: bold;
}

.status.synced {
    background-color: #27ae60;
}

.status.unsynced {
    background-color: #f39c12;
}

.word-col {
    font-size: 1.2rem;
    font-weight: bold;
}

#pagination-container {
    margin-top: 1.5rem;
    text-align: center;
}

.page-btn {
    margin: 0 0.2rem;
    background-color: #ecf0f1;
    color: #2c3e50;
    border: 1px solid #bdc3c7;
}

.page-btn.active {
    background-color: #3498db;
    color: white;
    border-color: #3498db;
}

/* --- Sync Modal Styles --- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    max-height: 85vh;
    overflow-y: auto !important;
    position: relative;
    display: flex;
    flex-direction: column;
}

.progress-bar {
    background: #ecf0f1;
    border-radius: 10px;
    overflow: hidden;
    margin: 1rem 0;
}

.progress-bar-inner {
    height: 20px;
    width: 0%;
    background: #3498db;
    transition: width 0.4s ease;
}

/* Find and replace the existing .sync-log style */
.sync-log {
    background: #2c3e50;
    color: #ecf0f1;
    font-family: monospace;
    font-size: 0.9rem;
    padding: 1rem;
    height: 200px;
    overflow-y: auto;
    border-radius: 4px;
    white-space: pre-wrap;
    direction: rtl;
    /* Add this line */
    text-align: right;
    /* Add this line */
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1.5rem;
}

.cancel-btn {
    background-color: #7f8c8d;
}

.cancel-btn:hover {
    background-color: #95a5a6;
}

.readonly-input {
    background-color: #ecf0f1;
    cursor: not-allowed;
}

/* --- Meaning Popup Table --- */
.meaning-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    font-size: 1rem;
}

.meaning-table td {
    padding: 0.75rem;
    border: 1px solid #ddd;
    text-align: right;
}

.meaning-table tr td:first-child {
    font-weight: bold;
    background-color: #f9f9f9;
    width: 30%;
    /* Give the label column a fixed width */
}

/* --- Enhanced Meaning Popup --- */
.meaning-scroll-container {
    max-height: 60vh;
    /* Set a max height relative to the viewport */
    overflow-y: auto;
    /* Add a scrollbar if content overflows */
    padding-right: 10px;
    /* Space for the scrollbar */
}

.meaning-table .label {
    font-weight: bold;
    background-color: #f9f9f9;
    width: 25%;
}

.meaning-table-compact {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    font-size: 0.9rem;
    /* Smaller font for compact info */
}

.meaning-table-compact td {
    border: 1px solid #ddd;
    padding: 0.5rem;
    width: 25%;
    /* Each cell takes 25% of the width */
}

.meaning-table-compact .label {
    font-weight: bold;
    background-color: #f9f9f9;
}

.form-group-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.modal-scroll-container {
    max-height: 65vh;
    /* Set a maximum height for the form area */
    overflow-y: auto;
    /* Add a vertical scrollbar if needed */
    padding: 5px;
    margin: -5px;
    border-bottom: 1px solid #eee;
    margin-bottom: 1rem;
}

.page-ellipsis {
    display: inline-block;
    padding: 0.5rem 0.8rem;
    margin: 0 0.2rem;
    color: #7f8c8d;
}






/* --- Admin: Book Builder --- */

.book-builder .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.book-builder .btn,
.btn {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.book-builder .btn:hover {
    background-color: #0056b3;
}

.book-builder .btn-secondary {
    background-color: #6c757d;
}

.book-builder .btn-secondary:hover {
    background-color: #5a6268;
}

.book-builder .btn-danger {
    background-color: #dc3545;
}

.book-builder .btn-danger:hover {
    background-color: #c82333;
}

.book-builder .btn-sm {
    padding: 4px 8px;
    font-size: 12px;
}

.book-list table {
    width: 100%;
    border-collapse: collapse;
}

.book-list th,
.book-list td {
    border-bottom: 1px solid #eee;
    padding: 12px 8px;
    text-align: right;
}

.book-list th {
    text-align: right;
    font-weight: bold;
}

.list-cover-preview {
    width: 40px;
    height: 60px;
    object-fit: cover;
    border-radius: 2px;
}

.builder-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

.metadata-form,
.structure-manager {
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 15px;
}

.metadata-form h4,
.structure-manager h4 {
    margin-top: 0;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.form-group-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

.unit-list {
    border: 1px solid #eee;
    border-radius: 4px;
    min-height: 100px;
    padding: 5px;
    background: #fdfdfd;
}

.unit-item {
    display: flex;
    align-items: center;
    padding: 10px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 3px;
    margin-bottom: 5px;
}

.unit-drag-handle {
    cursor: move;
    margin-left: 8px;
    color: #aaa;
}

.unit-icon {
    margin-right: 8px;
}

.unit-title {
    flex-grow: 1;
}

.unit-actions {
    margin-right: auto;
}

.structure-actions {
    margin-top: 10px;
}

.builder-actions {
    margin-top: 20px;
    border-top: 1px solid #eee;
    padding-top: 20px;
}

.modal-content.large {
    width: 80%;
    max-width: 1000px;
}

.form-group input.full-width {
    width: 100%;
}

/* --- Public: Bookshelf Grid --- */

.bookshelf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    padding: 20px;
}

.book-cover-link {
    text-decoration: none;
    color: #333;
}

.book-cover-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transition: all 0.2s ease-in-out;
    overflow: hidden;
}

.book-cover-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

.book-cover-img {
    width: 100%;
    height: 250px;
    object-fit: cover;
    border-bottom: 1px solid #eee;
}

.book-cover-title {
    font-size: 1.1rem;
    font-weight: 700;
    padding: 10px 12px 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-cover-author {
    font-size: 0.9rem;
    color: #555;
    padding: 0 12px 12px;
}


/* --- Public: Book Outline Page --- */
.outline-page {
    background: #f9f9f9;
}

.book-outline-card {
    max-width: 800px;
    margin: 20px auto;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.07);
    overflow: hidden;
}

.outline-header {
    display: flex;
    padding: 25px;
    background: #fdfdfd;
    border-bottom: 1px solid #eee;
}

.outline-cover {
    width: 150px;
    height: 220px;
    object-fit: cover;
    border-radius: 5px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-left: 25px;
}

.outline-meta h1 {
    margin: 0;
    font-size: 2.2rem;
}

.outline-meta h2 {
    margin: 5px 0 10px;
    font-size: 1.4rem;
    font-weight: 400;
    color: #444;
}

.outline-meta p {
    margin: 0;
    font-size: 1rem;
    color: #777;
    background: #f5f5f5;
    display: inline-block;
    padding: 4px 10px;
    border-radius: 15px;
}

.outline-nav {
    padding: 20px;
}

.outline-nav h3 {
    margin-top: 0;
    font-size: 1.5rem;
    border-bottom: 2px solid #007bff;
    padding-bottom: 10px;
    display: inline-block;
}

.unit-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.unit-list li {
    margin-bottom: 10px;
}

.unit-link {
    display: flex;
    align-items: center;
    background: #f9f9f9;
    padding: 15px;
    border-radius: 5px;
    text-decoration: none;
    color: #333;
    transition: all 0.2s ease;
    border: 1px solid #eee;
}

.unit-link:hover {
    background: #f0f0f0;
    border-color: #ddd;
    transform: translateX(-5px);
}

.unit-link .unit-icon {
    font-size: 1.2rem;
    margin-left: 10px;
}

.unit-link .unit-title {
    flex-grow: 1;
    font-size: 1.2rem;
    font-weight: 700;
}

.unit-link .unit-arrow {
    font-size: 1.2rem;
    font-weight: 700;
    color: #007bff;
}

/* --- Public: New Column-Based Viewer --- */

.book-viewer {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px 0;
}

.page-container {
    background: #fff;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);

    /* --- A5 Page Size (Portrait) --- */
    width: 148mm;
    height: 210mm;
    padding: 15mm;

    /* --- This is the CSS Column Logic --- */
    column-width: calc(148mm - 30mm);
    /* Page width minus padding */
    column-gap: 30mm;
    /* The space between pages (padding) */
    column-fill: auto;

    /* --- Hides the scrollbar --- */
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    /* For Firefox */
    -ms-overflow-style: none;
    /* For IE and Edge */

    /* This makes it snap to pages */
    scroll-snap-type: x mandatory;

    /* --- THIS FIXES THE SCROLL PROBLEM --- */
    /* Tells the snap where the "start" is (inside the padding) */
    scroll-padding-right: 15mm;

    /* This makes it flow from right to left */
    direction: rtl;

    /* Font styles */
    font-size: 1.3rem;
    line-height: 2.2;

    /* This makes the button-click scroll animated */
    scroll-behavior: smooth;

    /* --- THIS FIXES THE JUSTIFY PROBLEM --- */
    text-align: justify;
}

/* For Chrome, Safari, and Opera */
.page-container::-webkit-scrollbar {
    display: none;
}

/* Make sure all content inside snaps correctly */
.page-container>* {
    scroll-snap-align: start;
    break-inside: avoid;
}

.page-container p,
.page-container h1,
.page-container h2,
.page-container h3,
.page-container ul,
.page-container ol {
    margin-bottom: 1.2em;
    direction: rtl;
}

.page-container h1 {
    font-size: 2.5rem;
}

.page-container h2 {
    font-size: 2rem;
}

.page-container h3 {
    font-size: 1.7rem;
}

/* This is the clickable word span */
.word {
    cursor: pointer;
}

.word:hover {
    background-color: #ffd;
}

/* CRITICAL: Word Status Colors - These were missing! */
.word.status-verified {
    color: #27ae60 !important;
    font-weight: bold;
}

.word.status-synced {
    color: #f39c12 !important;
}

.word.status-unsynced {
    color: #e74c3c !important;
}

.word.status-unknown {
    color: #95a5a6 !important;
}

.viewer-body .loading {
    font-size: 1.5rem;
    color: #777;
    text-align: center;
    padding-top: 40%;
}

.viewer-body .loading.error {
    color: #dc3545;
}

/* --- Dictionary Popup --- */
.meaning-popup h3 {
    margin-top: 0;
    font-size: 2rem;
}

.meaning-popup .roman {
    font-size: 1.1rem;
    color: #555;
    margin-top: -15px;
    font-style: italic;
}

.meaning-popup .definition {
    font-size: 1.2rem;
    line-height: 1.8;
}

.meaning-popup .english {
    font-size: 1.1rem;
    color: #0056b3;
    font-family: Arial, sans-serif;
    text-align: left;
    direction: ltr;
    border-top: 1px solid #eee;
    padding-top: 10px;
}

.meaning-popup .meta {
    font-size: 1rem;
    color: #777;
    font-style: italic;
}

.meaning-popup .details {
    font-size: 1.1rem;
    line-height: 1.7;
    border-top: 1px dashed #ddd;
    padding-top: 10px;
    margin-top: 10px;
}

.meaning-popup .details strong {
    color: #000;
}

/* --- New Wrapper for Page Scrolling --- */
#content-wrapper {
    width: 100%;
    /* This animation makes the page turn smooth */
    transition: transform 0.3s ease-in-out;
    transform: translateY(0);
    /* Default position */
}

/* --- Clickable Word Style --- */

.word {
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.word:hover {
    background-color: #ffd;
    /* Yellow highlight */
}

/* --- Dictionary Popup Container (The Missing CSS) --- */

/* --- Dictionary Popup Container --- */
.meaning-popup {
    display: none;
    /* Hidden by default */
    position: fixed;
    /* Stays on screen */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    /* Dark overlay */
    justify-content: center;
    align-items: center;
    z-index: 99999;
    /* <-- THIS IS THE FIX */
}

#meaning-content {
    background: #fff;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 500px;
    max-height: 70vh;
    overflow-y: auto;
    direction: rtl;
    /* Ensure content is RTL */
    position: relative;
}

.close-popup {
    position: absolute;
    top: 10px;
    left: 15px;
    /* Switched to left for RTL */
    background: none;
    border: none;
    font-size: 2rem;
    color: #aaa;
    cursor: pointer;
    line-height: 1;
}

.close-popup:hover {
    color: #333;
}

/* --- Rich Dictionary Popup Styles --- */

#meaning-content h3 {
    margin-top: 0;
    font-size: 2.2rem;
    color: #0056b3;
    margin-bottom: 5px;
}

#meaning-content .meta-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 15px;
}

#meaning-content .roman {
    font-size: 1.1rem;
    color: #555;
    font-style: italic;
    margin-left: 10px;
}

#meaning-content .meta-tag {
    font-size: 0.9rem;
    color: #007bff;
    background: #f0f8ff;
    border: 1px solid #cce5ff;
    border-radius: 4px;
    padding: 2px 8px;
    margin-right: 5px;
}

#meaning-content .definition {
    font-size: 1.2rem;
    line-height: 1.8;
    margin-top: 0;
    border-bottom: 1px solid #eee;
    padding-bottom: 15px;
}

#meaning-content .english {
    font-size: 1.1rem;
    color: #333;
    font-family: Arial, sans-serif;
    text-align: left;
    direction: ltr;
    border-bottom: 1px solid #eee;
    padding-bottom: 15px;
}

#meaning-content .english b {
    color: #0056b3;
}

#meaning-content .detail-block {
    font-size: 1.1rem;
    line-height: 1.7;
    border-bottom: 1px solid #eee;
    padding-bottom: 15px;
    margin-bottom: 15px;
}

#meaning-content .detail-block div {
    margin-bottom: 8px;
}

#meaning-content .detail-block strong {
    color: #000;
    min-width: 120px;
    display: inline-block;
}

#meaning-content .detail-block em {
    color: #555;
    font-style: italic;
}

#meaning-content .grammar-def {
    font-size: 1rem;
    color: #444;
    background: #f9f9f9;
    border-right: 3px solid #007bff;
    padding: 10px;
    margin-top: 10px;
}

/* --- [NEW] Admin: Quiz Builder Styles --- */

.quiz-questions-container {
    max-height: 50vh;
    overflow-y: auto;
    padding: 10px;
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 15px;
}

.quiz-question-item {
    padding: 15px;
    margin-bottom: 10px;
}

.quiz-question-item.card {
    background: #fff;
    border: 1px solid #ccc;
    box-shadow: none;
}

.quiz-question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
    margin-bottom: 10px;
}

.quiz-question-input {
    width: 100%;
    padding: 8px;
    font-family: 'Noto Nastaliq Urdu', sans-serif;
    font-size: 1.1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    min-height: 80px;
}

.quiz-options-list {
    margin-top: 15px;
}

.quiz-option-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

.quiz-option-item input[type="radio"] {
    margin-left: 8px;
    flex-shrink: 0;
}

.quiz-option-input {
    flex-grow: 1;
    margin-right: 8px;
    padding: 6px;
    font-family: 'Noto Nastaliq Urdu', sans-serif;
    font-size: 1rem;
    border: 1px solid #ddd;
}

/* --- [NEW] Public: Quiz Viewer Styles --- */

.quiz-container {
    max-width: 800px;
    margin: 20px auto;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    direction: rtl;
    /* Ensure quiz is RTL */
}

.quiz-header {
    padding: 20px 25px;
    background: #f9f9f9;
    border-bottom: 1px solid #eee;
}

.quiz-header h1 {
    margin: 0;
    font-size: 1.8rem;
}

.quiz-progress {
    font-size: 1rem;
    color: #555;
    margin-top: 5px;
}

.quiz-body {
    padding: 25px;
}

.quiz-question h2 {
    font-size: 1.4rem;
    line-height: 1.6;
    margin-bottom: 25px;
}

.quiz-options-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.quiz-option {
    display: flex;
    align-items: center;
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quiz-option:hover {
    background: #f9f9f9;
}

.quiz-option.selected {
    border-color: #007bff;
    background: #f0f8ff;
}

.option-radio {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid #aaa;
    margin-left: 15px;
    flex-shrink: 0;
    position: relative;
}

.quiz-option.selected .option-radio {
    border-color: #007bff;
    background: #007bff;
}

.option-radio::after {
    content: '';
    display: block;
    width: 10px;
    height: 10px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.2s ease;
}

.quiz-option.selected .option-radio::after {
    transform: translate(-50%, -50%) scale(1);
}

.option-text {
    font-size: 1.2rem;
    line-height: 1.5;
}

.quiz-footer {
    padding: 20px 25px;
    background: #f9f9f9;
    border-top: 1px solid #eee;
    text-align: left;
    /* Aligns button to the left (end of RTL) */
}

.quiz-footer .btn {
    font-size: 1.1rem;
    padding: 10px 20px;
}

.quiz-footer .btn:disabled {
    background: #aaa;
    cursor: not-allowed;
}

.quiz-results {
    padding: 40px 25px;
    text-align: center;
}

.quiz-results h2 {
    font-size: 2rem;
    margin-bottom: 20px;
}

#quiz-score {
    font-size: 1.5rem;
    margin-bottom: 30px;
}

/* --- [NEW] Admin: Heading Structure Styles --- */

.heading-list {
    padding: 10px;
    background: #f4f4f4;
    border-radius: 5px;
}

.heading-item {
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 5px;
    margin-bottom: 15px;
}

.heading-header {
    display: flex;
    align-items: center;
    background: #e9ecef;
    padding: 10px 15px;
    border-bottom: 1px solid #ccc;
}

.heading-drag-handle {
    cursor: move;
    margin-left: 8px;
    color: #555;
    font-size: 1.2rem;
}

.heading-title-input {
    flex-grow: 1;
    font-size: 1.2rem;
    font-weight: bold;
    border: none;
    background: transparent;
    padding: 5px;
    margin-right: 10px;
}

.heading-title-input:focus {
    background: #fff;
    border: 1px solid #007bff;
}

.heading-actions {
    margin-right: auto;
    display: flex;
    gap: 5px;
}

.child-unit-list {
    min-height: 50px;
    padding: 10px;
}

.child-unit-list .unit-item {
    background: #fdfdfd;
}

/* --- [NEW] Public: Collapsible Heading Styles --- */

.heading-list-public {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.heading-item-public {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
}

.heading-title-public {
    font-size: 1.5rem;
    font-weight: 700;
    padding: 15px 20px;
    margin: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    background: #f9f9f9;
    border-bottom: 1px solid #eee;
}

.heading-title-public:hover {
    background: #f0f0f0;
}


/* Table Refinement */
table {
    border-collapse: separate;
    border-spacing: 0 8px;
    /* Row spacing */
}

th {
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 1px;
    color: #7f8c8d;
    border-bottom: none;
}

td {
    background: white;
    border-top: 1px solid #eee;
    border-bottom: 1px solid #eee;
}

td:first-child {
    border-left: 1px solid #eee;
    border-top-left-radius: var(--radius-sm);
    border-bottom-left-radius: var(--radius-sm);
}

td:last-child {
    border-right: 1px solid #eee;
    border-top-right-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
}

/* Meaning Popup Glassmorphism */
.meaning-popup {
    backdrop-filter: blur(5px);
}

#meaning-content {
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.98);
}

/* --- Audio Sync Tool Styles --- */
.sync-text-container {
    user-select: none;
}

.sync-word {
    display: inline-block;
    padding: 2px 4px;
    margin: 2px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.sync-word:hover {
    background-color: #efefef;
    border-color: #ccc;
}

.sync-word.synced {
    background-color: #fff9c4;
    /* Soft Yellow */
    border-color: #fdd835;
    color: #333;
}

.sync-word.active {
    background-color: #ffeb3b;
    /* Bright Yellow */
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
    border-color: #fbc02d;
}

.sync-word.next-to-sync {
    border-bottom: 2px solid #2196f3;
    /* Blue underline hint */
}