/* ──────────────────────────────────────────────
   RESET & BASE
────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:       #0a0a0f;
  --bg-surface:    #12121a;
  --bg-elevated:   #1a1a26;
  --bg-hover:      #22223a;
  --bg-active:     #1e1e35;
  --border:        rgba(255,255,255,0.07);
  --border-strong: rgba(255,255,255,0.14);

  --text-primary:   #f0f0f8;
  --text-secondary: #8888aa;
  --text-muted:     #55556a;

  --accent-start: #f09433;
  --accent-mid:   #dc2743;
  --accent-end:   #bc1888;
  --accent-grad:  linear-gradient(135deg, #f09433, #dc2743, #bc1888);

  --bubble-mine:   linear-gradient(135deg, #833ab4, #fd1d1d, #fcb045);
  --bubble-theirs: #1e1e2e;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --font: 'Inter', -apple-system, sans-serif;
  --sidebar-w: 340px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ──────────────────────────────────────────────
   OVERLAY / LOGIN
────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(188,24,136,0.18) 0%, rgba(10,10,15,0.98) 60%);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.4s ease;
}

.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 44px 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 40px 120px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04);
  animation: slideUp 0.4s ease;
}

.login-logo {
  width: 64px; height: 64px;
  margin: 0 auto 20px;
}
.login-logo svg { width: 100%; height: 100%; }

.login-card h1 {
  font-size: 22px; font-weight: 700;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 32px;
}

.input-group {
  text-align: left;
  margin-bottom: 16px;
}
.input-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 7px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.input-group input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-group input:focus {
  border-color: #dc2743;
  box-shadow: 0 0 0 3px rgba(220,39,67,0.15);
}
.input-group input::placeholder { color: var(--text-muted); }

.btn-primary {
  width: 100%;
  padding: 13px;
  background: var(--accent-grad);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: opacity var(--transition), transform var(--transition);
  position: relative;
  overflow: hidden;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary.loading { opacity: 0.7; pointer-events: none; }
.btn-primary.loading span::after {
  content: '…';
  animation: dots 1s infinite;
}

.twofa-hint {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 20px;
  line-height: 1.5;
}

.error-msg {
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(220,39,67,0.12);
  border: 1px solid rgba(220,39,67,0.3);
  border-radius: var(--radius-sm);
  color: #ff6b8a;
  font-size: 13px;
  text-align: left;
}

/* ──────────────────────────────────────────────
   APP LAYOUT
────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ──────────────────────────────────────────────
   SIDEBAR
────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
}

.btn-icon {
  width: 32px; height: 32px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

.sidebar-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-search input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 16px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}
.sidebar-search input:focus { border-color: var(--border-strong); }
.sidebar-search input::placeholder { color: var(--text-muted); }

.inbox-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.inbox-tabs::-webkit-scrollbar { display: none; }
.inbox-tab {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}
.inbox-tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.inbox-tab.active {
  background: var(--text-primary);
  color: var(--bg-surface);
  border-color: var(--text-primary);
}

.thread-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.thread-list::-webkit-scrollbar { width: 4px; }
.thread-list::-webkit-scrollbar-track { background: transparent; }
.thread-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

.thread-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background var(--transition);
  border-radius: 0;
  position: relative;
}
.thread-item:hover { background: var(--bg-hover); }
.thread-item.active { background: var(--bg-active); }
.thread-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  background: var(--accent-grad);
  border-radius: 0 2px 2px 0;
}

.thread-avatar {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--bg-hover);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}
.thread-avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.thread-avatar.group {
  background: linear-gradient(135deg, #833ab4, #bc1888);
}

.thread-info {
  flex: 1;
  min-width: 0;
}
.thread-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}
.thread-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thread-unread .thread-name { color: #fff; }
.thread-unread .thread-preview { color: var(--text-primary); font-weight: 500; }

.thread-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  flex-shrink: 0;
}
.thread-time {
  font-size: 11px;
  color: var(--text-muted);
}
.unread-badge {
  width: 18px; height: 18px;
  background: var(--accent-grad);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
}

/* ──────────────────────────────────────────────
   CHAT AREA
────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
}
.empty-icon { font-size: 52px; }
.empty-state h2 { font-size: 20px; font-weight: 600; color: var(--text-secondary); }
.empty-state p { font-size: 14px; }

#chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-header-user {
  display: flex;
  align-items: center;
  gap: 14px;
}
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #833ab4, #bc1888);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.chat-name { font-size: 16px; font-weight: 700; }
.chat-username { font-size: 12px; color: var(--text-secondary); margin-top: 1px; }

/* ──────────────────────────────────────────────
   MESSAGES
────────────────────────────────────────────── */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.messages-container::-webkit-scrollbar { width: 4px; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg-row {
  display: flex;
  margin-bottom: 2px;
}
.msg-row.mine { justify-content: flex-end; }
.msg-row.theirs { justify-content: flex-start; gap: 8px; }

/* Wrapper autour de bubble + time — c'est lui qui porte le max-width */
.msg-row > div:not(.msg-avatar-sm) {
  max-width: min(65%, calc(100% - 180px));
  min-width: 0;
  position: relative; /* Contexte de positionnement absolu pour .msg-actions */
}

.msg-avatar-sm {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #833ab4, #bc1888);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  align-self: flex-end;
  overflow: hidden;
}
.msg-avatar-sm img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.msg-avatar-sm.hidden-av { visibility: hidden; }

.bubble {
  display: inline-block;
  width: fit-content;
  max-width: 100%;
  padding: 10px 15px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
}
.mine .bubble {
  background: var(--bubble-mine);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.theirs .bubble {
  background: var(--bubble-theirs);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}

.msg-system {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  margin: 8px 0;
  font-style: italic;
}

.msg-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
  text-align: right;
}
.theirs .msg-time { text-align: left; }

.date-separator {
  text-align: center;
  margin: 16px 0 8px;
  position: relative;
}
.date-separator span {
  background: var(--bg-base);
  padding: 0 12px;
  font-size: 11px;
  color: var(--text-muted);
  position: relative;
  z-index: 1;
}
.date-separator::before {
  content: '';
  position: absolute;
  top: 50%; left: 0; right: 0;
  height: 1px;
  background: var(--border);
}

/* ──────────────────────────────────────────────
   MESSAGE ACTIONS (hover toolbar)
────────────────────────────────────────────── */
.msg-row {
  position: relative;
}
.msg-row:hover .msg-actions { opacity: 1; pointer-events: auto; }

.msg-actions {
  position: absolute;
  top: 50%; transform: translateY(-50%);
  display: flex;
  gap: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 10;
}
.msg-row.mine  .msg-actions { right: calc(100% + 8px); left: auto; }
.msg-row.theirs .msg-actions { left: calc(100% + 8px); right: auto; }

.action-btn {
  width: 30px; height: 30px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text-secondary);
  line-height: 1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.action-btn:hover { background: var(--bg-hover); transform: scale(1.15) translateY(-2px); color: var(--text-primary); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5); }
