:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --primary: #0ea5e9;
  --primary-hover: #38bdf8;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --border: #334155;
  --toolbar-bg: #1e293b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(circle at top right, #0b253d, var(--bg) 40%);
  font-family: "IBM Plex Sans", "DejaVu Sans", sans-serif;
}

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  min-height: 100vh;
}

.layout.panel-collapsed {
  grid-template-columns: 0px 1fr;
}

.layout.panel-collapsed .panel {
  display: none;
}

/* ── Panel ── */
.panel {
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.95), rgba(17, 24, 39, 0.85));
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
  max-height: 100vh;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h1 {
  margin: 0;
  font-size: 1.6rem;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  margin: 0.25rem 0 0.8rem;
  color: var(--muted);
  font-size: 0.88rem;
}

/* ── Form elements ── */
label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  margin-bottom: 0.7rem;
  color: var(--muted);
  font-weight: 500;
}

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  padding: 0.55rem 0.65rem;
  transition: border-color 0.15s;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.15);
}

textarea {
  resize: vertical;
}

/* ── Buttons ── */
.actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

button {
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  transition: background 0.15s, opacity 0.15s;
}

button:hover {
  background: var(--primary-hover);
}

button.secondary {
  background: #334155;
  color: var(--text);
}

button.secondary:hover {
  background: #475569;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn {
  background: transparent;
  color: var(--muted);
  padding: 0.35rem 0.5rem;
  font-size: 1rem;
  line-height: 1;
  border-radius: 4px;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.small-btn {
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
}

.danger-btn {
  background: var(--danger);
  color: #fff;
}

.danger-btn:hover {
  background: #dc2626;
}

/* ── Status bar ── */
.status {
  margin-top: 0.7rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.7);
  font-size: 0.82rem;
  color: var(--muted);
  min-height: 2.2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background 0.3s;
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.status-dot.connecting {
  background: var(--warning);
  animation: pulse 1s infinite;
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
}

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

/* ── Saved connections ── */
.saved-connections {
  margin-bottom: 0.5rem;
}

.saved-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.3rem;
}

/* ── Terminal area ── */
.terminal-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.terminal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.75rem;
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--border);
  min-height: 36px;
}

.session-info {
  font-size: 0.8rem;
  color: var(--muted);
  font-family: 'Fira Code', 'DejaVu Sans Mono', monospace;
}

.toolbar-actions {
  display: flex;
  gap: 0.2rem;
  align-items: center;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.75rem;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
}

.search-bar input {
  flex: 1;
  padding: 0.3rem 0.5rem;
  font-size: 0.82rem;
}

#terminal {
  flex: 1;
  width: 100%;
  border: none;
  overflow: hidden;
  background: #020617;
}

/* ── Context menu ── */
.context-menu {
  position: fixed;
  z-index: 1000;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  min-width: 160px;
}

.ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 400;
  border-radius: 0;
}

.ctx-item:hover {
  background: rgba(14, 165, 233, 0.15);
}

/* ── Fullscreen ── */
.terminal-wrap.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 500;
  background: #020617;
}

/* ── Utilities ── */
.grid.two {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: 2fr 1fr;
}

.hidden {
  display: none !important;
}

/* ── Responsive ── */
@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
  }

  #terminal {
    min-height: 55vh;
  }

  .layout.panel-collapsed {
    grid-template-columns: 1fr;
  }
}

/* ── Scrollbar for terminal ── */
.xterm-viewport::-webkit-scrollbar {
  width: 8px;
}

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

.xterm-viewport::-webkit-scrollbar-thumb {
  background: #475569;
  border-radius: 4px;
}

.xterm-viewport::-webkit-scrollbar-thumb:hover {
  background: #64748b;
}
