/* ─────────────────────────────────────────────────────
   Chat Panel — Right-side persistent chat
   Design system: Apple-inspired (SF Pro, #0071e3, glass)
   ───────────────────────────────────────────────────── */

/* ── Panel Container ── */
.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  z-index: 200;
  font-family: -apple-system, "system-ui", "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}
.chat-panel.collapsed {
  transform: translateX(380px);
}
.chat-panel.collapsed .chat-container {
  pointer-events: none;
  opacity: 0;
}

/* ── Toggle Button ── */
.chat-toggle {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #0071e3);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0, 113, 227, 0.35);
  z-index: 201;
  transition: transform 0.2s, box-shadow 0.2s;
}
.chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(0, 113, 227, 0.45);
}
.chat-toggle svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}
/* Toggle visibility managed by JS since it's outside the panel */

/* ── Badge ── */
.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: #ff3b30;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  line-height: 1;
}

/* ── Main Container ── */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-left: 1px solid rgba(0, 0, 0, 0.08);
  transition: opacity 0.25s;
  overflow: hidden;
}

/* ── Header ── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  min-height: 56px;
}
.chat-header-title {
  font-size: 18px;
  font-weight: 700;
  color: #1d1d1f;
  letter-spacing: -0.02em;
}
.chat-header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.chat-header-back {
  background: none;
  border: none;
  cursor: pointer;
  color: #0071e3;
  font-size: 15px;
  font-weight: 500;
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
.chat-header-back:hover {
  opacity: 0.8;
}

/* ── Action Buttons ── */
.chat-btn-new,
.chat-btn-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background 0.2s;
}
.chat-btn-new {
  background: #0071e3;
  color: #fff;
  font-weight: 700;
}
.chat-btn-new:hover {
  background: #005bb5;
}
.chat-btn-close {
  background: rgba(0, 0, 0, 0.05);
  color: #86868b;
  font-size: 20px;
}
.chat-btn-close:hover {
  background: rgba(0, 0, 0, 0.1);
}

/* ── Body (view area) ── */
.chat-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ── Conversation List ── */
.chat-conv-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.chat-conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}
.chat-conv-item:hover {
  background: rgba(0, 113, 227, 0.04);
}
.chat-conv-item.active {
  background: rgba(0, 113, 227, 0.08);
}
.chat-conv-item.olivia {
  border-bottom: 2px solid rgba(124, 58, 237, 0.12);
}

