* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0a0a0f;
  --surface: #141420;
  --surface2: #1e1e30;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --text: #e4e4e7;
  --text-dim: #71717a;
  --danger: #ef4444;
  --success: #22c55e;
  --border: #27272a;
  --tab-height: 44px;
}

html, body {
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  overflow: hidden;
}

/* Allow xterm's hidden textarea to receive mobile keyboard focus */
.xterm textarea.xterm-helper-textarea {
  position: absolute !important;
  opacity: 0 !important;
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  height: 100% !important;
  z-index: 10 !important;
  pointer-events: auto !important;
}

/* ---- Login ---- */
#login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
}
#login-screen h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--accent);
}
#login-screen p.sub {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 32px;
}
#login-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#login-form input {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
#login-form input:focus { border-color: var(--accent); }
#login-form button {
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
#login-form button:active { background: var(--accent-hover); }
#login-error {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  min-height: 20px;
}

/* ---- Main app ---- */
#app-screen { display: none; height: 100%; flex-direction: column; }
#app-screen.active { display: flex; }

/* Top bar */
#top-bar {
  display: flex;
  align-items: center;
  height: var(--tab-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#agent-status {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin: 0 10px;
  background: var(--danger);
  flex-shrink: 0;
}
#agent-status.connected { background: var(--success); }

#tab-bar {
  display: flex;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: none;
  gap: 2px;
  padding-right: 4px;
}
#tab-bar::-webkit-scrollbar { display: none; }

.tab {
  padding: 6px 14px;
  border-radius: 6px 6px 0 0;
  background: var(--bg);
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-bottom: none;
}
.tab.active {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
}
.tab .close-tab {
  font-size: 14px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 2px;
}
.tab .close-tab:hover { color: var(--danger); }

#btn-new-session {
  width: 36px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--accent);
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  margin: 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Terminal container */
#terminal-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}
.term-wrapper {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: none;
}
.term-wrapper.active { display: block; }
.term-wrapper .xterm { height: 100%; }

#no-sessions {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
  font-size: 15px;
  flex-direction: column;
  gap: 16px;
}
#no-sessions button {
  padding: 10px 24px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

/* ---- Modal ---- */
#modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}
#modal-overlay.active { display: flex; }

#modal {
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
}
#modal h2 {
  font-size: 18px;
  margin-bottom: 16px;
}
.modal-section {
  margin-bottom: 16px;
}
.modal-section label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.option-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.option-btn {
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
}
.option-btn.selected {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
#modal-launch {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}
#modal-launch:active { background: var(--accent-hover); }
#modal-cancel {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
}

/* ---- Input bar ---- */
#input-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#input-bar input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', 'Cascadia Code', monospace;
  font-size: 15px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
#input-bar input:focus { border-color: var(--accent); }
#input-bar button {
  padding: 10px 14px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
#input-bar button:active { background: var(--accent-hover); }
#special-keys {
  display: flex;
  gap: 4px;
  padding: 4px 8px 2px;
  background: var(--surface);
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}
#special-keys::-webkit-scrollbar { display: none; }
.skey {
  padding: 5px 10px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 11px;
  font-family: monospace;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.skey:active { background: var(--surface2); color: var(--text); }
