/* ==========================================================================
   SSH Terminal PWA — Styles
   Dark terminal theme with iOS PWA optimizations.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Autofill detection
   -------------------------------------------------------------------------- */
@keyframes onAutofill { from { opacity: 1; } to { opacity: 1; } }
input:-webkit-autofill { animation-name: onAutofill; }

/* --------------------------------------------------------------------------
   CSS Custom Properties
   -------------------------------------------------------------------------- */
:root {
  color-scheme: dark;

  --bg:       #1a1b26;
  --bg-light: #24283b;
  --bg-card:  #1f2335;
  --fg:       #a9b1d6;
  --fg-dim:   #7982a9;
  --fg-bright:#c0caf5;
  --accent:   #7aa2f7;
  --error:    #f7768e;
  --warning:  #e0af68;
  --success:  #9ece6a;
  --border:   #3b4261;
  --radius:   8px;
  --radius-lg:12px;
  --font-mono:'Menlo', 'Monaco', 'Courier New', monospace;
  --font-sans:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  /* Safe area insets */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

/* --------------------------------------------------------------------------
   Reset / Normalize
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background-color: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  width: 100%;
}

/* Focus visible for keyboard users */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* --------------------------------------------------------------------------
   Login Screen
   -------------------------------------------------------------------------- */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 1rem;
  padding-top: calc(1rem + var(--sat));
  padding-bottom: calc(1rem + var(--sab));
  background: var(--bg);
  overflow-y: auto;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.login-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.login-logo {
  flex-shrink: 0;
}

.login-title {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--fg-bright);
  letter-spacing: -0.02em;
}

/* Form */
.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.form-group label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--fg);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.form-group input {
  /* 16px prevents iOS auto-zoom on focus */
  font-size: 16px;
  font-family: var(--font-mono);
  padding: 0.625rem 0.75rem;
  background: var(--bg);
  color: var(--fg-bright);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(122, 162, 247, 0.2);
}

.form-group input::placeholder {
  color: var(--fg-dim);
}

/* Remove number input spinners */
.form-group input[type="number"]::-webkit-inner-spin-button,
.form-group input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.form-group input[type="number"] {
  -moz-appearance: textfield;
}

/* Login error */
.login-error {
  font-size: 0.875rem;
  color: var(--error);
  padding: 0.5rem 0.75rem;
  background: rgba(247, 118, 142, 0.1);
  border: 1px solid rgba(247, 118, 142, 0.3);
  border-radius: var(--radius);
  text-align: center;
}

.login-error[hidden] {
  display: none;
}

/* Login button */
.login-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font-sans);
  color: var(--bg);
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
}

.login-button:hover {
  background: #89b4fa;
}

.login-button:active {
  background: #6d8fd6;
}

.login-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Spinner */
.login-button-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid transparent;
  border-top-color: var(--bg);
  border-right-color: var(--bg);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.login-button-spinner[hidden] {
  display: none;
}

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

/* Footer */
.login-footer {
  margin-top: 1.5rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--fg-dim);
}

/* --------------------------------------------------------------------------
   Terminal Screen
   -------------------------------------------------------------------------- */
.terminal-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background: var(--bg);
  overflow: hidden;
  position: relative;
}

.terminal-screen[hidden] {
  display: none;
}

/* Status bar */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding: 0.375rem 0.75rem;
  padding-top: calc(0.375rem + var(--sat));
  padding-left: calc(0.75rem + var(--sal));
  padding-right: calc(0.75rem + var(--sar));
  background: var(--bg-light);
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--fg);
  min-height: 36px;
  z-index: 10;
  /* Force own compositing layer so GPU renders it above xterm.js canvas */
  transform: translateZ(0);
}

.status-bar-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
}

.status-bar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

/* Status dot */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot--connected {
  background: var(--success);
  box-shadow: 0 0 6px rgba(158, 206, 106, 0.5);
}

.status-dot--reconnecting {
  background: var(--warning);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-dot--disconnected {
  background: var(--error);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.status-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-latency {
  color: var(--fg-dim);
  white-space: nowrap;
}

/* Font size controls */
.font-size-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  border: none;
  padding: 0;
  margin: 0;
  min-width: 0;
}

.font-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  /* Ensure 44x44 touch target via padding even though visual is 28x28 */
  padding: 0;
  min-width: 28px;
  min-height: 28px;
  position: relative;
  transition: background-color 0.1s ease, border-color 0.1s ease;
}

