/* Global Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* Eliminate double-tap to zoom globally and block click delay */
}

html {
  overflow: hidden;
  height: 100%;
  touch-action: manipulation;
}


:root {
  --bg-color: #080c14;
  --panel-bg: rgba(13, 20, 35, 0.65);
  --panel-border: rgba(99, 102, 241, 0.15);
  --primary-color: #6366f1;
  --primary-glow: rgba(99, 102, 241, 0.4);
  --accent-color: #10b981;
  --accent-glow: rgba(16, 185, 129, 0.3);
  --danger-color: #ef4444;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --terminal-bg: #0c0c0c;
  
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-color);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
  position: relative;
  touch-action: manipulation;
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(16, 185, 129, 0.05) 0%, transparent 40%);
}

/* App Container Layout */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  position: relative;
}

/* Views Management */
.view-panel {
  display: none;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  opacity: 0;
  transition: opacity 0.3s ease;
  -webkit-overflow-scrolling: touch !important;
}

.view-panel.active {
  display: flex;
  opacity: 1;
}

/* Glassmorphism Card (Connection Panel) */
#connection-view {
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.glass-card {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  width: 100%;
  max-width: 520px;
  padding: 24px;
  margin: auto 0;
}

.card-header {
  text-align: center;
  margin-bottom: 24px;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.logo-icon {
  color: var(--primary-color);
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 0 8px var(--primary-glow));
}

.logo h1 {
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, #a5b4fc 0%, #6366f1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.subtitle {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Form Styles */
.form-group {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row {
  display: flex;
  gap: 12px;
  width: 100%;
}

.flex-1 { flex: 1; }
.flex-3 { flex: 3; }

label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

label i {
  width: 14px;
  height: 14px;
}

input[type="text"],
input[type="number"],
input[type="password"],
textarea {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: var(--text-primary);
  padding: 12px 14px;
  font-size: 14px;
  font-family: var(--font-sans);
  transition: all 0.2s ease;
  width: 100%;
  outline: none;
}

input:focus,
textarea:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
  background: rgba(255, 255, 255, 0.07);
}

textarea {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  height: 100px;
  resize: vertical;
}

/* Auth Buttons Toggle */
.auth-toggle-group {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.auth-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.auth-btn.active {
  background: var(--primary-color);
  color: white;
  box-shadow: 0 2px 8px var(--primary-glow);
}

/* Auth Sections switching */
.auth-section {
  display: none;
  animation: fadeIn 0.25s ease forwards;
}

.auth-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Password Toggle Wrapper */
.password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrapper input {
  padding-right: 44px;
}

.password-toggle {
  position: absolute;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
}

.password-toggle:hover {
  color: var(--text-primary);
}

/* File Upload styling */
.file-upload-wrapper {
  position: relative;
  width: 100%;
}

.file-upload-wrapper input[type="file"] {
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.file-upload-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px dashed rgba(99, 102, 241, 0.4);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--primary-color);
  text-align: center;
  transition: all 0.2s ease;
}

.file-upload-wrapper:hover .file-upload-trigger {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--primary-color);
}

/* Custom Checkbox */
.form-row-checkbox {
  margin: 18px 0;
}

.checkbox-container {
  display: flex;
  align-items: center;
  position: relative;
  padding-left: 28px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  user-select: none;
}

.checkbox-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.checkmark {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  height: 18px;
  width: 18px;
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  transition: all 0.2s ease;
}

.checkbox-container:hover input ~ .checkmark {
  background-color: rgba(255, 255, 255, 0.1);
}

.checkbox-container input:checked ~ .checkmark {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

.checkbox-container input:checked ~ .checkmark:after {
  display: block;
}

.checkbox-container .checkmark:after {
  left: 6px;
  top: 2px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Connect Submit Button */
.submit-btn {
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  border: none;
  border-radius: 12px;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  padding: 14px;
  width: 100%;
  cursor: pointer;
  box-shadow: 0 4px 16px var(--primary-glow);
  transition: all 0.2s ease;
  margin-top: 10px;
}

.submit-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--primary-glow);
}

.submit-btn:active {
  transform: translateY(1px);
}

/* Connection History */
.history-section {
  margin-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 18px;
}

.history-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 120px;
  overflow-y: auto;
  padding-right: 4px;
}

.empty-history {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 10px;
}

.history-item {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-item:hover {
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.2);
}

