* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

#app {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.company-logo {
    height: 40px;
    width: auto;
    object-fit: contain;
}

.header-left h1 {
    font-size: 24px;
    font-weight: 600;
}

.user-info {
    background: rgba(255,255,255,0.2);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 14px;
}

.header-center {
    display: flex;
    gap: 10px;
    align-items: center;
}

.project-name-input {
    padding: 8px 12px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 6px;
    background: rgba(255,255,255,0.9);
    font-size: 14px;
    min-width: 200px;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    background: rgba(255,255,255,0.9);
    color: #667eea;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn:hover {
    background: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sidebar {
    background: white;
    overflow-y: auto;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    z-index: 10;
}

.left-sidebar {
    width: 250px;
    padding: 20px;
}

.right-sidebar {
    width: 300px;
    padding: 20px;
}

.sidebar h3 {
    color: #667eea;
    margin-bottom: 15px;
    font-size: 18px;
}

.component-search {
    margin-bottom: 15px;
}

.component-search input {
    width: 100%;
    padding: 8px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
}

.component-category {
    margin-bottom: 20px;
}

.component-category h4 {
    color: #666;
    font-size: 14px;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.component-item {
    background: #f8f9fa;
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 6px;
    cursor: grab;
    transition: all 0.2s;
    border: 2px solid transparent;
    touch-action: none;
}

.component-item:hover {
    background: #e9ecef;
    border-color: #667eea;
    transform: scale(1.05);
}

.component-item:active {
    cursor: grabbing;
}

.canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fafafa;
    position: relative;
}

.toolbar {
    background: white;
    padding: 12px 20px;
    display: flex;
    gap: 8px;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.tool-btn {
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
}

.tool-btn:hover {
    border-color: #667eea;
    background: #f8f9fa;
}

.tool-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.tool-btn.primary {
    background: #28a745;
    color: white;
    border-color: #28a745;
    font-weight: 600;
}

.tool-btn.primary:hover {
    background: #218838;
}

.divider {
    color: #ddd;
    font-size: 20px;
    margin: 0 5px;
}

.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#canvas {
    width: 100%;
    height: 100%;
    cursor: default;
    touch-action: none;
}

#canvas.wire-mode {
    cursor: crosshair;
}

#canvas.delete-mode {
    cursor: no-drop;
}

.component {
    cursor: move;
    transition: filter 0.3s;
    touch-action: none;
}

.component:hover {
    filter: drop-shadow(0 0 8px rgba(102, 126, 234, 0.5));
}

.component.selected {
    filter: drop-shadow(0 0 12px rgba(102, 126, 234, 0.8));
}

.terminal {
    cursor: pointer;
    transition: all 0.2s;
}

.terminal:hover {
    r: 7;
    fill: #4CAF50;
    stroke: #fff;
    stroke-width: 2;
}

.wire {
    stroke: #2c3e50;
    stroke-width: 3;
    fill: none;
    cursor: pointer;
    transition: all 0.3s;
    stroke-linecap: round;
}

.wire:hover {
    stroke: #e74c3c;
    stroke-width: 4;
    filter: drop-shadow(0 0 4px rgba(231, 76, 60, 0.6));
}

.wire.animated {
    stroke-dasharray: 10;
    animation: dash 1s linear infinite;
}

@keyframes dash {
    to {
        stroke-dashoffset: -20;
    }
}

.wire.current-flow {
    stroke: #3498db;
    stroke-width: 4;
    marker-end: url(#arrowhead);
    filter: drop-shadow(0 0 6px rgba(52, 152, 219, 0.7));
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

.panel {
    background: white;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.properties-panel {
    max-height: 200px;
    overflow-y: auto;
}

.property-row {
    margin-bottom: 12px;
}

.property-row label {
    display: block;
    color: #666;
    font-size: 12px;
    margin-bottom: 4px;
    font-weight: 600;
}

.property-row input,
.property-row select {
    width: 100%;
    padding: 6px 8px;
    border: 2px solid #e0e0e0;
    border-radius: 4px;
    font-size: 13px;
}

.property-row input[type="range"] {
    padding: 0;
}

.hint {
    color: #999;
    font-size: 13px;
    font-style: italic;
}

.tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}

.tab-btn {
    flex: 1;
    padding: 8px;
    border: none;
    background: #f0f0f0;
    cursor: pointer;
    border-radius: 4px;
    font-size: 12px;
}

.tab-btn.active {
    background: #667eea;
    color: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    min-height: 250px;
}

#graphsTab {
    position: relative;
}

#analysisChart {
    width: 100% !important;
    height: 200px !important;
    max-height: 200px;
}