/* ── Avatar ── */
.chat-avatar {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #0071e3, #4da3ff);
  position: relative;
}
.chat-avatar.olivia {
  background: linear-gradient(135deg, #7c3aed, #a78bfa);
}
.chat-avatar.group {
  background: linear-gradient(135deg, #34c759, #30d158);
}
.chat-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.chat-avatar .online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #34c759;
  border: 2px solid #fff;
}
.chat-avatar .online-dot.in-meeting {
  background: #ff9f0a;
}
.chat-avatar .online-dot.offline {
  background: #8e8e93;
}

/* ── Status Toggle (in chat header) ── */
.chat-status-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid rgba(0,0,0,0.08);
  background: rgba(0,0,0,0.03);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: #1d1d1f;
  transition: all 0.2s;
  user-select: none;
}
.chat-status-toggle:hover { background: rgba(0,0,0,0.06); }
.chat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.chat-status-dot.available { background: #34c759; }
.chat-status-dot.in_meeting { background: #ff9f0a; }
.chat-status-dot.offline { background: #8e8e93; }

/* ── Read Receipts ── */
.chat-msg-receipt {
  font-size: 10px;
  color: #8e8e93;
  text-align: right;
  margin-top: 2px;
}
.chat-msg-receipt.read {
  color: #0071e3;
}
.chat-msg-receipt svg {
  width: 14px;
  height: 14px;
  vertical-align: middle;
}
.chat-receipt-count {
  font-size: 9px;
  margin-left: 1px;
}

/* ── Message Header Status ── */
.chat-msg-header-status {
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.chat-msg-header-status .chat-status-dot {
  width: 6px;
  height: 6px;
}

/* ── Conversation Info ── */
.chat-conv-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.chat-conv-name {
  font-size: 15px;
  font-weight: 600;
  color: #1d1d1f;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-conv-preview {
  font-size: 13px;
  color: #86868b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.chat-conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.chat-conv-time {
  font-size: 12px;
  color: #86868b;
}
.chat-conv-unread {
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: #0071e3;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* ── Messages View ── */
.chat-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}
.chat-msg-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  min-height: 48px;
}
.chat-msg-header-name {
  font-size: 16px;
  font-weight: 600;
  color: #1d1d1f;
}
.chat-msg-header-status {
  font-size: 12px;
  color: #34c759;
}
.chat-msg-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ── Message Bubbles ── */
.chat-msg {
  max-width: 82%;
  display: flex;
  flex-direction: column;
  animation: chatMsgIn 0.25s ease;
}
@keyframes chatMsgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-msg.sent {
  align-self: flex-end;
}
.chat-msg.received {
  align-self: flex-start;
}
.chat-msg-sender {
  font-size: 11px;
  font-weight: 600;
  color: #86868b;
  margin-bottom: 2px;
  padding: 0 4px;
}
.chat-msg-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-msg.sent .chat-msg-bubble {
  background: #0071e3;
  color: #fff;
  border-bottom-right-radius: 6px;
}
.chat-msg.received .chat-msg-bubble {
  background: #f0f0f5;
  color: #1d1d1f;
  border-bottom-left-radius: 6px;
}
.chat-msg.ai .chat-msg-bubble {
  background: linear-gradient(135deg, rgba(124,58,237,0.04), rgba(0,113,227,0.04));
  color: #1d1d1f;
  border-bottom-left-radius: 6px;
  border: 1px solid rgba(124, 58, 237, 0.1);
  padding: 12px 16px;
  white-space: normal;
}

/* ── AI Content Typography ── */
.chat-msg.ai .chat-msg-bubble .ai-p {
  margin: 0;
  line-height: 1.5;
}
.chat-msg.ai .chat-msg-bubble .ai-spacer {
  height: 8px;
}
.chat-msg.ai .chat-msg-bubble .ai-heading {
  font-weight: 700;
  color: #1d1d1f;
  margin: 6px 0 2px;
  line-height: 1.3;
}
.chat-msg.ai .chat-msg-bubble .ai-h1 { font-size: 16px; }
.chat-msg.ai .chat-msg-bubble .ai-h2 { font-size: 15px; }
.chat-msg.ai .chat-msg-bubble .ai-h3 { font-size: 14px; color: #6e6e73; text-transform: uppercase; letter-spacing: 0.03em; }
.chat-msg.ai .chat-msg-bubble strong {
  font-weight: 700;
  color: #1d1d1f;
}
.chat-msg.ai .chat-msg-bubble em {
  font-style: italic;
  color: #6e6e73;
}
.chat-msg.ai .chat-msg-bubble .ai-code {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 12px;
  background: rgba(124, 58, 237, 0.08);
  color: #7c3aed;
  padding: 1px 5px;
  border-radius: 4px;
}
.chat-msg.ai .chat-msg-bubble .ai-ul,
.chat-msg.ai .chat-msg-bubble .ai-ol {
  margin: 4px 0;
  padding-left: 20px;
  list-style-position: outside;
}
.chat-msg.ai .chat-msg-bubble .ai-ul {
  list-style-type: none;
  padding-left: 0;
}
.chat-msg.ai .chat-msg-bubble .ai-ul > li {
  position: relative;
  padding-left: 16px;
  margin: 3px 0;
  line-height: 1.45;
}
.chat-msg.ai .chat-msg-bubble .ai-ul > li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #7c3aed;
}
.chat-msg.ai .chat-msg-bubble .ai-ul > li.ai-sub {
  padding-left: 28px;
}
.chat-msg.ai .chat-msg-bubble .ai-ul > li.ai-sub::before {
  left: 14px;
  width: 4px;
  height: 4px;
  background: #a78bfa;
}
.chat-msg.ai .chat-msg-bubble .ai-ol > li {
  margin: 3px 0;
  line-height: 1.45;
}
.chat-msg.ai .chat-msg-bubble .ai-ol > li::marker {
  color: #7c3aed;
  font-weight: 600;
}
.chat-msg.ai .chat-msg-bubble .ai-hr {
  border: none;
  border-top: 1px solid rgba(124, 58, 237, 0.15);
  margin: 8px 0;
}
/* AI Tables */
.chat-msg.ai .chat-msg-bubble .ai-table-wrap {
  overflow-x: auto;
  margin: 6px -4px;
  border-radius: 8px;
  border: 1px solid rgba(124, 58, 237, 0.1);
}
.chat-msg.ai .chat-msg-bubble .ai-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.chat-msg.ai .chat-msg-bubble .ai-table th {
  background: rgba(124, 58, 237, 0.08);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #6e6e73;
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
}
.chat-msg.ai .chat-msg-bubble .ai-table td {
  padding: 5px 10px;
  border-top: 1px solid rgba(0,0,0,0.05);
  color: #1d1d1f;
}
.chat-msg.ai .chat-msg-bubble .ai-table tr:hover td {
  background: rgba(124, 58, 237, 0.03);
}
/* ── Inline Media (images, video, YouTube) ── */
.ai-media {
  margin: 6px 0;
  border-radius: 10px;
  overflow: hidden;
  max-width: 100%;
}
.ai-inline-img {
  display: block;
  max-width: 100%;
  max-height: 280px;
  border-radius: 10px;
  object-fit: contain;
  background: rgba(0,0,0,0.02);
  cursor: pointer;
  transition: transform 0.2s;
}
.ai-inline-img:hover {
  transform: scale(1.02);
}
.ai-inline-video {
  display: block;
  max-width: 100%;
  max-height: 280px;
  border-radius: 10px;
  background: #000;
}
.ai-inline-yt {
  display: block;
  width: 100%;
  aspect-ratio: 16/9;
  border-radius: 10px;
  border: none;
}
.ai-link {
  color: #0071e3;
  text-decoration: none;
  border-bottom: 1px solid rgba(0,113,227,0.3);
  transition: border-color 0.2s;
}
.ai-link:hover {
  border-bottom-color: #0071e3;
}
.chat-msg.sent .ai-link {
  color: rgba(255,255,255,0.9);
  border-bottom-color: rgba(255,255,255,0.4);
}
.chat-msg.sent .ai-link:hover {
  border-bottom-color: #fff;
}
/* Image lightbox on click */
.chat-lightbox {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: chatMsgIn 0.2s ease;
}
.chat-lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}
.chat-msg.system {
  align-self: center;
  max-width: 90%;
}
.chat-msg.system .chat-msg-bubble {
  background: transparent;
  color: #86868b;
  font-size: 12px;
  text-align: center;
  padding: 6px 12px;
}
.chat-msg-time {
  font-size: 10px;
  color: #86868b;
  margin-top: 2px;
  padding: 0 4px;
}
.chat-msg.sent .chat-msg-time {
  text-align: right;
}

/* ── AI Label ── */
.chat-msg-ai-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 700;
  color: #7c3aed;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 3px;
  padding: 2px 8px 2px 5px;
  background: rgba(124, 58, 237, 0.06);
  border-radius: 10px;
  width: fit-content;
}
.chat-msg-ai-label svg {
  width: 13px;
  height: 13px;
}

/* ── File Message ── */
.chat-file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: background 0.2s;
  margin: 4px 0;
}
.chat-file-card:hover {
  background: rgba(255, 255, 255, 0.9);
}
.chat-file-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #f5f5f7;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.chat-file-info {
  flex: 1;
  min-width: 0;
}
.chat-file-name {
  font-size: 13px;
  font-weight: 600;
  color: #1d1d1f;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-file-size {
  font-size: 11px;
  color: #86868b;
}
.chat-file-img {
  width: 100%;
  max-width: 240px;
  border-radius: 12px;
  margin: 4px 0;
}

