/* ════════════════════════════════════════════════════════════════════════
   Flight Control Alchemy — Admin UI
   Glass-cockpit dark theme per Artwork/fca-design-system-spec.md
   ════════════════════════════════════════════════════════════════════════ */

/* ── Self-hosted fonts ─────────────────────────────────────────────────── */
@font-face {
    font-family: 'Orbitron';
    src: url('assets/fonts/orbitron.woff2') format('woff2');
    font-weight: 400 800;       /* variable-font range */
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Rajdhani';
    src: url('assets/fonts/rajdhani-300.woff2') format('woff2');
    font-weight: 300;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Rajdhani';
    src: url('assets/fonts/rajdhani-400.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Rajdhani';
    src: url('assets/fonts/rajdhani-600.woff2') format('woff2');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

/* ── Design tokens ─────────────────────────────────────────────────────── */
:root {
    /* Backgrounds */
    --bg-base:        #03060e;
    --bg-surface:     #050810;
    --bg-raised:      #080c18;
    --bg-overlay:     #0c1220;

    /* Borders */
    --border-dim:     #0a1a2e;
    --border-mid:     #0f2540;
    --border-bright:  #1a3a5a;

    /* Cyan — structure / data */
    --cyan-bright:    #00ddff;
    --cyan-mid:       #00aaff;
    --cyan-deep:      #0066cc;

    /* Amber — action / alert */
    --amber-bright:   #ffd060;
    --amber-mid:      #ffa030;
    --amber-deep:     #c05800;

    /* Text */
    --text-primary:   #b8e8ff;
    --text-secondary: #5d98c0;   /* ~25% brighter than #4a7a9a */
    --text-muted:     #2a5274;   /* lifted to remain readable on dark bg */

    /* Section labels — amber, per design feedback */
    --text-label:     #ffa030;

    /* Status */
    --danger:         #ff3a3a;
    --success:        #30ffaa;

    /* Brand gradient */
    --brand-gradient: linear-gradient(90deg, #00aaff 0%, #00ddff 45%, #ffa030 100%);
    --brand-gradient-v: linear-gradient(180deg, #00aaff 0%, #ffa030 100%);

    /* Glow */
    --glow-cyan: 0 0 8px rgba(0, 221, 255, 0.55);
    --glow-amber: 0 0 8px rgba(255, 160, 48, 0.55);

    /* Cyan/amber clip-path for primary buttons */
    --btn-clip: polygon(8px 0%, 100% 0%, calc(100% - 8px) 100%, 0% 100%);
}

/* ── Alpine cloak ──────────────────────────────────────────────────────── */
[x-cloak] { display: none !important; }

/* ── Reset & base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    height: 100vh;
    overflow: hidden;
    font-family: 'Rajdhani', 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.35;
    background: var(--bg-base);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
body { display: flex; flex-direction: column; }

::selection { background: rgba(0, 221, 255, 0.25); color: var(--text-primary); }

/* Scrollbars */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: var(--bg-base); }
*::-webkit-scrollbar-thumb { background: var(--border-mid); }
*::-webkit-scrollbar-thumb:hover { background: var(--border-bright); }

/* ══════════════════════════════════════════════════════
   APP HEADER
══════════════════════════════════════════════════════ */
.app-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: 52px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-mid);
    flex-shrink: 0;
    z-index: 10;
    position: relative;
}
.app-header::after {
    content: '';
    position: absolute;
    left: 0; right: 0; bottom: -1px;
    height: 1px;
    background: var(--brand-gradient);
    opacity: 0.5;
    pointer-events: none;
}

.header-logo {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    margin-right: 6px;
    display: block;
    cursor: pointer;
}

.header-name {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    gap: 6px;
    min-width: 0;
}
.device-title {
    font-family: 'Orbitron', sans-serif;
    font-weight: 800;
    font-size: 14px;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    white-space: nowrap;
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}
.edit-icon {
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    padding: 2px 4px;
    transition: color 0.15s ease;
}
.edit-icon:hover { color: var(--cyan-bright); }
.name-edit-row { display: flex; gap: 6px; align-items: center; }
.name-input {
    padding: 4px 8px;
    border: 1px solid var(--border-mid);
    border-bottom: 1px solid var(--cyan-deep);
    background: var(--bg-surface);
    color: var(--text-primary);
    border-radius: 0;
    font-family: 'Rajdhani', sans-serif;
    font-size: 14px;
    width: 200px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.name-input:focus {
    border-color: var(--cyan-mid);
    box-shadow: 0 0 0 1px rgba(0, 170, 255, 0.35), 0 0 10px rgba(0, 170, 255, 0.18);
}

.header-modes {
    display: flex;
    gap: 4px;
    flex: 1;
    justify-content: center;
    flex-wrap: nowrap;
    overflow: hidden;
}

/* Mode buttons — pill-flavoured but square (no radius) with glow on active */
.mode-btn {
    padding: 5px 14px;
    border: 1px solid var(--border-mid);
    background: var(--bg-raised);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    border-radius: 0;
}
.mode-btn:hover {
    border-color: var(--border-bright);
    color: var(--cyan-bright);
}
.mode-btn.active {
    background: linear-gradient(180deg, rgba(0,170,255,0.18), rgba(0,170,255,0.05));
    border-color: var(--cyan-mid);
    color: var(--cyan-bright);
    box-shadow: inset 0 0 12px rgba(0, 170, 255, 0.18), 0 0 10px rgba(0, 170, 255, 0.25);
}

.mode-cog-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px; height: 22px;
    font-size: 11px;
    padding: 0;
    margin-left: 1px;
    margin-right: 6px;
    border: 1px solid transparent;
    border-radius: 0;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    transition: color 0.15s ease, background 0.15s ease;
}
.mode-cog-btn:hover { color: var(--cyan-bright); background: rgba(0, 170, 255, 0.08); }

.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* ══════════════════════════════════════════════════════
   GENERIC BUTTONS
══════════════════════════════════════════════════════ */

/* Base small button — angled cyan ghost by default */
.btn-sm {
    padding: 5px 14px;
    border: 1px solid var(--cyan-deep);
    background: rgba(0, 102, 204, 0.08);
    color: var(--cyan-bright);
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    white-space: nowrap;
    border-radius: 0;
    clip-path: var(--btn-clip);
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.btn-sm:hover:not(:disabled) {
    background: rgba(0, 170, 255, 0.18);
    border-color: var(--cyan-mid);
    color: var(--cyan-bright);
    box-shadow: 0 0 12px rgba(0, 170, 255, 0.35);
}
.btn-sm:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Ghost — no fill, used for cancel/secondary */
.btn-ghost {
    background: transparent;
    border-color: var(--border-mid);
    color: var(--text-secondary);
    clip-path: none;
    padding-left: 12px;
    padding-right: 12px;
}
.btn-ghost:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--border-bright);
    color: var(--text-primary);
    box-shadow: none;
}