.action-btn.liked {
  background: rgba(255, 77, 109, 0.16) !important;
  border-color: rgba(255, 77, 109, 0.4) !important;
}

/* ──────────────────────────────────────────────
   EMOJI PICKER
────────────────────────────────────────────── */
.emoji-picker {
  position: absolute;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  display: flex;
  gap: 6px;
  z-index: 100;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: slideUp 0.15s ease;
  white-space: nowrap;
}
.emoji-picker button {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  border-radius: 6px;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), transform var(--transition);
}
.emoji-picker button:hover { background: var(--bg-hover); transform: scale(1.2); }

/* ──────────────────────────────────────────────
   REPLY BAR (above input)
────────────────────────────────────────────── */
.reply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border));
}
.reply-bar-content {
  flex: 1;
  background: var(--bg-elevated);
  border-left: 3px solid #dc2743;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 6px 12px;
}

/* ──────────────────────────────────────────────
   REQUEST BAR
────────────────────────────────────────────── */
.request-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  text-align: center;
}
.request-bar-text {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
}
.request-bar-btns {
  display: flex;
  gap: 12px;
}
.btn-approve {
  background: var(--text-primary);
  color: var(--bg-surface);
  border: none;
  padding: 8px 24px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-approve:hover { opacity: 0.9; }
.btn-decline {
  background: transparent;
  color: #ff4d6d;
  border: 1px solid rgba(255, 77, 109, 0.3);
  padding: 8px 24px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-decline:hover { background: rgba(255, 77, 109, 0.1); border-color: #ff4d6d; }

  font-size: 13px;
}
.reply-bar-label {
  color: #dc2743;
  font-weight: 600;
  font-size: 11px;
  margin-bottom: 2px;
}
.reply-bar-text {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px;
}
.reply-cancel {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  line-height: 1;
  transition: color var(--transition);
}
.reply-cancel:hover { color: var(--text-primary); }

/* ──────────────────────────────────────────────
   REPLY QUOTE (inside bubble)
────────────────────────────────────────────── */
.replied-to {
  background: rgba(255,255,255,0.07);
  border-left: 3px solid rgba(255,255,255,0.3);
  border-radius: 0 6px 6px 0;
  padding: 5px 10px;
  margin-bottom: 6px;
  font-size: 12px;
  color: rgba(255,255,255,0.65);
  cursor: default;
}
.theirs .replied-to {
  background: rgba(255,255,255,0.05);
  border-left-color: rgba(255,255,255,0.2);
  color: var(--text-muted);
}
.replied-to-name {
  font-weight: 600;
  font-size: 11px;
  margin-bottom: 2px;
}

/* ──────────────────────────────────────────────
   REACTIONS DISPLAY
────────────────────────────────────────────── */
.reactions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.mine .reactions-row {
  justify-content: flex-end;
}
.theirs .reactions-row {
  justify-content: flex-start;
}
.reaction-chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  transition: background var(--transition);
}
.reaction-chip:hover { background: var(--bg-hover); }
.reaction-chip span { font-size: 11px; color: var(--text-secondary); }

/* ──────────────────────────────────────────────
   MEDIA THUMBNAILS IN BUBBLES
────────────────────────────────────────────── */
.media-thumb-wrap {
  position: relative;
  display: block;
  cursor: pointer;
  border-radius: 12px;
  overflow: hidden;
  max-width: 260px;
  margin-bottom: 4px;
  background: var(--bg-elevated);
}
.media-thumb-wrap img {
  display: block;
  width: 100%;
  max-width: 260px;
  max-height: 260px;
  object-fit: cover;
  border-radius: 12px;
  transition: opacity 0.2s ease;
}
.media-thumb-wrap:hover img { opacity: 0.85; }
.media-thumb-wrap .media-play-icon {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 44px; height: 44px;
  background: rgba(0,0,0,0.55);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  pointer-events: none;
}

/* View-once / raven_media badge */
.media-thumb-wrap.view-once {
  border: 2px solid #833ab4;
  box-shadow: 0 0 12px rgba(131,58,180,0.4);
}
.view-once-badge {
  position: absolute;
  bottom: 8px; left: 50%;
  transform: translateX(-50%);
  background: rgba(131,58,180,0.85);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
  backdrop-filter: blur(4px);
  pointer-events: none;
}
.media-thumb-label {
  font-size: 12px;
  color: rgba(255,255,255,0.7);
  margin-top: 4px;
}
.mine .media-thumb-label { text-align: right; }

/* Bubble with media: no padding on top/sides */
.bubble.has-media {
  padding: 4px;
  background: transparent !important;
  border: none !important;
}
.bubble.has-media .media-thumb-wrap {
  border-radius: 14px;
}

/* ──────────────────────────────────────────────
   LIGHTBOX
────────────────────────────────────────────── */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.2s ease;
  cursor: zoom-out;
}
.lightbox img, .lightbox video {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: 0 20px 80px rgba(0,0,0,0.8);
  cursor: default;
  animation: slideUp 0.2s ease;
}
.lightbox-close {
  position: absolute;
  top: 20px; right: 24px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  font-size: 18px;
  width: 40px; height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);
}
.lightbox-close:hover { background: rgba(255,255,255,0.2); }

/* ──────────────────────────────────────────────
   ATTACHMENT BUTTON & MEDIA MENU
────────────────────────────────────────────── */
.attach-wrapper {
  position: relative;
  flex-shrink: 0;
}

.attach-btn {
  width: 42px; height: 42px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.attach-btn:hover { background: var(--bg-hover); color: var(--text-primary); transform: rotate(45deg); }
.attach-btn.open { transform: rotate(45deg); color: #dc2743; border-color: #dc2743; }

.media-menu {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 6px;
  min-width: 150px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: slideUp 0.15s ease;
  z-index: 50;
}
.media-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition);
}
.media-menu button:hover { background: var(--bg-hover); }
.media-menu button span { font-size: 18px; }

/* ──────────────────────────────────────────────
   VOICE RECORDING BAR
────────────────────────────────────────────── */
.voice-recording-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: rgba(220, 39, 67, 0.08);
  border-top: 1px solid rgba(220, 39, 67, 0.2);
}

.rec-dot {
  width: 10px; height: 10px;
  background: #dc2743;
  border-radius: 50%;
  animation: pulse-rec 1s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes pulse-rec {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.rec-label { font-size: 13px; color: #dc2743; font-weight: 500; }
.rec-timer { font-size: 13px; color: var(--text-secondary); font-variant-numeric: tabular-nums; flex: 1; }

.rec-stop-btn {
  display: flex; align-items: center; gap: 6px;
  background: #dc2743;
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  cursor: pointer;
  transition: opacity var(--transition);
}
.rec-stop-btn:hover { opacity: 0.85; }

.rec-cancel-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  transition: color var(--transition);
}
.rec-cancel-btn:hover { color: var(--text-primary); }

/* ──────────────────────────────────────────────
   MEDIA SENDING PROGRESS
────────────────────────────────────────────── */
.media-sending-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
}

/* ──────────────────────────────────────────────
   MESSAGE INPUT
────────────────────────────────────────────── */
.message-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

#message-input {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  padding: 11px 18px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 140px;
  overflow-y: auto;
  transition: border-color var(--transition);
}
#message-input:focus { border-color: #dc2743; }
#message-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 42px; height: 42px;
  background: var(--accent-grad);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: opacity var(--transition), transform var(--transition);
}
.send-btn:hover { opacity: 0.85; transform: scale(1.05); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.4; pointer-events: none; }

