@import url('variables.css');

/**
 * Document Viewer Styles
 * For BrightDocs dental document management system
 */

/* ============================================
   Modal Container
   ============================================ */

#documentViewerModal {
    display: none;
    position: fixed;
    z-index: calc(var(--z-modal) + 100);
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.7);
}

.viewer-modal-content {
    position: relative;
    background-color: var(--bg-white);
    margin: var(--space-xl) auto;
    width: 95%;
    max-width: 1400px;
    height: calc(100vh - 40px);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ============================================
   Viewer Header
   ============================================ */

.viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px var(--space-xl);
    background: var(--primary-gradient);
    color: var(--bg-white);
    border-bottom: 2px solid var(--primary-hover);
}

.viewer-title {
    flex: 1;
}

.viewer-title h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.viewer-subtitle {
    font-size: 14px;
    opacity: 0.9;
    margin-top: 3px;
}

.viewer-actions {
    display: flex;
    gap: var(--space-sm);
}

.viewer-actions button {
    padding: var(--space-sm) var(--space-lg);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 14px;
    transition: all var(--transition-fast);
    background: rgba(255, 255, 255, 0.2);
    color: var(--bg-white);
}

.viewer-actions button:hover {
    background: rgba(255, 255, 255, 0.3);
}

.close-viewer-btn {
    font-size: 28px;
    font-weight: bold;
    color: var(--bg-white);
    background: none !important;
    border: none;
    cursor: pointer;
    padding: 0 !important;
    width: 30px;
    height: 30px;
    line-height: 28px;
    text-align: center;
}

.close-viewer-btn:hover {
    color: var(--bg-secondary);
}

/* ============================================
   Metadata Banner
   ============================================ */

.viewer-metadata {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xl);
    padding: var(--space-md) var(--space-xl);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

.metadata-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.metadata-item strong {
    color: var(--text-secondary);
}

.category-badge {
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    color: var(--bg-white);
    font-size: 12px;
    font-weight: 500;
}

.metadata-ai-info {
    position: relative;
    cursor: help;
}

.info-icon {
    font-size: 16px;
    cursor: help;
}

.ai-description-hint {
    font-size: 11px;
    color: var(--secondary-color);
    font-style: italic;
}

/* ============================================
   Navigation Breadcrumb
   ============================================ */

.viewer-breadcrumb {
    padding: var(--space-sm) var(--space-xl);
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
    display: none; /* Hidden by default, shown when history exists */
}

.breadcrumb-trail {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 5px;
}

