:root {
  --bg: #f4f6f4;
  --card: #ffffff;
  --ink: #1b2420;
  --muted: #6b7872;
  --line: #e3e8e4;
  --brand: #2f6f4f;
  --brand-dark: #245a3f;
  --brand-soft: #e6f1ea;
  --danger: #c0392b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.05);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 0.9rem; }

/* ---------- Boutons ---------- */
button { font-family: inherit; cursor: pointer; }
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 0.7rem 1rem;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  transition: transform 0.05s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-danger { color: var(--danger); border-color: #f0d2cd; background: #fdf2f0; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.45rem 0.7rem; font-size: 0.85rem; border-radius: 10px; }

.icon-btn {
  border: none;
  background: transparent;
  font-size: 1.3rem;
  padding: 0.35rem;
  border-radius: 10px;
  line-height: 1;
}

/* ---------- Login ---------- */
.login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, var(--brand-soft), var(--bg));
}
.login-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem 1.5rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-logo { font-size: 3rem; }
.login-card h1 { margin: 0.4rem 0 0.2rem; font-size: 1.4rem; }
.login-card input {
  width: 100%;
  padding: 0.8rem 0.9rem;
  margin: 1rem 0 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 1rem;
}

/* ---------- Header ---------- */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(244, 246, 244, 0.92);
  backdrop-filter: saturate(180%) blur(12px);
  padding: calc(var(--safe-top) + 0.6rem) 1rem 0.6rem;
  border-bottom: 1px solid var(--line);
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.brand { font-size: 1.25rem; margin: 0; }
.header-actions { display: flex; align-items: center; gap: 0.3rem; }

.chip {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.chip.identity .dot { width: 9px; height: 9px; border-radius: 50%; }

.toolbar { display: flex; gap: 0.5rem; margin-top: 0.7rem; }
.search-wrap { flex: 1; }
.search-wrap input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-size: 0.95rem;
}
.select {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  padding: 0.6rem 0.5rem;
  font-size: 0.9rem;
  color: var(--ink);
  max-width: 42%;
}

.filters {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  margin-top: 0.7rem;
  padding-bottom: 0.2rem;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.filter-chip {
  white-space: nowrap;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
}
.filter-chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.filter-chip .count {
  background: rgba(0, 0, 0, 0.08);
  border-radius: 999px;
  padding: 0 0.4rem;
  font-size: 0.75rem;
}
.filter-chip.active .count { background: rgba(255, 255, 255, 0.25); }

/* ---------- Liste ---------- */
.list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
  padding: 1rem 1rem calc(6rem + var(--safe-bottom));
  max-width: 1100px;
  margin: 0 auto;
}
@media (min-width: 640px) { .list { grid-template-columns: 1fr 1fr; } }
@media (min-width: 980px) { .list { grid-template-columns: 1fr 1fr 1fr; } }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
}
.card:active { transform: scale(0.99); }
.card-img {
  position: relative;
  aspect-ratio: 16 / 10;
  background: var(--brand-soft);
  background-size: cover;
  background-position: center;
}
.card-img .no-img {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 2.4rem;
  opacity: 0.5;
}
.status-badge {
  position: absolute;
  top: 0.6rem;
  left: 0.6rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}
.added-badge {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  border: 2px solid #fff;
}
.card-body { padding: 0.8rem 0.9rem 0.95rem; display: flex; flex-direction: column; gap: 0.35rem; }
.card-price { font-size: 1.15rem; font-weight: 800; }
.card-title { font-size: 0.95rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; color: var(--muted); font-size: 0.85rem; }
.card-meta .sep { opacity: 0.4; }
.card-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 0.3rem; padding-top: 0.55rem; border-top: 1px solid var(--line); }
.ratings { display: flex; gap: 0.7rem; }
.rating-pill { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.8rem; color: var(--muted); }
.rating-pill .who { width: 16px; height: 16px; border-radius: 50%; color: #fff; font-size: 0.6rem; font-weight: 700; display: grid; place-items: center; }
.visit-flag { font-size: 0.78rem; font-weight: 700; color: var(--brand); }
.source-tag { font-size: 0.72rem; color: var(--muted); }

/* ---------- Empty ---------- */
.empty {
  text-align: center;
  padding: 4rem 1.5rem;
  color: var(--muted);
}
.empty .big { font-size: 3rem; }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 1.1rem;
  bottom: calc(1.1rem + var(--safe-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--brand);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  box-shadow: 0 6px 20px rgba(47, 111, 79, 0.45);
  z-index: 30;
}
.fab:active { transform: scale(0.94); }

/* ---------- Modale / bottom sheet ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.15s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: var(--card);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 0.6rem 1.1rem calc(1.4rem + var(--safe-bottom));
  animation: slideup 0.2s ease;
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0.6; } }
@media (min-width: 640px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 20px; max-height: 88vh; }
}
.sheet-handle { width: 42px; height: 4px; background: var(--line); border-radius: 999px; margin: 0.3rem auto 0.6rem; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.6rem; }
.sheet-head h2 { font-size: 1.15rem; margin: 0; }

label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--muted); margin: 0.7rem 0 0.25rem; }
input, textarea, select { font-family: inherit; color: var(--ink); }
.field {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  font-size: 0.95rem;
  background: #fff;
}
textarea.field { min-height: 70px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.row-actions { display: flex; gap: 0.5rem; margin-top: 1.2rem; }
.row-actions .btn { flex: 1; }

.url-row { display: flex; gap: 0.5rem; }
.url-row .field { flex: 1; }

.preview {
  display: flex;
  gap: 0.7rem;
  background: var(--brand-soft);
  border-radius: 12px;
  padding: 0.6rem;
  margin-top: 0.6rem;
  align-items: center;
}
.preview img { width: 70px; height: 70px; object-fit: cover; border-radius: 9px; }
.preview .ptxt { font-size: 0.85rem; }

/* Status selector */
.status-grid { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.status-opt {
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 600;
}
.status-opt.active { color: #fff; }

/* Stars */
.stars { display: inline-flex; gap: 0.15rem; font-size: 1.5rem; }
.stars .star { color: #d6ddd8; line-height: 1; user-select: none; }
.stars .star.on { color: #f5b301; }

.fb-block { border: 1px solid var(--line); border-radius: 12px; padding: 0.7rem 0.8rem; margin-top: 0.6rem; }
.fb-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.3rem; }
.fb-head .who { width: 22px; height: 22px; border-radius: 50%; color: #fff; font-size: 0.7rem; font-weight: 700; display: grid; place-items: center; }
.fb-head .name { font-weight: 700; font-size: 0.9rem; }
.fb-head .mine { font-size: 0.72rem; color: var(--brand); font-weight: 700; }

.detail-img { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 12px; background: var(--brand-soft); }
.detail-price { font-size: 1.5rem; font-weight: 800; margin: 0.6rem 0 0.1rem; }
.detail-meta { color: var(--muted); font-size: 0.92rem; margin-bottom: 0.6rem; }
.detail-link { display: inline-block; margin-top: 0.2rem; color: var(--brand); font-weight: 600; font-size: 0.9rem; word-break: break-all; }
.divider { height: 1px; background: var(--line); margin: 1rem 0; }
.section-title { font-size: 0.95rem; font-weight: 700; margin: 0.2rem 0 0.4rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(5.5rem + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 80;
  box-shadow: var(--shadow);
  animation: fade 0.15s ease;
}

.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
  vertical-align: -3px;
}
.spinner.dark { border-color: var(--line); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }
