/* =====================================================
   Circuit Simulator - Design System & Styles
   ===================================================== */

/* ----- CSS Custom Properties (Design Tokens) ----- */
:root {
    /* Colors - Dark Theme (teal/navy inspired) */
    --bg-primary: #0a0f1a;
    --bg-secondary: #111827;
    --bg-tertiary: #1a2234;
    --bg-elevated: #243044;

    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent-primary: #2dd4bf;
    --accent-secondary: #34d399;
    --accent-warning: #fbbf24;
    --accent-danger: #f87171;

    --border-primary: #1e3a5f;
    --border-secondary: #1a2234;

    /* Grid colors */
    --grid-line: rgba(30, 58, 95, 0.5);
    --grid-line-major: rgba(45, 212, 191, 0.1);
    --grid-bg: #0a0f1a;

    /* Component colors */
    --component-stroke: #38bdf8;
    --component-fill: rgba(56, 189, 248, 0.08);
    --component-selected: #34d399;
    --wire-color: #fb923c;
    --node-color: #38bdf8;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Typography */
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;

    /* Layout */
    --header-height: 52px;
    --toolbar-width: 220px;
    --right-panel-width: 320px;
    --status-bar-height: 28px;

    /* Effects */
    --shadow-sm: 0 1px 2px 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);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* ----- Reset & Base ----- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-primary);
    font-size: var(--font-size-md);
    color: var(--text-primary);
    background-color: var(--bg-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ----- App Layout ----- */
#app {
    display: grid;
    grid-template-rows: var(--header-height) 1fr var(--status-bar-height);
    height: 100vh;
    width: 100vw;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-shrink: 0;
}

.logo-icon {
    width: 24px;
    height: 24px;
    color: var(--accent-primary);
    filter: drop-shadow(0 0 8px rgba(45, 212, 191, 0.4));
}

.logo-text {
    font-size: var(--font-size-md);
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

/* Header icon-only action buttons */
.header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
}

.header-divider {
    width: 1px;
    height: 24px;
    background: var(--border-primary);
    margin: 0 6px;
}

.header-icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    text-decoration: none;
}

.header-icon-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-primary);
    color: var(--text-primary);
}

.header-icon-btn:active {
    background: var(--bg-elevated);
}

.header-icon-btn svg {
    width: 18px;
    height: 18px;
}

/* ----- Buttons ----- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    font-family: var(--font-primary);
    font-size: var(--font-size-sm);
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn svg {
    width: 16px;
    height: 16px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), #0d9488);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(45, 212, 191, 0.3);
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #5eead4, var(--accent-primary));
    box-shadow: 0 4px 16px rgba(45, 212, 191, 0.4);
    transform: translateY(-1px);
}

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

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ----- Main Content ----- */
.app-main {
    display: grid;
    grid-template-columns: var(--toolbar-width) 4px 1fr 4px var(--right-panel-width);
    overflow: hidden;
}

/* Panel drag handles */
.panel-drag-handle {
    width: 4px;
    cursor: col-resize;
    background: var(--border-primary);
    transition: background var(--transition-fast);
    z-index: 10;
}

.panel-drag-handle:hover,
.panel-drag-handle.dragging {
    background: var(--accent-primary);
}

/* ----- Toolbar (Left Panel) ----- */
.toolbar {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 60px;
}

.toolbar-title {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-primary);
    flex-shrink: 0;
}

/* Toolbar search */
.toolbar-search {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm);
    border-bottom: 1px solid var(--border-primary);
    flex-shrink: 0;
}

.toolbar-search .search-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-muted);
}

.toolbar-search input {
    flex: 1;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: var(--font-size-xs);
    outline: none;
    transition: border-color var(--transition-fast);
}

.toolbar-search input::placeholder {
    color: var(--text-muted);
}

.toolbar-search input:focus {
    border-color: var(--accent-primary);
}

/* Component list */
.component-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-xs);
}

/* Component category section */
.component-category {
    margin-bottom: 2px;
}

.category-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: 8px 12px;
    cursor: pointer;
    user-select: none;
    transition: background-color var(--transition-fast);
}

.category-header:hover {
    background: var(--bg-tertiary);
}

.category-icon {
    font-size: 14px;
    line-height: 1;
}

