:root {
  color-scheme: dark;
  --bg: #101010;
  --side: #161616;
  --term: #121212;
  --text: #f2f2f0;
  --muted: #9a9a96;
  --faint: #6a6a66;
  --line: rgba(255, 255, 255, 0.08);
  --fill: rgba(255, 255, 255, 0.045);
  --fill-strong: rgba(255, 255, 255, 0.08);
  --green: #3dd68c;
  --amber: #e6b450;
  --red: #ff6b6b;
  --app-h: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { height: var(--app-h); overflow: hidden; overscroll-behavior: none; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid #d8d8d4; outline-offset: 2px; }

.app {
  height: var(--app-h);
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
}

.sidebar {
  background: var(--side);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 14px 6px 16px;
}
.brand {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.045em;
}
.side-label {
  margin: 12px 16px 6px;
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.hosts {
  list-style: none;
  margin: 0;
  padding: 0 8px 16px;
  overflow: auto;
  flex: 1;
  min-height: 0;
}
.side-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.side-foot .text-btn { margin-top: 0; }
.who {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  font-size: 13px;
}
#who-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.avatar {
  width: 22px;
  height: 22px;
  border-radius: 99px;
  background: #2a2a2a center / cover no-repeat;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 650;
  color: var(--text);
}
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
.avatar.has-image { color: transparent; }
.tag-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 8px;
}
.tag {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 99px;
  padding: 3px 8px;
  font-size: 11px;
}
.tag.on { background: var(--fill-strong); color: var(--text); }
.group-label {
  margin: 12px 8px 4px;
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.empty-note {
  color: var(--faint);
  font-size: 13px;
  padding: 8px 12px;
}
.host-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  border-radius: 8px;
}
.host-row:hover { background: var(--fill); }
.host-row:has(.host.selected) { background: var(--fill-strong); }
.host-row.drop-target { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28); }
.host-row.dragging { opacity: 0.45; }
.drag-handle {
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  margin-left: 2px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--faint);
  cursor: grab;
  touch-action: none;
}
.drag-handle:hover { color: var(--text); }
body.reordering, body.reordering .drag-handle { cursor: grabbing; }
.menu-btn {
  width: 28px;
  height: 28px;
  margin-right: 4px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--faint);
  font-size: 16px;
  line-height: 1;
}
.menu-btn:hover, .menu-btn[aria-expanded="true"] { color: var(--text); background: var(--fill-strong); }
.host-menu {
  position: fixed;
  z-index: 40;
  min-width: 132px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #1c1c1c;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
}
.menu-item:hover { background: var(--fill-strong); }
.lock {
  display: none;
  height: var(--app-h);
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.lock form {
  width: min(380px, 100%);
  padding: 28px 24px 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #161616;
}
.lock .brand { font-size: 22px; }
.lock h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.lock-hint { margin: 0; color: var(--muted); font-size: 14px; }
.lock .btn { width: 100%; height: 40px; }
.install {
  display: block;
  margin: 14px auto 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}
.side-foot .install { margin: 0; }
.install:hover { color: var(--text); }
.lock-home {
  display: block;
  margin-top: 16px;
  text-align: center;
  color: var(--faint);
  font-size: 13px;
  text-decoration: none;
}
.lock-home:hover { color: var(--text); }
body.locked .lock { display: flex; }
body.locked .app { display: none; }
.host {
  width: 100%;
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr);
  column-gap: 10px;
  row-gap: 2px;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 10px 10px 10px 12px;
}
.host:hover, .host.selected { background: transparent; }
.dot {
  grid-row: 1 / span 2;
  align-self: center;
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: #3c3c3c;
}
.host.connecting .dot { background: var(--amber); }
.host.connected .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(61, 214, 140, 0.14); }
.host-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.host-meta {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}
.top {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px 0 16px;
  border-bottom: 1px solid var(--line);
}
.identity { flex: 1; min-width: 0; }
.identity h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.identity p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.identity p.ok { color: var(--green); }
.identity p.bad { color: var(--red); }
.back {
  display: none;
  height: 32px;
  padding: 0 10px 0 2px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  height: 32px;
  padding: 0 14px;
  border-radius: 8px;
  background: #f4f4f2;
  color: #161616;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.busy:disabled { opacity: 1; cursor: progress; }
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 99px;
  animation: spin 0.7s linear infinite;
  flex: 0 0 auto;
}
.text-btn.busy {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.text-btn.busy:disabled { opacity: 1; cursor: progress; }
@keyframes spin { to { transform: rotate(360deg); } }
.upload {
  display: flex;
  align-items: center;
  gap: 8px;
}
.upload-track {
  flex: 1;
  height: 4px;
  min-width: 72px;
  border-radius: 99px;
  background: var(--fill-strong);
  overflow: hidden;
}
.upload-bar {
  height: 100%;
  width: 0%;
  background: var(--text);
}
.upload-track.indeterminate .upload-bar {
  width: 35%;
  animation: upload-slide 0.9s ease-in-out infinite;
}
@keyframes upload-slide {
  from { transform: translateX(-120%); }
  to { transform: translateX(320%); }
}
.upload span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.text-btn:disabled { opacity: 0.45; }
.btn.ghost {
  background: transparent;
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  flex: 0 0 auto;
}
.side-toggle[aria-pressed="false"] { background: var(--fill-strong); }

.screen {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--term);
  display: flex;
  flex-direction: column;
}
.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 6px 8px 0;
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
  flex: 0 0 auto;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 190px;
  height: 28px;
  padding: 0 6px 0 8px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  color: var(--muted);
}
.tab.active {
  color: var(--text);
  background: #1c1c1c;
  border-color: var(--line);
}
.tab-main, .tab-close {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 12px;
}
.tab-main {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tab-close { width: 16px; color: var(--faint); }
.tab-dot {
  width: 6px;
  height: 6px;
  border-radius: 99px;
  background: var(--amber);
  flex: 0 0 auto;
}
.tab.connected .tab-dot { background: var(--green); }
.screen-body { position: relative; flex: 1; min-height: 0; }
.placeholder, .terms { position: absolute; inset: 0; }
.terms { pointer-events: none; }
.term-pane { position: absolute; inset: 0; display: none; padding: 8px 4px 4px 12px; }
.term-pane.active { display: block; pointer-events: auto; }
.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}
.ph-kicker {
  margin: 0 0 8px;
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.placeholder h2 {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.035em;
}
#ph-meta {
  margin: 8px 0 0;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}
