:root {
  color-scheme: dark;
  --bg: #000;
  --line: #2a2a2a;
  --text: #f3f3f3;
  --muted: #8f8f8f;
  --bubble: #161616;
  --mine: #1858c0;
  --danger-bg: #2a1414;
  --danger: #ffc7c2;
  --accent: #1f6feb;
  --mention-bg: #10264a;
  --mention-text: #9ec5ff;
  --bot: #3a2f5c;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

button, textarea { font: inherit; color: inherit; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

button:focus-visible, a:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

#notice {
  position: fixed;
  z-index: 8;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 24px));
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 10px 14px;
  border: 1px solid #5c2a2a;
  border-radius: 12px;
  background: var(--danger-bg);
  color: var(--danger);
}

#alert { margin: 0; flex: 1; }

#retry {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 16px;
  border: 1px solid var(--danger);
  border-radius: 999px;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
}

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

.card { width: min(420px, 100%); text-align: center; }

.card img {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: #111;
  object-fit: cover;
}

.card h1 { margin: 18px 0 8px; font-size: 36px; letter-spacing: -0.03em; font-weight: 600; }

.lede { margin: 0 0 28px; color: var(--muted); }

#google-btn { min-height: 44px; display: flex; justify-content: center; }

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar, .brand, .thread-head, .chat-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar, .brand {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.topbar h1, .brand h1, .chat-title, .thread-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.who { margin: 0; color: var(--muted); font-size: 13px; }

.spacer { flex: 1; }

.signout, .reply, .icon-btn, .tab, .nav-btn, .jump, #send, #thread-send {
  min-height: 44px;
  min-width: 44px;
  cursor: pointer;
}

.signout, .icon-btn, .reply {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
}

.signout:hover, .reply:hover, .icon-btn:hover, .nav-btn:hover, .tab:hover { background: #141414; }

.body {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
}

.sidebar {
  display: none;
  width: 240px;
  flex: none;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #070707;
}

.sidebar .brand { border-bottom: 1px solid var(--line); }

#nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar .signout { margin: 12px; }

.conversation {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.switcher {
  display: flex;
  gap: 8px;
  padding: 8px 12px 0;
}

.tab, .nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  padding: 8px 12px;
  text-align: left;
  color: #c8c8c8;
  font-weight: 500;
}

.tab { flex: 1; justify-content: center; }

.nav-btn { width: 100%; border-color: transparent; }

.tab[aria-selected="true"] {
  color: #fff;
  font-weight: 700;
  background: #0b2548;
  border-color: var(--accent);
  box-shadow: inset 0 -3px 0 var(--accent);
}

.nav-btn[aria-current="page"] {
  color: #fff;
  font-weight: 700;
  background: #0b2548;
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.badge, .at-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.at-badge {
  background: var(--mention-bg);
  color: var(--mention-text);
  border: 1px solid #2d4f86;
  min-width: 1.25rem;
}

.chat-title { display: none; padding: 12px 16px 0; }

.log {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-anchor: auto;
  display: flex;
  flex-direction: column;
  padding: 8px 16px 12px;
}

.rows { display: flex; flex-direction: column; gap: 4px; }

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

.msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 8px 2px 10px;
  max-width: 640px;
}

.msg.me-mention {
  box-shadow: inset 3px 0 0 var(--mention-text);
  padding-left: 10px;
}

.meta { color: var(--muted); font-size: 12px; }

.bubble {
  max-width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bubble);
}

.msg.mine .bubble {
  background: var(--mine);
  color: #fff;
  border-color: #164a9e;
}

.msg.bot .bubble { background: var(--bot); }

.bubble p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mention {
  display: inline;
  padding: 0 0.35em;
  border-radius: 999px;
  background: var(--mention-bg);
  color: var(--mention-text);
}

.msg.mine .mention {
  background: rgba(0, 0, 0, .28);
  color: #fff;
  font-weight: 600;
}

