/* When template editor is active, hide main sidebar */
body:has(.template-editor) .sidebar {
    width: 0 !important;
    overflow: hidden !important;
}

/* Adjust main content when template editor is active */
body:has(.template-editor) .main-content {
    margin-left: 0 !important;
}

/* Template editor specific layout */
.template-editor {
    height: calc(100vh - 70px);
    display: flex;
    flex-direction: column;
    background: white;
}

.template-editor .editor-header {
    flex-shrink: 0;
    z-index: 10;
}

.template-editor .editor-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* Template editor sidebar - use specific class to avoid conflicts */
.template-editor .editor-sidebar {
    width: 280px !important;
    flex-shrink: 0;
    overflow-y: auto;
    background: #f8f9fa;
    border-right: 1px solid #dee2e6;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Override any global sidebar styles for editor-sidebar */
.template-editor .editor-sidebar.collapsed {
    width: 280px !important;
    display: block !important;
    visibility: visible !important;
}

/* Hide collapse button for template editor sidebar */
.template-editor #sidebar-collapse {
    display: none !important;
}

/* Main canvas area */
.template-editor .editor-main {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: #f5f5f5;
    min-width: 0; /* Prevent flex overflow */
}

/* Properties panel */
.template-editor .editor-properties {
    width: 300px;
    flex-shrink: 0;
    overflow-y: auto;
    background: white;
    border-left: 1px solid #dee2e6;
    transition: width 0.3s ease;
}

/* Properties panel collapsed */
.template-editor .editor-properties.collapsed {
    width: 40px;
}

.template-editor .editor-properties.collapsed .properties-content {
    display: none;
}

.template-editor .editor-properties.collapsed .properties-header h4 {
    display: none;
}

/* Ensure collapse button stays visible */
.template-editor .editor-properties .properties-header {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
}

.template-editor .editor-properties.collapsed .properties-header {
    justify-content: center;
    padding: 1rem 0.5rem;
}

/* Canvas wrapper takes full space */
.template-editor .canvas-wrapper {
    flex: 1;
    overflow: auto;
    padding: 20px;
}

/* Fix canvas toolbar */
.template-editor .canvas-toolbar {
    border-bottom: 1px solid #dee2e6;
    background: white;
    padding: 10px;
}

/* Ensure template editor takes full width when main sidebar is toggled */
body .main-content:has(.template-editor) {
    margin-left: 0 !important;
    transition: none !important;
}

/* Override sidebar-collapsed class when in template editor */
body .main-content.sidebar-collapsed:has(.template-editor) {
    margin-left: 0 !important;
}

/* Make sure editor sidebar content is visible */
.template-editor .editor-sidebar .sidebar-content {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Prevent main sidebar from affecting template editor layout */
body:has(.template-editor) .main-content {
    margin-left: 0 !important;
}

/* When main sidebar is toggled while in template editor, keep layout stable */
body:has(.template-editor) .main-content.sidebar-collapsed {
    margin-left: 0 !important;
}

/* Ensure editor sidebar is not affected by main sidebar classes */
.template-editor .editor-sidebar:not(.main-sidebar) {
    position: relative !important;
    width: 280px !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    transform: none !important;
}

/* Fix z-index issues when main sidebar is visible */
body:has(.template-editor) .sidebar:not(.editor-sidebar) {
    z-index: 40;
}

.template-editor {
    z-index: 50;
    position: relative;
}

/* Fix for contract generation buttons being too small */
.contracts-tab-modern .document-actions .btn,
#contracts-tab .document-actions .btn {
    width: auto !important;
    height: auto !important;
    padding: 0.375rem 0.75rem !important;
    font-size: 0.875rem !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
}

/* Keep icon-only buttons small */
.contracts-tab-modern .document-actions .btn-icon-only,
#contracts-tab .document-actions .btn-icon-only {
    width: 32px !important;
    height: 32px !important;
    padding: 0 !important;
}

/* Ensure button text is visible */
.contracts-tab-modern .document-actions .btn i,
#contracts-tab .document-actions .btn i {
    margin-right: 0 !important;
}