.category-label {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.category-chevron {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
}

.component-category.collapsed .category-chevron {
    transform: rotate(-90deg);
}

.component-category.collapsed .component-grid {
    display: none;
}

/* 2-column card grid */
.component-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px 4px 8px;
}

/* Component card */
.component-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 4px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.component-card:hover {
    background: var(--bg-elevated);
    border-color: var(--accent-primary);
    box-shadow: 0 0 10px rgba(45, 212, 191, 0.08);
}

.component-card:active {
    transform: scale(0.96);
}

.component-card .card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 32px;
}

.component-card .card-icon svg {
    width: 48px;
    height: 28px;
    color: var(--component-stroke);
}

.component-card .card-name {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.component-card .card-shortcut {
    position: absolute;
    top: 3px;
    right: 4px;
    font-size: 9px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    background: var(--bg-primary);
    border-radius: 3px;
    padding: 0 3px;
    line-height: 14px;
}

/* Active card */
.component-card.active {
    background: rgba(45, 212, 191, 0.12);
    border-color: var(--accent-primary);
}

.component-card.active .card-icon svg {
    color: var(--accent-primary);
    filter: drop-shadow(0 0 4px rgba(45, 212, 191, 0.4));
}

.component-card.active .card-name {
    color: var(--accent-primary);
}

/* ----- Canvas Container ----- */
.canvas-container {
    position: relative;
    overflow: hidden;
    background: var(--grid-bg);
}

.circuit-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.grid-background {
    pointer-events: none;
}

/* Canvas controls */
.canvas-controls {
    position: absolute;
    bottom: var(--spacing-md);
    right: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: var(--spacing-xs);
    box-shadow: var(--shadow-md);
}

.canvas-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.canvas-btn svg {
    width: 20px;
    height: 20px;
}

/* ----- Right Panel ----- */
.right-panel {
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    min-width: 200px;
}

.panel-title {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    border-bottom: none;
    background: transparent;
}

/* Right panel boxed sections */
.collapsible-section {
    margin: 6px 8px;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    background: var(--bg-tertiary);
}

.collapsible-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
    user-select: none;
    padding: 12px 16px;
    transition: background-color var(--transition-fast);
    font-size: var(--font-size-sm);
    font-weight: 600;
    letter-spacing: 0.03em;
    color: var(--text-primary);
    background: transparent;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.collapsible-header:hover {
    background-color: var(--bg-elevated);
}

/* Property Panel */
.property-panel {
    border-bottom: none;
}

.property-panel .collapsible-content {
    padding: var(--spacing-sm) var(--spacing-md) var(--spacing-md);
    max-height: 50vh;
    overflow-y: auto;
}

.placeholder-text {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    font-style: italic;
}

/* Property form fields */
.property-field {
    margin-bottom: var(--spacing-md);
}

.property-field label {
    display: block;
    font-size: var(--font-size-xs);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.property-field input,
.property-field select {
    width: 100%;
    padding: var(--spacing-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    transition: border-color var(--transition-fast);
}

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

/* Simulation Panel */
.simulation-panel {
    border-bottom: 1px solid var(--border-primary);
}

.simulation-controls {
    padding: var(--spacing-md);
}

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

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

.select-input,
.number-input {
    width: 100%;
    padding: var(--spacing-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    transition: border-color var(--transition-fast);
}

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

.sim-buttons {
    display: flex;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

.sim-buttons .btn {
    flex: 1;
    min-width: 70px;
    justify-content: center;
}

.btn-run {
    min-width: 100%;
}

/* Output Panel */
.output-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.output-content {
    flex: 1;
    padding: var(--spacing-md);
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
}

/* Output results styling */
.output-result {
    margin-bottom: var(--spacing-md);
}

.output-result .result-label {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
}

.output-result .result-value {
    color: var(--accent-secondary);
    font-weight: 500;
}

/* ----- Status Bar ----- */
.status-bar {
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
    padding: 0 var(--spacing-md);
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-primary);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.status-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.status-credit {
    margin-left: auto;
    font-weight: 500;
    font-size: 0.8rem;
    color: var(--text-muted);
}

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ----- SVG Component Styles ----- */
.component-group {
    cursor: move;
    transition: filter var(--transition-fast);
}

.component-group:hover {
    filter: brightness(1.2);
}

.component-group.selected {
    filter: drop-shadow(0 0 4px var(--component-selected));
}

.component-group .component-body {
    fill: var(--component-fill);
    stroke: var(--component-stroke);
    stroke-width: 2;
}

.component-group.selected .component-body {
    stroke: var(--component-selected);
}

.component-group .terminal {
    fill: var(--node-color);
    stroke: var(--bg-primary);
    stroke-width: 1;
    cursor: crosshair;
    transition: fill var(--transition-fast);
}

.component-group .terminal:hover {
    fill: var(--accent-secondary);
}

/* Selected terminal for click-to-connect wire mode */
.component-group .terminal.terminal-selected {
    fill: var(--accent-secondary);
    stroke: var(--accent-secondary);
    stroke-width: 2;
    filter: drop-shadow(0 0 6px var(--accent-secondary));
}

.component-group .component-label {
    fill: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    text-anchor: middle;
    dominant-baseline: middle;
    pointer-events: none;
}

.component-group .component-value {
    fill: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 10px;
    text-anchor: middle;
    dominant-baseline: middle;
    pointer-events: none;
}

/* Wire styles */
.wire {
    fill: none;
    stroke: var(--wire-color);
    stroke-width: 2;
    stroke-linecap: round;
    cursor: pointer;
    transition: stroke-width var(--transition-fast);
}

.wire:hover {
    stroke-width: 3;
}

.wire.selected {
    stroke: var(--component-selected);
    stroke-width: 3;
}

/* Wire preview while drawing */
.wire-preview {
    fill: none;
    stroke: var(--wire-color);
    stroke-width: 2;
    stroke-dasharray: 5, 5;
    opacity: 0.6;
    pointer-events: none;
}

/* Node junction point */
.junction-node {
    fill: var(--wire-color);
    stroke: var(--bg-primary);
    stroke-width: 1;
}

/* Selection box */
.selection-box {
    fill: rgba(45, 212, 191, 0.1);
    stroke: var(--accent-primary);
    stroke-width: 1;
    stroke-dasharray: 4, 2;
}

/* ----- Animations ----- */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

@keyframes glow {

    0%,
    100% {
        filter: drop-shadow(0 0 4px var(--accent-primary));
    }

    50% {
        filter: drop-shadow(0 0 8px var(--accent-primary));
    }
}

.simulating .component-group {
    animation: pulse 1s ease-in-out infinite;
}

/* Running indicator */
.status-running {
    color: var(--accent-secondary);
    animation: pulse 1s ease-in-out infinite;
}

/* ----- Responsive Adjustments ----- */
@media (max-width: 1200px) {
    :root {
        --toolbar-width: 180px;
        --right-panel-width: 260px;
    }

    .component-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .app-main {
        grid-template-columns: 60px 4px 1fr 4px 220px;
    }

    .toolbar-title,
    .toolbar-search,
    .category-label,
    .card-name {
        display: none;
    }

    .component-grid {
        grid-template-columns: 1fr;
    }

    .component-card {
        padding: var(--spacing-sm);
    }

    .card-shortcut {
        display: none;
    }
}

/* ----- Property Panel Enhancements ----- */
.property-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-primary);
}

.property-type {
    font-weight: 600;
    color: var(--accent-primary);
}

.property-id {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.property-actions {
    display: flex;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--border-primary);
}

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

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

.position-info .position-value,
.rotation-value {
    font-family: var(--font-mono);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

/* Input with unit */
.input-with-unit {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.input-with-unit input {
    flex: 1;
}

.input-unit {
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    min-width: 24px;
}

/* ----- Output Enhancements ----- */
.output-error {
    padding: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
    background: rgba(248, 81, 73, 0.1);
    border-left: 3px solid var(--accent-danger);
    border-radius: var(--radius-sm);
    color: var(--accent-danger);
    font-size: var(--font-size-sm);
}

.output-success {
    border-left: 3px solid var(--accent-secondary);
}

.result-section {
    margin-bottom: var(--spacing-md);
}

.result-section h4 {
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
}

.simulation-results .output-result {
    display: flex;
    justify-content: space-between;
    padding: var(--spacing-xs) 0;
    border-bottom: 1px solid var(--border-secondary);
}

/* Make simulation results scrollable with good visibility */
.simulation-results {
    max-height: 300px;
    overflow-y: auto;
    padding: var(--spacing-sm);
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    margin-top: var(--spacing-sm);
}

/* ----- Active Component Item (legacy, kept for compat) ----- */
.component-item.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.component-item.active svg {
    color: white;
}

.component-item.active .component-shortcut {
    color: rgba(255, 255, 255, 0.7);
}

/* ----- Chart Overlay Panel ----- */
.chart-overlay {
    display: none;
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
    height: 250px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    z-index: 100;
}

.chart-overlay.visible {
    display: flex;
    flex-direction: column;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-primary);
}

.chart-title {
    font-weight: 600;
    color: var(--text-primary);
}

.chart-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 var(--spacing-xs);
    line-height: 1;
}

.chart-close:hover {
    color: var(--accent-danger);
}

.chart-container {
    flex: 1;
    min-height: 0;
}

.chart-canvas {
    width: 100%;
    height: 100%;
}

/* ----- Oscilloscope Overlay ----- */
.scope-overlay {
    display: none;
    position: absolute;
    top: 20px;
    left: 20px;
    width: calc(100% - 40px);
    height: 300px;
    background: var(--bg-secondary);
    border: 1px solid var(--accent-primary);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 20px rgba(45, 212, 191, 0.1);
    overflow: hidden;
    z-index: 101;
    resize: both;
}

.scope-overlay.visible {
    display: flex;
    flex-direction: column;
}

.scope-overlay .chart-header {
    background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-elevated));
    border-bottom: 1px solid var(--accent-primary);
    cursor: grab;
    user-select: none;
}

.scope-overlay .chart-header:active {
    cursor: grabbing;
}

.scope-overlay .chart-title {
    font-weight: 600;
    color: var(--accent-primary);
}

.scope-overlay .chart-container {
    flex: 1;
    min-height: 0;
}

.scope-canvas {
    width: 100%;
    height: 100%;
}

/* ----- Collapsible Sections (kept for collapse logic) ----- */

.collapse-arrow {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    transition: transform var(--transition-fast);
    transform: rotate(0deg);
    /* Down arrow when expanded */
}

/* Collapsed state - arrow points right */
.collapsible-section.collapsed .collapse-arrow {
    transform: rotate(-90deg);
}

.collapsible-content {
    padding: 0 var(--spacing-md) var(--spacing-md);
    overflow: hidden;
}

.collapsible-section.collapsed .collapsible-content {
    display: none;
}

/* Right panel - scrollable with flex */
.right-panel {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    max-height: calc(100vh - var(--header-height) - var(--status-bar-height));
}

/* Output panel should grow to fill space */
.output-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.output-panel .collapsible-content {
    flex: 1;
    overflow-y: auto;
}

/* Simulation controls padding */
.simulation-controls {
    padding: 0;
}

/* ----- Preset Selection Modal ----- */
.preset-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(13, 17, 23, 0.85);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.preset-modal {
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: var(--spacing-xl);
    width: 90%;
    max-width: 800px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.preset-modal-title {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}

.preset-modal-desc {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xl);
}

.preset-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-lg);
    text-align: left;
}

