/* ============================================================
   TELEGRAM CLONE — Design raffiné
   fond #0e1621, sidebar #17212b, bulles sortantes #2b5278
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --sidebar-bg: #17212b;
  --sidebar-bg-2: #1e2a36;
  --sidebar-hover: #1d2936;
  --sidebar-active: #2b5278;
  --chat-bg: #0e1621;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --accent: #3e99f0;
  --accent-dark: #2b8ce0;
  --text-main: #f1f5f9;
  --text-secondary: #708499;
  --online: #4dcd5e;
  --radius: 14px;
}

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

body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #0e1621;
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.hidden { display: none !important; }

/* ============================================================
   ÉCRAN DE BIENVENUE
   ============================================================ */
.welcome {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1200px 600px at 70% -10%, rgba(42,165,224,0.18), transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(77,205,94,0.10), transparent 55%),
    linear-gradient(160deg, #1a2430 0%, #0e1621 100%);
  z-index: 50;
  padding: 20px;
}

.welcome-card {
  width: 400px;
  max-width: 100%;
  background: rgba(23, 33, 43, 0.95);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 24px;
  padding: 44px 40px 36px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6), 0 2px 8px rgba(0,0,0,0.3);
  animation: rise 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.welcome-logo svg { width: 84px; height: 84px; filter: drop-shadow(0 6px 16px rgba(42,165,224,0.4)); }

.welcome-card h1 {
  margin-top: 14px;
  font-size: 28px;
  font-weight: 300;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, #1e8fc9, #2aa5e0);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: #1e8fc9;
}

.welcome-sub { color: #a3b4c2; font-size: 14px; margin: 8px 0 26px; }

/* Sélecteur de photo */
.photo-picker { display: inline-flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; margin-bottom: 20px; }

.photo-circle {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2a3a4d, #1f2c3a);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  color: #708499;
  border: 3px solid #0e1621;
  box-shadow: 0 0 0 2px var(--accent), 0 8px 20px rgba(0,0,0,0.4);
  overflow: hidden;
  transition: transform 0.2s;
}

.photo-circle img { width: 100%; height: 100%; object-fit: cover; }
.photo-picker:hover .photo-circle { transform: scale(1.04); }

.photo-hint { font-size: 12.5px; color: var(--accent); font-weight: 500; }
.photo-hint em { font-style: normal; opacity: 0.6; font-weight: 400; }

/* Champ nom */
.name-input {
  width: 100%;
  border: none;
  border-bottom: 2px solid #31445a;
  background: transparent;
  padding: 12px 4px;
  font-size: 17px;
  text-align: center;
  outline: none;
  color: var(--text-main);
  transition: border-color 0.25s;
  margin-top: 6px;
}

.name-input:focus { border-color: var(--accent); }
.name-input::placeholder { color: #5f7c94; }

.welcome-error { color: #e53935; font-size: 13px; min-height: 18px; margin-top: 10px; }

.continue-btn {
  width: 100%;
  margin-top: 10px;
  border: none;
  border-radius: 12px;
  padding: 14px;
  background: linear-gradient(135deg, #2aa5e0, #1e8fc9);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 8px 20px rgba(42,165,224,0.35);
  transition: transform 0.15s, box-shadow 0.2s;
}

.continue-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(42,165,224,0.45); }
.continue-btn:active { transform: translateY(0); }

/* ============================================================
   APPLICATION
   ============================================================ */
.app { display: flex; height: 100vh; height: 100dvh; width: 100vw; animation: fade 0.4s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 300px;
  min-width: 300px;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  display: flex;
  flex-direction: column;
  border-right: 1px solid #0d141b;
  position: relative;
}

.sidebar-header { padding: 12px 12px 8px; }

.search-box {
  background: #242f3d;
  border-radius: 10px;
  display: flex;
  align-items: center;
  padding: 9px 14px;
  gap: 10px;
  transition: box-shadow 0.2s;
}

.search-box:focus-within { box-shadow: 0 0 0 2px rgba(42,165,224,0.35); }

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  width: 100%;
  font-size: 14px;
}

.search-box input::placeholder { color: #708499; }

.section-label {
  padding: 10px 14px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: #5f7c94;
}

.chats-list { overflow-y: auto; flex-shrink: 0; max-height: 42vh; }
.chats-list:last-of-type { flex: 1; max-height: none; }

.chats-list::-webkit-scrollbar, .messages::-webkit-scrollbar { width: 5px; }
.chats-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb { background: #2a3a4d; border-radius: 3px; }
.messages::-webkit-scrollbar-thumb { background: #c3ced8; }

.chat-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  gap: 10px;
  position: relative;
  transition: background 0.12s;
}

.chat-item::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.15s;
}

.chat-item:hover { background: var(--sidebar-hover); }
.chat-item.active { background: var(--sidebar-active); }
.chat-item.active::before { opacity: 1; }

.chat-item-info { flex: 1; min-width: 0; }

.chat-item-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }

.chat-item-name {
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-time { font-size: 11px; color: var(--text-secondary); flex-shrink: 0; }

.chat-item-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; gap: 8px; }

.chat-item-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-item-preview .tick { color: #4fae4f; font-size: 10px; }

.unread-badge {
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 7px;
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(42,165,224,0.4);
}

.online-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--online);
  box-shadow: 0 0 0 2px var(--sidebar-bg), 0 0 8px rgba(77,205,94,0.8);
  flex-shrink: 0;
  margin-right: 2px;
}

/* Footer profil */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #101921;
  border-top: 1px solid #0d141b;
}

