/* Web Serial Debug KR: Korean-first responsive workspace.
   Apache-2.0; original attribution and modification details are in LICENSE and NOTICE. */

/* Operate surface: neutral controls leave color to device traffic and status.
   ANSI output and syntax colors are data, not part of the control palette. */
:root {
    color-scheme: light;
    --app-bg: #f3f3f3;
    --surface: #ffffff;
    --surface-soft: #f7f7f7;
    --surface-hover: #ededed;
    --surface-active: #e0e0e0;
    --text: #202020;
    --muted: #505050;
    --subtle: #666666;
    --border: #dddddd;
    --border-strong: #898989;
    --accent: #333333;
    --accent-hover: #171717;
    --accent-soft: #e8e8e8;
    --accent-contrast: #ffffff;
    --focus: #333333;
    --selection-bg: #d5d5d5;
    --selection-color: #202020;
    --checked-bg: #333333;
    --checked-border: #333333;
    --btn-primary-bg: #252525;
    --btn-primary-color: #ffffff;
    --btn-primary-hover-bg: #111111;
    --btn-primary-active-bg: #000000;
    --tx: #0f766e;
    --tx-soft: #e6f4f2;
    --success: #0d7f4b;
    --success-soft: #eaf6ef;
    --danger: #c52233;
    --danger-soft: #fdeced;
    --warning: #995e00;
    --warning-soft: #fef7e6;
    --terminal-bg: #ffffff;
    --terminal-grid: #ededed;
    /* ANSI SGR 30-37 / 90-97 as rendered on --terminal-bg. Device output keeps
       its colors, but each must stay legible on the current theme. */
    --ansi-black: #3f3f3f;
    --ansi-red: #c62828;
    --ansi-green: #107c10;
    --ansi-yellow: #8f6a00;
    --ansi-blue: #1a5fb4;
    --ansi-magenta: #a626a4;
    --ansi-cyan: #0b7285;
    --ansi-white: #6e6e6e;
    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
    --font-mono: "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", "Malgun Gothic", monospace;
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --bs-primary: var(--accent);
    --bs-body-font-family: var(--font-ui);
    --bs-body-color: var(--text);
    --bs-body-bg: var(--surface);
    --bs-border-color: var(--border);
}

[data-theme="dark"] {
    color-scheme: dark;
    --app-bg: #101010;
    --surface: #181818;
    --surface-soft: #1f1f1f;
    --surface-hover: #292929;
    --surface-active: #333333;
    --text: #f0f0f0;
    --muted: #b5b5b5;
    --subtle: #a5a5a5;
    --border: #363636;
    --border-strong: #707070;
    --accent: #d4d4d4;
    --accent-hover: #f2f2f2;
    --accent-soft: #303030;
    --accent-contrast: #181818;
    --focus: #d4d4d4;
    --selection-bg: #444444;
    --selection-color: #f0f0f0;
    --checked-bg: #505050;
    --checked-border: #a0a0a0;
    --btn-primary-bg: #dedede;
    --btn-primary-color: #181818;
    --btn-primary-hover-bg: #f6f6f6;
    --btn-primary-active-bg: #bbbbbb;
    --tx: #14a89b;
    --tx-soft: #0d2b27;
    --success: #2ea043;
    --success-soft: #11281a;
    --danger: #f85149;
    --danger-soft: #2d1619;
    --warning: #d29922;
    --warning-soft: #282012;
    --terminal-bg: #101010;
    --terminal-grid: #222222;
    --ansi-black: #7b8496;
    --ansi-red: #f87171;
    --ansi-green: #4ade80;
    --ansi-yellow: #facc15;
    --ansi-blue: #60a5fa;
    --ansi-magenta: #c084fc;
    --ansi-cyan: #22d3ee;
    --ansi-white: #cbd5e1;
}

* { box-sizing: border-box; }

.language-control { display: flex; align-items: center; gap: 5px; min-width: 0; }
.language-control > .bi { color: var(--muted); }
.language-control .language-select { width: 104px; min-height: 28px; font-size: 12px; padding-block: 3px; }
html:not([lang="ko"]) body { word-break: normal; }
@media (max-width: 680px) {
    .header-actions { gap: 4px; }
    .language-control > .bi { display: none; }
    .language-control .language-select { width: 94px; }
}
[hidden] { display: none !important; }

html, body {
    margin: 0;
    min-width: 320px;
    min-height: 100%;
}

body {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 13px;
    line-height: 1.5;
    word-break: keep-all; /* Wrap Korean UI copy between words, not mid-word. */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button, input, select, textarea { font: inherit; }
button, a, input, select, textarea, summary { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }

button:focus-visible, a:focus-visible, summary:focus-visible, [tabindex="0"]:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

::selection {
    color: var(--selection-color);
    background: var(--selection-bg);
}

a {
    color: var(--accent);
    text-decoration: none;
}
a:not(.btn):not(.skip-link) {
    text-decoration: underline;
    text-decoration-color: var(--border-strong);
    text-underline-offset: 2px;
}
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }
.bi {
    display: inline-block;
    flex-shrink: 0;
    vertical-align: -.12em;
}

.skip-link {
    position: fixed;
    top: 10px;
    left: 16px;
    z-index: 1100;
    padding: 8px 14px;
    background: var(--btn-primary-bg);
    color: var(--btn-primary-color);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    transform: translateY(-160%);
    transition: transform .12s ease-out;
}
.skip-link:focus { transform: translateY(0); }