/* ──────────────────────────────────────────────
   LOADING / SPINNER
────────────────────────────────────────────── */
.loading-threads, .loading-messages {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  color: var(--text-muted);
  font-size: 13px;
}

.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--border-strong);
  border-top-color: #dc2743;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ──────────────────────────────────────────────
   UTILITIES
────────────────────────────────────────────── */
.hidden { display: none !important; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.bubble { animation: bubbleIn 0.18s ease; }

/* Skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-hover) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 8px;
}
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}


/* Scrollbar global */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* ──────────────────────────────────────────────
   PLAYABLE VOICE MESSAGES (VOCAUX) - CUSTOM PREMIUM PLAYER
────────────────────────────────────────────── */
.bubble.has-audio {
  padding: 12px 16px;
  min-width: 240px;
  max-width: 280px;
  background: var(--bubble-mine);
}
.theirs .bubble.has-audio {
  background: var(--bubble-theirs);
}
.voice-player-custom {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 2px 0;
}
.voice-play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  flex-shrink: 0;
  padding: 0;
}
.theirs .voice-play-btn {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}
.voice-play-btn:hover {
  background: rgba(255, 255, 255, 0.28);
  transform: scale(1.06);
}
.theirs .voice-play-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}
.voice-play-btn svg {
  width: 15px;
  height: 15px;
  fill: #fff;
  display: block;
}
.voice-progress-container {
  flex: 1;
  height: 5px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  position: relative;
  cursor: pointer;
}
.theirs .voice-progress-container {
  background: rgba(255, 255, 255, 0.2);
}
.voice-progress-bar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: #fff;
  border-radius: 3px;
  pointer-events: none;
  transition: width 0.1s linear;
}
.theirs .voice-progress-bar {
  background: #fff;
}

/* Seen receipt styling */
.seen-receipt {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  opacity: 0.85;
}
.theirs .seen-receipt {
  justify-content: flex-start;
  text-align: left;
}

/* ──────────────────────────────────────────────
   RESPONSIVE DESIGN (MOBILE-FIRST MASTER-DETAIL)
   ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px 8px 8px 0;
    margin-right: 8px;
    transition: transform var(--transition);
  }
  .back-btn:active {
    transform: scale(0.9);
  }
  .back-btn svg {
    display: block;
  }

  /* By default on mobile, show only sidebar */
  .sidebar {
    width: 100% !important;
    display: flex !important;
    border-right: none !important;
  }
  
  .chat-area {
    display: none !important;
  }

  /* When a chat is active, hide sidebar and show chat-area */
  #app.show-chat .sidebar {
    display: none !important;
  }

  #app.show-chat .chat-area {
    display: flex !important;
    width: 100% !important;
  }

  /* Chat header padding adjustments for mobile */
  .chat-header {
    padding: 12px 16px !important;
  }

  /* Messages max width adjustments on mobile to use screen space fully */
  .msg-row > div:not(.msg-avatar-sm) {
    max-width: 85% !important;
  }

  /* Safe zones at the bottom of modern mobile screens (gestures, notch safe-areas) */
  .message-input-area {
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 16px)) !important;
  }
  .voice-recording-bar {
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 16px)) !important;
  }
  .thread-list {
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 16px)) !important;
  }

  /* Block lateral horizontal swiping / scrolling entirely */
  .messages-container {
    overflow-x: hidden !important;
  }
  .chat-area {
    overflow-x: hidden !important;
  }

  /* Reposition message actions to float vertically centered and slightly overlapping the bubble edge on mobile to avoid cutting off and hover loss */
  .msg-actions {
    z-index: 100 !important;
  }
  .msg-row.mine .msg-actions {
    left: -32px !important;
    right: auto !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
  }
  .msg-row.theirs .msg-actions {
    right: -32px !important;
    left: auto !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
  }
}

/* Hide back button on desktop */
@media (min-width: 769px) {
  .back-btn {
    display: none !important;
  }
}
