:root {
  color-scheme: dark;
  --bg: #151719;
  --panel: #1d2023;
  --panel2: #22262a;
  --border: #363b40;
  --text: #d7dbdf;
  --muted: #8d969e;
  --accent: #4f8cff;
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: var(--app-height, 100dvh);
  margin: 0;
  overflow: hidden;
}
html { background: var(--bg); }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
  touch-action: manipulation;
}
button, input {
  font: inherit;
}
button {
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  height: 26px;
  border-radius: 5px;
  cursor: pointer;
}
button:hover { border-color: #58616b; }
.tool-button {
  width: 26px;
  min-width: 26px;
  display: inline-grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  border-radius: 4px;
  line-height: 1;
}
.tool-button:hover {
  background: var(--panel2);
  color: var(--text);
}
#app {
  width: 100%;
  height: var(--app-height, 100dvh);
  min-width: 0;
  max-width: 100vw;
  position: fixed;
  inset: 0;
  overflow: hidden;
}
#sidebar-backdrop {
  position: fixed;
  z-index: 8;
  inset: 0;
  display: none;
  background: transparent;
}
#sidebar.open + #workspace,
#sidebar.open ~ #workspace {
  pointer-events: auto;
}
#sidebar {
  position: fixed;
  z-index: 9;
  left: 0;
  top: 0;
  bottom: 0;
  width: 260px;
  border-right: 1px solid var(--border);
  box-shadow: 14px 0 28px rgba(0, 0, 0, .28);
  background: var(--panel);
  padding: 10px;
  overflow: auto;
  transform: translateX(-100%);
  transition: transform .16s ease;
}
#sidebar.open { transform: translateX(0); }
#sidebar-backdrop.open { display: block; }
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.brand-block {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.brand-icon {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
}
.brand {
  font-size: 16px;
  font-weight: 650;
}
.machine {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}
#new-session {
  width: 100%;
  margin-bottom: 10px;
}
#session-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.session-group {
  margin: 12px 2px 4px;
  width: calc(100% - 4px);
  height: 24px;
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: left;
  padding: 0 4px;
}
.session-group:hover {
  background: var(--panel2);
}
.group-arrow {
  color: var(--muted);
}
.group-count {
  color: var(--muted);
}
.session-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0 6px;
  overflow: hidden;
}
.session-item:hover { background: var(--panel2); }
.session-item.running .session-name::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 999px;
  background: #54d17a;
}
.session-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-meta {
  color: var(--muted);
  font-size: 11px;
}
#workspace {
  width: 100%;
  height: var(--app-height, 100dvh);
  min-width: 0;
  max-width: 100vw;
  overflow: hidden;
  position: relative;
}
#toolbar {
  height: 34px;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
#pane-count { color: var(--muted); font-size: 12px; }
#panes {
  position: absolute;
  inset: 34px 0 0 0;
  overflow: hidden;
}
.session-dialog-backdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .42);
}
.session-dialog {
  width: min(340px, calc(100vw - 32px));
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .36);
}
.session-dialog-title {
  font-size: 15px;
  font-weight: 650;
}
.provider-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.provider-picker label {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #111315;
  color: var(--text);
  cursor: pointer;
}
.provider-picker label:has(input:checked) {
  border-color: #4f8cff;
  background: rgba(79, 140, 255, .16);
}
.provider-picker input {
  margin: 0;
}
.session-name-input {
  height: 36px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #111315;
  color: var(--text);
  padding: 0 10px;
  outline: none;
}
.session-name-input:focus {
  border-color: #4f8cff;
}
.session-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.session-dialog-actions button {
  min-width: 70px;
}
.pane {
  position: absolute;
  border: 1px solid var(--border);
  background: #111315;
  overflow: hidden;
}
.pane.active {
  border-color: #58616b;
}
.pane.reconnecting {
  border-color: #8a6b2d;
}
.pane.reconnecting header input {
  color: #d6a94d;
}
.pane header {
  height: 28px;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 4px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.pane header input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  outline: none;
}
.pane header input:focus { color: var(--text); }
.pane header button {
  border: 0;
  background: transparent;
  min-width: 22px;
  padding: 0 5px;
  color: var(--muted);
  transition: background-color .08s ease, color .08s ease, transform .08s ease;
}
.pane header button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, .06);
}
.pane header button:active,
.pane header button.touch-active {
  color: #ffffff;
  background: rgba(79, 140, 255, .28);
  transform: scale(.92);
}
.pane header button.icon-button {
  width: 22px;
  min-width: 22px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}
