.chat-page {
  position: relative;
}

.chat-top {
  position: absolute;
  z-index: 20;
  top: 0;
  left: 0;
  right: 0;
  height: calc(44px + var(--safe-top));
  padding: var(--safe-top) 12px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  pointer-events: none;
  flex-shrink: 0;
}

.chat-top .icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 19px;
  color: var(--text-2);
  font-size: 21px;
  pointer-events: auto;
}

.chat-top .icon-btn:active {
  background: var(--chat-icon-bg, var(--bg-elev));
}

.chat-top .menu-left {
  position: absolute;
  left: 8px;
  top: calc(var(--safe-top) + 3px);
}

.chat-top .chat-search,
.chat-top .chat-top-spacer {
  position: absolute;
  right: 8px;
  top: calc(var(--safe-top) + 3px);
}

.chat-top .chat-top-spacer {
  pointer-events: none;
}

.peer {
  color: var(--text);
  font-size: 16px;
  line-height: 24px;
  font-weight: 500;
  letter-spacing: 2px;
}

.online-dot {
  display: none;
}

.ctx-bar {
  height: 0;
  overflow: hidden;
  flex-shrink: 0;
}

.ctx-bar .fill {
  height: 0;
}

.chat-fade {
  display: none;
}

.chat-stream {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: calc(var(--safe-top) + 58px) 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-padding-top: calc(var(--safe-top) + 58px);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, rgb(0 0 0 / 0.12) calc(var(--safe-top) + 10px), rgb(0 0 0 / 0.72) calc(var(--safe-top) + 42px), #000 calc(var(--safe-top) + 74px), #000 100%);
  mask-image: linear-gradient(to bottom, transparent 0, rgb(0 0 0 / 0.12) calc(var(--safe-top) + 10px), rgb(0 0 0 / 0.72) calc(var(--safe-top) + 42px), #000 calc(var(--safe-top) + 74px), #000 100%);
}

.chat-stream.long-press-locked {
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: contain;
}

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

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

.msg-row {
  max-width: 82%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  -webkit-touch-callout: none;
  user-select: none;
}

.msg-row.long-press-source-hidden {
  opacity: 0;
}

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

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

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

.msg-bubble {
  position: relative;
  max-width: 100%;
  min-height: 30px;
  padding: 6px 12px;
  border-radius: 16px;
  font-family: var(--font-ui);
  font-size: 13.5px;
  line-height: 1.55;
  font-weight: 400;
  letter-spacing: 0.15px;
  text-wrap: pretty;
  word-break: break-word;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.msg-row.user .msg-bubble {
  background: var(--bubble-user);
  color: var(--on-bubble-user, #fff);
}

.msg-row.ai .msg-bubble {
  background: var(--bubble-ai);
  color: var(--text);
}

.msg-row.user .msg-bubble.tail {
  border-bottom-right-radius: 4px;
}

.msg-row.ai .msg-bubble.tail {
  border-bottom-left-radius: 4px;
}

.msg-bubble.has-time {
  padding-bottom: 7px;
}

.btext {
  display: inline;
  font-size: 12.5px;
}

.msg-row.streaming .btext {
  white-space: pre-wrap;
}

.tspace {
  display: inline-block;
  width: 34px;
  height: 1px;
}

.tspace.user {
  width: 54px;
}

.bubble-time {
  position: absolute;
  right: 8px;
  bottom: 4px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--text-3);
  font-size: 9.5px;
  line-height: 12px;
  letter-spacing: 0.2px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.msg-row.user .bubble-time {
  color: var(--bubble-user-time, rgb(255 255 255 / 0.78));
}

.msg-bubble.has-attachments {
  padding-bottom: 6px;
}

.msg-bubble.has-attachments .btext {
  display: block;
}

.msg-bubble.has-attachments .tspace {
  display: none;
}

.msg-bubble.has-attachments .bubble-time {
  position: static;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
  margin-top: 6px;
}

.read-checks {
  display: inline-flex;
  color: currentColor;
  opacity: 0.9;
}

.read-checks svg {
  width: 12px;
  height: 12px;
}

.msg-bubble p {
  margin: 0;
}

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

.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-attachments {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.msg-attachment {
  color: inherit;
}

.msg-attachment.image {
  display: block;
  overflow: hidden;
  border-radius: 14px;
}

.msg-attachment.image img {
  display: block;
  max-width: min(240px, 62vw);
  max-height: 320px;
  object-fit: contain;
  border-radius: inherit;
}

.msg-attachment.file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  line-height: 18px;
  opacity: 0.9;
}

.msg-attachment.file svg {
  width: 14px;
  height: 14px;
}

.thought {
  padding: 0 0 6px;
  color: var(--text-3);
  font-size: 10.5px;
  line-height: 14px;
  letter-spacing: 0.3px;
}

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

.thought button:disabled {
  cursor: default;
}

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

.thought-expanded {
  width: 100%;
  margin: -2px 0 8px;
  color: var(--text-2);
}

.thought-body {
  position: relative;
  margin-left: 5px;
  padding-left: 0;
}

.thought-body::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 7px;
  bottom: 7px;
  width: 1px;
  background: var(--thought-line, var(--border-soft));
}

.tstep {
  position: relative;
  min-height: 22px;
  margin: 0 0 10px;
}

.tstep:last-child {
  margin-bottom: 0;
}

.tmark {
  position: absolute;
  z-index: 1;
  left: 0;
  top: 0;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--text-3);
}

.tmark svg {
  width: 20px;
  height: 20px;
  stroke-width: 1.7;
}

.tbody {
  min-width: 0;
  padding-left: 32px;
}

.ttext {
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.55;
  letter-spacing: 0.2px;
  white-space: pre-wrap;
}

.mcp-tags {
  margin-top: 5px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

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

.tstep.done .tmark {
  color: var(--done, var(--accent));
}

.tstep.done .ttext {
  color: var(--done, var(--accent));
  font-size: 12.5px;
}

.tool-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0 0 4px;
}

.composer {
  position: relative;
  padding: 8px 10px 8px;
  background: var(--bg);
  flex-shrink: 0;
}

.row-input {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 4px;
}

.plus,
.send {
  width: 38px;
  height: 38px;
  min-width: 38px;
  display: grid;
  place-items: center;
  border-radius: 19px;
  background: var(--chat-icon-bg, var(--bg-elev));
  color: var(--text-2);
  font-size: 21px;
}

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

.send:disabled {
  opacity: 0.35;
}

.textarea-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
}

