/**
 * Copyright (c) 2014 The xterm.js authors. All rights reserved.
 * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
 * https://github.com/chjj/term.js
 * @license MIT
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * Originally forked from (with the author's permission):
 *   Fabrice Bellard's javascript vt100 for jslinux:
 *   http://bellard.org/jslinux/
 *   Copyright (c) 2011 Fabrice Bellard
 *   The original design remains. The terminal itself
 *   has been extended to include xterm CSI codes, among
 *   other features.
 */

/**
 *  Default styles for xterm.js
 */

.xterm {
    cursor: text;
    position: relative;
    user-select: none;
    -ms-user-select: none;
    -webkit-user-select: none;
}

.xterm.focus,
.xterm:focus {
    outline: none;
}

.xterm .xterm-helpers {
    position: absolute;
    top: 0;
    /**
     * The z-index of the helpers must be higher than the canvases in order for
     * IMEs to appear on top.
     */
    z-index: 5;
}

.xterm .xterm-helper-textarea {
    padding: 0;
    border: 0;
    margin: 0;
    /* Move textarea out of the screen to the far left, so that the cursor is not visible */
    position: absolute;
    opacity: 0;
    left: -9999em;
    top: 0;
    width: 0;
    height: 0;
    z-index: -5;
    /** Prevent wrapping so the IME appears against the textarea at the correct position */
    white-space: nowrap;
    overflow: hidden;
    resize: none;
}

.xterm .composition-view {
    /* TODO: Composition position got messed up somewhere */
    background: #000;
    color: #FFF;
    display: none;
    position: absolute;
    white-space: nowrap;
    z-index: 1;
}

.xterm .composition-view.active {
    display: block;
}

.xterm .xterm-viewport {
    /* On OS X this is required in order for the scroll bar to appear fully opaque */
    background-color: #000;
    overflow-y: scroll;
    cursor: default;
    position: absolute;
    right: 0;
    left: 0;
    top: 0;
    bottom: 0;
}

.xterm .xterm-screen {
    position: relative;
}

.xterm .xterm-screen canvas {
    position: absolute;
    left: 0;
    top: 0;
}

.xterm-char-measure-element {
    display: inline-block;
    visibility: hidden;
    position: absolute;
    top: 0;
    left: -9999em;
    line-height: normal;
}

.xterm.enable-mouse-events {
    /* When mouse events are enabled (eg. tmux), revert to the standard pointer cursor */
    cursor: default;
}

.xterm.xterm-cursor-pointer,
.xterm .xterm-cursor-pointer {
    cursor: pointer;
}

.xterm.column-select.focus {
    /* Column selection mode */
    cursor: crosshair;
}

.xterm .xterm-accessibility:not(.debug),
.xterm .xterm-message {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
    z-index: 10;
    color: transparent;
    pointer-events: none;
}

.xterm .xterm-accessibility-tree:not(.debug) *::selection {
  color: transparent;
}

.xterm .xterm-accessibility-tree {
  font-family: monospace;
  user-select: text;
  white-space: pre;
}

.xterm .xterm-accessibility-tree > div {
  transform-origin: left;
  width: fit-content;
}