/* ── Input Bar ── */
.chat-msg-input {
  padding: 12px 14px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f0f0f5;
  border-radius: 22px;
  padding: 4px 6px 4px 4px;
  transition: box-shadow 0.2s;
}
.chat-input-row:focus-within {
  box-shadow: 0 0 0 2px rgba(0, 113, 227, 0.25);
  background: #fff;
}
.chat-input-row input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  font-family: inherit;
  padding: 8px 8px;
  outline: none;
  color: #1d1d1f;
}
.chat-input-row input::placeholder {
  color: #86868b;
}
.chat-attach-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #86868b;
  transition: background 0.2s, color 0.2s;
}
.chat-attach-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #0071e3;
}
.chat-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: #0071e3;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: background 0.2s, transform 0.15s;
}
.chat-send-btn:hover {
  background: #005bb5;
}
.chat-send-btn:active {
  transform: scale(0.92);
}
.chat-send-btn:disabled {
  background: #d1d1d6;
  cursor: default;
  transform: none;
}
.chat-send-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ── Mic Button (Voice Input) ── */
.chat-mic-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #86868b;
  transition: all 0.25s ease;
  position: relative;
  flex-shrink: 0;
}
.chat-mic-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #0071e3;
}
.chat-mic-btn svg {
  width: 16px;
  height: 16px;
}
.chat-mic-btn.recording {
  background: #fff0f0;
  border-color: #ff3b30;
  color: #ff3b30;
  animation: chatVoicePulse 1.5s ease-in-out infinite;
}
.chat-mic-btn.recording svg.chat-mic-icon { display: none; }
.chat-mic-btn.recording .chat-voice-bars { display: flex; }
.chat-mic-btn .chat-voice-bars {
  display: none;
  gap: 2px;
  align-items: center;
  height: 16px;
}
.chat-mic-btn .chat-voice-bars span {
  width: 2.5px;
  background: #ff3b30;
  border-radius: 2px;
  animation: chatVoiceBar 0.6s ease-in-out infinite;
}
.chat-mic-btn .chat-voice-bars span:nth-child(1) { height: 5px; animation-delay: 0s; }
.chat-mic-btn .chat-voice-bars span:nth-child(2) { height: 10px; animation-delay: 0.1s; }
.chat-mic-btn .chat-voice-bars span:nth-child(3) { height: 16px; animation-delay: 0.2s; }
.chat-mic-btn .chat-voice-bars span:nth-child(4) { height: 10px; animation-delay: 0.3s; }
.chat-mic-btn .chat-voice-bars span:nth-child(5) { height: 5px; animation-delay: 0.4s; }
.chat-mic-btn.no-speech { display: none; }
@keyframes chatVoicePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,59,48,0.3); }
  50% { box-shadow: 0 0 0 6px rgba(255,59,48,0); }
}
@keyframes chatVoiceBar {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1); }
}

/* ── Typing Indicator ── */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 18px;
  font-size: 12px;
  color: #86868b;
  animation: chatMsgIn 0.2s ease;
}
.chat-typing-dots {
  display: flex;
  gap: 3px;
}
.chat-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #86868b;
  animation: typingBounce 1.2s infinite;
}
.chat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

/* ── New Conversation View ── */
.chat-new-conv {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-search-input {
  margin: 12px 18px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: #f5f5f7;
  transition: border-color 0.2s, background 0.2s;
}
.chat-search-input:focus {
  border-color: #0071e3;
  background: #fff;
}
.chat-member-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.chat-member-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  cursor: pointer;
  transition: background 0.15s;
}
.chat-member-item:hover {
  background: rgba(0, 113, 227, 0.04);
}
.chat-member-name {
  font-size: 14px;
  font-weight: 500;
  color: #1d1d1f;
}
.chat-member-store {
  font-size: 12px;
  color: #86868b;
}
.chat-member-status {
  font-weight: 500;
}
.chat-member-status.available { color: #34c759; }
.chat-member-status.in_meeting { color: #ff9f0a; }
.chat-member-status.offline { color: #8e8e93; }

.chat-group-select-btns {
  display: flex;
  gap: 8px;
  padding: 6px 18px;
  border-bottom: 1px solid #f0f0f0;
}
.chat-select-btn {
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 12px;
  border: 1px solid #d2d2d7;
  background: #fff;
  color: #0071e3;
  cursor: pointer;
  transition: all 0.15s;
}
.chat-select-btn:hover {
  background: #0071e3;
  color: #fff;
  border-color: #0071e3;
}

/* ── Loading / Empty States ── */
.chat-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: #86868b;
  font-size: 14px;
  gap: 8px;
}
.chat-loading-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(0, 113, 227, 0.15);
  border-top-color: #0071e3;
  border-radius: 50%;
  animation: chatSpin 0.7s linear infinite;
}
@keyframes chatSpin {
  to { transform: rotate(360deg); }
}
.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: #86868b;
  font-size: 14px;
  gap: 8px;
  padding: 40px;
  text-align: center;
}
.chat-empty-icon {
  font-size: 40px;
  opacity: 0.3;
}