.history-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.history-host {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.history-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.history-delete {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.history-delete:hover {
  color: var(--danger-color);
  background: rgba(239, 68, 68, 0.1);
}

/* Terminal View Panel */
#terminal-view {
  background-color: var(--terminal-bg);
  overflow: hidden;
  height: 100%;
  touch-action: none !important;
}

.terminal-header {
  height: 52px;
  background: #0d111a;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  z-index: 10;
}

.connection-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  max-width: 60%;
  overflow: hidden;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.status-dot.connected {
  background-color: var(--accent-color);
  box-shadow: 0 0 8px var(--accent-glow);
}

.status-dot.reconnecting {
  background-color: #f59e0b;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
  animation: status-pulse-yellow 1.5s infinite ease-in-out;
}

@keyframes status-pulse-yellow {
  0% {
    transform: scale(0.9);
    opacity: 0.6;
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7);
  }
  50% {
    transform: scale(1.1);
    opacity: 1;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
  }
  100% {
    transform: scale(0.9);
    opacity: 0.6;
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
  }
}

#active-connection-title {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  color: var(--text-secondary);
}

.terminal-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.action-btn.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  box-shadow: 0 2px 8px var(--primary-glow);
}

.action-btn.active:hover {
  background: #4f46e5;
  color: white;
}

.danger-btn {
  border-color: rgba(239, 68, 68, 0.2);
}

.danger-btn:hover {
  background: var(--danger-color);
  border-color: var(--danger-color);
  color: white;
}

.action-btn i {
  width: 14px;
  height: 14px;
}

/* Terminal Wrapper occupies all remaining space and acts as a flex row */
.terminal-wrapper {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: flex !important;
  flex-direction: row !important;
  align-items: stretch !important;
  padding: 8px !important;
  gap: 0 !important;
}

/* Terminal Area wraps terminal-container and its scroll-helper */
.terminal-area {
  flex: 1;
  min-width: 0;
  height: 100%;
  position: relative;
}

/* Terminal Area Padding adjustments to prevent content overlap with Scroll Helper */
.terminal-area.has-left-helper:not(.helper-collapsed) {
  padding-left: 68px !important;
  padding-right: 8px !important;
}
.terminal-area.has-left-helper.helper-collapsed {
  padding-left: 48px !important;
  padding-right: 8px !important;
}
.terminal-area.has-right-helper:not(.helper-collapsed) {
  padding-right: 68px !important;
  padding-left: 8px !important;
}
.terminal-area.has-right-helper.helper-collapsed {
  padding-right: 48px !important;
  padding-left: 8px !important;
}

/* Mobile responsive padding adjustments (screen width <= 480px) */
@media (max-width: 480px) {
  .terminal-area.has-left-helper:not(.helper-collapsed) {
    padding-left: 64px !important;
    padding-right: 6px !important;
  }
  .terminal-area.has-left-helper.helper-collapsed {
    padding-left: 44px !important;
    padding-right: 6px !important;
  }
  .terminal-area.has-right-helper:not(.helper-collapsed) {
    padding-right: 64px !important;
    padding-left: 6px !important;
  }
  .terminal-area.has-right-helper.helper-collapsed {
    padding-right: 44px !important;
    padding-left: 6px !important;
  }
}

#terminal-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Customize xterm viewport styling */
.xterm-viewport {
  background-color: var(--terminal-bg) !important;
  -webkit-overflow-scrolling: touch !important; /* Enable smooth iOS momentum scrolling */
  touch-action: none !important; /* Managed by JS Kinetic scroll simulator */
  will-change: transform, scroll-position !important;
  transform: translate3d(0, 0, 0) !important; /* Force GPU composite layer creation */
}

.xterm-screen {
  font-family: var(--font-mono) !important;
  touch-action: none !important; /* Managed by JS Kinetic scroll simulator */
  -webkit-touch-callout: none !important; /* Disable iOS context menu on long-press */
  will-change: transform !important;
  transform: translate3d(0, 0, 0) !important; /* Force GPU composite layer creation */
}

#helper-keyboard {
  height: calc(var(--helper-favorites-height, 0px) + var(--helper-history-height, 0px) + var(--helper-prompt-height, 44px) + 48px); /* Dynamic height calculation */
  background-color: #0b0f19;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
  z-index: 20;
  transition: height 0.2s ease;
  touch-action: pan-x !important;
}