.breadcrumb-item {
    color: var(--info-color);
    cursor: pointer;
    text-decoration: none;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.breadcrumb-item:hover {
    text-decoration: underline;
}

.breadcrumb-separator {
    color: var(--secondary-color);
    margin: 0 3px;
}

.breadcrumb-current {
    color: var(--text-secondary);
    font-weight: 500;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   Viewer Body
   ============================================ */

.viewer-body {
    display: flex;
    flex-direction: row;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.viewer-content {
    flex: 1;
    overflow: auto;
    background: #e8e8e8;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.viewer-loading {
    text-align: center;
    font-size: 16px;
    color: var(--secondary-color);
    padding: 40px;
}

/* PDF Viewer */
.pdf-viewer {
    width: 100%;
    height: 100%;
    border: none;
}

/* Image Viewer */
.image-viewer {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    box-sizing: border-box;
}

.image-viewer img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Non-Viewable Document */
.non-viewable-document {
    text-align: center;
    padding: 40px;
    max-width: 600px;
    margin: 0 auto;
}

.file-icon {
    font-size: 80px;
    margin-bottom: var(--space-xl);
}

.non-viewable-document h3 {
    margin: 10px 0;
    color: var(--text-primary);
}

.file-info {
    color: var(--secondary-color);
    margin-bottom: var(--space-3xl);
}

.document-metadata {
    background: var(--bg-white);
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    margin: var(--space-xl) 0;
    text-align: left;
    box-shadow: var(--shadow-sm);
}

.metadata-row {
    padding: var(--space-sm) 0;
    border-bottom: 1px solid var(--bg-hover);
}

.metadata-row:last-child {
    border-bottom: none;
}

.extracted-text-preview {
    background: var(--bg-secondary);
    border-left: 4px solid var(--primary-color);
    padding: 15px;
    margin: var(--space-xl) 0;
    text-align: left;
    border-radius: var(--radius-sm);
}

.extracted-text-preview h4 {
    margin-top: 0;
    color: var(--text-secondary);
}

.extracted-text-preview p {
    margin-bottom: 0;
    color: var(--secondary-color);
    line-height: 1.6;
}

.download-actions {
    margin-top: var(--space-xl);
}

/* ============================================
   Right Sidebar Container
   ============================================ */

.viewer-sidebar {
    width: 300px;
    min-width: 280px;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-color);
    background: var(--bg-muted);
    overflow: hidden;
}

/* ============================================
   Notes Panel
   ============================================ */

.viewer-notes {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-bottom: 1px solid var(--border-color);
    min-height: 200px;
}

.notes-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px var(--space-md);
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.notes-header h3 {
    margin: 0;
    font-size: 0.95em;
    color: var(--text-primary);
}

.btn-add-note {
    background: var(--primary-color);
    color: var(--bg-white);
    border: none;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8em;
    transition: background var(--transition-fast);
}

.btn-add-note:hover {
    background: var(--primary-hover);
}

.notes-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
}

.no-notes {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 15px;
    font-size: 0.85em;
}

.note-item {
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    overflow: hidden;
}

.note-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-light);
}

.note-author {
    font-weight: 600;
    font-size: 0.8em;
    color: var(--text-primary);
}

.note-date {
    font-size: 0.7em;
    color: var(--text-muted);
}

.note-textarea.note-editable {
    width: 100%;
    min-height: 50px;
    padding: 8px 10px;
    border: none;
    resize: vertical;
    font-size: 0.85em;
    font-family: inherit;
    box-sizing: border-box;
    background: var(--bg-white);
}

.note-textarea.note-editable:focus {
    outline: none;
    background: #fffef0;
}

.note-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 10px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-light);
}

.btn-delete-note {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.9em;
    padding: 2px 6px;
    border-radius: 3px;
    opacity: 0.5;
    transition: opacity var(--transition-fast);
}

.btn-delete-note:hover {
    opacity: 1;
    background: var(--error-light);
}

.new-note-container {
    padding: 10px;
    background: var(--info-light);
    border-bottom: 1px solid #cce0ff;
    flex-shrink: 0;
}

.new-note-container .note-textarea {
    width: 100%;
    min-height: 60px;
    padding: var(--space-sm);
    border: 1px solid #cce0ff;
    border-radius: var(--radius-sm);
    resize: vertical;
    font-size: 0.85em;
    font-family: inherit;
    box-sizing: border-box;
}

.new-note-container .note-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.new-note-container .note-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--space-sm);
}

.btn-cancel-note {
    background: var(--secondary-color);
    color: var(--bg-white);
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75em;
}

.save-status {
    font-size: 0.7em;
    padding: 2px 5px;
    border-radius: 3px;
}

.save-status.typing {
    color: var(--text-secondary);
}

.save-status.saving {
    color: var(--primary-color);
}

.save-status.saved {
    color: var(--active-green);
}

.save-status.error {
    color: var(--danger-color);
}

/* ============================================
   Related Documents Panel
   ============================================ */

.viewer-related {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 150px;
    border-top: 2px solid var(--border-color);
    background: var(--bg-white);
    max-height: 250px;
}

.related-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px var(--space-md);
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.related-header h3 {
    margin: 0;
    font-size: 0.95em;
    color: var(--text-primary);
}

