/* SID Doc to Book Frontend Styles */

/* ============================================
   FONT IMPORTS - Arabic & Urdu Google Fonts
   ============================================ */
@import url('https://fonts.googleapis.com/css2?family=Amiri:ital,wght@0,400;0,700;1,400;1,700&family=Noto+Nastaliq+Urdu:wght@400;500;600;700&family=Noto+Naskh+Arabic:wght@400;500;600;700&family=Scheherazade+New:wght@400;500;600;700&display=swap');

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

.sdtb-book-container {
    max-width: 900px;
    margin: 30px auto;
    padding: 20px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #fff;
}

/* ============================================
   LANGUAGE-SPECIFIC FONT FAMILIES
   ============================================ */

/* Urdu Language - Nastaliq style font */
.sdtb-book-container[data-language="urdu"],
[dir="rtl"].sdtb-book-container[data-language="urdu"] {
    font-family: 'Noto Nastaliq Urdu', 'Jameel Noori Nastaleeq', 'Urdu Typesetting', serif;
}

.sdtb-book-container[data-language="urdu"] .sdtb-page-content {
    font-family: 'Noto Nastaliq Urdu', 'Jameel Noori Nastaleeq', 'Urdu Typesetting', serif;
    font-size: 1.3em;
    line-height: 2.2;
    letter-spacing: 0;
    word-spacing: 2px;
}

/* Arabic Language - Naskh style font (proper Arabic, not Urdu) */
.sdtb-book-container[data-language="arabic"],
[dir="rtl"].sdtb-book-container[data-language="arabic"] {
    font-family: 'Amiri', 'Noto Naskh Arabic', 'Scheherazade New', 'Traditional Arabic', serif;
}

.sdtb-book-container[data-language="arabic"] .sdtb-page-content {
    font-family: 'Amiri', 'Noto Naskh Arabic', 'Scheherazade New', 'Traditional Arabic', serif;
    font-size: 1.4em;
    line-height: 2.0;
    letter-spacing: 0;
    word-spacing: 1px;
}

/* Mixed Language (Arabic + Urdu) */
.sdtb-book-container[data-language="mixed"],
[dir="rtl"].sdtb-book-container[data-language="mixed"] {
    font-family: 'Noto Naskh Arabic', 'Amiri', 'Noto Nastaliq Urdu', serif;
}

.sdtb-book-container[data-language="mixed"] .sdtb-page-content {
    font-family: 'Noto Naskh Arabic', 'Amiri', 'Noto Nastaliq Urdu', serif;
    font-size: 1.3em;
    line-height: 2.0;
}

/* Prevent letter collision/overlap in RTL text */
[dir="rtl"] .sdtb-page-content {
    text-rendering: optimizeLegibility;
    -webkit-font-feature-settings: "kern" 1, "liga" 1;
    font-feature-settings: "kern" 1, "liga" 1;
    word-break: normal;
    overflow-wrap: break-word;
}

/* Book Header */
.sdtb-book-header {
    margin-bottom: 40px;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 30px;
}

.sdtb-book-info {
    display: flex;
    gap: 30px;
    margin-bottom: 30px;
}

.sdtb-book-thumbnail {
    flex-shrink: 0;
}

.sdtb-book-thumbnail img {
    max-width: 200px;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.sdtb-book-meta {
    flex: 1;
}

.sdtb-book-meta h1 {
    margin-top: 0;
    font-size: 2.5em;
    margin-bottom: 15px;
    color: #333;
}

.sdtb-author,
.sdtb-pages {
    margin: 10px 0;
    font-size: 1.1em;
    color: #666;
}

.sdtb-excerpt {
    margin-top: 20px;
    line-height: 1.6;
    color: #555;
    font-style: italic;
}

/* Search Box */
.sdtb-search-box {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 30px;
}

.sdtb-search-input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #ddd;
    border-radius: 4px;
    font-size: 1em;
    margin-bottom: 10px;
}

.sdtb-search-input:focus {
    outline: none;
    border-color: #0073aa;
    box-shadow: 0 0 5px rgba(0, 115, 170, 0.3);
}

.sdtb-search-button {
    padding: 12px 30px;
    background: #0073aa;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    font-weight: bold;
}

.sdtb-search-button:hover {
    background: #005a87;
}

.sdtb-search-results {
    margin-top: 15px;
    max-height: 300px;
    overflow-y: auto;
}