/* Expanded Multi-row layout styles */
#helper-keyboard.expanded {
  height: calc(var(--helper-favorites-height, 0px) + var(--helper-history-height, 0px) + var(--helper-prompt-height, 44px) + 200px); /* Dynamic height calculation */
  overflow: visible;
}

.helper-scroll-container {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  padding: 0 12px;
  width: 100%;
  height: 48px; /* Fixed height for keys row when collapsed */
  align-items: center;
  scrollbar-width: none; /* Hide scrollbar for Firefox */
  touch-action: pan-x !important;
  box-sizing: border-box;
}

/* Helper Prompt Bar styling */
.helper-prompt-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  width: 100%;
  height: 44px;
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  box-sizing: border-box;
}

.helper-prompt-input-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.helper-prompt-input-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 2;
}

#helper-prompt-input {
  width: 100%;
  height: 32px;
  min-height: 32px;
  max-height: 80px;
  resize: none;
  overflow-y: auto;
  line-height: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 6px 32px 6px 30px; /* adjusted padding for vertical alignment */
  outline: none;
  transition: border-color 0.25s, box-shadow 0.25s, background-color 0.25s; /* no transition on height to prevent lag */
  box-sizing: border-box;
}

#helper-prompt-input:focus {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

#helper-prompt-input::placeholder {
  color: var(--text-muted);
  font-family: var(--font-sans);
  opacity: 0.8;
}

.helper-prompt-clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.2s ease;
  z-index: 2;
}

.helper-prompt-clear-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.helper-prompt-clear-btn i {
  width: 12px;
  height: 12px;
}

.helper-prompt-send-btn {
  height: 32px;
  width: 44px;
  background: var(--primary-color);
  border: 1px solid var(--primary-color);
  border-radius: 8px;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.helper-prompt-send-btn:hover {
  background: #4f46e5;
  border-color: #4f46e5;
  box-shadow: 0 0 8px var(--primary-glow);
}

.helper-prompt-send-btn:active {
  transform: scale(0.95);
}

.helper-prompt-send-btn i {
  width: 14px;
  height: 14px;
}

/* Default unexpanded state: Let the browser treat .helper-row children as direct children of the flex container */
.helper-row {
  display: contents;
  touch-action: pan-x !important;
}

#helper-keyboard.expanded .helper-scroll-container {
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: hidden; /* Lock vertical scroll in expanded mode for safety */
  padding: 10px 12px;
  height: 200px; /* Explicit height for key rows when expanded */
  gap: 6px;
  align-items: flex-start;
  justify-content: flex-start;
  box-sizing: border-box;
}

#helper-keyboard.expanded .helper-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 5px;
  width: 100%;
  overflow-x: hidden; /* Defeat horizontal scroll entirely */
  justify-content: flex-start;
  align-items: center;
}

#helper-keyboard.expanded .helper-key {
  flex: 1;
  min-width: 0; /* Enable auto shrinking to fit screen width perfectly */
  padding: 0 2px;
  font-size: 11px;
  justify-content: center;
  text-align: center;
}

#key-layout-toggle.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  box-shadow: 0 0 8px var(--primary-glow);
}

.helper-scroll-container::-webkit-scrollbar {
  display: none; /* Hide scrollbar for Chrome/Safari */
}

.helper-key {
  height: 32px;
  min-width: 44px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.helper-key:active {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(0.95);
}

.helper-key.toggle-key.active {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: white;
  box-shadow: 0 0 8px var(--primary-glow);
}

.helper-key.nav-key {
  min-width: 36px;
}

.helper-key.nav-key i {
  width: 16px;
  height: 16px;
}

#key-clear {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.2);
  color: var(--danger-color);
}

#key-clear:active {
  background: var(--danger-color);
  color: white;
}

/* Global Loading Overlay */
.overlay-panel {
  display: none;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(5, 7, 12, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  touch-action: none !important;
}

.overlay-panel.active {
  display: flex;
}

.overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
  max-width: 320px;
  text-align: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(99, 102, 241, 0.1);
  border-radius: 50%;
  border-top-color: var(--primary-color);
  animation: spin 1s linear infinite;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.1);
}

#loading-message {
  font-size: 14px;
  color: var(--text-secondary);
}

.cancel-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 8px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cancel-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

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

