
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #00979d;
    --primary-dark: #007a7f;
    --secondary-color: #f0f0f0;
    --accent-color: #ff6b35;
    --success-color: #4caf50;
    --danger-color: #f44336;
    --warning-color: #ff9800;
    --text-color: #333;
    --text-light: #666;
    --border-color: #ddd;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: var(--text-color);
    overflow: hidden;
}

/* ===============================================
   App Container & Layout
   =============================================== */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ===============================================
   Header Toolbar
   =============================================== */

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    box-shadow: var(--shadow);
    z-index: 100;
}

.toolbar-left h1 {
    font-size: 1.4rem;
    font-weight: 600;
}

.toolbar-left .subtitle {
    font-size: 0.75rem;
    opacity: 0.8;
    margin-left: 10px;
}

.toolbar-center {
    display: flex;
    gap: 10px;
}

.view-toggle {
    display: flex;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    overflow: hidden;
}

.view-btn {
    padding: 8px 20px;
    border: none;
    background: transparent;
    color: white;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.view-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.view-btn.active {
    background: white;
    color: var(--primary-color);
    font-weight: 600;
}

.toolbar-right {
    display: flex;
    gap: 10px;
}

.control-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
}

.start-btn {
    background: var(--success-color);
    color: white;
}

.start-btn:hover:not(:disabled) {
    background: #45a049;
    transform: translateY(-1px);
}

.stop-btn {
    background: var(--danger-color);
    color: white;
}

.stop-btn:hover:not(:disabled) {
    background: #e53935;
    transform: translateY(-1px);
}

.reset-btn {
    background: var(--warning-color);
    color: white;
}

.reset-btn:hover {
    background: #f57c00;
    transform: translateY(-1px);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-icon {
    font-size: 0.8rem;
}

/* ===============================================
   Component Palette (Left Sidebar)
   =============================================== */

.component-palette {
    width: 200px;
    background: white;
    border-right: 1px solid var(--border-color);
    padding: 15px;
    overflow-y: auto;
}

.component-palette h2 {
    font-size: 1rem;
    color: var(--primary-color);
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary-color);
}

.palette-section {
    margin-bottom: 20px;
}