.composer textarea {
  flex: 1;
  width: 100%;
  min-height: 38px;
  max-height: 112px;
  margin: 0;
  padding: 9px 48px 9px 14px;
  resize: none;
  overflow-y: auto;
  border-radius: 19px;
  background: var(--bg-sunken);
  color: var(--text);
  font-size: 12.5px;
  line-height: 20px;
}

.composer textarea::placeholder {
  color: var(--text-3);
  font-size: 12.5px;
}

.textarea-wrap textarea:not(:placeholder-shown) + .context-hint {
  display: none;
}

.context-hint {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  color: var(--text-3);
  opacity: 0.72;
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.2px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.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: 6px;
  width: min(260px, 68vw);
}

.inline-message-edit textarea {
  width: 100%;
  min-height: 1.6em;
  padding: 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 12.5px;
  line-height: 1.6;
}

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

.inline-message-edit .actions button {
  padding: 4px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  color: var(--text-2);
}

.inline-message-edit .actions .send-edit {
  background: var(--text);
  color: var(--bg);
}

.long-press-float {
  position: absolute;
  z-index: 70;
  max-width: none;
  overflow: visible;
  pointer-events: none;
  animation: long-press-float-in 170ms ease-out both;
}

.long-press-float.clipped {
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 26px), transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 26px), transparent 100%);
}

.long-press-float > .msg-row {
  width: 100%;
  max-width: none;
}

.chat-search-form {
  padding: 8px 22px 0;
}

.chat-search-form input {
  width: 100%;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  background: var(--bg-elev);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
  color: var(--text);
  font-size: 13px;
}

.phone .chat-search-form input {
  display: block;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border-soft);
  background: var(--bg-elev);
  border-radius: 14px;
}

.chat-filter-row {
  padding: 10px 22px 8px 22px;
  display: flex;
  gap: 8px;
}