/* Scrollbars styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #0c0c0c;
}

::-webkit-scrollbar-thumb {
  background: #333333;
  border-radius: 4px;
  border: 1px solid #0c0c0c;
}

::-webkit-scrollbar-thumb:hover {
  background: #555555;
}

/* Desktop overrides */
@media (min-width: 768px) {
  body {
    background-size: 40% 40%;
  }
  
  .glass-card {
    padding: 32px;
  }
  
  /* On desktop, hide helper keyboard completely to fit the terminal full-screen */
  #helper-keyboard {
    display: none !important;
  }
  
  /* Slim title bar for terminal header on desktop, matching Windows Terminal */
  .terminal-header {
    height: 38px;
    background: #1e1e1e;
    padding: 0 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }
  
  .connection-info {
    font-size: 12px;
  }

  .action-btn {
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 6px;
  }
  
  /* Zero margins and padding for clean full window experience */
  .terminal-wrapper {
    padding: 0;
  }
}

/* Copy Modal Styles */
.copy-modal-card {
  width: 95%;
  max-width: 800px;
  height: 90%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 20px;
  overflow: hidden; /* Block child overflows and force inner scrolling */
}

#copy-dump-area {
  flex: 1;
  min-height: 0; /* Critical for enabling flex child scroll behaviour */
  height: 100%;
  max-height: 100%;
  width: 100%;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: var(--accent-color);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  padding: 12px;
  margin: 16px 0;
  outline: none;
  overflow-y: auto;
  overflow-x: hidden;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: text !important;
  -webkit-user-select: text !important;
  -webkit-touch-callout: default !important;
  touch-action: pan-y !important;
  -webkit-overflow-scrolling: touch !important;
}

.terminal-link {
  color: #60a5fa !important;
  text-decoration: underline;
  cursor: pointer;
  font-weight: 500;
  transition: opacity 0.15s ease;
}

.terminal-link:hover {
  opacity: 0.85;
}

.modal-buttons {
  display: flex;
  gap: 12px;
  width: 100%;
}

.modal-buttons button {
  flex: 1;
  margin-top: 0;
}

/* Remove text selection block to allow touch events to pass for scrolling, rely on long-press callout prevention */
#terminal-container {
  -webkit-touch-callout: none !important;
  touch-action: none !important; /* Managed by JS Kinetic scroll simulator */
  will-change: transform !important;
  transform: translate3d(0, 0, 0) !important; /* Force GPU composite layer creation */
  background-color: var(--terminal-bg) !important; /* Set opaque background to prevent blending compositor slowdowns */
}

/* Mobile-specific adjustments to fit the connection card on a single screen without scrolling */
@media (max-width: 480px) {
  #connection-view {
    padding: 8px;
    justify-content: flex-start; /* Prevent centering clipping on very small screens */
    overflow-y: auto;
  }

  .connection-card {
    padding: 14px 16px;
    border-radius: 16px;
    margin: 8px 0;
  }

  .card-header {
    margin-bottom: 12px;
  }

  .logo {
    margin-bottom: 4px;
    gap: 6px;
  }

  .logo-icon {
    width: 24px;
    height: 24px;
  }

  .logo h1 {
    font-size: 22px;
  }

  .subtitle {
    font-size: 11px;
  }

  .form-group {
    margin-bottom: 8px;
    gap: 4px;
  }

  .form-row {
    gap: 8px;
  }

  label {
    font-size: 12px;
    gap: 4px;
  }

  input[type="text"],
  input[type="number"],
  input[type="password"],
  textarea {
    padding: 8px 10px;
    font-size: 13px;
    border-radius: 8px;
  }

  textarea {
    height: 60px; /* Reduce private key box height to fit screen */
  }

  .auth-toggle-group {
    border-radius: 6px;
  }

  .auth-btn {
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 5px;
  }

  .file-upload-trigger {
    padding: 8px;
    font-size: 12px;
    border-radius: 8px;
  }

  .form-row-checkbox {
    margin: 10px 0;
  }

  .checkbox-container {
    font-size: 11px;
    padding-left: 24px;
  }

  .checkmark {
    width: 16px;
    height: 16px;
  }

  .checkmark:after {
    left: 5px;
    top: 1px;
  }

  .submit-btn {
    padding: 10px;
    font-size: 14px;
    border-radius: 10px;
    margin-top: 4px;
  }

  .history-section {
    margin-top: 12px;
    padding-top: 10px;
  }

  .history-section h3 {
    margin-bottom: 6px;
  }

  .history-list {
    max-height: 80px;
    gap: 6px;
  }

  .history-item {
    padding: 6px 10px;
    border-radius: 6px;
  }

  .history-host {
    font-size: 12px;
  }

  .history-meta {
    font-size: 10px;
  }
}

