:root {
    --bg-dark: #090b0e;
    --bg-card: rgba(22, 27, 34, 0.8);
    --bg-sidebar: #0d1117;
    --border-color: #21262d;
    --text-main: #c9d1d9;
    --text-muted: #8b949e;
    --text-bright: #f0f6fc;
    
    --accent-cyan: #58a6ff;
    --accent-yellow: #d29922;
    --accent-green: #3fb950;
    --accent-red: #f85149;
    
    --ch1-color: #ffec00;
    --ch2-color: #00f2fe;
    
    --gradient-bg: linear-gradient(135deg, #0d1117 0%, #090b0e 100%);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --glass-border: 1px solid rgba(255, 255, 255, 0.05);
}

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

body {
    background: var(--bg-dark);
    background-image: var(--gradient-bg);
    color: var(--text-main);
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    height: 100vh;
    overflow: hidden;
    display: flex;
}

/* App Layout */
.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* Sidebar Styles */
.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 10;
}

.brand {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    border-bottom: 1px solid var(--border-color);
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(45deg, var(--accent-cyan), #8a2be2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: white;
    box-shadow: 0 0 15px rgba(88, 166, 255, 0.4);
}

.brand h2 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-bright);
    letter-spacing: 0.5px;
}

.brand h2 span {
    color: var(--accent-cyan);
    font-weight: 300;
}

.brand-version {
    font-size: 0.72rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 1px;
    margin-left: 48px;
    margin-top: -2px;
    opacity: 0.65;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 12px;
    overflow-y: auto;
}

.nav-header {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    margin: 15px 12px 8px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    gap: 12px;
    margin-bottom: 4px;
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-bright);
}

.nav-item.active {
    background: rgba(88, 166, 255, 0.1);
    color: var(--accent-cyan);
    border-left: 3px solid var(--accent-cyan);
}

.connection-card {
    margin: 16px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.disconnected {
    background-color: var(--accent-red);
    box-shadow: 0 0 8px var(--accent-red);
}

.status-dot.connected {
    background-color: var(--accent-green);
    box-shadow: 0 0 8px var(--accent-green);
}

.connection-info {
    display: flex;
    flex-direction: column;
}

.status-text {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.device-text {
    font-size: 0.9rem;
    color: var(--text-bright);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: #0d0f12;
}

/* Top Header Styles */
.top-header {
    height: 70px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: var(--bg-sidebar);
    flex-shrink: 0;
}

.device-info-bar {
    display: flex;
    gap: 30px;
}

.info-item {
    display: flex;
    flex-direction: column;
}

.info-item .label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-item .value {
    font-size: 0.95rem;
    color: var(--text-bright);
    font-weight: 500;
}

.info-item .value.highlight {
    color: var(--accent-yellow);
}

.actions {
    display: flex;
    gap: 10px;
}

/* Workspace Grid */
.workspace-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 20px;
    padding: 20px;
    overflow: hidden;
    height: calc(100% - 70px);
}

.workspace-left {
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    overflow-x: hidden;
}

.workspace-right {
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow: hidden;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: var(--glass-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.01);
}

.card-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-bright);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-title i {
    color: var(--accent-cyan);
}

/* Scope Screen Styles */
.screen-card {
    flex: 0 0 auto;
    min-height: 350px;
    container-type: inline-size;
}

