/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #1a1a1a;
    line-height: 1.6;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.header h1 {
    color: #1a1a1a;
    margin-bottom: 0.5rem;
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header p {
    color: #6b7280;
    font-size: 1.2rem;
    font-weight: 400;
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    gap: 1rem;
    padding: 1rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Sidebar Container */
.sidebar-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 300px;
}

/* Elements List */
.elements-list {
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    height: fit-content;
    max-height: 300px;
    overflow-y: auto;
}

.elements-list h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.element-list-item {
    display: flex;
    align-items: center;
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    background: #f8f9fa;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.element-list-item:hover {
    background: #e9ecef;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.element-list-item.selected {
    background: #e3f2fd;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.element-list-item .element-icon {
    font-size: 1.2rem;
    margin-right: 0.8rem;
    width: 24px;
    text-align: center;
}

.element-list-item .element-info {
    flex: 1;
}

.element-list-item .element-name {
    font-weight: 500;
    color: #2c3e50;
    margin-bottom: 0.2rem;
}

.element-list-item .element-details {
    font-size: 0.8rem;
    color: #6c757d;
}

.element-layer-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    margin-left: 0.5rem;
}

.layer-number {
    font-size: 0.7rem;
    color: #667eea;
    font-weight: 500;
    background: rgba(102, 126, 234, 0.1);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    min-width: 50px;
    text-align: center;
}

.layer-buttons {
    display: flex;
    gap: 0.2rem;
}

.layer-btn {
    width: 20px;
    height: 20px;
    border: 1px solid #e9ecef;
    background: #f8f9fa;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 10px;
    font-weight: bold;
    color: #495057;
    transition: all 0.2s ease;
}

.layer-btn:hover:not(:disabled) {
    background: #e9ecef;
    border-color: #667eea;
    color: #667eea;
}

.layer-btn:active:not(:disabled) {
    background: #667eea;
    color: white;
    transform: scale(0.9);
}

.layer-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.layer-btn:disabled:hover {
    background: #f8f9fa;
    border-color: #e9ecef;
    color: #495057;
}

.no-elements {
    color: #7f8c8d;
    font-style: italic;
    text-align: center;
    padding: 2rem;
}

/* Sidebar */
.sidebar {
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    height: fit-content;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.sidebar h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.element-category {
    margin-bottom: 1.5rem;
}

.element-category h4 {
    color: #34495e;
    margin-bottom: 0.8rem;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.element-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 12px;
    cursor: grab;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(226, 232, 240, 0.8);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.element-item:hover {
    background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    border-color: rgba(102, 126, 234, 0.3);
}

.element-item:active {
    cursor: grabbing;
    transform: scale(0.98);
}

.element-item.dragging {
    opacity: 0.5;
    transform: rotate(5deg);
}

.element-icon {
    font-size: 1.5rem;
    margin-right: 0.8rem;
    width: 30px;
    text-align: center;
}

.element-item span {
    font-weight: 500;
    color: #2c3e50;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
}

.canvas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #ecf0f1;
}

.canvas-header h3 {
    color: #2c3e50;
    font-size: 1.3rem;
}

.canvas-controls {
    display: flex;
    gap: 0.8rem;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(108, 117, 125, 0.4);
}

/* Canvas */
.canvas-wrapper {
    position: relative;
    display: inline-block;
    border: 3px solid #2c3e50;
    border-radius: 8px;
    background: #000;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    margin: 0 auto;
}

#cyd-canvas {
    display: block;
    background: #000;
    border-radius: 5px;
}

.canvas-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    z-index: 10;
}

/* Properties Panel */
.properties-panel {
    width: 300px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    height: fit-content;
}

.properties-panel h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.no-selection {
    color: #7f8c8d;
    font-style: italic;
    text-align: center;
    padding: 2rem;
}

.property-group {
    margin-bottom: 1.5rem;
}

.property-group h4 {
    color: #34495e;
    margin-bottom: 0.8rem;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.property-field {
    margin-bottom: 1rem;
}

.property-field label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #2c3e50;
}

.property-field input,
.property-field select,
.property-field textarea {
    width: 100%;
    padding: 0.6rem;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: border-color 0.2s ease;
}