/* Force native text selection compatibility in xterm.js DOM renderer */
.xterm,
.xterm-screen,
.xterm-rows,
.xterm-row,
.xterm-row span {
  user-select: text !important;
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
}

.xterm-screen,
.xterm-rows,
.xterm-row,
.xterm-row span {
  cursor: text !important;
}

/* Customize selection highlight colors globally */
::selection {
  background: rgba(99, 102, 241, 0.4) !important;
  color: #ffffff !important;
}
::-moz-selection {
  background: rgba(99, 102, 241, 0.4) !important;
  color: #ffffff !important;
}

/* Customize xterm.js internal selection overlay visual style if browser default is bypassed */
.xterm .xterm-selection div {
  background-color: rgba(99, 102, 241, 0.4) !important;
}

/* Enable native selection handles dragging on mobile touch devices when selection is active */
#terminal-container.touch-selectable,
#terminal-container.touch-selectable .xterm-screen {
  touch-action: auto !important;
  -webkit-touch-callout: default !important;
}

/* Helper Keyboard Edit Mode Styles */
@keyframes key-wiggle {
  0% { transform: rotate(-1deg); }
  50% { transform: rotate(1deg); }
  100% { transform: rotate(-1deg); }
}

#helper-keyboard {
  position: relative;
}

#helper-keyboard.edit-mode .helper-key {
  animation: key-wiggle 0.2s infinite ease-in-out;
  border-color: rgba(99, 102, 241, 0.5) !important;
  box-shadow: 0 0 5px rgba(99, 102, 241, 0.2);
  background: rgba(99, 102, 241, 0.08) !important;
}

#helper-keyboard.edit-mode .helper-key.dragging {
  animation: none !important;
  opacity: 0.3 !important;
  border: 1px dashed var(--primary-color) !important;
  background: rgba(99, 102, 241, 0.15) !important;
}

.helper-key.floating-drag {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  background: rgba(99, 102, 241, 0.4) !important;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-color: var(--primary-color) !important;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5);
  transform: scale(1.15);
  transition: none !important;
}

/* Edit Mode Overlay Button style */
.edit-done-btn {
  display: none;
  position: absolute;
  top: -38px;
  right: 12px;
  height: 30px;
  padding: 0 14px;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border: none;
  border-radius: 6px;
  color: white;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

#helper-keyboard.edit-mode .edit-done-btn {
  display: flex;
}

.edit-done-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(16, 185, 129, 0.4);
}

.edit-done-btn:active {
  transform: translateY(1px);
}

/* iOS Safari IME Korean input fix: Force helper textarea to be on-screen and opaque but visually hidden */
.xterm-helper-textarea {
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  width: 10px !important;
  height: 10px !important;
  opacity: 1 !important;
  color: transparent !important;
  background: transparent !important;
  caret-color: transparent !important;
  border: none !important;
  resize: none !important;
  outline: none !important;
  z-index: -1 !important;
  overflow: hidden !important;
  pointer-events: none !important;
}

/* DevTag Feature Styles */
body:not(.show-dev-tags) .dev-tag {
  display: none !important;
}

.dev-tag {
  user-select: none;
  pointer-events: none;
  font-family: monospace;
  font-size: 8px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  border: 1px solid #fcd34d !important; /* border-amber-300 */
  background-color: #fef3c7 !important; /* bg-amber-100 */
  color: #92400e !important; /* text-amber-800 */
  z-index: 9999 !important;
  font-weight: 600;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}
.dev-tag.absolute {
  position: absolute;
  top: 2px;
  left: 2px;
}
.dev-tag.relative {
  position: relative;
}
.dev-tag.inline {
  display: inline-block;
}

/* DEV Toggle Button */
.btn-toggle-devtags {
  position: fixed;
  right: 12px;
  bottom: 80px;
  z-index: 9999;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #e5e7eb;
  font-size: 10px;
  font-weight: 900;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: all 0.2s ease;
  background-color: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(4px);
  color: #9ca3af;
}
.btn-toggle-devtags.active {
  background-color: #fbbf24; /* bg-amber-400 */
  border-color: #f59e0b; /* border-amber-500 */
  color: #451a03; /* text-amber-950 */
  transform: scale(1.1);
}