.category-filter {
    padding: 6px var(--space-md);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-md);
    font-size: 13px;
    background: var(--bg-white);
}

.related-docs-list {
    padding: 10px var(--space-xl);
}

#relatedDocuments {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
}

.category-group {
    margin-bottom: var(--space-xl);
}

.category-header {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0 0 var(--space-sm) 0;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--bg-hover);
}

.related-doc-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: var(--space-sm) 10px;
    margin: var(--space-xs) 0;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.related-doc-item:hover {
    background: var(--bg-secondary);
}

.doc-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.doc-info {
    flex: 1;
    min-width: 0;
}

.doc-name,
.related-doc-item .doc-name {
    font-size: 0.85em;
    color: var(--text-primary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-date {
    font-size: 11px;
    color: var(--secondary-color);
}

.related-doc-item .doc-type {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.related-doc-item .doc-brief {
    font-size: 0.75em;
    color: var(--text-secondary);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 3px;
}

.no-related {
    text-align: center;
    padding: var(--space-3xl);
    color: var(--secondary-color);
    font-style: italic;
}

/* ============================================
   Confirmation Modals
   ============================================ */

#deleteConfirmModal,
#reassignPatientModal {
    display: none;
    position: fixed;
    z-index: 1100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
}

.confirm-modal-content {
    background-color: var(--bg-white);
    margin: 15% auto;
    padding: 0;
    border: none;
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
}

.confirm-modal-header {
    padding: 15px var(--space-xl);
    background: var(--danger-color);
    color: var(--bg-white);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.confirm-modal-header h3 {
    margin: 0;
    font-size: 18px;
}

.confirm-modal-body {
    padding: var(--space-xl);
}

.confirm-doc-name {
    font-weight: 600;
    color: var(--text-primary);
    margin: 10px 0;
}

.form-group {
    margin: 15px 0;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-input);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: inherit;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.required {
    color: var(--danger-color);
}

.confirm-modal-footer {
    padding: 15px var(--space-xl);
    background: var(--bg-secondary);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ============================================
   Buttons
   ============================================ */

.btn-primary {
    background: var(--primary-color);
    color: var(--bg-white);
    padding: 10px var(--space-xl);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background var(--transition-fast);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary-color);
    color: var(--bg-white);
    padding: 10px var(--space-xl);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background var(--transition-fast);
}

.btn-secondary:hover {
    background: var(--secondary-hover);
}

.btn-danger {
    background: var(--danger-color);
    color: var(--bg-white);
    padding: 10px var(--space-xl);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background var(--transition-fast);
}

.btn-danger:hover {
    background: #c82333;
}

/* ============================================
   Error States
   ============================================ */

.error-message {
    color: var(--danger-color);
    text-align: center;
    padding: var(--space-xl);
    font-style: italic;
}

/* ============================================
   Scrollbar Styling
   ============================================ */

.viewer-related::-webkit-scrollbar,
.viewer-content::-webkit-scrollbar,
.notes-list::-webkit-scrollbar,
#relatedDocuments::-webkit-scrollbar {
    width: 8px;
}

.viewer-related::-webkit-scrollbar-track,
.viewer-content::-webkit-scrollbar-track,
.notes-list::-webkit-scrollbar-track,
#relatedDocuments::-webkit-scrollbar-track {
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
}

.viewer-related::-webkit-scrollbar-thumb,
.viewer-content::-webkit-scrollbar-thumb,
.notes-list::-webkit-scrollbar-thumb,
#relatedDocuments::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: var(--radius-sm);
}

.viewer-related::-webkit-scrollbar-thumb:hover,
.viewer-content::-webkit-scrollbar-thumb:hover,
.notes-list::-webkit-scrollbar-thumb:hover,
#relatedDocuments::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 1000px) {
    .viewer-sidebar {
        width: 260px;
        min-width: 240px;
    }
}