/* Expand touch target to 44px using ::after pseudo-element */
.font-btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
}

.font-btn:hover {
  background: var(--bg-light);
  border-color: var(--accent);
}

.font-btn:active {
  background: var(--bg);
  border-color: var(--accent);
}

.font-size-display {
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  color: var(--fg-dim);
  min-width: 20px;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
}

/* Disconnect button */
.disconnect-button {
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  padding: 0.25rem 0.5rem;
  color: var(--error);
  background: transparent;
  border: 1px solid var(--error);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
  min-height: 28px;
  min-width: 44px;
  -webkit-appearance: none;
  appearance: none;
}

.disconnect-button:hover {
  background: rgba(247, 118, 142, 0.15);
}

.disconnect-button:active {
  background: rgba(247, 118, 142, 0.25);
}

/* Terminal container.
   contain: paint creates a hard GPU paint boundary that clips the
   xterm.js canvas even when iOS promotes it to a compositing layer.
   overflow: clip prevents layout side-effects from canvas overflow. */
.terminal-container {
  flex: 1 1 auto;
  /* Allow shrinking below content size (xterm canvas) when the
     parent height is constrained by the iOS keyboard workaround.
     Without this, the canvas min-content height pushes the
     keyboard-toolbar off-screen. */
  min-height: 0;
  overflow: clip;
  contain: paint;
}

/* Padding lives on .xterm (not the parent) so that FitAddon's
   proposeDimensions() correctly subtracts it from the available
   height.  With the global box-sizing:border-box, parent padding
   is included in getComputedStyle().height but FitAddon only
   subtracts the element's own padding — causing an extra row. */
.terminal-container .xterm {
  height: 100%;
  padding: 4px;
}

.terminal-container .xterm-viewport {
  overflow-y: auto !important;
}

/* Disable text helpers on terminal textarea (iOS) */
.terminal-container .xterm-helper-textarea {
  font-size: 16px !important;
  opacity: 0;
  caret-color: transparent;
}

/* --------------------------------------------------------------------------
   Disconnect Overlay
   -------------------------------------------------------------------------- */
.disconnect-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26, 27, 38, 0.85);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.disconnect-overlay[hidden] {
  display: none;
}

.disconnect-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding: 2rem;
  max-width: 320px;
  width: calc(100% - 2rem);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.disconnect-overlay-message {
  font-size: 0.9375rem;
  color: var(--fg);
  line-height: 1.5;
}

.disconnect-overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}

.disconnect-overlay-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font-sans);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
}

.disconnect-overlay-btn--primary {
  color: var(--bg);
  background: var(--accent);
}

.disconnect-overlay-btn--primary:hover {
  background: #89b4fa;
}

.disconnect-overlay-btn--primary:active {
  background: #6d8fd6;
}

.disconnect-overlay-btn--secondary {
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border);
}

.disconnect-overlay-btn--secondary:hover {
  background: var(--bg-light);
}

.disconnect-overlay-btn--secondary:active {
  background: var(--bg);
}

/* --------------------------------------------------------------------------
   Keyboard Toolbar
   -------------------------------------------------------------------------- */
.keyboard-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  padding: 6px 8px;
  padding-bottom: calc(6px + var(--sab));
  padding-left: calc(8px + var(--sal));
  padding-right: calc(8px + var(--sar));
  background: var(--bg-light);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  z-index: 10;
  /* Force own compositing layer so GPU renders it above xterm.js canvas */
  transform: translateZ(0);
  /* Hide scrollbar for a cleaner look */
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* Hide toolbar on desktop (mouse-primary devices) */
@media (hover: hover) and (pointer: fine) {
  .keyboard-toolbar {
    display: none;
  }
}

.kb-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  /* min-height 44px satisfies Apple HIG touch target.
     min-width is reduced so 8 buttons fit on narrow screens;
     flex-shrink allows further compression before scrolling. */
  min-width: 36px;
  min-height: 44px;
  padding: 0 6px;
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  flex-shrink: 1;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-appearance: none;
  appearance: none;
  transition: background-color 0.1s ease, border-color 0.1s ease;
}

.kb-btn:active {
  background: var(--bg-light);
  border-color: var(--accent);
}