/* Prevent text selection during layout editing */
body.edit-mode-active,
body.edit-mode-active * {
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-touch-callout: none !important;
}

/* Prompt Modal Styles */
.prompt-modal-card {
  width: 90%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  padding: 24px;
}

#prompt-input {
  width: 100%;
  height: 100px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 12px;
  resize: none;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#prompt-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.prompt-history-list {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 120px;
  overflow-y: auto;
}

.prompt-history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  transition: all 0.2s ease;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prompt-history-item:hover {
  background: rgba(99, 102, 241, 0.15);
  color: var(--text-primary);
}

.prompt-history-item-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 8px;
  text-align: left;
}

.prompt-history-item-delete {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.prompt-history-item-delete:hover {
  color: var(--danger-color);
  background: rgba(239, 68, 68, 0.15);
}

.helper-key.prompt-key {
  background: rgba(16, 185, 129, 0.1) !important;
  border-color: rgba(16, 185, 129, 0.2) !important;
  color: var(--accent-color) !important;
}

.helper-key.prompt-key:active {
  background: var(--accent-color) !important;
  color: white !important;
}

/* Helper Prompt Favorites Bar Styles */
.helper-prompt-favorites-bar {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  padding: 6px 12px;
  width: 100%;
  height: 38px;
  align-items: center;
  background: rgba(7, 9, 15, 0.95);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  box-sizing: border-box;
  scrollbar-width: none; /* Hide scrollbar for Firefox */
  touch-action: pan-x !important;
}

.helper-prompt-favorites-bar::-webkit-scrollbar {
  display: none; /* Hide scrollbar for Chrome/Safari */
}

.favorite-chip {
  display: inline-flex;
  align-items: center;
  background: rgba(251, 191, 36, 0.05);
  border: 1px solid rgba(251, 191, 36, 0.15);
  border-radius: 12px;
  padding: 3px 8px 3px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: #fbbf24;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  gap: 6px;
  height: 24px;
  box-sizing: border-box;
  user-select: none;
}

.favorite-chip:hover {
  background: rgba(251, 191, 36, 0.12);
  border-color: rgba(251, 191, 36, 0.3);
  color: #fef08a;
}

.favorite-chip .chip-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.favorite-chip .chip-star-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fbbf24;
}

.favorite-chip .chip-star-icon i {
  width: 10px;
  height: 10px;
}

.favorite-chip .chip-delete {
  background: none;
  border: none;
  color: rgba(251, 191, 36, 0.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  border-radius: 50%;
  width: 14px;
  height: 14px;
  transition: all 0.15s ease;
}

.favorite-chip .chip-delete:hover {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger-color);
}

.favorite-chip .chip-delete i {
  width: 8px;
  height: 8px;
}

/* Favorite Toggle Button Styles */
.helper-prompt-favorite-btn {
  height: 32px;
  width: 36px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.helper-prompt-favorite-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fbbf24;
}

.helper-prompt-favorite-btn.active {
  background: rgba(251, 191, 36, 0.15) !important;
  border-color: #fbbf24 !important;
  color: #fbbf24 !important;
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.3);
}

.helper-prompt-favorite-btn:active {
  transform: scale(0.95);
}

/* Modal Favorites List Styles */
.prompt-favorites-list {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 150px;
  overflow-y: auto;
  margin-bottom: 8px;
}

.prompt-favorites-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(251, 191, 36, 0.02);
  border: 1px solid rgba(251, 191, 36, 0.05);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #fbbf24;
  transition: all 0.2s ease;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prompt-favorites-item:hover {
  background: rgba(251, 191, 36, 0.1);
  color: #fef08a;
  border-color: rgba(251, 191, 36, 0.2);
}

.prompt-favorites-item-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 8px;
  text-align: left;
}