/* ==========================================================================
   Buttons & Form Controls
   ========================================================================== */

.btn {
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    min-height: 32px;
    white-space: nowrap;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color .12s, color .12s, border-color .12s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { cursor: not-allowed; opacity: .55; }

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

.btn-outline-secondary {
    --bs-btn-color: var(--text);
    --bs-btn-bg: var(--surface);
    --bs-btn-border-color: var(--border-strong);
    --bs-btn-hover-color: var(--text);
    --bs-btn-hover-bg: var(--surface-hover);
    --bs-btn-hover-border-color: var(--border-strong);
    --bs-btn-active-color: var(--text);
    --bs-btn-active-bg: var(--surface-active);
    --bs-btn-active-border-color: var(--border-strong);
    --bs-btn-disabled-color: var(--muted);
    --bs-btn-disabled-border-color: var(--border);
    color: var(--text);
    background-color: var(--surface);
    border-color: var(--border-strong);
}

.btn-quiet {
    background: transparent;
    color: var(--muted);
    border-color: transparent;
}
.btn-quiet:hover:not(:disabled), .btn-quiet:focus-visible {
    color: var(--text);
    background: var(--surface-hover);
}
.btn-quiet:active:not(:disabled) { background: var(--surface-active); }
.btn-quiet:disabled { color: var(--subtle); }

.icon-button {
    width: 30px;
    min-width: 30px;
    height: 30px;
    min-height: 30px;
    padding: 0;
    font-size: 14px;
}

.form-control, .form-select {
    color: var(--text);
    background-color: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 13px;
    min-height: 33px;
    padding: 6px 9px;
    box-shadow: none;
}
.form-select {
    padding-right: 26px;
    background-position: right 8px center;
    background-size: 10px 8px;
}
/* The shared :focus-visible outline is the one focus indicator; a second
   low-contrast ring around it only adds noise. */
.form-control:focus, .form-select:focus {
    color: var(--text);
    background-color: var(--surface);
    border-color: var(--focus);
    box-shadow: none;
}
.form-control:disabled, .form-select:disabled {
    background-color: var(--surface-soft);
    color: var(--muted);
    border-color: var(--border);
    cursor: not-allowed;
}
.form-control::placeholder { color: var(--subtle); }

.form-check-input {
    width: 15px;
    height: 15px;
    margin: 0;
    border: 1px solid var(--border-strong);
    background-color: var(--surface);
    border-radius: 3px !important;
    cursor: pointer;
}
.form-check-input:checked {
    background-color: var(--checked-bg);
    border-color: var(--checked-border);
}
.form-check-input:focus {
    border-color: var(--focus);
    box-shadow: none;
}

.check-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
    white-space: normal;
    line-height: 1.4;
}

kbd {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 5px;
    white-space: nowrap;
}

/* ==========================================================================
   Header Bar
   ========================================================================== */

.app-header {
    flex: 0 0 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.brand-symbol {
    display: grid;
    place-items: center;
    height: 24px;
    width: 24px;
    background: transparent;
    border: none;
}
.brand-symbol img {
    width: 20px;
    height: 20px;
    filter: brightness(0) opacity(0.85);
}
[data-theme="dark"] .brand-symbol img {
    filter: brightness(0) invert(1);
}
.brand-copy h1 {
    font-size: 14px;
    line-height: 1.2;
    font-weight: 700;
    letter-spacing: -.2px;
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}
.github-link {
    color: var(--muted);
    font-size: 12px;
    min-height: 28px;
    padding: 2px 8px;
    gap: 4px;
}
.github-link:hover { color: var(--text); text-decoration: none; }
.github-link > .bi:first-child { font-size: 14px; }
.external-arrow { font-size: 11px; color: var(--subtle); }

/* ==========================================================================
   Integrated Workspace Layout (Unified Workbench)
   ========================================================================== */

.workspace {
    flex: 1;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    min-height: 0;
    padding: 0;
    gap: 0;
    background: var(--surface);
}

.sidebar {
    position: relative;
    min-height: 0;
    background: var(--surface);
    border: 0;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.connection-panel {
    width: 240px;
    border-right: 1px solid var(--border);
}

.tools-panel {
    width: 320px;
    border-left: 1px solid var(--border);
}

.panel-heading {
    flex: 0 0 38px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px 0 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-soft);
}

.section-title {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.section-title > .bi { font-size: 14px; color: var(--muted); }
.section-title h2 {
    font-size: 13px;
    font-weight: 650;
    letter-spacing: -.2px;
}

.toggle-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--subtle);
    background: transparent;
    cursor: pointer;
    font-size: 16px;
    width: 26px;
    height: 26px;
    padding: 0;
    transition: background-color .12s, color .12s;
}
.toggle-button:hover { background: var(--surface-hover); color: var(--text); }

/* Collapsed Sidebars */
.connection-panel:has(> .sidebar-content:not(.show)),
.tools-panel:has(> .sidebar-content:not(.show)) {
    width: 38px;
    min-width: 38px;
}
.sidebar:has(> .sidebar-content:not(.show)) .section-title { display: none; }
.sidebar:has(> .sidebar-content:not(.show)) .panel-heading { padding: 0 6px; justify-content: center; }

