/* ═══════════════════════════════════════
   Mobile Messenger — Premium Styles
   Telegram/Kommo-quality design
   ═══════════════════════════════════════ */

/* ── Container ── */
.messenger-app {
  position: fixed;
  top: 0; left: 0; right: 0;
  bottom: 66px; /* space for bottom-nav */
  z-index: 50;
  background: var(--bg, #f0f2f5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* When chat is open, elevate above bottom-nav (z-index:100) */
.messenger-app.chat-open {
  z-index: 200;
  bottom: 0; /* chat covers entire screen including bottom-nav area */
}

/* ── LIST VIEW ── */
.msg-list-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Header */
.msg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--header-bg, #0079bf);
  color: #fff;
  flex-shrink: 0;
}
.msg-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.msg-header-left i { width: 22px; height: 22px; }
.msg-header h2 { font-size: 19px; font-weight: 700; margin: 0; letter-spacing: -0.3px; }
.msg-header-actions { display: flex; gap: 4px; }
.msg-hdr-btn {
  width: 38px; height: 38px;
  background: rgba(255,255,255,.12);
  border: none; border-radius: 50%;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s;
}
.msg-hdr-btn:active { background: rgba(255,255,255,.25); }
.msg-hdr-btn i { width: 20px; height: 20px; }

/* Search bar */
.msg-search-bar {
  padding: 0 12px;
  background: var(--header-bg, #0079bf);
  max-height: 0;
  overflow: hidden;
  transition: max-height .25s ease, padding .25s ease;
}
.msg-search-bar.expanded {
  max-height: 56px;
  padding: 0 12px 10px;
}
.msg-search-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,.15);
  border-radius: 10px;
  padding: 0 12px;
}
.msg-search-inner i { width: 16px; height: 16px; color: rgba(255,255,255,.6); flex-shrink: 0; }
.msg-search-inner input {
  flex: 1;
  padding: 10px 0;
  border: none;
  font-size: 15px;
  background: transparent;
  color: #fff;
  outline: none;
}
.msg-search-inner input::placeholder { color: rgba(255,255,255,.5); }
.msg-search-clear {
  width: 28px; height: 28px;
  background: rgba(255,255,255,.15);
  border: none; border-radius: 50%;
  color: rgba(255,255,255,.7);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.msg-search-clear i { width: 16px; height: 16px; }

/* ── CONVERSATION LIST ── */
.msg-conv-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* Conversation item */
.msg-conv {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border, #e5e7eb);
  cursor: pointer;
  transition: background .12s;
  -webkit-tap-highlight-color: transparent;
}
.msg-conv:active { background: rgba(0,121,191,.06); }
.msg-conv.unread { background: rgba(0,121,191,.04); }

/* Avatar */
.msg-ava {
  width: 50px; height: 50px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  position: relative;
  font-size: 0;
  overflow: hidden;
}
.msg-ava-img {
  width: 50px; height: 50px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.msg-ava-text {
  width: 50px; height: 50px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.msg-ava-ch {
  position: absolute;
  bottom: -2px; right: -2px;
  font-size: 8px;
  font-weight: 800;
  background: var(--bg, #fff);
  padding: 2px 4px;
  border-radius: 6px;
  line-height: 1;
  letter-spacing: 0.3px;
  border: 2px solid var(--bg, #fff);
}

/* Conv body */
.msg-conv-body { flex: 1; min-width: 0; overflow: hidden; }
.msg-conv-row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.msg-conv-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text, #1f2937);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.msg-conv.unread .msg-conv-name { font-weight: 700; }
.msg-conv-time {
  font-size: 12px;
  color: var(--text2, #6b7280);
  flex-shrink: 0;
  white-space: nowrap;
}
.msg-conv.unread .msg-conv-time { color: var(--primary, #0079bf); font-weight: 600; }
.msg-conv-row2 { display: flex; align-items: center; gap: 8px; }
.msg-conv-preview {
  font-size: 14px;
  color: var(--text2, #6b7280);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  line-height: 1.3;
}
.msg-conv-preview.unread { color: var(--text, #1f2937); font-weight: 500; }
.msg-conv-badge {
  min-width: 20px; height: 20px;
  padding: 0 6px;
  background: var(--primary, #0079bf);
  color: #fff;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  line-height: 1;
}

/* ── CHAT VIEW ── */
.msg-chat-view {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 200;
  background: var(--bg, #f0f2f5);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}
.msg-chat-view.open { transform: translateX(0); }

/* Chat header */
.msg-chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--header-bg, #0079bf);
  color: #fff;
  flex-shrink: 0;
  min-height: 56px;
}
.msg-back-btn {
  width: 38px; height: 38px;
  background: rgba(255,255,255,.1);
  border: none; border-radius: 50%;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background .15s;
}
.msg-back-btn:active { background: rgba(255,255,255,.25); }
.msg-back-btn i { width: 22px; height: 22px; }

.msg-chat-contact {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  cursor: pointer;
}
.msg-chat-ava {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
  overflow: hidden;
}
.msg-chat-ava .msg-ava-img {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
}
.msg-chat-info { flex: 1; min-width: 0; }
.msg-chat-info h3 {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}
.msg-chat-sub {
  font-size: 12px;
  opacity: .7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

/* Channel selector */
.msg-ch-selector { display: flex; gap: 4px; flex-shrink: 0; align-items: center; }
.msg-ch-btn {
  padding: 5px 10px;
  border: 1.5px solid rgba(255,255,255,.3);
  border-radius: 8px;
  background: transparent;
  color: rgba(255,255,255,.6);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  letter-spacing: 0.3px;
}
.msg-ch-btn.active {
  border-color: transparent;
}
.msg-ch-btn:active { transform: scale(.92); }
.msg-ch-single {
  font-size: 12px;
  font-weight: 700;
  opacity: .8;
}

/* ── MESSAGES AREA ── */
.msg-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overscroll-behavior-y: contain;
  background: var(--bg, #f0f2f5);
}

/* Date pill */
.msg-date-pill {
  text-align: center;
  padding: 8px 0 4px;
  position: sticky;
  top: 0;
  z-index: 2;
}
.msg-date-pill span {
  display: inline-block;
  background: var(--card, #fff);
  padding: 4px 14px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text2, #6b7280);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

/* Message bubble */
/* Bubble row with avatar */
.msg-bwrap { display: flex; gap: 6px; align-items: flex-end; padding: 1px 0; }
.msg-bwrap.out { flex-direction: row-reverse; }
.msg-ava { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .7rem; color: #fff; flex-shrink: 0; position: relative; }
.msg-ava-badge { position: absolute; bottom: -2px; right: -2px; width: 13px; height: 13px; border-radius: 50%; display: flex; align-items: center; justify-content: center; border: 1.5px solid var(--bg, #f3f4f6); }

.msg-bubble {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 18px;
  position: relative;
  word-break: break-word;
  line-height: 1.45;
  font-size: 15px;
  animation: msgFadeIn .15s ease;
  flex: 0 1 auto;
}
@keyframes msgFadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.msg-bubble.in {
  background: var(--card, #fff);
  color: var(--text, #1f2937);
  border-bottom-left-radius: 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.msg-bubble.out {
  background: var(--primary, #0079bf);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
.msg-bubble.grouped { margin-top: -1px; }
.msg-bubble.in.grouped { border-top-left-radius: 6px; }
.msg-bubble.out.grouped { border-top-right-radius: 6px; }

.msg-bubble-body { margin-bottom: 2px; }
.msg-bubble-body a { color: inherit; text-decoration: underline; }
.msg-bubble.in .msg-bubble-body a { color: var(--primary, #0079bf); }

.msg-bubble-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 11px;
  opacity: .7;
  margin-top: 2px;
}
.msg-bubble.out .msg-bubble-footer { color: rgba(255,255,255,.8); }
.msg-bubble.in .msg-bubble-footer { color: var(--text2, #6b7280); }

.msg-bubble-ch {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-right: 2px;
}
.msg-bubble-time { white-space: nowrap; }

.msg-status { display: flex; align-items: center; }
.msg-status i { width: 13px; height: 13px; }
.msg-status.read i { color: #34d399 !important; opacity: 1; }
.msg-status.failed i { color: #f87171 !important; opacity: 1; }

/* ── TEMPLATES POPUP ── */
.msg-tpl-popup {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--card, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.15);
  max-height: 340px;
  overflow-y: auto;
  z-index: 50;
}
.msg-tpl-popup.show { display: block; }
.msg-tpl-hdr {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--border, #e5e7eb);
  font-size: 14px; font-weight: 700; color: var(--text, #1f2937);
}
.msg-tpl-hdr span { display: flex; align-items: center; gap: 5px; }
.msg-tpl-hdr-btns { display: flex; gap: 2px; }
.msg-tpl-hdr-btns button { background: none; border: none; color: var(--text2, #6b7280); padding: 4px; cursor: pointer; border-radius: 6px; }
.msg-tpl-hdr-btns button:active { background: rgba(0,0,0,.05); }
.msg-tpl-cat {
  padding: 8px 14px 3px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; color: var(--text2, #9ca3af); letter-spacing: 0.4px;
}
.msg-tpl-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border, #f3f4f6);
  transition: background .12s;
}
.msg-tpl-item:last-child { border-bottom: none; }
.msg-tpl-item:active, .msg-tpl-item.active { background: rgba(0,121,191,.06); }
.msg-tpl-cmd { font-size: 13px; font-weight: 600; color: var(--primary, #0079bf); white-space: nowrap; min-width: 55px; }
.msg-tpl-text { font-size: 13px; color: var(--text2, #6b7280); line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.msg-tpl-file { color: #f59e0b; flex-shrink: 0; }

/* Template button in input bar */
.msg-tpl-btn {
  width: 36px; height: 36px; border: none; background: none;
  color: var(--primary, #0079bf); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; flex-shrink: 0;
}
.msg-tpl-btn:active { background: rgba(0,121,191,.1); }

/* Template add form */
.msg-tpl-form {
  padding: 10px 14px; border-top: 1px solid var(--border, #e5e7eb);
  background: var(--bg2, #f9fafb);
}
.msg-tpl-form input, .msg-tpl-form textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px; font-size: 13px; margin-bottom: 6px; box-sizing: border-box;
  background: #fff; color: var(--text, #1f2937);
}
.msg-tpl-form textarea { resize: vertical; min-height: 40px; }
.msg-tpl-form-btns { display: flex; gap: 8px; margin-top: 4px; }
.msg-tpl-save {
  padding: 7px 16px; background: var(--primary, #0079bf); color: #fff;
  border: none; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.msg-tpl-cancel {
  padding: 7px 16px; background: none; color: var(--text2, #6b7280);
  border: 1px solid var(--border, #e5e7eb); border-radius: 8px; font-size: 13px; cursor: pointer;
}

/* ── INPUT BAR ── */
.msg-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 10px;
  background: var(--card, #fff);
  border-top: 1px solid var(--border, #e5e7eb);
  flex-shrink: 0;
}
.msg-tpl-btn {
  width: 40px; height: 40px;
  background: none;
  border: none;
  border-radius: 50%;
  color: var(--text2, #6b7280);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: color .15s;
}
.msg-tpl-btn:active { color: var(--primary, #0079bf); }
.msg-tpl-btn i { width: 20px; height: 20px; }

.msg-input-wrap { flex: 1; }
.msg-input-wrap textarea {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border, #e5e7eb);
  border-radius: 22px;
  font-size: 15px;
  font-family: inherit;
  background: var(--bg, #f0f2f5);
  color: var(--text, #1f2937);
  resize: none;
  max-height: 120px;
  min-height: 42px;
  line-height: 1.4;
  outline: none;
  box-sizing: border-box;
  transition: border-color .2s;
}
.msg-input-wrap textarea:focus { border-color: var(--primary, #0079bf); }
.msg-input-wrap textarea::placeholder { color: var(--text2, #9ca3af); }

.msg-send-btn {
  width: 42px; height: 42px;
  background: var(--primary, #0079bf);
  border: none; border-radius: 50%;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background .2s, transform .15s, opacity .2s;
}
.msg-send-btn:active { transform: scale(.88); }
.msg-send-btn:disabled { opacity: .35; }
.msg-send-btn i { width: 20px; height: 20px; }

/* ── Loading & Empty states ── */
.msg-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px 20px;
  color: var(--text2, #6b7280);
  font-size: 14px;
}
.msg-spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--border, #e5e7eb);
  border-top-color: var(--primary, #0079bf);
  border-radius: 50%;
  animation: msgSpin .7s linear infinite;
}
@keyframes msgSpin { to { transform: rotate(360deg); } }

.msg-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  color: var(--text2, #6b7280);
  text-align: center;
  gap: 8px;
  flex: 1;
}
.msg-empty-state.small { padding: 40px 20px; }
.msg-empty-state i { width: 48px; height: 48px; opacity: .3; }
.msg-empty-state h3 {
  font-size: 17px;
  color: var(--text, #1f2937);
  font-weight: 600;
  margin: 4px 0 0;
}
.msg-empty-state p { font-size: 14px; line-height: 1.4; margin: 0; }
.msg-empty-state .msg-hint { font-size: 13px; opacity: .7; }

/* ── Nav badge ── */
.msg-nav-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 18px);
  min-width: 17px; height: 17px;
  padding: 0 5px;
  background: #ef4444;
  color: #fff;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  pointer-events: none;
}

/* ── Feature 1: Filter tabs ── */
.msg-filter-tabs {
  display: flex; gap: 0; padding: 8px 12px 4px;
  background: var(--bg, #f0f2f5); flex-shrink: 0;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.msg-filter {
  padding: 6px 14px; border: none; border-radius: 16px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  background: transparent; color: var(--text2, #6b7280);
  cursor: pointer; transition: all .15s;
}
.msg-filter.active { background: var(--primary, #0079bf); color: #fff; }

/* ── Feature 2: Contact bottom sheet ── */
.msg-sheet-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 300; }
.msg-sheet {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 301;
  background: var(--card, #fff); border-radius: 16px 16px 0 0;
  max-height: 75vh; overflow-y: auto;
  transform: translateY(100%); transition: transform .3s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 -4px 20px rgba(0,0,0,.15);
}
.msg-sheet.open { transform: translateY(0); }
.msg-sheet-handle { text-align: center; padding: 10px 0 4px; cursor: pointer; }
.msg-sheet-handle span {
  display: inline-block; width: 36px; height: 4px;
  background: var(--border, #d1d5db); border-radius: 2px;
}
.msg-card { padding: 0 16px 20px; }
.msg-card-header { text-align: center; padding: 8px 0 16px; }
.msg-card-ava { display: flex; justify-content: center; margin-bottom: 10px; }
.msg-card-ava .msg-ava-img { width: 64px; height: 64px; }
.msg-card-ava .msg-ava-text { width: 64px; height: 64px; font-size: 24px; }
.msg-card-name { font-size: 18px; font-weight: 700; color: var(--text, #1f2937); }
.msg-card-detail {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 14px; color: var(--text2, #6b7280); margin-top: 4px;
}
.msg-card-detail a { color: var(--primary, #0079bf); text-decoration: none; }
.msg-card-section { border-top: 1px solid var(--border, #e5e7eb); padding: 12px 0 4px; margin-top: 8px; }
.msg-card-section-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 700; color: var(--text2, #6b7280);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px;
}
.msg-card-deal {
  display: flex; justify-content: space-between; padding: 6px 0;
  font-size: 14px; color: var(--text, #1f2937);
}
.msg-card-deal-amt { font-weight: 600; color: var(--primary, #0079bf); }
.msg-card-activity {
  display: flex; align-items: center; gap: 6px; padding: 5px 0;
  font-size: 13px; color: var(--text, #1f2937);
}
.msg-card-act-date { margin-left: auto; font-size: 12px; color: var(--text2, #6b7280); }
.msg-card-crm-link {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 16px; padding: 12px; border-radius: 10px;
  background: var(--bg, #f0f2f5); color: var(--primary, #0079bf);
  font-size: 14px; font-weight: 600; text-decoration: none;
}

/* ── Feature 3/5: Quick actions popup + forms ── */
.msg-qa-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 300; }
.msg-qa-popup {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 301;
  background: var(--card, #fff); border-radius: 16px 16px 0 0;
  padding: 12px 0 20px; box-shadow: 0 -4px 20px rgba(0,0,0,.15);
}
.msg-qa-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; cursor: pointer; font-size: 15px;
  color: var(--text, #1f2937); transition: background .12s;
}
.msg-qa-item:active { background: rgba(0,121,191,.06); }
.msg-qa-form-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 300; }
.msg-qa-form {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 301;
  background: var(--card, #fff); border-radius: 16px 16px 0 0;
  padding: 16px 16px 24px; box-shadow: 0 -4px 20px rgba(0,0,0,.15);
}
.msg-qa-form-inner { display: flex; flex-direction: column; gap: 10px; }
.msg-qa-form-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 16px; font-weight: 700; color: var(--text, #1f2937);
}
.msg-qa-input {
  width: 100%; padding: 10px 14px; border: 2px solid var(--border, #e5e7eb);
  border-radius: 10px; font-size: 15px; font-family: inherit;
  background: var(--bg, #f0f2f5); color: var(--text, #1f2937);
  outline: none; box-sizing: border-box;
}
.msg-qa-input:focus { border-color: var(--primary, #0079bf); }
.msg-qa-textarea { min-height: 80px; resize: vertical; }
.msg-qa-submit {
  padding: 12px; border: none; border-radius: 10px;
  background: var(--primary, #0079bf); color: #fff;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.msg-qa-cancel {
  padding: 10px; border: none; background: none;
  color: var(--text2, #6b7280); font-size: 14px; cursor: pointer;
}

/* ── Feature 4: Note mode ── */
.msg-note-toggle {
  width: 36px; height: 36px; background: none; border: none; border-radius: 50%;
  color: var(--text2, #6b7280); display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; transition: all .15s;
}
.msg-note-toggle.active { color: #f59e0b; background: rgba(245,158,11,.1); }
.msg-note-toggle i { width: 18px; height: 18px; }
textarea.note-mode { background: #fff8e1 !important; border-color: #ffc107 !important; }
.msg-bubble.note {
  background: #fff3cd; color: #664d03; align-self: center; max-width: 90%;
  border-radius: 12px; border-left: 3px solid #ffc107;
}
.msg-note-header {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; opacity: .7; margin-bottom: 2px;
}

/* ── Feature 5: Assign manager ── */
.msg-assign-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px; cursor: pointer; font-size: 15px;
  color: var(--text, #1f2937); border-bottom: 1px solid var(--border, #e5e7eb);
}
.msg-assign-item.active { color: var(--primary, #0079bf); font-weight: 600; }
.msg-assign-radio { font-size: 18px; width: 20px; text-align: center; }
.msg-assign-current { margin-left: auto; font-size: 12px; color: var(--text2, #6b7280); }

/* ── Feature 6: Chat search ── */
.msg-chat-search {
  max-height: 0; overflow: hidden; background: var(--header-bg, #0079bf);
  transition: max-height .25s ease; flex-shrink: 0;
}
.msg-chat-search.expanded { max-height: 50px; }
.msg-chat-search-inner {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; background: rgba(255,255,255,.15); margin: 0 10px 8px; border-radius: 8px;
}
.msg-chat-search-inner i { width: 16px; height: 16px; color: rgba(255,255,255,.6); }
.msg-chat-search-inner input {
  flex: 1; border: none; background: none; color: #fff;
  font-size: 14px; outline: none; padding: 4px 0;
}
.msg-chat-search-inner input::placeholder { color: rgba(255,255,255,.5); }
.msg-chat-search-count { font-size: 12px; color: rgba(255,255,255,.7); white-space: nowrap; }
.msg-csearch-btn {
  width: 28px; height: 28px; border: none; background: none;
  color: rgba(255,255,255,.7); display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.msg-bubble.highlight { animation: bubbleHighlight 1.5s ease; }
@keyframes bubbleHighlight { 0%,40% { box-shadow: 0 0 0 3px rgba(255,241,118,.8); } 100% { box-shadow: none; } }
mark { background: #FFF176; color: inherit; padding: 0 1px; border-radius: 2px; }

/* ── Feature 7: Pinned chats ── */
.msg-conv.pinned { background: rgba(0,121,191,.03); }
.msg-pin-icon {
  display: inline-flex; color: var(--text2, #9ca3af); margin-left: 2px;
  transform: rotate(45deg); flex-shrink: 0;
}
.msg-pin-icon i { width: 12px; height: 12px; }

/* ── Feature 8: Reply bar + bubble reply ── */
.msg-reply-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--card, #fff);
  border-top: 1px solid var(--border, #e5e7eb); flex-shrink: 0;
}
.msg-reply-preview { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.msg-reply-line { width: 3px; height: 32px; background: var(--primary, #0079bf); border-radius: 2px; flex-shrink: 0; }
.msg-reply-content { min-width: 0; overflow: hidden; }
.msg-reply-name { display: block; font-size: 12px; font-weight: 600; color: var(--primary, #0079bf); }
.msg-reply-text { display: block; font-size: 13px; color: var(--text2, #6b7280); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-reply-close {
  width: 32px; height: 32px; border: none; background: none;
  color: var(--text2, #6b7280); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.msg-bubble-reply {
  display: flex; gap: 6px; padding: 4px 0 6px; margin-bottom: 2px;
  border-bottom: 1px solid rgba(0,0,0,.06);
}
.msg-bubble-reply-line { width: 2px; background: rgba(0,121,191,.5); border-radius: 1px; flex-shrink: 0; }
.msg-bubble-reply-text { font-size: 12px; color: inherit; opacity: .7; line-height: 1.3; }

/* ── Feature 9: File upload + bubble attachments ── */
.msg-attach-btn {
  width: 36px; height: 36px; background: none; border: none; border-radius: 50%;
  color: var(--text2, #6b7280); display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.msg-attach-btn i { width: 20px; height: 20px; }
.msg-file-preview {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--card, #fff);
  border-top: 1px solid var(--border, #e5e7eb); flex-shrink: 0;
}
.msg-file-preview-inner { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.msg-file-thumb { width: 40px; height: 40px; border-radius: 6px; overflow: hidden; flex-shrink: 0; background: var(--bg, #f0f2f5); display: flex; align-items: center; justify-content: center; }
.msg-file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.msg-file-name { font-size: 13px; color: var(--text, #1f2937); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-file-remove {
  width: 32px; height: 32px; border: none; background: none;
  color: var(--text2, #6b7280); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.msg-bubble-img { margin: 4px -4px; }
.msg-bubble-img img { max-width: 100%; border-radius: 8px; cursor: pointer; }
.msg-bubble-file {
  display: flex; align-items: center; gap: 8px; padding: 8px;
  background: rgba(0,0,0,.05); border-radius: 8px; margin: 4px 0; cursor: pointer;
  font-size: 13px; color: inherit;
}

/* ── Feature 10: Link preview card ── */
.msg-link-card {
  display: flex; gap: 8px; margin: 6px 0 2px; padding: 8px;
  background: rgba(0,0,0,.04); border-radius: 8px; cursor: pointer;
  border-left: 3px solid var(--primary, #0079bf);
}
.msg-link-img { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
.msg-link-text { min-width: 0; overflow: hidden; }
.msg-link-title { font-size: 13px; font-weight: 600; color: inherit; line-height: 1.3; }
.msg-link-desc { font-size: 12px; opacity: .7; line-height: 1.3; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ── Feature 11: Typing indicator ── */
.msg-typing {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 16px; font-size: 13px; color: var(--text2, #6b7280);
  flex-shrink: 0;
}
.msg-typing-dots { display: flex; gap: 3px; }
.msg-typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text2, #9ca3af);
  animation: typingBounce .8s ease-in-out infinite;
}
.msg-typing-dots span:nth-child(2) { animation-delay: .15s; }
.msg-typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes typingBounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }

/* ── Safe areas (iOS notch) ── */
@supports (padding-top: env(safe-area-inset-top)) {
  .msg-header, .msg-chat-header {
    padding-top: calc(12px + env(safe-area-inset-top));
  }
  .msg-input-bar {
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
}
