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

:root {
  --bg: #1e1e2e;
  --surface: #2a2a3e;
  --surface2: #33334a;
  --border: #3a3a4e;
  --text: #cdd6f4;
  --subtext: #a6adc8;
  --accent: #89b4fa;
  --success: #a6e3a1;
  --warning: #f9e2af;
  --error: #f38ba8;
  --btn-bg: #3a3a5e;
  --btn-hover: #4a4a6e;
  --radius: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

/* === Login Page === */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 30px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 8px;
  color: var(--accent);
}

.login-card .subtitle {
  color: var(--subtext);
  font-size: 0.85rem;
  margin-bottom: 24px;
}

.login-card input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px; /* prevent iOS zoom */
  outline: none;
  margin-bottom: 16px;
}

.login-card input:focus {
  border-color: var(--accent);
}

.login-card button {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #1e1e2e;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.login-card button:active {
  opacity: 0.85;
}

.error-msg {
  color: var(--error);
  font-size: 0.85rem;
  margin-top: 12px;
  min-height: 1.2em;
}

/* === Projects Page === */
.projects-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.projects-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.projects-header h1 {
  font-size: 1.1rem;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.btn-new {
  padding: 8px 16px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #1e1e2e;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-new:active { opacity: 0.85; }

.btn-logout {
  padding: 8px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--subtext);
  font-size: 0.85rem;
  cursor: pointer;
}

.project-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.project-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.project-card:active {
  border-color: var(--accent);
}

.project-card .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.project-card .name {
  font-size: 1.05rem;
  font-weight: 600;
}

.btn-delete {
  width: 32px;
  height: 32px;
  background: #f38ba822;
  border: 1px solid #f38ba844;
  border-radius: 6px;
  color: var(--error);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-delete:active {
  background: #f38ba844;
}

.project-card .path {
  font-size: 0.78rem;
  color: var(--subtext);
  word-break: break-all;
  margin-bottom: 6px;
}

.project-card .meta {
  display: flex;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--subtext);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-git {
  background: #a6e3a122;
  color: var(--success);
}

.badge-time {
  background: #89b4fa22;
  color: var(--accent);
}

.badge-web {
  background: #f9e2af22;
  color: var(--warning);
}

/* === 2FA Banner === */
.totp-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: #f9e2af15;
  border-bottom: 1px solid #f9e2af33;
  color: var(--warning);
  font-size: 0.85rem;
  flex-shrink: 0;
}

.totp-banner.hidden { display: none; }

.btn-setup-2fa {
  flex-shrink: 0;
  padding: 6px 14px;
  background: var(--warning);
  border: none;
  border-radius: var(--radius);
  color: #1e1e2e;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-setup-2fa:active { opacity: 0.85; }

/* === Terminal Page === */
.terminal-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}

.terminal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 48px;
}

.project-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
  min-width: 0;
}

.project-info .name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-info .path {
  font-size: 0.72rem;
  color: var(--subtext);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-switch {
  flex-shrink: 0;
  margin-left: 12px;
  padding: 8px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--subtext);
  font-size: 0.8rem;
  cursor: pointer;
}

.tab-bar {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--subtext);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.terminal-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000;
  touch-action: none;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: auto;
}

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

.terminal-container.active {
  display: block;
}

.terminal-container .xterm {
  height: 100%;
}

.terminal-container .xterm-viewport {
  overflow-y: auto !important;
  will-change: scroll-position;
}

.status-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
  z-index: 10;
  gap: 16px;
}

.status-overlay.hidden {
  display: none;
}

.status-overlay .msg {
  color: var(--subtext);
  font-size: 0.95rem;
}

.btn-restart {
  padding: 12px 28px;
  background: var(--accent);
  color: #1e1e2e;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

/* === Text Input Bar === */
.input-bar {
  display: flex;
  gap: 8px;
  padding: 8px 10px 0;
  background: var(--surface);
  flex-shrink: 0;
}

.input-bar input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-family: monospace;
  outline: none;
}

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

.input-bar button {
  padding: 10px 20px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #1e1e2e;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.input-bar button:active {
  opacity: 0.85;
}

/* === Mobile Button Bar === */
.button-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  padding-bottom: calc(8px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-key {
  flex: 0 0 auto;
  min-width: 44px;
  height: 40px;
  padding: 0 12px;
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

.btn-key:active {
  background: var(--btn-hover);
  transform: scale(0.95);
}

.btn-key.wide {
  min-width: 64px;
}

/* === Paste Modal === */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  padding: 20px;
  width: 100%;
  max-width: 500px;
  max-height: 60vh;
}

.modal h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.modal textarea {
  width: 100%;
  height: 120px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 12px;
  font-size: 14px;
  font-family: monospace;
  resize: vertical;
  outline: none;
  margin-bottom: 12px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal-actions button {
  padding: 10px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
}

.modal-actions .btn-cancel {
  background: var(--surface2);
  color: var(--subtext);
}

.modal-actions .btn-send {
  background: var(--accent);
  color: #1e1e2e;
  font-weight: 600;
  border-color: var(--accent);
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 20px;
  color: var(--text);
  font-size: 0.85rem;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}