.property-field input:focus,
.property-field select:focus,
.property-field textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Arrow Controls */
.arrow-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.arrow-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.arrow-btn {
    width: 32px;
    height: 32px;
    border: 2px solid #e9ecef;
    background: #f8f9fa;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    color: #495057;
    transition: all 0.2s ease;
    user-select: none;
}

.arrow-btn:hover {
    background: #e9ecef;
    border-color: #667eea;
    color: #667eea;
}

.arrow-btn:active {
    background: #667eea;
    color: white;
    transform: scale(0.95);
}

.arrow-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.arrow-btn:disabled:hover {
    background: #f8f9fa;
    border-color: #e9ecef;
    color: #495057;
}

.position-display {
    min-width: 60px;
    text-align: center;
    font-weight: 500;
    color: #2c3e50;
    font-size: 14px;
}

.color-picker {
    width: 100%;
    height: 40px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

/* Canvas Elements */
.canvas-element {
    position: absolute;
    border: 2px solid transparent;
    cursor: move;
    user-select: none;
    transition: all 0.2s ease;
}

.canvas-element:hover {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.canvas-element.selected {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.3);
}

.canvas-element .resize-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #667eea;
    border: 2px solid white;
    border-radius: 50%;
    cursor: nw-resize;
}

.canvas-element .resize-handle.se {
    bottom: -4px;
    right: -4px;
    cursor: se-resize;
}

.canvas-element .resize-handle.sw {
    bottom: -4px;
    left: -4px;
    cursor: sw-resize;
}

.canvas-element .resize-handle.ne {
    top: -4px;
    right: -4px;
    cursor: ne-resize;
}

.canvas-element .resize-handle.nw {
    top: -4px;
    left: -4px;
    cursor: nw-resize;
}

/* Element Types */
.element-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    font-weight: 500;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 80px;
    min-height: 30px;
}

.element-text {
    color: white;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    min-height: 20px;
    padding: 0.2rem;
}

.element-image {
    background: #f8f9fa;
    border: 2px dashed #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    min-height: 40px;
    color: #6c757d;
    font-size: 0.8rem;
}

.element-sensor {
    background: #e8f5e8;
    border: 2px solid #28a745;
    border-radius: 6px;
    padding: 0.5rem;
    text-align: center;
    color: #155724;
    font-weight: 500;
    min-width: 80px;
    min-height: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.element-gauge {
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #856404;
    font-weight: 500;
    min-width: 60px;
    min-height: 60px;
}

.element-switch {
    background: #d1ecf1;
    border: 2px solid #17a2b8;
    border-radius: 20px;
    padding: 0.3rem;
    display: flex;
    align-items: center;
    min-width: 50px;
    min-height: 25px;
    position: relative;
}

.element-switch .switch-thumb {
    width: 20px;
    height: 20px;
    background: #17a2b8;
    border-radius: 50%;
    transition: transform 0.2s ease;
}

.element-slider {
    background: #f8d7da;
    border: 2px solid #dc3545;
    border-radius: 20px;
    padding: 0.3rem;
    display: flex;
    align-items: center;
    min-width: 80px;
    min-height: 25px;
    position: relative;
}

.element-slider .slider-thumb {
    width: 20px;
    height: 20px;
    background: #dc3545;
    border-radius: 50%;
    position: absolute;
    left: 5px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 0;
    border-radius: 12px;
    width: 80%;
    max-width: 800px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 2px solid #ecf0f1;
}

.modal-header h3 {
    color: #2c3e50;
    margin: 0;
}

.close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s ease;
}

.close:hover {
    color: #000;
}

.modal-body {
    padding: 1.5rem;
}

#yaml-output {
    width: 100%;
    height: 400px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    padding: 1rem;
    resize: vertical;
    background: #f8f9fa;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    justify-content: flex-end;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .main-content {
        flex-direction: column;
    }
    
    .sidebar,
    .properties-panel {
        width: 100%;
    }
    
    .canvas-container {
        order: -1;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 1rem;
    }
    
    .header h1 {
        font-size: 1.5rem;
    }
    
    .main-content {
        padding: 0.5rem;
    }
    
    .canvas-wrapper {
        transform: scale(0.8);
        transform-origin: center;
    }
}

/* Drag and Drop States */
.canvas-wrapper.drag-over {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.drop-indicator {
    position: absolute;
    border: 2px dashed #667eea;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 6px;
    pointer-events: none;
    z-index: 5;
}
