/**
 * Froala + elFinder Integration CSS
 * Custom styles for integrating Froala Editor with elFinder file manager
 */

.editor-container {
    margin-bottom: 20px;
}

.editor-label {
    margin-bottom: 10px;
    font-weight: bold;
    color: #333;
}

/* elFinder dialog customizations */
.ui-dialog .ui-dialog-titlebar {
    background: #f0f0f0 !important;
    color: #333 !important;
}

.elfinder-toolbar {
    background: #f8f8f8 !important;
}

/* Remove search outline */
.elfinder-quicklook-navbar input {
    border: none !important;
    outline: none !important;
}

/* Remove dialog padding to make elFinder fill the entire dialog */
.ui-dialog-content {
    padding: 0 !important;
}

#elfinder-modal {
    padding: 0 !important;
    margin: 0 !important;
}

/* Enhanced modal styling for proper elFinder sizing */
.elfinder-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.elfinder-modal-content {
    background-color: #fefefe;
    margin: 2% auto;
    padding: 0;
    border: 1px solid #888;
    width: 90%;
    height: 90%;
    max-width: 1200px;
    border-radius: 5px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.elfinder-modal-header {
    padding: 15px 20px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 5px 5px 0 0;
    flex-shrink: 0;
    height: 60px;
    box-sizing: border-box;
}

.elfinder-modal-title {
    margin: 0;
    font-size: 18px;
    font-weight: 500;
    color: #333;
}

.elfinder-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.elfinder-modal-close:hover,
.elfinder-modal-close:focus {
    color: #000;
    text-decoration: none;
}

.elfinder-modal-body {
    flex: 1;
    padding: 0;
    overflow: hidden;
    height: calc(100% - 60px);
    box-sizing: border-box;
}

/* Ensure elFinder container fills the modal body properly */
#elfinder-container {
    width: 100% !important;
    height: 100% !important;
    box-sizing: border-box !important;
}

/* Fix elFinder scroll bar issues - COMPREHENSIVE LAYOUT FIX */

.elfinder {
    overflow: hidden !important;
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
}

/* Fix the main workzone layout */
.elfinder-workzone {
    flex: 1 !important;
    display: flex !important;
    overflow: hidden !important;
    height: calc(100% - 50px) !important; /* Account for toolbar height */
}

/* Fix the right panel (file area) container */
.elfinder-cwd-wrapper {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    height: 100% !important;
    flex: 1 !important;
    position: relative !important;
}

/* The file content area itself - ensure it doesn't overflow */
.elfinder-cwd {
    overflow: visible !important;
    height: auto !important;
    min-height: 100% !important;
    padding-bottom: 20px !important; /* Add bottom padding to prevent cutoff */
}

/* Specific fixes for list and icon views */
.elfinder-cwd-wrapper-list {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    height: 100% !important;
}

.elfinder-cwd-wrapper-icons {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    height: 100% !important;
}

/* Ensure content is visible and properly sized */
.elfinder-cwd-view-list,
.elfinder-cwd-view-icons {
    width: 100% !important;
    min-height: auto !important;
    padding-bottom: 20px !important; /* Prevent bottom cutoff */
}

/* Fix for dialog content padding */
.ui-dialog-content.elfinder {
    padding: 0 !important;
    height: 100% !important;
    box-sizing: border-box !important;
}

/* Fix the left panel (tree) to not interfere with right panel */
.elfinder-navbar {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    height: 100% !important;
    flex-shrink: 0 !important;
}

/* Force scrollbar to always be visible when needed */
.elfinder-cwd-wrapper::-webkit-scrollbar {
    width: 12px !important;
    background-color: #f1f1f1 !important;
}

.elfinder-cwd-wrapper::-webkit-scrollbar-thumb {
    background-color: #c1c1c1 !important;
    border-radius: 6px !important;
}

.elfinder-cwd-wrapper::-webkit-scrollbar-thumb:hover {
    background-color: #a8a8a8 !important;
}

/* Ensure dialog has proper height calculation */
.ui-dialog .elfinder {
    height: calc(100% - 10px) !important;
}


/* Fix elFinder file icons graying out during scroll */
.elfinder-cwd-file.ui-state-disabled,
.elfinder-cwd-file .ui-state-disabled,
.elfinder-cwd-file.ui-state-disabled .elfinder-cwd-icon,
.elfinder-cwd-file.ui-state-disabled .elfinder-cwd-filename,
.elfinder-cwd-file .ui-state-disabled .elfinder-cwd-icon,
.elfinder-cwd-file .ui-state-disabled .elfinder-cwd-filename {
    opacity: 1 !important;
    filter: none !important;
    -ms-filter: none !important;
}