.palette-section h3 {
    font-size: 0.8rem;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.component-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px;
    margin-bottom: 10px;
    background: var(--secondary-color);
    border-radius: 8px;
    cursor: grab;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.component-item:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.component-item:active {
    cursor: grabbing;
}

.component-item span {
    font-size: 0.85rem;
    margin-top: 8px;
    font-weight: 500;
}

.component-preview {
    width: 60px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Arduino Icon */
.arduino-icon {
    width: 50px;
    height: 35px;
    background: #00979d;
    border-radius: 4px;
    position: relative;
    box-shadow: inset 0 -2px 4px rgba(0,0,0,0.2);
}

.arduino-icon::before {
    content: '';
    position: absolute;
    top: 5px;
    left: 5px;
    right: 5px;
    height: 8px;
    background: #333;
    border-radius: 2px;
}

.arduino-icon::after {
    content: 'UNO';
    position: absolute;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 8px;
    color: white;
    font-weight: bold;
}

/* LED Icon */
.led-icon {
    width: 20px;
    height: 30px;
    background: linear-gradient(180deg, #ff4444 0%, #cc0000 100%);
    border-radius: 50% 50% 20% 20%;
    position: relative;
    box-shadow: 0 0 10px rgba(255, 68, 68, 0.5);
}

.led-icon::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 8px;
    height: 10px;
    background: #666;
}

/* Button Icon */
.button-icon {
    width: 35px;
    height: 25px;
    background: #444;
    border-radius: 4px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.button-icon::before {
    content: '';
    width: 15px;
    height: 15px;
    background: #888;
    border-radius: 3px;
    box-shadow: inset 0 2px 4px rgba(255,255,255,0.3);
}

/* ===============================================
   Canvas Area
   =============================================== */

.canvas-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.canvas {
    flex: 1;
    position: relative;
    background: #fafafa;
    overflow: hidden;
}

.canvas-grid {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(rgba(0,0,0,0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0,0,0,0.03) 1px, transparent 1px);
    background-size: 20px 20px;
    pointer-events: none;
}

.components-layer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.components-layer > * {
    pointer-events: auto;
}

.wires-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.canvas-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-light);
    pointer-events: none;
}

.canvas-placeholder p {
    font-size: 1.1rem;
    margin-bottom: 10px;
}

.canvas-placeholder .hint {
    font-size: 0.9rem;
    opacity: 0.7;
}

.canvas-placeholder.hidden {
    display: none;
}

/* ===============================================
   Canvas Components
   =============================================== */

.canvas-component {
    position: absolute;
    cursor: move;
    user-select: none;
    transition: box-shadow 0.2s ease;
}

.canvas-component:hover {
    z-index: 10;
}

.canvas-component.selected {
    z-index: 20;
}

.canvas-component.selected::after {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    border: 2px dashed var(--primary-color);
    border-radius: 8px;
    pointer-events: none;
}

/* Arduino Uno on Canvas */
.arduino-uno-component {
    width: 280px;
    height: 180px;
    background: linear-gradient(145deg, #00979d, #007a7f);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    padding: 10px;
    display: flex;
    flex-direction: column;
}

.arduino-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.arduino-label {
    color: white;
    font-weight: bold;
    font-size: 1rem;
}

.arduino-usb {
    width: 30px;
    height: 15px;
    background: #333;
    border-radius: 2px;
}

.arduino-pins-container {
    display: flex;
    justify-content: space-between;
    flex: 1;
}

.pin-row {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.pin-row.digital {
    align-items: flex-end;
}

.pin-row.analog {
    align-items: flex-start;
}

.arduino-pin {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.65rem;
    color: white;
}

.pin-row.digital .arduino-pin {
    flex-direction: row-reverse;
}

.pin-dot {
    width: 12px;
    height: 12px;
    background: #ffd700;
    border-radius: 50%;
    border: 2px solid #333;
    transition: all 0.2s ease;
}

.pin-dot.active {
    background: #00ff00;
    box-shadow: 0 0 8px #00ff00;
}

.pin-dot.gnd {
    background: #333;
}

.pin-dot.power {
    background: #ff4444;
}

.arduino-chip {
    width: 60px;
    height: 40px;
    background: #222;
    border-radius: 4px;
    margin: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 0.5rem;
}

/* LED on Canvas */
.led-component {
    width: 60px;
    height: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    background: rgba(255,255,255,0.9);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.led-bulb {
    width: 30px;
    height: 45px;
    background: linear-gradient(180deg, #ff6666 0%, #cc0000 100%);
    border-radius: 50% 50% 30% 30%;
    transition: all 0.2s ease;
    position: relative;
}

.led-bulb.on {
    background: linear-gradient(180deg, #ff4444 0%, #ff0000 100%);
    box-shadow: 0 0 20px rgba(255, 0, 0, 0.8), 0 0 40px rgba(255, 0, 0, 0.4);
}

.led-legs {
    display: flex;
    gap: 8px;
    margin-top: 5px;
}

.led-leg {
    width: 3px;
    height: 25px;
    background: #888;
}

.led-leg.anode {
    height: 30px;
}

.led-label {
    font-size: 0.7rem;
    color: var(--text-light);
    margin-top: 5px;
}

/* Push Button on Canvas */
.button-component {
    width: 80px;
    height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    background: rgba(255,255,255,0.9);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.button-body {
    width: 50px;
    height: 35px;
    background: #333;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.button-cap {
    width: 25px;
    height: 25px;
    background: linear-gradient(145deg, #888, #666);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.1s ease;
    box-shadow: 0 3px 0 #444;
}

.button-cap:hover {
    background: linear-gradient(145deg, #999, #777);
}

.button-cap:active,
.button-cap.pressed {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #444;
}

.button-pins {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-top: 5px;
}

.button-pin {
    width: 3px;
    height: 15px;
    background: #888;
}

.button-label {
    font-size: 0.7rem;
    color: var(--text-light);
    margin-top: 5px;
}

/* ===============================================
   Code Panel
   =============================================== */

.code-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 400px;
    height: 100%;
    background: #1e1e1e;
    border-left: 3px solid var(--primary-color);
    display: flex;
    flex-direction: column;
    z-index: 50;
    transition: transform 0.3s ease;
}

.code-panel.hidden {
    transform: translateX(100%);
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: #252526;
    border-bottom: 1px solid #333;
}

.code-header h3 {
    color: #ddd;
    font-size: 0.9rem;
}

.copy-btn {
    padding: 5px 10px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.2s ease;
}

.copy-btn:hover {
    background: var(--primary-dark);
}

.code-display {
    flex: 1;
    padding: 15px;
    margin: 0;
    overflow: auto;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    color: #d4d4d4;
    white-space: pre-wrap;
}

.code-display code {
    display: block;
}

/* Syntax highlighting */
.code-keyword {
    color: #569cd6;
}

.code-function {
    color: #dcdcaa;
}

.code-number {
    color: #b5cea8;
}

.code-comment {
    color: #6a9955;
}

.code-string {
    color: #ce9178;
}

/* ===============================================
   Properties Panel (Right Sidebar)
   =============================================== */

.properties-panel {
    width: 220px;
    background: white;
    border-left: 1px solid var(--border-color);
    padding: 15px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.properties-panel h2 {
    font-size: 1rem;
    color: var(--primary-color);
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary-color);
}

.properties-content {
    flex: 1;
}

.no-selection {
    color: var(--text-light);
    font-size: 0.85rem;
    font-style: italic;
}

.property-group {
    margin-bottom: 15px;
}

.property-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-light);
    margin-bottom: 5px;
}

.property-group select,
.property-group input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
}

.property-group select:focus,
.property-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.component-info {
    padding: 10px;
    background: var(--secondary-color);
    border-radius: 6px;
    margin-bottom: 15px;
}

.component-info h4 {
    font-size: 0.9rem;
    margin-bottom: 5px;
    color: var(--primary-color);
}

.component-info p {
    font-size: 0.8rem;
    color: var(--text-light);
}

/* Simulation Status */
.simulation-status {
    margin-top: auto;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.simulation-status h3 {
    font-size: 0.85rem;
    color: var(--text-color);
    margin-bottom: 10px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #888;
}

.status-dot.running {
    background: var(--success-color);
    animation: pulse 1s infinite;
}

.status-dot.stopped {
    background: var(--danger-color);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

#statusText {
    font-size: 0.85rem;
    font-weight: 500;
}

.pin-states {
    font-size: 0.8rem;
}

.pin-state-item {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px solid #eee;
}

.pin-state-item:last-child {
    border-bottom: none;
}

.pin-value {
    font-weight: 600;
}

.pin-value.high {
    color: var(--success-color);
}

.pin-value.low {
    color: var(--text-light);
}

/* ===============================================
   Status Bar
   =============================================== */

.status-bar {
    display: flex;
    justify-content: space-between;
    padding: 8px 20px;
    background: #333;
    color: #aaa;
    font-size: 0.8rem;
}

/* ===============================================
   Wire Styles
   =============================================== */

.wire {
    fill: none;
    stroke-width: 3;
    stroke-linecap: round;
}

.wire.led-wire {
    stroke: #ff4444;
}

.wire.button-wire {
    stroke: #4444ff;
}

.wire.gnd-wire {
    stroke: #333;
}

/* ===============================================
   Drag and Drop Styles
   =============================================== */

.canvas.drag-over {
    background: rgba(0, 151, 157, 0.1);
}

.component-item.dragging {
    opacity: 0.5;
}

.drag-preview {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.8;
}

/* ===============================================
   Delete Button
   =============================================== */

.delete-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 24px;
    height: 24px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: none;
    z-index: 100;
}

.canvas-component.selected .delete-btn {
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-btn:hover {
    background: #d32f2f;
    transform: scale(1.1);
}

/* ===============================================
   Responsive Adjustments
   =============================================== */

@media (max-width: 1200px) {
    .component-palette {
        width: 160px;
    }
    
    .properties-panel {
        width: 180px;
    }
    
    .code-panel {
        width: 350px;
    }
}

@media (max-width: 900px) {
    .properties-panel {
        display: none;
    }
}
