/* The inbox as one chat screen (includes/inbox-ui.php, views/inbox.php, inbox-thread.php), and the Connect control on
   profile pages. Always loaded after css/profile.css and css/community.css; the app bar's css/dashboard.css comes first
   (includes/header.php). A two-pane chat screen in the site's own look (DESIGN.md): the list of chats on white at the
   left, the conversation on a white card at the right, forest for the member's own messages. */

/* ---- The screen: list | conversation, filling the window below the app bar ---- */
.ib-app {
  display: grid;
  grid-template-columns: clamp(300px, 26vw, 420px) minmax(0, 1fr);
  height: calc(100vh - var(--dash-bar-h, 60px) - var(--dash-bottom, 0px));
  height: calc(100dvh - var(--dash-bar-h, 60px) - var(--dash-bottom, 0px));
  min-height: 420px;
  overflow-wrap: anywhere;
}
.ib-svg { display: block; flex: none; height: 20px; width: 20px; }

/* ---- The list of chats ---- */
.ib-list {
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  position: relative;
}
.ib-list-head { align-items: center; display: flex; gap: 10px; justify-content: space-between; padding: 14px 16px 6px 20px; }
.ib-list-title { color: var(--gray-900); font-size: 1.65rem; font-weight: 800; line-height: 1.2; margin: 0; }
.ib-list-tools { display: flex; flex: none; gap: 8px; }
.ib-round {
  align-items: center;
  background: var(--gray-100);
  border-radius: 50%;
  color: var(--gray-800);
  cursor: pointer;
  display: inline-flex;
  height: 44px;
  justify-content: center;
  list-style: none;
  transition: background-color var(--transition-fast), color var(--transition-fast);
  width: 44px;
}
.ib-round:hover, .ib-drop[open] > .ib-round { background: var(--gray-200); color: var(--secondary-dark); }
.ib-round:focus-visible { outline: 2px solid var(--secondary); outline-offset: 2px; }
/* The list's menus hang from the list's own left edge, so they stay on screen however narrow it is */
.ib-list .ib-drop { position: static; }
.ib-list .ib-panel { left: 12px; right: auto; top: 64px; }
.ib-panel { max-height: min(72vh, 600px); padding: 16px 18px; width: min(360px, calc(100vw - 24px)); }
.ib-panel-title { color: var(--gray-900); font-size: 1.05rem; font-weight: 700; line-height: 1.35; margin: 0 0 10px; }
.ib-panel-text { color: var(--gray-700); font-size: 0.95rem; line-height: 1.55; }
.ib-panel-form .cm-show-name { margin: 12px 0; }
.ib-panel-foot { border-top: 1px solid var(--gray-200); margin-top: 16px; padding-top: 14px; }
.ib-panel-actions { display: grid; gap: 8px; margin-top: 14px; }
.ib-panel-actions .pv-btn { width: 100%; }

.ib-search {
  align-items: center;
  background: var(--gray-100);
  border: 2px solid transparent;
  border-radius: var(--radius-full);
  color: var(--gray-600);
  display: flex;
  gap: 8px;
  margin: 6px 16px 8px;
  min-height: 44px;
  padding: 0 14px;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}
.ib-search:focus-within { background: var(--white); border-color: var(--secondary); }
.ib-search .ib-svg { height: 18px; width: 18px; }
.ib-search-input { background: transparent; border: 0; color: var(--gray-900); flex: 1; font-size: 1rem; min-height: 40px; min-width: 0; outline: none; }
.ib-search-input::placeholder { color: var(--gray-600); }

.ib-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 16px 10px; }
.ib-chip {
  align-items: center;
  border-radius: var(--radius-full);
  color: var(--gray-800);
  display: inline-flex;
  font-size: 0.95rem;
  font-weight: 700;
  gap: 6px;
  min-height: 40px;
  padding: 6px 14px;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.ib-chip:hover { background: var(--gray-100); }
.ib-chip[aria-current="page"] { background: var(--pv-tint); color: var(--secondary-dark); }
.ib-chip-count { background: var(--secondary); border-radius: var(--radius-full); color: var(--white); font-size: 0.75rem; line-height: 1; min-width: 20px; padding: 4px 6px; text-align: center; }

.ib-list-notes { padding: 0 16px 6px; }
.ib-list-notes .pv-banner { font-size: 0.92rem; margin: 0 0 8px; }
.ib-list-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 8px 16px; scrollbar-width: thin; }
.ib-none { color: var(--gray-600); font-size: 0.95rem; line-height: 1.6; padding: 16px 12px; }

