:root {
  --orange: #f56b2a;
  --orange-dark: #e05a1b;
  --orange-soft: #fef0e8;
  --bg: #f6f6f4;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e5e7eb;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --blue: #2563eb;
  --violet: #7c3aed;
  --slate: #64748b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* ---------- Barre du haut ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 210px; }
.brand-logo {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--orange), var(--orange-dark));
  border-radius: 10px;
  color: #fff;
  font-weight: 800;
  font-size: 20px;
  display: grid;
  place-items: center;
}
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11.5px; color: var(--muted); }

.searchbox {
  flex: 1;
  max-width: 640px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 9px 16px;
  color: var(--muted);
  transition: border-color .15s, box-shadow .15s;
}
.searchbox:focus-within { border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange-soft); }
.searchbox input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  color: var(--text);
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 10px;
  width: 38px; height: 38px;
  font-size: 17px;
  cursor: pointer;
  color: var(--muted);
}
.icon-btn:hover { background: var(--bg); }

.settings-panel {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 24px;
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
  font-size: 13.5px;
}
.settings-panel input { border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; }

/* ---------- Filtres par statut ---------- */
.filters {
  display: flex;
  gap: 8px;
  padding: 14px 24px 10px;
  flex-wrap: wrap;
}
.chip {
  border: 1.5px solid var(--border);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: all .12s;
}
.chip:hover { border-color: #d1d5db; color: var(--text); }
.chip.active { background: var(--text); border-color: var(--text); color: #fff; }
.chip .count {
  background: rgba(0,0,0,.07);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11.5px;
}
.chip.active .count { background: rgba(255,255,255,.22); }
.chip.chip-relance.active { background: var(--red); border-color: var(--red); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }

/* ---------- Disposition principale ---------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(380px, 470px) 1fr;
  gap: 18px;
  padding: 4px 24px 24px;
  min-height: 0;
}
.list-pane { display: flex; flex-direction: column; min-height: 0; }
.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 4px 10px;
  font-size: 12.5px;
  color: var(--muted);
}
.list-header select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12.5px;
  background: var(--card);
  color: var(--text);
}
.conv-list { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 10px; }

/* ---------- Carte de conversation ---------- */
.conv-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color .12s, transform .08s;
}
.conv-card:hover { border-color: #d1d5db; }
.conv-card.selected { border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange-soft); }
.conv-flex { display: flex; gap: 12px; }
.conv-main { flex: 1; min-width: 0; }
.conv-thumb {
  width: 62px; height: 62px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: #f1f3f5;
  border: 1px solid var(--border);
}
.conv-thumb-empty { display: grid; place-items: center; font-size: 22px; }
.detail-thumb {
  width: 86px; height: 86px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  background: #f1f3f5;
  border: 1px solid var(--border);
}
.conv-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.conv-title { font-weight: 700; font-size: 14px; line-height: 1.3; }
.conv-price { color: var(--orange-dark); font-weight: 700; font-size: 13.5px; white-space: nowrap; }
.conv-meta { display: flex; align-items: center; gap: 8px; margin-top: 5px; font-size: 12.5px; color: var(--muted); }
.conv-preview {
  margin-top: 7px;
  font-size: 13px;
  color: #4b5563;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.conv-preview .who { font-weight: 600; color: var(--muted); }
.conv-badges { display: flex; gap: 6px; margin-top: 9px; flex-wrap: wrap; align-items: center; }

.badge {
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
  padding: 3px 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.badge-relance { background: #fef2f2; color: var(--red); border: 1px solid #fecaca; }
.badge-deleted { background: #f4f4f5; color: #52525b; border: 1px solid #d4d4d8; }
.badge-unread { background: var(--orange-soft); color: var(--orange-dark); }
.tag-pill {
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  padding: 3px 9px;
  color: #fff;
}

/* ---------- Panneau de détail ---------- */
.detail-pane {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 0;
  overflow-y: auto;
}
.empty-detail {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 6px;
}
.empty-icon { font-size: 44px; }

.detail { padding: 22px 26px; }
.detail-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.detail-title { font-size: 19px; font-weight: 800; line-height: 1.25; margin: 0; }
.detail-sub { color: var(--muted); font-size: 13.5px; margin-top: 5px; display: flex; gap: 14px; flex-wrap: wrap; }
.detail-price { color: var(--orange-dark); font-weight: 800; font-size: 19px; white-space: nowrap; }

.section-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 700;
  color: var(--muted);
  margin: 22px 0 8px;
}

.status-row { display: flex; gap: 7px; flex-wrap: wrap; }
.status-btn {
  border: 1.5px solid var(--border);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
.status-btn .dot { width: 8px; height: 8px; border-radius: 50%; }
.status-btn.active { color: #fff; }

.tags-row { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.tag-pill .x { cursor: pointer; opacity: .75; margin-left: 3px; }
.tag-pill .x:hover { opacity: 1; }
.tag-add {
  border: 1.5px dashed var(--border);
  background: transparent;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.tag-add:hover { border-color: var(--orange); color: var(--orange); }
.tag-menu {
  display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px;
  padding: 10px; background: var(--bg); border-radius: 10px;
}
.tag-menu input {
  border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 10px; font-size: 12px; width: 130px;
}

.ad-desc {
  font-size: 13px;
  color: #4b5563;
  white-space: pre-wrap;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  max-height: 130px;
  overflow-y: auto;
  line-height: 1.5;
}

textarea.notes {
  width: 100%;
  min-height: 74px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  font-family: inherit;
  resize: vertical;
  background: #fffdf5;
}
textarea.notes:focus { outline: none; border-color: var(--orange); }
.notes-saved { font-size: 11.5px; color: var(--green); margin-top: 3px; height: 14px; }

/* ---------- Fil de messages ---------- */
.thread { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.msg {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-wrap;
}
.msg .msg-date { display: block; font-size: 10.5px; opacity: .65; margin-top: 4px; }
.msg-in { align-self: flex-start; background: #f1f3f5; border-bottom-left-radius: 4px; }
.msg-out { align-self: flex-end; background: var(--orange-soft); border: 1px solid #fbd8c2; border-bottom-right-radius: 4px; }
.msg-unknown { align-self: stretch; max-width: 100%; background: #f8fafc; border: 1px dashed var(--border); }
.thread-empty { color: var(--muted); font-size: 13px; font-style: italic; }

/* ---------- Répondre ---------- */
.reply-box { display: flex; flex-direction: column; gap: 8px; }
.reply-text {
  width: 100%;
  min-height: 70px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  font-family: inherit;
  resize: vertical;
}
.reply-text:focus { outline: none; border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange-soft); }
.reply-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.reply-hint { font-size: 11.5px; color: var(--muted); }
.reply-status {
  font-size: 12.5px;
  border-radius: 8px;
  padding: 7px 11px;
  line-height: 1.4;
}
.reply-pending, .reply-sending { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.reply-failed { background: #fef2f2; border: 1px solid #fecaca; color: var(--red); }

.detail-actions { display: flex; gap: 10px; margin-top: 26px; flex-wrap: wrap; }
.btn {
  border: 1.5px solid var(--border);
  background: var(--card);
  border-radius: 10px;
  padding: 8px 15px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-primary:hover { background: var(--orange-dark); }
.btn-danger { color: var(--red); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 5px 11px; font-size: 12px; }

/* ---------- État vide ---------- */
.empty-list {
  background: var(--card);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 34px 26px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.7;
}
.empty-list b { color: var(--text); }
.empty-list ol { text-align: left; display: inline-block; margin: 10px 0 0; }

/* ---------- Écran de connexion ---------- */
#login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #fef0e8, #f6f6f4);
  display: grid;
  place-items: center;
  z-index: 1000;
}
.login-card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,.12);
  padding: 34px 30px;
  width: 320px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.login-logo {
  width: 52px; height: 52px; margin: 0 auto;
  background: linear-gradient(135deg, var(--orange), var(--orange-dark));
  border-radius: 13px;
  color: #fff; font-weight: 800; font-size: 27px;
  display: grid; place-items: center;
}
.login-card h2 { margin: 6px 0 0; font-size: 18px; }
.login-card p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.5; }
.login-card input {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange-soft); }
.login-card .btn-primary { justify-content: center; padding: 11px; }
.login-error { font-size: 12.5px; color: var(--red); min-height: 16px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .detail-pane { order: -1; }
  .brand { min-width: 0; }
  .brand-sub { display: none; }
}
