/* ============================================================
   💬 Chat (couple/chat.js): a full-screen conversation
   ============================================================ */
.sheet.is-chat .sheet-body { padding: 0 12px 8px; display: flex; flex-direction: column; }
.sheet.is-chat .sheet-footer { padding: 8px 10px max(8px, var(--safe-bottom)); }

/* top bar: count, search, pinned notes */
.chat-bar { position: sticky; top: 0; z-index: 3; margin: 0 -12px; padding: 4px 12px 6px; background: rgba(255, 248, 238, .94); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.chat-bar-row { display: flex; align-items: center; justify-content: space-between; min-height: 30px; }
.chat-count { font-size: var(--fs-xs); font-weight: 700; }
.chat-search-btn { width: 30px; height: 30px; font-size: 14px; }
.chat-pins { margin-top: 4px; display: flex; flex-direction: column; gap: 2px; }
.chat-pins-head, .chat-pin { display: flex; align-items: center; gap: 6px; width: 100%; text-align: left; padding: 6px 10px; border-radius: var(--r-md); background: #fffbeb; border: 1px solid #fde68a; font-size: var(--fs-xs); color: var(--ink-2); }
.chat-pins-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-pins-n { color: var(--ink-3); font-weight: 800; flex-shrink: 0; }
.chat-pin { background: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }

/* the log: grows from the bottom when it is short */
.chat-log { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; padding-top: 8px; }
.chat-older { display: block; margin: 4px auto 8px; }
.chat-start { text-align: center; font-size: var(--fs-xs); color: var(--ink-3); font-weight: 700; margin: 8px 0 4px; }
.chat-empty { margin: auto 0; }
.chat-time { align-self: center; margin: 14px 0 6px; padding: 2px 10px; border-radius: var(--r-pill); background: rgba(0, 0, 0, .05); font-size: 11px; font-weight: 800; color: var(--ink-3); }

.chat-group { display: flex; flex-direction: column; gap: 3px; margin-top: 10px; }
.chat-time + .chat-group { margin-top: 0; }
.sheet.is-chat .chat-msg { max-width: 100%; display: flex; flex-direction: row; align-items: flex-end; gap: 6px; align-self: stretch; border-radius: 12px; transition: background .4s; }
.sheet.is-chat .chat-msg.is-mine { justify-content: flex-end; }
.chat-col { display: flex; flex-direction: column; gap: 2px; max-width: 78%; min-width: 0; }
.chat-msg.is-mine .chat-col { align-items: flex-end; }
.chat-avatar { width: 28px; height: 28px; font-size: 13px; box-shadow: none; flex-shrink: 0; }
.chat-avatar.is-blank { visibility: hidden; }
.chat-name { font-size: 11px; font-weight: 800; color: var(--ink-3); padding: 0 8px; }

.sheet.is-chat .chat-bubble { white-space: pre-wrap; padding: 8px 12px; border-radius: 18px; }
/* the corners next to the rest of the group sit closer, and the last one has the tail */
.sheet.is-chat .chat-msg:not(.is-mine) .chat-bubble { border-bottom-left-radius: 6px; }
.sheet.is-chat .chat-msg:not(.is-mine):not(.is-first) .chat-bubble { border-top-left-radius: 6px; }
.sheet.is-chat .chat-msg.is-mine .chat-bubble { border-bottom-right-radius: 6px; }
.sheet.is-chat .chat-msg.is-mine:not(.is-first) .chat-bubble { border-top-right-radius: 6px; }
.sheet.is-chat .chat-quote { text-align: left; max-width: 100%; }
.sheet.is-chat .chat-reacts { margin-top: -4px; }
.sheet.is-chat .chat-msg.is-pinned .chat-bubble::after { content: " 📌"; font-size: 11px; }
.chat-msg.is-flash { background: rgba(251, 113, 133, .16); }
.chat-group > .chat-read { align-self: flex-end; font-size: 10px; color: var(--ink-3); font-weight: 700; padding: 0 4px; }
.chat-typing { margin: 10px 0 2px 34px; }

/* "↓ 3 条新消息" */
.chat-pill { position: sticky; bottom: 8px; align-self: center; z-index: 3; margin-top: 8px; padding: 6px 14px; border-radius: var(--r-pill); background: var(--rose); color: #fff; font-size: var(--fs-xs); font-weight: 800; box-shadow: var(--sh-1); }

/* search */
.sheet.is-chat .chat-bar + .input { margin: 10px 0; }
.chat-results { display: flex; flex-direction: column; gap: 6px; }
.chat-result { text-align: left; padding: 10px 12px; border-radius: var(--r-md); background: #fff; border: 1px solid var(--line); }
.chat-result-meta { font-size: 11px; font-weight: 800; color: var(--ink-3); margin-bottom: 2px; }
.chat-result-text { font-size: var(--fs-sm); line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.chat-hint { text-align: center; margin-top: 24px; }

/* composer */
.chat-composer { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-composer .reply-bar { margin-bottom: 6px; }
.chat-quick { margin-bottom: 6px; }
.chat-quick .chip-row { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; touch-action: pan-x; }
.chat-quick .chip-row::-webkit-scrollbar { display: none; }
.chat-quick .relay-toggle { margin-top: 6px; }
.chat-row { display: flex; align-items: flex-end; gap: 6px; }
.chat-extras { width: 38px; height: 38px; font-size: 17px; }
.chat-extras.is-on { background: #ffe4e6; }
.chat-input { flex: 1; min-width: 0; resize: none; min-height: 38px; max-height: 120px; padding: 8px 12px; line-height: 1.4; border-radius: 19px; overflow-y: auto; }
.sheet-footer .chat-send { flex: none; height: 38px; padding: 0 16px; border-radius: 19px; }
.chat-send:disabled { opacity: .45; }

/* a wide screen: the conversation keeps a readable width */
@media (min-width: 900px) {
  .sheet.is-chat .chat-log, .sheet.is-chat .chat-results, .sheet.is-chat .chat-bar + .input { width: 100%; max-width: 760px; margin-inline: auto; }
  .sheet.is-chat .chat-bar-row, .sheet.is-chat .chat-pins { max-width: 760px; margin-inline: auto; }
  .chat-composer { max-width: 760px; margin-inline: auto; }
}

/* long press: the app's menu, not the phone's text selection */
@media (pointer: coarse) {
  .sheet.is-chat .chat-bubble { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}
.note-actions { flex: 1; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.sheet-footer .note-actions .btn { flex: none; }

/* swipe left to answer */
.sheet.is-chat .chat-msg { position: relative; }
.chat-col { transition: transform .2s var(--ease-spring, ease); }
.chat-msg.is-swiping .chat-col { transition: none; }
.chat-msg::after { content: "↩︎"; position: absolute; right: 4px; top: 50%; transform: translateY(-50%) scale(.6); opacity: 0; font-size: 18px; color: var(--rose); transition: opacity .15s, transform .15s; pointer-events: none; }
.chat-msg.is-swiping::after { opacity: .4; }
.chat-msg.is-ready::after { opacity: 1; transform: translateY(-50%) scale(1); }

/* a message taken back */
.chat-recalled { align-self: center; margin: 8px 0; font-size: 11px; font-weight: 700; color: var(--ink-3); display: flex; align-items: center; gap: 6px; }
.chat-reedit { color: var(--rose); font-weight: 800; font-size: 11px; }

/* photos */
.chat-photo { display: block; padding: 0; border-radius: 14px; overflow: hidden; background: #f3e8de; border: 1px solid var(--line); position: relative; }
.chat-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-photo.is-pending { width: 150px; height: auto; min-height: 90px; opacity: .7; }
.chat-photo.is-pending img { height: auto; }
.chat-sending { font-size: 11px; font-weight: 800; color: var(--ink-3); }
.chat-photo .chat-sending { position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 8px; background: rgba(0, 0, 0, .4); color: #fff; text-align: center; }
.sheet.is-photo-view { background: #000; }
.sheet.is-photo-view .sheet-header { background: #000; color: #fff; }
.sheet.is-photo-view .sheet-body { display: flex; align-items: center; justify-content: center; padding: 0; }
.chat-photo-full { max-width: 100%; max-height: 100%; object-fit: contain; }

/* voice messages */
.sheet.is-chat .chat-voice { display: flex; align-items: center; gap: 8px; min-height: 40px; text-align: left; position: relative; }
.chat-msg.is-mine .chat-voice { flex-direction: row-reverse; }
.chat-voice-dur { font-size: var(--fs-sm); font-weight: 700; color: var(--ink-2); }
.chat-voice-wave { display: inline-flex; align-items: center; gap: 2px; height: 16px; }
.chat-voice-wave i { width: 3px; border-radius: 2px; background: currentColor; opacity: .55; }
.chat-voice-wave i:nth-child(1) { height: 6px; }
.chat-voice-wave i:nth-child(2) { height: 11px; }
.chat-voice-wave i:nth-child(3) { height: 16px; }
.chat-voice.is-playing .chat-voice-wave i { animation: chatWave .9s ease-in-out infinite; opacity: 1; }
.chat-voice.is-playing .chat-voice-wave i:nth-child(2) { animation-delay: .15s; }
.chat-voice.is-playing .chat-voice-wave i:nth-child(3) { animation-delay: .3s; }
@keyframes chatWave { 0%, 100% { transform: scaleY(.5); } 50% { transform: scaleY(1.1); } }
.chat-voice-dot { position: absolute; right: -14px; top: 50%; width: 8px; height: 8px; margin-top: -4px; border-radius: 50%; background: var(--rose); }
.chat-voice.is-pending { opacity: .7; justify-content: space-between; }

/* composer: photo and hold-to-talk */
.chat-photo-btn { width: 38px; height: 38px; font-size: 17px; }
.sheet-footer .chat-mic { flex: none; height: 38px; width: 64px; padding: 0; border-radius: 19px; font-size: 18px; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.chat-mic.is-holding { background: var(--rose); color: #fff; transform: scale(1.06); }
.chat-rec { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 20; width: 180px; padding: 18px 14px; border-radius: 20px; background: rgba(30, 20, 40, .82); color: #fff; text-align: center; pointer-events: none; }
.chat-rec-icon { font-size: 40px; animation: chatPulse 1.2s ease-in-out infinite; }
.chat-rec-time { font-size: var(--fs-md); font-weight: 900; margin-top: 4px; }
.chat-rec-hint { font-size: 12px; margin-top: 6px; opacity: .85; }
.chat-rec.is-cancel { background: rgba(190, 18, 60, .9); }
.chat-rec.is-cancel .chat-rec-icon { animation: none; }
@keyframes chatPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }

/* the cat's own messages */
.chat-avatar.is-cat { background: linear-gradient(135deg, #fde68a, #f59e0b); font-size: 15px; }
.chat-msg:has(.chat-avatar.is-cat) .chat-bubble { background: #fffbeb; border-color: #fde68a; }

/* date jump */
.chat-bar-tools { display: flex; gap: 6px; }
.chat-date-btn { width: 30px; height: 30px; font-size: 14px; }

/* my messages not on the server yet, uploads that failed */
.chat-group > .chat-status { align-self: flex-end; font-size: 10px; font-weight: 700; color: var(--ink-3); padding: 0 4px; }
.chat-status.is-failed { display: flex; gap: 6px; color: var(--rose); }
.chat-retry { font-size: 11px; font-weight: 800; color: var(--rose); padding: 2px 8px; border-radius: var(--r-pill); background: #ffe4e6; }
.chat-retry.is-drop { color: var(--ink-3); background: #f5efe9; }
.chat-msg.is-failed .chat-sending { color: var(--rose); }
.chat-photo.is-pending .chat-sending { color: #fff; }
.chat-msg.is-failed .chat-photo .chat-sending { background: rgba(190, 18, 60, .75); }

/* the cat answering */
.chat-typing.is-cat { color: #b45309; }
.chat-cat-ai { margin-left: 6px; }
.chat-quick-tip { margin-top: 6px; font-size: 11px; color: var(--ink-3); line-height: 1.5; }
