/* Comments UI Panel */
#comments-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    max-width: 100vw;
    height: 100vh;
    background-color: #F8F4EC; /* brand-cream */
    box-shadow: -5px 0 25px rgba(0,0,0,0.1);
    z-index: 10000;
    transition: right 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
    border-left: 1px solid rgba(43, 109, 109, 0.1);
}

#comments-panel.open {
    right: 0;
}

#comments-header {
    padding: 20px 24px;
    background-color: #2B6D6D; /* brand-teal */
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#comments-header h3 {
    margin: 0;
    font-family: 'Playfair Display', serif;
    font-size: 1.25rem;
    font-weight: 500;
}

#close-comments-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    padding: 4px;
}
#close-comments-btn:hover { color: white; }

#comments-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overscroll-behavior: contain;
}

.comment-item {
    background: white;
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    border-top: 3px solid #D4AF37; /* brand-gold */
    position: relative;
}

.comment-delete-btn, .comment-check-btn {
    position: absolute;
    top: 12px;
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.comment-delete-btn { right: 12px; }
.comment-check-btn { right: 44px; }

.comment-delete-btn:hover {
    color: #d9534f;
    background-color: rgba(217, 83, 79, 0.1);
}

.comment-check-btn:hover, .comment-check-btn.resolved {
    color: #2B6D6D;
    background-color: rgba(43, 109, 109, 0.1);
}

.comment-item.is-resolved {
    opacity: 0.7;
    border-top-color: #2B6D6D;
}
.comment-item.is-resolved .comment-text {
    text-decoration: line-through;
    color: #888;
}

.comment-author {
    font-weight: 700;
    font-size: 0.85rem;
    color: #2B6D6D;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.comment-date {
    font-size: 0.7rem;
    color: #666;
    margin-bottom: 8px;
}

.comment-text {
    font-size: 0.9rem;
    color: #333;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

#comments-form-container {
    padding: 20px 24px;
    background: white;
    border-top: 1px solid rgba(0,0,0,0.05);
}

#comments-form-container input,
#comments-form-container textarea {
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    background: #F8F4EC;
}

#comments-form-container button {
    width: 100%;
    padding: 12px;
    background-color: #2B6D6D;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 0.8rem;
    transition: background 0.2s;
}

#comments-form-container button:hover {
    background-color: #1a4a4a;
}

/* Floating Toggle Button */
#toggle-comments-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 30px;
    background-color: #D4AF37; /* brand-gold */
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(212, 175, 55, 0.4);
    cursor: pointer;
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

#toggle-comments-btn:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 6px 20px rgba(212, 175, 55, 0.5);
}

@media print {
    #comments-panel, #toggle-comments-btn, .comment-active-badge { display: none !important; }
}

/* Active Page Visuals */
.comment-active-page {
    position: relative;
}

.comment-active-border {
    position: absolute;
    inset: 0;
    border: 5px solid #2B6D6D;
    z-index: 9998;
    pointer-events: none;
}

.comment-active-badge {
    position: absolute;
    top: 0;
    left: 0;
    background-color: #2B6D6D;
    color: white;
    padding: 8px 16px;
    font-weight: 700;
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 14px;
    z-index: 100;
    border-bottom-right-radius: 8px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* Custom Delete Modal */
#comment-delete-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

#comment-delete-modal.open {
    opacity: 1;
    pointer-events: auto;
}

#comment-delete-modal .modal-content {
    background: white;
    padding: 24px;
    border-radius: 12px;
    width: 320px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    transform: translateY(20px);
    transition: transform 0.2s;
    font-family: 'Plus Jakarta Sans', sans-serif;
}

#comment-delete-modal.open .modal-content {
    transform: translateY(0);
}

#comment-delete-modal h4 {
    margin: 0 0 8px 0;
    color: #333;
    font-size: 1.1rem;
    font-weight: 700;
}

#comment-delete-modal p {
    margin: 0 0 20px 0;
    color: #666;
    font-size: 0.9rem;
    line-height: 1.4;
}

#comment-delete-modal .modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

#comment-delete-modal button {
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    border: none;
}

#modal-cancel-btn {
    background: #f0f0f0;
    color: #555;
}
#modal-cancel-btn:hover { background: #e0e0e0; }

#modal-confirm-btn {
    background: #d9534f;
    color: white;
}
#modal-confirm-btn:hover { background: #c9302c; }

/* Shift body left when comments open */
@media (min-width: 1024px) {
    body {
        transition: padding-right 0.3s ease-in-out;
    }
    body.comments-open {
        padding-right: 400px;
    }
    
    /* Scale down pages to prevent left-side overflow */
    body.comments-open .a4-sheet {
        zoom: 0.65;
        transition: zoom 0.3s ease-in-out;
    }
}
@media (min-width: 1300px) {
    body.comments-open .a4-sheet { zoom: 0.75; }
}
@media (min-width: 1500px) {
    body.comments-open .a4-sheet { zoom: 0.85; }
}
@media (min-width: 1700px) {
    body.comments-open .a4-sheet { zoom: 1; }
}

@media (min-width: 1024px) {
    
    /* Shift Print Button */
    .fixed.right-4, .fixed.sm\:right-6 {
        transition: right 0.3s ease-in-out !important;
    }
    body.comments-open .fixed.sm\:right-6 {
        right: calc(400px + 1.5rem) !important;
    }
    
    /* Collapse floating buttons into icons when comments open */
    body.comments-open .fixed.z-50.top-4 a,
    body.comments-open .fixed.z-50.top-4 button {
        aspect-ratio: 1 / 1;
        width: 2.75rem !important;
        height: 2.75rem !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    body.comments-open .fixed.z-50.top-4 span.hidden.sm\:inline {
        display: none !important;
        opacity: 0;
    }
    body.comments-open .fixed.z-50.top-4 svg {
        margin-right: 0 !important;
        width: 1.25rem !important; 
        height: 1.25rem !important;
        display: block !important;
    }
}

/* Ensure global floating buttons render above the border */
.fixed.z-50 {
    z-index: 9999 !important;
}