/* Toggle state for Ctrl / Alt */
.kb-btn--toggle[aria-pressed="true"] {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* Ctrl+C danger highlight */
.kb-btn--danger {
  color: var(--error);
  border-color: rgba(247, 118, 142, 0.4);
}

.kb-btn--danger:active {
  background: rgba(247, 118, 142, 0.15);
  border-color: var(--error);
}

/* Settings gear button */
.kb-btn--settings {
  color: var(--fg-dim);
  border-style: dashed;
}

.kb-btn--settings:active {
  color: var(--accent);
}

.keyboard-toolbar::-webkit-scrollbar {
  display: none;
}

/* --------------------------------------------------------------------------
   Keyboard Variant Popup (long-press)
   -------------------------------------------------------------------------- */
.kb-variant-popup {
  position: fixed;
  z-index: 9999;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px;
  max-width: calc(100vw - 16px);
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.kb-variant-item {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 8px;
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--accent);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-appearance: none;
  appearance: none;
  transition: background-color 0.1s ease, border-color 0.1s ease;
}

.kb-variant-item:active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* --------------------------------------------------------------------------
   Keyboard Settings Panel
   -------------------------------------------------------------------------- */
.kb-settings-panel {
  flex-shrink: 0;
  padding: 12px;
  padding-left: calc(12px + var(--sal));
  padding-right: calc(12px + var(--sar));
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  max-height: 40vh;
  overflow-y: auto;
  z-index: 10;
}

.kb-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.kb-settings-title {
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--fg-bright);
}

.kb-settings-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 1rem;
  color: var(--fg-dim);
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  position: relative;
}

/* 44px touch target */
.kb-settings-close::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
}

.kb-settings-close:active {
  color: var(--fg-bright);
  background: var(--bg-light);
}

.kb-settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.kb-settings-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  min-height: 36px;
}

.kb-settings-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.kb-settings-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.kb-settings-apply,
.kb-settings-reset {
  padding: 6px 16px;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-mono);
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  min-height: 36px;
  min-width: 44px;
  transition: background-color 0.1s ease;
}

.kb-settings-apply {
  color: var(--bg);
  background: var(--accent);
  border: none;
}

.kb-settings-apply:active {
  background: #6d8fd6;
}

.kb-settings-reset {
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--border);
}

.kb-settings-reset:active {
  background: var(--bg-light);
}

/* --------------------------------------------------------------------------
   Responsive Adjustments
   -------------------------------------------------------------------------- */

/* Landscape on small screens: tighten spacing, hide status text */
@media (max-height: 500px) and (orientation: landscape) {
  .status-bar {
    min-height: 24px;
    padding-top: calc(0.125rem + var(--sat));
    padding-bottom: 0.125rem;
    font-size: 0.625rem;
  }

  /* Hide status text in landscape — just show the dot indicator */
  .status-text {
    display: none;
  }

  /* Hide latency text in landscape */
  .status-latency {
    display: none;
  }

  /* Compact font controls in landscape */
  .font-btn {
    width: 24px;
    height: 24px;
    font-size: 0.8125rem;
    min-width: 24px;
    min-height: 24px;
  }

  .font-size-display {
    font-size: 0.5625rem;
    min-width: 16px;
  }

  /* Compact disconnect button in landscape */
  .disconnect-button {
    font-size: 0.5625rem;
    padding: 0.125rem 0.375rem;
    min-height: 24px;
  }

  /* Compact download button in landscape */
  .download-button {
    font-size: 0.5625rem;
    padding: 0.125rem 0.375rem;
    min-height: 24px;
  }

  /* Compact tab bar in landscape */
  .tab-bar {
    min-height: 24px;
    padding: 2px 8px;
  }

  .tab-item {
    font-size: 0.5625rem;
    padding: 2px 6px;
  }

  .keyboard-toolbar {
    padding-top: 3px;
    padding-bottom: calc(3px + var(--sab));
    gap: 3px;
  }

  .kb-btn {
    min-height: 36px;
    min-width: 36px;
    font-size: 0.75rem;
    padding: 0 6px;
  }

  /* Hide settings gear in landscape to save space */
  .kb-btn--settings {
    min-width: 30px;
  }

  /* Compact variant popup in landscape */
  .kb-variant-item {
    min-height: 36px;
    min-width: 36px;
    font-size: 0.75rem;
  }
}