@media (max-width: 800px) {
    .viewer-body {
        flex-direction: column;
    }

    .viewer-sidebar {
        width: 100%;
        max-width: none;
        max-height: 300px;
        border-left: none;
        border-top: 1px solid var(--border-color);
        flex-direction: row;
    }

    .viewer-notes,
    .viewer-related {
        flex: 1;
        min-height: auto;
        border-bottom: none;
    }

    .viewer-notes {
        border-right: 1px solid var(--border-color);
    }
}

@media (max-width: 768px) {
    .viewer-modal-content {
        width: 100%;
        height: 100vh;
        margin: 0;
        border-radius: 0;
    }

    .viewer-header {
        flex-wrap: wrap;
    }

    .viewer-actions {
        width: 100%;
        margin-top: 10px;
        justify-content: space-between;
    }

    .viewer-metadata {
        flex-direction: column;
        gap: var(--space-sm);
    }

    .viewer-related {
        max-height: 200px;
    }

    .confirm-modal-content {
        width: 95%;
        margin: 10% auto;
    }
}

/* ============================================
   Email Page Document Viewer Overrides
   (email.html uses different class names)
   ============================================ */

.document-viewer-modal-content {
    position: relative;
    background-color: var(--bg-white);
    margin: 20px auto;
    width: 95%;
    max-width: 1400px;
    height: calc(100vh - 40px);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.document-viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 24px;
    background: var(--primary-gradient);
    color: white;
    border-bottom: 2px solid var(--primary-hover);
    flex-shrink: 0;
}

.document-viewer-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.document-viewer-header .close-btn {
    font-size: 28px;
    font-weight: bold;
    color: white;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    line-height: 28px;
    text-align: center;
}

.document-viewer-header .close-btn:hover {
    color: #e0e0e0;
}

.document-viewer-body {
    display: flex;
    flex-direction: row;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.viewer-main-content {
    flex: 1;
    overflow: auto;
    background: #e8e8e8;
    min-width: 0;
    min-height: 400px;
    display: flex;
    align-items: stretch;
    justify-content: center;
}

.viewer-main-content iframe,
.viewer-main-content .pdf-viewer {
    width: 100%;
    height: 100%;
    min-height: 500px;
    border: none;
}

.viewer-metadata-banner {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
    flex-shrink: 0;
}


/* Responsive adjustments for document viewer on email page */
@media (max-width: 768px) {
    .document-viewer-modal-content {
        width: 100%;
        height: 100vh;
        margin: 0;
        border-radius: 0;
    }

    .document-viewer-body {
        flex-direction: column;
    }

    .viewer-main-content {
        min-height: 300px;
    }
}


/* metadata editing
*/


.metadata-editable {
    cursor: pointer;
    position: relative;
    padding-right: 50px;
}

.metadata-editable:hover {
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

.metadata-edit-icon {
    opacity: 0;
    transition: opacity 0.2s;
    font-size: 12px;
    margin-left: 4px;
}

.metadata-editable:hover .metadata-edit-icon {
    opacity: 0.6;
}

.metadata-input {
    padding: 4px 8px;
    border: 1px solid #3498db;
    border-radius: 4px;
    font-size: 14px;
    min-width: 150px;
}

.metadata-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.3);
}

.metadata-select {
    min-width: 200px;
}

.metadata-date-input {
    min-width: 140px;
}

.metadata-save-status {
    font-size: 12px;
    margin-left: 8px;
}

.metadata-save-status.saving {
    color: #f39c12;
}

.metadata-save-status.saved {
    color: #27ae60;
}

.metadata-save-status.error {
    color: #e74c3c;
}

/* Add Insurer Modal */
.add-insurer-modal-content {
    max-width: 450px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
    color: #333;
}

.form-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.form-input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.form-error {
    color: #e74c3c;
    font-size: 13px;
    margin-top: 8px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 16px;
    border-top: 1px solid #eee;
}

.metadata-patient-input {
    min-width: 250px;
}