/* ── Notification Toast ── */
.chat-toast {
  position: fixed;
  top: 20px;
  right: 400px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 14px;
  padding: 12px 18px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  z-index: 300;
  max-width: 300px;
  animation: toastSlideIn 0.3s ease;
  cursor: pointer;
  transition: opacity 0.3s;
  border: 1px solid rgba(0, 0, 0, 0.06);
}
.chat-toast.hiding {
  opacity: 0;
}
@keyframes toastSlideIn {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-toast-title {
  font-size: 13px;
  font-weight: 700;
  color: #1d1d1f;
}
.chat-toast-body {
  font-size: 12px;
  color: #86868b;
  margin-top: 2px;
}

/* ── Mobile Responsive ── */
@media (max-width: 768px) {
  .chat-panel {
    width: 100%;
    border-left: none;
  }
  .chat-panel.collapsed {
    transform: translateX(100%);
  }
  .chat-container {
    border-left: none;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .chat-toggle {
    bottom: calc(20px + env(safe-area-inset-bottom, 0));
    right: 16px;
    width: 50px;
    height: 50px;
  }
  .chat-toggle svg {
    width: 22px;
    height: 22px;
  }
  .chat-toast {
    right: 16px;
    left: 16px;
    top: auto;
    bottom: calc(80px + env(safe-area-inset-bottom, 0));
    max-width: none;
  }
  /* Header compact */
  .chat-header {
    padding: 12px 16px;
    min-height: 48px;
    padding-top: max(12px, env(safe-area-inset-top, 0));
  }
  .chat-header-title {
    font-size: 16px;
  }
  /* Messages body */
  .chat-msg-body {
    padding: 12px 14px;
  }
  .chat-msg {
    max-width: 88%;
  }
  .chat-msg-bubble {
    font-size: 15px;
    padding: 9px 13px;
  }
  .chat-msg.ai .chat-msg-bubble {
    padding: 10px 14px;
  }
  /* Input bar with safe area */
  .chat-msg-input {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0));
  }
  .chat-input-row {
    padding: 3px 5px 3px 3px;
  }
  .chat-input-row input {
    font-size: 16px; /* Prevents iOS zoom on focus */
    padding: 8px 6px;
  }
  /* Conversation list compact */
  .chat-conv-item {
    padding: 12px 16px;
    gap: 10px;
  }
  .chat-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    font-size: 14px;
  }
  /* Search input */
  .chat-search-input {
    margin: 10px 16px;
  }
  /* Members list compact */
  .chat-member-item {
    padding: 9px 16px;
  }
  /* AI table scroll */
  .chat-msg.ai .chat-msg-bubble .ai-table-wrap {
    margin: 6px -8px;
  }
  /* Mention dropdown */
  .chat-mention-dropdown {
    margin: 0 12px 6px;
  }
  /* Lightbox mobile */
  .chat-lightbox img {
    max-width: 96vw;
    max-height: 85vh;
  }
  /* Lock page scroll when chat is open */
  body.chat-open {
    overflow: hidden;
  }
}