.preset-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    cursor: pointer;
    transition: all 0.2s ease;
}

.preset-card:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(45, 212, 191, 0.1);
}

.preset-card h3 {
    margin: 0 0 var(--spacing-sm) 0;
    color: var(--accent-primary);
    font-size: 1.1rem;
}

.preset-card p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* --- Sensor UI Controls Overlay --- */
.sensor-controls-overlay {
    position: absolute;
    top: var(--spacing-md);
    right: var(--spacing-md);
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    background: rgba(10, 15, 26, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    box-shadow: var(--shadow-md);
    min-width: 280px;
}
.sensor-button-group {
    display: flex;
    gap: var(--spacing-xs);
}
.sensor-controls-overlay .btn {
    padding: 8px 12px;
    font-size: var(--font-size-sm);
    justify-content: center;
    flex: 1;
}

.sensor-live-panel {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-sm);
    padding: var(--spacing-sm);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-secondary);
    max-height: 200px;
    overflow-y: auto;
}

.sensor-live-header {
    font-weight: bold;
    color: var(--accent-primary);
    margin-bottom: var(--spacing-xs);
    border-bottom: 1px solid var(--border-secondary);
    padding-bottom: 4px;
}

.sensor-live-row {
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    padding: var(--spacing-xs);
    border-radius: 4px;
}

.sensor-live-name {
    color: var(--accent-secondary);
    font-weight: 600;
}

.sensor-live-val {
    margin-left: var(--spacing-sm);
}