/*
 * OWON XDM1041 Web Interface
 * Based on PS5 UART Web Tool design
 */

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

body {
    --bg-gradient-start: #1e1e2e;
    --bg-gradient-end: #2d2d44;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-heading: #ffffff;
    --panel-bg: rgba(255, 255, 255, 0.05);
    --panel-border: rgba(255, 255, 255, 0.1);
    --control-bg: rgba(255, 255, 255, 0.1);
    --control-hover-bg: rgba(255, 255, 255, 0.15);
    --control-border: rgba(255, 255, 255, 0.2);
    --control-border-hover: rgba(255, 255, 255, 0.3);
    --accent-color: #4a9eff;
    --accent-color-dim: rgba(74, 158, 255, 0.3);
    --canvas-bg: rgba(0, 0, 0, 0.2);
    --info-panel-bg: rgba(0, 0, 0, 0.2);
    --shadow-color: rgba(0, 0, 0, 0.5);
    --credits-bg: rgba(255, 255, 255, 0.03);
    --credits-hover-bg: rgba(255, 255, 255, 0.05);
    --success-color: #00c853;
    --success-dim: rgba(0, 200, 83, 0.25);
    --warn-color: #ff9800;
    --danger-color: #f44336;
    --danger-bg: rgba(244, 67, 54, 0.2);
    --segmented-bg: rgba(255, 255, 255, 0.05);
    --segmented-label: rgba(255, 255, 255, 0.7);
    --segmented-label-hover: rgba(255, 255, 255, 0.9);
    --segmented-separator: rgba(255, 255, 255, 0.1);
    --tools-badge-bg: #191828;
    --tools-dropdown-bg: rgba(0, 0, 0, 0.7);
    --tools-dropdown-hover-bg: rgba(255, 255, 255, 0.1);

    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    color: var(--text-primary);
    padding: 15px;
    min-height: 100vh;
    height: 100vh;
    overflow: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

body.light-theme {
    --bg-gradient-start: #e8eef7;
    --bg-gradient-end: #c9d6e8;
    --text-primary: #2d3748;
    --text-secondary: #4a5568;
    --text-heading: #1a202c;
    --panel-bg: rgba(255, 255, 255, 0.8);
    --panel-border: rgba(0, 0, 0, 0.1);
    --control-bg: rgba(255, 255, 255, 0.9);
    --control-hover-bg: rgba(240, 244, 248, 1);
    --control-border: rgba(0, 0, 0, 0.15);
    --control-border-hover: rgba(0, 0, 0, 0.25);
    --accent-color: #2563eb;
    --accent-color-dim: rgba(37, 99, 235, 0.2);
    --canvas-bg: rgba(255, 255, 255, 0.5);
    --info-panel-bg: rgba(0, 0, 0, 0.03);
    --shadow-color: rgba(0, 0, 0, 0.15);
    --credits-bg: rgba(0, 0, 0, 0.03);
    --credits-hover-bg: rgba(0, 0, 0, 0.05);
    --success-color: #008000;
    --success-dim: rgba(0, 128, 0, 0.2);
    --warn-color: #e65100;
    --danger-color: #c62828;
    --danger-bg: rgba(198, 40, 40, 0.15);
    --segmented-bg: rgba(0, 0, 0, 0.03);
    --segmented-label: rgba(0, 0, 0, 0.6);
    --segmented-label-hover: rgba(0, 0, 0, 0.8);
    --segmented-separator: rgba(0, 0, 0, 0.15);
    --tools-badge-bg: #ced5e0;
    --tools-dropdown-bg: rgba(255, 255, 255, 0.7);
    --tools-dropdown-hover-bg: rgba(0, 0, 0, 0.1);
}

.container {
    max-width: 1750px;
    margin: 0 auto;
    height: calc(100vh - 30px);
    display: flex;
    flex-direction: column;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-shrink: 0;
    gap: 15px;
}

.header-center { flex: 1; text-align: center; }

/* Navigation Menu */
.tool-navigation {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.tool-breadcrumb {
    background: var(--tools-badge-bg);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    color: var(--text-primary);
}

.tool-separator {
    width: 20px;
    height: 20px;
    stroke: var(--text-secondary);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    flex-shrink: 0;
}

.tool-name-container {
    position: relative;
    display: inline-block;
}

.tool-name {
    color: var(--text-heading);
    font-size: 2em;
    margin: 0;
    text-shadow: 2px 2px 4px var(--shadow-color);
    cursor: pointer;
    transition: color 0.3s ease;
    text-decoration: underline;
    text-decoration-style: dotted;
}

.tool-name-container:hover .tool-name {
    color: var(--accent-color);
}

.tool-dropdown {
    position: absolute;
    top: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--tools-dropdown-bg);
    backdrop-filter: blur(10px);
    border-radius: 10px;
    padding: 16px;
    min-width: 400px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 1000;
    box-shadow: 0 8px 24px var(--shadow-color);
}

.tool-name-container:hover .tool-dropdown,
.tool-name-container.dropdown-active .tool-dropdown {
    opacity: 1;
    visibility: visible;
}

.tool-name-container.dropdown-active .tool-name {
    color: var(--accent-color);
}

.tool-dropdown-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 20px;
}

