:root {
  color-scheme: dark;
  --bg: #090a0e;
  --phone: rgba(16, 17, 22, 0.86);
  --thread: #0f1015;
  --hairline: rgba(255, 255, 255, 0.1);
  --muted: rgba(244, 246, 248, 0.62);
  --text: #f7f8fa;
  --blue: #0a84ff;
  --blue-2: #006fed;
  --gray: rgba(255, 255, 255, 0.13);
  --green: #32d074;
  --yellow: #ffd66b;
  --red: #ff5c70;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

button,
input {
  font: inherit;
}

.message-body {
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 26% 0%, rgba(10, 132, 255, 0.2), transparent 24rem),
    radial-gradient(circle at 76% 10%, rgba(50, 208, 116, 0.14), transparent 22rem),
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.08) 1px, transparent 1.4px),
    var(--bg);
  background-size: auto, auto, 18px 18px, auto;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.message-app {
  min-height: 100vh;
}

.messages-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: center;
  min-height: 5rem;
  padding: 0.6rem clamp(0.9rem, 3vw, 1.4rem);
  border-bottom: 1px solid var(--hairline);
  background: rgba(9, 10, 14, 0.78);
  backdrop-filter: blur(22px);
}

.back-link,
.top-action {
  color: #78c7ff;
  font-weight: 760;
  text-decoration: none;
}

.contact-stack {
  display: grid;
  justify-items: center;
  gap: 0.26rem;
  min-width: 0;
}

.contact-avatars {
  display: flex;
  justify-content: center;
}

.contact-avatars span {
  display: grid;
  width: 2.08rem;
  height: 2.08rem;
  place-items: center;
  border: 2px solid rgba(9, 10, 14, 0.94);
  border-radius: 50%;
  background: linear-gradient(135deg, #198fff, #004eaa);
  color: white;
  font-size: 0.66rem;
  font-weight: 950;
}

.contact-avatars span + span {
  margin-left: -0.48rem;
  background: linear-gradient(135deg, #45e0ac, #ffd66b);
  color: #121318;
}

.contact-stack strong {
  font-size: 0.92rem;
  line-height: 1;
}

.contact-stack small {
  max-width: 18rem;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.buddy-shell {
  display: grid;
  grid-template-columns: minmax(360px, 640px) minmax(320px, 440px);
  gap: 1rem;
  width: min(100% - 2rem, 1120px);
  margin: 1rem auto;
  align-items: start;
}

.phone-surface,
.observer-panel {
  min-width: 0;
  border: 1px solid var(--hairline);
  border-radius: 34px;
  background: var(--phone);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(20px);
}

.phone-surface {
  min-height: calc(100vh - 7rem);
  overflow: hidden;
}

.thread-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.05rem 0.8rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.035);
}

.eyebrow {
  margin: 0 0 0.28rem;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.thread-status h1,
.panel-heading h2 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.1;
}

.live-pill {
  display: inline-flex;
  min-height: 2rem;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid rgba(50, 208, 116, 0.32);
  border-radius: 999px;
  padding: 0 0.72rem;
  color: #c8ffd7;
  font-size: 0.74rem;
  font-weight: 900;
  white-space: nowrap;
}

.live-pill::before {
  content: "";
  width: 0.48rem;
  height: 0.48rem;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 14px rgba(50, 208, 116, 0.76);
}

.agent-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  padding: 0.72rem 0.9rem;
}

.agent-card {
  display: grid;
  gap: 0.24rem;
  border: 1px solid var(--hairline);
  border-radius: 18px;
  padding: 0.62rem;
  background: rgba(255, 255, 255, 0.055);
}

.agent-card span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 850;
  text-transform: uppercase;
}

.agent-card strong {
  overflow: hidden;
  font-size: 0.88rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-thread {
  display: grid;
  align-content: start;
  min-width: 0;
  min-height: 28rem;
  overflow: hidden;
  padding: 0.5rem 0.78rem 1rem;
}

.loading-state,
.timestamp {
  margin: 1rem 0 0.7rem;
  color: rgba(247, 248, 250, 0.45);
  font-size: 0.78rem;
  font-weight: 760;
  text-align: center;
}

.turn-group {
  display: grid;
  gap: 0.42rem;
  margin-bottom: 0.6rem;
}

.bubble-row {
  display: flex;
  min-width: 0;
  max-width: 100%;
  gap: 0.42rem;
  align-items: end;
}

.bubble-row.codex {
  justify-content: flex-end;
}

.bubble-row.grok,
.bubble-row.system {
  justify-content: flex-start;
}

.mini-avatar {
  display: grid;
  flex: 0 0 1.8rem;
  width: 1.8rem;
  height: 1.8rem;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-size: 0.62rem;
  font-weight: 950;
}

.codex .mini-avatar {
  order: 2;
  background: var(--blue);
}

.bubble {
  position: relative;
  min-width: 0;
  max-width: min(78%, 34rem);
  overflow-wrap: anywhere;
  border-radius: 21px;
  padding: 0.68rem 0.82rem;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.16);
}

.codex .bubble {
  border-bottom-right-radius: 6px;
  background: linear-gradient(180deg, var(--blue), var(--blue-2));
  color: white;
}

.grok .bubble {
  border-bottom-left-radius: 6px;
  background: var(--gray);
  color: var(--text);
}

.system .bubble {
  border: 1px solid rgba(255, 214, 107, 0.22);
  background: rgba(255, 214, 107, 0.09);
}

