:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-soft: #f1f3f6;
  --text: #15171a;
  --muted: #6f7680;
  --border: #e3e6ea;
  --accent: #15171a;
  --accent-2: #2f343b;
  --danger: #d92d20;
  --clovis: #111827;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
button, input, textarea, select { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

.app-shell { height: 100vh; display: grid; grid-template-columns: 360px minmax(0, 1fr); }
.sidebar {
  min-width: 0; height: 100vh; background: var(--panel); border-right: 1px solid var(--border);
  display: grid; grid-template-rows: auto auto 1fr auto;
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 24px 22px 14px; }
.wordmark { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .18em; text-decoration: none; }
.sidebar-header h1 { margin: 5px 0 0; font-size: 28px; letter-spacing: -.04em; }
.icon-button, .composer-icon, .send-button {
  border: 0; background: transparent; padding: 0; cursor: pointer; display: inline-grid; place-items: center;
}
.icon-button { width: 38px; height: 38px; border-radius: 12px; }
.icon-button:hover { background: var(--panel-soft); }
.icon-button svg, .composer-icon svg, .send-button svg { width: 21px; height: 21px; fill: currentColor; }
.compose-button { background: var(--text); color: white; }
.compose-button:hover { background: var(--accent-2); }
.sidebar-search-wrap { margin: 0 16px 10px; height: 42px; border-radius: 14px; background: var(--panel-soft); display: flex; align-items: center; padding: 0 12px; gap: 8px; }
.sidebar-search-wrap .search-icon { width: 18px; height: 18px; fill: var(--muted); flex: 0 0 auto; }
.sidebar-search-wrap input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); }
.sidebar-search-wrap input::placeholder { color: #9298a1; }
.conversation-list { min-height: 0; overflow-y: auto; padding: 2px 10px 16px; }
.conversation-loading { padding: 24px 12px; color: var(--muted); font-size: 14px; }
.conversation-item {
  width: 100%; border: 0; text-align: left; background: transparent; display: grid; grid-template-columns: 48px minmax(0,1fr) auto;
  gap: 11px; padding: 10px; border-radius: 16px; cursor: pointer; align-items: center;
}
.conversation-item:hover { background: #f7f8fa; }
.conversation-item.active { background: #eef1f5; }
.conversation-item.pinned { margin-bottom: 8px; }
.conversation-copy { min-width: 0; }
.conversation-name-row { display: flex; gap: 7px; align-items: center; min-width: 0; }
.conversation-name { font-size: 14px; font-weight: 750; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-preview { margin-top: 3px; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-meta { align-self: stretch; padding-top: 2px; display: flex; flex-direction: column; align-items: end; justify-content: space-between; gap: 4px; }
.conversation-time { font-size: 11px; color: #999fa7; }
.unread-badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--text); color: white; font-size: 11px; display: grid; place-items: center; }
.clovis-dot { width: 7px; height: 7px; background: #22c55e; border-radius: 50%; flex: 0 0 auto; }
.account-strip { border-top: 1px solid var(--border); padding: 13px 14px; display: grid; grid-template-columns: 40px minmax(0,1fr) auto; gap: 10px; align-items: center; }
.account-copy { min-width: 0; display: flex; flex-direction: column; }
.account-copy strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-copy span { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-settings { text-decoration: none; }

.avatar { width: 42px; height: 42px; border-radius: 50%; background: #dce1e8; color: #323842; display: grid; place-items: center; font-size: 14px; font-weight: 800; background-position: center; background-size: cover; flex: 0 0 auto; }
.avatar.small { width: 40px; height: 40px; }
.avatar.large { width: 72px; height: 72px; font-size: 22px; }
.avatar.clovis { background: #111827; color: #fff; }
.group-avatar { background: linear-gradient(135deg, #dfe3e8, #cfd5dc); }

.chat-panel { min-width: 0; height: 100vh; background: var(--panel); }
.empty-state { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px; text-align: center; }
.empty-icon { width: 72px; height: 72px; border-radius: 22px; background: var(--panel-soft); display: grid; place-items: center; }
.empty-icon svg { width: 34px; height: 34px; fill: var(--text); }
.empty-state h2 { font-size: 24px; margin: 18px 0 6px; letter-spacing: -.03em; }
.empty-state p { color: var(--muted); max-width: 420px; margin: 0 0 20px; line-height: 1.5; }
.primary-button, .secondary-button, .danger-button { min-height: 40px; padding: 0 16px; border-radius: 12px; font-weight: 700; border: 1px solid transparent; cursor: pointer; }
.primary-button { background: var(--text); color: white; }
.primary-button:hover { background: #2a2e33; }
.primary-button:disabled { opacity: .45; cursor: not-allowed; }
.secondary-button { background: white; border-color: var(--border); }
.secondary-button:hover { background: var(--panel-soft); }
.danger-button { width: 100%; background: #fff2f0; color: var(--danger); border-color: #ffd7d2; }
.small-button { min-height: 34px; font-size: 12px; }

.conversation-view { height: 100%; min-height: 0; display: grid; grid-template-rows: auto auto 1fr auto auto auto; }
.chat-header { height: 74px; border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 18px; gap: 12px; }
.mobile-back { display: none; }
.chat-title-wrap { min-width: 0; flex: 1; }
.chat-title-line { display: flex; align-items: center; gap: 7px; }
.chat-title-line h2 { margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clovis-badge { font-size: 9px; letter-spacing: .12em; font-weight: 900; padding: 3px 5px; border-radius: 5px; background: #111827; color: white; }
.retention-pill { margin-top: 3px; padding: 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; }
.retention-pill:hover { color: var(--text); }
.chat-actions { display: flex; align-items: center; }
.retention-banner { background: #faf6e8; color: #6b5a1d; border-bottom: 1px solid #efe5bc; padding: 8px 18px; text-align: center; font-size: 12px; }
.messages-scroll { min-height: 0; overflow-y: auto; background: #fff; padding: 18px 18px 10px; }
.load-older-wrap { text-align: center; margin-bottom: 14px; }
.messages { max-width: 920px; margin: 0 auto; display: flex; flex-direction: column; gap: 3px; }
.date-separator { align-self: center; color: #969ca5; font-size: 11px; font-weight: 700; margin: 18px 0 10px; }
.message-row { display: flex; gap: 8px; max-width: 78%; position: relative; margin: 2px 0; }
.message-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.message-row.theirs { align-self: flex-start; }
.message-row .message-avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: #e3e7ec; background-size: cover; background-position: center; font-size: 10px; font-weight: 800; flex: 0 0 auto; align-self: end; }
.message-row.mine .message-avatar { display: none; }
.message-stack { min-width: 0; }
.message-author { color: var(--muted); font-size: 11px; font-weight: 750; margin: 0 0 3px 10px; }
.message-bubble { border-radius: 18px; padding: 9px 12px; background: #f0f2f5; line-height: 1.42; font-size: 14px; word-break: break-word; white-space: pre-wrap; position: relative; }
.message-row.mine .message-bubble { background: #16181b; color: white; }
.message-row.clovis-message .message-bubble { background: #eef0f4; border: 1px solid #e2e5e9; }
.message-row.clovis-message .message-author { color: #111827; }
.message-time { font-size: 10px; color: #a0a5ad; margin-top: 4px; padding: 0 8px; }
.message-row.mine .message-time { text-align: right; }
.message-reply { margin: -2px -4px 7px; padding: 6px 8px; border-left: 2px solid currentColor; background: rgba(0,0,0,.05); border-radius: 8px; opacity: .8; font-size: 11px; }
.message-row.mine .message-reply { background: rgba(255,255,255,.12); }
.message-reply strong { display: block; margin-bottom: 2px; }
.message-file { min-width: 220px; }
.message-file img { display: block; width: min(360px, 58vw); max-height: 360px; object-fit: cover; border-radius: 12px; margin-bottom: 7px; background: #dde1e7; }
.message-file a { color: inherit; font-weight: 750; text-decoration: none; }
.message-file small { display: block; opacity: .7; margin-top: 2px; }
.message-actions { opacity: 0; pointer-events: none; position: absolute; top: 50%; transform: translateY(-50%); display: flex; align-items: center; gap: 3px; }
.message-row.theirs .message-actions { left: calc(100% + 7px); }
.message-row.mine .message-actions { right: calc(100% + 7px); }
.message-row:hover .message-actions { opacity: 1; pointer-events: auto; }
.message-action { width: 28px; height: 28px; border: 1px solid var(--border); background: white; border-radius: 9px; cursor: pointer; color: var(--muted); display: grid; place-items: center; font-size: 13px; }
.message-action:hover { background: var(--panel-soft); color: var(--text); }
.reactions { display: flex; gap: 3px; margin-top: 4px; padding: 0 5px; }
.reaction-chip { border: 1px solid var(--border); background: white; border-radius: 12px; font-size: 11px; padding: 2px 6px; cursor: pointer; }
.reaction-chip.mine { background: #edf1f5; border-color: #d6dbe1; }
.deleted-copy { opacity: .65; font-style: italic; }

.typing-row { max-width: 920px; margin: 8px auto 0; display: flex; align-items: end; gap: 8px; }
.typing-avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; font-weight: 800; }
.clovis-avatar { background: #111827; color: white; }
.typing-bubble { height: 34px; padding: 0 12px; background: #f0f2f5; border-radius: 17px; display: flex; align-items: center; gap: 4px; }
.typing-bubble span { width: 5px; height: 5px; border-radius: 50%; background: #8d939b; animation: blink 1.2s infinite; }
.typing-bubble span:nth-child(2) { animation-delay: .15s; }
.typing-bubble span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%,60%,100% { opacity:.3; transform: translateY(0); } 30% { opacity:1; transform: translateY(-2px); } }

.reply-preview, .attachment-preview { border-top: 1px solid var(--border); padding: 9px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #fafbfc; }
.reply-preview > div, .attachment-preview-copy { min-width: 0; }
.reply-preview span, .attachment-preview-copy span { color: var(--muted); font-size: 11px; display: block; }
.reply-preview strong, .attachment-preview-copy strong { font-size: 12px; }
.reply-preview p { margin: 2px 0 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer { padding: 12px 16px 14px; border-top: 1px solid var(--border); display: grid; grid-template-columns: auto minmax(0,1fr) auto; gap: 9px; align-items: end; background: white; }
.composer textarea { max-height: 150px; min-height: 42px; resize: none; border: 1px solid var(--border); background: #f7f8fa; border-radius: 16px; padding: 10px 13px; outline: none; line-height: 1.4; }
.composer textarea:focus { border-color: #b7bdc5; background: white; }
.composer-icon { width: 42px; height: 42px; border-radius: 14px; color: var(--muted); }
.composer-icon:hover { background: var(--panel-soft); color: var(--text); }
.send-button { width: 42px; height: 42px; border-radius: 14px; background: var(--text); color: white; }
.send-button:hover { background: #2b2f34; }
.send-button:disabled { opacity: .35; cursor: not-allowed; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(17,24,39,.35); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 18px; }
.modal { width: min(540px, 100%); max-height: min(760px, calc(100vh - 36px)); overflow-y: auto; background: white; border-radius: 22px; box-shadow: var(--shadow); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 21px 22px 14px; }
.modal-header h2 { margin: 3px 0 0; font-size: 22px; letter-spacing: -.03em; }
.eyebrow { color: var(--muted); font-size: 9px; font-weight: 850; letter-spacing: .16em; }
.modal-close { font-size: 24px; line-height: 1; }
.field-label { display: block; padding: 0 22px 7px; font-size: 12px; font-weight: 750; }
.people-search-box { margin: 0 22px; min-height: 46px; border: 1px solid var(--border); border-radius: 13px; padding: 6px 9px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.people-search-box:focus-within { border-color: #abb2bc; }
.people-search-box input { min-width: 140px; flex: 1; border: 0; outline: 0; padding: 6px 2px; }
.selected-people { display: contents; }
.person-chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 5px 8px; background: var(--panel-soft); font-size: 12px; font-weight: 700; }
.person-chip button { border: 0; background: transparent; cursor: pointer; padding: 0; color: var(--muted); }
.people-results { margin: 6px 22px 0; border-radius: 13px; overflow: hidden; max-height: 210px; overflow-y: auto; }
.person-result { width: 100%; border: 0; background: transparent; padding: 9px 4px; display: grid; grid-template-columns: 36px minmax(0,1fr) auto; gap: 9px; align-items: center; cursor: pointer; text-align: left; }
.person-result:hover { background: #f8f9fb; }
.person-result .avatar { width: 36px; height: 36px; }
.person-result strong, .member-main strong { display: block; font-size: 13px; }
.person-result span, .member-main span { color: var(--muted); font-size: 11px; }
.person-result .check { color: var(--muted); }
.new-chat-options { padding: 12px 22px 2px; display: grid; gap: 14px; }
.toggle-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; cursor: pointer; }
.toggle-row > span:first-child { flex: 1; }
.toggle-row strong, .toggle-row small { display: block; }
.toggle-row small { color: var(--muted); font-size: 11px; margin-top: 2px; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 42px; height: 24px; border-radius: 999px; background: #d5d9df; position: relative; transition: .2s; }
.switch::after { content:""; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: white; top: 3px; left: 3px; box-shadow: 0 1px 4px rgba(0,0,0,.18); transition: .2s; }
.toggle-row input:checked + .switch { background: var(--text); }
.toggle-row input:checked + .switch::after { left: 21px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 12px; font-weight: 750; }
.field input, .field select, .info-section select { width: 100%; height: 42px; border: 1px solid var(--border); border-radius: 12px; background: white; padding: 0 10px; outline: none; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 18px 22px 22px; }
.info-profile { text-align: center; padding: 6px 22px 18px; }
.info-profile .avatar { margin: 0 auto; }
.info-profile h3 { margin: 10px 0 2px; font-size: 18px; }
.info-profile p { margin: 0; color: var(--muted); font-size: 12px; }
.info-section { border-top: 1px solid var(--border); padding: 17px 22px; }
.info-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.info-section-heading strong, .info-section-heading small { display: block; }
.info-section-heading small { color: var(--muted); font-size: 11px; margin-top: 2px; }
.setting-note { color: var(--muted); font-size: 11px; line-height: 1.45; margin: 8px 0 0; }
.text-button { border: 0; background: transparent; color: var(--text); font-size: 12px; font-weight: 800; cursor: pointer; }
.member-list { display: grid; gap: 5px; }
.member-row { display: grid; grid-template-columns: 38px minmax(0,1fr) auto; gap: 9px; align-items: center; padding: 7px 0; }
.member-row .avatar { width: 38px; height: 38px; }
.member-role { font-size: 10px; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.danger-section { padding-bottom: 22px; }
.toast-container { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: grid; gap: 8px; }
.toast { min-width: 240px; max-width: 360px; border-radius: 13px; background: #15171a; color: white; padding: 11px 13px; box-shadow: var(--shadow); font-size: 13px; }
.toast.error { background: #8f1d16; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 100%; }
  .sidebar { position: absolute; inset: 0; z-index: 10; width: 100%; }
  .chat-panel { position: absolute; inset: 0; z-index: 20; transform: translateX(100%); transition: transform .22s ease; }
  .app-shell.mobile-chat-open .chat-panel { transform: translateX(0); }
  .mobile-back { display: inline-grid; }
  .message-row { max-width: 88%; }
  .chat-header { padding: 0 10px; }
  .messages-scroll { padding-left: 10px; padding-right: 10px; }
}

@media (max-width: 520px) {
  .sidebar-header { padding-top: 18px; }
  .modal-backdrop { align-items: end; padding: 0; }
  .modal { width: 100%; border-radius: 22px 22px 0 0; max-height: 92vh; }
  .message-file img { width: min(300px, 70vw); }
}


/* ========================================================================
   BROMERO MESSAGES V2 — MOBILE FIT, MESSAGE ACTIONS, IMAGE VIEWER
   ======================================================================== */

html, body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overscroll-behavior: none;
}

body {
  min-height: 100svh;
  height: 100dvh;
}

.app-shell {
  height: 100dvh;
  min-height: 100svh;
}

.sidebar,
.chat-panel {
  height: 100%;
  min-height: 0;
}

.conversation-view {
  height: 100%;
  grid-template-rows: auto 1fr auto auto auto;
}

.chat-header {
  min-height: 74px;
  height: auto;
  padding-top: max(0px, env(safe-area-inset-top));
}

.messages-scroll {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.message-row {
  touch-action: manipulation;
}

.message-bubble {
  cursor: pointer;
  -webkit-user-select: text;
  user-select: text;
}

.message-row.image-message .message-bubble {
  padding: 0;
  overflow: hidden;
  background: transparent;
  border: 0;
  border-radius: 18px;
  line-height: 0;
}

.message-row.mine.image-message .message-bubble,
.message-row.clovis-message.image-message .message-bubble {
  background: transparent;
  border: 0;
}

.message-image-button {
  display: block;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  border-radius: 18px;
  overflow: hidden;
  cursor: zoom-in;
  line-height: 0;
  max-width: min(440px, 62vw);
}

.message-image-button img {
  display: block;
  width: 100%;
  max-width: min(440px, 62vw);
  max-height: min(540px, 64vh);
  object-fit: cover;
  background: #e4e7eb;
}

.image-caption {
  line-height: 1.42;
  white-space: pre-wrap;
  padding: 9px 12px 10px;
  background: #f0f2f5;
  color: var(--text);
}

.message-row.mine .image-caption {
  background: #16181b;
  color: #fff;
}

.message-file:not(.image-only) {
  min-width: 220px;
}

.message-file:not(.image-only) a {
  color: inherit;
  font-weight: 750;
  text-decoration: none;
}

.message-file:not(.image-only) small {
  display: block;
  opacity: .7;
  margin-top: 2px;
}

.message-actions {
  opacity: 0;
  pointer-events: none;
  top: 50%;
  transform: translateY(-50%);
  gap: 3px;
  z-index: 8;
  transition: opacity .12s ease;
}

.message-row.theirs .message-actions {
  left: 100%;
  padding-left: 6px;
}

.message-row.mine .message-actions {
  right: 100%;
  padding-right: 6px;
}

.message-row:hover .message-actions,
.message-row.action-open .message-actions,
.message-actions:hover {
  opacity: 1;
  pointer-events: auto;
}

.message-action {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(17, 24, 39, .08);
}

.message-action svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.reactions {
  flex-wrap: wrap;
}

.reaction-picker,
.message-menu {
  position: fixed;
  z-index: 310;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 14px 36px rgba(15, 23, 42, .18);
}

.reaction-picker {
  display: flex;
  gap: 3px;
  padding: 6px;
  border-radius: 999px;
}

.reaction-picker button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-size: 19px;
  display: grid;
  place-items: center;
}

.reaction-picker button:hover {
  background: var(--panel-soft);
  transform: scale(1.08);
}

.message-menu {
  min-width: 180px;
  padding: 6px;
  border-radius: 14px;
}

.message-menu button {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  border-radius: 9px;
  padding: 10px 11px;
  cursor: pointer;
  font-size: 13px;
}

.message-menu button:hover {
  background: var(--panel-soft);
}

.message-menu .danger-menu-item {
  color: var(--danger);
}

.typing-row {
  margin-top: 8px;
  padding-bottom: 2px;
}

.typing-avatar {
  background: #e3e7ec;
  color: #323842;
  background-size: cover;
  background-position: center;
}

.typing-avatar.clovis {
  background: #111827;
  color: #fff;
}

.typing-stack {
  display: grid;
  gap: 3px;
}

.typing-name {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  padding-left: 8px;
}

.composer {
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  align-items: center;
}

.composer textarea {
  min-height: 40px;
  border-radius: 20px;
  padding: 9px 14px;
}

.composer-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.send-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  box-shadow: none;
  transition: transform .12s ease, background .12s ease, opacity .12s ease;
}

.send-button svg {
  width: 19px;
  height: 19px;
  transform: translateX(1px);
}

.send-button:not(:disabled):active {
  transform: scale(.94);
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: rgba(7, 9, 12, .96);
  color: #fff;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.image-viewer-topbar {
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 16px;
}

.viewer-icon-button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
  color: #fff;
  cursor: pointer;
  font-size: 26px;
  display: grid;
  place-items: center;
}

.image-viewer-stage {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px 18px 18px;
  overflow: auto;
}

.image-viewer-stage img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.image-viewer-toolbar {
  min-height: 72px;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px 12px;
  border-top: 1px solid rgba(255,255,255,.12);
  background: rgba(13, 15, 19, .92);
}

.viewer-action {
  min-width: 68px;
  border: 0;
  background: transparent;
  color: #fff;
  text-decoration: none;
  border-radius: 12px;
  padding: 7px 9px;
  cursor: pointer;
  display: grid;
  place-items: center;
  gap: 3px;
  font-size: 11px;
}

.viewer-action:hover {
  background: rgba(255,255,255,.09);
}

.viewer-action svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

@media (max-width: 860px) {
  .sidebar,
  .chat-panel {
    position: fixed;
    inset: 0;
    height: 100dvh;
    min-height: 100svh;
  }

  .chat-panel {
    width: 100%;
  }

  .chat-header {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .composer {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .message-row {
    max-width: 84%;
  }

  .message-actions {
    top: auto;
    bottom: calc(100% + 5px);
    transform: none;
    padding: 0 !important;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: 0 10px 26px rgba(15,23,42,.16);
  }

  .message-row.theirs .message-actions {
    left: 36px;
  }

  .message-row.mine .message-actions {
    right: 0;
  }

  .message-row:not(.action-open) .message-actions {
    opacity: 0;
    pointer-events: none;
  }

  .reaction-picker {
    left: 50% !important;
    right: auto !important;
    top: auto !important;
    bottom: calc(86px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
  }

  .message-menu {
    left: 50% !important;
    right: auto !important;
    top: auto !important;
    bottom: calc(84px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    width: min(320px, calc(100vw - 28px));
  }

  .message-image-button,
  .message-image-button img {
    max-width: min(390px, 78vw);
  }
}

@media (max-width: 520px) {
  .chat-header {
    min-height: 68px;
    gap: 9px;
  }

  .chat-header .avatar {
    width: 40px;
    height: 40px;
  }

  .chat-title-line h2 {
    font-size: 15px;
  }

  .retention-pill {
    font-size: 11px;
  }

  .messages-scroll {
    padding-top: 12px;
    padding-bottom: 8px;
  }

  .message-row {
    max-width: 88%;
  }

  .message-image-button,
  .message-image-button img {
    max-width: min(360px, 80vw);
    max-height: 58vh;
  }

  .composer {
    gap: 6px;
    padding-top: 9px;
  }

  .composer-icon,
  .send-button {
    width: 38px;
    height: 38px;
  }

  .composer textarea {
    min-height: 38px;
  }

  .image-viewer-toolbar {
    justify-content: space-around;
    gap: 0;
  }

  .viewer-action {
    min-width: 58px;
    padding-left: 5px;
    padding-right: 5px;
  }
}

.message-file.image-only { min-width: 0; }
.message-file.image-only .message-image-button img { margin-bottom: 0; border-radius: 0; }
.message-row.image-message .message-reply { margin: 8px 10px 7px; line-height: 1.35; padding: 6px 8px; }

/* ========================================================================
   BROMERO MESSAGES V3 — shared chat customization + voice messages
   ======================================================================== */

:root {
  --chat-accent: #16181b;
  --chat-accent-contrast: #fff;
  --chat-other: #f0f2f5;
  --chat-canvas: #fff;
}

.conversation-view[data-chat-theme="midnight"] { --chat-accent:#343b4b; --chat-other:#e8ebf1; }
.conversation-view[data-chat-theme="rose"] { --chat-accent:#b84969; --chat-other:#f8e9ee; }
.conversation-view[data-chat-theme="ocean"] { --chat-accent:#2179a8; --chat-other:#e6f2f8; }
.conversation-view[data-chat-theme="forest"] { --chat-accent:#39745a; --chat-other:#e6f1eb; }
.conversation-view[data-chat-theme="sunset"] { --chat-accent:#b76345; --chat-other:#f8ece7; }

.conversation-view .message-row.mine .message-bubble { background: var(--chat-accent); color: var(--chat-accent-contrast); }
.conversation-view .message-row.theirs:not(.clovis-message) .message-bubble { background: var(--chat-other); }
.conversation-view .message-row.mine .image-caption { background: var(--chat-accent); color: var(--chat-accent-contrast); }

/* V3.4: The wallpaper is anchored to a non-scrolling stage. The message list
   scrolls OVER it, so the background never moves with conversation history. */
.messages-stage {
  min-height: 0;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: #fff;
}

.chat-background-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-color: #fff;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}

.messages-stage .messages-scroll {
  position: relative;
  z-index: 1;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  background: transparent !important;
}

.load-older-wrap,
.messages,
.typing-row {
  position: relative;
  z-index: 1;
  background: transparent;
}

.conversation-view[data-chat-background="soft"] .chat-background-layer {
  opacity: 1;
  background-color: #fff;
  background-image: radial-gradient(circle at 15% 15%,#f3f5f8 0 2px,transparent 3px);
  background-size: 34px 34px;
}
.conversation-view[data-chat-background="dots"] .chat-background-layer {
  opacity: 1;
  background-color: #fff;
  background-image: radial-gradient(circle,#d9dde3 1.4px,transparent 1.5px);
  background-size: 20px 20px;
}
.conversation-view[data-chat-background="grid"] .chat-background-layer {
  opacity: .6;
  background-color: #fff;
  background-image: linear-gradient(#e4e7eb 1px,transparent 1px),linear-gradient(90deg,#e4e7eb 1px,transparent 1px);
  background-size: 28px 28px;
}
.conversation-view[data-chat-background="midnight"] .chat-background-layer {
  opacity: 1;
  background-color: #e3e6ed;
  background-image: linear-gradient(145deg,#e8eaf0,#d9dee8);
}
.conversation-view[data-chat-background="rose"] .chat-background-layer {
  opacity: 1;
  background-color: #fff1f5;
  background-image: linear-gradient(145deg,#fff4f7,#f8e5ec);
}
.conversation-view[data-chat-background="ocean"] .chat-background-layer {
  opacity: 1;
  background-color: #eaf6fb;
  background-image: linear-gradient(145deg,#f0f9fd,#dfeff6);
}
.conversation-view[data-chat-background="forest"] .chat-background-layer {
  opacity: 1;
  background-color: #e9f3ed;
  background-image: linear-gradient(145deg,#f1f8f4,#e0eee6);
}
.conversation-view[data-chat-background="image"] .chat-background-layer { opacity: .34; }
.conversation-view[data-chat-background="none"] .chat-background-layer { display: none !important; }

/* The selected-message controls now live UNDER the message instead of beside it. */
.message-row { overflow: visible; }
.message-stack { min-width: 0; display: flex; flex-direction: column; }
.message-row.mine .message-stack { align-items: flex-end; }
.message-row.theirs .message-stack { align-items: flex-start; }
.message-actions,
.message-row.theirs .message-actions,
.message-row.mine .message-actions {
  position: static !important;
  inset: auto !important;
  transform: none !important;
  opacity: 0;
  pointer-events: none;
  display: flex;
  gap: 5px;
  padding: 5px 2px 0 !important;
  background: transparent;
  border: 0;
  box-shadow: none;
  max-height: 0;
  overflow: hidden;
  transition: opacity .12s ease, max-height .15s ease, padding .15s ease;
}
.message-row.action-open .message-actions,
.message-row:hover .message-actions,
.message-actions:hover {
  opacity: 1;
  pointer-events: auto;
  max-height: 42px;
}
.message-row.mine .message-actions { justify-content:flex-end; }
.message-row.theirs .message-actions { justify-content:flex-start; }
.message-action { background:#fff; border:1px solid var(--border); }
.message-row.action-open { padding-bottom: 2px; }

.system-message {
  align-self: center;
  max-width: min(620px,86%);
  margin: 10px auto;
  color: #8a9099;
  text-align: center;
  font-size: 11px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.system-message time { font-size: 9px; opacity:.7; }

.message-menu-link {
  display:block;
  width:100%;
  text-decoration:none;
  color:var(--text);
  text-align:left;
  border-radius:9px;
  padding:10px 11px;
  font-size:13px;
}
.message-menu-link:hover { background:var(--panel-soft); }

/* Voice recorder */
.voice-button,
.recording-send {
  width:40px;
  height:40px;
  border:0;
  border-radius:50%;
  display:grid;
  place-items:center;
  cursor:pointer;
  background:#f0f2f5;
  color:#30343a;
}
.voice-button:hover { background:#e6e9ed; }
.voice-button svg,
.recording-send svg { width:19px;height:19px;fill:currentColor; }
.recording-send { background:var(--chat-accent); color:white; flex:0 0 auto; }
.composer.recording-hidden { display:none; }
.voice-recording-bar {
  padding:10px 16px calc(12px + env(safe-area-inset-bottom));
  min-height:64px;
  border-top:1px solid var(--border);
  background:#fff;
  display:flex;
  align-items:center;
  gap:10px;
}
.recording-cancel,
.recording-pause {
  border:0;
  background:transparent;
  cursor:pointer;
  color:#59606a;
}
.recording-cancel { width:34px;height:34px;border-radius:50%;font-size:24px;display:grid;place-items:center; }
.recording-cancel:hover,.recording-pause:hover { background:#f2f3f5; }
.recording-pause { padding:8px 10px;border-radius:10px;font-weight:700;font-size:12px; }
.recording-dot { width:8px;height:8px;border-radius:50%;background:#df4b55;animation:recordingPulse 1s infinite; }
@keyframes recordingPulse { 50%{opacity:.35} }
.recording-wave { flex:1;min-width:70px;height:30px;display:flex;align-items:center;justify-content:center;gap:3px;overflow:hidden; }
.recording-wave i { width:3px;border-radius:99px;background:#8a919b;height:8px;animation:voiceWave .75s ease-in-out infinite alternate; }
.recording-wave i:nth-child(2n){animation-delay:.12s;height:16px}.recording-wave i:nth-child(3n){animation-delay:.24s;height:22px}.recording-wave i:nth-child(5n){animation-delay:.34s;height:12px}
@keyframes voiceWave { to{ transform:scaleY(1.45); opacity:.55; } }

/* Voice message bubble */
.voice-message-row .message-bubble { padding:8px 10px; }
.voice-message { min-width:240px; max-width:min(370px,70vw); display:grid; grid-template-columns:34px minmax(90px,1fr) auto auto; align-items:center; gap:8px; }
.voice-play { width:34px;height:34px;border:0;border-radius:50%;background:rgba(0,0,0,.08);color:inherit;display:grid;place-items:center;cursor:pointer; }
.message-row.mine .voice-play { background:rgba(255,255,255,.16); }
.voice-play svg { width:16px;height:16px;fill:currentColor; }
.voice-progress { width:100%; min-width:90px; accent-color:currentColor; cursor:pointer; }
.voice-duration { font-size:11px; opacity:.72; font-variant-numeric:tabular-nums; }
.voice-speed { border:0;border-radius:9px;background:rgba(0,0,0,.06);color:inherit;cursor:pointer;font-size:10px;font-weight:800;padding:5px 6px; }
.message-row.mine .voice-speed { background:rgba(255,255,255,.14); }
.voice-caption { padding-top:6px; line-height:1.4; }

/* V3 settings */
.settings-modal-v3 { width:min(620px,calc(100vw - 28px)); max-height:min(880px,92dvh); overflow:hidden; padding:0; }
.settings-scroll { overflow-y:auto; max-height:calc(92dvh - 74px); overscroll-behavior:contain; }
.settings-name-row { display:flex;align-items:center;justify-content:center;gap:7px; }
.nickname-pencil { width:28px;height:28px;border:0;border-radius:50%;background:transparent;color:#6b7280;cursor:pointer;display:grid;place-items:center; }
.nickname-pencil:hover { background:#f1f3f5;color:#111; }
.nickname-pencil svg { width:15px;height:15px;fill:currentColor; }
.nickname-editor { display:grid;grid-template-columns:minmax(0,1fr) auto auto;gap:7px;width:min(430px,100%);margin:12px auto 0; }
.nickname-editor input { min-width:0;height:38px;border:1px solid var(--border);border-radius:11px;padding:0 10px;outline:none; }
.settings-grid { display:grid;gap:10px; }
.settings-grid.two-col { grid-template-columns:repeat(2,minmax(0,1fr)); }
.settings-actions { display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin-top:10px; }
.toggle-row.compact { padding:10px 0;border-bottom:1px solid #f0f1f3; }
.toggle-row.compact:last-child { border-bottom:0; }
.settings-action-list { display:grid;border:1px solid var(--border);border-radius:13px;overflow:hidden; }
.settings-action-list button { border:0;border-bottom:1px solid var(--border);background:#fff;min-height:44px;padding:0 12px;text-align:left;display:flex;align-items:center;justify-content:space-between;cursor:pointer;color:var(--text); }
.settings-action-list button:last-child { border-bottom:0; }
.settings-action-list button:hover { background:#f7f8fa; }
.danger-list button { color:#b43b43; }
.member-row-v3 { align-items:center; }
.member-tools { margin-left:auto;display:flex;align-items:center;gap:6px; }
.member-role-select { height:30px;border:1px solid var(--border);border-radius:8px;background:#fff;font-size:11px; }
.member-remove { border:0;background:transparent;color:#b43b43;font-size:11px;cursor:pointer; }

/* Search + shared media */
.utility-modal { width:min(650px,calc(100vw - 28px)); max-height:86dvh; overflow:hidden; }
.utility-body { padding:14px 18px 20px;overflow-y:auto;max-height:calc(86dvh - 72px); }
.utility-search { margin:0 0 12px; }
.utility-search input { width:100%; }
.utility-results { display:grid;gap:7px; }
.search-result-message { width:100%;border:1px solid var(--border);background:#fff;border-radius:12px;padding:10px 12px;text-align:left;display:grid;gap:3px;cursor:pointer; }
.search-result-message:hover { background:#f7f8fa; }
.search-result-message span { color:#515761;font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis; }
.search-result-message time { color:#969ca5;font-size:10px; }
.media-tabs { display:flex;gap:4px;padding-bottom:12px;overflow-x:auto; }
.media-tabs button { border:0;background:#f1f3f5;border-radius:999px;padding:8px 12px;white-space:nowrap;cursor:pointer;font-weight:700;font-size:11px; }
.media-tabs button.active { background:#17191d;color:#fff; }
.media-photo-grid { display:grid;grid-template-columns:repeat(3,1fr);gap:6px; }
.media-photo-grid a { aspect-ratio:1;border-radius:10px;overflow:hidden;background:#e8eaed; }
.media-photo-grid img { width:100%;height:100%;object-fit:cover;display:block; }
.media-list-item { border-bottom:1px solid var(--border);padding:11px 4px;display:flex;align-items:center;justify-content:space-between;gap:10px;text-decoration:none;color:var(--text); }
.media-list-item strong,.media-list-item small { display:block; }
.media-list-item small { color:var(--muted);margin-top:2px;font-size:10px; }
.media-list-item audio { width:min(280px,48vw); }

@media (max-width: 860px) {
  .message-row:hover:not(.action-open) .message-actions { opacity:0;pointer-events:none;max-height:0;padding-top:0 !important; }
  .message-row.action-open .message-actions { opacity:1;pointer-events:auto;max-height:42px;padding-top:5px !important; }
  .voice-recording-bar { padding-left:max(10px,env(safe-area-inset-left));padding-right:max(10px,env(safe-area-inset-right)); }
  .message-menu { bottom:calc(84px + env(safe-area-inset-bottom)); }
}

@media (max-width: 520px) {
  .settings-grid.two-col { grid-template-columns:1fr; }
  .settings-modal-v3 { width:100%;max-height:100dvh;height:100dvh;border-radius:0; }
  .settings-scroll { max-height:calc(100dvh - 70px);padding-bottom:env(safe-area-inset-bottom); }
  .nickname-editor { grid-template-columns:1fr auto; }
  .nickname-editor .secondary-button { grid-column:2; }
  .voice-message { min-width:210px;max-width:76vw;grid-template-columns:32px minmax(70px,1fr) auto auto;gap:6px; }
  .recording-wave { gap:2px; }
  .recording-pause { padding-left:7px;padding-right:7px; }
  .media-photo-grid { grid-template-columns:repeat(3,1fr);gap:3px; }
  .media-list-item { align-items:flex-start;flex-direction:column; }
  .media-list-item audio { width:100%; }
}

/* V3 interaction rule: message actions are click/long-press driven, never hover-only. */
.message-row:not(.action-open) .message-actions,
.message-row:hover:not(.action-open) .message-actions {
  opacity: 0 !important;
  pointer-events: none !important;
  max-height: 0 !important;
  padding-top: 0 !important;
}
.message-row.action-open .message-actions {
  opacity: 1 !important;
  pointer-events: auto !important;
  max-height: 42px !important;
  padding-top: 5px !important;
}