.sidebar-content {
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

/* ==========================================================================
   Left Panel: Connection Configuration
   ========================================================================== */

.port-section {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.small-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 4px;
}
.port-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
}
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--subtle);
    flex-shrink: 0;
}
.port-info {
    font-size: 12px;
    line-height: 1.5;
    margin-top: 4px;
    overflow-wrap: anywhere;
}
.port-select-button {
    width: 100%;
    margin-top: 10px;
    font-size: 12.5px;
    min-height: 32px;
    background: var(--surface-soft);
    border-style: dashed;
}
.connection-message {
    margin-top: 6px;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.5;
    overflow-wrap: anywhere;
}
.connection-message .alert {
    margin: 0;
    padding: 6px 8px;
    font-size: 12px;
}
.connection-fields { padding: 12px 14px; }
.field-label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 4px;
}
.field-hint {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.5;
    margin-top: 4px;
    margin-bottom: 10px;
}
.field-stack {
    display: flex;
    flex-direction: column;
    margin-top: 10px;
    align-items: stretch;
}
.field-stack > .form-control, .field-stack > .form-select {
    width: 100%;
    border-radius: var(--radius-sm) !important;
    margin: 0 !important;
}
.field-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.advanced-settings {
    border-block: 1px solid var(--border);
    margin-top: 14px;
    padding: 10px 0;
}
.advanced-settings summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    user-select: none;
}
summary::-webkit-details-marker { display: none; }
.advanced-settings summary > .bi { font-size: 11px; transition: transform .12s ease; }
.advanced-settings[open] summary > .bi { transform: rotate(180deg); }
.reconnect-option { margin-top: 12px; font-size: 12.5px; }
.connect-button {
    width: 100%;
    min-height: 36px;
    margin-top: 14px;
    font-size: 13.5px;
    font-weight: 600;
}

/* ==========================================================================
   Center Panel: Terminal Monitor & Composer
   ========================================================================== */

.terminal-workspace {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    background: var(--surface);
}

.workspace-titlebar {
    flex: 0 0 38px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-soft);
}
.workspace-title-group h2 {
    font-size: 13px;
    letter-spacing: -.2px;
    line-height: 1.2;
    font-weight: 650;
}
.monitor-state {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 550;
}

.terminal-panel {
    display: flex;
    flex-direction: column;
    min-height: 160px;
    flex: 1;
    overflow: hidden;
    background: var(--surface);
    border: 0;
    border-radius: 0;
}

.log-toolbar {
    flex: 0 0 auto;
    min-height: 38px;
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 5px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-wrap: wrap;
}
.search-field {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1 1 140px;
    min-width: 110px;
    height: 28px;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
    padding: 0 6px;
}
.search-field > .bi { font-size: 12px; color: var(--subtle); }
.search-field input {
    width: 100%;
    min-width: 20px;
    border: 0;
    color: var(--text);
    font-size: 12px;
    padding: 2px 0;
    background: transparent;
}
/* The bordered wrapper is the visible control, so it carries the focus ring
   instead of an outline drawn around the bare input inside it. */
.search-field input:focus-visible { outline: none; }
.search-field input::placeholder { color: var(--subtle); }
.search-field:focus-within {
    border-color: var(--focus);
    background: var(--surface);
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}
.search-field kbd { font-size: 12px; }

.compact-select {
    width: auto;
    min-height: 28px;
    padding: 3px 22px 3px 7px;
    font-size: 12px;
    border-color: var(--border);
    background-color: var(--surface-soft);
    box-shadow: none;
}
.direction-select { width: auto; min-width: 80px; }
.toolbar-divider {
    height: 16px;
    border-left: 1px solid var(--border);
    margin-inline: 1px;
}
.toolbar-button {
    font-size: 12px;
    min-height: 28px;
    padding: 3px 8px;
    gap: 4px;
    border: 1px solid var(--border);
    background: var(--surface-soft);
}
.toolbar-button > .bi { font-size: 14px; }
.log-actions {
    display: flex;
    gap: 3px;
    margin-left: auto;
}
.log-actions > .icon-button {
    width: 28px;
    min-width: 28px;
    height: 28px;
    min-height: 28px;
    font-size: 13px;
    border: 1px solid var(--border);
    background: var(--surface-soft);
}
.log-actions > .icon-button:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.log-display-options {
    flex: 0 0 auto;
    min-height: 34px;
    display: flex;
    align-items: center;
    gap: 8px 12px;
    padding: 4px 12px;
    background: var(--surface-soft);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.inline-field {
    display: flex;
    align-items: center;
    gap: 6px;
}
.inline-field > label {
    white-space: nowrap;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}
.log-display-options .compact-select {
    min-height: 25px;
    padding: 2px 20px 2px 6px;
    border-color: var(--border-strong);
    background-color: var(--surface);
}
.auto-scroll-button {
    margin-left: auto;
    font-size: 12px;
    color: var(--accent);
    padding: 2px 8px;
    min-height: 25px;
}

.terminal-body {
    position: relative;
    min-height: 0;
    flex: 1;
    background-color: var(--terminal-bg);
}
#serial-logs {
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: auto;
    padding: 10px 14px;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.6;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: normal; /* Device output wraps like a terminal, not like UI prose. */
}
#serial-logs.no-wrap, #serial-logs.no-wrap .log-body, #serial-logs.no-wrap .log-text, #serial-logs.no-wrap .log-hex {
    white-space: pre;
    overflow-wrap: normal;
}
#serial-logs.is-paused {
    box-shadow: inset 0 2px 0 var(--warning);
}
.log-entry {
    display: grid;
    grid-template-columns: 88px 42px minmax(0, 1fr);
    gap: 8px;
    align-items: start;
    padding: 3px 0;
    border-bottom: 1px solid var(--terminal-grid);
    min-height: 24px;
}
.log-entry:last-child { border-bottom: 0; }
.log-time {
    color: var(--subtle);
    font-size: 12px;
    padding-top: 1px;
    font-variant-numeric: tabular-nums;
    user-select: none;
}
.log-direction {
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    border-radius: 3px;
    text-align: center;
    padding: 1px 4px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    line-height: 1.35;
    user-select: none;
}
.log-entry[data-direction="rx"] .log-direction {
    color: var(--success);
    background: var(--success-soft);
    border-color: color-mix(in srgb, var(--success) 25%, transparent);
}
.log-entry[data-direction="tx"] .log-direction {
    color: var(--tx);
    background: var(--tx-soft);
    border-color: color-mix(in srgb, var(--tx) 25%, transparent);
}
.log-entry[data-direction="system"] .log-direction {
    color: var(--muted);
    background: var(--surface-soft);
    border-color: var(--border);
}
.log-entry[data-direction="system"] .log-body {
    color: var(--muted);
    font-family: var(--font-ui);
    font-size: 12px;
}
.log-body {
    min-width: 0;
    color: inherit;
    white-space: inherit;
    overflow-wrap: inherit;
}
.log-body pre {
    color: inherit;
    font: inherit;
    margin: 0;
    white-space: inherit;
    overflow-wrap: inherit;
}
.log-hex {
    color: var(--muted);
    font-size: 12px;
    letter-spacing: .3px;
}
.log-text { color: inherit; }
/* ANSI SGR spans are classed by the parser; colors come from the theme tokens. */
.ansi-0 { color: var(--ansi-black); }
.ansi-1 { color: var(--ansi-red); }
.ansi-2 { color: var(--ansi-green); }
.ansi-3 { color: var(--ansi-yellow); }
.ansi-4 { color: var(--ansi-blue); }
.ansi-5 { color: var(--ansi-magenta); }
.ansi-6 { color: var(--ansi-cyan); }
.ansi-7 { color: var(--ansi-white); }
.ansi-bold { font-weight: 700; }

.empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px 16px;
    pointer-events: none;
}
.empty-state h3 {
    font-size: 14px;
    letter-spacing: -.2px;
    font-weight: 600;
    color: var(--text);
}
.empty-state > p {
    font-size: 12.5px;
    color: var(--muted);
    line-height: 1.6;
    margin-top: 4px;
}

.log-statusbar {
    flex: 0 0 auto;
    min-height: 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 14px;
    border-top: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--muted);
    background: var(--surface-soft);
    flex-wrap: wrap;
    gap: 6px 12px;
}
.traffic-stats {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
.traffic-stats > span {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}
.traffic-stats > span:first-child > .bi { color: var(--success); }
.traffic-stats > span:nth-child(2) > .bi { color: var(--tx); }
.traffic-stats b {
    font-weight: 600;
    color: var(--text);
}
.log-count-label { font-family: var(--font-ui); }
.session-clock {
    display: flex;
    gap: 5px;
    align-items: center;
    font-variant-numeric: tabular-nums;
    margin-left: auto;
}

/* Data Composer (Send Area) */
.composer {
    flex: 0 0 auto;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 10px 14px 12px;
}
.composer-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    flex-wrap: wrap;
    gap: 6px;
}
.composer-heading h3 {
    font-size: 13px;
    font-weight: 650;
    letter-spacing: -.2px;
}
.history-tools {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--muted);
    flex-wrap: wrap;
}
.history-tools > .bi { font-size: 12px; color: var(--subtle); }
.history-tools .compact-select {
    max-width: 210px;
    color: var(--text);
    background-color: var(--surface);
    border: 1px solid var(--border-strong);
    padding: 2px 22px 2px 6px;
    font-size: 12px;
    min-height: 26px;
}
.history-tools .icon-button {
    height: 26px;
    min-height: 26px;
    width: 26px;
    min-width: 26px;
    font-size: 12px;
}

.composer-input-wrap { position: relative; }
#serial-send-content {
    resize: vertical;
    min-height: 64px;
    max-height: 180px;
    padding: 8px 10px 22px;
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.5;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    width: 100%;
}
/* The id selector above outranks Bootstrap's .is-invalid, so the invalid state
   is restated here with the theme's danger color and without the icon. */
