/* chat module styles (builds on base.css tokens). */

/* -- rooms list (sidebar + phone list) ------------------------------------------- */

.chat-rooms { display: flex; flex-direction: column; }
.chat-room-item {
  display: flex; align-items: center; gap: 9px; width: 100%; height: 32px; padding: 0 8px 0 10px; border-radius: 6px;
  color: var(--text-2); font-size: 13.5px; font-weight: 500; text-align: left; transition: background 0.1s, color 0.1s;
}
.chat-room-item:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.chat-room-item.is-active { background: var(--selected); color: var(--accent-text); font-weight: 600; }
.chat-room-item.is-unread { color: var(--text); font-weight: 700; }
.chat-room-item.is-muted { color: var(--text-3); }
.chat-room-icon { width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; color: var(--text-3); flex: none; }
.chat-room-item.is-active .chat-room-icon { color: var(--accent); }
.chat-room-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-room-muted { color: var(--text-3); flex: none; }
.chat-room-add { color: var(--text-3); }
.chat-room-item .avatar-stack .avatar + .avatar { margin-left: -8px; }
.chat-badge {
  min-width: 18px; height: 18px; padding: 0 6px; border-radius: 9px; background: var(--surface-3); color: var(--text-2);
  font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none;
  font-variant-numeric: tabular-nums;
}
.chat-room-item.is-unread .chat-badge { background: var(--accent); color: #fff; }
.chat-badge.is-mention { background: var(--red); color: #fff; }

.chat-mobile-list { display: flex; flex-direction: column; min-height: 0; flex: 1; overflow-y: auto; }
.chat-rooms.is-page .chat-room-item { height: 44px; font-size: 15px; }
.chat-rooms.is-page .sidebar-section-actions { opacity: 1; }

/* -- room layout ------------------------------------------------------------------ */

.chat-main { display: flex; flex: 1; min-height: 0; min-width: 0; }
.chat-main > .empty, .chat-main > .loading { flex: 1; align-self: center; }
.chat-room { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; position: relative; }

.chat-head { gap: 8px; }
.chat-head-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-head-name { display: flex; align-items: center; gap: 6px; min-width: 0; color: var(--text-2); }
.chat-head-name .page-title { color: var(--text); }
.chat-head-topic {
  font-size: 12.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: left; max-width: 100%; padding: 0; min-height: 16px;
}
button.chat-head-topic:hover { color: var(--text-2); }
.chat-head-members {
  display: inline-flex; align-items: center; height: 30px; padding: 0 4px; border-radius: 15px;
  border: 1px solid var(--border); color: var(--text-2);
}
.chat-head-members:hover { background: var(--hover); }

.chat-list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 0 6px; overscroll-behavior: contain; }

.chat-intro { padding: 28px 24px 14px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.chat-intro h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; }
.chat-intro p { margin: 0; }
.chat-intro-icon {
  width: 48px; height: 48px; border-radius: 12px; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}

.chat-day, .chat-unread-divider, .chat-thread-divider {
  display: flex; align-items: center; gap: 10px; margin: 14px 20px 6px; font-size: 12px; font-weight: 650; color: var(--text-3);
}
.chat-day::before, .chat-day::after, .chat-thread-divider::after { content: ''; flex: 1; height: 1px; background: var(--divider); }
.chat-day span {
  padding: 2px 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); flex: none;
}
.chat-unread-divider { color: var(--red); margin: 6px 20px; }
.chat-unread-divider::before { content: ''; flex: 1; height: 1px; background: var(--red); opacity: 0.55; }
.chat-unread-divider span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }

/* -- messages --------------------------------------------------------------------- */