.phone .chat-filter-row {
  padding-left: 22px;
}

.chat-filter-row .chip {
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--text-2);
  font-size: 12px;
  letter-spacing: 0.4px;
}

.search-section-title,
.search-detail-title {
  padding: 14px 22px 7px;
  color: var(--text-3);
  font-size: 11px;
  letter-spacing: 1px;
}

.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;
}

.search-result .meta {
  color: var(--text-3);
  font-size: 11.5px;
}

.media-grid {
  padding: 0 22px 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.phone .media-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.media-tile {
  width: 100%;
  min-width: 0;
  aspect-ratio: 1;
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  background: var(--bg-elev);
  color: var(--text-2);
}

.media-tile img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.media-tile.file {
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.media-tile .file-ico svg {
  width: 24px;
  height: 24px;
  color: var(--accent);
}

.media-tile .file-name {
  max-width: 100%;
  overflow: hidden;
  color: var(--text-2);
  font-size: 10.5px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-meta {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 14px 5px 4px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.52), transparent);
  color: #fff;
  font-size: 9px;
  line-height: 1.2;
  text-align: left;
  opacity: 0.92;
}

.media-tile.file .media-meta {
  display: none;
}

.media-preview {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: flex;
  background: rgba(0, 0, 0, 0.92);
  color: #fff;
}

.media-preview .close {
  position: absolute;
  z-index: 2;
  top: calc(var(--safe-top) + 10px);
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 26px;
  line-height: 1;
}

.media-preview-image {
  flex: 1;
  width: 100%;
  min-height: 0;
  padding: calc(var(--safe-top) + 56px) 0 calc(24px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-preview-image img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.search-calendar {
  margin: 0 18px 24px;
  padding: 0 4px 22px;
}

.search-calendar .week,
.search-calendar .days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
}

.search-calendar .week {
  position: sticky;
  top: 0;
  z-index: 3;
  padding: 9px 0 10px;
  border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(12px);
  color: var(--text-3);
  font-size: 12px;
  letter-spacing: 1px;
}

.search-calendar-list {
  padding-top: 10px;
}

.search-month-block {
  padding: 18px 0 28px;
  border-bottom: 1px solid var(--border-soft);
}

.search-month-block:last-child {
  border-bottom: 0;
}

.search-month-title {
  padding: 0 0 14px 7px;
  color: var(--text-3);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.8px;
}

.search-month-days {
  row-gap: 9px;
}

.search-calendar .day {
  min-width: 0;
  height: 48px;
  display: grid;
  place-items: center;
  color: var(--text-2);
  font-size: 17px;
  position: relative;
  border-radius: 18px;
}

.search-calendar .day.ghost {
  pointer-events: none;
}

.search-calendar .day:not(.ghost):active {
  background: var(--bg-sunken);
}

.search-calendar .day.today span {
  box-shadow: inset 0 0 0 1.5px var(--accent);
}

.search-calendar .day.has span {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--accent) 20%, var(--bg));
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 18%, transparent);
}

.search-calendar .day i {
  position: absolute;
  bottom: 0;
  min-width: 14px;
  height: 14px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--text-3);
  font-size: 9px;
  line-height: 14px;
  font-style: normal;
}

.search-choice-panel {
  position: absolute;
  left: 28px;
  right: 28px;
  top: 30%;
  z-index: 10;
  padding: 14px;
  border-radius: 18px;
  background: var(--bg);
  box-shadow: var(--shadow-menu);
}

.search-choice-panel .title {
  margin-bottom: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 1px;
}

.search-choice-panel button {
  width: 100%;
  padding: 12px 4px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--border-soft);
  color: var(--text-2);
  font-size: 13px;
  text-align: left;
}

.search-choice-panel em {
  color: var(--text-3);
  font-size: 11px;
  font-style: normal;
  white-space: nowrap;
}

.msg-row.jump-highlight .msg-bubble {
  animation: message-jump 1.2s ease;
}

@keyframes message-jump {
  0%, 100% { box-shadow: none; }
  18%, 72% { box-shadow: 0 0 0 3px var(--accent-soft), 0 8px 24px rgba(0, 0, 0, 0.14); }
}