#serial-send-content.is-invalid, #serial-send-content.is-invalid:focus {
    border-color: var(--danger);
    background-image: none;
    box-shadow: none;
}
.byte-count {
    position: absolute;
    bottom: 5px;
    right: 24px; /* Clear of the textarea resize grip and scrollbar. */
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
    color: var(--subtle);
    pointer-events: none;
    background: var(--surface);
    padding-left: 4px;
}
.composer-input-wrap:has(.is-invalid) .byte-count {
    color: var(--danger);
    font-weight: 600;
}
.send-options {
    display: flex;
    gap: 8px 14px;
    align-items: center;
    padding: 7px 0 6px;
    flex-wrap: wrap;
}
.send-options .check-label { font-size: 12.5px; }
.line-ending-field .compact-select {
    border-color: var(--border-strong);
    background-color: var(--surface);
    font-size: 12px;
    min-height: 26px;
    padding: 2px 22px 2px 6px;
}
.encoding-note {
    margin-left: auto;
    color: var(--subtle);
    font-size: 12px;
    white-space: nowrap;
}
.send-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px 12px;
    margin-top: 4px;
    flex-wrap: wrap;
}
.repeat-options {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.repeat-options .check-label { font-size: 12.5px; }
.repeat-options .muted {
    font-family: var(--font-mono);
    font-size: 12px;
}
.compact-number {
    width: 72px;
    min-height: 28px;
    padding: 2px 4px 2px 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    background-color: var(--surface);
    border: 1px solid var(--border-strong);
}
.send-button {
    min-width: 120px;
    min-height: 34px;
    padding-inline: 14px;
    font-size: 13px;
    font-weight: 600;
}
.send-button > .bi { font-size: 14px; }
.send-button kbd {
    margin-left: 6px;
    color: inherit;
    background: transparent;
    border: none;
    padding: 0;
    font-size: 12px;
    opacity: 1;
}

/* ==========================================================================
   Right Panel: Tools (Quick Send, Options, Script)
   ========================================================================== */

.tools-panel .sidebar-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.tools-panel .sidebar-content:not(.show) { display: none; }

.tools-heading {
    flex: 0 0 38px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px 0 10px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-soft);
}

.tools-heading .tool-tabs {
    padding: 0;
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: flex-end;
    background: transparent;
    border-bottom: 0;
    height: 100%;
}
.tools-heading .toggle-button {
    flex-shrink: 0;
    margin-left: 4px;
}
.nav-tabs {
    border-bottom: 0;
    gap: 10px;
    flex-wrap: nowrap;
    height: 100%;
}
.nav-tabs .nav-link {
    border: 0;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    border-radius: 0;
    background: transparent;
    padding: 8px 2px 7px;
    margin-bottom: -1px;
    flex-shrink: 0;
}
.nav-tabs .nav-link:hover { color: var(--text); border-color: transparent; }
.nav-tabs .nav-link.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: transparent;
    font-weight: 700;
}

/* Collapsed Tools Panel */
.tools-panel:has(> .sidebar-content:not(.show)) .tool-tabs { display: none; }
.tools-panel:has(> .sidebar-content:not(.show)) .tools-heading { padding: 0 6px; justify-content: center; }

.tab-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 14px;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}
.tab-pane { outline-offset: -2px !important; }
.tab-pane.fade { transition: opacity .12s ease; }

/* ==========================================================================
   FUNSR PRO Speed Settings Tab
   ========================================================================== */

.funsr-label-row,
.funsr-preview-row,
.funsr-reported-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
    flex-wrap: wrap;
    gap: 4px;
}

.funsr-label-row .field-label,
.funsr-preview-row .field-label,
.funsr-reported-row .field-label {
    margin: 0;
}

.funsr-unit-note,
.funsr-preview-mode,
.funsr-reported-note {
    font-size: 12px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.funsr-input-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.funsr-number-input {
    flex: 1;
    min-width: 70px;
    font-family: var(--font-mono);
    font-size: 13.5px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.funsr-step-buttons {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.funsr-step-btn {
    min-width: 44px;
    min-height: 33px;
    font-size: 12.5px;
    font-family: var(--font-mono);
    font-weight: 600;
    padding: 4px 8px;
}

.funsr-range-wrap {
    margin: 10px 0 0;
    display: flex;
    align-items: center;
}

.funsr-range-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 24px;
    background: transparent;
    cursor: pointer;
    margin: 0;
    border-radius: var(--radius-sm);
}

.funsr-range-slider:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.funsr-range-slider::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    background: var(--border-strong);
    border-radius: 3px;
}

.funsr-range-slider::-moz-range-track {
    width: 100%;
    height: 6px;
    background: var(--border-strong);
    border-radius: 3px;
}

.funsr-range-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
    margin-top: -6px;
    cursor: pointer;
    transition: background-color .12s ease;
}

.funsr-range-slider::-webkit-slider-thumb:hover {
    background: var(--accent-hover);
}

.funsr-range-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
    cursor: pointer;
    transition: background-color .12s ease;
}

.funsr-range-slider::-moz-range-thumb:hover {
    background: var(--accent-hover);
}

.funsr-preset-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-top: 8px;
}

.funsr-preset-btn {
    min-height: 30px;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 4px;
}

.funsr-draft-hint {
    margin-top: 8px;
    margin-bottom: 14px;
}

