/* Mobile-first dark UI shared by all pages. */
:root {
  --bg: #0b0f14;
  --bg-raised: #151b23;
  --bg-input: #0f141b;
  --border: #263140;
  --text: #e6edf3;
  --text-dim: #8b98a5;
  --accent: #2dd4a7;
  --accent-press: #24b18c;
  --danger: #f2555a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; /* no pull-to-refresh over the terminal */
}

button { font: inherit; cursor: pointer; }

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
}
.topbar .icon-btn:active { color: var(--text); }

/* ---- Server list ---- */
.server-list { padding: 12px; display: flex; flex-direction: column; gap: 10px; }

.server-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 14px;
  color: var(--text);
  min-height: 72px; /* big one-thumb tap target */
}
.server-card:active { background: #1b2430; }
.server-card .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #3a4655; flex-shrink: 0;
}
.server-card .dot.active { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.server-card .info { flex: 1; min-width: 0; }
.server-card .name { font-size: 16px; font-weight: 600; }
.server-card .detail {
  font-size: 13px; color: var(--text-dim);
  font-family: ui-monospace, Menlo, monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}
.server-card .edit {
  background: none; border: none; color: var(--text-dim);
  font-size: 18px; padding: 12px; min-width: 44px; min-height: 44px;
}

.badge {
  font-size: 10px; padding: 2px 7px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .5px;
}
.badge.key { color: var(--accent); border-color: var(--accent); }

.empty { text-align: center; color: var(--text-dim); padding: 60px 20px; line-height: 1.6; }

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + var(--safe-bottom));
  width: 60px; height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #06251c;
  font-size: 30px;
  line-height: 60px;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.fab:active { background: var(--accent-press); }

/* ---- Forms (login + add/edit sheet) ---- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.field input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px; /* ≥16px stops Android/iOS zoom-on-focus */
  padding: 14px 12px;
}
.field input:focus { outline: none; border-color: var(--accent); }

.btn {
  width: 100%;
  padding: 15px;
  border-radius: 12px;
  border: none;
  font-size: 16px;
  font-weight: 600;
  min-height: 50px;
}
.btn-primary { background: var(--accent); color: #06251c; }
.btn-primary:active { background: var(--accent-press); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }

.form-error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 8px 0; }

/* ---- Login page ---- */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
  max-width: 420px;
  margin: 0 auto;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .mark { font-family: ui-monospace, Menlo, monospace; font-size: 42px; color: var(--accent); font-weight: 700; }
.login-logo .sub { color: var(--text-dim); font-size: 14px; margin-top: 4px; }

/* ---- Bottom sheet (add / edit server) ---- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 20;
  display: none;
}
.sheet-backdrop.open { display: block; }
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 21;
  background: var(--bg-raised);
  border-radius: 18px 18px 0 0;
  border-top: 1px solid var(--border);
  padding: 18px 18px calc(18px + var(--safe-bottom));
  transform: translateY(105%);
  transition: transform .22s ease;
  max-height: 88dvh;
  overflow-y: auto;
}
.sheet.open { transform: translateY(0); }
.sheet h2 { margin: 0 0 16px; font-size: 17px; }
.sheet .row2 { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }
.sheet .actions { display: grid; gap: 10px; margin-top: 6px; }

/* ---- Terminal page ---- */
.term-page {
  /* 100dvh tracks the Android keyboard so the toolbar rides above it */
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.term-topbar {
  display: flex; align-items: center; gap: 6px;
  padding: calc(6px + var(--safe-top)) 8px 6px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.term-topbar .title { flex: 1; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-pill {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  background: #3a4655; color: var(--text);
  white-space: nowrap;
}
.status-pill.ok { background: #10402f; color: var(--accent); }
.status-pill.bad { background: #4a1d1f; color: var(--danger); }

#term-container { flex: 1; min-height: 0; padding: 2px 0 0 4px; }
.xterm .xterm-viewport { background: var(--bg) !important; }

/* ---- Touch key toolbar ---- */
.key-toolbar {
  flex-shrink: 0;
  display: flex;
  gap: 6px;
  padding: 7px 8px calc(7px + var(--safe-bottom));
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.key-toolbar::-webkit-scrollbar { display: none; }
.key-btn {
  flex-shrink: 0;
  min-width: 46px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  font-family: ui-monospace, Menlo, monospace;
}
.key-btn:active { background: #26303d; }
.key-btn.toggled { background: var(--accent); color: #06251c; border-color: var(--accent); }
.key-btn.danger { color: var(--danger); }

/* ---- Claude chat page ---- */
.chat-page {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #06251c;
  border-bottom-right-radius: 4px;
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble.thinking {
  align-self: flex-start;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  font-size: 13px;
  font-style: italic;
}
.bubble.note {
  align-self: center;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  padding: 2px 8px;
  text-align: center;
}
.bubble.note.err { color: var(--danger); }

.bubble.tool {
  align-self: flex-start;
  max-width: 96%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
}
.tool-head { color: var(--accent); margin-bottom: 4px; }
.tool-body, .tool-result {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-dim);
  max-height: 220px;
  overflow-y: auto;
}
.tool-result { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); color: var(--text); }
.tool-result.err { color: var(--danger); }

/* Permission approval bar */
.perm-bar {
  flex-shrink: 0;
  background: #2a2113;
  border-top: 1px solid #6b5417;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.perm-text {
  flex: 1;
  font-size: 13px;
  font-family: ui-monospace, Menlo, monospace;
  color: #f0d58a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.perm-actions { display: flex; gap: 8px; flex-shrink: 0; }
.btn-allow, .btn-deny {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
}
.btn-allow { background: var(--accent); color: #06251c; }
.btn-deny { background: transparent; color: var(--danger); border: 1px solid var(--danger); }

/* Composer */
.chat-input-bar {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
}
.auto-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 10px;
  color: var(--text-dim);
  min-width: 34px;
  gap: 2px;
  padding-bottom: 8px;
}
.auto-toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
#chat-input {
  flex: 1;
  resize: none;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  line-height: 1.35;
  padding: 11px 12px;
  max-height: 140px;
}
#chat-input:focus { outline: none; border-color: var(--accent); }
.chat-send {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #06251c;
  font-size: 20px;
}
.chat-send:active { background: var(--accent-press); }
