/* =====================================================================
   TopMarché — Design system CSS (mobile-first, sans dépendance externe)
   ===================================================================== */

:root {
  /* Palette TopMarché, extraite du logo officiel */
  --tm-navy: #001838;
  --tm-navy-light: #0a2d5e;
  --tm-orange: #f86000;
  --tm-orange-dark: #d94e00;
  --tm-orange-light: #fff1e2;
  --tm-orange-gradient: linear-gradient(135deg, #ff8a1f 0%, #f86000 55%, #e14e00 100%);
  --tm-dark: #001838;
  --tm-gray-900: #1f2937;
  --tm-gray-700: #4b5563;
  --tm-gray-500: #6b7280;
  --tm-gray-300: #d1d5db;
  --tm-gray-200: #e5e7eb;
  --tm-gray-100: #f3f4f6;
  --tm-red: #e0433f;
  --tm-white: #ffffff;
  --tm-radius: 12px;
  --tm-radius-sm: 8px;
  --tm-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --tm-header-h: 68px;
  --tm-bottomnav-h: 60px;
  --tm-max-width: 1200px;
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--tm-gray-900);
  background: var(--tm-gray-100);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tm-bottomnav-h) + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 16px; }

/* ---------- Header ---------- */
.tm-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--tm-white);
  border-bottom: 1px solid var(--tm-gray-200);
  box-shadow: 0 1px 0 rgba(0,24,56,.04);
  height: var(--tm-header-h);
}
.tm-header-inner {
  max-width: var(--tm-max-width); margin: 0 auto; height: 100%;
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
}
.tm-logo { display: flex; align-items: center; white-space: nowrap; flex-shrink: 0; }
.tm-logo img { height: 48px; width: auto; display: block; }
@media (min-width: 480px) {
  .tm-logo img { height: 52px; }
}
.tm-search { flex: 1; display: none; }
.tm-search input {
  width: 100%; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--tm-gray-300);
  background: var(--tm-gray-100);
}
.tm-search input:focus { outline: none; border-color: var(--tm-orange); background: white; }
.tm-search button { display: none; }
.tm-header-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.tm-icon-link { font-size: 1.2rem; padding: 6px; display: none; color: var(--tm-navy); }

@media (min-width: 768px) {
  .tm-search { display: flex; max-width: 480px; }
  .tm-icon-link { display: inline-block; }
}

/* ---------- Bottom nav (mobile) ---------- */
.tm-bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  background: var(--tm-white); border-top: 1px solid var(--tm-gray-200);
  display: flex; height: var(--tm-bottomnav-h);
  padding-bottom: env(safe-area-inset-bottom);
}
.tm-bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 0.68rem; color: var(--tm-gray-500); gap: 2px;
}
.tm-bottom-nav a span { font-size: 1.25rem; }
.tm-bottom-nav a.active { color: var(--tm-orange); font-weight: 600; }
.tm-nav-sell span {
  background: var(--tm-orange-gradient); color: white; border-radius: 50%;
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
  box-shadow: 0 2px 6px rgba(248,96,0,.4);
}
@media (min-width: 768px) {
  .tm-bottom-nav { display: none; }
  body { padding-bottom: 0; }
}

/* ---------- Layout ---------- */
.tm-main { max-width: var(--tm-max-width); margin: 0 auto; padding: 16px; min-height: 60vh; }
.tm-page-title { font-size: 1.3rem; font-weight: 700; margin: 4px 0 16px; color: var(--tm-navy); }
.tm-section { margin-bottom: 28px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 999px; padding: 12px 22px; font-weight: 600; font-size: 0.95rem;
  transition: opacity .15s; text-align: center;
}
.btn:active { opacity: .8; }
.btn-primary { background: var(--tm-orange-gradient); color: white; box-shadow: 0 2px 8px rgba(248,96,0,.35); }
.btn-secondary { background: var(--tm-gray-100); color: var(--tm-navy); border: 1px solid var(--tm-gray-300); }
.btn-outline { background: transparent; border: 1.5px solid var(--tm-orange); color: var(--tm-orange-dark); }
.btn-danger { background: var(--tm-red); color: white; }
.btn-block { display: flex; width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 0.85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; color: var(--tm-gray-700); }
.form-control {
  width: 100%; padding: 12px 14px; border: 1px solid var(--tm-gray-300); border-radius: var(--tm-radius-sm);
  background: white;
}
.form-control:focus { outline: none; border-color: var(--tm-orange); box-shadow: 0 0 0 3px var(--tm-orange-light); }
textarea.form-control { resize: vertical; min-height: 100px; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.form-error { color: var(--tm-red); font-size: 0.8rem; margin-top: 4px; }
.form-hint { color: var(--tm-gray-500); font-size: 0.8rem; margin-top: 4px; }

/* ---------- Cards / grid annonces ---------- */
.tm-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
}
@media (min-width: 600px) { .tm-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .tm-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1100px) { .tm-grid { grid-template-columns: repeat(5, 1fr); } }