.funsr-preview-box {
    padding: 10px 12px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.funsr-preview-box .funsr-preview-row {
    margin: 0 0 8px;
}

.funsr-preview-box .funsr-command-line {
    margin: 0;
}

.funsr-command-line {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}

.funsr-command-text {
    font-family: var(--font-mono);
    font-size: 13.5px;
    font-weight: 700;
    color: var(--text);
    background: transparent;
    padding: 2px 6px;
    border-radius: 3px;
    letter-spacing: .5px;
}

.funsr-command-desc {
    font-size: 12px;
    color: var(--muted);
}

.funsr-confirm-label {
    display: flex;
    font-size: 12.5px;
    font-weight: 550;
    line-height: 1.4;
    color: var(--text);
    align-items: flex-start;
    gap: 7px;
    margin: 12px 0 10px;
}

.funsr-confirm-label .form-check-input {
    margin-top: 2px;
    flex-shrink: 0;
}

.funsr-apply-btn {
    width: 100%;
    min-height: 36px;
    font-size: 13.5px;
    font-weight: 600;
}

.funsr-status-text {
    font-size: 12px;
    line-height: 1.5;
    color: var(--muted);
    margin: 8px 0 0;
    overflow-wrap: anywhere;
}

.funsr-reported-row {
    margin-top: 2px;
}

.funsr-reported-value {
    display: block;
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    padding: 8px 10px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
}

.funsr-notice {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.funsr-notice p {
    font-size: 12px;
    line-height: 1.55;
    color: var(--muted);
}

.funsr-doc-link {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
}

.funsr-doc-link > .bi {
    font-size: 11px;
}

.quick-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.quick-heading .field-label {
    width: auto;
    margin: 0;
    color: var(--text);
    font-size: 12.5px;
    font-weight: 600;
}
.group-actions { display: flex; gap: 3px; }
.group-actions .icon-button {
    height: 26px;
    min-height: 26px;
    width: 26px;
    min-width: 26px;
    font-size: 12px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
}
.quick-hint {
    font-size: 12px;
    margin-top: 4px;
    margin-bottom: 10px;
}
.quick-list {
    min-height: 40px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* CSS Grid 2-row layout for quick command items */
.quick-item {
    position: relative;
    display: grid;
    grid-template-columns: minmax(80px, 1fr) auto auto auto;
    grid-template-rows: auto auto;
    gap: 5px 6px;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    background: transparent;
}

.quick-item:first-child { padding-top: 2px; }
.quick-item:last-child { border-bottom: none; }

.quick-item .quick-send {
    grid-row: 1;
    grid-column: 1;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    min-height: 28px;
    padding: 3px 8px;
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.35;
    min-width: 80px;
    white-space: normal;
    word-break: break-word;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--text);
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin: 0 !important;
}

.quick-item .quick-send:hover:not(:disabled) {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-color);
    border-color: var(--btn-primary-bg);
}

.quick-item .quick-send:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.quick-item .quick-label {
    grid-row: 1;
    grid-column: 2;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 12px;
    font-weight: 600;
    padding: 0 2px;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    margin: 0;
}

.quick-item .quick-label .form-check-input {
    width: 14px;
    height: 14px;
}

.quick-item .quick-load {
    grid-row: 1;
    grid-column: 3;
    min-width: 34px;
    min-height: 28px;
    font-size: 12px;
    padding: 2px 6px;
    color: var(--muted);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
    margin: 0 !important;
}

.quick-item .quick-load:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.quick-item .quick-remove {
    grid-row: 1;
    grid-column: 4;
    height: 28px;
    min-height: 28px;
    width: 24px;
    min-width: 24px;
    padding: 0;
    color: var(--subtle);
    border: 1px solid transparent;
    background: transparent;
    border-radius: var(--radius-sm);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: grid;
    place-items: center;
    margin: 0 !important;
}

.quick-item .quick-remove:hover {
    color: var(--danger);
    background: var(--danger-soft);
}

.quick-item input[type="text"], .quick-item input:not([type]) {
    grid-row: 2;
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    font-family: var(--font-mono);
    font-size: 12.5px;
    padding: 5px 8px;
    min-height: 30px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    margin: 0 !important;
}

.add-command {
    width: 100%;
    margin-top: 10px;
    min-height: 32px;
    font-size: 12.5px;
    color: var(--text);
    border-style: dashed;
    background: var(--surface-soft);
}

.quick-transfer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.quick-transfer .btn {
    font-size: 12px;
    padding: 4px 10px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
}

.command-tip {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin-top: 12px;
    color: var(--muted);
}

.command-tip > .bi {
    font-size: 14px;
    color: var(--subtle);
    margin-top: 1px;
}

.command-tip > p {
    font-size: 12px;
    line-height: 1.6;
}

.command-tip p > span {
    font-size: 12px;
    color: var(--subtle);
}

.tool-section-title {
    font-size: 13px;
    font-weight: 650;
    margin: 2px 0 10px;
}

.settings-check {
    display: flex;
    margin: 8px 0;
    font-size: 12.5px;
}

#nav-options > .field-label { margin-top: 14px; }

.tool-divider {
    border-top: 1px solid var(--border);
    margin: 16px 0 14px;
}

.settings-actions {
    display: flex;
    gap: 6px;
}

.settings-actions > .btn {
    flex: 1;
    font-size: 12px;
    padding-inline: 6px;
}

.reset-button {
    color: var(--danger);
    font-size: 12px;
    margin: 12px 0 2px;
    padding: 4px 0;
}

.reset-button:hover {
    background: transparent;
    text-decoration: underline;
}

#serial-code-editor {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    min-height: 240px;
    background: var(--surface-soft);
}

#serial-code-editor .CodeMirror {
    font-family: var(--font-mono);
    font-size: 12px;
    height: 270px;
    background-color: var(--surface);
}

#serial-code-editor .CodeMirror-gutters {
    background: var(--surface-soft);
    border-right-color: var(--border);
}

#serial-code-editor .CodeMirror-linenumber { color: var(--subtle); }

.CodeMirror-readonly { opacity: .8; }

.script-actions {
    display: flex;
    gap: 6px;
    justify-content: space-between;
    margin-top: 10px;
}

.script-actions .btn { font-size: 12.5px; }

.script-reference {
    margin-top: 14px;
    font-size: 12px;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    background: var(--surface-soft);
}

