/* PACSPad Configurator - Dark Theme */

:root {
    --primary-color: #2196F3;
    --primary-hover: #1976D2;
    --success-color: #2196F3;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --keygroup-bg: #1a3050;
    --keygroup-border: #2a6ab0;
    --bg-color: #1a1a1a;
    --card-bg: #252525;
    --text-color: #ddd;
    --text-muted: #888;
    --border-color: #444;
}

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

body {
    font-family: Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow-x: hidden;
    overflow-y: auto;
}

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

.sidebar {
    height: 100vh;
    width: 256px;
    position: fixed;
    top: 0;
    left: 0;
    background-color: #2d2d2d;
    z-index: 1000;
    padding-top: 0;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0,0,0,0.5);
    overflow-y: auto;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: #555 transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: #777; }

/* Sidebar sections */
.sidebar-section { padding: 0 12px; border-top: 1px solid #3a3a3a; }
.sidebar-section:first-child { border-top: none; }

.sidebar-section-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 0; cursor: pointer; color: #aaa;
    font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
    font-weight: 600; user-select: none;
}
.sidebar-section-header:hover { color: #fff; }
.sidebar-section-header .chevron { transition: transform 0.2s; }
.sidebar-section.collapsed .chevron { transform: rotate(-90deg); }

.sidebar-section-body {
    overflow: hidden; padding-bottom: 10px;
    max-height: 500px; transition: max-height 0.2s ease, padding 0.2s;
}
.sidebar-section.collapsed .sidebar-section-body {
    max-height: 0; padding-bottom: 0;
}

/* Connection section */
#section-connection {
    border-bottom: 2px solid #444;
}
#section-connection.collapsed .sidebar-section-body {
    padding-bottom: 0;
}
.connect-btn {
    width: 100%;
    padding: 8px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
}
.connect-btn:hover { background-color: var(--primary-hover); }

/* Sidebar profile dropdown */
.sidebar-profile-select {
    width: 100%; padding: 6px 8px; border-radius: 4px;
    background: #3a3a3a; color: white; border: 1px solid #555;
    font-size: 13px; margin-bottom: 8px; cursor: pointer;
}
.sidebar-profile-select option {
    background: #3a3a3a;
    color: white;
}
.sidebar-profile-select option:disabled {
    color: #666;
    font-style: italic;
}