/* Danger — red */
.btn-danger {
    background: rgba(255, 58, 58, 0.10);
    border-color: var(--danger);
    color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
    background: rgba(255, 58, 58, 0.22);
    border-color: var(--danger);
    color: #fff;
    box-shadow: 0 0 12px rgba(255, 58, 58, 0.45);
}

/* Tiny inline button (drag handles, axis ops, etc.) */
.btn-xs {
    padding: 2px 7px;
    border: 1px solid var(--border-mid);
    background: var(--bg-raised);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
    border-radius: 0;
    line-height: 1.3;
    transition: all 0.15s ease;
}
.btn-xs:hover { background: rgba(0, 170, 255, 0.10); border-color: var(--cyan-mid); color: var(--cyan-bright); }

/* Plain native <button>: get a minimum baseline so unstyled buttons in
   modal-buttons rows still look right */
button:not([class]),
.modal-content button:not([class]) {
    padding: 6px 14px;
    border: 1px solid var(--cyan-deep);
    background: rgba(0, 102, 204, 0.08);
    color: var(--cyan-bright);
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    border-radius: 0;
    transition: all 0.15s ease;
}
button:not([class]):hover:not(:disabled),
.modal-content button:not([class]):hover:not(:disabled) {
    background: rgba(0, 170, 255, 0.18);
    border-color: var(--cyan-mid);
    box-shadow: 0 0 10px rgba(0, 170, 255, 0.3);
}
button:disabled { cursor: not-allowed; opacity: 0.4; }

/* Save/profile state animations (kept as state-driven colour pulses) */
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.btn-xs.loading {
    display: inline-block;
    animation: spin 0.7s linear infinite;
    cursor: default;
    pointer-events: none;
}

