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

:root {
  --bg: #1a1a2e;
  --bg-light: #16213e;
  --text: #eaeaea;
  --text-muted: #888;
  --accent: #4dabf7;
  --header-height: 48px;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Prevent pull-to-refresh and scroll on mobile */
  overscroll-behavior: none;
  position: fixed;
  width: 100%;
  /* Prevent iOS rubber-banding */
  -webkit-overflow-scrolling: auto;
}

body {
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Header */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-height);
  flex-shrink: 0;
  padding: 0 12px;
  background: var(--bg-light);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  position: relative;
  z-index: 100;
}

#menu-btn {
  background: none;
  border: none;
  color: var(--text);
  padding: 8px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

#menu-btn:hover {
  background: rgba(255,255,255,0.1);
}

#menu-btn:active {
  background: rgba(255,255,255,0.2);
}

#session-title {
  font-size: 16px;
  font-weight: 500;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Status indicator */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #495057;
  transition: background 0.2s;
  flex-shrink: 0;
}

.status-dot.connected {
  background: #4ecdc4;
}

.status-dot.loading {
  background: #ffe66d;
  animation: pulse 0.5s ease-in-out infinite;
}

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

/* Navigation menu */
nav {
  position: absolute;
  top: var(--header-height);
  left: 0;
  right: 0;
  background: var(--bg-light);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  z-index: 99;
  max-height: calc(100vh - var(--header-height) - 100px);
  overflow-y: auto;
}

nav.hidden {
  display: none;
}

#session-list {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-btn {
  background: none;
  border: none;
  color: var(--text);
  padding: 12px 16px;
  text-align: left;
  cursor: pointer;
  border-radius: 6px;
  font-size: 15px;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.session-btn:hover {
  background: rgba(255,255,255,0.1);
}

.session-btn:active {
  background: rgba(255,255,255,0.2);
}

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

.no-sessions {
  padding: 16px;
  color: var(--text-muted);
  text-align: center;
}

/* Terminal container - height set by JavaScript */
main, #terminal-container {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--bg);
  /* Height is set dynamically by updateTerminalHeight() */
}

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

.xterm-viewport {
  overflow-y: hidden !important;
  /* Let tmux handle scrolling, not xterm */
}

.xterm-screen {
  height: 100% !important;
}

/* Hide scrollbar since tmux handles scrolling */
.xterm-viewport::-webkit-scrollbar {
  display: none;
}

/* Input toolbar - fixed at bottom */
#input-toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  padding-left: calc(12px + env(safe-area-inset-left));
  padding-right: calc(12px + env(safe-area-inset-right));
  background: var(--bg-light);
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  /* Prevent iOS from doing weird things */
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

.quick-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.key-btn {
  padding: 10px 14px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-family: Menlo, Monaco, monospace;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.key-btn:hover {
  background: rgba(255,255,255,0.15);
}

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

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

/* Input row - also used as form */
.input-row {
  display: flex;
  gap: 8px;
  margin: 0;
}

#text-input {
  flex: 1;
  padding: 10px 14px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px; /* Prevents iOS zoom on focus */
  font-family: Menlo, Monaco, monospace;
  outline: none;
  -webkit-appearance: none;
  /* Prevent iOS input quirks */
  -webkit-text-size-adjust: 100%;
  /* Prevent scroll-into-view behavior */
  scroll-margin: 0;
}

#text-input:focus {
  border-color: var(--accent);
  background: rgba(255,255,255,0.1);
}

#text-input::placeholder {
  color: var(--text-muted);
}

#send-btn {
  padding: 10px 20px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: var(--bg);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  /* Ensure button is touchable */
  touch-action: manipulation;
}

#send-btn:hover {
  opacity: 0.9;
}

#send-btn:active {
  opacity: 0.8;
}

/* Prevent text selection on UI elements */
header, footer, nav {
  user-select: none;
  -webkit-user-select: none;
}