.screen-wrapper {
    flex: 0 0 auto;
    aspect-ratio: 3 / 2;
    height: calc((100cqw - 40px) / 1.5 + 47px);
    background: #050709;
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

#scope-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.canvas-overlay {
    position: absolute;
    inset: 0;
    background: rgba(5, 7, 9, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 1.1rem;
    z-index: 2;
    backdrop-filter: blur(2px);
}

/* Dynamic Control Panels Styles */
.controls-card {
    flex: 0.9;
    overflow-y: auto;
}

.control-panel {
    padding: 20px;
}

.control-panel h3 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-bright);
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-group label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Form Controls */
select, input[type="text"] {
    width: 100%;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 6px;
    padding: 10px 12px;
    color: var(--text-bright);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

select:focus, input[type="text"]:focus {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}

.select-wrapper {
    position: relative;
}

.input-with-btn {
    display: flex;
    gap: 8px;
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-block {
    width: 100%;
}

.btn-primary {
    background: #1f6feb;
    color: white;
    border-color: rgba(240, 246, 252, 0.1);
}

.btn-primary:hover {
    background: #388bfd;
}

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

.btn-accent:hover {
    background: #4cd964;
}

.btn-danger {
    background: #da3633;
    color: white;
}

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

.btn-outline {
    background: transparent;
    border: 1px solid #30363d;
    color: var(--text-bright);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: #8b949e;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-xs {
    padding: 4px 8px;
    font-size: 0.75rem;
}

.btn-icon {
    width: 38px;
    height: 38px;
    padding: 0;
    background: transparent;
    border: 1px solid #30363d;
    color: var(--text-bright);
    border-radius: 50%;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: #8b949e;
}

.btn-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.scpi-btn {
    background: #21262d;
    border: 1px solid #30363d;
    color: var(--text-bright);
}

.scpi-btn:hover {
    background: #30363d;
    border-color: #8b949e;
}

/* Toggle Switches */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

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

.toggle-switch label {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #30363d;
    border-radius: 24px;
    transition: background-color 0.3s;
}

.toggle-switch label:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle-switch input:checked + label {
    background-color: var(--accent-green);
}

.toggle-switch input:checked + label:before {
    transform: translateX(24px);
}

/* Channel Configurations Flex */
.channels-flex {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.ch-block {
    flex: 1;
    min-width: 200px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ch1-accent {
    border-top: 4px solid var(--ch1-color);
}

.ch2-accent {
    border-top: 4px solid var(--ch2-color);
}

.ch-block h4 {
    font-size: 1rem;
    margin-bottom: 5px;
}

.ch1-accent h4 { color: var(--ch1-color); }
.ch2-accent h4 { color: var(--ch2-color); }

.btn-toggle-ch {
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: bold;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid transparent;
}

.ch1-btn {
    border-color: var(--ch1-color);
    color: var(--ch1-color);
}

.ch1-btn[data-active="true"] {
    background: var(--ch1-color);
    color: black;
}

.ch2-btn {
    border-color: var(--ch2-color);
    color: var(--ch2-color);
}

.ch2-btn[data-active="true"] {
    background: var(--ch2-color);
    color: black;
}

/* Terminal Card */
.terminal-card {
    flex: 1.3;
    font-family: 'JetBrains Mono', monospace;
}

.terminal-actions .btn-clear {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.95rem;
}

.terminal-actions .btn-clear:hover {
    color: var(--accent-red);
}

.terminal-body {
    flex: 1;
    background: #080c10;
    padding: 16px;
    overflow-y: auto;
    font-size: 0.85rem;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.terminal-line {
    word-break: break-all;
    white-space: pre-wrap;
}

.terminal-line.sent {
    color: var(--accent-cyan);
}

.terminal-line.sent::before {
    content: ">> ";
    font-weight: bold;
}

.terminal-line.recv {
    color: #8b949e;
    border-left: 2px solid rgba(255, 255, 255, 0.1);
    padding-left: 8px;
}

.terminal-line.recv::before {
    content: "<< ";
    font-weight: bold;
    color: var(--text-muted);
}

.terminal-line.system {
    color: var(--accent-yellow);
    font-style: italic;
}

.terminal-line.error {
    color: var(--accent-red);
}

.terminal-footer {
    background: #0d1117;
    border-top: 1px solid var(--border-color);
    padding: 10px 16px;
}

#terminal-form {
    display: flex;
    align-items: center;
    gap: 10px;
}

.prompt {
    color: var(--accent-cyan);
    font-weight: bold;
}

#terminal-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 0;
    color: var(--text-bright);
    font-family: inherit;
}

#terminal-input:focus {
    box-shadow: none;
}

/* Quick Commands & Chips */
.quick-commands-card {
    flex: 0.7;
}

.quick-buttons {
    padding: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    overflow-y: auto;
}

.chip {
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    color: var(--text-main);
    font-size: 0.8rem;
    cursor: pointer;
    font-family: 'JetBrains Mono', monospace;
    transition: all 0.2s;
}

.chip:hover {
    background: var(--accent-cyan);
    border-color: var(--accent-cyan);
    color: #000;
}

/* Measure grid styling */
.measure-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-top: 15px;
}

.measure-card {
    background: #161b22;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
}

.m-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.m-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-cyan);
    font-family: 'JetBrains Mono', monospace;
}

