/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    overflow-x: hidden;
}

/* Container */
.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.header-buttons {
    display: flex;
    gap: 0.5rem;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.btn-primary {
    background-color: #007bff;
    color: white;
}

.btn-primary:hover {
    background-color: #0056b3;
}

.btn-success {
    background-color: #28a745;
    color: white;
}

.btn-success:hover {
    background-color: #1e7e34;
}

.btn-info {
    background-color: #17a2b8;
    color: white;
}

.btn-info:hover {
    background-color: #117a8b;
}

.btn-danger {
    background-color: #dc3545;
    color: white;
}

.btn-danger:hover {
    background-color: #c82333;
}

.btn-outline {
    background-color: transparent;
    color: #666;
    border: 1px solid #ddd;
}

.btn-outline:hover {
    background-color: #f8f9fa;
    border-color: #adb5bd;
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: white;
    border-right: 1px solid #e9ecef;
    padding: 1.5rem;
    overflow-y: auto;
    box-shadow: 2px 0 10px rgba(0,0,0,0.05);
}

.sidebar h3 {
    margin-bottom: 1rem;
    color: #495057;
    font-size: 1.1rem;
    font-weight: 600;
}

.elements-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.element-category h4 {
    margin-bottom: 0.75rem;
    color: #6c757d;
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.element-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    cursor: grab;
    transition: all 0.2s ease;
    margin-bottom: 0.5rem;
    user-select: none;
}

.element-item:hover {
    background-color: #e9ecef;
    border-color: #007bff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,123,255,0.15);
}

.element-item:active {
    cursor: grabbing;
    transform: scale(0.95);
}

.element-item svg {
    flex-shrink: 0;
}

/* Canvas Area */
.canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #fafafa;
}

.canvas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background-color: white;
    border-bottom: 1px solid #e9ecef;
}

.canvas-header h3 {
    color: #495057;
    font-size: 1.1rem;
    font-weight: 600;
}

.canvas-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.canvas-controls select {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: white;
    cursor: pointer;
}

.design-canvas {
    flex: 1;
    margin: 1.5rem;
    background-color: white;
    border: 2px dashed #dee2e6;
    border-radius: 12px;
    position: relative;
    overflow: auto;
    min-height: 500px;
    transition: all 0.3s ease;
}

.design-canvas.drag-over {
    border-color: #007bff;
    background-color: #f8f9ff;
    border-style: solid;
}

.canvas-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #6c757d;
    font-size: 1.1rem;
    pointer-events: none;
}

/* Properties Panel */
.properties-panel {
    width: 300px;
    background-color: white;
    border-left: 1px solid #e9ecef;
    padding: 1.5rem;
    overflow-y: auto;
    box-shadow: -2px 0 10px rgba(0,0,0,0.05);
}

.properties-panel h3 {
    margin-bottom: 1rem;
    color: #495057;
    font-size: 1.1rem;
    font-weight: 600;
}

.properties-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.no-selection {
    color: #6c757d;
    font-style: italic;
    text-align: center;
    margin-top: 2rem;
}

.property-group {
    margin-bottom: 1.5rem;
}

.property-group h4 {
    margin-bottom: 0.75rem;
    color: #495057;
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.property-item {
    margin-bottom: 1rem;
}

.property-item label {
    display: block;
    margin-bottom: 0.25rem;
    color: #495057;
    font-size: 0.875rem;
    font-weight: 500;
}

.property-item input,
.property-item select,
.property-item textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.875rem;
    transition: border-color 0.2s ease;
}

.property-item input:focus,
.property-item select:focus,
.property-item textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
}

/* Dropped Elements */
.dropped-element {
    position: absolute;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: move;
    transition: all 0.2s ease;
    min-width: 80px;
    min-height: 30px;
}

.dropped-element:hover {
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
}

.dropped-element.selected {
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
}

.dropped-element .resize-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: #007bff;
    border: 1px solid white;
    border-radius: 50%;
    cursor: nw-resize;
}

.dropped-element .resize-handle.bottom-right {
    bottom: -4px;
    right: -4px;
}

.dropped-element .delete-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background-color: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    display: none;
    align-items: center;
    justify-content: center;
}

.dropped-element:hover .delete-btn {
    display: flex;
}

/* Element Styles */
.element-label {
    padding: 0.5rem;
    background-color: transparent;
    color: #333;
    font-size: 1rem;
    border: none;
    outline: none;
}

.element-button {
    padding: 0.5rem 1rem;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background-color 0.2s ease;
}

.element-button:hover {
    background-color: #0056b3;
}

.element-input {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.875rem;
    width: 200px;
}

.element-slider {
    width: 200px;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    cursor: pointer;
}

.element-gauge {
    width: 120px;
    height: 120px;
    border: 4px solid #e9ecef;
    border-top-color: #007bff;
    border-radius: 50%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #495057;
}

.element-led {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: #28a745;
    box-shadow: 0 0 10px rgba(40, 167, 69, 0.5);
}

.element-chart {
    width: 300px;
    height: 200px;
    border: 2px solid #007bff;
    border-radius: 8px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: #495057;
    font-weight: 500;
    position: relative;
    overflow: hidden;
}

.element-chart::before {
    content: '';
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    bottom: 40px;
    border-left: 2px solid #007bff;
    border-bottom: 2px solid #007bff;
    opacity: 0.3;
}

.element-chart::after {
    content: '';
    position: absolute;
    bottom: 40px;
    left: 20px;
    right: 20px;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, #007bff 20%, #28a745 40%, #ffc107 60%, #dc3545 80%, transparent 100%);
    opacity: 0.5;
}

.element-container {
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    min-width: 200px;
    min-height: 100px;
    background-color: rgba(248, 249, 250, 0.5);
    position: relative;
}

.element-divider {
    width: 100%;
    height: 1px;
    background-color: #dee2e6;
    margin: 1rem 0;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    border-radius: 12px;
    width: 80%;
    max-width: 800px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: modalSlideIn 0.3s ease;
}

.modal-content.preview-modal {
    width: 90%;
    max-width: 1200px;
    height: 80vh;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.close {
    color: white;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    transition: opacity 0.2s ease;
}

.close:hover {
    opacity: 0.7;
}

.modal-body {
    padding: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
}

.code-tabs {
    display: flex;
    margin-bottom: 1rem;
    border-bottom: 1px solid #e9ecef;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: #6c757d;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.tab-btn.active {
    color: #007bff;
    border-bottom-color: #007bff;
}

.tab-btn:hover {
    color: #007bff;
}

.code-content {
    background-color: #f8f9fa;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.code-content pre {
    margin: 0;
    padding: 1.5rem;
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.5;
    background-color: #f8f9fa;
}

.code-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

#preview-frame {
    width: 100%;
    height: 60vh;
    border: none;
    border-radius: 8px;
    background-color: white;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .sidebar {
        width: 250px;
    }
    
    .properties-panel {
        width: 250px;
    }
}

@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }
    
    .sidebar,
    .properties-panel {
        width: 100%;
        max-height: 200px;
    }
    
    .header {
        padding: 1rem;
    }
    
    .header h1 {
        font-size: 1.25rem;
    }
    
    .header-buttons {
        flex-wrap: wrap;
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Animation Classes */
.fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.slide-in {
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(-20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}