/* Messages view — quiet Apple Messages-style baseline: contacts, conversation, calls. */
.msg-page {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Helvetica, Arial, sans-serif;
  background: #f5f5f7;
  color: #1d1d1f;
  -webkit-text-size-adjust: 100%;
}
.msg-page .skip {
  position: absolute;
  left: -999px;
}
.msg-page .skip:focus {
  left: 8px;
  top: 8px;
  z-index: 10;
  background: #fff;
  padding: 8px 12px;
  border-radius: 8px;
}
.msg-shell {
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  max-width: 1120px;
  margin: 0 auto;
  min-height: 100dvh;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #fff;
}
.msg-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #e5e5ea;
}
.msg-header h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 600;
}
.msg-brand {
  font-weight: 700;
  text-decoration: none;
  color: inherit;
  font-size: 20px;
}
.msg-brand span { color: #0071e3; }
.msg-net {
  margin: 0;
  font-size: 12px;
  color: #6e6e73;
  flex: 1;
}
.msg-header nav button,
.msg-list-head button,
.msg-conv-actions button,
.msg-callbar button,
.msg-start,
#conversation-older {
  font: inherit;
  font-size: 13px;
  border: 1px solid #d2d2d7;
  background: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
.msg-header nav button:disabled,
.msg-callbar button:disabled { opacity: .45; cursor: default; }
.primary {
  background: #0071e3 !important;
  border-color: #0071e3 !important;
  color: #fff !important;
}
.danger { color: #d70015; border-color: #d70015; }
.msg-main {
  flex: 1;
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  overflow: hidden;
}
.msg-list {
  border-right: 1px solid #e5e5ea;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
}
.msg-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.msg-list-head h2 { font-size: 15px; margin: 0; }
.msg-search-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
#msg-search {
  font: inherit;
  font-size: 14px;
  border: 1px solid #e5e5ea;
  background: #f5f5f7;
  border-radius: 8px;
  padding: 7px 10px;
}
#msg-list-status, .msg-empty, .hint, .msg-sync, .msg-status {
  font-size: 12px;
  color: #6e6e73;
  margin: 4px 0;
}
.msg-error { font-size: 12px; color: #d70015; }
#msg-contacts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.msg-contact {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 8px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
}
.msg-contact:hover { background: #f5f5f7; }
.msg-contact[aria-current="true"] { background: #e8e8ed; }
.msg-avatar {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  color: #fff;
  background: #86868b var(--avatar-img, none) center / cover no-repeat;
}
.msg-conv {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.msg-conv-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid #e5e5ea;
}
#msg-back { display: none; border: 0; background: none; color: #0071e3; font-size: 15px; padding: 4px 0; }
.msg-conv-id { flex: 1; min-width: 0; }
.msg-conv-id h2 { font-size: 15px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-conv-id p { margin: 0; font-size: 12px; color: #6e6e73; }
.msg-conv-actions { display: flex; gap: 8px; flex: none; }
#conversation-call { white-space: nowrap; }
#conversation-feed {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  min-height: 0;
}
#conversation-timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.conversation-item { display: flex; flex-direction: column; gap: 2px; max-width: 75%; }
.conversation-item.message[data-self="true"] { align-self: flex-end; align-items: flex-end; }
.conversation-item.message[data-self="false"] { align-self: flex-start; align-items: flex-start; }
.conversation-meta { font-size: 11px; color: #6e6e73; margin: 0; }
.message-body {
  margin: 0;
  font-size: 15px;
  line-height: 1.4;
  padding: 8px 12px;
  border-radius: 18px;
  overflow-wrap: anywhere;
}
.conversation-item[data-self="true"] .message-body { background: #0071e3; color: #fff; }
.conversation-item[data-self="false"] .message-body { background: #e9e9eb; color: #1d1d1f; }
.conversation-item.call { max-width: 100%; font-size: 13px; color: #6e6e73; }
.conversation-item.call details { background: #f5f5f7; border-radius: 10px; padding: 8px 10px; }
.conversation-item.message.speech[data-speech="interim"] .message-body { opacity: .65; }
.speech-more { align-self: center; font-size: 12px; color: #6e6e73; background: none; border: 1px solid #d2d2d7; border-radius: 12px; padding: 2px 10px; cursor: pointer; }
.cc-captions { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.cc-captions li { background: #f5f5f7; border-radius: 10px; padding: 6px 10px; display: flex; align-items: flex-start; gap: 8px; }
.cc-captions li.cc-interim { opacity: .7; }
.cc-avatar { flex: none; width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: #fff; background: #86868b; overflow: hidden; }
.cc-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cc-name { flex: none; font-size: 12px; font-weight: 600; color: #3a3a3c; max-width: 32%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cc-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.msg-composer { padding: 10px 14px 4px; flex: none; }
.msg-composer > label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
#message-text {
  flex: 1;
  font: inherit;
  font-size: 15px;
  border: 1px solid #d2d2d7;
  border-radius: 18px;
  padding: 8px 14px;
  resize: none;
  max-height: 120px;
}
.msg-callbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 12px;
  border-top: 1px solid #e5e5ea;
  flex-wrap: wrap;
}
/* One coherent friends row + conversation list: suppress the redundant
   call-people toolbar/status list UI; incoming-call banner and dialogs stay. */
#calls-people .call-people-toolbar,
#calls-people .call-people-status { display: none; }
/* Hide dead call controls until a call is active; consent/disclosure hints stay. */
.msg-main[data-joined="false"] .msg-callbar { display: none; }
.msg-main[data-joined="true"] #cc-save-hint { display: none; }
.controls-note { flex: 1 1 200px; margin: 0; font-size: 12px; color: #6e6e73; }
.audio-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.msg-foot { padding: 10px 16px 20px; font-size: 12px; color: #6e6e73; }
/* Mobile: list -> conversation */
@media (max-width: 759px) {
  .msg-main { grid-template-columns: 1fr; }
  .msg-page[data-view="list"] .msg-conv { display: none; }
  .msg-page[data-view="list"] .msg-callbar { display: none; }
  /* An active call keeps End/Mute reachable even while Back shows contacts. */
  .msg-page[data-view="list"] .msg-main[data-joined="true"] .msg-callbar { display: flex; }
  .msg-page[data-view="conversation"] .msg-list { display: none; }
  #msg-back { display: inline; }
  .msg-net { display: none; }
  .conversation-item { max-width: 88%; }
  .cc-name { max-width: 26%; }
}
@media (prefers-reduced-motion: reduce) {
  .msg-page * { transition: none !important; }
}

/* Friends row: one avatar circle per friend, plus button at the end. */
.msg-friends {
  list-style: none;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px;
  margin: 0;
}
.msg-friends li { flex: 0 0 auto; }
.msg-friend {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: #e5e5ea;
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  font: inherit;
}
.msg-friend[aria-current="true"] { border-color: #0071e3; }
.msg-friend img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.msg-friend-initial {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: #3a3a3c;
}
.msg-friend-add {
  font-size: 22px;
  line-height: 1;
  color: #0071e3;
  background: #fff;
  border-style: dashed;
  border-color: #0071e3;
}
/* Compact friend entry stays in the contacts column. */
#msg-invite { padding: 8px 0 12px; }
#msg-invite button { font: inherit; font-size: 13px; border: 1px solid #d2d2d7; background: #fff; border-radius: 8px; padding: 6px 12px; cursor: pointer; }
#msg-invite-status { font-size: 13px; margin: 0 0 8px; overflow-wrap: anywhere; word-break: break-word; }
#msg-invite-status:empty { margin: 0; }
#msg-invite-incoming { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
#msg-invite-incoming p { font-size: 13px; margin: 0; overflow-wrap: anywhere; }
#msg-invite-accept, #msg-invite-dismiss { min-height: 44px; }
#msg-invite-add-row { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
#msg-invite-add-row label { font-size: 12px; color: #6e6e73; }
.msg-invite-entry, .msg-invite-actions { display: flex; gap: 8px; align-items: center; }
#msg-invite-name { flex: 1; min-width: 0; box-sizing: border-box; min-height: 44px; font: inherit; font-size: 16px; border: 1px solid #d2d2d7; border-radius: 8px; padding: 6px 10px; }
#msg-invite-add { min-width: 64px; min-height: 44px; }
#msg-invite-share { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
#msg-invite-share-note { font-size: 13px; margin: 0; overflow-wrap: anywhere; word-break: break-word; }
#msg-invite-share label { font-size: 12px; color: #6e6e73; }
#msg-invite-text { width: 100%; box-sizing: border-box; min-height: 44px; font: inherit; font-size: 13px; border: 1px solid #d2d2d7; border-radius: 8px; padding: 6px 10px; overflow-wrap: anywhere; word-break: break-word; }
#msg-invite-copy { min-height: 44px; }
#msg-invite button:focus-visible, #msg-invite input:focus-visible, #msg-invite textarea:focus-visible { outline: 2px solid #0071e3; outline-offset: 2px; }
/* Hidden-attribute semantics win over author display styles. */
.msg-page [hidden] { display: none !important; }
/* The speech-as-messages disclosure stays visible: it is the persistent
   statement of what calls do, in every state. */
#msg-invite-link { font-size: 12px; word-break: break-all; }
#msg-invite-paste-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
#msg-invite-paste-row label { width: 100%; font-size: 12px; color: #6e6e73; }
#msg-invite-paste { flex: 1; min-width: 0; font: inherit; font-size: 13px; border: 1px solid #d2d2d7; border-radius: 8px; padding: 6px 10px; }
/* Visible keyboard focus on the core controls (avatars row, list, back, composer). */
.msg-friend:focus-visible,
.msg-contact:focus-visible,
#msg-back:focus-visible,
#message-send:focus-visible,
#conversation-call:focus-visible {
  outline: 2px solid #0071e3;
  outline-offset: 2px;
}
/* Back is the only control on narrow viewports: keep a 44px touch target. */
#msg-back { min-width: 44px; min-height: 44px; }
.msg-header nav button,
.msg-list-head button,
.msg-conv-actions button,
.msg-callbar button,
#conversation-older { min-width: 44px; min-height: 44px; }
#message-send {
  min-width: 64px;
  min-height: 44px;
  border: 0;
  border-radius: 22px;
  padding: 0 14px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
#message-text, #msg-search { min-height: 44px; box-sizing: border-box; }
#msg-search { font-size: 16px; }

/* Signed-out entry presents a real action rather than empty account data. */
.msg-welcome { display: none; }
.msg-page[data-signed-in="false"] .msg-main { display: none; }
.msg-page[data-signed-in="false"] .msg-welcome {
 display: flex; flex: 1; flex-direction: column; align-items: center;
 justify-content: center; text-align: center; padding: 24px; gap: 12px;
}
.msg-welcome h2 { font-size: clamp(24px, 5vw, 36px); margin: 0; }
.msg-welcome p { color: #60646c; margin: 0 0 12px; }
.msg-welcome button { min-height: 44px; padding: 12px 20px; font: inherit;
 border: 0; border-radius: 12px; background: #007aff; color: white; cursor: pointer; }
.msg-page[data-signed-in="false"] .skip { display: none; }

.msg-header { justify-content: flex-end; border-bottom: 0; padding: 8px 12px; }
.msg-page[data-signed-in="false"] .msg-header { display: none; }
#account-toggle { width: 44px; height: 44px; border: 0; background: transparent;
 border-radius: 50%; font-size: 28px; padding: 0; }

.msg-page:not([data-has-conversation="true"]) .msg-conv-head { display: none; }
#conversation-storage { display: none; }
.msg-page[data-signed-in="false"] .ca-dialog {
 width: min(360px, calc(100vw - 48px)); border: 0; border-radius: 0; box-shadow: none;
 background: white; padding: 0;
}
.msg-page[data-signed-in="false"] .ca-dialog::backdrop { background: white; }

.msg-page .ca-button.ca-icon, .msg-page .call-people-close {
 border: 0; background: transparent; min-width: 44px; min-height: 44px;
 padding: 6px; font-size: 26px; line-height: 1;
}
.msg-page .call-people-close { position: absolute; top: 8px; right: 8px; }
.msg-page .call-people-dialog h2 { padding-right: 44px; }

.msg-page .ca-dialog, .msg-page .ca-input, .msg-page .ca-button { color: #1d1d1f; }
.msg-page .ca-button.ca-link { color: #007aff; text-decoration: none; }
.msg-page .ca-button:focus-visible, .msg-page .ca-input:focus-visible {
 outline: 2px solid #007aff; outline-offset: 2px;
}