.prompt-favorites-item-delete {
  background: transparent;
  border: none;
  color: rgba(251, 191, 36, 0.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.prompt-favorites-item-delete:hover {
  color: var(--danger-color);
  background: rgba(239, 68, 68, 0.15);
}

/* History Item Star Button Styles */
.prompt-history-item-favorite {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.2s ease;
  margin-right: 4px;
}

.prompt-history-item-favorite:hover,
.prompt-history-item-favorite i.active-star {
  color: #fbbf24;
}

.prompt-history-item-favorite i.active-star {
  fill: #fbbf24;
}

/* Helper Prompt History Bar Styles */
.helper-prompt-history-bar {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  padding: 6px 12px;
  width: 100%;
  height: 38px;
  align-items: center;
  background: rgba(7, 9, 15, 0.95);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  box-sizing: border-box;
  scrollbar-width: none; /* Hide scrollbar for Firefox */
  touch-action: pan-x !important;
}

.helper-prompt-history-bar::-webkit-scrollbar {
  display: none; /* Hide scrollbar for Chrome/Safari */
}

.history-chip {
  display: inline-flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 3px 8px 3px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  gap: 6px;
  height: 24px;
  box-sizing: border-box;
  user-select: none;
}

.history-chip:hover {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.25);
  color: var(--text-primary);
}

.history-chip .chip-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.history-chip .chip-favorite {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  border-radius: 50%;
  width: 14px;
  height: 14px;
  transition: all 0.15s ease;
}

.history-chip .chip-favorite:hover {
  background: rgba(251, 191, 36, 0.15);
}

.history-chip .chip-favorite i {
  width: 8px;
  height: 8px;
}

.history-chip .chip-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  border-radius: 50%;
  width: 14px;
  height: 14px;
  transition: all 0.15s ease;
}

.history-chip .chip-delete:hover {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger-color);
}

.history-chip .chip-delete i {
  width: 8px;
  height: 8px;
}

/* Enter Toggle Button Styles */
.helper-prompt-enter-btn {
  height: 32px;
  width: 36px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.helper-prompt-enter-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.helper-prompt-enter-btn.active {
  background: rgba(99, 102, 241, 0.15) !important;
  border-color: var(--primary-color) !important;
  color: var(--primary-color) !important;
  box-shadow: 0 0 8px var(--primary-glow);
}

.helper-prompt-enter-btn:active {
  transform: scale(0.95);
}

/* Scroll Helper Floating Bar */
.scroll-helper-bar {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(13, 20, 35, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 8px;
  z-index: 100;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0.35;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* Hover / Active state */
.scroll-helper-bar:hover,
.scroll-helper-bar:focus-within,
.scroll-helper-bar.active {
  opacity: 1;
  background: rgba(13, 20, 35, 0.85);
  border-color: rgba(99, 102, 241, 0.3);
  box-shadow: 0 8px 32px rgba(99, 102, 241, 0.2);
}

.scroll-helper-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.scroll-helper-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
}

.scroll-helper-btn:active {
  background: var(--primary-color);
  color: #ffffff;
  transform: scale(0.9);
  box-shadow: 0 0 10px var(--primary-glow);
}

.scroll-helper-btn i {
  width: 18px;
  height: 18px;
  transition: transform 0.2s ease;
}

/* Collapsed state styles */
.scroll-helper-bar.collapsed {
  background: rgba(13, 20, 35, 0.4);
  border-radius: 50%;
  padding: 4px;
}

.scroll-helper-bar.collapsed:hover,
.scroll-helper-bar.collapsed.active {
  opacity: 1;
  background: rgba(13, 20, 35, 0.8);
}

.scroll-helper-bar.collapsed .scroll-helper-btn:not(.toggle-btn) {
  display: none;
}

.scroll-helper-bar.collapsed .toggle-btn i {
  transform: rotate(180deg); /* points to the left */
}

/* Adjustments for smaller screens */
@media (max-width: 480px) {
  .scroll-helper-bar {
    right: 8px;
    gap: 6px;
    padding: 6px;
  }
  .scroll-helper-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
  }
  .scroll-helper-btn i {
    width: 16px;
    height: 16px;
  }
}

/* Settings Trigger Button */
.settings-trigger-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-trigger-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.settings-trigger-btn i {
  width: 20px;
  height: 20px;
}

/* Settings Modal styles */
.settings-modal-card {
  width: 90%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  padding: 24px;
}

/* Mobile Optimization for Terminal Header & Action Buttons */
@media (max-width: 767px) {
  .terminal-header {
    height: 44px;
    padding: 0 10px;
  }

  .connection-info {
    font-size: 12px;
    gap: 6px;
    max-width: 45%;
  }

  .status-dot {
    width: 6px;
    height: 6px;
  }

  .terminal-actions {
    gap: 6px;
  }

  .action-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 6px;
    gap: 0;
  }

  .action-btn span {
    display: none !important;
  }

  .action-btn i,
  .action-btn svg {
    width: 16px;
    height: 16px;
  }
}

/* Scroll Helper Left-Side Alignment Option */
.scroll-helper-bar.left-side {
  right: auto;
  left: 12px;
}