@keyframes btn-pulse-ok {
    0%   { background: rgba(0, 102, 204, 0.08); border-color: var(--cyan-deep); color: var(--cyan-bright); }
    25%  { background: rgba(48, 255, 170, 0.18); border-color: var(--success); color: var(--success); box-shadow: 0 0 14px rgba(48, 255, 170, 0.5); }
    100% { background: rgba(0, 102, 204, 0.08); border-color: var(--cyan-deep); color: var(--cyan-bright); }
}
@keyframes btn-pulse-fail {
    0%   { background: rgba(0, 102, 204, 0.08); border-color: var(--cyan-deep); color: var(--cyan-bright); }
    25%  { background: rgba(255, 58, 58, 0.22); border-color: var(--danger); color: var(--danger); box-shadow: 0 0 14px rgba(255, 58, 58, 0.5); }
    100% { background: rgba(0, 102, 204, 0.08); border-color: var(--cyan-deep); color: var(--cyan-bright); }
}
.btn-save-ok   { animation: btn-pulse-ok   3s ease forwards; }
.btn-save-fail { animation: btn-pulse-fail 3s ease forwards; }

@keyframes btn-pulse-busy {
    0%   { background: rgba(255, 160, 48, 0.10); border-color: var(--amber-mid); color: var(--amber-bright); }
    50%  { background: rgba(255, 160, 48, 0.25); border-color: var(--amber-bright); color: var(--amber-bright); box-shadow: 0 0 14px rgba(255, 160, 48, 0.55); }
    100% { background: rgba(255, 160, 48, 0.10); border-color: var(--amber-mid); color: var(--amber-bright); }
}
.btn-busy { animation: btn-pulse-busy 1.2s ease-in-out infinite; cursor: not-allowed; }

/* ══════════════════════════════════════════════════════
   PANELS  (two equal halves, stacked)
══════════════════════════════════════════════════════ */
.panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: var(--bg-base);
    position: relative;
}
.panel::before {
    content: '';
    position: absolute;
    left: 0; right: 0; top: 0;
    height: 1px;
    background: radial-gradient(ellipse at center, var(--cyan-bright) 0%, transparent 70%);
    opacity: 0.55;
    pointer-events: none;
    z-index: 1;
}

.panel-divider {
    height: 2px;
    background: var(--brand-gradient);
    opacity: 0.55;
    flex-shrink: 0;
}

.panel-tabbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 14px;
    height: 38px;
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border-dim);
    flex-shrink: 0;
}

.panel-label {
    font-family: 'Orbitron', sans-serif;
    font-size: 9px;
    font-weight: 600;
    color: var(--text-label);
    text-transform: uppercase;
    letter-spacing: 0.35em;
    margin-right: 8px;
    flex-shrink: 0;
}

.tab-btn {
    padding: 4px 12px;
    border: 1px solid var(--border-mid);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    white-space: nowrap;
    border-radius: 0;
    transition: all 0.15s ease;
}
.tab-btn:hover {
    border-color: var(--border-bright);
    color: var(--cyan-bright);
    background: rgba(0, 170, 255, 0.05);
}
.tab-btn.active {
    background: linear-gradient(180deg, rgba(0,170,255,0.18), rgba(0,170,255,0.04));
    border-color: var(--cyan-mid);
    color: var(--cyan-bright);
    box-shadow: inset 0 -2px 0 var(--cyan-bright);
}
.tab-btn--ext { font-style: normal; }
.tab-btn--ext.active {
    background: linear-gradient(180deg, rgba(255,160,48,0.18), rgba(255,160,48,0.04));
    border-color: var(--amber-mid);
    color: var(--amber-bright);
    box-shadow: inset 0 -2px 0 var(--amber-bright);
}
.tab--offline { opacity: 0.5; }
.tab--offline:not(.active) { color: var(--text-muted); border-color: var(--border-dim); }
.tab-offline-badge { margin-left: 5px; font-size: 10px; color: var(--amber-mid); }

.tab-led-cog {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px; height: 22px;
    font-size: 12px;
    padding: 0;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 0;
    margin-left: -2px;
    flex-shrink: 0;
    line-height: 1;
    transition: color 0.15s ease, background 0.15s ease;
}
.tab-led-cog:hover:not(:disabled) { color: var(--cyan-bright); background: rgba(0, 170, 255, 0.08); }
.tab-led-cog:disabled { color: var(--border-dim); cursor: default; }