.tool-dropdown-group:first-child {
    margin-top: 0px;
}

.tool-dropdown-group-title {
    color: var(--accent-color);
    font-size: 1em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 8px 0;
    padding: 0 8px;
}

.tool-dropdown-item {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 12px;
    border-radius: 8px;
    text-decoration: none;
    transition: background 0.2s ease;
}

.tool-dropdown-item:hover {
    background: var(--tools-dropdown-hover-bg);
}

.tool-dropdown-item.active {
    background: rgba(74, 158, 255, 0.2);
}

.tool-dropdown-item-icon {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tool-dropdown-item-icon img {
    width: 32px;
    height: 32px;
}

.tool-dropdown-item-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    text-align: left;
}

.tool-dropdown-item-name {
    color: var(--text-heading);
    font-size: 0.95em;
    font-weight: 600;
}

.tool-dropdown-item-desc {
    color: var(--text-secondary);
    font-size: 0.8em;
    line-height: 1.3;
}

.version-badge-header {
    background: var(--accent-color-dim);
    color: var(--accent-color);
    padding: 3px 5px 2px 5px;
    border-radius: 5px;
    font-size: 0.65em;
    font-weight: 600;
    border: 1px solid var(--accent-color);
    cursor: pointer;
    transition: all 0.3s ease;
    align-self: flex-start;
    margin-top: 4px;
}

.version-badge-header:hover {
    background: var(--accent-color);
    color: var(--text-heading);
}

.credits {
    width: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2em;
    font-weight: bold;
    text-shadow: 2px 2px 4px var(--shadow-color);
}

.credits-logo-wrap {
    position: relative;
    width: 59px;
    height: 59px;
    margin-right: 20px;
    flex-shrink: 0;
}

.credits-logo-wrap img {
    position: absolute;
    left: 0;
    top: 0;
    width: 59px;
    height: 59px;
    margin: 0;
    transition: opacity 0.2s ease;
}

.credits-logo-wrap .credits-logo-yt { opacity: 0; }
.credits-link:hover .credits-logo-wrap .credits-logo-default { opacity: 0; }
.credits-link:hover .credits-logo-wrap .credits-logo-yt { opacity: 1; }

.credits-link {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.credits-link:hover { color: #ff0000; }

.feedback {
    width: 300px;
    display: flex;
    justify-content: flex-end;
    text-align: right;
    font-size: 0.8em;
    color: var(--text-secondary);
}

.feedback a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color 0.3s ease;
}

.feedback a:hover { color: var(--text-primary); text-decoration: underline; }

header h1 {
    color: var(--text-heading);
    font-size: 2em;
    margin-bottom: 5px;
    text-shadow: 2px 2px 4px var(--shadow-color);
}

.subtitle { color: var(--text-secondary); font-size: 0.95em; }

.menu-toggle {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1002;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    border: 1px solid var(--control-border);
    background: var(--control-bg);
    color: var(--text-heading);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.menu-toggle:hover {
    background: var(--control-hover-bg);
    border-color: var(--control-border-hover);
}

.menu-toggle svg { width: 20px; height: 20px; fill: currentColor; }

.drawer-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.drawer-overlay.active { display: block; opacity: 1; }

.drawer-close {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    border: 1px solid var(--control-border);
    background: var(--control-bg);
    color: var(--text-heading);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 10;
}

.drawer-close:hover {
    background: var(--control-hover-bg);
    border-color: var(--control-border-hover);
}

.drawer-close svg { width: 20px; height: 20px; fill: currentColor; }

.main-content {
    display: grid;
    grid-template-columns: 300px 1fr 300px;
    gap: 15px;
    align-items: stretch;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.controls {
    background: var(--panel-bg);
    padding: 20px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    overflow-y: auto;
    max-height: 100%;
    position: relative;
}

.control-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 30px;
}

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

/* Keep DC/AC control truly hidden when mode is not Volt/Current. */
#volt-curr-ac-wrap[hidden] {
    display: none !important;
}

#voltage-zero-threshold-wrap[hidden] {
    display: none !important;
}

