:root {
  color-scheme: dark;
  --bg: #090b12;
  --panel: #11131f;
  --panel-2: #171a29;
  --line: #2a2f45;
  --text: #f3f5fb;
  --muted: #9ca5b8;
  --soft: #c5cbe0;
  --violet: #9d6cff;
  --teal: #38d6c4;
  --amber: #f7bf4f;
  --green: #3ee786;
  --red: #ff6375;
  --grey: #8f98aa;
  --shadow: 0 18px 50px rgb(0 0 0 / 0.36);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

html,
body,
#app {
  min-height: 100%;
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% -8%, rgb(157 108 255 / 0.22), transparent 32rem),
    radial-gradient(circle at 96% 4%, rgb(56 214 196 / 0.14), transparent 24rem),
    var(--bg);
  color: var(--text);
  overflow: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

.view {
  min-height: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.login-view {
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}

.login-card {
  width: min(100%, 420px);
  margin: 0 auto;
  padding: 28px 22px 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(17 19 31 / 0.9);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #5b36d6, #30cbbd);
  box-shadow: 0 10px 30px rgb(91 54 214 / 0.28);
  font-weight: 800;
}

.brand-title {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0;
}

.brand-subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.field label {
  color: var(--soft);
  font-size: 0.84rem;
  font-weight: 700;
}

.input,
.textarea,
.select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c0f19;
  color: var(--text);
  outline: none;
  padding: 13px 14px;
}

.textarea {
  min-height: 92px;
  resize: vertical;
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px rgb(157 108 255 / 0.16);
}

.primary-btn,
.ghost-btn,
.danger-btn,
.icon-btn,
.fab,
.chip-btn {
  min-height: 44px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.primary-btn {
  width: 100%;
  background: linear-gradient(135deg, #7855f7, #23bbaa);
  color: white;
  font-weight: 800;
}

.ghost-btn {
  padding: 0 14px;
  background: #202438;
  border: 1px solid var(--line);
  color: var(--soft);
}

.danger-btn {
  padding: 0 14px;
  background: rgb(255 99 117 / 0.12);
  border: 1px solid rgb(255 99 117 / 0.38);
  color: #ffc6cd;
}

.icon-btn {
  width: 44px;
  background: #202438;
  border: 1px solid var(--line);
}

.primary-btn:active,
.ghost-btn:active,
.danger-btn:active,
.icon-btn:active,
.fab:active,
.chip-btn:active {
  transform: scale(0.98);
}

.error {
  min-height: 22px;
  margin: 12px 0 0;
  color: #ff9aa7;
  font-size: 0.9rem;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 14px 12px;
  border-bottom: 1px solid rgb(255 255 255 / 0.07);
  background: rgb(9 11 18 / 0.82);
  backdrop-filter: blur(18px);
}

.title-block {
  min-width: 0;
}

.screen-title {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.screen-meta {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.actions {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
}

.list {
  flex: 1 1 auto;
  overflow: auto;
  padding: 14px 14px calc(92px + env(safe-area-inset-bottom));
}

.terminal-card {
  width: 100%;
  text-align: left;
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(17 19 31 / 0.9);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.18);
}

.card-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 1rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  flex: 0 0 auto;
  min-width: 62px;
  padding: 5px 8px;
  border-radius: 999px;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.badge.claude {
  color: #efe7ff;
  background: rgb(157 108 255 / 0.23);
}

.badge.codex {
  color: #d8fffb;
  background: rgb(56 214 196 / 0.2);
}

.badge.shell {
  color: #eef1f6;
  background: rgb(143 152 170 / 0.2);
}

.summary {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.state-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border-radius: 50%;
  background: var(--grey);
}

.state-dot.working {
  background: var(--green);
  box-shadow: 0 0 0 0 rgb(62 231 134 / 0.68);
  animation: pulse 1.5s infinite;
}

.state-dot.waiting {
  background: var(--amber);
}

.state-dot.dead {
  background: var(--red);
}

@keyframes pulse {
  70% {
    box-shadow: 0 0 0 10px rgb(62 231 134 / 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgb(62 231 134 / 0);
  }
}

.empty {
  margin: 24px 2px;
  color: var(--muted);
  text-align: center;
}

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7855f7, #23bbaa);
  color: white;
  font-size: 2rem;
  line-height: 1;
  box-shadow: var(--shadow);
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: end;
  background: rgb(0 0 0 / 0.52);
}

.sheet {
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: 8px 8px 0 0;
  border-top: 1px solid var(--line);
  background: #11131f;
  box-shadow: var(--shadow);
}

.sheet-title {
  margin: 0 0 16px;
  font-size: 1.1rem;
}

.kind-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.chip-btn {
  min-width: 0;
  background: #202438;
  border: 1px solid var(--line);
  color: var(--soft);
  font-weight: 800;
}

.chip-btn.active {
  color: white;
  border-color: rgb(157 108 255 / 0.72);
  background: rgb(157 108 255 / 0.22);
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.terminal-view {
  background: #05070d;
}

.term-wrap {
  flex: 1 1 auto;
  min-height: 0;
  padding: 8px 8px 0;
}

#terminal {
  width: 100%;
  height: 100%;
}

.xterm {
  height: 100%;
  padding: 8px;
}

.command-bar {
  flex: 0 0 auto;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid rgb(255 255 255 / 0.08);
  background: rgb(9 11 18 / 0.95);
}

.quick-keys {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  margin-bottom: 8px;
}

.quick-keys button {
  min-height: 38px;
  border-radius: 8px;
  background: #1b2031;
  border: 1px solid var(--line);
  color: var(--soft);
  font-weight: 800;
}

.send-row {
  display: grid;
  grid-template-columns: 1fr 78px;
  gap: 8px;
}

.send-row .input {
  min-width: 0;
}

.send-row .primary-btn {
  min-width: 0;
}

.loading {
  display: grid;
  place-items: center;
  min-height: 100%;
  color: var(--muted);
}

@media (min-width: 760px) {
  .list {
    width: min(100%, 860px);
    margin: 0 auto;
  }

  .sheet {
    width: min(100%, 520px);
    justify-self: center;
    border-radius: 8px 8px 0 0;
  }

  .term-wrap {
    padding: 10px 12px 0;
  }

  .command-bar {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(360px, 2fr);
    gap: 10px;
    align-items: center;
  }

  .quick-keys {
    margin-bottom: 0;
  }
}

/* --- pairing login + artifact-free terminal (integration additions) --- */
.hidden { display: none !important; }
.code-input {
  letter-spacing: .42em;
  text-align: center;
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
}
#use-token { width: 100%; margin-top: 6px; }
.term-wrap { overflow: auto; -webkit-overflow-scrolling: touch; }
#terminal { will-change: transform; }
