/* ===== RESET & VARIABLES ===== */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --brand: #f97316;
  --brand-rgb: 249, 115, 22;
  --brand-dark: #c2410c;
  --brand-light: #fff7ed;
  --brand-grad: linear-gradient(135deg, #fb923c 0%, #f97316 55%, #ea580c 100%);
  --text: #0f1419;
  --text-2: #536471;
  --text-3: #8b98a5;
  --border: #eff3f4;
  --hover: rgba(0, 0, 0, 0.03);
  --bg: #ffffff;
  --bg-soft: #f7f9f9;
  --bg-card: #f4f6f7;
  --chat-bg: #f6f3ef;
  --recv: #ffffff;
  --shadow: rgba(0, 0, 0, 0.08);
  --success: #16a34a;
  --danger: #dc2626;
  --blue: #1e88e5;
  --pink: #e11d48;
  --purple: #8e24aa;
  --overlay: rgba(15, 20, 25, 0.5);
  --spring: cubic-bezier(.34, 1.4, .64, 1);
  --ease: cubic-bezier(.22, 1, .36, 1);
}

html[data-accent="blue"] {
  --brand: #2563eb; --brand-rgb: 37, 99, 235; --brand-dark: #1d4ed8; --brand-light: #eff6ff;
  --brand-grad: linear-gradient(135deg, #60a5fa 0%, #3b82f6 55%, #2563eb 100%);
  --chat-bg: #f1f5fb;
}
html[data-accent="green"] {
  --brand: #16a34a; --brand-rgb: 22, 163, 74; --brand-dark: #15803d; --brand-light: #f0fdf4;
  --brand-grad: linear-gradient(135deg, #4ade80 0%, #22c55e 55%, #16a34a 100%);
  --chat-bg: #f0f7f2;
}

html[data-theme="dark"] {
  --text: #e7e9ea;
  --text-2: #8b949b;
  --text-3: #71767b;
  --border: #2f3336;
  --hover: rgba(255, 255, 255, 0.04);
  --bg: #000000;
  --bg-soft: #16181c;
  --bg-card: #16181c;
  --chat-bg: #0b0b0d;
  --recv: #1c1e22;
  --brand-light: #2a1a08;
  --brand-dark: #fb923c;
  --shadow: rgba(0, 0, 0, 0.5);
  --overlay: rgba(0, 0, 0, 0.7);
}
html[data-theme="dark"][data-accent="blue"] { --brand-light: #0c1a33; --brand-dark: #60a5fa; --chat-bg: #090b10; }
html[data-theme="dark"][data-accent="green"] { --brand-light: #0a2415; --brand-dark: #4ade80; --chat-bg: #080c09; }

html, body { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .25s ease, color .25s ease;
}

.conv-messages, .notif-item, .conv-item, .bubble, .newchat-user, .msg-wrapper {
  -webkit-user-select: none; -moz-user-select: none; user-select: none;
}
input, textarea { -webkit-user-select: text; -moz-user-select: text; user-select: text; }
button { font-family: inherit; cursor: pointer; }

/* ===== SPINNER ===== */
.spinner {
  width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== PAGE PRINCIPALE ===== */
.app-page {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  max-width: 640px; margin: 0 auto; width: 100%; position: relative;
}
.app-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 10px 18px; flex-shrink: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  z-index: 20;
}
.app-title { font-size: 26px; font-weight: 800; letter-spacing: -0.6px; color: var(--text); }
.app-topbar-actions { display: flex; align-items: center; gap: 2px; }
.app-icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; color: var(--text);
  display: flex; align-items: center; justify-content: center; font-size: 16px; transition: background .15s, transform .15s;
}
.app-icon-btn:hover { background: var(--hover); }
.app-icon-btn:active { transform: scale(.9); }
.app-icon-btn.spinning i { animation: spin .8s linear infinite; }
#markAllBtn { color: var(--brand); }

/* ===== ONGLETS ===== */
.app-tabs { display: flex; padding: 4px 12px 8px; gap: 6px; flex-shrink: 0; background: var(--bg); }
.app-tab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: transparent; border: 0; border-radius: 100px; padding: 10px 8px;
  font-size: 15px; font-weight: 600; color: var(--text-2); transition: color .15s, background .15s;
}
.app-tab.active { color: var(--text); font-weight: 800; background: var(--bg-card); }
.app-tab-badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px;
  padding: 0 6px; border-radius: 100px; background: var(--pink); color: #fff; font-size: 11px; font-weight: 800;
  animation: badgePop .3s var(--spring);
}
@keyframes badgePop { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.app-page-content {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 100px; overscroll-behavior: contain;
}

/* ===== FILTRES (activité + messages) ===== */
.filters-scroll {
  display: flex; gap: 8px; overflow-x: auto; padding: 8px 16px 10px; scrollbar-width: none;
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.filters-scroll::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 7px; background: var(--bg-card);
  border: 1px solid transparent; color: var(--text); font-size: 13px; font-weight: 700;
  padding: 8px 14px; border-radius: 14px; transition: all .15s; white-space: nowrap;
}
.filter-chip i { font-size: 13px; line-height: 1; }
.filter-chip:active { transform: scale(.96); }
.filter-chip.active { background: var(--brand-grad); color: #fff; box-shadow: 0 4px 14px rgba(var(--brand-rgb), .35); }
.filter-chip.active i { color: #fff !important; }
.filter-count {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px;
  padding: 0 5px; border-radius: 100px; background: rgba(0, 0, 0, 0.08); color: inherit; font-size: 11px; font-weight: 800;
}
.filter-chip.active .filter-count { background: rgba(255, 255, 255, 0.25); }
.filter-count:empty { display: none; }

.conv-head-sticky { position: sticky; top: 0; z-index: 6; background: var(--bg); }
.msg-filters { position: static; padding-top: 2px; }

/* ===== NOTIFICATIONS ===== */
.notif-list { padding: 4px 10px 0; }
.notif-loading, .notif-empty {
  text-align: center; padding: 60px 20px; color: var(--text-3); font-size: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.notif-empty-icon { font-size: 44px; opacity: .5; }
.notif-item {
  display: flex; gap: 12px; padding: 12px; margin-bottom: 4px; border-radius: 18px;
  transition: background .12s, transform .12s; position: relative; align-items: flex-start;
  animation: notifIn .3s var(--ease) both; cursor: pointer;
}
@keyframes notifIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.notif-item:hover { background: var(--hover); }
.notif-item:active { transform: scale(.985); }
.notif-item.unread { background: rgba(var(--brand-rgb), .09); }
.notif-item.unread::before {
  content: ""; position: absolute; left: 2px; top: 50%; transform: translateY(-50%);
  width: 6px; height: 6px; border-radius: 50%; background: var(--brand);
}
.notif-avatar-wrap { position: relative; flex-shrink: 0; }
.notif-avatar {
  width: 48px; height: 48px; border-radius: 50%; overflow: hidden;
  background: var(--brand-grad); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 18px; flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px rgba(var(--brand-rgb), .3);
}
.notif-avatar.icon { background: var(--bg-card); color: var(--text-3); box-shadow: 0 0 0 1px var(--border); font-size: 20px; }
.notif-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.notif-type-badge {
  position: absolute; bottom: -3px; right: -3px; width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--bg); display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .2);
}
.notif-type-badge.like { background: var(--pink); }
.notif-type-badge.comment { background: var(--blue); }
.notif-type-badge.repost { background: var(--success); }
.notif-type-badge.follow { background: var(--brand); }
.notif-type-badge.mention { background: var(--purple); }
.notif-type-badge.default { background: var(--text-2); }
.notif-body { flex: 1; min-width: 0; padding-top: 2px; }
.notif-name-line { font-size: 14.5px; font-weight: 700; color: var(--text); line-height: 1.3; word-wrap: break-word; }
.notif-action-line { font-size: 14px; color: var(--text-2); line-height: 1.35; word-wrap: break-word; margin-top: 2px; }
.notif-extra {
  margin-top: 6px; padding: 7px 10px; border-radius: 12px; background: var(--bg-card);
  font-size: 13.5px; color: var(--text); line-height: 1.35; word-wrap: break-word;
  border-left: 3px solid var(--brand);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.notif-time { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.notif-thumb { width: 44px; height: 44px; border-radius: 10px; overflow: hidden; flex-shrink: 0; background: var(--bg-card); align-self: center; }
.notif-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.notif-follow-btn {
  align-self: center; border: 0; background: var(--brand-grad); color: #fff; padding: 8px 16px;
  border-radius: 100px; font-size: 13px; font-weight: 700; flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(var(--brand-rgb), .3); transition: opacity .15s, transform .15s;
}
.notif-follow-btn:active { transform: scale(.94); }
.notif-follow-btn:disabled { opacity: .5; cursor: not-allowed; }
.notif-follow-btn.following { background: var(--bg-card); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }

/* ===== LISTE DES CONVERSATIONS ===== */
.conv-search-wrap { padding: 6px 16px 4px; }
.conv-search {
  display: flex; align-items: center; gap: 10px; background: var(--bg-card); border-radius: 100px;
  padding: 11px 16px; box-shadow: inset 0 0 0 1px var(--border);
}
.conv-search i { color: var(--text-3); font-size: 14px; flex-shrink: 0; }
.conv-search input { flex: 1; border: 0; outline: 0; background: transparent; font-size: 14px; color: var(--text); min-width: 0; }
.conv-search input::placeholder { color: var(--text-3); }

.conv-list { padding: 4px 10px; }
.conv-loading, .conv-empty {
  text-align: center; padding: 60px 20px; color: var(--text-3); font-size: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.conv-item {
  display: flex; gap: 12px; padding: 12px; margin-bottom: 2px; border-radius: 18px;
  transition: background .12s, transform .12s; align-items: center; cursor: pointer;
}
.conv-item:hover { background: var(--hover); }
.conv-item:active { transform: scale(.985); }
.conv-item.unread { background: rgba(var(--brand-rgb), .08); }
.conv-item.unread .conv-preview { color: var(--text); font-weight: 600; }
.conv-item.unread .conv-name { font-weight: 800; }
.conv-item.unread .conv-time { color: var(--brand); font-weight: 700; }

.conv-avatar-wrap { position: relative; flex-shrink: 0; }
.conv-avatar {
  width: 54px; height: 54px; border-radius: 50%; overflow: hidden; background: var(--brand-grad); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 20px;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px rgba(var(--brand-rgb), .3);
}
.conv-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.online-dot {
  position: absolute; bottom: 2px; right: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #22c55e; border: 3px solid var(--bg); display: none;
}
.online-dot.active { display: block; }
.conv-body { flex: 1; min-width: 0; }
.conv-name-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.conv-name { font-size: 15px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.conv-time { font-size: 12px; color: var(--text-3); flex-shrink: 0; }
.conv-preview { font-size: 13.5px; color: var(--text-2); display: flex; align-items: center; gap: 8px; min-width: 0; }
.conv-preview-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-badge {
  background: var(--brand-grad); color: #fff; font-size: 11.5px; font-weight: 800; min-width: 22px; height: 22px;
  padding: 0 7px; border-radius: 100px; display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; box-shadow: 0 2px 8px rgba(var(--brand-rgb), .4);
}

/* ===== FAB ===== */
.fab-new {
  position: fixed; bottom: 96px; right: 20px; width: 58px; height: 58px; border-radius: 20px;
  background: var(--brand-grad); color: #fff; border: 0; display: flex; align-items: center; justify-content: center;
  font-size: 20px; box-shadow: 0 8px 22px rgba(var(--brand-rgb), .45); z-index: 40; transition: transform .2s var(--spring);
}
.fab-new:hover { transform: scale(1.06); }
.fab-new:active { transform: scale(.92); }

/* ===== NAV BASSE ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); display: flex; width: 100%; max-width: 640px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  box-shadow: 0 -1px 0 var(--border), 0 -8px 24px rgba(0, 0, 0, .04);
  padding: 6px 0 max(6px, env(safe-area-inset-bottom)); z-index: 60;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; text-decoration: none;
  color: var(--text-2); font-size: 10px; font-weight: 600; padding: 4px 0; transition: color .12s;
}
.nav-item svg { stroke: currentColor; transition: transform .15s; }
.nav-item:active svg { transform: scale(.88); }
.nav-item.active { color: var(--brand); }
.nav-icon-wrap { position: relative; display: flex; align-items: center; justify-content: center; }
.nav-badge {
  position: absolute; top: -6px; right: -8px; background: var(--pink); color: #fff; font-size: 9px; font-weight: 800;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 100px; display: inline-flex;
  align-items: center; justify-content: center; border: 2px solid var(--bg); animation: badgePop .3s var(--spring);
}

/* ===== VUE CONVERSATION ===== */
.conv-view {
  position: fixed; inset: 0; z-index: 200; display: none; flex-direction: column;
  background: radial-gradient(circle at 15% 0%, rgba(var(--brand-rgb), .08), transparent 45%), var(--chat-bg);
}
.conv-view.open { display: flex; animation: convSlideIn .28s var(--ease); }
@keyframes convSlideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.conv-header {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  box-shadow: 0 1px 0 var(--border); flex-shrink: 0; max-width: 640px; margin: 0 auto; width: 100%; z-index: 3;
}
.conv-back, .conv-more {
  width: 40px; height: 40px; border-radius: 50%; background: transparent; border: 0; color: var(--text);
  display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; transition: background .15s;
}
.conv-back:hover, .conv-more:hover { background: var(--hover); }
.conv-header .conv-avatar-wrap { cursor: pointer; }
.conv-header .conv-avatar { width: 42px; height: 42px; font-size: 16px; box-shadow: none; }
.conv-header .online-dot { width: 12px; height: 12px; border-width: 2px; }
.conv-header-info { flex: 1; min-width: 0; }
.conv-header-name { font-size: 16px; font-weight: 800; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; }
.conv-header-status { font-size: 12px; color: var(--text-2); margin-top: 1px; line-height: 1.2; }
.conv-header-status.online { color: var(--success); font-weight: 600; }
.conv-header-status.typing { color: var(--brand); font-weight: 600; }

/* ===== ZONE MESSAGES ===== */
.conv-stage { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; max-width: 640px; margin: 0 auto; width: 100%; }
.conv-messages {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 14px 12px; display: flex; flex-direction: column; gap: 3px; overscroll-behavior: contain;
}
.conv-messages > .conv-loading { padding: 40px 20px; display: block; }

.chat-empty-state { margin: auto; text-align: center; color: var(--text-2); font-size: 14px; padding: 30px 20px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.chat-empty-state .ces-avatar {
  width: 84px; height: 84px; border-radius: 50%; overflow: hidden; display: flex; align-items: center; justify-content: center;
  background: var(--brand-grad); color: #fff; font-size: 30px; font-weight: 800; box-shadow: 0 8px 24px rgba(var(--brand-rgb), .3);
}
.chat-empty-state .ces-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-empty-state strong { color: var(--text); font-size: 17px; }

.date-separator { text-align: center; margin: 14px 0 6px; }
.date-separator span {
  display: inline-block; padding: 5px 14px; font-size: 11.5px; color: var(--text-3);
  background: color-mix(in srgb, var(--bg) 75%, transparent); backdrop-filter: blur(8px);
  box-shadow: 0 1px 0 var(--border); border-radius: 100px; font-weight: 600;
}

.scroll-down {
  position: absolute; right: 14px; bottom: 12px; width: 42px; height: 42px; border-radius: 50%;
  border: 0; background: var(--bg); color: var(--text); font-size: 15px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18), 0 0 0 1px var(--border);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: scale(.6) translateY(10px); pointer-events: none;
  transition: opacity .2s, transform .25s var(--spring); z-index: 5;
}
.scroll-down.show { opacity: 1; transform: none; pointer-events: auto; }
.scroll-down-badge {
  position: absolute; top: -7px; right: -4px; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 100px;
  background: var(--brand-grad); color: #fff; font-size: 11px; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ===== MESSAGES ===== */
.msg-wrapper { position: relative; display: flex; width: 100%; overflow: visible; align-items: flex-start; margin-top: 8px; }
.msg-wrapper.grp { margin-top: 0; }
.msg-wrapper.sent { justify-content: flex-end; }
.msg-wrapper.received { justify-content: flex-start; }
.msg-wrapper.flash .bubble { animation: flashBubble 1.2s ease; }
@keyframes flashBubble { 0%, 100% { filter: none; } 30% { filter: brightness(1.15) saturate(1.2); box-shadow: 0 0 0 3px rgba(var(--brand-rgb), .45); } }

.msg-swipe-icon {
  position: absolute; top: 50%; transform: translateY(-50%) scale(.6); opacity: 0; color: var(--brand); font-size: 18px;
  transition: opacity .15s ease, transform .15s ease; pointer-events: none; z-index: 1;
}
.msg-wrapper.received .msg-swipe-icon { left: 10px; }
.msg-wrapper.sent .msg-swipe-icon { right: 10px; }
.msg-swipe-icon.visible { opacity: 1; transform: translateY(-50%) scale(1); }

.msg-row { display: flex; flex-direction: column; max-width: 80%; transition: transform .2s var(--ease); position: relative; z-index: 2; }
.msg-row.sent { align-items: flex-end; }
.msg-row.received { align-items: flex-start; }

.bubble-wrap { position: relative; width: fit-content; max-width: 100%; }
.bubble-wrap.has-reactions { margin-bottom: 16px; }

.bubble {
  padding: 8px 12px 6px; border-radius: 20px; font-size: 15px; line-height: 1.4; word-wrap: break-word;
  overflow-wrap: anywhere; position: relative; cursor: pointer; transition: transform .12s;
  width: fit-content; max-width: 100%; min-width: 64px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  animation: bubbleIn .28s var(--spring);
}
@keyframes bubbleIn { from { transform: scale(.88) translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }
.bubble:active { transform: scale(.985); }
.bubble.sending { opacity: .7; }
.bubble.has-embed { width: 290px; max-width: 100%; }

.msg-row.received .bubble { background: var(--recv); color: var(--text); border-bottom-left-radius: 6px; box-shadow: 0 0 0 1px var(--border), 0 2px 8px rgba(0, 0, 0, .03); }
.msg-row.sent .bubble { background: var(--brand-grad); color: #fff; border-bottom-right-radius: 6px; box-shadow: 0 4px 14px rgba(var(--brand-rgb), .28); }
.msg-wrapper.sent.grp .bubble { border-top-right-radius: 7px; }
.msg-wrapper.received.grp .bubble { border-top-left-radius: 7px; }
.bubble.failed { background: var(--danger) !important; color: #fff !important; }

.bubble-text { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.bubble-text a.msg-link, .bubble-text a.msg-mention { text-decoration: underline; text-underline-offset: 2px; word-break: break-all; font-weight: 600; }
.msg-row.sent .bubble-text a { color: #fff; text-decoration-color: rgba(255, 255, 255, .6); }
.msg-row.received .bubble-text a { color: var(--brand); text-decoration-color: rgba(var(--brand-rgb), .5); }

.bubble-meta { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 2px; font-size: 10.5px; line-height: 1; opacity: .72; min-height: 12px; }
.msg-row.received .bubble-meta { color: var(--text-2); }
.bubble-meta .msg-status-icon { display: inline-flex; align-items: center; }
.bubble-meta .msg-status-icon i { font-size: 10.5px; }
.bubble-meta .msg-edited-tag { font-style: italic; margin-right: 2px; }
.bubble-meta .read { opacity: 1; color: #fff; }

.bubble.has-image { padding: 3px; }
.bubble.has-image .bubble-meta {
  position: absolute; right: 9px; bottom: 8px; margin: 0; padding: 3px 7px; border-radius: 100px;
  background: rgba(0, 0, 0, .45); color: #fff; opacity: 1;
}
.bubble-image { border-radius: 17px; overflow: hidden; max-width: 260px; cursor: pointer; }
.bubble-image img { width: 100%; display: block; max-height: 340px; object-fit: cover; }

/* ----- Réponse citée (moderne) ----- */
.bubble-reply-quote {
  position: relative; display: flex; align-items: stretch; gap: 8px; padding: 7px 10px 7px 14px; margin: 0 0 7px;
  border-radius: 12px; background: rgba(0, 0, 0, .07); overflow: hidden; cursor: pointer; max-width: 100%;
  transition: background .15s;
}
.bubble-reply-quote::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--brand); }
.msg-row.sent .bubble-reply-quote { background: rgba(255, 255, 255, .2); }
.msg-row.sent .bubble-reply-quote::before { background: #fff; }
.bubble-reply-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.bubble-reply-name { font-weight: 800; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--brand); }
.msg-row.sent .bubble-reply-name { color: #fff; }
.bubble-reply-text { font-size: 13px; line-height: 1.3; opacity: .88; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-wrap: break-word; }
.bubble-reply-thumb { width: 38px; height: 38px; border-radius: 8px; overflow: hidden; flex-shrink: 0; background: rgba(0, 0, 0, .1); }
.bubble-reply-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ----- Embeds : YouTube, images, aperçus de liens ----- */
.msg-embed { display: block; margin-top: 7px; border-radius: 14px; overflow: hidden; position: relative; text-decoration: none; color: inherit; }
.yt-embed { background: #000; }
.yt-frame { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; cursor: pointer; overflow: hidden; }
.yt-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.yt-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.yt-play {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 54px; height: 38px; border-radius: 12px;
  background: #ff0000; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4); transition: transform .15s var(--spring);
}
.yt-frame:hover .yt-play { transform: translate(-50%, -50%) scale(1.1); }
.yt-badge {
  position: absolute; left: 8px; top: 8px; background: rgba(0, 0, 0, .6); color: #fff; font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 100px; display: inline-flex; align-items: center; gap: 5px;
}
.yt-badge i { color: #ff3b3b; }
.yt-open {
  display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px; font-size: 12px; font-weight: 700;
  background: rgba(0, 0, 0, .85); color: #fff; text-decoration: none;
}
.img-embed { cursor: pointer; background: rgba(0, 0, 0, .06); }
.img-embed img { width: 100%; display: block; max-height: 300px; object-fit: cover; }
.vid-embed video { width: 100%; display: block; max-height: 300px; background: #000; border-radius: 14px; }

.link-card { background: rgba(0, 0, 0, .06); border: 1px solid rgba(0, 0, 0, .06); }
.msg-row.sent .link-card { background: rgba(255, 255, 255, .18); border-color: rgba(255, 255, 255, .25); }
.lc-img { width: 100%; max-height: 150px; object-fit: cover; display: block; }
.lc-body { padding: 8px 11px 9px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lc-title { font-size: 13.5px; font-weight: 800; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lc-desc { font-size: 12.5px; opacity: .85; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lc-url { font-size: 11.5px; opacity: .65; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-card.social { display: flex; align-items: center; gap: 10px; padding: 9px 11px; }
.lc-icon {
  width: 38px; height: 38px; border-radius: 11px; background: var(--brand-grad); color: #fff; font-weight: 800; font-size: 14px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.link-card.social .lc-body { padding: 0; }

/* ----- Réactions ----- */
.msg-reactions { position: absolute; bottom: -14px; display: flex; gap: 3px; z-index: 3; }
.msg-row.sent .msg-reactions { right: 8px; }
.msg-row.received .msg-reactions { left: 8px; }
.msg-reaction-pill {
  display: inline-flex; align-items: center; gap: 3px; background: var(--bg); border: 1.5px solid var(--bg);
  border-radius: 100px; padding: 2px 7px 2px 6px; line-height: 1; cursor: pointer; color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18), 0 0 0 1px var(--border); animation: bubbleIn .25s var(--spring);
}
.msg-reaction-pill .emo { font-size: 14px; }
.msg-reaction-pill .cnt { font-size: 11px; font-weight: 800; }
.msg-reaction-pill.mine { background: var(--brand-light); box-shadow: 0 2px 8px rgba(var(--brand-rgb), .25), 0 0 0 1.5px var(--brand); }
.msg-reaction-pill.mine .cnt { color: var(--brand); }

/* ----- Compact ----- */
body.compact .bubble { padding: 6px 10px 5px; font-size: 14px; border-radius: 16px; }
body.compact .msg-wrapper { margin-top: 5px; }
body.compact .msg-wrapper.grp { margin-top: 0; }
body.compact .bubble-meta { font-size: 10px; }

/* ===== BARRE DE RÉPONSE (au-dessus de la saisie) ===== */
.reply-preview-bar {
  display: none; align-items: center; gap: 10px; padding: 9px 10px 9px 16px; margin: 0 12px; background: var(--bg);
  border-radius: 16px; box-shadow: 0 0 0 1px var(--border), 0 6px 20px rgba(0, 0, 0, .08); position: relative; overflow: hidden;
  max-width: 616px; width: calc(100% - 24px); align-self: center; animation: slideUpReply .22s var(--ease);
}
.reply-preview-bar::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--brand-grad); }
.reply-preview-bar.active { display: flex; }
@keyframes slideUpReply { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.reply-preview-icon { color: var(--brand); font-size: 15px; flex-shrink: 0; }
.reply-preview-content { flex: 1; min-width: 0; }
.reply-preview-name { font-size: 12.5px; font-weight: 800; color: var(--brand); margin-bottom: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-preview-text { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-preview-thumb { width: 40px; height: 40px; border-radius: 10px; overflow: hidden; flex-shrink: 0; background: var(--bg-card); }
.reply-preview-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.reply-preview-close {
  width: 30px; height: 30px; border-radius: 50%; border: 0; background: var(--bg-card); color: var(--text-2);
  display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; transition: transform .15s;
}
.reply-preview-close:active { transform: scale(.88); }

/* ===== TYPING ===== */
.conv-typing { padding: 4px 20px 6px; font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 8px; max-width: 640px; margin: 0 auto; width: 100%; flex-shrink: 0; }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: typingBounce 1.2s infinite ease-in-out; }
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes typingBounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ===== SAISIE ===== */
.conv-input-bar { display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); background: transparent; flex-shrink: 0; max-width: 640px; margin: 0 auto; width: 100%; }
.conv-attach {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--bg); box-shadow: 0 0 0 1px var(--border);
  color: var(--text-2); display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; transition: background .15s, color .15s;
}
.conv-attach:hover { background: var(--brand-light); color: var(--brand); }
#convTextInput {
  flex: 1; border: 0; outline: 0; background: var(--bg); border-radius: 24px; padding: 11px 18px; font-size: 15px;
  color: var(--text); font-family: inherit; resize: none; max-height: 120px; line-height: 1.4; min-width: 0;
  box-shadow: 0 0 0 1px var(--border), 0 4px 16px rgba(0, 0, 0, .06); transition: box-shadow .15s;
}
#convTextInput::placeholder { color: var(--text-3); }
#convTextInput:focus { box-shadow: 0 0 0 2px var(--brand), 0 4px 16px rgba(var(--brand-rgb), .15); }
.conv-send {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--brand-grad); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(var(--brand-rgb), .4); transition: transform .2s var(--spring), opacity .15s;
}
.conv-send:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.conv-send:not(:disabled):active { transform: scale(.88); }

/* ===== SHEETS ===== */
.sheet-overlay {
  display: none; position: fixed; inset: 0; background: var(--overlay); z-index: 300; align-items: flex-end;
  justify-content: center; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: fadeIn .2s ease;
}
.sheet-overlay.open { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sheet-box {
  background: var(--bg); width: 100%; max-width: 520px; max-height: 88vh; border-radius: 26px 26px 0 0;
  display: flex; flex-direction: column; overflow: hidden; animation: sheetUp .28s var(--ease);
  padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -10px 40px rgba(0, 0, 0, .2);
}
@keyframes sheetUp { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 4px; background: var(--border); margin: 10px auto 6px; flex-shrink: 0; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; padding: 6px 18px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sheet-header h2 { font-size: 17px; font-weight: 800; color: var(--text); }
.sheet-close { width: 34px; height: 34px; border-radius: 50%; border: 0; background: transparent; color: var(--text); display: flex; align-items: center; justify-content: center; font-size: 16px; }
.sheet-close:hover { background: var(--hover); }
.sheet-body { padding: 0 0 8px; overflow-y: auto; }

.msg-sheet .reactions-strip { display: flex; justify-content: space-between; gap: 4px; padding: 10px 14px 12px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.msg-sheet .reactions-strip::-webkit-scrollbar { display: none; }
.reaction-btn { flex-shrink: 0; width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent; font-size: 26px; display: flex; align-items: center; justify-content: center; transition: transform .2s var(--spring); }
.reaction-btn:hover, .reaction-btn:active { transform: scale(1.3) translateY(-4px); }
.msg-action-item, .conv-option {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; font-size: 15px; font-weight: 600; color: var(--text);
  border: 0; background: var(--bg); width: calc(100% - 16px); margin: 2px 8px; border-radius: 14px; text-align: left; transition: background .12s;
}
.msg-action-item:hover, .conv-option:hover { background: var(--hover); }
.msg-action-item i, .conv-option i { width: 22px; font-size: 16px; color: var(--text-2); text-align: center; flex-shrink: 0; }
.msg-action-item.danger, .conv-option.danger { color: var(--danger); }
.msg-action-item.danger i, .conv-option.danger i { color: var(--danger); }

/* ===== PARAMÈTRES ===== */
.settings-body { padding: 6px 16px 18px; }
.settings-block { margin-top: 14px; }
.settings-label { font-size: 12px; font-weight: 800; letter-spacing: .5px; text-transform: uppercase; color: var(--text-3); margin-bottom: 8px; }
.accent-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.accent-opt {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 8px 12px;
  border-radius: 18px; border: 2px solid var(--border); background: var(--bg-card); color: var(--text); font-weight: 700; font-size: 13px;
  transition: transform .15s var(--spring), border-color .15s, box-shadow .15s;
}
.accent-opt:active { transform: scale(.95); }
.accent-dot { width: 40px; height: 40px; border-radius: 50%; box-shadow: 0 6px 16px rgba(0, 0, 0, .2); }
.accent-opt i { position: absolute; top: 8px; right: 8px; font-size: 16px; color: var(--brand); opacity: 0; transform: scale(.5); transition: all .2s var(--spring); }
.accent-opt.active { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(var(--brand-rgb), .18); }
.accent-opt.active i { opacity: 1; transform: scale(1); }
.seg { display: flex; padding: 4px; gap: 4px; border-radius: 16px; background: var(--bg-card); }
.seg-btn { flex: 1; border: 0; background: transparent; color: var(--text-2); font-weight: 700; font-size: 14px; padding: 10px; border-radius: 12px; display: flex; align-items: center; justify-content: center; gap: 8px; transition: all .15s; }
.seg-btn.active { background: var(--bg); color: var(--brand); box-shadow: 0 2px 8px rgba(0, 0, 0, .1); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.setting-row:last-of-type { border-bottom: 0; }
.setting-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.setting-text b { font-size: 14.5px; color: var(--text); }
.setting-text small { font-size: 12.5px; color: var(--text-3); line-height: 1.3; }
input.switch {
  appearance: none; -webkit-appearance: none; flex-shrink: 0; width: 48px; height: 28px; border-radius: 100px;
  background: var(--border); position: relative; outline: 0; transition: background .2s; cursor: pointer;
}
input.switch::before {
  content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .3); transition: transform .22s var(--spring);
}
input.switch:checked { background: var(--brand); }
input.switch:checked::before { transform: translateX(20px); }
.settings-reset {
  width: 100%; margin-top: 16px; padding: 13px; border-radius: 14px; border: 0; background: var(--bg-card);
  color: var(--text-2); font-weight: 700; font-size: 14px; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.settings-reset:active { transform: scale(.98); }

/* ===== NOUVELLE CONVERSATION ===== */
.newchat-search { display: flex; align-items: center; gap: 10px; background: var(--bg-card); border-radius: 100px; padding: 11px 16px; margin: 14px 16px 10px; }
.newchat-search i { color: var(--text-3); font-size: 14px; flex-shrink: 0; }
.newchat-search input { flex: 1; border: 0; outline: 0; background: transparent; font-size: 15px; color: var(--text); min-width: 0; }
.newchat-search input::placeholder { color: var(--text-3); }
.newchat-tabs { display: flex; gap: 8px; padding: 0 16px 12px; overflow-x: auto; scrollbar-width: none; }
.newchat-tabs::-webkit-scrollbar { display: none; }
.newchat-tab {
  flex-shrink: 0; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 13px; font-weight: 700;
  padding: 7px 14px; border-radius: 100px; transition: all .15s; white-space: nowrap; display: inline-flex; align-items: center; gap: 7px;
}
.newchat-tab.active { background: var(--brand-grad); color: #fff; border-color: transparent; }
.newchat-results { padding: 0 0 12px; min-height: 200px; max-height: 50vh; overflow-y: auto; }
.newchat-empty { text-align: center; padding: 50px 20px; color: var(--text-3); font-size: 14px; line-height: 1.4; }
.newchat-empty i { font-size: 32px; opacity: .4; display: block; margin-bottom: 12px; }
.newchat-note { margin: 0 16px 8px; padding: 9px 12px; border-radius: 12px; background: var(--brand-light); color: var(--brand); font-size: 12.5px; font-weight: 600; }
.newchat-user { display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin: 0 8px; border-radius: 14px; transition: background .12s; cursor: pointer; }
.newchat-user:hover { background: var(--hover); }
.newchat-user-avatar { width: 46px; height: 46px; border-radius: 50%; overflow: hidden; background: var(--brand-grad); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 17px; flex-shrink: 0; }
.newchat-user-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.newchat-user-info { flex: 1; min-width: 0; }
.newchat-user-name { font-size: 14.5px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 4px; }
.newchat-user-handle { font-size: 13px; color: var(--text-2); margin-top: 1px; }
.newchat-user-arrow { color: var(--text-3); font-size: 14px; flex-shrink: 0; }

/* ===== IMAGE VIEWER ===== */
.img-viewer { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, .94); z-index: 400; align-items: center; justify-content: center; padding: 16px; }
.img-viewer.open { display: flex; animation: fadeIn .2s ease; }
.img-viewer img { max-width: 100%; max-height: 92vh; object-fit: contain; border-radius: 4px; animation: zoomIn .25s var(--ease); }
@keyframes zoomIn { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.img-viewer-close {
  position: absolute; top: max(16px, env(safe-area-inset-top)); right: 16px; width: 42px; height: 42px; border-radius: 50%;
  background: rgba(255, 255, 255, .15); border: 0; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 18px;
}

/* ===== TOASTS ===== */
.toast-container { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 500; display: flex; flex-direction: column; gap: 8px; width: calc(100% - 32px); max-width: 380px; pointer-events: none; }
.toast { padding: 12px 16px; border-radius: 14px; font-size: 13.5px; font-weight: 600; color: #fff; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); pointer-events: auto; animation: toastIn .25s var(--ease); }
@keyframes toastIn { from { transform: translateY(-10px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--text); color: var(--bg); }

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  .app-title { font-size: 24px; }
  .conv-avatar { width: 50px; height: 50px; font-size: 18px; }
  .notif-avatar { width: 44px; height: 44px; font-size: 16px; }
  .notif-thumb { width: 40px; height: 40px; }
  .msg-row { max-width: 86%; }
  .bubble.has-embed { width: min(290px, 100%); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ===== SCROLLBAR ===== */
.conv-messages::-webkit-scrollbar, .app-page-content::-webkit-scrollbar, .newchat-results::-webkit-scrollbar { width: 6px; }
.conv-messages::-webkit-scrollbar-track, .app-page-content::-webkit-scrollbar-track, .newchat-results::-webkit-scrollbar-track { background: transparent; }
.conv-messages::-webkit-scrollbar-thumb, .app-page-content::-webkit-scrollbar-thumb, .newchat-results::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== BADGE CERTIFICATION ===== */
.cert-badge { display: inline-flex; align-items: center; flex-shrink: 0; color: #1d9bf0; margin-left: 4px; line-height: 0; }
.cert-badge svg { width: 17px; height: 17px; display: block; }
.conv-name { display: flex; align-items: center; }
.conv-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.conv-header-name { display: flex; align-items: center; }
.newchat-user-name .cert-badge { margin-left: 2px; }