.control-section-title {
    color: var(--accent-color);
    margin-bottom: 10px;
    font-size: 1em;
    border-bottom: 2px solid var(--accent-color-dim);
    padding-bottom: 6px;
    font-weight: 600;
}

.sidebar-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar-buttons .btn {
    width: 100%;
    padding: 12px 16px;
    flex: none;
}

/* Mode section: same look as template Filter Pads (segmented-control) */
.segmented-control {
    display: flex;
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid var(--control-border);
    background: var(--segmented-bg);
    width: 100%;
}

.segmented-control input[type="radio"] {
    display: none;
}

.segmented-control label {
    padding: 7px 0px;
    font-size: 0.95em;
    font-weight: normal;
    color: var(--segmented-label);
    background: var(--segmented-bg);
    cursor: pointer;
    transition: all 0.3s ease;
    border-right: 1px solid var(--panel-border);
    margin: 0;
    user-select: none;
    flex: 1;
    text-align: center;
}

.segmented-control .control-botton-line {
    border-bottom: 1px solid var(--segmented-separator);
}

.segmented-control label:last-child {
    border-right: none;
}

.segmented-control label:hover {
    background: var(--control-hover-bg);
    color: var(--segmented-label-hover);
}

.segmented-control input[type="radio"]:checked + label {
    background: var(--accent-color-dim);
    color: var(--text-heading);
    font-weight: 600;
}

/* Mode section: grid layout like Filter Pads */
#mode-control.segmented-control {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
}

#mode-control .btn-mode {
    padding: 0px;
    font-size: 0.95em;
    font-weight: normal;
    color: var(--segmented-label);
    background: var(--segmented-bg);
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    margin: 0;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    font-family: inherit;
}

#mode-control .btn-mode.control-botton-line {
    border-bottom: 1px solid var(--segmented-separator);
}

#mode-control .btn-mode:last-child {
    border-right: none;
}

#mode-control .btn-mode:hover {
    background: var(--control-hover-bg);
    color: var(--segmented-label-hover);
}

#mode-control .btn-mode.active {
    background: var(--accent-color-dim);
    color: var(--text-heading);
    font-weight: 600;
}

.mode-btn-icon {
    padding: 16px 10px;
    height: 1em;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mode-btn-icon svg {
    width: 1em;
    height: 1em;
    vertical-align: top;
}

.mode-btn-label {
    flex: 1;
    text-align: left;
}

#mode-control .btn-mode {
    border-left: none;
}

#mode-control .btn-mode:nth-child(2n) {
    border-left: 1px solid var(--panel-border);
}

.range-select-wrap .custom-select {
    width: 100%;
}

.checkbox-container {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
}

.checkbox-container input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent-color);
}

.checkbox-container label {
    margin: 0;
    cursor: pointer;
    font-size: 0.95em;
    user-select: none;
}

.threshold-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

#voltage-zero-threshold {
    flex: 1;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid var(--control-border);
    background: var(--control-bg);
    color: var(--text-heading);
    font-size: 0.95em;
}

#voltage-zero-threshold:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--accent-color-dim);
}

.threshold-unit {
    color: var(--text-secondary);
    font-size: 0.95em;
    min-width: 1.5em;
}

.threshold-help {
    margin-top: 8px;
    color: var(--text-secondary);
    font-size: 0.8em;
}

