/* Auth Overlay - Now has a close button */
#auth-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.8); display: none; justify-content: center; align-items: center; z-index: 1000; }
.auth-box { background: white; padding: 2.5rem; border-radius: 8px; width: 300px; box-shadow: 0 4px 15px rgba(0,0,0,0.2); position: relative; }
.close-auth { position: absolute; top: 10px; right: 15px; cursor: pointer; font-size: 1.5rem; color: var(--text-muted); }
.close-auth:hover { color: var(--text-color); }
.auth-box h2 { margin-top: 0; text-align: center; }
.auth-toggle { text-align: center; margin-top: 15px; font-size: 0.9rem; color: var(--color-1); cursor: pointer; }
.auth-toggle:hover { text-decoration: underline; }

.toolbar { display: flex; justify-content: space-between; align-items: center; padding: 1rem 2rem; background: var(--bg-color); border-bottom: 1px solid var(--border); box-shadow: 0 1px 3px rgba(0,0,0,0.05); z-index: 10; }
.header-title { display: flex; flex-direction: column; }
.header-title h2 { margin: 0; }
.header-title small { color: var(--text-muted); font-size: 0.9rem; }
.header-right { display: flex; align-items: center; gap: 20px; }
.user-greeting { font-weight: bold; color: var(--color-1); }
.logout-btn { background: none; border: 1px solid var(--border); padding: 6px 12px; border-radius: 4px; cursor: pointer; }

.lang-toggle { display: flex; gap: 10px; }
.lang-btn { padding: 8px 16px; border: 1px solid var(--border); background: white; border-radius: 6px; cursor: pointer; font-weight: 500; transition: all 0.2s; }
.lang-btn.active { background: var(--color-1); color: white; border-color: var(--color-1); }

/* 1. Container: Full width, small margins, allowed to float */
.container { 
    display: flex; 
    gap: 0.5rem; /* Small gap between text and comments */
    padding: 0.5rem; /* Very small margins on the far left and right edges */
    max-width: 100%; /* REMOVED the 1400px limit so it fills the screen */
    margin: 0; 
    align-items: flex-start; /* Required for sticky to work */
    box-sizing: border-box;
}

/* 2. Text Pane: Takes up 2/3 of the screen */
.text-pane { 
    flex: 1.5; /* 2 units of width */
    background: var(--bg-color); 
    padding: 1rem; 
    border-radius: 0px; 
    
     
    box-sizing: border-box; /* Keeps padding from breaking the width */
}

/* 3. Comment Pane: Takes up 1/3 of the screen, sticks to top, doesn't cut off */
.comment-pane { 
    flex: 1; /* 1 unit of width (Text is 2, Comment is 1 = 2/3 & 1/3 split) */
    background: var(--card-bg); 
    padding: 1rem; 
    border-radius: 8px; 
    border: 1px solid var(--border); 
    box-shadow: 0 10px 25px var(--box-shadow); 
    
    /* CRITICAL: Forces padding to be calculated INSIDE the max-height */
    box-sizing: border-box; 

    /* STICKY SIDEBAR FIXES */
    position: sticky;
    top: 10px; /* Sticks almost completely flush to the top of the monitor */
    
    /* Safely fits within the screen without cutting off the bottom */
    max-height: calc(100vh - 20px); 
    overflow-y: auto; 
}

.verse-line { display: flex; padding: 1rem; border-radius: 8px; cursor: pointer; transition: background 0.2s; border: 1px solid transparent; margin-bottom: 8px; text-decoration: none; color: inherit;}
.verse-line:hover { background: var(--bg-color); }
.verse-line.active { background: var(--verse-line-active-background); border-color: var(--verse-line-active-border); }
.verse-num { flex: 0 0 50px; font-weight: bold; color: var(--text-muted); font-size: 0.9rem; }
.verse-content { flex: 1; display: flex; flex-direction: column; gap: 8px; font-size: 1.1rem; line-height: 1.6; }
.hebrew-text { direction: rtl; font-family: "Times New Roman", serif; font-size: 1.4rem; }
.comment-count { flex: 0 0 40px; text-align: right; color: var(--color-1); font-weight: bold; }
.comment-count sup { background: var(--bg-color); padding: 3px 6px; border-radius: 12px; border: 1px solid var(--border); font-size: 0.8rem; }