.xterm .live-region {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.xterm-dim {
    /* Dim should not apply to background, so the opacity of the foreground color is applied
     * explicitly in the generated class and reset to 1 here */
    opacity: 1 !important;
}

.xterm-underline-1 { text-decoration: underline; }
.xterm-underline-2 { text-decoration: double underline; }
.xterm-underline-3 { text-decoration: wavy underline; }
.xterm-underline-4 { text-decoration: dotted underline; }
.xterm-underline-5 { text-decoration: dashed underline; }

.xterm-overline {
    text-decoration: overline;
}

.xterm-overline.xterm-underline-1 { text-decoration: overline underline; }
.xterm-overline.xterm-underline-2 { text-decoration: overline double underline; }
.xterm-overline.xterm-underline-3 { text-decoration: overline wavy underline; }
.xterm-overline.xterm-underline-4 { text-decoration: overline dotted underline; }
.xterm-overline.xterm-underline-5 { text-decoration: overline dashed underline; }

.xterm-strikethrough {
    text-decoration: line-through;
}

.xterm-screen .xterm-decoration-container .xterm-decoration {
	z-index: 6;
	position: absolute;
}

.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer {
	z-index: 7;
}

.xterm-decoration-overview-ruler {
    z-index: 8;
    position: absolute;
    top: 0;
    right: 0;
    pointer-events: none;
}

.xterm-decoration-top {
    z-index: 2;
    position: relative;
}



/* Derived from vs/base/browser/ui/scrollbar/media/scrollbar.css */

/* xterm.js customization: Override xterm's cursor style */
.xterm .xterm-scrollable-element > .scrollbar {
    cursor: default;
}

/* Arrows */
.xterm .xterm-scrollable-element > .scrollbar > .scra {
	cursor: pointer;
	font-size: 11px !important;
}

.xterm .xterm-scrollable-element > .visible {
	opacity: 1;

	/* Background rule added for IE9 - to allow clicks on dom node */
	background:rgba(0,0,0,0);

	transition: opacity 100ms linear;
	/* In front of peek view */
	z-index: 11;
}
.xterm .xterm-scrollable-element > .invisible {
	opacity: 0;
	pointer-events: none;
}
.xterm .xterm-scrollable-element > .invisible.fade {
	transition: opacity 800ms linear;
}

/* Scrollable Content Inset Shadow */
.xterm .xterm-scrollable-element > .shadow {
	position: absolute;
	display: none;
}
.xterm .xterm-scrollable-element > .shadow.top {
	display: block;
	top: 0;
	left: 3px;
	height: 3px;
	width: 100%;
	box-shadow: var(--vscode-scrollbar-shadow, #000) 0 6px 6px -6px inset;
}
.xterm .xterm-scrollable-element > .shadow.left {
	display: block;
	top: 3px;
	left: 0;
	height: 100%;
	width: 3px;
	box-shadow: var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset;
}
.xterm .xterm-scrollable-element > .shadow.top-left-corner {
	display: block;
	top: 0;
	left: 0;
	height: 3px;
	width: 3px;
}
.xterm .xterm-scrollable-element > .shadow.top.left {
	box-shadow: var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset;
}
/* ==========================================================================
   EA-KVM Enterprise Orchestrator — Precision Industrial Design System
   Palette: Dark Carbon (#090B0E), Slate (#101318 / #161A22), Border (#1E2430)
   Typography: Inter (UI) + JetBrains Mono (Telemetry, IP, MAC, Logs)
   Strictly ZERO neon gradients, ZERO emojis, ZERO excessive border-radius.
   ========================================================================== */

:root {
  --bg-primary: #090B0E;
  --bg-secondary: #101318;
  --bg-elevated: #161A22;
  --border-struct: #1E2430;
  --accent-blue: #3B82F6;
  --accent-emerald: #10B981;
  --status-online: #10B981;
  --status-warn: #F59E0B;
  --status-crit: #EF4444;
  --text-primary: #F3F4F6;
  --text-secondary: #9CA3AF;
  --text-muted: #6B7280;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, monospace;
}

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

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.4;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.mono {
  font-family: var(--font-mono);
}

/* Top Global Navigation Bar */
.nx-app-shell {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  background: var(--bg-primary);
}

.nx-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 42px;
  padding: 0 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-struct);
  flex-shrink: 0;
  user-select: none;
}

.nx-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.nx-brand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: var(--bg-elevated);
  border: 1px solid var(--accent-blue);
  border-radius: 4px;
  color: var(--accent-blue);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
}

.nx-nav-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nx-nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
  border-radius: 4px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.nx-nav-tab:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.nx-nav-tab.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--accent-blue);
}

.nx-topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nx-cmd-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding: 0 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-struct);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
}

.nx-cmd-trigger:hover {
  border-color: var(--accent-blue);
  color: var(--text-primary);
}

.nx-kbd {
  padding: 1px 5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-struct);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}

/* Buttons & Controls */
.nx-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-struct);
  border-radius: 4px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.nx-btn:hover {
  border-color: var(--accent-blue);
}

.nx-btn-primary {
  background: #1D4ED8;
  border-color: var(--accent-blue);
  color: #F3F4F6;
}

.nx-btn-primary:hover {
  background: #2563EB;
}

.nx-btn-emerald {
  background: rgba(16, 185, 129, 0.14);
  border-color: var(--accent-emerald);
  color: var(--accent-emerald);
}

.nx-btn-danger {
  background: rgba(239, 68, 68, 0.12);
  border-color: var(--status-crit);
  color: var(--status-crit);
}

.nx-input, .nx-select {
  height: 28px;
  padding: 0 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border-struct);
  border-radius: 4px;
  font-family: var(--font-ui);
  font-size: 12px;
  outline: none;
}

.nx-input:focus, .nx-select:focus {
  border-color: var(--accent-blue);
}

/* Workspace Body */
.nx-workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Fleet Manager Layout */
.nx-fleet-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.nx-filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-struct);
}

.nx-filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.nx-fleet-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.nx-fleet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 10px;
}

.nx-node-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border: 1px solid var(--border-struct);
  border-radius: 4px;
  overflow: hidden;
}

.nx-node-card:hover {
  border-color: var(--accent-blue);
}

.nx-node-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-struct);
}

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