.pane header button.icon-button svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mobile-key-button {
  display: none;
}
.term-host {
  position: absolute;
  inset: 28px 0 0 0;
  padding: 6px;
  overflow: hidden;
  max-width: 100%;
  touch-action: manipulation;
  -webkit-user-select: text;
  user-select: text;
}
.term-host.initializing .xterm {
  visibility: hidden;
}
.term-host.initializing::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid rgba(141, 150, 158, .35);
  border-top-color: rgba(215, 219, 223, .9);
  border-radius: 999px;
  animation: tmux-spin .7s linear infinite;
}
@keyframes tmux-spin {
  to { transform: rotate(360deg); }
}
.term-host .xterm {
  width: 100%;
  height: 100%;
  max-width: 100%;
  overflow: hidden;
}
.term-host .xterm-viewport {
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}
.term-host .xterm-screen {
  max-width: 100%;
  overflow: hidden;
}
.term-host .composition-view {
  max-width: calc(100% - 12px);
  overflow: hidden;
  contain: paint;
  pointer-events: none;
}
.term-host .xterm-viewport::-webkit-scrollbar {
  width: 0;
  height: 0;
}
.term-scrollbar {
  position: absolute;
  z-index: 5;
  top: 6px;
  right: 2px;
  bottom: 6px;
  width: 12px;
  opacity: 0;
  transition: opacity .12s ease;
  pointer-events: auto;
  touch-action: none;
}
.term-scrollbar.visible,
.term-scrollbar:hover,
.term-scrollbar:active {
  opacity: 1;
}
.term-scrollbar.hidden {
  display: none;
}
.term-scrollbar-thumb {
  width: 8px;
  margin-left: 2px;
  border-radius: 999px;
  background: rgba(122, 132, 143, .72);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .2);
  touch-action: none;
}
.term-scrollbar-thumb:hover,
.term-scrollbar-thumb:active {
  background: rgba(157, 166, 176, .9);
}
.login-body {
  display: grid;
  place-items: center;
  min-height: 100%;
}
.login-card {
  width: min(360px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}
.login-card .brand { margin-bottom: 14px; }
.login-card form { display: grid; gap: 10px; }
.login-card input {
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #111315;
  color: var(--text);
  padding: 0 10px;
}
#error { min-height: 18px; color: #ff7b7b; }

@media (max-width: 760px) {
  #sidebar { width: min(300px, 86vw); }
  #toolbar {
    height: 30px;
    padding: 2px 6px;
  }
  #panes {
    inset: 30px 0 0 0;
  }
  .pane header {
    height: 26px;
    padding: 1px 3px;
  }
  .pane header button {
    min-width: 20px;
    padding: 0 3px;
  }
  .pane header button.mobile-key-button {
    display: inline-grid;
    place-items: center;
    width: 20px;
    min-width: 20px;
    padding: 0;
    color: var(--text);
  }
  .pane header button.mobile-space-button {
    width: 26px;
    min-width: 26px;
  }
  .pane header button.icon-button {
    width: 20px;
    min-width: 20px;
  }
  .term-host {
    inset: 26px 0 0 0;
    padding: 4px;
  }
  .term-scrollbar {
    top: 4px;
    bottom: 4px;
  }
}