/* Ensure file icons remain clickable and visible during scroll */
.elfinder-cwd-file {
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* Override jQuery UI disabled state for elFinder files specifically */
.elfinder .elfinder-cwd-file.ui-state-disabled,
.elfinder .elfinder-cwd-file .ui-state-disabled {
    opacity: 1 !important;
    background-image: inherit !important;
}

/* Prevent temporary disabled states from affecting file visibility */
.elfinder-cwd-view-icons .elfinder-cwd-file.ui-state-disabled,
.elfinder-cwd-view-list .elfinder-cwd-file.ui-state-disabled {
    opacity: 1 !important;
    cursor: pointer !important;
}

/* File link styling in Froala editor */
.fr-element .file-link {
    display: inline-block;
    padding: 4px 8px;
    margin: 2px;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    color: #495057;
    text-decoration: none;
    font-size: 14px;
    transition: all 0.2s ease;
}

.fr-element .file-link:hover {
    background-color: #e9ecef;
    border-color: #adb5bd;
    color: #212529;
    text-decoration: none;
}

.fr-element .file-link:active {
    background-color: #dee2e6;
    border-color: #6c757d;
}

/* ===== elFinder Info Dialog Fixes ===== */
/* Fix for "Get Info" popup dialog issues:
 * 1. Horizontal scrollbar issue with auto-width
 * 2. Close button visibility and click-outside-to-close functionality
 */

/* Fix for Info Dialog Horizontal Scrollbar Issue */
.elfinder-dialog-info {
    /* Ensure proper width calculation without horizontal scrollbar */
    min-width: 350px !important;
    max-width: 600px !important;
    width: auto !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

.elfinder-dialog-info .ui-dialog-content {
    /* Remove horizontal scrollbar from dialog content */
    overflow-x: hidden !important;
    overflow-y: auto !important;
    padding: 15px !important;
    box-sizing: border-box !important;
    word-wrap: break-word !important;
    word-break: break-all !important;
}

/* Fix for long file paths and names */
.elfinder-dialog-info .elfinder-info-tb {
    table-layout: fixed !important;
    width: 100% !important;
    border-collapse: collapse !important;
}

.elfinder-dialog-info .elfinder-info-tb td {
    word-wrap: break-word !important;
    word-break: break-all !important;
    overflow-wrap: break-word !important;
    max-width: 0 !important;
    padding: 5px 8px !important;
    vertical-align: top !important;
}

.elfinder-dialog-info .elfinder-info-tb td:first-child {
    width: 30% !important;
    font-weight: bold !important;
    white-space: nowrap !important;
    word-break: normal !important;
}

.elfinder-dialog-info .elfinder-info-tb td:last-child {
    width: 70% !important;
}

/* Fix for Close Button Visibility - Override jQuery UI icon issue */
.elfinder-dialog-info .ui-dialog-titlebar-close {
    opacity: 1 !important;
    visibility: visible !important;
    display: block !important;
    width: 20px !important;
    height: 20px !important;
    background: #f0f0f0 !important;
    border: 1px solid #ccc !important;
    border-radius: 3px !important;
}

.elfinder-dialog-info .ui-dialog-titlebar-close:hover {
    background: #e0e0e0 !important;
    border-color: #999 !important;
}

/* Override the problematic jQuery UI icon with text */
.elfinder-dialog-info .ui-dialog-titlebar-close .ui-icon {
    background-image: none !important;
    background: none !important;
    width: 100% !important;
    height: 100% !important;
    text-indent: 0 !important;
    overflow: visible !important;
}

.elfinder-dialog-info .ui-dialog-titlebar-close .ui-icon:before {
    content: "×" !important;
    font-size: 16px !important;
    font-weight: bold !important;
    color: #666 !important;
    line-height: 18px !important;
    display: block !important;
    text-align: center !important;
    width: 100% !important;
    height: 100% !important;
}

.elfinder-dialog-info .ui-dialog-titlebar-close:hover .ui-icon:before {
    color: #333 !important;
}

/* Fix for Dialog Title Bar - Remove problematic flex layout */
.elfinder-dialog-info .ui-dialog-titlebar {
    background: #f8f9fa !important;
    border-bottom: 1px solid #dee2e6 !important;
    padding: 10px 15px !important;
    /* Removed flex properties that were causing layout issues */
}

.elfinder-dialog-info .ui-dialog-title {
    font-size: 16px !important;
    font-weight: 500 !important;
    color: #333 !important;
    margin: 0 !important;
    /* Removed flex properties that were causing layout issues */
}

/* Ensure dialog has proper z-index and positioning */
.elfinder-dialog-info.ui-dialog {
    z-index: 10001 !important;
    position: fixed !important;
}

/* Fix for dialog overlay to enable click-outside-to-close */
.ui-widget-overlay.elfinder-overlay-info {
    z-index: 10000 !important;
    background: rgba(0, 0, 0, 0.3) !important;
    cursor: pointer !important;
}

/* Additional fixes for specific elFinder versions */
.elfinder .ui-dialog.elfinder-dialog-info {
    border: 1px solid #ccc !important;
    border-radius: 6px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

.elfinder .ui-dialog.elfinder-dialog-info .ui-dialog-content {
    background: #fff !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    font-size: 13px !important;
    line-height: 1.4 !important;
}

/* Fix for elFinder error dialog icon overlay issue */
.elfinder-dialog-error .ui-dialog-content,
.elfinder-dialog-confirm .ui-dialog-content,
.ui-dialog.elfinder-dialog-error .ui-dialog-content,
.ui-dialog.elfinder-dialog-confirm .ui-dialog-content {
    padding-left: 56px !important;
    min-height: 35px !important;
    position: relative !important;
}

/* Ensure error dialog icon is properly positioned */
.elfinder-dialog-error .elfinder-dialog-icon,
.elfinder-dialog-confirm .elfinder-dialog-icon,
.ui-dialog.elfinder-dialog-error .elfinder-dialog-icon,
.ui-dialog.elfinder-dialog-confirm .elfinder-dialog-icon {
    position: absolute !important;
    width: 32px !important;
    height: 32px !important;
    left: 10px !important;
    top: 50% !important;
    margin-top: -16px !important;
    z-index: 1 !important;
}

/* RTL support for error dialogs */
.elfinder-rtl .elfinder-dialog-error .ui-dialog-content,
.elfinder-rtl .elfinder-dialog-confirm .ui-dialog-content,
.elfinder-rtl .ui-dialog.elfinder-dialog-error .ui-dialog-content,
.elfinder-rtl .ui-dialog.elfinder-dialog-confirm .ui-dialog-content {
    padding-left: 0 !important;
    padding-right: 56px !important;
}

.elfinder-rtl .elfinder-dialog-error .elfinder-dialog-icon,
.elfinder-rtl .elfinder-dialog-confirm .elfinder-dialog-icon,
.elfinder-rtl .ui-dialog.elfinder-dialog-error .elfinder-dialog-icon,
.elfinder-rtl .ui-dialog.elfinder-dialog-confirm .elfinder-dialog-icon {
    left: auto !important;
    right: 10px !important;
}

/* Fix for thumbnail image in info dialog */
.elfinder-dialog-info .elfinder-info-preview {
    max-width: 100% !important;
    text-align: center !important;
    margin-bottom: 15px !important;
}

.elfinder-dialog-info .elfinder-info-preview img {
    max-width: 100% !important;
    max-height: 200px !important;
    border: 1px solid #ddd !important;
    border-radius: 4px !important;
}

/* Ensure proper spacing in info table */
.elfinder-dialog-info .elfinder-info-tb tr {
    border-bottom: 1px solid #f0f0f0 !important;
}

.elfinder-dialog-info .elfinder-info-tb tr:last-child {
    border-bottom: none !important;
}

/* Fix for UTF-8 encoding issues in elFinder info dialog */
.elfinder-dialog-info .elfinder-info-tb td {
    /* Ensure proper UTF-8 character handling */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
    font-feature-settings: "kern" 1 !important;
    text-rendering: optimizeLegibility !important;
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
}

/* Fix for path display with ellipsis encoding issues */
.elfinder-dialog-info .elfinder-info-tb td:last-child {
    /* Clean up malformed ellipsis characters */
    white-space: pre-wrap !important;
    line-height: 1.4 !important;
}

/* Remove malformed ellipsis characters using CSS content replacement */
.elfinder-dialog-info .elfinder-info-tb td:last-child::before {
    content: "" !important;
}

/* Ensure proper text overflow handling without malformed characters */
.elfinder-dialog-info .elfinder-info-tb td:last-child {
    text-overflow: ellipsis !important;
    overflow: hidden !important;
    max-width: 300px !important;
    white-space: nowrap !important;
}

/* Override for path field specifically to allow wrapping */
/* Note: Using JavaScript to add .path-field class to path rows since :contains() is not standard CSS */
.elfinder-dialog-info .elfinder-info-tb tr.path-field td:last-child,
.elfinder-dialog-info .elfinder-info-tb td[data-field="path"] {
    white-space: normal !important;
    word-break: break-all !important;
    overflow-wrap: break-word !important;
    text-overflow: clip !important;
    max-width: none !important;
}

/* Responsive adjustments for info dialog */
@media (max-width: 768px) {
    .elfinder-dialog-info {
        min-width: 300px !important;
        max-width: 95vw !important;
        margin: 10px !important;
    }

    .elfinder-dialog-info .elfinder-info-tb td:first-child {
        width: 35% !important;
        font-size: 12px !important;
    }

    .elfinder-dialog-info .elfinder-info-tb td:last-child {
        width: 65% !important;
        font-size: 12px !important;
    }
}

/* File link styling outside editor (for preview) */
.file-link {
    display: inline-block;
    padding: 4px 8px;
    margin: 2px;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    color: #495057;
    text-decoration: none;
    font-size: 14px;
    transition: all 0.2s ease;
}

.file-link:hover {
    background-color: #e9ecef;
    border-color: #adb5bd;
    color: #212529;
    text-decoration: none;
}