.tab-spacer { flex: 1; }

.device-label {
    font-family: 'Rajdhani', sans-serif;
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 340px;
    font-style: normal;
    letter-spacing: 0.02em;
}

/* ══════════════════════════════════════════════════════
   PANEL BODY
══════════════════════════════════════════════════════ */
.panel-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: var(--bg-surface);
}
.panel-body--ext {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    background: var(--bg-surface);
}
.ext-target-panel { text-align: center; font-family: 'Rajdhani', sans-serif; font-size: 14px; }
.ext-target-panel p { margin: 0 0 14px; }

/* ── Axes column ── */
.axes-col {
    width: 320px;
    flex-shrink: 0;
    border-right: 1px solid var(--border-dim);
    padding: 8px 14px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0;
    background: var(--bg-surface);
}

.col-heading {
    font-family: 'Orbitron', sans-serif;
    font-size: 9px;
    font-weight: 400;
    color: var(--amber-bright);
    text-transform: uppercase;
    letter-spacing: 0.35em;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-dim);
    margin-bottom: 4px;
    flex-shrink: 0;
}
.col-heading-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 0 6px 0;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border-dim);
    flex-shrink: 0;
    min-height: 26px;
}
.col-hint {
    font-family: 'Rajdhani', sans-serif;
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    letter-spacing: 0.02em;
    cursor: help;
}

/* ══════════════════════════════════════════════════════
   AXIS ROWS
══════════════════════════════════════════════════════ */
.axis-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    border-bottom: 1px solid var(--border-dim);
    min-height: 40px;
    position: relative;
    transition: background 0.12s ease;
}
.axis-row::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 4px; bottom: 4px;
    width: 2px;
    background: var(--brand-gradient-v);
    opacity: 0;
    transition: opacity 0.15s ease;
}
.axis-row:hover::before { opacity: 0.9; }

.axis-row--src { cursor: grab; }
.axis-row--src:hover { background: rgba(0, 170, 255, 0.04); }
.axis-row--src:active { cursor: grabbing; }
.axis-row--dst:hover { background: rgba(0, 170, 255, 0.06); }

.axis-name-wrap {
    position: relative;
    width: 44px;
    flex-shrink: 0;
}
.axis-name {
    font-family: 'Orbitron', sans-serif;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.06em;
}
.axis-link-dot {
    position: absolute;
    top: -4px;
    right: -1px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--amber-bright);
    box-shadow: 0 0 6px var(--amber-mid);
    z-index: 1;
    pointer-events: none;
}
.axis-track {
    flex: 1;
    height: 3px;
    background: var(--bg-raised);
    border-radius: 0;
    overflow: hidden;
    border: 1px solid var(--border-dim);
}
.axis-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--cyan-deep), var(--cyan-bright));
    box-shadow: 0 0 8px var(--cyan-bright);
    transition: width 0.05s linear;
}
.axis-fill--out { background: linear-gradient(90deg, var(--cyan-deep), var(--cyan-bright)); }

.axis-pct {
    width: 40px;
    text-align: right;
    font-family: 'Orbitron', sans-serif;
    font-size: 10px;
    color: var(--text-secondary);
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.link-badge {
    font-size: 12px;
    flex-shrink: 0;
    width: 18px;
    text-align: center;
    color: var(--cyan-bright);
}
.no-link-spacer { width: 18px; flex-shrink: 0; }
.trigger-badge {
    font-family: 'Orbitron', sans-serif;
    font-size: 8px;
    background: var(--amber-mid);
    color: #000;
    border-radius: 0;
    padding: 1px 4px;
    flex-shrink: 0;
    line-height: 1.3;
    font-weight: 700;
    letter-spacing: 0.10em;
    box-shadow: 0 0 6px rgba(255, 160, 48, 0.5);
}

/* ══════════════════════════════════════════════════════
   BUTTONS COLUMN
══════════════════════════════════════════════════════ */
.buttons-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    overflow: hidden;
    background: var(--bg-surface);
}

/* 16 × 8 = 128 buttons, 40 px squares — dimensions preserved (drag depends on them) */
.btn-grid {
    display: grid;
    grid-template-columns: repeat(16, 40px);
    grid-template-rows: repeat(8, 40px);
    gap: 4px;
    overflow: auto;
    flex: 1;
    align-content: start;
    padding-bottom: 4px;
}

