:root {
  color-scheme: dark;
  --app: #070707;
  --panel: #111111;
  --raised: #202020;
  --card: #282828;
  --inset: #161616;
  --line: #343434;
  --ink: #fcfcfc;
  --muted: rgba(252, 252, 252, 0.59);
  --accent: #1084fe;
  --success: #38d591;
  --danger: #ff5667;
  --warning: #ffb13b;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 75% -10%, rgba(16, 132, 254, 0.16), transparent 36rem),
    var(--app);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

button, textarea, input { -webkit-tap-highlight-color: transparent; }
button:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid #69b4ff;
  outline-offset: 2px;
}

.pair-page {
  height: 100%;
  overflow: auto;
  padding: max(42px, env(safe-area-inset-top)) 22px max(32px, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
}
.pair-card { width: min(100%, 430px); }
.pair-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  margin-bottom: 28px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.55);
}
.eyebrow {
  margin: 0 0 12px;
  color: #7fc0ff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.pair-card h1 {
  margin: 0;
  font-size: clamp(38px, 11vw, 56px);
  line-height: 0.98;
  letter-spacing: -0.055em;
}
.lede {
  margin: 24px 0 26px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}
.pair-form { display: grid; gap: 11px; }
.pair-form label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.pair-form input {
  width: 100%;
  height: 62px;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--ink);
  background: var(--inset);
  font: 650 27px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.31em;
  text-align: center;
  padding-left: 0.31em;
}
.pair-form input::placeholder { color: #555; }
.primary-button {
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  padding: 0 18px;
  color: white;
  background: var(--accent);
  font-weight: 700;
  cursor: pointer;
}
.primary-button:disabled { opacity: 0.45; }
.pair-form .primary-button { height: 54px; font-size: 16px; }
.error-text {
  margin: 12px 0 0;
  border: 1px solid rgba(255, 86, 103, 0.35);
  border-radius: 12px;
  padding: 11px 13px;
  color: #ff9ba5;
  background: rgba(255, 86, 103, 0.09);
  font-size: 13px;
  line-height: 1.45;
}
.pair-steps {
  display: grid;
  gap: 4px;
  margin-top: 24px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
  font-size: 13px;
}
.pair-steps span, .fine-print { color: var(--muted); }
.fine-print { font-size: 11px; line-height: 1.45; margin: 18px 0 0; }

.app-shell { height: 100%; }
.roster {
  height: 100%;
  overflow: auto;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  padding: max(14px, env(safe-area-inset-top)) 13px max(18px, env(safe-area-inset-bottom));
}
.roster-header, .chat-header {
  display: flex;
  align-items: center;
  gap: 11px;
}
.roster-header { min-height: 56px; padding: 2px 3px 14px; }
.brand-lockup { display: flex; align-items: center; gap: 11px; min-width: 0; flex: 1; }
.brand-lockup img { width: 38px; height: 38px; border-radius: 10px; }
.brand-lockup div { display: grid; min-width: 0; }
.brand-lockup strong { font-size: 15px; }
.brand-lockup span { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.icon-button, .back-button, .stop-button, .install-hint button, .jump-button {
  border: 0;
  cursor: pointer;
}
.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: var(--muted);
  background: var(--raised);
  font-size: 18px;
}
.install-hint {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 3px 0 15px;
  border: 1px solid rgba(16, 132, 254, 0.23);
  border-radius: 14px;
  padding: 11px 12px;
  background: rgba(16, 132, 254, 0.08);
}
.install-hint div { display: grid; gap: 2px; flex: 1; }
.install-hint strong { font-size: 12px; }
.install-hint span { color: var(--muted); font-size: 11px; }
.install-hint button { color: var(--muted); background: transparent; font-size: 22px; }
.roster-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.connection-label { display: flex; align-items: center; gap: 6px; letter-spacing: 0; text-transform: none; }
.connection-label i { width: 7px; height: 7px; border-radius: 50%; background: var(--warning); }
.connection-label.live i { background: var(--success); box-shadow: 0 0 12px rgba(56, 213, 145, 0.6); }
.chat-list { display: grid; gap: 4px; }
.chat-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 65px;
  border: 0;
  border-radius: 15px;
  padding: 7px 9px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.chat-row:active, .chat-row.selected { background: var(--raised); }
.avatar, .chat-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 14px;
  color: white;
  font-weight: 800;
  text-shadow: 0 1px 2px #0005;
}
.avatar { width: 46px; height: 46px; font-size: 18px; }
.chat-avatar { width: 38px; height: 38px; border-radius: 12px; font-size: 15px; }
.row-copy { min-width: 0; display: grid; gap: 4px; }
.row-copy strong, .row-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-copy strong { font-size: 14px; }
.row-copy span { color: var(--muted); font-size: 12px; }
.row-meta { display: grid; justify-items: end; gap: 7px; color: var(--muted); font-size: 10px; }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.working-dot { width: 8px; height: 8px; border: 2px solid #777; border-top-color: white; border-radius: 50%; animation: spin .8s linear infinite; }
.empty-state { display: grid; gap: 5px; place-items: center; padding: 70px 20px; text-align: center; }
.empty-state span { color: var(--muted); font-size: 13px; }

.conversation {
  position: relative;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  background: var(--app);
}
.chat-header {
  z-index: 3;
  min-height: calc(60px + env(safe-area-inset-top));
  border-bottom: 1px solid rgba(255,255,255,.07);
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  background: rgba(10, 10, 10, 0.88);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}
.back-button { width: 30px; padding: 0; color: #7fc0ff; background: transparent; font-size: 38px; line-height: 1; }
.chat-heading { display: grid; min-width: 0; flex: 1; }
.chat-heading strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.chat-heading span { color: var(--muted); font-size: 11px; }
.stop-button {
  border: 1px solid rgba(255, 86, 103, .35);
  border-radius: 10px;
  padding: 7px 10px;
  color: #ff8d98;
  background: rgba(255, 86, 103, .08);
  font-size: 12px;
}
.messages {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 14px 22px;
  scroll-padding-bottom: 30px;
}
.message-row { display: flex; margin: 5px 0; }
.message-row.user { justify-content: flex-end; }
.message-row.bot { justify-content: flex-start; }
.message-bubble {
  max-width: min(84%, 720px);
  border-radius: 19px;
  padding: 10px 13px;
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message-row.user .message-bubble { border-bottom-right-radius: 6px; background: #4c4c4c; }
.message-row.bot .message-bubble { border-bottom-left-radius: 6px; background: var(--card); }
.sender-name { margin: 14px 3px 3px; color: var(--muted); font-size: 11px; }
.activity-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 86%;
  margin: 5px 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  background: var(--inset);
  font-size: 11px;
}
.activity-chip i { width: 6px; height: 6px; border-radius: 50%; background: var(--warning); }
.activity-chip.ok i { background: var(--success); }
.activity-chip.failed i { background: var(--danger); }
.option-card {
  margin: 10px 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: var(--card);
}
.option-card h3 { margin: 0 0 4px; font-size: 15px; }
.option-card p { margin: 0 0 12px; color: var(--muted); font-size: 13px; line-height: 1.4; white-space: pre-wrap; }
.option-list { display: grid; gap: 7px; }
.option-list button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 11px;
  color: var(--ink);
  background: var(--raised);
  text-align: left;
}
.question-answer { display: flex; gap: 7px; margin-top: 8px; }
.question-answer input { min-width: 0; flex: 1; border: 1px solid var(--line); border-radius: 11px; padding: 9px 10px; color: var(--ink); background: var(--inset); }
.question-answer button { border: 0; border-radius: 11px; padding: 0 13px; color: white; background: var(--accent); }
.screen-image { display: block; max-width: 90%; margin: 8px 0; border: 1px solid var(--line); border-radius: 13px; }
.streaming-bubble::after { content: ""; display: inline-block; width: 2px; height: 1em; margin-left: 3px; background: currentColor; vertical-align: -2px; animation: blink 1s step-end infinite; }
.jump-button {
  position: absolute;
  right: 14px;
  bottom: calc(82px + env(safe-area-inset-bottom));
  z-index: 4;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--ink);
  background: rgba(38,38,38,.95);
  box-shadow: 0 6px 24px #0008;
  font-size: 12px;
}
.approval-panel {
  border-top: 1px solid rgba(255, 177, 59, .25);
  padding: 13px 14px;
  background: rgba(255, 177, 59, .07);
}
.approval-kicker { color: var(--warning); font-size: 10px; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
.approval-panel > strong { display: block; margin-top: 4px; font-size: 14px; }
.approval-panel pre {
  max-height: 120px;
  overflow: auto;
  margin: 9px 0;
  border-radius: 10px;
  padding: 9px;
  color: #ddd;
  background: #0b0b0b;
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.approval-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; }
.deny-button { min-height: 46px; border: 1px solid rgba(255,86,103,.4); border-radius: 13px; color: #ff909b; background: rgba(255,86,103,.07); font-weight: 700; }
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border-top: 1px solid rgba(255,255,255,.06);
  padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  background: rgba(10,10,10,.94);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}
.composer textarea {
  resize: none;
  min-height: 44px;
  max-height: 130px;
  min-width: 0;
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 11px 15px;
  color: var(--ink);
  background: var(--inset);
  line-height: 20px;
}
.composer textarea::placeholder { color: var(--muted); }
.composer button {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  color: white;
  background: var(--accent);
  font-size: 22px;
  font-weight: 800;
}
.composer button:disabled { color: #777; background: var(--raised); }
.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 14px));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  color: var(--ink);
  background: #292929;
  box-shadow: 0 12px 40px #000a;
  font-size: 12px;
}

@media (min-width: 760px) {
  .app-shell { display: grid; grid-template-columns: minmax(270px, 340px) minmax(0, 1fr); }
  .roster { border-right: 1px solid var(--line); }
  .conversation { display: grid !important; }
  .back-button { display: none; }
  .message-bubble { max-width: min(72%, 720px); }
}

@media (max-width: 759px) {
  .app-shell.chat-open .roster { display: none; }
  .app-shell:not(.chat-open) .conversation { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0; } }
