/* ============================================================
   WhatsClone — Design inspiré WhatsApp, mobile-first
   ============================================================ */
:root {
  --teal-dark: #075E54;
  --teal: #128C7E;
  --green: #25D366;
  --green-light: #DCF8C6;
  --chat-bg: #E5DDD5;
  --panel-bg: #FFFFFF;
  --border: #E9EDEF;
  --text-main: #111B21;
  --text-sub: #667781;
  --bubble-out: #D9FDD3;
  --bubble-in: #FFFFFF;
  --danger: #E53935;
  --unread: #25D366;
  --header-h: 60px;
  --nav-h: 58px;
  --radius: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-main);
  background: var(--panel-bg);
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }
a { color: var(--teal); text-decoration: none; }
img { max-width: 100%; display: block; }

/* ---------- Auth pages ---------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--teal-dark);
  padding: 20px;
}
.auth-card {
  background: #fff;
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
.auth-logo { font-size: 48px; margin-bottom: 4px; }
.auth-card h1 { margin: 0 0 4px; color: var(--teal-dark); font-size: 22px; }
.auth-sub { color: var(--text-sub); margin: 0 0 20px; font-size: 14px; }
.auth-card form { text-align: left; }
.auth-card label { display: block; font-size: 13px; color: var(--text-sub); margin: 12px 0 4px; }
.auth-card input {
  width: 100%; padding: 11px 12px; border: 1px solid #D1D7DB; border-radius: 8px; font-size: 15px;
}
.auth-card input:focus { outline: none; border-color: var(--teal); }
.auth-footer { margin-top: 18px; font-size: 13.5px; color: var(--text-sub); }
.btn {
  display: inline-block; border: none; border-radius: 24px; padding: 12px 20px;
  font-size: 15px; font-weight: 600; text-align: center;
}
.btn-primary { background: var(--teal-dark); color: #fff; }
.btn-primary:hover { background: var(--teal); }
.btn-block { width: 100%; margin-top: 18px; }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 13.5px; margin-bottom: 12px; text-align: left; }
.alert-error { background: #FDECEA; color: var(--danger); }
.alert-success { background: #E7F8EE; color: #1B873F; }

/* ============================================================
   APP SHELL
   ============================================================ */
.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  background: var(--panel-bg);
  overflow: hidden;
}

