/* ==========================================================================
   Tuimux — Terminal Styles
   ========================================================================== */

/* ---------- Terminal Container ---------- */
.terminal-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-primary);
}

.terminal-wrapper {
  position: absolute;
  inset: 0;
  display: none;
}

.terminal-wrapper.active {
  display: flex;
  flex-direction: column;
}

/* xterm.js container */
.terminal-wrapper .xterm-viewport {
  overflow-y: auto;
}

.terminal-wrapper .xterm {
  height: 100%;
  padding: 4px;
}

.terminal-wrapper .xterm-screen {
  width: 100% !important;
}

.terminal-wrapper .xterm-viewport::-webkit-scrollbar {
  width: 6px;
}

.terminal-wrapper .xterm-viewport::-webkit-scrollbar-track {
  background: transparent;
}

.terminal-wrapper .xterm-viewport::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 3px;
}

.terminal-wrapper .xterm-viewport::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ---------- Terminal Search Bar ---------- */
.terminal-search {
  position: absolute;
  top: 0;
  right: 16px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transform: translateY(-100%);
  transition: transform 0.2s ease;
  opacity: 0;
  pointer-events: none;
}

.terminal-search.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: all;
}

.terminal-search input {
  width: 220px;
  height: 26px;
  padding: 0 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font-mono);
  outline: none;
}

.terminal-search input:focus {
  border-color: var(--accent);
}

.terminal-search .search-count {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  min-width: 40px;
  text-align: center;
}

.terminal-search .search-nav {
  display: flex;
  gap: 2px;
}

.terminal-search .search-nav button,
.terminal-search .search-close {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: background 0.1s, color 0.1s;
}

.terminal-search .search-nav button:hover,
.terminal-search .search-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ---------- Error Banner ---------- */
.terminal-error {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(247, 118, 142, 0.12);
  border-bottom: 1px solid rgba(247, 118, 142, 0.3);
  color: var(--error);
  font-size: 13px;
  animation: error-slide-in 0.2s ease-out;
}

@keyframes error-slide-in {
  from { transform: translateY(-100%); }
  to   { transform: translateY(0); }
}

.terminal-error .error-icon {
  flex-shrink: 0;
  font-size: 16px;
}

.terminal-error .error-message {
  flex: 1;
}

.terminal-error .error-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.terminal-error .error-actions button {
  height: 26px;
  padding: 0 10px;
  border: 1px solid rgba(247, 118, 142, 0.3);
  border-radius: 4px;
  background: transparent;
  color: var(--error);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

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

.terminal-error .error-dismiss {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--error);
  cursor: pointer;
  border-radius: 4px;
  font-size: 16px;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.terminal-error .error-dismiss:hover {
  opacity: 1;
}

/* ---------- Connecting State ---------- */
.terminal-connecting {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg-primary);
  z-index: 5;
}