.sdtb-search-result-item {
    padding: 10px;
    background: white;
    border-left: 4px solid #0073aa;
    margin-bottom: 8px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.sdtb-search-result-item:hover {
    background: #f0f0f0;
}

/* Book Reader */
.sdtb-reader {
    margin-bottom: 40px;
    min-height: 600px;
    background: #fafafa;
    padding: 40px;
    border-radius: 8px;
}

.sdtb-page {
    background: white;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.sdtb-page-number {
    text-align: center;
    color: #999;
    font-size: 0.9em;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e0e0;
}

.sdtb-page-title {
    font-size: 1.8em;
    margin-top: 0;
    margin-bottom: 25px;
    color: #333;
    border-bottom: 2px solid #0073aa;
    padding-bottom: 15px;
}

.sdtb-page-content {
    font-size: 1.1em;
    line-height: 1.8;
    color: #333;
    word-wrap: break-word;
    user-select: text;
    -webkit-user-select: text;
    margin-bottom: 30px;
}

.sdtb-page-content::selection {
    background-color: #0073aa;
    color: white;
}

/* Formatting preservation styles */
.sdtb-page-content p {
    margin-bottom: 15px;
    margin-top: 0;
}

.sdtb-page-content h1,
.sdtb-page-content h2,
.sdtb-page-content h3,
.sdtb-page-content h4,
.sdtb-page-content h5,
.sdtb-page-content h6 {
    font-weight: bold;
    margin-top: 20px;
    margin-bottom: 15px;
    color: #222;
}

.sdtb-page-content h1 { font-size: 2em; }
.sdtb-page-content h2 { font-size: 1.8em; }
.sdtb-page-content h3 { font-size: 1.6em; }
.sdtb-page-content h4 { font-size: 1.4em; }
.sdtb-page-content h5 { font-size: 1.2em; }
.sdtb-page-content h6 { font-size: 1.1em; }

.sdtb-page-content strong {
    font-weight: bold;
    color: #222;
}

.sdtb-page-content em {
    font-style: italic;
    color: #555;
}

.sdtb-page-content u {
    text-decoration: underline;
}

.sdtb-page-content span[style*="font-size"] {
    /* Preserve font size from document */
}

.sdtb-no-content {
    text-align: center;
    padding: 60px 20px;
    color: #999;
    font-size: 1.2em;
}

/* Selection Tools */
.sdtb-page-selection-tools {
    display: flex;
    gap: 10px;
    padding: 20px 0;
    border-top: 1px solid #e0e0e0;
}

.sdtb-select-all,
.sdtb-copy-selection {
    padding: 10px 20px;
    background: #0073aa;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95em;
    transition: all 0.3s ease;
}

.sdtb-select-all:hover,
.sdtb-copy-selection:hover {
    background: #005a87;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Navigation */
.sdtb-navigation {
    margin-top: 40px;
}

.sdtb-nav-buttons {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.sdtb-nav-prev,
.sdtb-nav-next {
    padding: 12px 25px;
    background: #0073aa;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.3s ease;
    font-weight: bold;
}

.sdtb-nav-prev:hover,
.sdtb-nav-next:hover {
    background: #005a87;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.sdtb-page-input {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.sdtb-page-input label {
    font-weight: bold;
    color: #333;
}

.sdtb-page-number-input {
    width: 80px;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 4px;
    text-align: center;
    font-size: 1em;
}

.sdtb-page-number-input:focus {
    outline: none;
    border-color: #0073aa;
}

.sdtb-go-btn {
    padding: 10px 20px;
    background: #0073aa;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
}

.sdtb-go-btn:hover {
    background: #005a87;
}

/* Progress Bar */
.sdtb-progress {
    width: 100%;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
}

.sdtb-progress-bar {
    height: 100%;
    background: linear-gradient(to right, #0073aa, #00a8e1);
    transition: width 0.3s ease;
    border-radius: 4px;
}

/* Archive Page */
.sdtb-archive {
    max-width: 1200px;
    margin: 30px auto;
    padding: 20px;
}

.sdtb-archive h1 {
    margin-bottom: 40px;
    text-align: center;
    font-size: 2.5em;
    color: #333;
}

.sdtb-books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 30px;
    margin-bottom: 40px;
}

.sdtb-book-card {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.sdtb-book-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.sdtb-card-thumbnail {
    overflow: hidden;
    height: 300px;
}

.sdtb-card-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.sdtb-card-thumbnail:hover img {
    transform: scale(1.05);
}

.sdtb-card-body {
    padding: 20px;
}

.sdtb-card-body h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.3em;
}

.sdtb-card-body h3 a {
    color: #333;
    text-decoration: none;
}

.sdtb-card-body h3 a:hover {
    color: #0073aa;
}

.sdtb-card-author {
    color: #666;
    font-size: 0.95em;
    margin: 5px 0;
}

.sdtb-card-pages {
    color: #999;
    font-size: 0.9em;
    margin: 5px 0;
}

.sdtb-card-excerpt {
    color: #555;
    font-size: 0.95em;
    line-height: 1.6;
    margin: 15px 0;
}

.sdtb-read-btn {
    display: inline-block;
    padding: 10px 20px;
    background: #0073aa;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.3s ease;
    font-weight: bold;
}

.sdtb-read-btn:hover {
    background: #005a87;
    transform: translateX(3px);
}

/* RTL Support */
[dir="rtl"] .sdtb-book-info {
    flex-direction: row-reverse;
}

[dir="rtl"] .sdtb-nav-buttons {
    flex-direction: row-reverse;
}

[dir="rtl"] .sdtb-page-input {
    flex-direction: row-reverse;
}

[dir="rtl"] .sdtb-search-result-item {
    border-left: none;
    border-right: 4px solid #0073aa;
}

/* Responsive Design */
@media (max-width: 768px) {
    .sdtb-book-info {
        flex-direction: column;
    }

    .sdtb-book-meta h1 {
        font-size: 1.8em;
    }

    .sdtb-reader {
        padding: 20px;
    }

    .sdtb-page {
        padding: 20px;
    }

    .sdtb-page-content {
        font-size: 1em;
    }

    .sdtb-nav-buttons {
        flex-direction: column;
        align-items: stretch;
    }

    .sdtb-nav-prev,
    .sdtb-nav-next,
    .sdtb-go-btn {
        width: 100%;
        text-align: center;
    }

    .sdtb-page-input {
        width: 100%;
    }

    .sdtb-page-number-input {
        flex: 1;
    }

    .sdtb-books-grid {
        grid-template-columns: 1fr;
    }

    [dir="rtl"] .sdtb-book-info {
        flex-direction: column;
    }

    [dir="rtl"] .sdtb-nav-buttons {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .sdtb-book-container {
        padding: 10px;
        margin: 10px auto;
    }

    .sdtb-book-header {
        margin-bottom: 20px;
        padding-bottom: 20px;
    }

    .sdtb-book-meta h1 {
        font-size: 1.4em;
    }

    .sdtb-page-selection-tools {
        flex-direction: column;
    }

    .sdtb-select-all,
    .sdtb-copy-selection {
        width: 100%;
    }
}

/* ============================================
   SEARCH HIGHLIGHT STYLES
   ============================================ */

/* Highlight matched text in page content */
.sdtb-search-highlight {
    background-color: #ffeb3b;
    color: #000;
    padding: 2px 4px;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Pulse animation for first match */
.sdtb-highlight-pulse {
    animation: sdtb-pulse 1s ease-in-out 2;
}

@keyframes sdtb-pulse {
    0%, 100% {
        background-color: #ffeb3b;
        transform: scale(1);
    }
    50% {
        background-color: #ff9800;
        transform: scale(1.05);
    }
}

/* Highlight in search result snippets */
.sdtb-highlight-snippet {
    background-color: #fff3cd;
    color: #856404;
    padding: 1px 3px;
    border-radius: 2px;
    font-weight: bold;
}

/* Search result snippet styling */
.sdtb-result-snippet {
    font-size: 0.85em;
    color: #666;
    margin-top: 5px;
    line-height: 1.5;
    max-height: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Current page badge in search results */
.sdtb-current-badge {
    background: #28a745;
    color: white;
    font-size: 0.75em;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 8px;
}

/* Highlight current page result */
.sdtb-current-page-result {
    background: #e8f5e9 !important;
    border-color: #28a745 !important;
}

[dir="rtl"] .sdtb-current-badge {
    margin-left: 0;
    margin-right: 8px;
}

/* ============================================
   ADDITIONAL RTL IMPROVEMENTS
   ============================================ */

/* Better text alignment for RTL */
[dir="rtl"] .sdtb-page-content p,
[dir="rtl"] .sdtb-page-content div {
    text-align: right;
}

[dir="rtl"] .sdtb-page-content {
    unicode-bidi: plaintext;
}

/* RTL search box */
[dir="rtl"] .sdtb-search-input {
    text-align: right;
    direction: rtl;
}

/* RTL result items */
[dir="rtl"] .sdtb-result-snippet {
    text-align: right;
    direction: rtl;
}

/* ============================================
   SHARE & PRINT BUTTONS
   ============================================ */

.sdtb-share-print-tools {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    padding: 20px 0;
    margin-top: 15px;
    border-top: 1px solid #e0e0e0;
}

.sdtb-share-buttons {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.sdtb-share-label {
    font-weight: bold;
    color: #666;
    font-size: 0.95em;
}

.sdtb-share-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
}

.sdtb-share-btn svg {
    transition: transform 0.2s ease;
}

.sdtb-share-btn:hover svg {
    transform: scale(1.1);
}

/* WhatsApp */
.sdtb-share-whatsapp {
    background: #25D366;
    color: white;
}

.sdtb-share-whatsapp:hover {
    background: #128C7E;
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.4);
}

/* Facebook */
.sdtb-share-facebook {
    background: #1877F2;
    color: white;
}

.sdtb-share-facebook:hover {
    background: #0d65d9;
    box-shadow: 0 4px 12px rgba(24, 119, 242, 0.4);
}

/* Twitter/X */
.sdtb-share-twitter {
    background: #000000;
    color: white;
}

.sdtb-share-twitter:hover {
    background: #333333;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Copy Link */
.sdtb-share-copy {
    background: #6c757d;
    color: white;
}

.sdtb-share-copy:hover {
    background: #545b62;
    box-shadow: 0 4px 12px rgba(108, 117, 125, 0.4);
}

.sdtb-share-copy.copied {
    background: #28a745;
}

/* Print Button */
.sdtb-print-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: #17a2b8;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: bold;
    transition: all 0.3s ease;
}

.sdtb-print-btn:hover {
    background: #138496;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(23, 162, 184, 0.4);
}

.sdtb-print-btn svg {
    flex-shrink: 0;
}

/* RTL Share buttons */
[dir="rtl"] .sdtb-share-print-tools {
    flex-direction: row-reverse;
}

[dir="rtl"] .sdtb-share-buttons {
    flex-direction: row-reverse;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    /* Hide non-essential elements */
    .sdtb-book-header,
    .sdtb-search-box,
    .sdtb-navigation,
    .sdtb-page-selection-tools,
    .sdtb-share-print-tools,
    .sdtb-nav-buttons,
    .sdtb-progress,
    header,
    footer,
    nav,
    .site-header,
    .site-footer,
    .sidebar,
    #wpadminbar {
        display: none !important;
    }

    /* Reset container styles */
    .sdtb-book-container {
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .sdtb-reader {
        background: white !important;
        padding: 0 !important;
        min-height: auto !important;
    }

    .sdtb-page {
        box-shadow: none !important;
        padding: 20px !important;
        page-break-inside: avoid;
    }

    .sdtb-page-number {
        text-align: center;
        border-bottom: 1px solid #ccc;
        padding-bottom: 10px;
        margin-bottom: 20px;
    }

    .sdtb-page-content {
        font-size: 12pt !important;
        line-height: 1.6 !important;
    }

    /* Ensure proper font for RTL in print */
    [dir="rtl"] .sdtb-page-content {
        font-size: 14pt !important;
        line-height: 2 !important;
    }

    /* Print header */
    .sdtb-print-header {
        display: block !important;
        text-align: center;
        margin-bottom: 20px;
        padding-bottom: 15px;
        border-bottom: 2px solid #333;
    }

    .sdtb-print-header h1 {
        margin: 0 0 5px 0;
        font-size: 18pt;
    }

    .sdtb-print-header p {
        margin: 0;
        color: #666;
    }
}

/* Hidden print header (only shows in print) */
.sdtb-print-header {
    display: none;
}

/* ============================================
   RESPONSIVE SHARE BUTTONS
   ============================================ */

@media (max-width: 768px) {
    .sdtb-share-print-tools {
        flex-direction: column;
        align-items: stretch;
    }

    .sdtb-share-buttons {
        justify-content: center;
    }

    .sdtb-print-btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .sdtb-share-btn {
        width: 36px;
        height: 36px;
    }

    .sdtb-share-btn svg {
        width: 16px;
        height: 16px;
    }
}