.panel-header { 
    display: flex; 
    flex-direction: column;
    align-items: stretch; 
    margin-bottom: 1.5rem; 
    border-bottom: 1px solid var(--border); 
    
    position: sticky;
    top: -1.5rem; 
    margin-top: -1.5rem; 
    padding-top: 1.5rem; 
    padding-bottom: 1rem;
    
    background-color: var(--card-bg, #ffffff); 
    z-index: 100;
}

.header-left { 
    display: flex; 
    flex-direction: column; 
    align-items: flex-start; 
    gap: 10px;
    width: 100%;
}

.header-left-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
}

.back-btn { background: none; border: none; color: var(--color-1); cursor: pointer; font-size: 1rem; font-weight: 600; display: none; margin-right: 15px; }
.back-btn:hover { text-decoration: underline; }
.add-comment-btn, .submit-btn { 
    background: var(--color-1); 
    color: white; 
    border: none; 
    padding: 8px 16px; 
    border-radius: 6px; 
    cursor: pointer; 
    font-weight: bold; 
    transition: 0.2s; 
    white-space: nowrap;
    width: auto;
    flex: 0 0 auto;
}
.add-comment-btn:hover, .submit-btn:hover { background: var(--color-1-hover); }

.comment-card { background: var(--text-pane); padding: 1rem; border-radius: 8px; border: 1px solid var(--border); margin-bottom: 1rem; cursor: pointer; transition: box-shadow 0.2s; display: flex; gap: 15px;}
.thread-item { display: flex; gap: 15px; margin-top: 1rem; background: var(--text-pane); padding: 1rem; border-radius: 8px; border: 1px solid var(--border); }
.thread-replies { margin-left: 1rem; border-left: 2px solid var(--border); padding-left: 1rem; }
.vote-col { display: flex; flex-direction: column; align-items: center; gap: 5px; color: var(--text-muted); }
.vote-btn { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 1.2rem; padding: 0 5px; }
.vote-btn:hover { color: var(--color-1); }

.comment-content { flex: 1; }
.comment-author { font-size: 0.85rem; font-weight: bold; color: var(--color-1); margin-bottom: 5px; cursor: pointer; display: inline-block; text-decoration: none;}
.comment-author:hover { text-decoration: underline; }
.comment-content h4 { margin: 0 0 5px 0; color: var(--text-color); }
.comment-content p { margin: 0 0 10px 0; color: var(--text-color); font-size: 0.95rem; line-height: 1.5; }
.reply-btn { background: none; border: none; color: var(--color-1); cursor: pointer; font-size: 0.85rem; font-weight: 600; padding: 0; }
.reply-btn:hover { text-decoration: underline; }
.empty-state { text-align: center; color: var(--text-muted); margin-top: 3rem; font-style: italic; }

.reply-form { background: var(--card-bg); padding: 0.6rem; border-radius: 8px; border: 1px solid var(--border); margin-bottom: 1.5rem; box-shadow: 0 2px 8px rgba(0,0,0,0.05); color: var(--text-color)}
.reply-form.nested { background: var(--bg-color); margin-top: 15px; margin-bottom: 0; border: 1px dashed var(--border); box-shadow: none; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 5px; font-weight: bold; font-size: 0.9rem; }
.form-group input, .form-group textarea { font-size: 1rem; color: var(--text-color); width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 4px; box-sizing: border-box; font-family: inherit; background-color: var(--bg-color); }
.form-group textarea { resize: vertical; min-height: 80px;  }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 1rem; }
.cancel-btn { background: white; border: 1px solid var(--border); padding: 8px 16px; border-radius: 6px; cursor: pointer; font-weight: 500; }
.cancel-btn:hover { background: var(--hover-color); }

.save-btn {
    background: transparent;
    color: var(--color-1);
    border: 2px solid var(--color-1);
    padding: 6px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.9rem;
    margin-right: 15px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.header-right button {
    height: 36px;
    padding: 0 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    white-space: nowrap;

}

.save-btn:hover {
    background: var(--color-1);
    color: white;
}

.comment-pane.fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    
    width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important; /* Overrides the calc(100vh - 20px) limit */
    
    margin: 0 !important;
    border-radius: 0 !important; /* Removes rounded corners so it sits flush */
    border: none !important; /* Removes the outer border */
    
    z-index: 1100 !important; /* Ensures it pops completely over your global header */
    box-sizing: border-box !important;
}