/* Sidebar icon buttons */
.sidebar-icon-row { display: flex; gap: 4px; }
.sidebar-icon-grid { display: flex; flex-wrap: wrap; gap: 4px; }
.sidebar-icon-btn {
    width: 28px; height: 28px; border: none; border-radius: 4px;
    background: #444; color: white; cursor: pointer;
    font-size: 14px; display: flex; align-items: center; justify-content: center;
    padding: 0; flex-shrink: 0;
}
.sidebar-icon-btn:hover { background: #555; }
.sidebar-icon-btn.danger { background: var(--danger-color); }
.sidebar-icon-btn.danger:hover { background: #c82333; }

/* Sidebar tap dance stepper */
.sidebar-timeout { display: flex; align-items: center; gap: 4px; }
.sidebar-timeout-btn {
    width: 28px; height: 28px; border: none; border-radius: 4px;
    background: var(--primary-color); color: white; cursor: pointer;
    font-size: 16px; display: flex; align-items: center; justify-content: center;
}
.sidebar-timeout-btn:hover { background: var(--primary-hover); }
.sidebar-timeout-label { color: #aaa; font-size: 12px; margin-bottom: 4px; }
.sidebar-timeout-value { color: white; font-weight: bold; font-size: 14px; flex: 1; text-align: center; }

body.disconnected .sidebar-timeout-btn { background: #444; cursor: not-allowed; pointer-events: none; }
body.disconnected .sidebar-timeout-value { color: #555; }

/* Profile mode buttons (per-profile mode assignment) */
.profile-mode-buttons { display: flex; gap: 4px; margin-bottom: 4px; }
.profile-mode-btn {
    flex: 1; padding: 5px 0; border-radius: 4px; text-align: center;
    font-size: 11px; cursor: pointer; user-select: none;
    background: #444; color: #888; border: 1px solid #555;
}
.profile-mode-btn:hover { background: #555; color: white; }
.profile-mode-btn.active { background: var(--primary-color); color: white; border-color: var(--primary-color); }
.profile-mode-btn.active:hover { background: var(--primary-hover); }

/* Status section rows */
.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
}

.status-label {
    font-size: 12px;
    color: #999;
}

.status-value {
    font-size: 12px;
    font-weight: 600;
    color: white;
}

/* Reboot banner (deferred mode change) */
.reboot-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: rgba(255, 193, 7, 0.15);
    border: 1px solid rgba(255, 193, 7, 0.35);
    border-radius: 4px;
    margin-bottom: 4px;
}

.reboot-banner-text {
    flex: 1;
    font-size: 11px;
    color: var(--warning-color);
}

.reboot-banner-btn {
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    border: none;
    border-radius: 3px;
    background: var(--warning-color);
    color: #333;
    cursor: pointer;
    white-space: nowrap;
}

.reboot-banner-btn:hover {
    background: #e6ac00;
}

/* Sidebar device section */
.sidebar-fw-version { color: #aaa; font-size: 12px; margin-bottom: 8px; }
.sidebar-fw-version span { color: white; }
.fw-version-current { color: #4caf50 !important; }
.fw-version-outdated { color: #f44336 !important; }

.sidebar-version-select {
    width: 100%; padding: 4px 6px; border-radius: 4px;
    background: #3a3a3a; color: #888; border: 1px solid #555;
    font-size: 11px; cursor: pointer; margin-bottom: 6px;
}
.sidebar-version-select:disabled { cursor: not-allowed; color: #555; }
.sidebar-version-select option { background: #3a3a3a; color: white; }

.sidebar-device-btn {
    width: 100%; padding: 6px; border: none; border-radius: 4px;
    background: var(--primary-color); color: white; cursor: pointer;
    font-size: 12px; margin-bottom: 6px; text-align: center;
}
.sidebar-device-btn:hover { background: var(--primary-hover); }
.sidebar-device-btn:disabled { background: #444; cursor: not-allowed; color: #666; }
.sidebar-device-btn.danger { background: var(--danger-color); }
.sidebar-device-btn.danger:hover { background: #c82333; }

.sidebar-flash-progress { margin-bottom: 6px; }
.sidebar-flash-progress progress { width: 100%; height: 16px; }
.sidebar-flash-progress span { color: #aaa; font-size: 11px; }

/* Sidebar footer (User Manual link) */
.sidebar-footer {
    margin-top: auto;
    padding: 12px;
    border-top: 1px solid #3a3a3a;
}
.sidebar-manual-link {
    display: block;
    text-align: center;
    padding: 7px 0;
    color: #aaa;
    font-size: 12px;
    text-decoration: none;
    border-radius: 4px;
}
.sidebar-manual-link:hover { color: #fff; background: #3a3a3a; }

/* Sidebar tooltip */
.sidebar-tooltip {
    position: fixed;
    background: #111;
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10001;
    transform: translate(-50%, -100%);
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    display: none;
}

/* ================================================================
   Disconnected State
   ================================================================ */

body.disconnected .content {
    opacity: 0.25;
    pointer-events: none;
    filter: grayscale(40%);
}

body.disconnected .sidebar-section:not(#section-connection):not(#section-legacy) {
    opacity: 0.4;
    pointer-events: none;
}

body.disconnected .sidebar-section:not(#section-connection):not(#section-legacy) .sidebar-section-body {
    max-height: 0 !important;
    padding-bottom: 0 !important;
}

/* Legacy section: only visible when disconnected */
body.connected #section-legacy { display: none; }

/* ================================================================
   No Profiles State
   ================================================================ */

body.no-profiles .content {
    opacity: 0.15;
    pointer-events: none;
    filter: grayscale(60%);
}

body.no-profiles #section-profiles .sidebar-profile-select,
body.no-profiles #section-profiles .sidebar-icon-btn:not(.no-profile-ok),
body.no-profiles #section-profiles .profile-mode-buttons {
    opacity: 0.3;
    pointer-events: none;
}

body.disconnected .sidebar-section:not(#section-connection):not(#section-legacy) .chevron {
    transform: rotate(-90deg);
}

/* ================================================================
   Menu button (hidden)
   ================================================================ */

.menu-btn {
    display: none;
}

/* ================================================================
   Content
   ================================================================ */

.content {
    margin-left: 256px;
    overflow: auto;
    transition: opacity 0.3s, filter 0.3s;
}

/* Program page */
.program-content {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 20px;
    max-width: 1600px;
    margin: 0 auto;
    padding-top: 20px;
    width: fit-content;
}

.top-containers-wrapper {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: stretch;
    width: 100%;
    flex-wrap: wrap;
}

/* ================================================================
   Layer Tabs
   ================================================================ */

.keypad-wrapper {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    background-color: var(--card-bg);
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
    width: 400px;
    min-height: 440px;
}

.layer-tabs {
    display: flex;
    gap: 4px;
    padding: 12px 20px 0;
}

.layer-tab {
    flex: 1;
    padding: 6px 0;
    font-size: 13px;
    font-weight: 500;
    background-color: #333;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    position: relative;
}

.layer-tab:hover { background-color: #3a3a3a; color: var(--text-color); }
.layer-tab.active { background-color: var(--card-bg); color: var(--text-color); border-bottom-color: var(--card-bg); }

.layer-tab .layer-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--primary-color);
    margin-left: 4px;
    vertical-align: middle;
}

.layer-tab .layer-dot.hidden { display: none; }

/* Transparent key style on non-base layers */
.key.transparent {
    opacity: 0.4;
}

/* ================================================================
   Keypad
   ================================================================ */

.keypad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
    padding: 20px;
    width: 400px;
    height: 400px;
}

.key {
    width: 100%;
    height: 100%;
    font-size: 18px;
    border: none;
    background-color: #3a3a3a;
    color: var(--text-color);
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
    user-select: none;
    position: relative;
    padding: 0;
    overflow: hidden;
}

/* Key number — centered by default, top-left corner when has-config */
.key-number {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.15s;
}

.key.has-config .key-number {
    top: 2px; left: 4px; right: auto; bottom: auto;
    font-size: 10px;
    color: #888;
    align-items: flex-start;
    justify-content: flex-start;
}

.key.active.has-config .key-number { color: rgba(255,255,255,0.6); }

/* Preview container — hidden by default, shown when has-config */
.key-preview {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    padding: 14px 4px 4px;
    gap: 1px;
}

.key.has-config .key-preview { display: flex; }

.key-behavior-badge {
    font-size: 11px;
    font-weight: 700;
    color: white;
    line-height: 1;
}

.key-summary {
    font-size: 10px;
    color: #aaa;
    line-height: 1;
    max-width: 100%;
    text-align: center;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    flex: 1;
    min-height: 0;
}

.key-summary-line {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.key.active .key-summary { color: rgba(255,255,255,0.85); }

/* Behavior color tints */
.key.behavior-click { background-color: #2a5a8a; }
.key.behavior-click:hover { background-color: #336a9a; }
.key.behavior-hold { background-color: #2a7a3a; }
.key.behavior-hold:hover { background-color: #338a44; }
.key.behavior-latch { background-color: #8a7a1a; }
.key.behavior-latch:hover { background-color: #9a8a24; }
.key.behavior-release { background-color: #5a5a5a; }
.key.behavior-release:hover { background-color: #6a6a6a; }
.key.behavior-toggle { background-color: #b05020; }
.key.behavior-toggle:hover { background-color: #c0602a; }
.key.behavior-cycle { background-color: #6a3a8a; }
.key.behavior-cycle:hover { background-color: #7a4a9a; }
.key.behavior-tapdance { background-color: #8a2a5a; }
.key.behavior-tapdance:hover { background-color: #9a3a6a; }

/* Release indicator badge on keypad buttons */
.key-release-badge {
    position: absolute;
    top: 2px;
    right: 3px;
    font-size: 8px;
    font-weight: 700;
    color: var(--warning-color);
    line-height: 1;
    z-index: 1;
    display: none;
}
.key.has-custom-release .key-release-badge { display: block; }

/* Active key overrides behavior color */
.key.active, .key.active:hover { background-color: var(--primary-color); color: white; }

/* Drag-and-drop states for keypad buttons */
.key.dragging { opacity: 0.5; }
.key.drag-over { outline: 2px solid var(--primary-color); outline-offset: -2px; transform: scale(1.05); }

/* Drag-and-drop states for layer tabs */
.layer-tab.dragging { opacity: 0.5; }
.layer-tab.drag-over { outline: 2px solid var(--primary-color); outline-offset: -2px; transform: scale(1.05); }

/* Floating drag tooltip */
#dragTooltip {
    position: fixed;
    display: none;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    z-index: 9999;
    white-space: nowrap;
}

/* Dim unconfigured buttons */
.key:not(.has-config) { opacity: 0.6; }
.key:not(.has-config):hover { opacity: 0.85; }
.key:not(.has-config).active { opacity: 1; }

/* ================================================================
   Config Panel
   ================================================================ */

#configPanel {
    position: relative;
    background-color: var(--card-bg);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
    width: 400px;
    min-height: 440px;
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    color: var(--text-color);
}

#configPanel > div { width: 100%; }
#configPanel h2 { margin: 0; padding: 0; font-size: 24px; color: var(--text-color); }
#configPanel h3 { margin: 0; padding: 0; margin-right: 10px; display: inline; color: var(--text-color); }

#configContent {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    flex-grow: 1;
}

#behaviorConfig {
    display: none;
    flex-direction: column;
    width: 100%;
    flex: 1;
}

#behaviorSelect {
    display: inline;
    background: #333;
    color: var(--text-color);
    border: 1px solid #555;
    border-radius: 4px;
    padding: 4px 8px;
}
#behaviorSelect option {
    background: #333;
    color: var(--text-color);
}

#keyList {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 5px;
    min-height: 100px;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow-y: auto;
    flex: 1;
    margin: 10px 0;
    background: #1e1e1e;
}

.key-item {
    background-color: #3a3a3a;
    border: 1px solid #555;
    padding: 2px 5px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    cursor: move;
    user-select: none;
    color: var(--text-color);
}

.key-item.dragging { background-color: #4a4a4a; }
.key-item.drag-over { border-top: 2px solid var(--primary-color); }

.key-group-item {
    background-color: var(--keygroup-bg);
    border: 1px solid var(--keygroup-border);
}

.remove-key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    min-height: 22px;
    margin-left: 5px;
    cursor: pointer;
    color: #ff6b6b;
    font-size: 16px;
    font-weight: bold;
    border-radius: 50%;
    transition: background-color 0.15s;
}
.remove-key:hover {
    background-color: rgba(255, 107, 107, 0.2);
}

/* Super Macro compact summary (in key list) */
.super-macro-item {
    background-color: #2a1a3a !important;
    border: 1px solid #8a5acc !important;
    font-size: 11px !important;
    padding: 1px 4px !important;
    line-height: 1.3;
}
.sm-chord { color: #bb86fc; }
.sm-delay { color: #ffc107; }
.sm-text { color: #80cbc4; }
.sm-sep { color: #555; font-size: 10px; margin: 0 1px; }

/* Super Macro floating panel (non-modal, centered in content area) */

#configPanel button {
    margin-top: 10px;
    padding: 10px;
    font-size: 16px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

#configPanel button:hover { background-color: var(--primary-hover); }

.button-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 10px;
    padding: 2px;
}

.button-grid .grid-button {
    margin-top: 0 !important;
}

.grid-button {
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: var(--primary-color);
    color: white;
    min-height: 40px;
    width: 100%;
}

.grid-button:hover { opacity: 0.9; }
.grid-button.danger { background-color: var(--danger-color) !important; }
.grid-button.full-width { grid-column: 1 / -1; width: 100%; }
#releaseButtonContainer { margin-top: 10px; padding: 0 2px; }

/* Release behavior alert banner */
.release-alert {
    display: none;
    margin: 8px 0;
    padding: 8px 10px;
    background: rgba(255, 193, 7, 0.12);
    border: 1px solid rgba(255, 193, 7, 0.35);
    border-radius: 4px;
    font-size: 12px;
    color: var(--warning-color);
    cursor: pointer;
}
.release-alert:hover { background: rgba(255, 193, 7, 0.2); }

#toggleGroup { background-color: var(--primary-color); }
#clearKeyConfig { background-color: var(--danger-color) !important; }

.config-message {
    margin-top: 10px;
    padding: 8px;
    font-weight: bold;
    text-align: center;
    border-radius: 5px;
}

.config-message.success {
    background-color: var(--keygroup-bg);
    color: var(--primary-color);
    border: 1px solid var(--keygroup-border);
}

.config-message.error {
    background-color: #3a1a1a;
    color: #ff6b6b;
    border: 1px solid #5a2a2a;
}

/* ================================================================
   Dictation Container
   ================================================================ */

.dictation-container {
    background-color: var(--card-bg);
    padding: 12px;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    width: 130px;
    max-width: calc(100vw - 40px);
    flex: 0 0 auto;
}

.dictate-label {
    font-size: 14px;
    font-weight: bold;
    padding: 4px 0;
    text-align: center;
    color: var(--text-color);
}

.dictate-panel {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
}

.dictate-button {
    width: auto;
    min-width: 60px;
    padding: 6px 8px;
    font-size: 12px;
    background-color: #3a3a3a;
    border: 1px solid #555;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
    color: var(--primary-color);
}

.dictate-button:hover { background-color: #484848; }

/* Layer control buttons (above numpad) */
.layer-controls-above-numpad {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 4px;
    justify-content: flex-end;
}

.layer-controls-separator {
    height: 1px;
    background-color: #444;
    width: 100%;
    margin: -2px 0;
}

.layer-control-group {
    display: flex;
    gap: 4px;
    align-items: center;
}

.layer-control-button {
    flex: 1;
    height: 16px;
    padding: 0;
    font-size: 9px;
    background-color: #2a3a2a;
    color: #88cc88;
    border: 1px solid #446644;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.2s;
    line-height: 16px;
    text-align: center;
}

.layer-control-button:hover { background-color: #3a4a3a; }

/* ================================================================
   Virtual Keyboard
   ================================================================ */

.keyboard-container {
    background-color: var(--card-bg);
    padding: 4.5px;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 950px;
    max-width: calc(100vw - 40px);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.keyboard-container::-webkit-scrollbar {
    -webkit-appearance: none;
    height: 12px;
    background-color: #1e1e1e;
    border-radius: 6px;
}

.keyboard-container::-webkit-scrollbar-thumb {
    background-color: #555;
    border-radius: 6px;
    border: 2px solid #1e1e1e;
}

.keyboard-subcontainer {
    display: flex;
    gap: 1px;
    align-items: flex-end;
}

.main-keyboard-area {
    background-color: var(--card-bg);
    border-radius: 8px;
    padding: 7px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.keyboard-separator, .nav-mouse-separator, .mode-separator {
    height: 1px;
    background-color: #444;
    width: 100%;
    margin: -2px 0;
}

.function-keys, .main-keys {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.function-keys .keyboard-row div[style*="width: 20px"] {
    width: 21.9px !important;
}

.keyboard-row {
    display: flex;
    justify-content: flex-start;
    gap: 4px;
    width: 100%;
}

.virtual-key {
    height: 37.5px;
    width: 37.5px;
    min-width: 37.5px;
    padding: 0;
    font-size: 11px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #333;
    border: 1px solid #4a4a4a;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    color: var(--text-color);
}

.virtual-key:hover { background-color: #484848; }

/* Section-specific key colors */
.main-keys .virtual-key { background-color: #333; border-color: #4a4a4a; }
.main-keys .virtual-key:hover { background-color: #434343; }

.function-keys .keyboard-row:first-child .virtual-key { background-color: #3a3420; border-color: #5a4d30; }
.function-keys .keyboard-row:first-child .virtual-key:hover { background-color: #4a4228; }
.function-keys .keyboard-row:nth-child(2) .virtual-key { background-color: #333; border-color: #4a4a4a; }
.function-keys .keyboard-row:nth-child(2) .virtual-key:hover { background-color: #434343; }

.mouse-buttons .virtual-key { background-color: #253540; border-color: #3a5060; }
.mouse-buttons .virtual-key:hover { background-color: #304550; }

.nav-keys-top .virtual-key, .arrow-keys .virtual-key { background-color: #353535; border-color: #4a4a4a; }
.nav-keys-top .virtual-key:hover, .arrow-keys .virtual-key:hover { background-color: #454545; }

.numpad .virtual-key { background-color: #2c3048; border-color: #404868; }
.numpad .virtual-key:hover { background-color: #3a3a58; }

/* Key widths */
.key-1u { width: 37.5px; min-width: 37.5px; }
.key-1-25u { width: 47.4px; min-width: 47.4px; }
.key-1-5u { width: 56.25px; min-width: 56.25px; }
.key-1-75u { width: 71.2px; min-width: 71.2px; }
.key-2u { width: 75px; min-width: 75px; }
.key-2-25u { width: 82.8px; min-width: 82.8px; }
.key-2-75u { width: 97.75px; min-width: 97.75px; }
.key-6-25u { width: 237px; min-width: 237px; }

/* Nav + Mouse combined */
.nav-mouse-wrapper { display: flex; flex-direction: column; gap: 6px; }
.nav-mouse-combined {
    background-color: var(--card-bg);
    border-radius: 8px;
    padding: 7px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mouse-buttons-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.mouse-buttons {
    display: grid;
    grid-template-columns: repeat(3, 37.5px);
    grid-template-rows: repeat(2, 37.5px);
    gap: 4px;
    justify-content: center;
}

.mouse-buttons .virtual-key { font-size: 10px; text-align: center; }

.nav-keys-top {
    display: grid;
    grid-template-columns: repeat(3, 37.5px);
    gap: 4px;
}

.arrow-keys {
    display: grid;
    grid-template-columns: repeat(3, 37.5px);
    gap: 4px;
    grid-template-areas:
        ". up ."
        "left down right";
}

.arrow-keys .virtual-key[data-code="ArrowUp"] { grid-area: up; }
.arrow-keys .virtual-key[data-code="ArrowLeft"] { grid-area: left; }
.arrow-keys .virtual-key[data-code="ArrowDown"] { grid-area: down; }
.arrow-keys .virtual-key[data-code="ArrowRight"] { grid-area: right; }

/* Numpad */
.numpad-area {
    background-color: var(--card-bg);
    border-radius: 8px;
    padding: 7px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.numpad {
    display: grid;
    grid-template-columns: repeat(4, 37.5px);
    gap: 4px;
    grid-template-areas:
        "num div mult minus"
        "seven eight nine plus"
        "four five six plus"
        "one two three enter"
        "zero zero dot enter";
    height: fit-content;
}

.numpad .virtual-key[data-code="NumpadAdd"] { grid-area: plus; height: 79px; }
.numpad .virtual-key[data-code="NumpadEnter"] { grid-area: enter; height: 79px; }
.numpad .virtual-key[data-code="Numpad0"] { grid-area: zero; width: 79px; }

/* ================================================================
   Dialog
   ================================================================ */

.dialog {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.dialog-content {
    background-color: #2d2d2d;
    color: var(--text-color);
    padding: 20px;
    border-radius: 5px;
    min-width: 300px;
    max-width: 500px;
    width: 90%;
}

.dialog-content h3 {
    color: var(--text-color);
    margin-bottom: 10px;
}

.dialog-content label {
    color: var(--text-color);
    cursor: pointer;
}

.dialog-content button {
    padding: 8px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}
.dialog-content button:hover { background: var(--primary-hover); }

.dialog-buttons {
    margin-top: 10px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

#macroText {
    width: 100%;
    margin: 10px 0;
    padding: 8px;
    border: 1px solid #555;
    border-radius: 4px;
    font-family: inherit;
    resize: vertical;
    background: #333;
    color: var(--text-color);
}

/* ================================================================
   Toast Messages
   ================================================================ */

.message-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}

.message {
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 500;
    max-width: 400px;
    text-align: center;
    animation: slideUp 0.3s ease-out;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    pointer-events: auto;
}

.message.success {
    background-color: var(--keygroup-bg);
    color: var(--primary-color);
    border: 1px solid var(--keygroup-border);
}

.message.error {
    background-color: #3a1a1a;
    color: #ff6b6b;
    border: 1px solid #5a2a2a;
}

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ================================================================
   Custom Dialogs
   ================================================================ */

.custom-dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.custom-dialog-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
}

.custom-dialog-content {
    position: relative;
    background: #2d2d2d;
    border-radius: 8px;
    padding: 20px;
    min-width: 300px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    animation: dialogSlideIn 0.2s ease-out;
}

@keyframes dialogSlideIn {
    from { opacity: 0; transform: scale(0.9) translateY(-20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.custom-dialog-content h3 {
    margin: 0 0 15px 0;
    color: var(--text-color);
    font-size: 18px;
}

.custom-dialog-content p {
    margin: 0 0 15px 0;
    color: #999;
    line-height: 1.4;
}

.custom-dialog-input {
    width: 100%;
    padding: 10px;
    border: 2px solid #555;
    border-radius: 4px;
    font-size: 14px;
    margin-bottom: 15px;
    box-sizing: border-box;
    background: #333;
    color: var(--text-color);
}

.custom-dialog-input:focus {
    border-color: var(--primary-color);
    outline: none;
}

.custom-dialog-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.custom-dialog-button {
    padding: 8px 16px;
    border: 1px solid #555;
    border-radius: 4px;
    background: #3a3a3a;
    color: var(--text-color);
    cursor: pointer;
    font-size: 14px;
    min-width: 70px;
}

.custom-dialog-button:hover { background: #4a4a4a; }

.custom-dialog-button.primary {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.custom-dialog-button.primary:hover { background: var(--primary-hover); }

.custom-dialog-button.warning {
    background: var(--warning-color);
    color: #333;
    border-color: var(--warning-color);
}

.custom-dialog-button.warning:hover { background: #e6ac00; }

/* ================================================================
   New Profile / Template Dialog
   ================================================================ */

.template-section {
    margin-bottom: 15px;
}

.template-section-header {
    color: #999;
    font-size: 13px;
    margin-bottom: 8px;
}

.template-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #444;
    border-radius: 4px;
    background: #252525;
}

.template-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #333;
    transition: background 0.15s;
}

.template-item:last-child { border-bottom: none; }

.template-item:hover { background: #353535; }

.template-item-info {
    flex: 1;
    min-width: 0;
}

.template-item-name {
    color: var(--text-color);
    font-size: 14px;
    font-weight: 500;
}

.template-item-desc {
    color: #777;
    font-size: 11px;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.template-item-arrow {
    color: #555;
    font-size: 16px;
    margin-left: 8px;
    flex-shrink: 0;
}

.template-item:hover .template-item-arrow { color: var(--primary-color); }

.template-loading, .template-error {
    padding: 12px;
    color: #777;
    font-size: 13px;
    text-align: center;
}

.template-error { color: #cc6666; }

/* ================================================================
   Copy Layer Dialog
   ================================================================ */

.copy-layer-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.copy-layer-row label {
    width: 40px;
    flex-shrink: 0;
    color: #999;
    font-size: 13px;
}

.copy-layer-select {
    flex: 1;
    padding: 8px;
    border: 2px solid #555;
    border-radius: 4px;
    font-size: 13px;
    background: #333;
    color: var(--text-color);
    appearance: auto;
}

.copy-layer-select:focus {
    border-color: var(--primary-color);
    outline: none;
}

/* ================================================================
   PIN Setup Dialog
   ================================================================ */

.pin-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 8px;
    width: 260px;
    height: 260px;
    margin: 12px auto;
}

.pin-grid-btn {
    width: 100%;
    height: 100%;
    font-size: 16px;
    font-weight: 600;
    border: 2px solid #555;
    background-color: #3a3a3a;
    color: var(--text-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pin-grid-btn:hover { background-color: #484848; border-color: #666; }

.pin-grid-btn.pin-selected {
    background-color: var(--primary-color);
    border-color: var(--primary-hover);
    color: white;
    box-shadow: 0 0 8px rgba(33, 150, 243, 0.4);
}

.pin-grid-btn.pin-selected:hover {
    background-color: var(--primary-hover);
}

.pin-sequence-display {
    text-align: center;
    min-height: 24px;
    font-size: 14px;
    color: #888;
    margin: 4px 0 8px;
    letter-spacing: 2px;
}

/* ================================================================
   PIN Lock Overlay
   ================================================================ */

.pin-lock-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    z-index: 20000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pin-lock-content {
    text-align: center;
    color: var(--text-color);
    max-width: 400px;
    padding: 40px;
}

.pin-lock-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.pin-lock-content h2 {
    font-size: 24px;
    margin-bottom: 12px;
    color: white;
}

.pin-lock-content p {
    color: #999;
    line-height: 1.5;
    margin-bottom: 8px;
}

.pin-lock-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #444;
    border-top-color: var(--primary-color);
    border-radius: 50%;
    margin: 20px auto 12px;
    animation: pinLockSpin 1s linear infinite;
}

@keyframes pinLockSpin {
    to { transform: rotate(360deg); }
}

.pin-lock-waiting {
    font-size: 13px;
    color: #666;
}

/* ================================================================
   Settings Select (Default Key Behavior)
   ================================================================ */

.sidebar-setting-select {
    width: 100%; padding: 6px 8px; border-radius: 4px;
    background: #3a3a3a; color: white; border: 1px solid #555;
    font-size: 13px; cursor: pointer;
}
.sidebar-setting-select option { background: #3a3a3a; color: white; }

/* ================================================================
   Legacy Section
   ================================================================ */

.legacy-description {
    color: #888;
    font-size: 11px;
    margin-bottom: 8px;
    line-height: 1.4;
}

/* Legacy Update Wizard */
.legacy-wizard {
    max-width: 560px !important;
}

.legacy-progress {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
}

.legacy-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #3a3a3a;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    transition: background 0.2s, color 0.2s;
}

.legacy-dot.active { background: var(--primary-color); color: white; }
.legacy-dot.complete { background: #2e7d32; color: white; }

.legacy-step { min-height: 150px; }

.legacy-step-desc {
    color: #999;
    line-height: 1.4;
    margin: 0 0 12px 0;
}

.legacy-hint {
    color: #888;
    font-size: 12px;
    margin-top: 12px;
}

.legacy-instructions { margin: 8px 0; }

.legacy-instruction {
    display: flex;
    gap: 10px;
    margin: 8px 0;
    align-items: flex-start;
    color: #ccc;
    font-size: 13px;
    line-height: 1.4;
}

.legacy-step-num {
    min-width: 24px;
    height: 24px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.legacy-image-area {
    margin: 12px 0;
    text-align: center;
}

.legacy-image-area img {
    max-width: 100%;
    border-radius: 8px;
}

.legacy-device-status {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 12px 0;
}

.legacy-device-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #333;
    border-radius: 4px;
    font-size: 13px;
    color: #ccc;
}

.legacy-status-icon { font-size: 16px; }

.legacy-fw-info {
    margin-top: 12px;
    font-size: 12px;
    font-weight: 500;
}

.legacy-flash-info { margin: 16px 0; }

.legacy-flash-device {
    color: #ccc;
    font-size: 13px;
    margin-bottom: 8px;
}

.legacy-flash-progress { margin: 8px 0; }
.legacy-flash-progress progress { width: 100%; height: 20px; }

.legacy-flash-status {
    color: #aaa;
    font-size: 12px;
    margin-top: 4px;
}

.legacy-complete-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    background: #2e7d32;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: white;
}

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

@media (max-width: 850px) {
    .top-containers-wrapper {
        flex-direction: column;
        align-items: center;
        padding: 0 20px;
    }
    .keypad-wrapper {
        min-height: auto;
    }
    #configPanel {
        width: 100%;
        max-width: 400px;
        min-height: auto;
    }
    .dictation-container {
        width: 100%;
        max-width: 280px;
    }
}

@media (max-width: 600px) {
    .top-containers-wrapper { padding: 0 10px; }
    .keyboard-container { padding: 4.5px; max-width: calc(100vw - 20px); }
    .virtual-key { flex-shrink: 0; }
}

/* ================================================================
   Variables Section
   ================================================================ */

.variables-empty {
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
    padding: 4px 0;
}

.variable-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-radius: 4px;
    margin-bottom: 4px;
    background: #3a3a3a;
    font-size: 12px;
}

.variable-name {
    font-weight: 600;
    color: var(--primary-color);
    min-width: 60px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.variable-value {
    flex: 1;
    color: #aaa;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.variable-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.variable-action-btn {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    border-radius: 3px;
}
.variable-action-btn:hover { color: #fff; background: #555; }
.variable-action-btn.insert { color: var(--primary-color); font-weight: bold; }
.variable-action-btn.insert:hover { color: #fff; background: var(--primary-color); }
.variable-action-btn.danger:hover { color: #ff6b6b; }

.variable-picker-list {
    max-height: 300px;
    overflow-y: auto;
    margin: 12px 0;
}

.variable-picker-item {
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 4px;
    margin-bottom: 4px;
    background: #3a3a3a;
    color: var(--primary-color);
    font-weight: 600;
    font-size: 14px;
}
.variable-picker-item:hover {
    background: #4a4a4a;
}

/* ============================================================================
 * BLE HID Host Styles
 * ============================================================================ */

.ble-results-container {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 4px;
}

.ble-scan-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    background: var(--bg-secondary);
    border-radius: 4px;
    margin-bottom: 2px;
    cursor: pointer;
    font-size: 11px;
}
.ble-scan-item:hover { background: var(--border-color); }

.ble-scan-type {
    font-weight: bold;
    color: var(--accent-color);
    min-width: 36px;
}
.ble-scan-name { flex: 1; }
.ble-scan-rssi { color: #888; font-size: 10px; }
.ble-scan-addr { color: #666; font-size: 9px; font-family: monospace; }

.ble-scanning, .ble-no-results {
    color: #888;
    font-size: 11px;
    padding: 8px 4px;
    text-align: center;
}

.ble-section-label {
    font-size: 10px;
    font-weight: bold;
    color: #888;
    text-transform: uppercase;
    margin: 4px 0 2px 0;
}

.ble-device-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 6px;
    background: var(--bg-secondary);
    border-radius: 4px;
    margin-bottom: 2px;
    font-size: 11px;
}
.ble-device-item.selected { border: 1px solid var(--accent-color); }
.ble-device-item.bonded { opacity: 0.7; }

.ble-device-info { flex: 1; cursor: pointer; }
.ble-device-name { font-weight: bold; display: block; }
.ble-device-meta { color: #888; font-size: 10px; }

.ble-device-actions { display: flex; gap: 2px; }

.ble-btn-sm {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 3px;
    padding: 2px 6px;
    font-size: 10px;
    cursor: pointer;
    line-height: 1;
}
.ble-btn-sm:hover { background: var(--border-color); }
.ble-btn-sm.danger { color: var(--danger-color); }
.ble-btn-sm.danger:hover { background: var(--danger-color); color: white; }
.ble-auto-connect-label {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    color: #888;
    cursor: pointer;
    white-space: nowrap;
}

.ble-capture-container {
    max-height: 150px;
    overflow-y: auto;
}

.ble-capture-hint {
    color: #888;
    font-size: 11px;
    padding: 8px 4px;
    text-align: center;
    font-style: italic;
}

.ble-capture-event {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 6px;
    background: var(--bg-secondary);
    border-radius: 3px;
    margin-bottom: 1px;
    font-size: 10px;
}
.ble-capture-event.active { border-left: 2px solid var(--accent-color); }

.ble-capture-name { flex: 1; font-weight: bold; }
.ble-capture-value { color: var(--accent-color); min-width: 30px; }
.ble-capture-detail { color: #666; font-family: monospace; font-size: 9px; }

.ble-remap-container {
    max-height: 200px;
    overflow-y: auto;
}

.ble-remap-rule {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 6px;
    background: var(--bg-secondary);
    border-radius: 3px;
    margin-bottom: 1px;
    font-size: 10px;
}
.ble-remap-src { font-family: monospace; color: var(--accent-color); }
.ble-remap-arrow { color: #888; }
.ble-remap-dest { flex: 1; }

.ble-passthrough-toggle {
    font-size: 11px;
    margin-bottom: 4px;
}
.ble-passthrough-toggle label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

.ble-desc-summary {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}
.ble-desc-badge {
    background: var(--accent-color);
    color: white;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: bold;
}
.ble-desc-count { color: #888; font-size: 10px; margin-left: auto; }

.ble-desc-fields {
    max-height: 150px;
    overflow-y: auto;
}
.ble-desc-field {
    display: flex;
    gap: 4px;
    padding: 2px 4px;
    font-size: 10px;
    border-bottom: 1px solid var(--bg-secondary);
}
.ble-desc-field-type { color: var(--accent-color); min-width: 50px; font-weight: bold; }
.ble-desc-field-name { flex: 1; }
.ble-desc-field-detail { color: #666; font-family: monospace; font-size: 9px; }

/* ============================================================================
 * BLE Remap Editor (main content panel)
 * ============================================================================ */

.ble-remap-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 20px 0;
}
.ble-remap-back {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-radius: 5px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
}
.ble-remap-back:hover { background: var(--border-color); }
.ble-remap-title {
    flex: 1;
    font-size: 16px;
    font-weight: bold;
    color: var(--text-color);
}
.ble-passthrough-label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    font-size: 12px;
    color: #aaa;
    white-space: nowrap;
}

.ble-scroll-options {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    padding: 4px 20px 0;
}
.ble-scroll-invert-label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    font-size: 12px;
    color: #aaa;
    white-space: nowrap;
}
.ble-scroll-unsupported {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Layer tabs inside the BLE remap editor (reuses .layer-tabs/.layer-tab) */
.ble-layer-tabs {
    padding: 8px 20px 0;
}
.ble-input-fallthrough {
    opacity: 0.45;
    font-style: italic;
}

.ble-input-list {
    flex: 1 1 0;
    /* Cap to the keypad-area footprint so the captured-input list can't grow
       the editor unbounded; overflow scrolls within this fixed height. */
    max-height: 360px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 20px 20px;
}

.ble-input-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: #3a3a3a;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    border: 2px solid transparent;
    transition: all 0.15s;
}
.ble-input-item:hover { background: #4a4a4a; }
.ble-input-item.active {
    border-color: var(--primary-color);
    background: #2a4a6a;
}
.ble-input-item.has-rule {
    background: #2a5a3a;
}
.ble-input-item.has-rule.active {
    background: #2a4a6a;
}
.ble-input-item.captured {
    border-color: #886622;
    background: #3a3520;
}

.ble-input-type {
    font-weight: bold;
    color: var(--primary-color);
    min-width: 40px;
    font-size: 11px;
    text-transform: uppercase;
}
.ble-input-name { flex: 1; }
.ble-input-dest {
    font-size: 11px;
    color: #aaa;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ble-remap-placeholder {
    color: #888;
    text-align: center;
    padding: 40px 20px;
    font-size: 14px;
}

/* Config panel for BLE remap */
#bleRemapConfigPanel {
    padding: 12px;
}
#bleRemapConfigPanel h3 {
    margin: 0 0 4px 0;
    font-size: 16px;
}

.ble-remap-input-title {
    color: var(--primary-color);
}
.ble-remap-input-detail {
    font-size: 11px;
    color: #888;
    font-family: monospace;
    margin-bottom: 12px;
}

.ble-remap-dest-select {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.ble-remap-dest-select label {
    font-weight: bold;
    font-size: 13px;
}
.ble-remap-dest-select select {
    flex: 1;
    padding: 6px;
    background: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
}

.ble-remap-key-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 10px;
    min-height: 50px;
    background: var(--bg-color);
    border-radius: 5px;
    border: 1px solid var(--border-color);
    margin-bottom: 8px;
    align-items: center;
}

.ble-remap-key-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: var(--keygroup-bg);
    border: 1px solid var(--keygroup-border);
    border-radius: 4px;
    font-size: 12px;
}
.ble-remap-key-remove {
    cursor: pointer;
    color: #888;
    font-size: 14px;
    margin-left: 2px;
}
.ble-remap-key-remove:hover { color: var(--danger-color); }

.ble-remap-hint {
    color: #888;
    font-size: 12px;
    font-style: italic;
    padding: 8px 0;
}

.ble-remap-mouse-buttons {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}
.ble-remap-mouse-btn {
    padding: 8px 14px;
    background: #3a3a3a;
    border: 2px solid transparent;
    border-radius: 5px;
    color: var(--text-color);
    cursor: pointer;
    font-size: 13px;
}
.ble-remap-mouse-btn:hover { background: #4a4a4a; }
.ble-remap-mouse-btn.active {
    border-color: var(--primary-color);
    background: #2a4a6a;
}

/* ================================================================
   Disconnected BLE Device Overlay
   ================================================================ */

.program-content.device-disconnected .top-containers-wrapper,
.program-content.device-disconnected .keyboard-container {
    opacity: 0.35;
    pointer-events: none;
    filter: grayscale(0.6);
    transition: opacity 0.2s, filter 0.2s;
}

.ble-disconnected-banner {
    text-align: center;
    padding: 14px 20px;
    background: #2a2a2a;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 14px;
    margin: 0 auto;
    max-width: 500px;
}
.ble-disconnected-banner .ble-disc-name {
    color: var(--text-color);
    font-weight: bold;
}

/* ================================================================
   BLE Input Type Tabs (Mouse / Keyboard / Media Keys)
   ================================================================ */

.ble-input-tabs {
    display: flex;
    gap: 0;
    padding: 0 20px;
}
.ble-input-tab {
    flex: 1;
    padding: 7px 0;
    font-size: 12px;
    font-weight: 500;
    background: #333;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-bottom: none;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
    text-align: center;
    position: relative;
}
.ble-input-tab:first-child { border-radius: 6px 0 0 0; }
.ble-input-tab:last-child { border-radius: 0 6px 0 0; }
.ble-input-tab:only-child { border-radius: 6px 6px 0 0; }
.ble-input-tab + .ble-input-tab { border-left: none; }
.ble-input-tab:hover { background: #3a3a3a; color: var(--text-color); }
.ble-input-tab.active {
    background: var(--card-bg);
    color: var(--text-color);
    border-bottom: 2px solid var(--primary-color);
}
.ble-tab-count {
    display: inline-block;
    font-size: 10px;
    background: #2a5a3a;
    color: #8f8;
    border-radius: 8px;
    padding: 0 5px;
    margin-left: 4px;
    min-width: 16px;
    text-align: center;
    line-height: 16px;
    vertical-align: middle;
}

/* Capture hint at bottom of input list */
.ble-capture-hint {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    padding: 8px 0;
    font-style: italic;
}

/* ===== BLE Speed Priority popup ===== */
.sp-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.sp-modal {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    width: 360px;
    max-width: 90vw;
    padding: 16px;
}
.sp-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 8px;
}
.sp-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}
.sp-close:hover { color: var(--text-color); }
.sp-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
    line-height: 1.4;
}
.sp-scale-top, .sp-scale-bottom {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    padding: 2px 0;
}
.sp-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 4px 0;
}
.sp-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: grab;
    user-select: none;
}
.sp-item.fastest {
    border-color: var(--primary-color);
    box-shadow: inset 3px 0 0 var(--primary-color);
}
.sp-item.dragging { opacity: 0.4; }
.sp-item.drag-over { outline: 2px dashed var(--primary-color); outline-offset: 1px; }
.sp-grip { color: var(--text-muted); cursor: grab; }
.sp-rank {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sp-name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-status { font-size: 11px; color: var(--text-muted); }
.sp-item.connected .sp-status { color: var(--primary-color); }

/* ============================================================================
   Bug-report assistant panel (pacspad-bot.js)
   ============================================================================ */
#pbotPanel {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 32px);
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    display: none;
    flex-direction: column;
    z-index: 2000;
    overflow: hidden;
}
#pbotPanel.open { display: flex; }

.pbot-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #1e1e1e;
    border-bottom: 1px solid var(--border-color);
}
.pbot-title { flex: 1; font-size: 14px; font-weight: bold; }
.pbot-dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}
.pbot-dot.connected { background: var(--primary-color); }
.pbot-headbtn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    border-radius: 4px;
    font-size: 12px;
    padding: 2px 8px;
    cursor: pointer;
}
.pbot-headbtn:hover { color: #fff; border-color: #666; }

.pbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.pbot-msg {
    max-width: 88%;
    padding: 8px 11px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}
.pbot-user {
    align-self: flex-end;
    background: var(--keygroup-bg);
    border: 1px solid var(--keygroup-border);
}
.pbot-assistant {
    align-self: flex-start;
    background: #2e2e2e;
    border: 1px solid #3a3a3a;
}
.pbot-note {
    align-self: center;
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
}
.pbot-note a { color: var(--primary-color); }

.pbot-controls {
    padding: 4px 12px 0 12px;
    display: flex;
    align-items: center;
}
.pbot-consent-label {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

.pbot-inputrow {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
}
.pbot-inputrow textarea {
    flex: 1;
    resize: none;
    background: #1e1e1e;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px;
    font-size: 13px;
    font-family: inherit;
}
.pbot-inputrow textarea:focus { outline: none; border-color: var(--primary-color); }
.pbot-inputrow button {
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0 16px;
    font-size: 13px;
    cursor: pointer;
}
.pbot-inputrow button:hover { background: var(--primary-hover); }
.pbot-inputrow button:disabled { background: #444; cursor: default; }

.pbot-disclaimer {
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
    padding: 0 12px 8px 12px;
}

/* Configuration confirmation card (pbot) */
.pbot-card {
    align-self: stretch;
    background: #20242c;
    border: 1px solid var(--keygroup-border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 12px;
}
.pbot-card.applied { border-color: var(--primary-color); }
.pbot-card.declined { opacity: 0.6; }
.pbot-card-title { font-weight: bold; font-size: 13px; margin-bottom: 6px; }
.pbot-card-row { margin: 6px 0; }
.pbot-card-btn { color: var(--primary-color); font-weight: bold; font-size: 11px; }
.pbot-card-diff {
    font-family: monospace;
    font-size: 11px;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 2px 0 0 8px;
    color: var(--text-color);
}
.pbot-card-note { font-size: 10px; color: var(--text-muted); margin-top: 8px; }
.pbot-card-actions { display: flex; gap: 8px; margin-top: 8px; }
.pbot-card-actions button {
    border: none;
    border-radius: 5px;
    padding: 5px 16px;
    font-size: 12px;
    cursor: pointer;
}
.pbot-apply { background: var(--primary-color); color: #fff; }
.pbot-apply:hover:not(:disabled) { background: var(--primary-hover); }
.pbot-cancel { background: #3a3a3a; color: var(--text-color); }
.pbot-cancel:hover:not(:disabled) { background: #4a4a4a; }
.pbot-card-actions button:disabled { opacity: 0.5; cursor: default; }