/* ── Clear Chat Button ── */
.chat-btn-clear {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #86868b;
  transition: background 0.2s, color 0.2s;
  flex-shrink: 0;
}
.chat-btn-clear:hover {
  background: rgba(255, 59, 48, 0.08);
  color: #ff3b30;
}

/* ── @Mention Autocomplete Dropdown ── */
.chat-mention-dropdown {
  max-height: 180px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  margin: 0 14px 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
.chat-mention-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.12s;
}
.chat-mention-item:first-child {
  border-radius: 12px 12px 0 0;
}
.chat-mention-item:last-child {
  border-radius: 0 0 12px 12px;
}
.chat-mention-item:only-child {
  border-radius: 12px;
}
.chat-mention-item:hover,
.chat-mention-item.selected {
  background: rgba(0, 113, 227, 0.06);
}
.chat-mention-item .chat-avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
  font-size: 11px;
}
.chat-mention-name {
  font-size: 13px;
  font-weight: 600;
  color: #1d1d1f;
}
.chat-mention-store {
  font-size: 11px;
  color: #86868b;
}

/* ── Moderation Warning ── */
.chat-moderation-warning {
  align-self: center;
  max-width: 90%;
  background: rgba(255, 59, 48, 0.08);
  border: 1px solid rgba(255, 59, 48, 0.2);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 13px;
  color: #ff3b30;
  text-align: center;
  animation: chatMsgIn 0.25s ease;
}
.chat-moderation-warning strong {
  display: block;
  margin-bottom: 4px;
}

/* ── Reaction Picker (floating bar above message) ── */
.chat-reaction-picker {
  position: absolute;
  top: -44px;
  left: 0;
  display: flex;
  gap: 2px;
  background: #fff;
  border-radius: 22px;
  padding: 4px 6px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
  z-index: 10;
  animation: reactionPickerIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chat-msg.sent .chat-reaction-picker {
  left: auto;
  right: 0;
}
@keyframes reactionPickerIn {
  from { opacity: 0; transform: scale(0.8) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.chat-reaction-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.15s;
  padding: 0;
  line-height: 1;
}
.chat-reaction-btn:hover {
  transform: scale(1.3);
  background: rgba(0, 0, 0, 0.05);
}
.chat-reaction-btn:active {
  transform: scale(1.0);
}

/* ── Reaction Pills (below message bubble) ── */
.chat-msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
  padding: 0 4px;
}
.chat-msg.sent .chat-msg-reactions {
  justify-content: flex-end;
}
.chat-reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(0, 0, 0, 0.03);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.4;
}
.chat-reaction-pill:hover {
  background: rgba(0, 0, 0, 0.06);
}
.chat-reaction-pill.mine {
  border-color: rgba(0, 113, 227, 0.3);
  background: rgba(0, 113, 227, 0.08);
}

@media (max-width: 768px) {
  .chat-reaction-picker {
    top: -40px;
    padding: 3px 4px;
  }
  .chat-reaction-btn {
    width: 32px;
    height: 32px;
    font-size: 18px;
  }
}