/* Dynamic Language Buttons */
.lang-toggle { display: flex; gap: 10px; }
.lang-btn { padding: 5px 15px; border: 1px solid var(--border); background: var(--card-bg); border-radius: 4px; cursor: pointer; color: var(--text-muted); transition: 0.2s; font-weight: 500; }
.lang-btn.active { background: var(--color-1); color: white; border-color: var(--color-1); }
.verse-lang { display: none; margin-bottom: 5px; } /* Hidden by default, JS toggles them */

/* Hierarchical Library Styles */
.corpus-group { margin-bottom: 2.5rem; margin-left: 10%; margin-right: 10%; }

/* UPDATED: Added cursor, hover effects, and flexbox to align the arrow */
.corpus-title { color: var(--color-1); border-bottom: 2px solid var(--border); padding-bottom: 8px; margin-bottom: 1.5rem; font-size: 1.8rem; display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; transition: opacity 0.2s;}
.corpus-title:hover { opacity: 0.8; }

.book-group { margin-bottom: 1.5rem; margin-left: 1rem; background: var(--card-bg); padding: 1.5rem; border: 1px solid #e2e8f0; border-radius: 8px; box-shadow: 0 2px 5px var(--box-shadow); }

/* UPDATED: Added cursor and user-select limits */
.book-title { margin: 0 0 10px 0; color: var(--text-muted); font-size: 1.3rem; display: flex; align-items: baseline; gap: 10px; cursor: pointer; user-select: none; transition: opacity 0.2s; }
.book-title:hover { opacity: 0.8; }
.book-author { font-size: 0.9rem; color: var(--color-2); font-weight: normal; }

/* NEW: Logic for the toggle arrows and hiding content */
.toggle-icon { display: inline-block; font-size: 0.7em; transition: transform 0.2s ease; }
.collapsed .toggle-icon { transform: rotate(-90deg); } /* Rotates arrow to point right */
.collapsed-content { display: none !important; }

.chapter-list { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 15px; }
.chapter-link { background: var(--bg-color); border: 1px solid var(--border); padding: 8px 15px; border-radius: 6px; text-decoration: none; color: var(--text-color); font-size: 0.95rem; transition: all 0.2s; }
.chapter-link:hover { background: var(--hover-color); border-color: #90cdf4; color: var(--hover-text); transform: translateY(-1px); }

/* General styling for all custom select dropdowns */
select#new-comment-tag,
select#tag-filter-select,
select#sort-dropdown,
select#mobile-sort-dropdown {
    
    background-color: var(--card-bg, #ffffff);
    color: var(--text-color, #333333);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 6px;
    padding: 8px 32px 8px 12px; /* Extra padding on the right for the arrow */
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;

    width: auto;
    flex: 0 0 auto;
    
}


/* Hover and Focus interaction states */
select#new-comment-tag:hover,
select#tag-filter-select:hover,
select#sort-dropdown:hover,
select#mobile-sort-dropdown:hover {
    border-color: #a0aec0;
}

select#new-comment-tag:focus,
select#tag-filter-select:focus,
select#sort-dropdown:focus,
select#mobile-sort-dropdown:focus {
    border-color: var(--primary, #2b6cb0);
    box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.2);
}

/* Specific sizing for the post comment form dropdown */
select#new-comment-tag {
    margin-bottom: 15px;
    padding-top: 10px;
    padding-bottom: 10px;
    font-size: 1rem;
}

.header-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

/* =========================================
   COMMENT TAG BADGES
   ========================================= */