.kind-chip {
  display: inline-flex;
  margin-bottom: 0.34rem;
  border-radius: 999px;
  padding: 0.16rem 0.42rem;
  background: rgba(255, 255, 255, 0.16);
  color: inherit;
  font-size: 0.64rem;
  font-weight: 920;
  text-transform: uppercase;
}

.bubble p {
  margin: 0;
  overflow-wrap: anywhere;
  line-height: 1.42;
}

.message-meta {
  display: flex;
  gap: 0.3rem;
  justify-content: flex-end;
  margin-top: 0.34rem;
  opacity: 0.68;
  font-size: 0.68rem;
}

.proof-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.48rem;
}

.proof-chips button {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  padding: 0.22rem 0.46rem;
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  cursor: pointer;
  font-size: 0.66rem;
  font-weight: 850;
}

.handoff-bar {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: center;
  padding: 0.78rem;
  border-top: 1px solid var(--hairline);
  background: rgba(15, 16, 21, 0.86);
  backdrop-filter: blur(18px);
}

.attachment-button,
.send-button {
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: var(--text);
  cursor: pointer;
  font-weight: 950;
}

.attachment-button {
  width: 2.28rem;
  height: 2.28rem;
  font-size: 1.45rem;
}

.send-button {
  min-height: 2.28rem;
  padding: 0 0.88rem;
  background: var(--blue);
}

.handoff-copy {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 0.42rem 0.7rem;
  background: rgba(255, 255, 255, 0.08);
}

.handoff-copy span,
.command-card span {
  display: block;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 850;
  text-transform: uppercase;
}

.handoff-copy strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 0.86rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.observer-panel {
  position: sticky;
  top: 6rem;
  max-height: calc(100vh - 7rem);
  overflow: hidden;
}

.inspector-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.3rem;
  padding: 0.65rem;
  border-bottom: 1px solid var(--hairline);
}

.inspector-tabs button {
  min-height: 2.2rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 900;
}

.inspector-tabs button.active {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.inspector-section {
  display: none;
  max-height: calc(100vh - 11rem);
  overflow: auto;
  padding: 1rem;
}

.inspector-section.active {
  display: grid;
  gap: 0.72rem;
}

.panel-heading {
  display: grid;
  gap: 0.15rem;
}

.evidence-list,
.contribution-list,
.service-list,
.runtime-list,
.screenshot-list,
.next-list {
  display: grid;
  gap: 0.62rem;
}

.evidence-card,
.contribution-card,
.service-card,
.next-card,
.screenshot-card,
.command-card {
  border: 1px solid var(--hairline);
  border-radius: 18px;
  padding: 0.78rem;
  background: rgba(255, 255, 255, 0.06);
}

.evidence-card {
  display: grid;
  gap: 0.34rem;
}

.card-topline {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
}

.card-topline strong {
  font-size: 0.92rem;
}

.status-token {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  border-radius: 999px;
  padding: 0.12rem 0.4rem;
  background: rgba(50, 208, 116, 0.14);
  color: #c7ffd8;
  font-size: 0.64rem;
  font-weight: 900;
  text-transform: uppercase;
}

.status-token.pending {
  background: rgba(255, 214, 107, 0.14);
  color: #ffe6a2;
}

.status-token.risk {
  background: rgba(255, 92, 112, 0.16);
  color: #ffb4be;
}

.evidence-card p,
.contribution-card p,
.service-card p,
.next-card p,
.screenshot-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.evidence-card code,
.command-card code {
  display: block;
  overflow-x: auto;
  border-radius: 12px;
  padding: 0.58rem;
  background: rgba(0, 0, 0, 0.28);
  color: #bfe9ff;
  font-size: 0.75rem;
  white-space: nowrap;
}

.contribution-card dl,
.service-card dl {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.34rem 0.62rem;
  margin: 0.55rem 0 0;
  font-size: 0.82rem;
}

.contribution-card dt,
.service-card dt {
  color: var(--muted);
  font-weight: 850;
}

.contribution-card dd,
.service-card dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.screenshot-card img {
  display: block;
  width: 100%;
  margin-bottom: 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.24);
}

.command-card {
  display: grid;
  gap: 0.5rem;
}

@media (max-width: 980px) {
  .buddy-shell {
    grid-template-columns: 1fr;
    width: min(100% - 1rem, 700px);
  }

  .buddy-shell > * {
    min-width: 0;
  }

  .observer-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 620px) {
  .messages-topbar {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .top-action {
    display: none;
  }

  .contact-stack small {
    max-width: 11rem;
  }

  .buddy-shell {
    max-width: 100vw;
    width: 100%;
    margin: 0;
    overflow: hidden;
  }

  .phone-surface,
  .observer-panel {
    width: 100vw;
    max-width: 100vw;
    border-inline: 0;
    border-radius: 0;
  }

  .phone-surface {
    min-height: calc(100vh - 5rem);
  }

  .live-pill {
    display: none;
  }

  .agent-strip {
    grid-template-columns: 1fr;
  }

  .mini-avatar {
    flex-basis: 1.55rem;
    width: 1.55rem;
    height: 1.55rem;
    font-size: 0.56rem;
  }

  .bubble-row.codex {
    justify-content: flex-start;
  }

  .codex .mini-avatar {
    order: 0;
  }

  .codex .bubble {
    border-bottom-right-radius: 21px;
    border-bottom-left-radius: 6px;
  }

  .bubble {
    max-width: min(76vw, 19rem);
  }
}