@media (max-width: 480px) {
  .scroll-helper-bar.left-side {
    right: auto;
    left: 8px;
  }
}

/* Mirror the toggle button icons horizontally if positioned on the left side */
.scroll-helper-bar.left-side .toggle-btn i,
.scroll-helper-bar.left-side .toggle-btn svg {
  transform: scaleX(-1) !important;
}

/* File Explorer Sidebar */
.file-explorer-sidebar {
  width: 260px;
  min-width: 200px;
  max-width: 50%;
  background: rgba(10, 15, 30, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  margin-right: 8px;
  display: none; /* Hidden by default, toggled via .explorer-open class on .terminal-wrapper */
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  z-index: 10;
  touch-action: auto !important; /* Allow touch scrolling on mobile */
}

/* If explorer-open is set, show sidebar */
.terminal-wrapper.explorer-open .file-explorer-sidebar {
  display: flex;
}

/* Explorer Header */
.explorer-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(13, 20, 35, 0.5);
  flex-shrink: 0;
}

.explorer-title {
  display: flex;
  align-items: center;
  gap: 6px;
}

.explorer-icon {
  width: 16px;
  height: 16px;
  color: var(--primary-color);
}

.explorer-title h4 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.explorer-actions {
  display: flex;
  gap: 4px;
}

.explorer-action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.explorer-action-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.explorer-action-btn i,
.explorer-action-btn svg {
  width: 14px;
  height: 14px;
}

/* Explorer Tree Body */
.explorer-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  user-select: none;
  touch-action: pan-y !important; /* Allow vertical drag gesture for scrolling */
  -webkit-overflow-scrolling: touch !important; /* Smooth scrolling on iOS */
}

.explorer-status {
  padding: 12px;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  font-size: 11px;
}

/* File explorer tree items */
.explorer-item {
  display: flex;
  flex-direction: column;
}

.explorer-item-row {
  display: flex;
  align-items: center;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  color: var(--text-secondary);
  position: relative;
}

.explorer-item-row:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.explorer-item-row.active {
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
}

.explorer-item-row .chevron-icon {
  width: 12px;
  height: 12px;
  margin-right: 4px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.explorer-item-row .chevron-icon svg {
  width: 10px;
  height: 10px;
}

.explorer-item-row .chevron-icon.expanded {
  transform: rotate(90deg);
}

.explorer-item-row .item-icon {
  width: 14px;
  height: 14px;
  margin-right: 6px;
  flex-shrink: 0;
}

.explorer-item-row.folder-row .item-icon {
  color: #fbbf24; /* Amber folder color */
}

.explorer-item-row.file-row .item-icon {
  color: #9ca3af; /* Gray file color */
}

.explorer-item-row .item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

/* Tree children nesting */
.explorer-item-children {
  padding-left: 14px;
  display: none;
  border-left: 1px dashed rgba(255, 255, 255, 0.06);
  margin-left: 11px;
}

.explorer-item-children.expanded {
  display: block;
}

/* Explorer Item Row Context Actions */
.explorer-item-row .item-actions {
  display: none;
  gap: 2px;
  flex-shrink: 0;
  position: absolute;
  right: 6px;
  background: rgba(13, 20, 35, 0.9);
  padding: 0 4px;
  border-radius: 4px;
}

.explorer-item-row:hover .item-actions {
  display: flex;
}

.item-action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 18px;
  height: 18px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.item-action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.item-action-btn.danger:hover {
  color: #ef4444;
}

.item-action-btn i,
.item-action-btn svg {
  width: 11px;
  height: 11px;
}

/* Editor Modal Spec adjustments */
.editor-modal-card {
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6) !important;
  border: 1px solid rgba(99, 102, 241, 0.25) !important;
  touch-action: auto !important;
}

#editor-textarea {
  touch-action: auto !important;
}

/* Mobile responsive sidebar */
@media (max-width: 767px) {
  .file-explorer-sidebar {
    width: 200px;
    margin-right: 4px;
  }
}

@media (max-width: 480px) {
  .file-explorer-sidebar {
    position: absolute;
    top: 8px;
    left: 8px;
    bottom: 8px;
    width: calc(100% - 16px);
    max-width: 280px;
    z-index: 15;
    background: rgba(10, 15, 30, 0.96) !important;
    box-shadow: 0 10px 35px rgba(0, 0, 0, 0.7);
  }
}