.nx-status-dot.online { background: var(--status-online); }
.nx-status-dot.warn { background: var(--status-warn); }
.nx-status-dot.offline { background: var(--status-crit); }

.nx-thumb-wrap {
  position: relative;
  width: 100%;
  height: 156px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-struct);
  overflow: hidden;
}

.nx-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.nx-node-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-struct);
  font-family: var(--font-mono);
  font-size: 11px;
}

.nx-node-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  gap: 4px;
}

/* Dense Industrial Table (32px-36px rows) */
.nx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.nx-table th {
  height: 32px;
  padding: 0 10px;
  text-align: left;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border-struct);
}

.nx-table td {
  height: 34px;
  padding: 0 10px;
  border-bottom: 1px solid var(--border-struct);
  color: var(--text-primary);
}

.nx-table tr:hover td {
  background: var(--bg-elevated);
}

.nx-tag {
  display: inline-block;
  padding: 1px 6px;
  background: var(--bg-primary);
  border: 1px solid var(--border-struct);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-secondary);
  margin-right: 4px;
}

/* KVM & Remote Desktop Session Workspace */
.nx-kvm-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.nx-kvm-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #050608;
  position: relative;
  overflow: hidden;
}

.nx-session-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 36px;
  padding: 0 10px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-struct);
  z-index: 20;
  transition: transform 0.18s ease;
}

.nx-session-toolbar.auto-hidden {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  transform: translateY(-32px);
}

.nx-session-toolbar.auto-hidden:hover {
  transform: translateY(0);
}

.nx-canvas-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.nx-kvm-canvas {
  max-width: 100%;
  max-height: 100%;
  border: 1px solid var(--border-struct);
  background: var(--bg-primary);
  outline: none;
  cursor: crosshair;
}

/* Real-Time Telemetry HUD Overlay (RustDesk style) */
.nx-telemetry-hud {
  position: absolute;
  top: 46px;
  left: 12px;
  width: 290px;
  padding: 8px 10px;
  background: rgba(16, 19, 24, 0.94);
  border: 1px solid var(--border-struct);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  z-index: 15;
  pointer-events: none;
}

.nx-hud-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

/* Right Hardware Engineering Dock */
.nx-kvm-dock {
  width: 360px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-struct);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.nx-dock-section {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-struct);
}

.nx-dock-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.nx-led-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.nx-led-box {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-struct);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
}

/* Compact Virtual OSD Keyboard */
.nx-osd-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  margin-top: 6px;
}

.nx-osd-key {
  height: 26px;
  background: var(--bg-primary);
  border: 1px solid var(--border-struct);
  border-radius: 3px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 10px;
  cursor: pointer;
}

.nx-osd-key:hover {
  border-color: var(--accent-blue);
  color: var(--text-primary);
}

/* Terminal Multiplexer Split-Pane Grid */
.nx-term-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.nx-term-grid {
  flex: 1;
  display: grid;
  gap: 4px;
  padding: 4px;
  background: var(--bg-primary);
  overflow: hidden;
}

.nx-term-grid.layout-single { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.nx-term-grid.layout-split-h { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.nx-term-grid.layout-split-v { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
.nx-term-grid.layout-quad { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }

.nx-term-pane {
  display: flex;
  flex-direction: column;
  background: #07090C;
  border: 1px solid var(--border-struct);
  border-radius: 4px;
  overflow: hidden;
}

.nx-term-pane.active-pane {
  border-color: var(--accent-blue);
}

.nx-term-pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 28px;
  padding: 0 8px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-struct);
  font-family: var(--font-mono);
  font-size: 11px;
}

.nx-term-output {
  flex: 1;
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.45;
  color: #E5E7EB;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.nx-term-input-row {
  display: flex;
  align-items: center;
  height: 30px;
  padding: 0 8px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-struct);
}

.nx-term-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  outline: none;
  margin-left: 6px;
}

/* Dual-Pane SFTP File Manager */
.nx-sftp-dual {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px;
  overflow: hidden;
}

.nx-sftp-pane {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border: 1px solid var(--border-struct);
  border-radius: 4px;
  overflow: hidden;
}

/* Command Palette Modal (Ctrl+K) */
.nx-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 8, 0.78);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 90px;
  z-index: 100;
}

.nx-cmd-modal {
  width: 580px;
  background: var(--bg-elevated);
  border: 1px solid var(--accent-blue);
  border-radius: 6px;
  overflow: hidden;
}

.nx-cmd-input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: none;
  border-bottom: 1px solid var(--border-struct);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
}

.nx-cmd-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 34px;
  padding: 0 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-struct);
}

.nx-cmd-item:hover, .nx-cmd-item.selected {
  background: rgba(59, 130, 246, 0.16);
}