.tm-card {
  background: white; border-radius: var(--tm-radius); overflow: hidden; box-shadow: var(--tm-shadow);
  display: block; position: relative;
}
.tm-card-img { aspect-ratio: 3/4; width: 100%; object-fit: cover; background: var(--tm-gray-200); }
.tm-card-body { padding: 8px 10px 12px; }
.tm-card-title { font-size: 0.85rem; color: var(--tm-gray-700); margin: 0 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tm-card-price { font-weight: 700; font-size: 1rem; color: var(--tm-navy); }
.tm-card-meta { font-size: 0.72rem; color: var(--tm-gray-500); margin-top: 2px; }
.tm-fav-btn {
  position: absolute; top: 8px; right: 8px; background: rgba(255,255,255,.9); border-radius: 50%;
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; font-size: 1rem; border: none;
}
.tm-fav-btn.active { color: var(--tm-red); }

/* ---------- Filtres ---------- */
.tm-filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 12px; }
.tm-filter-chip {
  flex: 0 0 auto; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--tm-gray-300);
  background: white; font-size: 0.82rem; white-space: nowrap;
}
.tm-filter-chip.active { background: var(--tm-dark); color: white; border-color: var(--tm-dark); }

/* ---------- Détail annonce ---------- */
.tm-listing-gallery { border-radius: var(--tm-radius); overflow: hidden; background: var(--tm-gray-200); aspect-ratio: 1/1; margin-bottom: 16px; }
.tm-listing-gallery img { width: 100%; height: 100%; object-fit: cover; }
.tm-listing-thumbs { display: flex; gap: 8px; margin-bottom: 20px; overflow-x: auto; }
.tm-listing-thumbs img { width: 60px; height: 60px; object-fit: cover; border-radius: 8px; cursor: pointer; border: 2px solid transparent; }
.tm-listing-thumbs img.active { border-color: var(--tm-orange); }
.tm-price-row { display: flex; align-items: baseline; gap: 10px; margin: 8px 0 16px; }
.tm-price-row .price { font-size: 1.8rem; font-weight: 800; color: var(--tm-orange); }
.tm-badge { display: inline-block; padding: 4px 10px; border-radius: 999px; background: var(--tm-gray-100); font-size: 0.78rem; color: var(--tm-gray-700); margin: 2px 6px 2px 0; }
.tm-seller-card { display: flex; align-items: center; gap: 12px; padding: 14px; background: white; border-radius: var(--tm-radius); box-shadow: var(--tm-shadow); margin: 16px 0; }
.tm-avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--tm-gray-200); object-fit: cover; flex-shrink: 0; }
.tm-avatar-sm { width: 32px; height: 32px; }
.tm-stars { color: #f5a623; font-size: 0.85rem; }
.tm-sticky-buy {
  position: sticky; bottom: calc(var(--tm-bottomnav-h) + 8px); background: white; border-radius: var(--tm-radius);
  box-shadow: var(--tm-shadow); padding: 12px; display: flex; gap: 10px; margin-top: 16px;
}
@media (min-width: 768px) { .tm-sticky-buy { bottom: 16px; } }

/* ---------- Messagerie ---------- */
.tm-conv-list { display: flex; flex-direction: column; background: white; border-radius: var(--tm-radius); overflow: hidden; box-shadow: var(--tm-shadow); }
.tm-conv-item { display: flex; gap: 12px; padding: 14px; border-bottom: 1px solid var(--tm-gray-100); align-items: center; }
.tm-conv-item .name { font-weight: 600; font-size: 0.92rem; }
.tm-conv-item .preview { font-size: 0.82rem; color: var(--tm-gray-500); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.tm-unread-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--tm-orange); margin-left: auto; flex-shrink: 0; }