.grid-btn--src,
.grid-btn--out {
    width: 40px;
    height: 40px;
    border-radius: 0;
    border: 1px solid var(--border-mid);
    background: var(--bg-raised);
    color: var(--text-secondary);
    font-family: 'Orbitron', sans-serif;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 2px;
    line-height: 1;
    transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease, box-shadow 0.12s ease, opacity 0.08s ease;
}
.grid-btn--src { cursor: grab; }
.grid-btn--src:active { cursor: grabbing; }

.grid-btn--src:hover,
.grid-btn--out:hover {
    border-color: var(--cyan-mid);
    color: var(--cyan-bright);
    box-shadow: 0 0 10px rgba(0, 170, 255, 0.4), inset 0 0 8px rgba(0, 170, 255, 0.15);
    opacity: 1;
}

.grid-btn--src.pressed {
    background: rgba(255, 58, 58, 0.35);
    border-color: var(--danger);
    color: #fff;
    box-shadow: 0 0 10px rgba(255, 58, 58, 0.5);
}
/* Output cell wrapper (positions badges + link dot) */
.out-btn-cell {
    width: 40px;
    height: 40px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.out-btn-link-dot {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--amber-bright);
    box-shadow: 0 0 5px var(--amber-mid);
    z-index: 1;
    pointer-events: none;
}
.out-btn-toggle-badge {
    position: absolute;
    top: 2px;
    left: 3px;
    font-family: 'Orbitron', sans-serif;
    font-size: 8px;
    color: var(--cyan-bright);
    font-weight: 700;
    z-index: 1;
    pointer-events: none;
    line-height: 1;
    text-shadow: 0 0 4px var(--cyan-bright);
}

/* `.dropzone` is a permanent marker class on every drop target — it must be
   neutral until the user is actively dragging.  The amber highlight only
   appears via `.dropzone--active` (added by drag handlers if needed) or on
   real CSS-level `:hover` while a drag is in flight via the browser.
   Keeping this rule empty intentionally — do not give .dropzone a visible
   style on its own. */

/* Non-default mapping highlight — cyan glow on destination axes / output
   buttons that have an explicit override of the 1:1 default. The
   `has-mapping` class is added by Alpine via the same condition used to
   show the orange `.axis-link-dot` / `.out-btn-link-dot`. */
.axis-row--dst.has-mapping {
    background: rgba(0, 170, 255, 0.05);
}
.axis-row--dst.has-mapping::before { opacity: 0.9; }
.axis-row--dst.has-mapping .axis-name { color: var(--cyan-bright); }
.axis-row--dst.has-mapping .axis-fill--out {
    background: linear-gradient(90deg, var(--cyan-mid), var(--cyan-bright));
    box-shadow: 0 0 10px var(--cyan-bright);
}

.grid-btn--out.has-mapping {
    border-color: var(--cyan-mid);
    background: linear-gradient(180deg, rgba(0, 170, 255, 0.18), rgba(0, 170, 255, 0.04));
    color: var(--cyan-bright);
    box-shadow: 0 0 8px rgba(0, 170, 255, 0.35), inset 0 0 6px rgba(0, 170, 255, 0.10);
}

/* `btn-pressed` lives below all structural state classes (has-mapping,
   inherited) so that an active press always overrides the mapped /
   inherited baseline at equal specificity. */
.grid-btn--out.btn-pressed {
    background: linear-gradient(180deg, rgba(0, 221, 255, 0.55), rgba(0, 170, 255, 0.30));
    border-color: var(--cyan-bright);
    color: #fff;
    box-shadow: 0 0 14px rgba(0, 221, 255, 0.75), inset 0 0 10px rgba(0, 221, 255, 0.25);
}

/* Implied 1:1 default styling — slightly muted */
.implied-default { opacity: 0.7; }

/* ══════════════════════════════════════════════════════
   MODALS
══════════════════════════════════════════════════════ */
.modal {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(2, 5, 12, 0.78);
    backdrop-filter: blur(2px);
    display: flex; justify-content: center; align-items: center;
    z-index: 1000;
}
.modal-content {
    background: var(--bg-overlay);
    border: 1px solid var(--border-bright);
    padding: 22px;
    border-radius: 0;
    max-width: 440px;
    width: 90%;
    display: flex;
    flex-direction: column;
    color: var(--text-primary);
    font-family: 'Rajdhani', sans-serif;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(0, 170, 255, 0.05);
    position: relative;
}
.modal-content::before {
    content: '';
    position: absolute;
    left: 0; right: 0; top: 0;
    height: 1px;
    background: radial-gradient(ellipse at center, var(--cyan-bright) 0%, transparent 70%);
    opacity: 0.65;
    pointer-events: none;
}