/* ---- Sidebar (liste conversations) ---- */
.sidebar {
  width: 100%;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-right: 1px solid var(--border);
}
.sidebar-header {
  height: var(--header-h);
  padding-top: var(--safe-top);
  background: var(--teal-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 8px;
  flex-shrink: 0;
}
.sidebar-header h2 { font-size: 19px; margin: 0; font-weight: 600; }
.header-icons { display: flex; gap: 4px; align-items: center; }
.icon-btn {
  background: none; border: none; color: #fff; font-size: 20px; width: 40px; height: 40px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center; position: relative;
}
.icon-btn:hover { background: rgba(255,255,255,.12); }
.badge {
  position: absolute; top: 2px; right: 2px; background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px;
}

.search-bar { padding: 8px 10px; background: #fff; flex-shrink: 0; }
.search-bar input {
  width: 100%; border: none; background: #F0F2F5; border-radius: 20px; padding: 9px 16px;
  font-size: 14.5px;
}
.search-bar input:focus { outline: none; background: #E9EDEF; }

.tabs { display: flex; gap: 8px; padding: 4px 10px 8px; flex-shrink: 0; overflow-x: auto; }
.tab-chip {
  border: none; background: #F0F2F5; color: var(--text-sub); padding: 6px 14px; border-radius: 16px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.tab-chip.active { background: #E7FCE3; color: var(--teal-dark); }

.status-strip { display: flex; gap: 12px; padding: 10px 14px; overflow-x: auto; border-bottom: 8px solid #F7F8FA; flex-shrink: 0; }
.status-item { text-align: center; flex-shrink: 0; width: 62px; }
.status-avatar-ring {
  width: 56px; height: 56px; border-radius: 50%; padding: 2px;
  background: conic-gradient(var(--green) 0deg 360deg); margin: 0 auto 4px;
}
.status-avatar-ring.viewed { background: #D1D7DB; }
.status-avatar-ring img { width: 100%; height: 100%; border-radius: 50%; border: 2px solid #fff; object-fit: cover; }
.status-item span { font-size: 11px; color: var(--text-sub); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-add { position: relative; }
.status-add .plus {
  position: absolute; bottom: 2px; right: 2px; background: var(--green); color: #fff; width: 18px; height: 18px;
  border-radius: 50%; font-size: 13px; display: flex; align-items: center; justify-content: center; border: 2px solid #fff;
}

.conv-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.conv-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid #F5F6F6;
}
.conv-item:active { background: #F0F2F5; }
.conv-avatar { width: 50px; height: 50px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: #ddd; }
.conv-main { flex: 1; min-width: 0; }
.conv-top-row { display: flex; justify-content: space-between; align-items: center; }
.conv-title { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--text-sub); flex-shrink: 0; }
.conv-bottom-row { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; }
.conv-preview { font-size: 13.5px; color: var(--text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-unread {
  background: var(--unread); color: #fff; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px;
  border-radius: 10px; display: flex; align-items: center; justify-content: center; padding: 0 6px; flex-shrink: 0;
}
.empty-hint { text-align: center; color: var(--text-sub); padding: 40px 20px; font-size: 14px; }

/* ---- Chat panel ---- */
.chat-panel {
  width: 100%;
  display: none;
  flex-direction: column;
  background: var(--chat-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Cg fill='%23d9d1c7' fill-opacity='0.4'%3E%3Ccircle cx='10' cy='10' r='1.4'/%3E%3Ccircle cx='40' cy='30' r='1.4'/%3E%3Ccircle cx='20' cy='50' r='1.4'/%3E%3C/g%3E%3C/svg%3E");
}
.chat-header {
  height: var(--header-h);
  padding-top: var(--safe-top);
  background: var(--teal-dark);
  color: #fff;
  display: flex; align-items: center; gap: 10px; padding-left: 6px; padding-right: 10px; flex-shrink: 0;
}
.chat-header .back-btn { background: none; border: none; color: #fff; font-size: 22px; width: 36px; height: 36px; }
.chat-header img { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info .name { font-size: 15.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header-info .sub { font-size: 12px; color: #D5E6E3; }
.chat-header-actions { display: flex; gap: 2px; }

.chat-search-bar { display: none; padding: 8px; background: #fff; gap: 8px; align-items: center; flex-shrink: 0; }
.chat-search-bar.active { display: flex; }
.chat-search-bar input { flex: 1; border: none; background: #F0F2F5; border-radius: 20px; padding: 8px 14px; font-size: 14px; }
.chat-search-bar button { background: none; border: none; font-size: 14px; color: var(--teal-dark); font-weight: 600; }

.messages-scroll { flex: 1; overflow-y: auto; padding: 14px 8px; -webkit-overflow-scrolling: touch; }
.msg-row { display: flex; margin-bottom: 4px; }
.msg-row.out { justify-content: flex-end; }
.msg-bubble-wrap { max-width: 78%; position: relative; }
.msg-bubble {
  padding: 6px 9px 8px 9px; border-radius: 8px; font-size: 14.5px; line-height: 1.35; position: relative;
  box-shadow: 0 1px 0.5px rgba(0,0,0,.13); word-wrap: break-word; white-space: pre-wrap;
}
.msg-row.in .msg-bubble { background: var(--bubble-in); border-top-left-radius: 0; }
.msg-row.out .msg-bubble { background: var(--bubble-out); border-top-right-radius: 0; }
.msg-sender { font-size: 12.5px; font-weight: 700; color: var(--teal); margin-bottom: 2px; }
.msg-reply-quote {
  background: rgba(0,0,0,.05); border-left: 3px solid var(--teal); border-radius: 4px; padding: 4px 6px;
  margin-bottom: 4px; font-size: 12.5px; color: var(--text-sub);
}
.msg-reply-quote b { color: var(--teal-dark); display: block; font-size: 12px; }
.msg-meta { display: flex; justify-content: flex-end; align-items: center; gap: 3px; margin-top: 2px; float: right; margin-left: 8px; }
.msg-time { font-size: 10.5px; color: var(--text-sub); }
.msg-ticks { font-size: 13px; color: var(--text-sub); line-height: 1; }
.msg-ticks.read { color: #53BDEB; }
.msg-deleted { color: var(--text-sub); font-style: italic; font-size: 13.5px; }
.msg-image { border-radius: 8px; max-width: 260px; margin-bottom: 4px; cursor: pointer; }
.msg-file { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.04); border-radius: 8px; padding: 8px; margin-bottom: 4px; }
.msg-file .fi { font-size: 24px; }
.msg-file .fn { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.msg-file .fs { font-size: 11px; color: var(--text-sub); }
.msg-audio { display: flex; align-items: center; gap: 8px; min-width: 200px; }
.msg-audio audio { flex: 1; height: 34px; }
.msg-reactions { display: flex; gap: 2px; margin-top: -6px; margin-bottom: 2px; }
.reaction-chip { background: #fff; border: 1px solid var(--border); border-radius: 10px; font-size: 11.5px; padding: 1px 5px; box-shadow: 0 1px 2px rgba(0,0,0,.1); }

.date-sep { text-align: center; margin: 10px 0; }
.date-sep span { background: #fff; color: var(--text-sub); font-size: 12px; padding: 4px 10px; border-radius: 8px; box-shadow: 0 1px 1px rgba(0,0,0,.08); }

.msg-context-menu {
  position: fixed; background: #fff; border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.25);
  z-index: 200; overflow: hidden; min-width: 180px;
}
.msg-context-menu button {
  display: flex; width: 100%; text-align: left; padding: 11px 16px; border: none; background: #fff; font-size: 14.5px; gap: 10px;
}
.msg-context-menu button:hover { background: #F5F6F6; }
.reaction-bar {
  position: fixed; background: #fff; border-radius: 24px; box-shadow: 0 4px 16px rgba(0,0,0,.25);
  padding: 6px 10px; display: flex; gap: 8px; z-index: 201;
}
.reaction-bar button { background: none; border: none; font-size: 22px; }
.reaction-bar button:hover { transform: scale(1.2); }

.reply-preview-bar {
  display: none; align-items: center; gap: 8px; background: #F0F2F5; padding: 8px 12px; border-top: 1px solid var(--border);
}
.reply-preview-bar.active { display: flex; }
.reply-preview-bar .rp-content { flex: 1; border-left: 3px solid var(--teal); padding-left: 8px; font-size: 13px; color: var(--text-sub); }
.reply-preview-bar .rp-content b { color: var(--teal-dark); display: block; font-size: 12.5px; }
.reply-preview-bar .rp-close { background: none; border: none; font-size: 18px; color: var(--text-sub); }

.attach-preview-bar { display: none; padding: 10px; background: #F0F2F5; border-top: 1px solid var(--border); align-items: center; gap: 10px; }
.attach-preview-bar.active { display: flex; }
.attach-preview-bar img { width: 60px; height: 60px; object-fit: cover; border-radius: 8px; }
.attach-preview-bar .ap-info { flex: 1; font-size: 13px; }
.attach-preview-bar button { background: none; border: none; font-size: 18px; color: var(--danger); }

.chat-input-bar {
  display: flex; align-items: flex-end; gap: 6px; padding: 8px; background: #F0F2F5;
  padding-bottom: calc(8px + var(--safe-bottom)); flex-shrink: 0;
}
.chat-input-bar .icon-btn2 {
  background: none; border: none; font-size: 22px; color: #54656F; width: 40px; height: 40px; flex-shrink: 0;
}
.chat-input-wrap { flex: 1; background: #fff; border-radius: 22px; display: flex; align-items: flex-end; padding: 4px 8px; }
#messageInput {
  flex: 1; border: none; resize: none; max-height: 110px; padding: 8px 6px; font-size: 15px; line-height: 1.3;
}
#messageInput:focus { outline: none; }
.send-btn {
  background: var(--teal-dark); color: #fff; border: none; width: 44px; height: 44px; border-radius: 50%;
  font-size: 19px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.send-btn.recording { background: var(--danger); }

.emoji-picker {
  display: none; position: absolute; bottom: calc(var(--nav-h) + 4px); left: 0; right: 0; background: #fff;
  border-top: 1px solid var(--border); max-height: 260px; overflow-y: auto; padding: 8px; z-index: 50;
  grid-template-columns: repeat(8, 1fr); gap: 4px;
}
.emoji-picker.active { display: grid; }
.emoji-picker button { background: none; border: none; font-size: 22px; padding: 4px; }

.chat-empty-state {
  display: none; flex: 1; flex-direction: column; align-items: center; justify-content: center; color: var(--text-sub);
  background: #F7F8FA; text-align: center; padding: 20px;
}
.chat-empty-state .ce-icon { font-size: 70px; margin-bottom: 12px; }

/* ---- Bottom navigation (mobile) ---- */
.bottom-nav {
  height: var(--nav-h);
  padding-bottom: var(--safe-bottom);
  background: #fff; border-top: 1px solid var(--border);
  display: flex; flex-shrink: 0;
}
.nav-btn {
  flex: 1; background: none; border: none; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; color: var(--text-sub); font-size: 10.5px; position: relative; padding-top: 6px;
}
.nav-btn .ni { font-size: 21px; }
.nav-btn.active { color: var(--teal-dark); }
.nav-btn .nbadge {
  position: absolute; top: 2px; right: 22%; background: var(--danger); color: #fff; font-size: 9px; font-weight: 700;
  min-width: 15px; height: 15px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
}

/* ---- Panels génériques (profil, nouvelle discussion, etc.) ---- */
.panel-overlay {
  position: fixed; inset: 0; background: #fff; z-index: 100; display: none; flex-direction: column;
}
.panel-overlay.active { display: flex; }
.panel-header {
  height: var(--header-h); padding-top: var(--safe-top); background: var(--teal-dark); color: #fff;
  display: flex; align-items: center; gap: 14px; padding-left: 10px; flex-shrink: 0;
}
.panel-header button.back-btn { background: none; border: none; color: #fff; font-size: 22px; }
.panel-header h3 { font-size: 17px; margin: 0; font-weight: 600; }
.panel-body { flex: 1; overflow-y: auto; }

.user-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid #F5F6F6; }
.user-row img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; }
.user-row .ur-main { flex: 1; min-width: 0; }
.user-row .ur-name { font-size: 15px; font-weight: 500; }
.user-row .ur-sub { font-size: 12.5px; color: var(--text-sub); }
.user-row button.mini-btn { background: #F0F2F5; border: none; border-radius: 16px; padding: 6px 12px; font-size: 12.5px; font-weight: 600; color: var(--teal-dark); }

.profile-avatar-big { width: 130px; height: 130px; border-radius: 50%; object-fit: cover; margin: 24px auto; display: block; }
.profile-field { padding: 16px 20px; border-bottom: 1px solid #F5F6F6; }
.profile-field label { display: block; font-size: 12.5px; color: var(--teal); margin-bottom: 6px; font-weight: 600; }
.profile-field input, .profile-field textarea {
  width: 100%; border: none; font-size: 16px; padding: 4px 0; border-bottom: 1px solid transparent;
}
.profile-field input:focus, .profile-field textarea:focus { outline: none; border-bottom-color: var(--teal); }
.center-btn-wrap { text-align: center; padding: 16px; }

.section-label { padding: 10px 16px 6px; font-size: 13px; color: var(--teal-dark); font-weight: 700; background: #F7F8FA; }

/* Status viewer fullscreen */
.status-viewer { position: fixed; inset: 0; background: #000; z-index: 300; display: none; flex-direction: column; }
.status-viewer.active { display: flex; }
.status-progress-row { display: flex; gap: 4px; padding: 8px 8px 0; }
.status-progress-row .bar { flex: 1; height: 3px; background: rgba(255,255,255,.3); border-radius: 2px; overflow: hidden; }
.status-progress-row .bar i { display: block; height: 100%; width: 0; background: #fff; }
.status-viewer-header { display: flex; align-items: center; gap: 10px; padding: 10px 14px; color: #fff; }
.status-viewer-header img { width: 36px; height: 36px; border-radius: 50%; }
.status-viewer-body { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; color: #fff; font-size: 22px; text-align: center; }
.status-viewer-body img { max-height: 100%; border-radius: 8px; }
.status-close { position: absolute; top: 12px; right: 14px; background: none; border: none; color: #fff; font-size: 24px; }

.fab { position: fixed; bottom: calc(var(--nav-h) + 16px + var(--safe-bottom)); right: 16px; width: 54px; height: 54px; border-radius: 50%; background: var(--green); border: none; color: #fff; font-size: 24px; box-shadow: 0 3px 8px rgba(0,0,0,.3); z-index: 40; }

.toast { position: fixed; bottom: calc(var(--nav-h) + 20px); left: 50%; transform: translateX(-50%); background: #323232; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13.5px; z-index: 400; opacity: 0; transition: opacity .2s; }
.toast.show { opacity: 1; }

.form-group { padding: 12px 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text-sub); margin-bottom: 6px; }
.form-group input, .form-group textarea { width: 100%; padding: 10px; border: 1px solid #D1D7DB; border-radius: 8px; font-size: 15px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px; }
.chip { background: #E7FCE3; color: var(--teal-dark); border-radius: 14px; padding: 4px 10px; font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.chip button { background: none; border: none; color: var(--teal-dark); font-size: 13px; }

/* ============================================================
   Responsive : desktop (>= 900px) — vue 2 colonnes façon WhatsApp Web
   ============================================================ */
@media (min-width: 900px) {
  .app { max-width: 1400px; margin: 0 auto; box-shadow: 0 0 0 1px var(--border); }
  .sidebar { width: 400px; flex-shrink: 0; }
  .chat-panel { display: flex; flex: 1; }
  .chat-panel.hidden-mobile-only { display: flex !important; }
  .chat-empty-state.desktop-visible { display: flex; }
  .bottom-nav { display: none; }
  .fab { display: none; }
  .desktop-rail {
    width: 74px; flex-shrink: 0; background: #F7F8FA; border-right: 1px solid var(--border);
    display: flex; flex-direction: column; align-items: center; padding: 18px 0; gap: 22px;
  }
  .desktop-rail button { background: none; border: none; font-size: 23px; color: var(--text-sub); position: relative; }
  .desktop-rail button.active { color: var(--teal-dark); }
  .desktop-rail .rail-bottom { margin-top: auto; }
}
@media (max-width: 899px) {
  .desktop-rail { display: none; }
}

/* Cacher liste ou chat sur mobile selon état */
body.mobile-view-chat .sidebar { display: none; }
body.mobile-view-chat .chat-panel { display: flex; }
body:not(.mobile-view-chat) .chat-panel { display: none; }
@media (min-width: 900px) {
  body.mobile-view-chat .sidebar, body:not(.mobile-view-chat) .sidebar { display: flex; }
  body:not(.mobile-view-chat) .chat-panel { display: flex; }
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: #c7c7c7; border-radius: 3px; }