/* "Requests for you", above the chats */
.ib-requests-link { align-items: center; border-radius: var(--radius-md); color: var(--gray-900); display: flex; gap: 12px; margin-bottom: 2px; padding: 10px 12px; }
.ib-requests-link:hover { background: var(--gray-100); }
.ib-requests-icon { align-items: center; background: var(--pv-tint); border-radius: 50%; color: var(--secondary-dark); display: inline-flex; flex: none; height: 52px; justify-content: center; width: 52px; }
.ib-requests-icon .ib-svg { height: 24px; width: 24px; }
.ib-requests-text { flex: 1; font-size: 1rem; font-weight: 700; min-width: 0; }

/* One chat: the whole row opens it */
.ib-rows { list-style: none; }
.ib-row-link { align-items: center; border-radius: var(--radius-md); color: inherit; display: flex; gap: 12px; min-width: 0; padding: 10px 12px; transition: background-color var(--transition-fast); }
.ib-row-link:hover { background: var(--gray-100); }
.ib-row-link:focus-visible { outline: 2px solid var(--secondary); outline-offset: -2px; }
.ib-row.is-active .ib-row-link { background: var(--pv-tint); }
.ib-row .cm-avatar { --cm-avatar: 52px; flex: none; font-size: 1.3rem; }
.ib-row-text { display: block; flex: 1; min-width: 0; }
.ib-row-top { align-items: center; display: flex; gap: 6px; min-width: 0; }
.ib-row-name { color: var(--gray-900); font-size: 1rem; font-weight: 600; line-height: 1.35; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-row-sub { color: var(--gray-600); display: flex; font-size: 0.9rem; gap: 4px; line-height: 1.4; margin-top: 2px; min-width: 0; }
.ib-row-excerpt { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-row-when { flex: none; white-space: nowrap; }
.ib-row.is-unread .ib-row-name { font-weight: 800; }
.ib-row.is-unread .ib-row-sub { color: var(--gray-900); font-weight: 700; }
.ib-row-ended { background: var(--gray-100); border-radius: var(--radius-full); color: var(--gray-700); display: inline-block; font-size: 0.76rem; line-height: 1.4; margin-top: 4px; padding: 1px 9px; }
.ib-unread-pill { background: var(--secondary); border-radius: var(--radius-full); color: var(--white); flex: none; font-size: 0.78rem; font-weight: 700; line-height: 1; min-width: 22px; padding: 5px 7px; text-align: center; }
.ib-verified { align-items: center; background: var(--secondary); border-radius: 50%; color: var(--white); display: inline-flex; flex: none; height: 16px; justify-content: center; width: 16px; }
.ib-verified svg { height: 10px; width: 10px; }

/* The Requests filter */
.ib-req-section { padding: 4px 6px 14px; }
.ib-req-heading { align-items: center; color: var(--gray-900); display: flex; font-size: 1rem; font-weight: 700; gap: 8px; margin: 6px 4px 8px; }
.ib-req-count { background: var(--gray-100); border-radius: var(--radius-full); color: var(--gray-700); font-size: 0.8rem; padding: 1px 9px; }
.ib-req-warn { background: var(--sandal-cream); border: 1px solid var(--sandal-light); border-radius: var(--radius-md); color: var(--gray-800); font-size: 0.88rem; line-height: 1.5; margin: 0 4px 10px; padding: 8px 12px; }
.ib-req-list { display: grid; gap: 10px; list-style: none; }
.ib-request { background: var(--white); border: 1px solid var(--gray-200); border-radius: var(--radius-lg); padding: 14px; }
.ib-request .cm-tools { margin-top: 8px; }
.ib-sent { align-items: center; border-bottom: 1px solid var(--gray-100); display: flex; gap: 10px; justify-content: space-between; padding: 8px 6px; }
.ib-sent:last-child { border-bottom: 0; }
.ib-sent .cm-author { flex: 1; min-width: 0; }
.ib-sent form { flex: none; }
.ib-sent .cm-btn-small { margin-top: 0; width: auto; }
.ib-app a.cm-author-name { align-items: center; display: inline-flex; min-height: 44px; }

.ib-note {
  background: var(--sandal-cream);
  border-radius: var(--radius-md);
  color: var(--gray-800);
  font-size: 0.96rem;
  line-height: 1.55;
  margin-top: 12px;
  padding: 10px 14px;
}
.ib-note-label { font-size: 0.9rem; }
.ib-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

/* ---- The conversation ---- */
.ib-chat {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  margin: 12px;
  min-height: 0;
  min-width: 0;
}
.ib-chat-head { align-items: center; border-bottom: 1px solid var(--gray-200); display: flex; gap: 12px; min-width: 0; padding: 10px 14px 10px 18px; }
.ib-chat-head .cm-avatar { --cm-avatar: 44px; flex: none; font-size: 1.15rem; }
.ib-back { align-items: center; border-radius: 50%; color: var(--gray-800); display: none; flex: none; height: 44px; justify-content: center; margin-left: -8px; width: 40px; }
.ib-back:hover { background: var(--gray-100); }
.ib-back .ib-svg { height: 24px; width: 24px; }
.ib-chat-who { flex: 1; min-width: 0; }
.ib-chat-name { align-items: center; color: var(--gray-900); display: flex; font-size: 1.1rem; font-weight: 700; gap: 6px; line-height: 1.3; margin: 0; min-width: 0; }
.ib-chat-name > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-chat-meta { align-items: center; color: var(--gray-600); display: flex; flex-wrap: wrap; font-size: 0.86rem; gap: 0 12px; line-height: 1.4; }
.ib-chat-identity { min-width: 0; }
.ib-chat-link { color: var(--secondary); font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }
.ib-chat-link:hover { color: var(--secondary-dark); }
.ib-drop-end { flex: none; }
.ib-panel-tools .cm-tool-form:first-of-type { margin-top: 0; }

.ib-chat-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 20px;
  scrollbar-width: thin;
}
.ib-chat-body > .pv-banner { margin: 0; }
.ib-older { display: flex; flex-wrap: wrap; gap: 0 18px; justify-content: center; }
.ib-older-link { align-items: center; color: var(--secondary); display: inline-flex; font-weight: 700; min-height: 40px; text-decoration: underline; text-underline-offset: 2px; }
.ib-system { align-items: flex-start; align-self: center; background: var(--gray-100); border-radius: var(--radius-lg); color: var(--gray-700); display: flex; font-size: 0.84rem; gap: 8px; line-height: 1.5; max-width: 560px; padding: 8px 12px; }
.ib-system .ib-svg { color: var(--secondary); height: 16px; margin-top: 2px; width: 16px; }
.ib-thread-note { margin: 0; }
.ib-thread-empty { color: var(--gray-600); font-size: 1rem; line-height: 1.6; margin: auto; padding: 24px 0; text-align: center; }

/* Messages sit at the bottom of the space, newest last, as in any chat */
.ib-bubbles { display: flex; flex-direction: column; gap: 6px; list-style: none; margin-top: auto; }
.ib-day { list-style: none; margin: 10px 0 4px; text-align: center; }
.ib-day span { background: var(--gray-100); border-radius: var(--radius-full); color: var(--gray-700); display: inline-block; font-size: 0.76rem; font-weight: 700; padding: 3px 12px; }
.ib-bubble-row { display: flex; min-width: 0; scroll-margin: 16px; }
.ib-bubble-row.is-mine { justify-content: flex-end; }
.ib-bubble { border-radius: 18px; max-width: min(72%, 560px); min-width: 0; padding: 8px 14px 6px; }
.is-theirs .ib-bubble { background: var(--gray-100); border-bottom-left-radius: 6px; color: var(--gray-900); }
.is-mine .ib-bubble { background: var(--secondary); border-bottom-right-radius: 6px; color: var(--white); }
.ib-bubble-body { font-size: 1rem; line-height: 1.5; }
.ib-bubble-date { color: var(--gray-600); font-size: 0.72rem; line-height: 1.3; margin-top: 3px; text-align: right; }
.is-mine .ib-bubble-date { color: rgba(255, 255, 255, 0.85); }

.ib-chat-foot { border-top: 1px solid var(--gray-200); padding: 10px 14px; }
.ib-compose { align-items: flex-end; display: flex; gap: 8px; }
.ib-compose-input {
  background: var(--gray-100);
  border: 2px solid transparent;
  border-radius: 22px;
  color: var(--gray-900);
  flex: 1;
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
  max-height: 168px;
  min-height: 44px;
  min-width: 0;
  padding: 9px 16px;
  resize: none;
}
.ib-compose-input:focus { background: var(--white); border-color: var(--secondary); outline: none; }
/* A one-line hint in a narrow box ends in "…" rather than wrapping out of sight */
.ib-compose-input::placeholder { color: var(--gray-600); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-send { align-items: center; border-radius: 50%; color: var(--secondary); display: inline-flex; flex: none; height: 44px; justify-content: center; width: 44px; }
.ib-send:hover { background: var(--pv-tint); }
.ib-send:focus-visible { outline: 2px solid var(--secondary); outline-offset: 2px; }
.ib-send .ib-svg { height: 22px; width: 22px; }
.ib-closed { color: var(--gray-700); font-size: 0.95rem; line-height: 1.5; padding: 6px; text-align: center; }

/* No chat open */
.ib-chat-empty { align-items: center; justify-content: center; }
.ib-pick { max-width: 460px; padding: 32px 24px; text-align: center; }
.ib-pick-art { display: block; height: 120px; margin: 0 auto 16px; width: 120px; }
.ib-pick-title { color: var(--gray-900); font-size: 1.4rem; font-weight: 800; line-height: 1.3; }
.ib-pick-text { color: var(--gray-600); font-size: 1rem; line-height: 1.55; margin-top: 6px; }
.ib-pick-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }

/* ---- Connect, on a profile page ---- */
.ib-connect, .ib-state { overflow-wrap: anywhere; }
.ib-connect { display: grid; flex-basis: 100%; gap: 2px; grid-template-columns: minmax(0, 1fr); justify-items: end; max-width: 100%; min-width: 0; }
.ib-connect-note { width: 100%; }
.ib-connect-note summary {
  color: var(--gray-600);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1.3;
  padding: 13px 0;
  text-align: right;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ib-connect-note summary:hover { color: var(--secondary); }
.ib-connect-note textarea { min-height: 84px; resize: vertical; }
.ib-connect-hint { color: var(--gray-600); font-size: 0.86rem; line-height: 1.45; margin-top: 6px; text-align: left; }
.ib-state {
  align-items: center;
  background: var(--pv-tint);
  border: 1px solid var(--pv-tint-line);
  border-radius: var(--radius-full);
  color: var(--secondary-dark);
  display: inline-flex;
  font-size: 0.98rem;
  font-weight: 700;
  justify-content: center;
  line-height: 1.3;
  min-height: 48px;
  padding: 10px 22px;
}
.ib-state-quiet { background: var(--gray-100); border-color: var(--gray-200); color: var(--gray-700); font-weight: 400; }

/* ---- Tablets: a narrower list ---- */
@media (max-width: 1023px) {
  .ib-app { grid-template-columns: clamp(280px, 36vw, 360px) minmax(0, 1fr); }
  .ib-chat { margin: 8px; }
  .ib-bubble { max-width: 82%; }
}

/* ---- Phones: one side at a time; the open conversation fills the screen, with a back arrow ---- */
@media (max-width: 760px) {
  .ib-app { grid-template-columns: minmax(0, 1fr); }
  .ib-app[data-view="list"] .ib-chat { display: none; }
  .ib-app[data-view="chat"] .ib-list { display: none; }
  .ib-list { border-right: 0; }
  .ib-list-head { padding: 12px 12px 4px 16px; }
  .ib-search { margin: 6px 12px 8px; }
  .ib-chips { padding: 2px 12px 8px; }
  .ib-chip { min-height: 44px; }
  .ib-list-scroll { padding: 0 4px 16px; }
  .ib-chat { border: 0; border-radius: 0; box-shadow: none; margin: 0; }
  .ib-chat-head { padding: 8px 10px 8px 12px; gap: 10px; }
  .ib-back { display: inline-flex; }
  .ib-chat-body { padding: 12px; }
  .ib-bubble { max-width: 86%; }
  .ib-chat-foot { padding: 8px 10px; }
  .ib-actions { display: grid; grid-template-columns: minmax(0, 1fr); }
  .ib-connect { justify-items: stretch; }
  .ib-connect-note summary { text-align: left; }
}
@media (max-width: 480px) {
  .ib-sent { align-items: stretch; flex-direction: column; }
  .ib-sent .cm-btn-small { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .ib-row-link, .ib-round, .ib-chip, .ib-search { transition: none; }
}