.modal-content h3 {
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    color: var(--amber-bright);
    margin: 0 0 14px;
}
.modal-content h4 {
    font-family: 'Orbitron', sans-serif;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--amber-bright);
    margin: 0 0 8px;
}
.modal-content label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--text-primary);
}
.modal-content p { color: var(--text-secondary); font-size: 13px; }

.modal-field { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.modal-field label { margin-bottom: 0; }
.modal-close { align-self: flex-end; }
.modal-section {
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-dim);
}
.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 18px;
    flex-wrap: wrap;
}

/* Native inputs inside modals */
.modal-content input[type="text"],
.modal-content input[type="number"],
.modal-content select,
.modal-content textarea {
    padding: 5px 9px;
    background: var(--bg-surface);
    border: 1px solid var(--border-mid);
    border-bottom: 1px solid var(--cyan-deep);
    color: var(--text-primary);
    font-family: 'Rajdhani', sans-serif;
    font-size: 14px;
    border-radius: 0;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.modal-content select {
    border-bottom-color: var(--amber-deep);
}
.modal-content input:focus,
.modal-content select:focus,
.modal-content textarea:focus {
    border-color: var(--cyan-mid);
    box-shadow: 0 0 0 1px rgba(0, 170, 255, 0.35), 0 0 10px rgba(0, 170, 255, 0.18);
}
.modal-content select:focus { box-shadow: 0 0 0 1px rgba(255, 160, 48, 0.35), 0 0 10px rgba(255, 160, 48, 0.18); }

.modal-content input[type="checkbox"] {
    width: 14px; height: 14px;
    accent-color: var(--cyan-bright);
    cursor: pointer;
}

.sources-field { flex-direction: column; align-items: flex-start; }
.sources-field label { margin-bottom: 4px; }
.sources-list {
    display: flex; flex-direction: column; width: 100%;
    max-height: 130px; overflow-y: auto;
    border: 1px solid var(--border-mid);
    border-radius: 0;
    background: var(--bg-surface);
}
.mapping-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 12px;
    border-bottom: 1px solid var(--border-dim);
    font-size: 13px;
}
.mapping-row:last-child { border-bottom: none; }
.no-mapping { color: var(--text-muted); font-style: italic; padding: 6px 12px; font-size: 13px; }
.remove-source-btn {
    font-family: 'Orbitron', sans-serif;
    font-size: 9px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    padding: 2px 9px;
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: 0;
    cursor: pointer;
    transition: all 0.15s ease;
}
.remove-source-btn:hover {
    background: rgba(255, 58, 58, 0.18);
    box-shadow: 0 0 8px rgba(255, 58, 58, 0.4);
}

.color-picker-modal { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.preview {
    width: 18px; height: 18px;
    border: 1px solid var(--border-bright);
    border-radius: 0;
}

/* ══════════════════════════════════════════════════════
   KBM PANEL
══════════════════════════════════════════════════════ */
.panel-body--kbm {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: 14px;
    padding: 10px 14px;
    overflow: auto;
    background: var(--bg-surface);
}
.kbm-keyboard-section {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    gap: 8px;
}
.kbm-mouse-section {
    width: 360px;
    flex-shrink: 0;
    border-right: 1px solid var(--border-dim);
    padding-right: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
}
.kbm-subheading {
    font-family: 'Orbitron', sans-serif;
    font-size: 9px;
    font-weight: 400;
    color: var(--amber-bright);
    text-transform: uppercase;
    letter-spacing: 0.35em;
    margin-bottom: 4px;
}

.kb-wrapper {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    overflow: hidden;
    max-width: 1040px;
}
.kb-row {
    display: flex;
    gap: 3px;
    align-items: stretch;
    flex: 1;
}
.kb-key {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border-mid);
    border-radius: 0;
    background: var(--bg-raised);
    font-family: 'Orbitron', sans-serif;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    overflow: hidden;
    padding: 0 4px;
    cursor: default;
    transition: background 0.1s ease, border-color 0.1s ease, color 0.1s ease, box-shadow 0.1s ease;
}
.kb-key:not(:disabled):hover {
    background: rgba(0, 170, 255, 0.08);
    border-color: var(--cyan-mid);
    color: var(--cyan-bright);
}
.kb-key--mapped {
    background: linear-gradient(180deg, rgba(0,170,255,0.25), rgba(0,170,255,0.08));
    border-color: var(--cyan-mid);
    color: var(--cyan-bright);
    box-shadow: inset 0 0 8px rgba(0, 170, 255, 0.2);
}
.kb-spacer-btn {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    cursor: default;
    pointer-events: none;
}