/* Viewer: readout + log */
.viewer-panel {
    background: var(--panel-bg);
    padding: 20px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.readout-mode-rail {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(4, minmax(0, 1fr));
    gap: 0;
    align-content: stretch;
    align-items: stretch;
    flex: 0 0 150px;
    background: var(--segmented-bg);
    border-right: 1px solid var(--panel-border);
    overflow: hidden;
}

.readout-rail-btn {
    padding: 0;
    min-height: 0;
    height: 100%;
    border-radius: 0;
    border: none;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--segmented-label);
    background: var(--segmented-bg);
}

.readout-mode-rail .readout-rail-btn {
    padding: 12px;
}
.readout-mode-rail .readout-rail-btn svg {
    width: 1.5em;
    height: 1.5em;
}

.readout-rail-btn .mode-btn-icon {
    padding: 0;
    width: 1.5em;
    height: 1.5em;
}

.readout-rail-label {
    padding-top: 5px;
    font-size: 0.7rem;
    line-height: 1;
}

.readout-rail-btn:hover {
    background: var(--control-hover-bg);
    color: var(--segmented-label-hover);
}

.readout-rail-btn.active {
    background: var(--accent-color-dim);
    color: var(--text-heading);
}

.readout-mode-rail .readout-rail-btn:nth-child(odd) {
    border-right: 1px solid var(--segmented-separator);
}

.readout-mode-rail .readout-rail-btn:nth-child(-n+6) {
    border-bottom: 1px solid var(--segmented-separator);
}

.readout-mode-rail .readout-rail-btn:nth-child(1) {
    border-top-left-radius: 8px;
}

.readout-mode-rail .readout-rail-btn:nth-child(7) {
    border-bottom-left-radius: 8px;
}

.viewer-panel .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-shrink: 0;
    gap: 12px;
}

.viewer-panel .panel-header .section-title {
    margin-bottom: 0;
    flex-shrink: 0;
    display: inline-block;
}

.connection-badge {
    width: 150px;
    flex-shrink: 0;
    text-align: center;
    font-size: 0.8em;
    font-weight: 600;
    text-transform: lowercase;
    padding: 4px 12px;
    border-radius: 999px;
    letter-spacing: 0.02em;
}

.connection-badge-disconnected {
    background: rgba(244, 67, 54, 0.25);
    color: #f44336;
    border: 1px solid rgba(244, 67, 54, 0.5);
}

.connection-badge-connected {
    background: rgba(0, 200, 83, 0.25);
    color: #00c853;
    border: 1px solid rgba(0, 200, 83, 0.5);
}

.section-title {
    color: var(--accent-color);
    font-size: 1.05em;
    font-weight: 600;
    border-bottom: 2px solid var(--accent-color-dim);
    padding-bottom: 6px;
    margin-bottom: 12px;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85em;
    font-weight: 600;
    border-radius: 4px;
    border: 1px solid var(--control-border);
    background: var(--control-bg);
    color: var(--text-heading);
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
}

.btn-small:hover {
    background: var(--control-hover-bg);
    border-color: var(--control-border-hover);
}

/* Multimeter readout display */
.readout-wrap {
    background: transparent;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 16px;
    flex-shrink: 0;
    min-height: 300px;
    display: flex;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0;
}

.readout-content {
    display: flex;
    flex: 1;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--canvas-bg);
}

.readout-main-line {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 3em;
    flex-wrap: wrap;
}

