/* ── Reset & base ──────────────────────────────────────────────────────────── */

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

:root {
  --bg:       #0f1419;
  --bg2:      #1a2332;
  --bg3:      #243044;
  --accent:   #4fc3f7;
  --accent2:  #29b6f6;
  --text:     #e8eaf0;
  --text-dim: #8899aa;
  --border:   #2a3a4e;
  --danger:   #ef5350;
  --tab-h:    44px;
  --bar-h:    52px;
  --safe-b:   env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  padding: 0 10px;
  height: 32px;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.1s, color 0.1s;
}

button:active { background: var(--bg2); }

/* ── Login screen ──────────────────────────────────────────────────────────── */

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  padding: 24px;
}

.login-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-icon { font-size: 48px; margin-bottom: 12px; }

.login-box h1 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 28px;
  letter-spacing: 0.5px;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#login-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;  /* prevent zoom on iOS */
  padding: 12px 14px;
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
}

#login-form input:focus { border-color: var(--accent); }

#login-form button {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  height: 44px;
  width: 100%;
  transition: background 0.15s;
}

#login-form button:active { background: var(--accent2); }

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
}

/* ── App layout ────────────────────────────────────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  width: 100%;
}

/* ── Tab bar ───────────────────────────────────────────────────────────────── */

#tab-bar {
  display: flex;
  align-items: center;
  height: var(--tab-h);
  min-height: var(--tab-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 6px;
  gap: 4px;
  overflow: hidden;
}

#tab-list {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  flex: 1;
  scrollbar-width: none;
}
#tab-list::-webkit-scrollbar { display: none; }

.tab {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 10px;
  height: 30px;
  border-radius: 6px;
  background: var(--bg3);
  border: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  font-size: 13px;
  flex-shrink: 0;
  transition: background 0.1s;
}

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

.tab-label {
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  outline: none;
  cursor: pointer;
}

.tab-label[contenteditable="true"] {
  cursor: text;
  border-bottom: 1px solid var(--accent);
}

.tab-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  height: auto;
  padding: 0 2px;
  border-radius: 3px;
  line-height: 1;
  min-width: 0;
}

.tab-close:hover { color: var(--danger); background: none; }

#new-tab-btn {
  font-size: 18px;
  font-weight: 300;
  width: 30px;
  height: 30px;
  padding: 0;
  flex-shrink: 0;
  border-color: var(--accent);
  color: var(--accent);
}

.tab-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

#font-decrease, #font-increase {
  font-size: 11px;
  width: 28px;
  padding: 0;
}

#logout-btn {
  font-size: 14px;
  width: 30px;
  padding: 0;
  color: var(--text-dim);
}

/* ── Terminal container ────────────────────────────────────────────────────── */

#terminal-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}

.term-pane {
  position: absolute;
  inset: 0;
  padding: 4px;
  display: none;
}

.term-pane.active { display: block; }

/* xterm overrides */
.xterm {
  height: 100%;
}

.xterm-viewport {
  overflow-y: auto !important;
  scrollbar-width: thin;
  scrollbar-color: var(--bg3) transparent;
}

.xterm-viewport::-webkit-scrollbar { width: 6px; }
.xterm-viewport::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 3px; }

/* Disconnect overlay */
.disconnected-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 20, 25, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 14px;
  color: var(--text-dim);
  z-index: 10;
}

.disconnected-overlay button {
  background: var(--accent);
  color: #000;
  border: none;
  font-weight: 600;
  height: 40px;
  padding: 0 24px;
}

/* ── Shortcut bar ──────────────────────────────────────────────────────────── */

#shortcut-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: var(--bar-h);
  min-height: var(--bar-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 0 6px;
  padding-bottom: max(6px, var(--safe-b));
  overflow-x: auto;
  scrollbar-width: none;
  /* Float above virtual keyboard */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
}

/* Space so the terminal isn't hidden behind the fixed shortcut bar */
#terminal-container {
  padding-bottom: var(--bar-h);
}

#shortcut-bar::-webkit-scrollbar { display: none; }

.key-btn {
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  height: 36px;
  min-width: 36px;
  padding: 0 8px;
  flex-shrink: 0;
  background: var(--bg3);
  border-color: var(--border);
}

.key-btn:active { background: var(--accent); color: #000; border-color: var(--accent); }

#copy-btn {
  font-size: 15px;
  height: 36px;
  width: 36px;
  padding: 0;
  margin-left: auto;
  flex-shrink: 0;
  background: var(--bg3);
}

#copy-btn.copied {
  color: var(--accent);
  border-color: var(--accent);
}

.enter-btn {
  color: var(--accent);
  border-color: var(--accent) !important;
  min-width: 44px;
}

#paste-btn {
  font-size: 15px;
  height: 36px;
  width: 36px;
  padding: 0;
  flex-shrink: 0;
  background: var(--bg3);
}

/* ── Tab status dots ───────────────────────────────────────────────────────── */

.tab-status {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4caf50;
  flex-shrink: 0;
}

.tab.disconnected .tab-status { background: var(--danger); }
.tab.connecting .tab-status { background: #ffc107; }

/* ── Copy modal ────────────────────────────────────────────────────────────── */

.copy-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}

.copy-modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  padding: 0 0 max(16px, var(--safe-b));
}

.copy-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
}

.copy-modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  height: auto;
  padding: 4px 8px;
}

.copy-modal-text {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: none;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  line-height: 1.5;
  padding: 12px 16px;
  resize: none;
  overflow-y: auto;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}

.copy-modal-all {
  margin: 10px 16px 0;
  background: var(--accent);
  color: #000;
  border: none;
  font-weight: 600;
  height: 44px;
  width: calc(100% - 32px);
  border-radius: 8px;
  font-size: 15px;
}