.mouse-axis-row {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 8px 12px;
    border: 1px solid var(--border-mid);
    border-radius: 0;
    background: var(--bg-raised);
    cursor: default;
    min-height: 48px;
    transition: background 0.1s ease, border-color 0.1s ease;
}
.mouse-axis-row:hover { border-color: var(--cyan-mid); background: rgba(0, 170, 255, 0.06); }
.mouse-axis-row--mapped { cursor: pointer; }
.mouse-axis-row--mapped:hover { border-color: var(--danger) !important; background: rgba(255, 58, 58, 0.10) !important; }
.mouse-axis-name { font-family: 'Orbitron', sans-serif; color: var(--text-primary); font-size: 11px; font-weight: 600; letter-spacing: 0.06em; }
.mouse-axis-src { font-size: 11px; color: var(--cyan-bright); font-style: normal; letter-spacing: 0.02em; }
.mouse-axis-hint { font-family: 'Orbitron', sans-serif; font-size: 9px; color: var(--text-muted); letter-spacing: 0.10em; text-transform: uppercase; }

.mouse-btn-grid--primary {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}
.mouse-btn-grid--secondary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.mouse-btn-drop {
    padding: 10px 8px;
    border: 1px solid var(--border-mid);
    border-radius: 0;
    background: var(--bg-raised);
    color: var(--text-secondary);
    cursor: default;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 58px;
    transition: background 0.1s ease, border-color 0.1s ease, color 0.1s ease;
}
.mouse-btn-drop--sm { min-height: 44px; }
.mouse-btn-drop:hover { border-color: var(--cyan-mid); background: rgba(0, 170, 255, 0.06); color: var(--cyan-bright); }
.mouse-btn--mapped {
    background: linear-gradient(180deg, rgba(0,170,255,0.20), rgba(0,170,255,0.06));
    border-color: var(--cyan-mid);
    color: var(--cyan-bright);
    cursor: pointer;
    box-shadow: inset 0 0 8px rgba(0, 170, 255, 0.15);
}
.mouse-btn--mapped:hover { border-color: var(--danger) !important; background: rgba(255, 58, 58, 0.12) !important; color: var(--danger) !important; }
.mouse-btn-label { font-family: 'Orbitron', sans-serif; font-size: 11px; font-weight: 600; letter-spacing: 0.10em; text-transform: uppercase; }
.mouse-btn-src { font-size: 11px; color: var(--cyan-bright); font-style: normal; letter-spacing: 0.02em; }

/* Keyboard modifier active states */
.kb-key--shift-active {
    background: linear-gradient(180deg, rgba(0,170,255,0.3), rgba(0,170,255,0.1)) !important;
    border-color: var(--cyan-bright) !important;
    color: #fff !important;
    box-shadow: 0 0 10px rgba(0, 170, 255, 0.5) !important;
}
.kb-key--ctrl-active {
    background: linear-gradient(180deg, rgba(255,208,96,0.28), rgba(255,208,96,0.08)) !important;
    border-color: var(--amber-bright) !important;
    color: var(--amber-bright) !important;
    box-shadow: 0 0 10px rgba(255, 208, 96, 0.45) !important;
}
.kb-key--alt-active {
    background: linear-gradient(180deg, rgba(255,160,48,0.28), rgba(255,160,48,0.08)) !important;
    border-color: var(--amber-mid) !important;
    color: var(--amber-mid) !important;
    box-shadow: 0 0 10px rgba(255, 160, 48, 0.45) !important;
}

/* ══════════════════════════════════════════════════════
   MODE INHERITANCE UI
══════════════════════════════════════════════════════ */
.inherit-badge {
    display: inline-block;
    font-family: 'Orbitron', sans-serif;
    font-size: 8px;
    font-weight: 700;
    margin-left: 5px;
    opacity: 0.75;
    vertical-align: middle;
    line-height: 1;
    letter-spacing: 0.10em;
}