.readout-analog {
    display: none;
    width: min(100%, 420px);
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.readout-wrap.readout-view-analog .readout-main-line {
    display: none;
}

.readout-wrap.readout-view-analog .readout-analog {
    display: flex;
}

.readout-primary-line {
    display: inline-flex;
    align-items: baseline;
    justify-content: center;
    gap: 3em;
    width: 600px;
}

.viewer-panel.scpi-log-off .readout-wrap {
    flex: 1;
    min-height: 0;
}

.readout-value {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: var(--readout-value-font-size, clamp(2rem, 5vw, 3.5rem));
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: 0.02em;
}

.readout-wrap.readout-value-font-workbench .readout-value {
    font-family: 'Workbench', sans-serif;
}

.readout-wrap.readout-value-font-share-tech-mono .readout-value {
    font-family: 'Share Tech Mono', monospace;
}

.readout-wrap.readout-value-font-vt323 .readout-value {
    font-family: 'VT323', monospace;
}

.readout-wrap.readout-value-font-major-mono-display .readout-value {
    font-family: 'Major Mono Display', monospace;
}

.readout-wrap.readout-value-font-syne-mono .readout-value {
    font-family: 'Syne Mono', monospace;
}

.readout-wrap.readout-value-font-reddit-mono .readout-value {
    font-family: 'Reddit Mono', monospace;
}

.readout-wrap.readout-value-font-bitcount-grid-single .readout-value {
    font-family: 'Bitcount Grid Single', monospace;
}

.readout-wrap.readout-value-font-zcool-qingke-huangyou .readout-value {
    font-family: 'ZCOOL QingKe HuangYou', sans-serif;
}

.readout-unit {
    font-size: calc(var(--readout-value-font-size, clamp(2rem, 5vw, 3.5rem)) * 0.5);
    line-height: 1;
    color: var(--text-secondary);
}

.readout-mode {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2em;
    min-width: 3.6em;
    font-size: 1em;
    color: var(--accent-color);
    text-shadow: 0 0 6px rgba(74, 158, 255, 0.75), 0 0 14px rgba(74, 158, 255, 0.45);
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.readout-mode-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.readout-mode-icon svg {
    width: 3.5em;
    height: 3.5em;
}

.readout-mode-label {
    flex: 0 0 auto;
    font-size: 0.62rem;
    line-height: 1;
    text-transform: capitalize;
}

/* Analog view: charcoal panel + white arc scale + orange needle (classic meter look) */
.analog-meter-panel {
    --analog-panel-bg: #222222;
    /* Keep footer the same dark tone even in light theme */
    --analog-footer-bg: #222222;
    --analog-needle: #ff4500;
    --analog-scale: #ffffff;
    width: 100%;
    max-width: 400px;
    background: var(--analog-panel-bg);
    border-radius: 8px;
    padding: 0;
    border: 1px solid #141414;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.04),
        0 10px 28px rgba(0, 0, 0, 0.42);
    overflow: hidden;
}

.analog-meter-face {
    padding: 14px 16px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: var(--analog-panel-bg);
    position: relative;
}

.analog-meter-scale-wrap {
    position: relative;
    width: 100%;
    z-index: 2;
}

.analog-meter-svg {
    display: block;
    width: 100%;
    height: auto;
    color: var(--analog-scale);
    position: relative;
    z-index: 2;
}

.analog-scale-numbers {
    pointer-events: none;
}

.analog-scale-numbers text {
    font-weight: 600;
    letter-spacing: 0.01em;
}

.analog-meter-center {
    position: absolute;
    left: 50%;
    top: 63%;
    transform: translate(-50%, -50%);
    z-index: 0;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--analog-scale);
}

.analog-meter-big-unit {
    font-family: Arial, Helvetica, sans-serif;
    font-size: clamp(2rem, 5vw, 2.75rem);
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.02em;
}

.analog-dc-symbol {
    width: min(100px, 28vw);
    height: auto;
    color: var(--analog-scale);
    display: block;
}

.analog-meter-digital {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    justify-content: center;
    gap: 0.35rem;
    margin-top: 6px;
    padding: 5px 14px 7px;
    width: 100%;
    box-sizing: border-box;
}

.analog-digital-value,
.analog-digital-unit {
    font-family: 'DSEG7 Classic Mini', 'Share Tech Mono', monospace;
    font-weight: 400;
    color: var(--analog-scale);
    text-shadow: 0 0 6px rgba(255, 255, 255, 0.12);
}

.analog-digital-value {
    font-size: clamp(1.35rem, 3.5vw, 1.85rem);
    letter-spacing: 0.02em;
}

.analog-digital-unit {
    font-size: clamp(0.95rem, 2.4vw, 1.2rem);
    opacity: 0.95;
}

.analog-needle-line {
    pointer-events: none;
}

.analog-needle-ext-line {
    pointer-events: none;
}

.analog-pivot-dot {
    pointer-events: none;
    filter: drop-shadow(0 0 0.5px rgba(0, 0, 0, 0.4));
}

.analog-meter-footer {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 12px 14px 13px;
    background: var(--analog-footer-bg);
    border-top: 1px solid #181818;
}

.analog-meter-digital--footer {
    /* Footer placement: keep text centered and avoid stretching to full width. */
    width: auto;
    margin-top: 0;
    padding: 0;
    box-sizing: border-box;
}

.analog-meter-footer .analog-corner-screw:first-child {
    justify-self: start;
}

.analog-meter-footer .analog-corner-screw:last-child {
    justify-self: end;
}

.analog-corner-screw {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    box-sizing: border-box;
    border: 1px solid #2e2e2e;
    background: radial-gradient(circle at 30% 28%, #353535, #121212 55%, #080808 100%);
    box-shadow:
        inset 0 1px 1px rgba(255, 255, 255, 0.06),
        inset 0 -2px 5px rgba(0, 0, 0, 0.9),
        0 1px 2px rgba(0, 0, 0, 0.85);
    position: relative;
}

.analog-corner-screw::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 9px;
    height: 1px;
    margin-left: -4.5px;
    margin-top: -0.5px;
    background: #0a0a0a;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.04);
}

body.light-theme .readout-mode {
    text-shadow: 0 0 5px rgba(37, 99, 235, 0.55), 0 0 10px rgba(37, 99, 235, 0.35);
}

body.light-theme .analog-meter-panel {
    --analog-panel-bg: #ffffff;
    --analog-scale: #000000;
    border-color: #1c1c1c;
}

/* Footer keeps the dark background tone; do not recolor its digits to black. */
body.light-theme .analog-meter-footer {
    --analog-scale: #ffffff;
}

/* If the face ever needs the shadow removed in light theme, do it only there. */
body.light-theme .analog-meter-face .analog-digital-value,
body.light-theme .analog-meter-face .analog-digital-unit {
    text-shadow: none;
}

.readout-wrap.continuity-closed .readout-value { color: var(--success-color); }
.readout-wrap.continuity-open .readout-value { color: var(--text-secondary); }
.readout-wrap.continuity-closed .analog-readout-numeric { color: var(--success-color); }
.readout-wrap.continuity-open .analog-readout-numeric { color: var(--text-secondary); }

.scpi-log-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.scpi-log-section.scpi-log-section--hidden {
    display: none;
}

.scpi-log-section .scpi-panel-header {
    display: grid;
    grid-template-columns: minmax(0, auto) minmax(140px, 1fr) auto;
    align-items: center;
    gap: 10px 14px;
}

.scpi-log-section .scpi-panel-title {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.scpi-log-section .scpi-tab-control {
    width: 100%;
    max-width: 280px;
    justify-self: center;
}

.scpi-panel-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 0;
    position: relative;
}

/* [hidden] must win over .scpi-pane { display: flex } (same specificity otherwise loses in author CSS). */
.scpi-panel-body > .scpi-pane[hidden] {
    display: none !important;
}

.scpi-pane {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.scpi-pane-graph {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 180px;
}

.measurement-graph-canvas {
    display: block;
    width: 100%;
    flex: 1;
    min-height: 160px;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    background: var(--canvas-bg);
}

.scpi-pane-log {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.scpi-pane-log .terminal-box {
    min-height: 120px;
}

.terminal-box {
    background: var(--canvas-bg);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 12px 16px;
    min-height: 80px;
    flex: 1;
    overflow: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85em;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.terminal-box .line-success { color: var(--success-color); }
.terminal-box .line-info   { color: #64b5f6; }
.terminal-box .line-warn   { color: var(--warn-color); }
.terminal-box .line-error  { color: var(--danger-color); }

.info-panel {
    background: var(--panel-bg);
    padding: 20px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    overflow-y: auto;
    max-height: 100%;
}

.info-section { margin-bottom: 30px; }
.info-section:last-child { margin-bottom: 0; }

.info-section h3 {
    color: var(--accent-color);
    margin-bottom: 10px;
    font-size: 1.05em;
    border-bottom: 2px solid var(--accent-color-dim);
    padding-bottom: 6px;
    font-weight: 600;
}

.visual-styles-section .custom-select {
    max-width: 100%;
}

/* Font and Range selectboxes: solid backgrounds (no opacity). Lists may be in body when open. */
.visual-styles-section .custom-select-trigger,
.visual-styles-section .custom-select-list,
.visual-styles-section .custom-select-option,
#readout-value-font-list,
#readout-value-font-list .custom-select-option,
.range-select-wrap .custom-select-trigger,
#range-select-list,
#range-select-list .custom-select-option {
    background-color: #2d2d3d;
}

.visual-styles-section .custom-select-trigger:hover,
.visual-styles-section .custom-select-option:hover,
#readout-value-font-list .custom-select-option:hover,
.range-select-wrap .custom-select-trigger:hover,
#range-select-list .custom-select-option:hover {
    background-color: #3a3a4a;
}

body.light-theme .visual-styles-section .custom-select-trigger,
body.light-theme .visual-styles-section .custom-select-list,
body.light-theme .visual-styles-section .custom-select-option,
body.light-theme #readout-value-font-list,
body.light-theme #readout-value-font-list .custom-select-option,
body.light-theme .range-select-wrap .custom-select-trigger,
body.light-theme #range-select-list,
body.light-theme #range-select-list .custom-select-option {
    background-color: #e8ecf0;
}

body.light-theme .visual-styles-section .custom-select-trigger:hover,
body.light-theme .visual-styles-section .custom-select-option:hover,
body.light-theme #readout-value-font-list .custom-select-option:hover,
body.light-theme .range-select-wrap .custom-select-trigger:hover,
body.light-theme #range-select-list .custom-select-option:hover {
    background-color: #dce2e8;
}

.visual-styles-section #decimal-places-control {
    max-width: 100%;
}