/* JS-driven landscape class for additional optimizations */
.terminal-screen.landscape .status-bar {
  /* Use full viewport width with minimal padding */
  padding-left: calc(0.375rem + var(--sal));
  padding-right: calc(0.375rem + var(--sar));
}

.terminal-screen.landscape .status-bar-right {
  gap: 0.375rem;
}

/* Small mobile portrait */
@media (max-width: 380px) {
  .login-card {
    padding: 1.25rem;
  }

  .login-title {
    font-size: 1.25rem;
  }

  .kb-btn {
    min-width: 38px;
    padding: 0 6px;
    font-size: 0.75rem;
  }
}

/* --------------------------------------------------------------------------
   Reduced Motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --------------------------------------------------------------------------
   SSH Key Toggle
   -------------------------------------------------------------------------- */
.ssh-key-toggle {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--fg-dim);
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
  text-align: center;
}

.ssh-key-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.ssh-key-toggle[aria-expanded="true"] {
  color: var(--accent);
  border-color: var(--accent);
  border-style: solid;
}

.form-group textarea {
  font-size: 14px;
  font-family: var(--font-mono);
  padding: 0.625rem 0.75rem;
  background: var(--bg);
  color: var(--fg-bright);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
  min-height: 80px;
  max-height: 200px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
}

.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(122, 162, 247, 0.2);
  outline: none;
}

.form-group textarea::placeholder {
  color: var(--fg-dim);
}

/* --------------------------------------------------------------------------
   Tab Bar
   -------------------------------------------------------------------------- */
.tab-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  padding: 4px 8px;
  padding-left: calc(8px + var(--sal));
  padding-right: calc(8px + var(--sar));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  z-index: 10;
  min-height: 32px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.tab-bar::-webkit-scrollbar {
  display: none;
}

.tab-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  color: var(--fg-dim);
  background: var(--bg-light);
  border: 1px solid transparent;
  border-radius: 4px 4px 0 0;
  cursor: pointer;
  white-space: nowrap;
  max-width: 160px;
  flex-shrink: 0;
  transition: background-color 0.1s ease, color 0.1s ease;
  user-select: none;
  -webkit-user-select: none;
}

.tab-item:hover {
  color: var(--fg);
  background: var(--bg-card);
}

.tab-item--active {
  color: var(--fg-bright);
  background: var(--bg-card);
  border-color: var(--border);
  border-bottom-color: var(--bg-card);
}

.tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.tab-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-size: 0.75rem;
  color: var(--fg-dim);
  background: transparent;
  border: none;
  border-radius: 2px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  -webkit-appearance: none;
  appearance: none;
  position: relative;
}

/* Expand touch target for close button */
.tab-close::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 28px;
}

.tab-close:hover {
  color: var(--error);
  background: rgba(247, 118, 142, 0.15);
}

.tab-add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--fg-dim);
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-appearance: none;
  appearance: none;
  transition: color 0.1s ease, border-color 0.1s ease;
  position: relative;
}

/* Expand touch target for add button */
.tab-add-btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
}

.tab-add-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.tab-add-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Terminals wrapper — fills remaining space */
.terminals-wrapper {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}

.terminals-wrapper .terminal-container {
  position: absolute;
  inset: 0;
}

.terminals-wrapper .terminal-container[hidden] {
  display: none;
}

/* --------------------------------------------------------------------------
   Download Button
   -------------------------------------------------------------------------- */
.download-button {
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  padding: 0.25rem 0.5rem;
  color: var(--fg-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
  min-height: 28px;
  min-width: 44px;
  -webkit-appearance: none;
  appearance: none;
}

.download-button:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.download-button:active {
  color: var(--fg-bright);
  background: var(--bg-light);
}

/* --------------------------------------------------------------------------
   Paste Overlay (long-press)
   -------------------------------------------------------------------------- */
.paste-overlay {
  position: fixed;
  z-index: 9999;
  display: flex;
  gap: 6px;
  padding: 6px;
  width: calc(100vw - 16px);
  max-width: 320px;
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.paste-overlay-input {
  flex: 1;
  font-size: 16px;
  font-family: var(--font-mono);
  padding: 8px 10px;
  background: var(--bg);
  color: var(--fg-bright);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  -webkit-appearance: none;
  appearance: none;
}

.paste-overlay-input::placeholder {
  color: var(--fg-dim);
}


/* --------------------------------------------------------------------------
   Utility
   -------------------------------------------------------------------------- */
[hidden] {
  display: none !important;
}