.placeholder-actions { display: flex; gap: 16px; }
.text-btn {
  margin-top: 18px;
  border: 0;
  background: transparent;
  color: var(--faint);
  font-size: 13px;
}
.placeholder-actions .text-btn { margin-top: 18px; }
.text-btn:hover { color: var(--red); }
.form-actions .text-btn { margin-top: 0; }
.xterm, .xterm-viewport { background: #121212 !important; }
.xterm-viewport::-webkit-scrollbar { width: 10px; }
.xterm-viewport::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.16); border-radius: 99px; }
.xterm-helper-textarea { font-size: 16px !important; }

.keys {
  display: none;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #141414;
  scrollbar-width: none;
}
.keys::-webkit-scrollbar { display: none; }
.keys button {
  flex: 0 0 auto;
  min-width: 40px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #222;
  color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
}
.keys button.latched { background: #f4f4f2; color: #161616; }

dialog {
  width: min(440px, calc(100vw - 24px));
  max-height: min(640px, calc(var(--app-h) - 24px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #1b1b1b;
  color: var(--text);
  padding: 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.62); }
dialog h2 { margin: 0 0 14px; font-size: 18px; letter-spacing: -0.03em; }
form { display: flex; flex-direction: column; gap: 12px; }
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}
.split { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111;
  color: var(--text);
  padding: 10px 12px;
  font-size: 16px;
}
textarea {
  min-height: 112px;
  resize: vertical;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.hint, .form-error { margin: 0; font-size: 12px; }
.hint { color: var(--muted); }
.form-error { color: var(--red); min-height: 1em; }
.form-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.form-actions-end { display: flex; gap: 8px; margin-left: auto; }
dialog h3 { margin: 8px 0 0; font-size: 14px; font-weight: 600; }
.profile-row { display: flex; align-items: center; gap: 14px; }
.profile-photo { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.profile-photo .text-btn { margin-top: 0; align-self: flex-start; }
#password-form { margin-top: 8px; padding-top: 4px; border-top: 1px solid var(--line); }
input[type="file"] { padding: 8px; }

@media (min-width: 801px) {
  body.side-hidden .app { grid-template-columns: minmax(0, 1fr); }
  body.side-hidden .sidebar { display: none; }
}

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  body.nav-open .sidebar { display: flex; }
  body.nav-open .stage { display: none; }
  .side-toggle { display: none; }
  .back { display: inline-flex; align-items: center; }
  .placeholder h2 { font-size: 24px; }
}

@media (max-width: 900px), (pointer: coarse) {
  body.session-on .keys { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .spinner, .upload-bar { animation: none !important; }
  .upload-track.indeterminate .upload-bar { width: 100%; }
}