.visual-styles-section #readout-view-control {
    max-width: 100%;
}

/* Font size slider */
.visual-styles-section input[type="range"]#readout-font-size-slider {
    width: 100%;
    max-width: 280px;
    margin-top: 4px;
    accent-color: var(--accent-color);
}

.visual-styles-section #font-size-value {
    font-weight: normal;
    color: var(--text-secondary);
    margin-left: 0.25em;
}

.hint-block {
    font-size: 0.9em;
    line-height: 1.5;
    color: var(--text-secondary);
}

.hotkey-list { list-style: none; margin: 0; padding: 0; }

.hotkey-list li {
    padding: 4px 0;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.hotkey-list kbd {
    flex-shrink: 0;
    padding: 2px 8px;
    font-size: 0.85em;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    background: var(--control-bg);
    border: 1px solid var(--control-border);
    border-radius: 4px;
    color: var(--text-heading);
}

.additional-info-content {
    color: var(--text-secondary);
    line-height: 1.6;
}

.additional-info-content a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color 0.3s ease;
}

.additional-info-content a:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

.btn {
    padding: 12px 24px;
    font-size: 1em;
    font-weight: 600;
    border: 1px solid var(--control-border);
    background: var(--control-bg);
    color: var(--text-heading);
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
}

.btn:hover:not(:disabled) {
    background: var(--control-hover-bg);
    border-color: var(--control-border-hover);
}

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

