/* ========================================
   ECU Pinout Generator - Styles
   ======================================== */

:root {
    /* Core Colors */
    --bg-primary: #0d0d14;
    --bg-secondary: #141420;
    --bg-tertiary: #1a1a2e;
    --bg-elevated: #222236;
    
    --text-primary: #f0f0f5;
    --text-secondary: #a0a0b0;
    --text-muted: #606070;
    
    --accent-primary: #00ff88;
    --accent-secondary: #ff3366;
    --accent-tertiary: #3388ff;
    --accent-warning: #ffaa00;
    
    --border-color: #2a2a40;
    --border-light: #3a3a50;
    
    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    
    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    
    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

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

body {
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* ========================================
   App Layout
   ======================================== */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    color: var(--accent-primary);
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.header-actions {
    display: flex;
    gap: var(--spacing-sm);
}

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

/* ========================================
   Sidebar
   ======================================== */

.sidebar {
    width: 400px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.panel {
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    border: 1px solid var(--border-color);
}

.panel-title {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-color);
}

.panel-title svg {
    color: var(--accent-primary);
}

/* ========================================
   Form Elements
   ======================================== */

.form-group {
    margin-bottom: var(--spacing-md);
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
    font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    transition: border-color var(--transition-fast);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.form-group select {
    cursor: pointer;
}

/* Color Input */
.color-input-wrapper {
    display: flex;
    gap: var(--spacing-sm);
}

.color-input-wrapper input[type="color"] {
    width: 48px;
    height: 38px;
    padding: 2px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
}

.color-input-wrapper input[type="text"] {
    flex: 1;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}

/* Number Input */
.number-input {
    display: flex;
    align-items: center;
    gap: 0;
}

.number-input button {
    width: 38px;
    height: 38px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.number-input button:first-child {
    border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.number-input button:last-child {
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.number-input button:hover {
    background: var(--accent-primary);
    color: var(--bg-primary);
}

.number-input input {
    width: 60px;
    text-align: center;
    border-radius: 0;
    border-left: none;
    border-right: none;
}

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 26px;
    transition: var(--transition-normal);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: var(--transition-normal);
}

.toggle input:checked + .toggle-slider {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.toggle input:checked + .toggle-slider:before {
    background: var(--bg-primary);
    transform: translateX(22px);
}

/* ========================================
   Buttons
   ======================================== */

.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent-primary);
    color: var(--bg-primary);
}

.btn-primary:hover {
    background: #00cc6a;
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-elevated);
    border-color: var(--accent-primary);
}

.btn-outline {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-outline:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
}

.btn-small {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.8rem;
}

.btn-danger {
    background: var(--accent-secondary);
    color: white;
}

.btn-danger:hover {
    background: #cc2952;
}

/* ========================================
   Connector List
   ======================================== */

.connector-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
}

.connector-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.connector-item:hover {
    border-color: var(--accent-primary);
    background: var(--bg-elevated);
}

.connector-item.active {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(0, 255, 136, 0.2);
}

.connector-color {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    border: 2px solid rgba(255,255,255,0.2);
}

.connector-info {
    flex: 1;
}

.connector-info .name {
    font-size: 0.85rem;
    font-weight: 500;
}

.connector-info .details {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.connector-actions {
    display: flex;
    gap: var(--spacing-xs);
}

.connector-actions button {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.connector-actions button:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

/* ========================================
   Legend Items
   ======================================== */

.legend-items {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    max-height: 200px;
    overflow-y: auto;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.legend-item input[type="color"] {
    width: 32px;
    height: 32px;
    padding: 2px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.legend-item input[type="text"] {
    flex: 1;
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
}

.legend-item button {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: color var(--transition-fast);
}

.legend-item button:hover {
    color: var(--accent-secondary);
}

/* ========================================
   Annotation List
   ======================================== */

.annotation-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    max-height: 200px;
    overflow-y: auto;
}

.annotation-item {
    padding: var(--spacing-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.annotation-item .row {
    display: flex;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-xs);
}

.annotation-item .row:last-child {
    margin-bottom: 0;
}

.annotation-item input,
.annotation-item select {
    flex: 1;
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.8rem;
}

.annotation-item input[type="color"] {
    width: 32px;
    flex: none;
    padding: 2px;
}

.annotation-item button {
    width: 28px;
    height: 28px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}

.annotation-item button:hover {
    color: var(--accent-secondary);
}

/* ========================================
   Preview Section
   ======================================== */

.preview-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    overflow: hidden;
}

.preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.zoom-controls button {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.zoom-controls button:hover {
    background: var(--accent-primary);
    color: var(--bg-primary);
    border-color: var(--accent-primary);
}

.zoom-controls span {
    font-size: 0.85rem;
    color: var(--text-secondary);
    min-width: 50px;
    text-align: center;
}

.preview-info {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

.preview-container {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
    background: 
        radial-gradient(circle at center, var(--bg-tertiary) 0%, var(--bg-primary) 100%),
        repeating-linear-gradient(0deg, transparent, transparent 20px, var(--border-color) 20px, var(--border-color) 21px),
        repeating-linear-gradient(90deg, transparent, transparent 20px, var(--border-color) 20px, var(--border-color) 21px);
    background-blend-mode: normal;
}

.preview-canvas {
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    transform-origin: center center;
    transition: transform var(--transition-normal);
}

/* ========================================
   Pin Editor Panel
   ======================================== */

.pin-editor-panel {
    width: 0;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    overflow: hidden;
    transition: width var(--transition-normal);
}

.pin-editor-panel.active {
    width: 350px;
    padding: var(--spacing-md);
}

.pin-editor-panel .panel-title {
    position: relative;
}

.pin-editor-panel .close-btn {
    position: absolute;
    right: 0;
    top: -4px;
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
}

.pin-editor-panel .close-btn:hover {
    color: var(--accent-secondary);
}

.hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    padding: var(--spacing-lg);
}

/* ========================================
   Modal
   ======================================== */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.modal-content.modal-large {
    max-width: 800px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-header .close-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color var(--transition-fast);
}

.modal-header .close-btn:hover {
    color: var(--accent-secondary);
}

.modal-body {
    padding: var(--spacing-lg);
    overflow-y: auto;
    max-height: 60vh;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

/* ========================================
   Pin Grid (Modal)
   ======================================== */

.pin-grid-container {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.pin-grid-row {
    display: flex;
    gap: var(--spacing-xs);
    flex-wrap: wrap;
}

.pin-cell {
    width: 48px;
    height: 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;	
}

.pin-cell:hover {
    border-color: var(--accent-primary);
    transform: scale(1.05);
}

.pin-cell.selected {
    border-radius: 100%;
    background: #646464 !important;
}

.pin-cell .pin-number {
    font-size: 0.75rem;
    font-weight: 600;
    color: white !important;
}

.pin-cell .pin-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 2px;
}

.pin-color-picker {
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--border-color);
}

.pin-color-picker h4 {
    font-size: 0.85rem;
    margin-bottom: var(--spacing-sm);
    color: var(--text-secondary);
}

.color-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

.color-swatch {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.color-swatch:hover {
    transform: scale(1.1);
}

.color-swatch.active {
    border-color: white;
    box-shadow: 0 0 0 2px var(--accent-primary);
}

.color-swatch .swatch-label {
    position: absolute;
    bottom: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.65rem;
    color: white !important;
    white-space: nowrap;
}

/* ========================================
   Connector Preview Styles (Generated SVG)
   ======================================== */

.ecu-diagram {
    padding: 40px;
    min-width: 800px;
}

.ecu-diagram .title {
    text-anchor: middle;
    font-size: 18px;
    font-weight: 600;
    fill: #ffffff;
}

.ecu-diagram .connector-group {
    cursor: pointer;
}

.ecu-diagram .connector-group:hover .connector-body {
    stroke: var(--accent-primary);
    stroke-width: 3;
}

/* ========================================
   Theme Variations
   ======================================== */

/* Blueprint Theme */
.theme-blueprint .preview-container {
    background: 
        linear-gradient(rgba(0, 40, 80, 0.9), rgba(0, 30, 60, 0.95)),
        repeating-linear-gradient(0deg, transparent, transparent 24px, rgba(100, 180, 255, 0.1) 24px, rgba(100, 180, 255, 0.1) 25px),
        repeating-linear-gradient(90deg, transparent, transparent 24px, rgba(100, 180, 255, 0.1) 24px, rgba(100, 180, 255, 0.1) 25px);
}

/* Clean Theme */
.theme-clean .preview-container {
    background: #f5f5f7;
}

/* Industrial Theme */
.theme-industrial .preview-container {
    background: 
        linear-gradient(135deg, #2d2d2d 0%, #1a1a1a 100%),
        repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255,255,255,0.02) 10px, rgba(255,255,255,0.02) 20px);
}

/* ========================================
   Scrollbar
   ======================================== */

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

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 1200px) {
    .sidebar {
        width: 280px;
    }
    
    .pin-editor-panel.active {
        width: 300px;
    }
}

@media (max-width: 900px) {
    .app-main {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        max-height: 300px;
        flex-direction: row;
        flex-wrap: wrap;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .sidebar .panel {
        flex: 1;
        min-width: 250px;
    }
    
    .header-actions {
        flex-wrap: wrap;
    }
}