.chat-msg { position: relative; display: flex; gap: 10px; padding: 6px 20px 4px; min-width: 0; }
.chat-msg.is-grouped { padding-top: 1px; padding-bottom: 2px; }
.chat-msg:focus { outline: none; }
.chat-msg:hover, .chat-msg:focus-within { background: var(--surface-2); }
.chat-msg.is-highlight { animation: chat-highlight 2.6s var(--ease); }
@keyframes chat-highlight { 0%, 40% { background: var(--accent-soft); } 100% { background: transparent; } }
.chat-msg-gutter { width: 34px; flex: none; display: flex; justify-content: center; padding-top: 2px; }
.chat-msg-hovertime { font-size: 10.5px; color: var(--text-3); opacity: 0; line-height: 22px; white-space: nowrap; }
.chat-msg:hover .chat-msg-hovertime { opacity: 1; }
.chat-msg-main { flex: 1; min-width: 0; }
.chat-msg-head { display: flex; align-items: baseline; gap: 8px; line-height: 1.3; }
.chat-msg-author { font-weight: 700; font-size: 14px; }
.chat-msg-time { font-size: 11.5px; color: var(--text-3); }
.chat-msg-body { font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.chat-msg-body p { margin: 0; }
.chat-msg-body p + p { margin-top: 0.45em; }
.chat-msg-edited { font-size: 11px; color: var(--text-3); margin-left: 2px; }
.chat-msg-deleted { font-size: 13px; color: var(--text-3); font-style: italic; }

.chat-msg-tools {
  position: absolute; top: -12px; right: 16px; display: none; gap: 1px; padding: 2px; z-index: 2;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-1);
}
.chat-msg:hover .chat-msg-tools, .chat-msg-tools:focus-within { display: flex; }
/* Touch: tap a message to reveal its actions. */
@media (hover: none) {
  .chat-msg-tools { top: 2px; right: 8px; }
  .chat-msg:hover .chat-msg-tools { display: none; }
  .chat-msg:focus-within .chat-msg-tools { display: flex; }
}

.chat-attachments { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.chat-attachments .attachment { max-width: 320px; }

.chat-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.chat-reaction {
  display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 8px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); font-size: 13px; line-height: 1;
}
.chat-reaction:hover { border-color: var(--border-strong); background: var(--hover); }
.chat-reaction.is-mine { background: var(--accent-soft); border-color: var(--accent); }
.chat-reaction-count { font-size: 11.5px; font-weight: 650; color: var(--text-2); font-variant-numeric: tabular-nums; }
.chat-reaction.is-mine .chat-reaction-count { color: var(--accent-text); }
.chat-reaction-add { color: var(--text-3); opacity: 0; padding: 0 6px; }
.chat-msg:hover .chat-reaction-add, .chat-reaction-add:focus-visible { opacity: 1; }
@media (hover: none) { .chat-reaction-add { opacity: 1; } }

.chat-thread-summary {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 5px; padding: 3px 10px 3px 4px; border-radius: 8px;
  font-size: 12.5px; border: 1px solid transparent; max-width: 100%;
}
.chat-thread-summary:hover { background: var(--surface); border-color: var(--border); }
.chat-thread-count { color: var(--accent-text); font-weight: 650; }
.chat-thread-summary .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-conv-card {
  display: flex; align-items: center; gap: 10px; margin-top: 6px; padding: 9px 12px; max-width: 460px;
  border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
.chat-conv-card:hover { background: var(--surface-2); text-decoration: none; border-color: var(--border-strong); border-left-color: var(--accent); }
.chat-conv-card.is-restricted { color: var(--text-3); border-left-color: var(--border-strong); font-size: 13px; gap: 6px; }
.chat-conv-icon { color: var(--accent); display: flex; flex: none; }
.chat-conv-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-conv-title { font-weight: 650; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-conv-sub { font-size: 12.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-edit { margin-top: 2px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); }
.chat-edit .rich-editor-content { padding: 8px 10px; min-height: 36px; }
.chat-edit-actions { display: flex; align-items: center; gap: 6px; padding: 4px 6px 6px 10px; }

/* -- composer --------------------------------------------------------------------- */

.chat-typing { height: 20px; padding: 0 22px; font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 6px; flex: none; }
.chat-typing-dots { display: inline-flex; gap: 3px; }
.chat-typing-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--text-3); animation: chat-dot 1.2s infinite ease-in-out; }
.chat-typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-dot { 0%, 60%, 100% { transform: none; opacity: 0.5; } 30% { transform: translateY(-3px); opacity: 1; } }

