:root {
  color-scheme: dark;
  --bg: #0b1020;
  --bg-elev: #131a2e;
  --bg-elev2: #1b2440;
  --text: #e8ecf8;
  --muted: #8d97b8;
  --accent: #5b8cff;
  --accent-dim: #2d3e6b;
  --bubble-user: #5b8cff;
  --bubble-bot: #1b2440;
  --danger: #ff6b6b;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background: var(--bg);
}
.hidden { display: none !important; }

/* Gate / Setup */
.gate-card {
  margin: auto;
  width: min(360px, 88vw);
  text-align: center;
  padding: 24px;
}
.gate-card h1 {
  font-size: 34px;
  margin: 0 0 8px;
  letter-spacing: 0.5px;
  color: var(--accent);
}
.gate-card p { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.gate-card input {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--bg-elev2);
  color: var(--text);
  font-size: 20px;
  text-align: center;
  letter-spacing: 6px;
  padding: 14px;
  border-radius: 12px;
  margin-bottom: 14px;
  outline: none;
}
#base-url-input { letter-spacing: normal; font-size: 14px; text-align: left; }
.gate-card button {
  width: 100%;
  background: var(--accent);
  color: #06102a;
  font-weight: 700;
  font-size: 16px;
  border: none;
  padding: 14px;
  border-radius: 12px;
}
.error { color: var(--danger); min-height: 18px; font-size: 13px; margin-top: 10px; }

/* Roster */
.roster-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px 20px;
}
.roster-header h1 { margin: 0; font-size: 28px; color: var(--accent); }
.roster-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}
.roster-search-wrap {
  padding: 2px 16px 10px;
}
.roster-search-wrap input {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--bg-elev2);
  color: var(--text);
  font-size: 15px;
  padding: 10px 14px;
  border-radius: 12px;
  outline: none;
}

.roster-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 16px 24px;
  -webkit-overflow-scrolling: touch;
}

/* Each roster row: blob avatar, bold name + role chip, muted preview line,
   optional relative timestamp top-right. Flat list, no card borders. */
.bot-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 2px;
  border-bottom: 1px solid rgba(255,255,255,0.045);
}
.bot-row:last-child { border-bottom: none; }

.bot-avatar-wrap {
  position: relative;
  flex-shrink: 0;
  width: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.bot-blob-avatar { display: block; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3)); will-change: transform; }

.bot-star {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: #06102a;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
}

.bot-row-main {
  flex: 1;
  min-width: 0;
}
.bot-row-top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.bot-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
}
.bot-chip {
  flex-shrink: 1;
  min-width: 0;
  background: rgba(255,255,255,0.08);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bot-preview {
  margin-top: 4px;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  background: none; border: none; color: var(--text);
  font-size: 22px; padding: 6px 10px; border-radius: 10px;
}
.icon-btn:active { background: var(--bg-elev2); }

/* Chat */
.chat-header {
  display: flex; align-items: center; gap: 4px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--bg-elev2);
}
/* Grok-style grouped avatar + name/title pill, with the think-mode dots
   anchored to the same group so they read as "this bot is working". */
.chat-header-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  background: rgba(255,255,255,0.05);
  border-radius: 999px;
  padding: 4px 12px 4px 4px;
  margin: 0 4px;
}
.chat-bot-avatar { display: flex; align-items: center; flex-shrink: 0; }
.chat-title { flex: 1; min-width: 0; }
.chat-bot-name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-bot-title { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.think-dots {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  padding-right: 2px;
}
.think-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.2;
}
.think-dots.hidden { display: none; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: #06102a;
  border-bottom-right-radius: 4px;
}
.msg.bot {
  align-self: flex-start;
  background: var(--bubble-bot);
  border-bottom-left-radius: 4px;
}
.msg.system {
  align-self: center;
  color: var(--muted);
  font-size: 12px;
  background: none;
}

/* Composer: Grok-style capsule -- a round "+" to the left, a pill-shaped
   input field (with an inline mic icon on its right edge), and a distinct
   round send button at the far right. */
.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--bg-elev2);
  background: var(--bg);
}
.composer-plus {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-elev);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 20px;
  padding: 0;
}
.composer-pill {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--bg-elev2);
  border-radius: 24px;
  padding: 6px 6px 6px 16px;
}
#chat-input {
  flex: 1;
  resize: none;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 4px;
  font-size: 15px;
  max-height: 120px;
  outline: none;
  font-family: inherit;
}
.mic-btn-inline {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 17px;
  padding: 0;
}
.mic-btn-inline.recording { background: var(--danger); color: white; }
.send-btn {
  background: var(--accent);
  color: #06102a;
  border: none;
  width: 42px; height: 42px;
  border-radius: 50%;
  font-size: 18px;
  flex-shrink: 0;
}

/* ---------- Push notification opt-in banner ---------- */
.push-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 50;
  background: var(--bg-elev);
  border: 1px solid var(--accent-dim, var(--bg-elev2));
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.push-banner p { margin: 0; font-size: 14px; color: var(--text); }
.push-banner .push-actions { display: flex; gap: 10px; justify-content: flex-end; }
.push-banner button {
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
}
.push-banner .push-enable-btn { background: var(--accent); color: #06102a; }
.push-banner .push-skip-btn { background: none; color: var(--muted); }