.user-info { display: flex; align-items: center; gap: 12px; cursor: pointer; flex: 1; border-radius: 10px; padding: 4px; transition: background 0.15s; }
.user-info:hover { background: rgba(255,255,255,0.06); }

.user-text { display: flex; flex-direction: column; min-width: 0; }

.user-text strong { color: #fff; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.status-online { color: var(--online); font-size: 12px; }

.footer-icons { display: flex; gap: 10px; font-size: 15px; color: #708499; cursor: pointer; }
.footer-icons span { padding: 5px; border-radius: 8px; transition: background 0.15s, color 0.15s; }
.footer-icons span:hover { background: rgba(255,255,255,0.08); color: #fff; }
#logoutBtn:hover { color: #ff6b6b; }

/* ---------- Avatars ---------- */
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  user-select: none;
  overflow: hidden;
  background: linear-gradient(135deg, #4f9ac4, #2aa5e0);
}

.avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-item .avatar { width: 42px; height: 42px; font-size: 15px; }
.avatar-lg { width: 44px; height: 44px; font-size: 16px; }

.avatar-wrap { position: relative; flex-shrink: 0; }
.avatar-wrap .online-dot {
  position: absolute;
  bottom: 0; right: 0;
  width: 10px; height: 10px;
  box-shadow: 0 0 0 2px var(--sidebar-bg);
}

/* ---------- Panneau de chat ---------- */
.chat-panel {
  flex: 1;
  display: flex;
  background: var(--chat-bg);
  background-image: radial-gradient(900px 500px at 15% 10%, rgba(42,165,224,0.06), transparent 55%),
                    radial-gradient(800px 400px at 85% 90%, rgba(77,205,94,0.05), transparent 50%);
  position: relative;
  min-width: 0;
}

.empty-state { margin: auto; text-align: center; color: var(--text-secondary); padding: 20px; }

.empty-logo svg { opacity: 0.9; filter: drop-shadow(0 10px 30px rgba(42,165,224,0.35)); }

.empty-state h2 {
  font-size: 30px;
  font-weight: 300;
  margin-top: 18px;
  background: linear-gradient(90deg, #1e8fc9, #2aa5e0);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.empty-state p { font-size: 14px; margin-top: 8px; }

/* Chat view */
.chat-view { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-header {
  background: rgba(23, 33, 43, 0.92);
  backdrop-filter: blur(10px);
  padding: 10px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  z-index: 2;
}

.chat-title { display: flex; align-items: center; gap: 12px; cursor: pointer; border-radius: 10px; padding: 4px; transition: background 0.15s; }
.chat-title:hover { background: rgba(255,255,255,0.05); }

.chat-title-text { display: flex; flex-direction: column; }

.chat-title-text strong { font-size: 15.5px; color: #fff; font-weight: 600; }

.chat-title-text span { font-size: 12.5px; color: var(--text-secondary); }
.chat-title-text span.online { color: var(--online); }

.chat-actions { color: #6d7f8f; font-size: 20px; cursor: pointer; padding: 6px 10px; border-radius: 8px; transition: background 0.15s; }
.chat-actions:hover { background: rgba(255,255,255,0.08); }

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-anchor: none;
  padding: 20px 84px 10px;
  scroll-behavior: smooth;
}
.messages > :last-child { margin-bottom: 6px; }

.msg-date-separator { text-align: center; margin: 6px 0 12px; }

.msg-date-separator span {
  background: rgba(35, 49, 64, 0.9);
  color: #8ea2b8;
  font-size: 12px;
  padding: 3px 13px;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  backdrop-filter: blur(4px);
}

.msg-row { display: flex; margin-bottom: 5px; animation: msgIn 0.25s cubic-bezier(0.22, 1, 0.36, 1); }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-row.in { justify-content: flex-start; }
.msg-row.out { justify-content: flex-end; }

.bubble {
  max-width: 42%;
  padding: 5px 10px 4px;
  border-radius: 12px;
  font-size: 12.5px;
  line-height: 1.3;
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
  color: var(--text-main);
  box-shadow: 0 1px 1px rgba(0,0,0,0.28);
}

.msg-row.in .bubble {
  background: #1b2733;
  border: 1px solid rgba(255,255,255,0.05);
  border-bottom-left-radius: 3px;
}

.msg-row.out .bubble {
  background: linear-gradient(180deg, #315f8d 0%, #2b5278 100%);
  border-bottom-right-radius: 3px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 1px 0 rgba(255,255,255,0.08) inset;
}

.msg-meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 3px;
  margin-top: 1px;
  font-size: 9.5px;
  color: #6d7f8f;
  float: right;
  margin-left: 10px;
}

.msg-row.out .msg-meta { color: #9dc3e6; }
.tick { font-size: 11px; color: #9dc3e6; }

/* Composer */
.composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 22px 16px;
}

.composer-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.composer input[type="text"] {
  flex: 1;
  background: #17212b;
  border: 1px solid rgba(255,255,255,0.06);
  outline: none;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text-main);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: box-shadow 0.2s;
}

.composer input::placeholder { color: #708499; }

.composer input:focus { box-shadow: 0 2px 8px rgba(0,0,0,0.4), 0 0 0 2px rgba(62,153,240,0.3); border-color: rgba(62,153,240,0.4); }

.attach-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.attach-btn svg { width: 20px; height: 20px; }
.attach-btn:hover { background: rgba(255,255,255,0.08); transform: scale(1.06); }
.attach-btn:active { transform: scale(0.94); }

.pending-file {
  background: #17212b;
  border: 1px dashed #2b5278;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13.5px;
  color: #8ea2b8;
  cursor: pointer;
  user-select: none;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.pending-file:hover { border-color: #ff5252; color: #ff6b6b; }

.send-btn {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #2aa5e0, #1e8fc9);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(42,165,224,0.4);
  transition: transform 0.15s, box-shadow 0.2s;
  flex-shrink: 0;
}

.send-btn:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 8px 18px rgba(42,165,224,0.5); }
.send-btn:active { transform: scale(0.95); }
.send-btn svg { margin-left: -2px; }

/* Fichiers dans les bulles */
.file-card {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 140px;
  max-width: 210px;
}
.file-ico { font-size: 19px; flex-shrink: 0; }
.file-info { flex: 1; min-width: 0; }
.file-name {
  font-weight: 600;
  font-size: 11.5px;
  word-break: break-word;
}
.file-name a { color: inherit; text-decoration: none; }
.file-name a:hover { text-decoration: underline; }
.file-size { font-size: 10px; color: #93a6ba; margin-top: 1px; }
.file-dl {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(62,153,240,0.2);
  color: #6ab2f2;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  text-decoration: none;
  transition: background 0.15s;
}
.file-dl:hover { background: rgba(62,153,240,0.35); }
.file-image {
  display: block;
  max-width: 200px;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 3px;
}
.file-image img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 8px;
}
.file-caption { display: block; margin-top: 3px; word-break: break-word; font-size: 12px; }

/* ============================================================
   VERSION MOBILE — plein écran, bouton retour, fond à motifs
   ============================================================ */
.back-btn {
  display: none;
  border: none;
  background: transparent;
  color: #6ab2f2;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 10px 4px 4px;
}

@media (max-width: 820px) {
  .sidebar { width: 100%; min-width: 100%; }
  .chat-panel { display: none; }
  .chat-panel.open { display: flex; position: fixed; inset: 0; height: 100dvh; z-index: 30; background: var(--chat-bg); }
  .sidebar.hidden-mobile { display: none; }
  .messages { padding: 14px 10px 6px; -webkit-overflow-scrolling: touch; }
  .bubble { max-width: 88%; }
  .welcome-card { padding: 30px 22px 26px; }

  .back-btn { display: block; }
  .chat-actions { display: none; }
  .composer { padding: 8px 10px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .send-btn { width: 40px; height: 40px; }
  .attach-btn { width: 34px; height: 34px; }
  .file-image { max-width: 210px; }
  .file-card { min-width: 140px; max-width: 220px; }
  .chat-title-text span { font-size: 12px; }
  .empty-logo svg { width: 56px; height: 56px; }
  .sidebar-header { padding: 10px 10px 6px; }
  .chat-item { padding: 8px 10px; }
  .msg-meta { margin-left: 6px; }
}