.terminal-connecting .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.terminal-connecting .connecting-text {
  font-size: 13px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.terminal-connecting .connecting-host {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ---------- Terminal Too Small Overlay ---------- */
.terminal-too-small {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(26, 27, 38, 0.9);
  backdrop-filter: blur(2px);
  z-index: 6;
  text-align: center;
  padding: 24px;
}

.terminal-too-small .icon {
  font-size: 28px;
  color: var(--warning);
}

.terminal-too-small .message {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
}

.terminal-too-small .hint {
  font-size: 12px;
  color: var(--text-muted);
}

.terminal-too-small .dimensions {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  padding: 4px 10px;
  background: var(--bg-elevated);
  border-radius: 4px;
}

/* ---------- Broadcast Mode ---------- */
.terminal-wrapper.broadcast {
  outline: 2px solid var(--warning);
  outline-offset: -2px;
}

.terminal-wrapper.broadcast::before {
  content: 'BROADCAST';
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  padding: 2px 10px;
  background: var(--warning);
  color: var(--bg-primary);
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 1px;
  border-radius: 0 0 4px 4px;
  pointer-events: none;
}

/* ---------- Grid Layout (Split Panes) ---------- */
.terminal-grid {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 0;
}

/* Layouts */
.terminal-grid.layout-1x1 {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.terminal-grid.layout-1x2 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
}

.terminal-grid.layout-2x1 {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr 1fr;
}

.terminal-grid.layout-2x2 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.terminal-grid.layout-1x3 {
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr;
}

.terminal-grid.layout-3x1 {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}

/* Grid pane */
.terminal-pane {
  position: relative;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.terminal-pane .xterm {
  height: 100%;
  width: 100%;
}

.terminal-pane.focused {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

.terminal-pane.focused::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(122, 162, 247, 0.3);
}

/* Pane label (top-left badge) */
.terminal-pane .pane-label {
  position: absolute;
  top: 2px;
  left: 6px;
  z-index: 3;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.terminal-pane:hover .pane-label,
.terminal-pane.focused .pane-label {
  opacity: 1;
}

/* ---------- Pane Divider ---------- */
.pane-divider {
  position: absolute;
  z-index: 4;
  background: var(--border);
  transition: background 0.15s;
}

.pane-divider:hover,
.pane-divider.dragging {
  background: var(--accent);
}

.pane-divider.horizontal {
  height: 4px;
  left: 0;
  right: 0;
  cursor: row-resize;
  margin-top: -2px;
}

.pane-divider.vertical {
  width: 4px;
  top: 0;
  bottom: 0;
  cursor: col-resize;
  margin-left: -2px;
}

.pane-divider::after {
  content: '';
  position: absolute;
}

.pane-divider.horizontal::after {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 2px;
  border-radius: 1px;
  background: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s;
}

.pane-divider.vertical::after {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 32px;
  border-radius: 1px;
  background: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s;
}

.pane-divider:hover::after,
.pane-divider.dragging::after {
  opacity: 1;
}

/* ---------- Terminal Status Bar ---------- */
.terminal-statusbar {
  height: 22px;
  min-height: 22px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 12px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.terminal-statusbar .status-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.terminal-statusbar .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.terminal-statusbar .status-dot.connected    { background: var(--success); }
.terminal-statusbar .status-dot.disconnected { background: var(--text-muted); }
.terminal-statusbar .status-dot.error        { background: var(--error); }

.terminal-statusbar .spacer {
  flex: 1;
}

.terminal-statusbar .dimensions-display {
  color: var(--text-muted);
}

/* ---------- Resize Indicator ---------- */
.terminal-resize-indicator {
  position: absolute;
  bottom: 28px;
  right: 12px;
  z-index: 7;
  padding: 4px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.terminal-resize-indicator.visible {
  opacity: 1;
}

/* ---------- Selection / Copy Feedback ---------- */
.copy-feedback {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 8px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 13px;
  color: var(--accent);
  font-family: var(--font-mono);
  pointer-events: none;
  z-index: 7;
  animation: copy-fade 0.8s ease-out forwards;
}

@keyframes copy-fade {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -60%) scale(0.95);
  }
}

/* ---------- Drop Zone (Drag file to upload) ---------- */
.terminal-dropzone {
  position: absolute;
  inset: 0;
  z-index: 11;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(26, 27, 38, 0.85);
  backdrop-filter: blur(4px);
  border: 2px dashed var(--accent);
}

.terminal-dropzone.active {
  display: flex;
}

.terminal-dropzone .drop-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--accent);
}

.terminal-dropzone .drop-label .icon {
  font-size: 36px;
  opacity: 0.8;
}

/* ---------- Reconnect Banner ---------- */
.terminal-reconnect {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  font-size: 13px;
  color: var(--text-primary);
  animation: reconnect-in 0.2s ease-out;
}

@keyframes reconnect-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.terminal-reconnect .reconnect-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.terminal-reconnect button {
  height: 24px;
  padding: 0 10px;
  background: var(--accent);
  border: none;
  border-radius: 4px;
  color: var(--bg-primary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.terminal-reconnect button:hover {
  background: var(--accent-hover);
}