.script-reference summary {
    cursor: pointer;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.script-reference summary > .bi {
    font-size: 11px;
    transition: transform .12s ease;
}

.script-reference[open] summary > .bi { transform: rotate(180deg); }

.script-reference p {
    margin-top: 8px;
    line-height: 1.8;
}

.script-reference code {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 1px 4px;
    border-radius: 3px;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.app-footer {
    flex: 0 0 30px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-top: 1px solid var(--border);
    padding: 0 16px;
    color: var(--muted);
    font-size: 12px;
    background: var(--surface);
}

.footer-browser {
    margin-right: auto;
}

.app-footer a {
    color: var(--muted);
}

.app-footer a:hover {
    color: var(--text);
}

.app-footer a > .bi {
    font-size: 11px;
    margin-left: 2px;
}

/* ==========================================================================
   Modals
   ========================================================================== */

.modal-content {
    background-color: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    color: var(--text);
    box-shadow: 0 12px 36px rgba(0, 0, 0, .18);
}

.modal-header, .modal-footer {
    border-color: var(--border);
    padding: 12px 18px;
}

.modal-body {
    padding: 16px 18px;
    line-height: 1.6;
    overflow-wrap: anywhere;
    font-size: 13px;
}

.modal-title {
    font-size: 14.5px !important;
    font-weight: 650;
}

.help-content { font-size: 13px; }

.help-content section + section {
    border-top: 1px solid var(--border);
    margin-top: 14px;
    padding-top: 14px;
}

.help-content h3 {
    font-size: 13.5px;
    font-weight: 650;
    margin-bottom: 6px;
}

.help-content p {
    color: var(--muted);
    line-height: 1.6;
}

.help-content p + p { margin-top: 8px; }

.help-content ol {
    padding-left: 18px;
    line-height: 1.8;
}

.shortcut-list { margin: 8px 0; }

.shortcut-list > div {
    display: flex;
    gap: 16px;
    align-items: center;
    padding: 4px 0;
}

.shortcut-list dt {
    width: 140px;
    flex-shrink: 0;
    font-weight: 500;
}

.shortcut-list dd {
    margin: 0;
    color: var(--muted);
}

.noscript-warning {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: var(--surface);
    display: grid;
    place-content: center;
    padding: 24px;
    font-size: 15px;
    color: var(--text);
}

/* ==========================================================================
   Dark Theme & State Overrides
   ========================================================================== */

[data-theme="dark"] .form-select {
    --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23b5b5b5' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

[data-theme="dark"] .btn-close {
    filter: invert(1) grayscale(1) brightness(1.7);
}

[data-theme="dark"] .CodeMirror {
    color: var(--text);
    background-color: var(--surface);
}

[data-theme="dark"] .CodeMirror-cursor {
    border-left-color: var(--text);
}

[data-theme="dark"] .CodeMirror-activeline-background {
    background: rgba(255, 255, 255, .04);
}

/* The bundled "idea" theme is light-only: every token it leaves black or navy
   needs a dark counterpart, or code such as parameters and operators vanishes. */
[data-theme="dark"] .cm-s-idea span.cm-string,
[data-theme="dark"] .cm-s-idea span.cm-string-2 { color: #7ee787; }
[data-theme="dark"] .cm-s-idea span.cm-keyword,
[data-theme="dark"] .cm-s-idea span.cm-atom,
[data-theme="dark"] .cm-s-idea span.cm-tag { color: #d2a8ff; }
[data-theme="dark"] .cm-s-idea span.cm-def,
[data-theme="dark"] .cm-s-idea span.cm-variable,
[data-theme="dark"] .cm-s-idea span.cm-property,
[data-theme="dark"] .cm-s-idea span.cm-attribute,
[data-theme="dark"] .cm-s-idea span.cm-link { color: #a5d6ff; }
[data-theme="dark"] .cm-s-idea span.cm-variable-2,
[data-theme="dark"] .cm-s-idea span.cm-variable-3,
[data-theme="dark"] .cm-s-idea span.cm-type,
[data-theme="dark"] .cm-s-idea span.cm-operator { color: var(--text); }
[data-theme="dark"] .cm-s-idea span.cm-comment,
[data-theme="dark"] .cm-s-idea span.cm-meta,
[data-theme="dark"] .cm-s-idea span.cm-qualifier,
[data-theme="dark"] .cm-s-idea span.cm-bracket { color: #8b949e; }
[data-theme="dark"] .cm-s-idea span.cm-number { color: #ff9b62; }
[data-theme="dark"] .cm-s-idea span.cm-builtin { color: #ffa657; }
[data-theme="dark"] .cm-s-idea span.cm-error { color: #ff7b72; }
[data-theme="dark"] .cm-s-idea .CodeMirror-matchingbracket {
    outline: 1px solid var(--border-strong);
    color: var(--text) !important;
}
[data-theme="dark"] .CodeMirror-selected,
[data-theme="dark"] .CodeMirror-focused .CodeMirror-selected,
[data-theme="dark"] .CodeMirror-line::selection,
[data-theme="dark"] .CodeMirror-line > span::selection,
[data-theme="dark"] .CodeMirror-line > span > span::selection { background: var(--selection-bg); }

#serial-logs.hide-time .log-entry, #serial-logs.no-time .log-entry {
    grid-template-columns: 42px minmax(0, 1fr);
}

.monitor-state:has([data-state="connected"]) .status-dot,
.port-section:has([data-state="connected"]) .status-dot {
    background: var(--success);
}

.monitor-state:has([data-state="busy"]) .status-dot,
.port-section:has([data-state="busy"]) .status-dot {
    background: var(--accent);
}

.connection-message[data-state="unsupported"] {
    color: var(--warning);
}

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

@media (min-width: 1600px) {
    .connection-panel { width: 260px; }
    .tools-panel { width: 350px; }
    .log-entry { font-size: 12.5px; }
}

@media (max-width: 1200px) {
    .connection-panel { width: 220px; }
    .tools-panel { width: 280px; }
    .nav-tabs { gap: 8px; }
    .nav-tabs .nav-link { font-size: 12px; padding: 8px 1px 7px; }
    .search-field kbd { display: none; }
    .encoding-note { display: none; }
}

@media (max-width: 1050px) {
    .workspace {
        grid-template-columns: auto minmax(0, 1fr);
        overflow-y: auto;
        align-content: start;
    }
    .connection-panel {
        width: 220px;
        grid-column: 1;
        grid-row: 1;
        max-height: 750px;
        border-right: 1px solid var(--border);
        border-bottom: 1px solid var(--border);
    }
    .connection-panel:has(> .sidebar-content:not(.show)) {
        width: 38px;
        min-width: 38px;
    }
    .terminal-workspace {
        grid-column: 2;
        grid-row: 1;
        min-height: 650px;
        border-bottom: 1px solid var(--border);
    }
    .tools-panel {
        grid-column: 1 / -1;
        grid-row: 2;
        width: 100%;
        max-height: 550px;
        border-left: 0;
        border-top: 1px solid var(--border);
    }
    .tools-panel:has(> .sidebar-content:not(.show)) {
        width: 100%;
        height: 38px;
        min-height: 38px;
    }
    .tools-panel:has(> .sidebar-content:not(.show)) .tools-heading {
        justify-content: flex-end;
        padding: 0 10px;
    }
    /* Stacked below the terminal, the panel opens downward: point the chevron
       up to collapse and down to expand instead of sideways. */
    .tools-panel .toggle-button > .bi { transform: rotate(-90deg); }
    .tools-panel .tab-content { min-height: 220px; }
    .quick-list {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }
    .tools-panel .add-command { max-width: 220px; }
    .footer-browser { display: none; }
    .app-footer a { margin-left: auto; }
}

@media (max-height: 750px) and (min-width: 1051px) {
    .app-header { flex-basis: 38px; }
    .workspace-titlebar { flex-basis: 34px; }
    .panel-heading { flex-basis: 34px; }
    .tools-heading { flex-basis: 34px; }
    .log-toolbar { min-height: 34px; }
    #serial-send-content {
        min-height: 52px;
        height: 56px;
    }
    .port-section {
        padding-top: 8px;
        padding-bottom: 8px;
    }
    .field-stack { margin-top: 8px; }
}

@media (max-width: 680px) {
    html { min-width: 0; }
    body {
        min-width: 0;
        overflow: auto;
        height: auto;
        min-height: 100dvh;
    }
    .app-header {
        flex: 0 0 44px;
        gap: 8px;
        padding: 6px 12px;
    }
    .brand-symbol img {
        width: 18px;
        height: 18px;
    }
    .brand-copy h1 { font-size: 13.5px; }
    .header-actions .github-link { display: none; }
    .header-actions .icon-button {
        width: 26px;
        min-width: 26px;
        height: 26px;
        min-height: 26px;
        font-size: 13px;
    }
    .workspace {
        display: flex;
        flex-direction: column;
        overflow: visible;
    }
    .sidebar { flex-shrink: 0; }
    .connection-panel {
        width: 100%;
        max-height: none;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }
    .connection-panel .sidebar-content {
        display: flex;
        flex-direction: column;
        overflow: visible;
    }
    .connection-panel .sidebar-content:not(.show) { display: none; }
    /* Collapsed in the single-column layout it is a full-width bar with its
       title, not a 38px stub in the corner. */
    .connection-panel:has(> .sidebar-content:not(.show)) {
        width: 100%;
        min-width: 0;
    }
    .connection-panel:has(> .sidebar-content:not(.show)) .panel-heading {
        justify-content: space-between;
        padding: 0 10px 0 14px;
    }
    .connection-panel:has(> .sidebar-content:not(.show)) .section-title { display: flex; }
    .connection-panel .toggle-button > .bi { transform: rotate(90deg); }
    .port-section {
        padding: 10px;
        border-bottom: 1px solid var(--border);
        border-right: 0;
    }
    .connection-fields { padding: 10px; }
    .connection-fields > .field-hint { display: none; }
    .terminal-workspace {
        min-height: 540px;
        height: 76dvh;
        flex: 0 0 auto;
        border-bottom: 1px solid var(--border);
    }
    .quick-list {
        display: flex;
        flex-direction: column;
    }
    .tools-panel {
        width: 100%;
        max-height: none;
        border-left: 0;
    }
    .tools-panel .sidebar-content { overflow: visible; }
    .tools-panel .tab-content { overflow: visible; }
    .tools-panel .add-command { max-width: none; }
    .app-footer {
        min-height: 32px;
        flex-wrap: wrap;
        gap: 4px 10px;
        padding: 6px 12px;
        font-size: 12px;
    }
    .modal-dialog { margin: 10px; }
}

@media (max-width: 380px) {
    .app-header { gap: 4px; padding-inline: 10px; }
    .brand { gap: 4px; }
    .brand-symbol { width: 18px; }
    .language-control .language-select { width: 78px; }
}

/* ==========================================================================
   Reduced Motion Accessibility
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}