.btn-primary {
    background: var(--accent-color-dim);
    border-color: var(--accent-color);
    color: var(--text-heading);
}

.btn-primary:hover:not(:disabled) {
    background: rgba(74, 158, 255, 0.4);
    border-color: var(--accent-color);
}

.btn-danger {
    background: var(--danger-bg);
    border-color: var(--danger-color);
    color: var(--text-heading);
}

.btn-danger:hover:not(:disabled) {
    background: rgba(244, 67, 54, 0.35);
    border-color: var(--danger-color);
}

/* Modal overlay */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

/* Modal content */
.modal-content {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 30px;
    color-scheme: dark;
    max-width: 700px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    backdrop-filter: blur(11px);
    box-shadow: 0 10px 40px var(--shadow-color);
    transform: scale(0.8);
    transition: transform 0.4s ease;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-content h2 {
    color: var(--text-heading);
    font-size: 1.8em;
    margin-bottom: 20px;
    text-align: center;
}

.modal-body {
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 0.9em;
}

.modal-option {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.modal-option:last-child {
    margin-bottom: 0;
}

.modal-option label {
    font-weight: 600;
    color: var(--text-heading);
}

.readout-color-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.readout-color-row input[type="color"] {
    width: 48px;
    height: 36px;
    padding: 2px;
    border-radius: 6px;
    border: 1px solid var(--control-border);
    background: var(--control-bg);
    cursor: pointer;
}

.readout-color-row input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.readout-color-row input[type="color"]::-webkit-color-swatch {
    border-radius: 4px;
    border: none;
}

#decimal-places-control {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    max-width: 120px;
}

.custom-select {
    position: relative;
    max-width: 280px;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 12px;
    font-size: 1em;
    font-family: inherit;
    border-radius: 6px;
    border: 1px solid var(--control-border);
    background-color: var(--control-bg);
    color: var(--text-heading);
    cursor: pointer;
    text-align: left;
}

.custom-select-trigger:hover {
    background-color: var(--control-hover-bg);
    border-color: var(--control-border-hover);
}

.custom-select-arrow {
    margin-left: 8px;
    font-size: 0.7em;
    opacity: 0.8;
}

.custom-select-list {
    position: fixed;
    margin-top: 4px;
    padding: 4px 0;
    border-radius: 6px;
    border: 1px solid var(--control-border);
    background-color: var(--control-bg);
    box-shadow: 0 4px 12px var(--shadow-color);
    z-index: 1001;
    display: none;
}

.custom-select-list.open {
    display: block;
}

.custom-select-option {
    padding: 8px 12px;
    font-size: 1em;
    font-family: inherit;
    background-color: var(--control-bg);
    color: var(--text-heading);
    cursor: pointer;
}

.custom-select-option:hover {
    background-color: var(--control-hover-bg);
}

/* Modal close button */
.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--control-border);
    background: var(--control-bg);
    color: var(--text-heading);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    padding: 0;
}

