/**
 * Template Management Styles
 */

/* Ensure template management section is visible when active */
#templateManagement {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    flex: 1;
}

#templateManagement.active {
    display: flex !important;
    height: 100%;
}

/* Template list container - needs scrollbar */
#template-list-container {
    width: 100%;
    height: 100%;
    overflow-y: auto !important;
    overflow-x: hidden;
    padding: 20px;
    flex: 1;
    min-height: 0; /* Important for flex containers */
}

/* Template editor container */
#template-editor-container {
    width: 100%;
    height: 100%;
    overflow-y: auto !important;
    overflow-x: hidden;
    flex: 1;
    min-height: 0; /* Important for flex containers */
}

/* Ensure scrollbars are visible in webkit browsers */
#template-list-container::-webkit-scrollbar,
#template-editor-container::-webkit-scrollbar {
    width: 8px;
}

#template-list-container::-webkit-scrollbar-track,
#template-editor-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#template-list-container::-webkit-scrollbar-thumb,
#template-editor-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

#template-list-container::-webkit-scrollbar-thumb:hover,
#template-editor-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}

#template-3d-editor-container {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1;
}

/* Remove any conflicting hidden styles */
#templateManagement .hidden {
    display: none;
}

#templateManagement > div:not(.hidden):not(#template-3d-editor-container) {
    display: block !important;
}

/* Ensure parent containers have proper height */
.dashboard-content {
    height: calc(100vh - 60px); /* Adjust based on header height */
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    height: 100%;
    min-height: 0; /* Critical for nested flex containers */
}

.content-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0; /* Critical for nested flex containers */
}

.dashboard-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    height: 100%;
    min-height: 0; /* Critical for nested flex containers */
}

.dashboard-section.hidden {
    display: none !important;
}

/* Specific fix for when 3D editor is visible */
#template-3d-editor-container:not(.hidden) {
    display: flex !important;
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
    flex: 1 !important;
}

/* Template 3D Editor Wrapper */
.template-3d-editor-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    background: #f5f5f5;
    flex: 1;
}

/* Editor Header */
.template-3d-editor-wrapper .editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #ffffff;
    border-bottom: 1px solid #ddd;
    flex-shrink: 0;
    height: 50px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.template-3d-editor-wrapper .header-left,
.template-3d-editor-wrapper .header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Editor Content Area */
.template-3d-editor-wrapper .editor-content {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
    width: 100%;
}

/* Canvas Container */
.template-3d-editor-wrapper .canvas-container {
    flex: 1;
    position: relative;
    background: #ffffff;
    overflow: hidden;
    width: 100%;
}

/* Ensure the canvas fills the container */
.template-3d-editor-wrapper .canvas-container canvas {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

/* Override any dark mode styles that might leak in */
.template-3d-editor-wrapper,
.template-3d-editor-wrapper * {
    background-color: initial;
}

.template-3d-editor-wrapper .editor-header h2 {
    color: #333;
    font-size: 18px;
    margin: 0;
}

/* Editor Toolbar */
.template-3d-editor-wrapper .editor-toolbar {
    position: absolute;
    top: 70px; /* Move below the header */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 8px;
    display: flex;
    gap: 5px;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    align-items: center;
    flex-wrap: nowrap;
    white-space: nowrap;
    max-width: 90%;
    overflow-x: auto;
    pointer-events: auto; /* Ensure toolbar is clickable */
}

/* Side Panel */
.template-3d-editor-wrapper .side-panel {
    width: 300px;
    background: #ffffff;
    border-left: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: -2px 0 4px rgba(0,0,0,0.05);
}

/* Tool Buttons */
.template-3d-editor-wrapper .tool-btn {
    width: 36px;
    height: 36px;
    border: 1px solid #ddd;
    background: #ffffff;
    color: #666;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 16px;
}

.template-3d-editor-wrapper .tool-btn:hover {
    background: #f0f0f0;
    color: #333;
    border-color: #999;
}

.template-3d-editor-wrapper .tool-btn.active {
    background: #007bff;
    color: #fff;
    border-color: #007bff;
}

/* Save Status */
.template-3d-editor-wrapper .save-status {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #666;
    font-size: 14px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 20px;
    transition: all 0.3s ease;
}

.template-3d-editor-wrapper .save-status.saved {
    color: #28a745;
    background: rgba(40, 167, 69, 0.1);
    animation: saveStatusPulse 0.5s ease;
}

.template-3d-editor-wrapper .save-status.unsaved {
    color: #ffc107;
    background: rgba(255, 193, 7, 0.1);
}

@keyframes saveStatusPulse {
    0% {
        transform: scale(1);
        background: rgba(40, 167, 69, 0.2);
    }
    50% {
        transform: scale(1.05);
        background: rgba(40, 167, 69, 0.3);
    }
    100% {
        transform: scale(1);
        background: rgba(40, 167, 69, 0.1);
    }
}

/* Property Panels */
.template-3d-editor-wrapper .property-section {
    padding: 20px;
    border-bottom: 1px solid #eee;
}

.template-3d-editor-wrapper .section-title {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Form Controls */
.template-3d-editor-wrapper .form-group {
    margin-bottom: 15px;
}

.template-3d-editor-wrapper .form-label {
    display: block;
    color: #666;
    font-size: 13px;
    margin-bottom: 5px;
}

.template-3d-editor-wrapper .form-control {
    width: 100%;
    padding: 8px 12px;
    background: #ffffff;
    border: 1px solid #ddd;
    border-radius: 4px;
    color: #333;
    font-size: 14px;
}

.template-3d-editor-wrapper .form-control:focus {
    outline: none;
    border-color: #007bff;
}

/* Toolbar Groups */
.template-3d-editor-wrapper .toolbar-group {
    display: flex;
    gap: 3px;
    padding: 0 5px;
    border-right: 1px solid #ddd;
    flex-shrink: 0;
}

.template-3d-editor-wrapper .toolbar-group:last-child {
    border-right: none;
}

/* Ensure buttons and header text are visible */
.template-3d-editor-wrapper .editor-header h2 {
    color: #333;
    font-size: 18px;
    margin: 0;
}

.template-3d-editor-wrapper .btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.template-3d-editor-wrapper .btn:hover {
    background: #0056b3;
}

.template-3d-editor-wrapper .btn.btn-secondary {
    background: #6c757d;
}

.template-3d-editor-wrapper .btn.btn-secondary:hover {
    background: #545b62;
}

/* Canvas size inputs in toolbar */
.template-3d-editor-wrapper .canvas-size-inputs {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 0 10px;
}

.template-3d-editor-wrapper .canvas-size-inputs input {
    width: 60px;
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    color: #333;
}

/* Editor footer positioning */
.template-3d-editor-wrapper .editor-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.9);
    border-top: 1px solid #ddd;
    padding: 8px 15px;
    font-size: 12px;
    color: #666;
    z-index: 10;
}

/* Ensure canvas is visible */
.template-3d-editor-wrapper canvas {
    display: block !important;
    visibility: visible !important;
}

/* Object List */
.template-3d-editor-wrapper .object-list {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.template-3d-editor-wrapper .object-item {
    padding: 10px;
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
}

.template-3d-editor-wrapper .object-item:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.template-3d-editor-wrapper .object-item.selected {
    background: #e7f3ff;
    border-color: #007bff;
}