/* Base styling for the little ellipse */
.comment-tag-badge {
    font-size: 0.65rem;
    padding: 3px 10px;
    border-radius: 20px;
    background-color: var(--card-bg, #ffffff);
    border: 1px solid var(--border, #e2e8f0);
    color: var(--text-muted, #718096);
    margin-left: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
}

/* Dynamic Colors based on the tag! */
.tag-historical-cultural {
    background-color: #fff5f5;
    color: #c53030;
    border-color: #fed7d7;
}

.tag-theological {
    background-color: #ebf4ff;
    color: #2b6cb0;
    border-color: #bee3f8;
}

.tag-literary {
    background-color: #f0fff4;
    color: #2f855a;
    border-color: #c6f6d5;
}

.tag-practical-devotional {
    background-color: #faf5ff;
    color: #6b46c1;
    border-color: #e9d8fd;
}

.tag-legal-ethical {
    background-color: #fffff0; /* soft yellow */
    color: #b7791f;
    border-color: #fef08a;
}

.tag-mystical-allegorical {
    background-color: #fdf2f8; /* soft pink/purple */
    color: #9d174d;
    border-color: #fbcfe8;
}

.tag-linguistic {
    background-color: #fcf6a6; /* soft pink/purple */
    color: #53520a;
    border-color: #ca7944;
}

/* ========================================= */
/* --- FULL-WIDTH COMMENT OVERRIDES --- */
/* ========================================= */

/* 1. Force the main wrapper to stretch its children */
#comment-content {
    width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important; /* This strictly prevents shrink-wrapping! */
}

/* 2. Force every card to accept the 100% width */
.comment-card, 
.thread-item {
    width: 100% !important;
    min-width: 100% !important;
    box-sizing: border-box !important;
}

/* 3. Ensure the text section inside the card pushes the Report button all the way to the right */
.comment-content {
    flex: 1 1 auto !important;
    min-width: 0 !important; /* Fixes text-width calculation issues */
    width: 100% !important;
}

/* 4. Ensure threaded replies under the main comment also stretch */
.thread-replies {
    width: calc(100% - 1rem) !important;
    box-sizing: border-box !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
}



/* ========================================= */
/* --- MOBILE RESPONSIVE LAYOUT --- */
/* ========================================= */

/* Hide mobile close button on desktop */
.mobile-close-btn {
    display: none;
    background: none;
    border: none;
    font-size: 2.2rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 10px;
    margin-right: 5px;
}

#close-panel-btn {
    display: none;
}

/* Hide mobile panel on desktop */
.mobile-comment-pane {
    display: none; 
}

.mobile-discuss-prompt {
    display: none;
}


/* Library Hub Styles */
.library-hub-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 20px;
}

.library-hero {
    text-align: center;
    margin-bottom: 3rem;
}

.library-hero h1 {
    font-family: serif;
    font-size: 2.5rem;
    color: var(--color-1);
    margin-bottom: 10px;
}

.library-hero p {
    color: var(--text-muted);
    font-size: 1.1rem;
    max-width: 600px;
    margin: 0 auto;
}

.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
}

.library-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 30px 20px;
    text-align: center;
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.library-card:hover {
    transform: translateY(-5px);
    border-color: var(--color-2); /* Uses your gold accent color */
    box-shadow: 0 8px 15px var(--box-shadow);
    background: var(--hover-color);
}

.library-icon {
    font-size: 3rem;
    margin-bottom: 10px;
}

.library-title {
    font-size: 1.5rem;
    font-weight: bold;
    font-family: serif;
    margin: 0;
}

.library-desc {
    font-size: 0.95rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin: 0;
}