/* ── Drag & Drop File Upload Overlay ── */
.chat-drop-active {
  position: relative;
}
.chat-drop-active::after {
  content: 'Drop files here';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 113, 227, 0.08);
  border: 2px dashed #0071e3;
  border-radius: 12px;
  color: #0071e3;
  font-size: 15px;
  font-weight: 600;
  z-index: 5;
  pointer-events: none;
}

/* ── Expired Image Placeholder ── */
.ai-img-expired {
  padding: 16px 20px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px dashed rgba(0, 0, 0, 0.15);
  border-radius: 10px;
  color: #86868b;
  font-size: 13px;
  text-align: center;
  font-style: italic;
}

/* ── Leave/Delete Button (in msg header) ── */
.chat-btn-leave {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #86868b;
  transition: background 0.2s, color 0.2s;
  flex-shrink: 0;
}
.chat-btn-leave:hover {
  background: rgba(255, 59, 48, 0.08);
  color: #ff3b30;
}

/* ── Conversation Item Delete (swipe / hover) ── */
.chat-conv-item {
  position: relative;
  overflow: hidden;
}
.chat-conv-delete-btn {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 0;
  background: #ff3b30;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  transition: width 0.2s ease;
  white-space: nowrap;
  padding: 0;
}
.chat-conv-item:hover .chat-conv-delete-btn,
.chat-conv-item.swiped .chat-conv-delete-btn {
  width: 72px;
  padding: 0 10px;
}
.chat-conv-item.olivia .chat-conv-delete-btn {
  display: none;
}
.chat-conv-delete-btn:hover {
  background: #e02020;
}

/* ── Confirmation Dialog ── */
.chat-confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: chatMsgIn 0.2s ease;
}
.chat-confirm-box {
  background: #fff;
  border-radius: 14px;
  padding: 24px;
  max-width: min(320px, calc(100vw - 48px));
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
  text-align: center;
}
.chat-confirm-box h3 {
  font-size: 16px;
  font-weight: 700;
  color: #1d1d1f;
  margin: 0 0 8px;
}
.chat-confirm-box p {
  font-size: 13px;
  color: #86868b;
  margin: 0 0 20px;
  line-height: 1.4;
}
.chat-confirm-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.chat-confirm-btns button {
  flex: 1;
  padding: 10px 16px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.chat-confirm-cancel {
  background: #f0f0f5;
  color: #1d1d1f;
}
.chat-confirm-cancel:hover {
  background: #e5e5ea;
}
.chat-confirm-danger {
  background: #ff3b30;
  color: #fff;
}
.chat-confirm-danger:hover {
  background: #e02020;
}

/* ── Group Chat: Selected Members Bar ── */
.chat-group-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 18px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  align-items: center;
  min-height: 46px;
}
.chat-group-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(0, 113, 227, 0.08);
  border-radius: 14px;
  font-size: 12px;
  font-weight: 600;
  color: #0071e3;
}
.chat-group-chip-x {
  cursor: pointer;
  font-size: 14px;
  opacity: 0.6;
  margin-left: 2px;
}
.chat-group-chip-x:hover {
  opacity: 1;
}
.chat-group-actions {
  display: flex;
  gap: 8px;
  padding: 10px 18px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}
.chat-group-name-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: #f5f5f7;
}
.chat-group-name-input:focus {
  border-color: #0071e3;
  background: #fff;
}
.chat-group-create-btn {
  padding: 10px 20px;
  border-radius: 10px;
  border: none;
  background: #34c759;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.chat-group-create-btn:hover {
  background: #2db84d;
}
.chat-group-create-btn:disabled {
  background: #d1d1d6;
  cursor: default;
}