/* DMM Display layout */
.dmm-display {
    background: #080c10;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
}

.dmm-header {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.dmm-value-wrapper {
    display: flex;
    align-items: baseline;
    gap: 5px;
}

.dmm-val {
    font-size: 3rem;
    font-family: 'JetBrains Mono', monospace;
    color: #39ff14;
    text-shadow: 0 0 15px rgba(57, 255, 20, 0.4);
    font-weight: 300;
}

.dmm-unit {
    font-size: 1.5rem;
    color: #39ff14;
    font-weight: 600;
}

.dmm-controls {
    display: flex;
    gap: 10px;
}

/* Utils */
.hidden {
    display: none !important;
}

.mt-3 {
    margin-top: 15px;
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 24px;
    border-radius: 8px;
    background: rgba(22, 27, 34, 0.9);
    color: var(--text-bright);
    border: 1px solid var(--accent-cyan);
    box-shadow: var(--glass-shadow);
    z-index: 9999;
    transition: transform 0.3s, opacity 0.3s;
    font-weight: 500;
}

/* Scope Status Bar Integration */
.scope-status-bar {
    background: #10141a !important;
    padding: 8px 16px !important;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    border-bottom: 1px solid #21262d !important;
}

.status-group-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.viewport-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    min-width: 168px;
    margin-left: auto;
    padding: 4px 8px;
    border: 1px solid #30363d;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.22);
}

#viewport-indicator {
    width: 110px;
    height: 24px;
    display: block;
}

.trigger-offset-readout {
    width: 54px;
    color: var(--text-bright);
    font: 600 0.72rem 'JetBrains Mono', monospace;
    text-align: right;
    white-space: nowrap;
}

.screen-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.scope-status-badge {
    background: #2ea44f;
    color: white;
    font-weight: bold;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 4px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    min-width: 50px;
    text-align: center;
}

.scope-status-badge.stopped {
    background: #cf222e;
}

.scope-status-badge.scanning {
    background: #d29922;
}

.btn-run-stop {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-bright);
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-run-stop:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: #3fb950;
    color: #3fb950;
}

.btn-run-stop.running:hover {
    border-color: #f85149;
    color: #f85149;
}

/* Cursors Panel Styles */
:root {
    --cursor-v-color: #ff2e93; /* Neon magenta */
    --cursor-h-color: #00ff66; /* Neon green */
}

.cursors-readout-card {
    background: rgba(22, 27, 34, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    margin-top: 20px;
}

.readout-header {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-bright);
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.readout-table {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.readout-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    padding: 4px 0;
}

.readout-row.header-row {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.8rem;
    border-bottom: 1px dashed var(--border-color);
    padding-bottom: 4px;
    margin-bottom: 4px;
}

.readout-row.highlight-row {
    font-weight: 600;
    color: var(--text-bright);
}

.readout-divider {
    height: 1px;
    background: var(--border-color);
    margin: 8px 0;
}

.cursor-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.v-indicator {
    background-color: var(--cursor-v-color);
    box-shadow: 0 0 6px var(--cursor-v-color);
}

.h-indicator {
    background-color: var(--cursor-h-color);
    box-shadow: 0 0 6px var(--cursor-h-color);
}

.param-name {
    display: flex;
    align-items: center;
    color: var(--text-muted);
}

.readout-row.highlight-row .param-name {
    color: var(--text-bright);
}

.param-value {
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-bright);
}