@media (max-width: 768px) {
    
    /* Hide the desktop panel completely on mobile */
    .comment-pane {
        display: none !important;
    }

    /* --- TRUE FULLSCREEN MOBILE MODAL --- */
    .mobile-comment-pane {
        display: flex; 
        position: fixed !important;
        
        /* THE FIX: Pin to all four edges simultaneously to ignore viewport bugs */
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        height: auto !important; /* Let top and bottom dictate the size */
        
        margin: 0 !important;
        border-radius: 0 !important; 
        
        background: var(--card-bg); 
        z-index: 1100 !important; 
        
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        flex-direction: column;
        transition: opacity 0.2s ease-in-out, visibility 0.2s !important;
    }

    .mobile-comment-pane.mobile-open {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    /* Isolated Internal Scrolling */
    #mobile-scroll-wrapper {
        flex: 1 1 auto !important; /* Flex magic: Tells it to perfectly fill exactly whatever space is left below the header! */
        overflow-y: auto !important; 
        -webkit-overflow-scrolling: touch !important; 
        overscroll-behavior: none !important; 
        width: 100%;
    }

    #mobile-comment-content {
        flex: none !important; /* Stops the browser from artificially squashing the comments */
        height: auto !important;
        overflow: visible !important; /* Turns off internal scrolling so it relies on the wrapper */
        
        /* The padding below is Top: 15px, Right: 15px, Bottom: 30px, Left: 15px. 
           30px gives just a tiny bit of breathing room at the bottom without creating a giant grey void! */
        padding: 15px 15px 30px 15px !important; 
    }

    .text-pane { 
        padding: 0.6rem 0.4rem; 
    }

    .container {
        padding: 0.25rem !important;
        gap: 0 !important;
    }

    .verse-line {
        padding: 0.75rem 0.4rem !important;
        gap: 8px !important;
    }

    .verse-num {
        flex: 0 0 28px !important;
        font-size: 0.8rem !important;
    }

    .comment-count {
        flex: 0 0 28px !important;
        font-size: 0.85rem !important;
    }

    .toolbar {
        /* Stack the title and the buttons on two separate lines */
        flex-direction: column !important;
        align-items: flex-start !important;
        padding: 12px 15px !important;
        gap: 12px !important;
    }

    .header-title {
        /* Force the title and author onto the same line */
        display: flex !important;
        flex-direction: row !important;
        align-items: baseline !important;
        gap: 8px;
    }

    /* Shrink the document name */
    .header-title #display-title {
        font-size: 1.25rem !important;
        margin: 0;
    }

    /* Shrink the author text */
    .header-title #display-author {
        font-size: 0.9rem !important;
    }

    .header-right {
        /* Allow the buttons to stretch across the second line */
        width: 100%;
        flex-wrap: wrap !important;
        justify-content: flex-start;
        gap: 8px !important;
    }

    .mobile-discuss-prompt {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        bottom: 30px; /* Distance from the bottom of the screen */
        left: 50%;
        transform: translateX(-50%); /* Perfectly centers it */
        
        background-color: var(--primary, #007bff);
        color: #ffffff;
        padding: 12px 28px;
        border-radius: 50px; /* Makes it a pill/oval shape */
        font-weight: bold;
        font-size: 0.95rem;
        box-shadow: 0 4px 15px rgba(0,0,0,0.3);
        z-index: 8000;
        
        /* MAGIC TRICK: This allows the user to click right through the oval 
            so it never blocks them from selecting the text behind it! */
        pointer-events: none; 
    }

    /* Stack the X above the controls row on mobile */
    /* Stack the X above the controls row on mobile */
    #mobile-panel-header {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        justify-content: flex-start !important; 
        padding: 12px 15px !important;
        border-bottom: 1px solid rgba(128, 128, 128, 0.2) !important;
        text-align: left !important;
        gap: 8px !important;
        position: relative !important; /* Anchors the back button to this header */
    }

    #mobile-back-btn {
        position: absolute !important;
        top: 12px !important;
        left: 15px !important;
        margin: 0 !important;
        z-index: 1 !important;
        height: 1.8rem !important;
        line-height: 1.8rem !important;
        font-size: 1rem !important;
        align-items: center !important;
        padding: 0 !important;
    }

    #mobile-back-btn[style*="display: block"] {
        display: flex !important;
    }

    #mobile-close-btn {
        position: static !important;
        order: -1 !important; /* Puts the X on its own line, above the controls */
        align-self: flex-end !important; /* Keeps it tucked to the top-right */
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        margin: 0 !important;
        padding: 0 !important;
        height: 1.8rem !important;
        line-height: 1.8rem !important;
        font-size: 1.8rem !important; 
        background: transparent !important;
        border: none !important;
        color: inherit !important;
        cursor: pointer !important;
        transform: none !important; 
    }

    #mobile-panel-header > div,
    #mobile-panel-title {
        margin: 0 !important;
        font-size: 1.1rem !important;
        line-height: 1 !important;
    }

    /* Library page CSS */


    .corpus-group {
        margin-right: 0%;
        margin-left: 0%;
    }

    .book-group {
        margin-left: 0.5rem;
        padding: 1rem;
    }

    .reply-form {
        border: none !important;
    }

    select#new-comment-tag {
        width: auto !important;
    }

    #auth-overlay,
    #delete-modal,
    #report-modal {
        z-index: 99999 !important;
    }

    /* --- MOBILE HEADER: FORCE SINGLE LINE --- */

    /* 1. Target the left-side group to prevent wrapping and allow it to shrink */
    #mobile-panel-header > div > div {
        flex-wrap: nowrap !important;
        gap: 6px !important; /* Slightly tighter gap to save space */
        min-width: 0 !important; /* Crucial: allows the container itself to shrink */
    }

    /* 2. Target the inner wrapper holding the two dropdowns */
    #mobile-panel-header > div > div > div {
        flex-shrink: 1 !important;
        min-width: 0 !important;
        gap: 4px !important;
    }

    /* 3. Allow dropdowns and buttons to dynamically shrink and cut off text if needed */
    #mobile-tag-dropdown,
    #mobile-sort-dropdown,
    #mobile-add-comment-btn,
    #mobile-back-btn {
        flex-shrink: 1 !important;
        min-width: 0 !important; 
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important; /* Adds "..." if text gets cut off */
        padding-left: 6px !important;
        padding-right: 6px !important;
    }
}