.circuit-summary {
    margin-top: 15px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 8px;
    padding: 12px;
    font-size: 12px;
    border: 1px solid #dee2e6;
    max-height: 400px;
    overflow-y: auto;
}

.summary-header {
    font-size: 13px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 2px solid #667eea;
    color: #495057;
}

.summary-item {
    margin-bottom: 12px;
    padding: 8px;
    background: white;
    border-radius: 6px;
    border-left: 3px solid #667eea;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.summary-label {
    display: block;
    font-weight: 600;
    color: #495057;
    margin-bottom: 3px;
}

.summary-value {
    display: block;
    color: #667eea;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 5px;
}

.summary-desc {
    color: #6c757d;
    font-size: 11px;
    line-height: 1.5;
    font-style: italic;
    margin-top: 4px;
}

.summary-footer {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #dee2e6;
    text-align: center;
    color: #6c757d;
}

.log-window {
    max-height: 200px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    background: #f8f9fa;
    padding: 10px;
    border-radius: 4px;
}

.log-entry {
    padding: 4px;
    border-bottom: 1px solid #e0e0e0;
}

.log-entry.error {
    color: #dc3545;
}

.log-entry.warning {
    color: #ffc107;
}

.log-entry.info {
    color: #17a2b8;
}

.log-entry.success {
    color: #28a745;
}

.ai-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-small {
    padding: 8px 12px;
    border: 2px solid #667eea;
    border-radius: 6px;
    background: white;
    color: #667eea;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-small:hover {
    background: #667eea;
    color: white;
}

.ai-response {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
}

.ai-response h4 {
    color: #667eea;
    margin-bottom: 8px;
}

.ai-response ul {
    margin-left: 20px;
}

.ai-response li {
    margin-bottom: 4px;
}

.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    max-width: 400px;
    width: 90%;
    position: relative;
}

.modal-content.large {
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-content h2 {
    color: #667eea;
    margin-bottom: 20px;
}

.modal-content form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.modal-content input {
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
}

.modal-content button[type="submit"] {
    padding: 12px;
    border: none;
    border-radius: 6px;
    background: #667eea;
    color: white;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
}

.modal-content button[type="submit"]:hover {
    background: #5568d3;
}

.demo-info {
    margin-top: 10px;
    font-size: 12px;
    color: #666;
    text-align: center;
}

.close {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #999;
    cursor: pointer;
}

.close:hover {
    color: #333;
}

.templates-list,
.projects-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    max-height: 500px;
    overflow-y: auto;
}

.template-card,
.project-card {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.template-card:hover,
.project-card:hover {
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.template-card h4,
.project-card h4 {
    color: #333;
    margin-bottom: 8px;
}

.template-card p,
.project-card p {
    color: #666;
    font-size: 12px;
    margin-bottom: 8px;
}

.template-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    background: #667eea;
    color: white;
}

.component-value {
    font-size: 11px;
    fill: #666;
}

.led-glow {
    filter: drop-shadow(0 0 10px currentColor);
    animation: glow 1s ease-in-out infinite alternate;
}

@keyframes glow {
    from {
        filter: drop-shadow(0 0 5px currentColor);
    }
    to {
        filter: drop-shadow(0 0 15px currentColor);
    }
}

.motor-spin {
    animation: spin 2s linear infinite;
    transform-origin: center;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

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

::-webkit-scrollbar-thumb:hover {
    background: #5568d3;
}

.code-editor-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.code-editor-instructions {
    background: #f8f9fa;
    padding: 10px 12px;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.code-editor-instructions p {
    font-weight: 600;
    color: #667eea;
    margin-bottom: 8px;
    font-size: 13px;
}

.code-editor-instructions ol {
    margin-left: 20px;
    color: #666;
    font-size: 12px;
}

.code-editor-instructions li {
    margin-bottom: 4px;
    line-height: 1.4;
}

.code-editor {
    width: 100%;
    min-height: 250px;
    max-height: 400px;
    padding: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
    resize: vertical;
    background: #f8f9fa;
    color: #333;
}

.code-editor:focus {
    outline: none;
    border-color: #667eea;
    background: white;
}

.code-editor-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.code-editor-actions .btn {
    padding: 10px 20px;
    font-size: 14px;
}

.code-editor-actions .btn.primary {
    background: #28a745;
    color: white;
    border-color: #28a745;
}

.code-editor-actions .btn.primary:hover {
    background: #218838;
}

.touch-drag-proxy {
    box-shadow: 0 0 15px rgba(0,0,0,0.3);
    border: 2px solid #667eea;
    opacity: 0.7;
}