.modal-close:hover {
    background: var(--control-hover-bg);
    border-color: var(--control-border-hover);
}

.modal-close svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

body.light-theme .modal-content {
    color-scheme: light;
}

/* Responsive */
@media (max-width: 1620px) {
    .readout-primary-line {
        width: auto;
    }
}
@media (max-width: 1400px) {
    .menu-toggle { display: flex; }
    .drawer-close { display: flex; }
    body { height: auto; min-height: 100vh; overflow: auto; }
    .container { height: auto; min-height: calc(100vh - 30px); }
    .main-content {
        grid-template-columns: 1fr;
        height: auto;
        min-height: 0;
    }
    .viewer-panel {
        height: auto;
        min-height: 300px;
        max-height: calc(100vh - 150px);
        max-height: calc(100dvh - 150px);
        overflow: auto;
    }
    .readout-mode-rail {
        flex-basis: 150px;
    }
    .info-panel { display: none; }
    .controls {
        position: fixed;
        top: 0;
        left: -320px;
        width: 300px;
        height: 100vh;
        height: 100dvh;
        z-index: 1000;
        transition: left 0.3s ease;
        margin: 0;
        border-radius: 0;
        padding-top: 55px;
    }
    .controls.open { left: 0; }
    .feedback { display: none; }
    header h1 { font-size: 1.3em; }
    header .subtitle { display: none; }
    header { flex-direction: column; gap: 10px; }
    header .credits { display: none; }
}

@media (max-width: 1000px) {
    .main-content { grid-template-columns: 1fr; gap: 10px; }
    #mode-control.segmented-control { grid-template-columns: 1fr; }
    #mode-control .btn-mode:nth-child(2n) { border-left: none; }
    #mode-control .btn-mode:not(:last-child) { border-bottom: 1px solid var(--segmented-separator); }
    .readout-wrap {
        flex-direction: column;
        align-items: center;
    }
    .readout-mode-rail {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        grid-template-rows: repeat(2, minmax(0, 1fr));
        flex: 0 0 auto;
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--panel-border);
        overflow: hidden;
    }
    .readout-mode-rail .readout-rail-btn {
        border-right: 1px solid var(--segmented-separator);
        border-bottom: none;
    }
    .readout-mode-rail .readout-rail-btn:nth-child(4n) {
        border-right: none;
    }
    .readout-mode-rail .readout-rail-btn:nth-child(-n+4) {
        border-bottom: 1px solid var(--segmented-separator);
    }
    .readout-mode-rail .readout-rail-btn:nth-child(n+5) {
        border-bottom: none;
    }
    .readout-mode-rail .readout-rail-btn:nth-child(1),
    .readout-mode-rail .readout-rail-btn:nth-child(7) {
        border-radius: 0;
    }
}
@media (max-width: 500px) {
    .tool-navigation {
        padding-left: 45px;
    }
    .tool-navigation .tool-breadcrumb,
    .tool-navigation .tool-separator {
        display: none;
    }
}