/* ── Member item checkbox (group mode) ── */
.chat-member-item .chat-member-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #d1d1d6;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
  margin-left: auto;
}
.chat-member-item.selected .chat-member-check {
  background: #0071e3;
  border-color: #0071e3;
}
.chat-member-item.selected .chat-member-check::after {
  content: '✓';
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

/* ── Group Mode Toggle ── */
.chat-group-toggle {
  display: flex;
  gap: 8px;
  padding: 10px 18px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
.chat-group-toggle button {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  background: #fff;
  color: #1d1d1f;
}
.chat-group-toggle button.active {
  background: #0071e3;
  border-color: #0071e3;
  color: #fff;
}

/* ── Group Info Panel ── */
.chat-group-header-clickable {
  cursor: pointer;
  border-radius: 6px;
  padding: 2px 4px;
  transition: background 0.15s;
}
.chat-group-header-clickable:hover {
  background: rgba(0, 113, 227, 0.06);
}
.chat-group-info-panel {
  position: absolute;
  top: 52px;
  left: 0;
  right: 0;
  bottom: 0;
  background: #f8f8fa;
  padding: 14px 18px;
  overflow-y: auto;
  z-index: 10;
  animation: fadeSlideDown 0.2s ease-out;
  -webkit-overflow-scrolling: touch;
}
@keyframes fadeSlideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-group-info-section {
  margin-bottom: 12px;
}
.chat-group-info-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #86868b;
  margin-bottom: 8px;
}
.chat-group-info-rename {
  display: flex;
  gap: 8px;
}
.chat-group-rename-input {
  flex: 1;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #d2d2d7;
  font-size: 14px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s;
}
.chat-group-rename-input:focus {
  border-color: #0071e3;
}
.chat-rename-save-btn {
  padding: 6px 14px;
  border-radius: 8px;
  border: none;
  background: #0071e3;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.chat-rename-save-btn:hover {
  background: #005bb5;
}
.chat-group-info-member {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}
.chat-group-info-member-name {
  font-size: 13px;
  font-weight: 500;
  color: #1d1d1f;
}
.chat-group-info-role {
  font-size: 10px;
  font-weight: 600;
  color: #0071e3;
  background: rgba(0, 113, 227, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.chat-group-info-leave {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid #ff3b30;
  background: transparent;
  color: #ff3b30;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 4px;
}
.chat-group-info-leave:hover {
  background: #ff3b30;
  color: #fff;
}

/* ── OliviaAI Bar (bottom of thread listing) ── */
.chat-olivia-bar {
  flex-shrink: 0;
  border-top: 1px solid #e5e5ea;
  background: #f9f9fb;
  padding: 8px 12px;
}
.chat-olivia-bar .chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-olivia-bar input {
  flex: 1;
  border: 1px solid #d1d1d6;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 16px;
  outline: none;
  background: #fff;
  transition: border-color 0.2s;
}
.chat-olivia-bar input:focus {
  border-color: #7c3aed;
}
.chat-olivia-bar .chat-send-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  background: #7c3aed;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.chat-olivia-bar .chat-send-btn:hover {
  background: #6d28d9;
}
.chat-olivia-bar .chat-send-btn svg {
  width: 16px;
  height: 16px;
  fill: #fff;
}
.chat-olivia-response {
  max-height: 200px;
  overflow-y: auto;
  padding: 10px 14px;
  margin-bottom: 8px;
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e5e5ea;
  font-size: 13px;
  line-height: 1.5;
  color: #1c1c1e;
  position: relative;
}
.chat-olivia-response .olivia-thinking {
  color: #7c3aed;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-olivia-response .olivia-thinking .chat-typing-dots {
  display: inline-flex;
}
.chat-olivia-response .olivia-dismiss {
  position: absolute;
  top: 4px;
  right: 8px;
  background: none;
  border: none;
  color: #8e8e93;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
}
.chat-olivia-response .olivia-dismiss:hover {
  color: #1c1c1e;
}

/* ── OliviaAI Search Results (injected into main page) ── */
/* Search results now navigate to actual /inventory and /search pages */

/* Chat panel overlays content — no body shift needed */