.chat-composer {
  margin: 0 16px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--surface);
  flex: none; transition: border-color 0.12s, box-shadow 0.12s;
}
.chat-composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.chat-composer .rich-editor-content { padding: 10px 12px 4px; min-height: 40px; overflow-y: auto; font-size: 14px; }
.chat-composer .editor-toolbar { border-bottom: 0; padding: 2px 6px 6px; }
.chat-composer-files { padding: 8px 10px 0; }
.chat-uploading { padding: 6px 12px 0; }
.chat-send { margin-left: 6px; }

.chat-jump {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 118px; z-index: 3;
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 14px; border-radius: 15px;
  background: var(--accent); color: #fff; font-size: 12.5px; font-weight: 650; box-shadow: var(--shadow-2);
  animation: pop-in 0.15s var(--ease);
}
.chat-jump:hover { background: var(--accent-hover); }

.chat-join {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin: 0 16px 14px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-2);
}

/* -- thread panel ----------------------------------------------------------------- */

.chat-thread {
  width: 400px; flex: none; display: flex; flex-direction: column; min-height: 0;
  border-left: 1px solid var(--border); background: var(--surface);
}
.chat-thread-head { display: flex; align-items: center; gap: 8px; min-height: var(--header-h); padding: 8px 10px 8px 16px; border-bottom: 1px solid var(--border); flex: none; }
.chat-thread-list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 0; }
.chat-thread .chat-msg { padding-left: 14px; padding-right: 14px; }
.chat-thread .chat-msg-tools { right: 10px; }
.chat-thread .chat-composer { margin: 0 10px 10px; }
.chat-thread-divider { margin: 10px 14px; }

@media (max-width: 1100px) {
  .chat-thread { width: 340px; }
}
@media (max-width: 900px) {
  .chat-main.has-thread .chat-room { display: none; }
  .chat-thread { width: auto; flex: 1; border-left: 0; }
}

/* -- modals & popovers ------------------------------------------------------------ */

.chat-name-input { display: flex; align-items: center; gap: 0; }
.chat-name-input > span {
  height: var(--btn-h); display: flex; align-items: center; padding: 0 9px; border: 1px solid var(--border-strong); border-right: 0;
  border-radius: var(--radius) 0 0 var(--radius); background: var(--surface-2); color: var(--text-3); font-weight: 650;
}
.chat-name-input .input { border-top-left-radius: 0; border-bottom-left-radius: 0; flex: 1; }

.chat-browse, .chat-people, .chat-share-list { display: flex; flex-direction: column; max-height: 52vh; overflow-y: auto; margin: 0 -6px; }
.chat-browse-row { display: flex; align-items: center; gap: 10px; padding: 9px 6px; border-bottom: 1px solid var(--divider); }
.chat-browse-row:last-child { border-bottom: 0; }
.chat-person, .chat-share-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 6px; text-align: left; width: 100%; min-width: 0;
}
.chat-person:hover, .chat-share-item:hover { background: var(--hover); }
.chat-person.is-picked { background: var(--selected); color: var(--accent-text); }
.chat-person .grow, .chat-share-item .grow { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-share-item > .icon, .chat-share-item > svg { color: var(--text-3); flex: none; }

.chat-members { display: flex; flex-direction: column; }
.chat-members-list { max-height: 320px; overflow-y: auto; padding: 4px; }
.chat-member { display: flex; align-items: center; gap: 9px; padding: 5px 8px; border-radius: 6px; color: var(--text); font-size: 13.5px; min-width: 0; }
.chat-member:hover { background: var(--hover); text-decoration: none; }
.chat-member .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }

/* -- phones ----------------------------------------------------------------------- */

@media (max-width: 760px) {
  .chat-msg { padding: 6px 12px 4px; gap: 8px; }
  .chat-msg-gutter { width: 30px; }
  .chat-day, .chat-unread-divider { margin-left: 12px; margin-right: 12px; }
  .chat-composer { margin: 0 8px calc(8px + env(safe-area-inset-bottom)); }
  .chat-join { margin: 0 8px 8px; }
  .chat-typing { padding: 0 14px; }
  .chat-jump { bottom: 104px; }
  .chat-intro { padding: 20px 14px 10px; }
  .chat-conv-card { max-width: 100%; }
  .chat-attachments .attachment { max-width: 100%; }
}