.lock-btn {
    min-width: 22px;
    height: 22px;
    padding: 0 4px;
    font-size: 12px;
    border-radius: 0;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    transition: opacity 0.15s ease, color 0.15s ease;
}
.lock-btn:hover { color: var(--amber-bright); opacity: 1; }

.out-btn-lock-badge {
    position: absolute;
    bottom: 1px;
    left: 2px;
    font-size: 12px;
    line-height: 1;
    pointer-events: auto;
    z-index: 2;
    opacity: 0.85;
    color: var(--amber-mid);
    text-shadow: 0 0 4px var(--amber-mid);
}

/* Active "Alternate" axis profile — amber swoosh behind the axis name */
.axis-row--alt .axis-name {
    color: var(--amber-bright);
    text-shadow: 0 0 8px var(--amber-mid);
}
.axis-row--alt .axis-name-wrap::after {
    content: '';
    position: absolute;
    top: -4px;
    bottom: -4px;
    left: -8px;
    right: -10px;
    background: linear-gradient(90deg,
                rgba(255, 160, 48, 0.38) 0%,
                rgba(255, 160, 48, 0.14) 55%,
                rgba(255, 160, 48, 0) 100%);
    border-radius: 2px;
    z-index: 0;
    pointer-events: none;
}
.axis-row--alt .axis-name { position: relative; z-index: 1; }

.axis-row--inherited { opacity: 0.55; }
.grid-btn--out.inherited { opacity: 0.45; }

@keyframes flash-highlight {
    0%   { box-shadow: 0 0 0 0 rgba(0, 221, 255, 0.0); }
    30%  { box-shadow: 0 0 0 6px rgba(0, 221, 255, 0.75), 0 0 18px rgba(0, 221, 255, 0.55); }
    100% { box-shadow: 0 0 0 0 rgba(0, 221, 255, 0.0); }
}
.flash-highlight { animation: flash-highlight 1.0s ease-out forwards; }

/* Native input fallback for inline-styled <input>s in markup */
input[type="text"], input[type="number"] {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-mid);
    border-bottom: 1px solid var(--cyan-deep);
    border-radius: 0;
    font-family: 'Rajdhani', sans-serif;
    font-size: 13px;
    padding: 4px 8px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="text"]:focus, input[type="number"]:focus {
    border-color: var(--cyan-mid);
    box-shadow: 0 0 0 1px rgba(0, 170, 255, 0.35);
}
select {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-mid);
    border-bottom: 1px solid var(--amber-deep);
    border-radius: 0;
    font-family: 'Rajdhani', sans-serif;
    font-size: 13px;
    padding: 4px 8px;
    outline: none;
}
select:focus {
    border-color: var(--amber-mid);
    box-shadow: 0 0 0 1px rgba(255, 160, 48, 0.35);
}
textarea {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-mid);
    border-radius: 0;
    font-family: 'Rajdhani', monospace;
    padding: 6px 8px;
    outline: none;
}

/* Range sliders */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    height: 16px;
    cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
    height: 3px;
    background: linear-gradient(90deg, var(--cyan-deep), var(--cyan-bright));
    border: 1px solid var(--border-dim);
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    background: var(--cyan-bright);
    border: 1px solid var(--cyan-bright);
    border-radius: 0;
    margin-top: -5px;
    box-shadow: 0 0 6px var(--cyan-bright);
}
input[type="range"]::-moz-range-track {
    height: 3px;
    background: linear-gradient(90deg, var(--cyan-deep), var(--cyan-bright));
    border: 1px solid var(--border-dim);
}
input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--cyan-bright);
    border: 1px solid var(--cyan-bright);
    border-radius: 0;
    box-shadow: 0 0 6px var(--cyan-bright);
}

/* ══════════════════════════════════════════════════════
   COG ICON (legacy cog-btn in old admin pages)
══════════════════════════════════════════════════════ */
.cog-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    font-size: 16px;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: 0;
    background: var(--bg-raised);
    border: 1px solid var(--border-mid);
    transition: all 0.15s ease;
}
.cog-btn:hover { background: rgba(0, 170, 255, 0.08); color: var(--cyan-bright); border-color: var(--cyan-mid); }