.tm-chat { display: flex; flex-direction: column; height: calc(100vh - var(--tm-header-h) - var(--tm-bottomnav-h) - 32px); }
.tm-chat-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 8px 4px; }
.tm-msg { max-width: 75%; padding: 10px 14px; border-radius: 16px; font-size: 0.9rem; line-height: 1.35; }
.tm-msg.me { align-self: flex-end; background: var(--tm-orange); color: white; border-bottom-right-radius: 4px; }
.tm-msg.other { align-self: flex-start; background: white; border-bottom-left-radius: 4px; box-shadow: var(--tm-shadow); }
.tm-chat-input { display: flex; gap: 8px; padding-top: 10px; }
.tm-chat-input input { flex: 1; }

/* ---------- Profil ---------- */
.tm-profile-header { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.tm-profile-header .tm-avatar { width: 72px; height: 72px; }
.tm-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--tm-gray-200); margin-bottom: 16px; }
.tm-tab { padding: 10px 16px; font-weight: 600; color: var(--tm-gray-500); border-bottom: 2px solid transparent; }
.tm-tab.active { color: var(--tm-orange); border-color: var(--tm-orange); }

/* ---------- Utilitaires ---------- */
.tm-empty { text-align: center; padding: 48px 16px; color: var(--tm-gray-500); }
.tm-empty .icon { font-size: 2.5rem; margin-bottom: 8px; }
.tm-loading { text-align: center; padding: 40px; color: var(--tm-gray-500); }
.tm-spinner { width: 28px; height: 28px; border: 3px solid var(--tm-gray-200); border-top-color: var(--tm-orange); border-radius: 50%; animation: tm-spin .7s linear infinite; margin: 0 auto 10px; }
@keyframes tm-spin { to { transform: rotate(360deg); } }
.tm-flex { display: flex; align-items: center; }
.tm-flex-between { display: flex; align-items: center; justify-content: space-between; }
.tm-gap-8 { gap: 8px; }
.tm-mt-16 { margin-top: 16px; }
.tm-text-muted { color: var(--tm-gray-500); font-size: 0.85rem; }

/* ---------- Toasts ---------- */
.toast-root { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 999; display: flex; flex-direction: column; gap: 8px; width: 90%; max-width: 380px; }
.toast { background: var(--tm-dark); color: white; padding: 12px 16px; border-radius: var(--tm-radius-sm); font-size: 0.88rem; box-shadow: var(--tm-shadow); animation: tm-toast-in .2s ease-out; }
.toast.error { background: var(--tm-red); }
.toast.success { background: var(--tm-orange-dark); }
@keyframes tm-toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Modal ---------- */
.tm-modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .tm-modal-backdrop { align-items: center; } }
.tm-modal { background: white; border-radius: 16px 16px 0 0; width: 100%; max-width: 480px; max-height: 88vh; overflow-y: auto; padding: 20px; }
@media (min-width: 640px) { .tm-modal { border-radius: 16px; } }
.tm-modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.tm-modal-close { background: none; border: none; font-size: 1.4rem; line-height: 1; }

/* ---------- Upload photos ---------- */
.tm-photo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.tm-photo-slot { aspect-ratio: 1/1; border-radius: 10px; border: 2px dashed var(--tm-gray-300); display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; background: var(--tm-gray-100); font-size: 1.5rem; color: var(--tm-gray-500); }
.tm-photo-slot img { width: 100%; height: 100%; object-fit: cover; }
.tm-photo-remove { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.6); color: white; border: none; border-radius: 50%; width: 20px; height: 20px; font-size: 0.7rem; }

/* ---------- Auth ---------- */
.tm-auth-container { max-width: 420px; margin: 20px auto; background: white; padding: 28px 22px; border-radius: var(--tm-radius); box-shadow: var(--tm-shadow); }
.tm-auth-logo { height: 56px; width: auto; margin: 0 auto 12px; }
.tm-auth-switch { text-align: center; margin-top: 16px; font-size: 0.88rem; color: var(--tm-gray-500); }
.tm-auth-switch a { color: var(--tm-orange); font-weight: 600; }

/* ---------- Steps / checkout ---------- */
.tm-summary-row { display: flex; justify-content: space-between; padding: 8px 0; font-size: 0.9rem; }
.tm-summary-row.total { font-weight: 700; font-size: 1.05rem; border-top: 1px solid var(--tm-gray-200); padding-top: 12px; margin-top: 4px; }
