.chat-top {
  position: relative;
  z-index: 5;
  height: 40px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  flex-shrink: 0;
}

.chat-top .menu-left {
  position: absolute;
  left: 8px;
  top: 3px;
}

.chat-top .search-right {
  position: absolute;
  right: 8px;
  top: 3px;
}

.peer {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
  font-size: 16px;
  line-height: 24px;
  font-weight: 500;
  letter-spacing: 2px;
}

.online-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--online);
}

.ctx-bar {
  position: relative;
  height: 2px;
  background: var(--border-soft);
  flex-shrink: 0;
}

.ctx-bar .fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 2%;
  background: var(--text-3);
  opacity: 0.5;
  transition: width 400ms ease;
}

.ctx-bar .fill.warn {
  background: var(--warn);
  opacity: 0.85;
}

.ctx-bar .fill.full {
  background: var(--warn);
  opacity: 1;
  animation: ctx-pulse 8s ease-in-out infinite;
}

@keyframes ctx-pulse {
  50% {
    opacity: 0.85;
  }
}

.chat-fade {
  position: absolute;
  z-index: 4;
  top: 42px;
  left: 0;
  right: 0;
  height: 26px;
  pointer-events: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  background: linear-gradient(to bottom, var(--bg), color-mix(in srgb, var(--bg) 0%, transparent));
  mask-image: linear-gradient(to bottom, #000 0, #000 34%, transparent 100%);
}

.chat-stream {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 18px 18px 4px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.chat-empty {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 0 48px;
  color: var(--text-3);
  font-size: 13px;
  line-height: 1.8;
  text-align: center;
}

.msg-time-center {
  align-self: center;
  margin: 6px 0;
  color: var(--text-3);
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
}

.msg-row {
  max-width: 78%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-row.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row.ai {
  align-self: flex-start;
  align-items: flex-start;
  max-width: 86%;
}

.ai-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}

.msg-bubble {
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.6;
  letter-spacing: 0.2px;
  text-wrap: pretty;
  word-break: break-word;
}

.msg-row.user .msg-bubble {
  border-top-right-radius: 6px;
  background: var(--bubble-user);
  color: #fff;
}

.msg-row.ai .msg-bubble {
  border-top-left-radius: 6px;
  background: var(--bubble-ai);
  color: var(--text);
}

.ai-group .msg-bubble + .msg-bubble {
  border-top-left-radius: 12px;
}

.msg-bubble p {
  margin: 0;
}

.msg-bubble p + p,
.msg-bubble ul + p,
.msg-bubble p + ul {
  margin-top: 10px;
}

.msg-bubble ul {
  margin: 0;
  padding-left: 18px;
}

.msg-bubble pre {
  margin: 8px 0 0;
  padding: 10px 12px;
  overflow-x: auto;
  border-radius: 10px;
  background: var(--bg-sunken);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
}

.msg-foot {
  padding: 0 4px;
  color: var(--text-3);
  font-size: 10.5px;
  line-height: 14px;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
}

.thought {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0 6px;
  color: var(--text-3);
  font-size: 12px;
  line-height: 16px;
}

.thought button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: inherit;
}

.thought .chev {
  width: 10px;
  height: 10px;
  opacity: 0.7;
}

.thought-expanded {
  margin: 0 0 8px 4px;
  padding: 4px 0 0 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-left: 1px solid var(--border);
  color: var(--text-3);
}

.thought-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 12.5px;
  line-height: 1.55;
}

.thought-step svg {
  width: 12px;
  height: 12px;
  margin-top: 3px;
}

.thought-step.done {
  color: var(--accent);
}

.tool-tag {
  display: inline-flex;
  margin: 3px 4px 0 0;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-elev);
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 16px;
}

.composer {
  position: relative;
  padding: 10px 12px 2px;
  margin-bottom: 8px;
  border-top: 1px solid var(--border-soft);
  background: var(--bg);
  flex-shrink: 0;
}

.row-input {
  display: flex;
  align-items: flex-end;
  gap: 2px;
}

.plus,
.clock,
.send {
  width: 38px;
  height: 38px;
  min-width: 38px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: var(--text-2);
  font-size: 22px;
}

.plus.open {
  background: var(--bg-elev);
  color: var(--accent);
}

.send {
  color: var(--accent);
}

.send:disabled {
  opacity: 0.35;
}

.composer textarea {
  flex: 1;
  min-height: 40px;
  max-height: 112px;
  margin: 0 4px;
  padding: 10px 16px;
  resize: none;
  overflow-y: auto;
  border-radius: 20px;
  background: var(--bg-sunken);
  color: var(--text);
  font-size: 14.5px;
  line-height: 20px;
}

.composer textarea::placeholder {
  color: var(--text-3);
}

.pending-attachments {
  padding: 0 44px 8px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.attachment-chip {
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--text-2);
  font-size: 11.5px;
  white-space: nowrap;
}

.inline-message-edit {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.inline-message-edit textarea {
  min-width: 190px;
  color: inherit;
  line-height: 1.6;
}

.inline-message-edit .actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  font-size: 12px;
}

.long-press-active .msg-bubble {
  transform: scale(1.02);
  box-shadow: 0 4px 24px oklch(0 0 0 / 0.18);
}

.search-result {
  width: 100%;
  padding: 13px 22px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.search-result .top {
  display: flex;
  justify-content: space-between;
  color: var(--text-3);
  font-size: 11px;
  letter-spacing: 0.5px;
}

.search-result .who {
  color: var(--accent);
}

.search-result .body {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text-2);
  font-size: 13px;
  line-height: 20px;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