.mention.me { font-weight: 700; }

.bot-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.45;
  vertical-align: 1px;
}

.reply-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(100%, 420px);
  height: 44px;
  min-height: 44px;
  max-height: 44px;
}

.reply-row .reply,
.reply-row .replies {
  height: 44px;
  min-height: 44px;
  max-height: 44px;
}

.reply-row .reply { flex: none; }

.replies {
  flex: 1;
  min-width: 44px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: left;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.replies:hover { color: var(--text); }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--accent);
}

#status, #thread-status {
  flex: none;
  min-height: 44px;
}

.status {
  margin: 0 16px;
  color: var(--muted);
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status p { margin: 0; }

.dots { display: inline-flex; gap: 4px; }

.dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #bdbdbd;
  animation: blink 1.2s infinite ease-in-out;
}

.dots i:nth-child(2) { animation-delay: .2s; }

.dots i:nth-child(3) { animation-delay: .4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: .25; }
  40% { opacity: 1; }
}

.dock { position: relative; flex: none; }

.jump {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  z-index: 2;
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
}

.composer {
  position: relative;
  padding: 8px 16px calc(12px + env(safe-area-inset-bottom));
}

.mention-pop {
  position: absolute;
  z-index: 4;
  left: 16px;
  right: 16px;
  bottom: calc(100% - 4px);
  max-height: min(288px, 35dvh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #101010;
}

.mention-pop button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.mention-pop button[aria-selected='true'] {
  background: var(--mention-bg);
  color: var(--mention-text);
}

.mention-pop .label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.mention-pop .handle {
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
}

.mention-pop button[aria-selected='true'] .handle { color: inherit; }

.mention-pop .kind {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.mention-pop .kind .bot-tag { margin-left: 0; }

.mention-pop .hint {
  display: flex;
  align-items: center;
  min-height: 48px;
  margin: 0;
  padding: 0 16px;
  color: var(--muted);
}

#thread-heading:focus {
  outline: none;
}

form.composer-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 8px 8px 8px 16px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #101010;
}

form.composer-form:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

textarea {
  flex: 1;
  min-height: 24px;
  max-height: 160px;
  padding: 10px 0;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
}

textarea:focus,
textarea:focus-visible {
  outline: none;
}

#send, #thread-send {
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  background: #fff;
  color: #000;
  font-weight: 600;
}

#send:disabled, #thread-send:disabled { opacity: .45; cursor: default; }

.thread {
  position: relative;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.thread-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  min-height: 56px;
}

.thread-context { color: var(--muted); font-size: 13px; }

.thread-root {
  flex: none;
  padding: 8px 16px 4px;
  border-bottom: 1px solid var(--line);
  max-height: 40%;
  overflow-y: auto;
}

.thread-count {
  margin: 0;
  padding: 8px 16px 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

@media (max-width: 899px) {
  .sidebar { display: none !important; }
  .chat-title { display: none; }
  .thread {
    position: fixed;
    inset: 0;
    z-index: 6;
    width: 100%;
    transform: translateX(100%);
    visibility: hidden;
  }
  .thread.open {
    transform: none;
    visibility: visible;
  }
  #thread-close { display: none; }
}

@media (min-width: 900px) {
  .topbar { display: none; }
  .sidebar { display: flex; }
  .switcher { display: none; }
  .chat-title { display: flex; }
  .thread {
    display: none;
    width: 380px;
    flex: 0 0 380px;
    border-left: 1px solid var(--line);
  }
  .thread.open { display: flex; }
  #thread-back { display: none; }
  .msg.thread-open {
    background: #0b2548;
    border-radius: 12px;
    box-shadow: inset 3px 0 0 var(--accent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .thread { transition: none; }
  .dots i { animation: none; opacity: .7; }
}

@media (prefers-reduced-motion: no-preference) {
  .thread { transition: transform 180ms ease; }
}
