/* =====================================================
   KOJIJI.CSS — Refonte Mobile-First v2
   Art direction: marketplace local → chaleureux, lisible, accessible
   Palette: bleu Bootstrap conservé + surfaces neutres chaleureuses
   Density: balanced
   ===================================================== */

/* --- Design Tokens --- */
:root {
  /* Type scale fluide — plancher 12px */
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);

  /* Espacement (base 4px) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Couleurs Bootstrap conservées + tokens sémantiques */
  --color-primary:        #0d6efd;
  --color-primary-hover:  #0b5ed7;
  --color-primary-light:  rgba(13, 110, 253, 0.08);
  --color-bg:             #f5f4f0;
  --color-surface:        #ffffff;
  --color-surface-2:      #f8f9fa;
  --color-border:         rgba(0, 0, 0, 0.1);
  --color-divider:        #dee2e6;
  --color-text:           #212529;
  --color-text-muted:     #6c757d;
  --color-text-faint:     #adb5bd;
  --color-success:        #198754;
  --color-danger:         #dc3545;

  /* Rayon */
  --radius-sm:   0.375rem;
  --radius-md:   0.5rem;
  --radius-lg:   0.75rem;
  --radius-xl:   1rem;
  --radius-full: 9999px;

  /* Ombres chaleureuses */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.07);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.09);
  --shadow-lg: 0 8px 28px rgba(0,0,0,0.12);

  /* Transition */
  --t: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* --- Reset ciblé --- */
*, *::before, *::after { box-sizing: border-box; }

body {
  background: var(--color-bg);
  font-size: var(--text-base);
  color: var(--color-text);
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
}

/* -----------------------------------------------------------------------
   Layout principal
----------------------------------------------------------------------- */

.page-wrap {
  padding-top: var(--space-4);
  padding-bottom: 5.5rem;
}

@media (min-width: 768px) {
  .page-wrap { padding-bottom: var(--space-8); }
}

/* -----------------------------------------------------------------------
   Header
----------------------------------------------------------------------- */

header h1 {
  font-size: var(--text-lg);
  font-weight: 700;
  margin-bottom: var(--space-1);
  line-height: 1.2;
}

#userMsg {
  font-size: var(--text-sm);
  min-height: 1.4em;
  color: var(--color-text-muted);
}

/* -----------------------------------------------------------------------
   Boîte de recherche
----------------------------------------------------------------------- */

.search-box {
  min-width: 0;
  flex: 1 1 auto;
}

.search-box .form-control {
  font-size: var(--text-base);
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-md) 0 0 var(--radius-md) !important;
}

.search-box .btn {
  padding: 0 0.85rem;
  font-size: var(--text-base);
  min-width: 2.75rem;
  min-height: 44px;
}

/* -----------------------------------------------------------------------
   Boutons toggle Vue Liste / Carte
----------------------------------------------------------------------- */

/* Séparer les boutons : annuler la fusion des bordures de Bootstrap */
.view-toggle {
  gap: var(--space-1);
}

/* Réinitialiser la marge négative de Bootstrap qui écrase les bordures adjacentes */
.view-toggle > .btn + .btn {
  margin-left: 0;
}

/* Redonner un border-radius individuel à chaque bouton (annule l'aplatissement du btn-group) */
.view-toggle > .btn {
  border-radius: var(--radius-sm) !important;
}

.view-toggle .btn {
  font-size: var(--text-sm);
  min-height: 44px;
  padding: 0.5rem 0.85rem;
}

/* Fix desktop : forcer la couleur active (bleu rempli) sur le bouton sélectionné */
.view-toggle .btn.active,
.view-toggle .btn[aria-pressed="true"] {
  background-color: var(--color-primary) !important;
  border-color: var(--color-primary) !important;
  color: #fff !important;
}

/* -----------------------------------------------------------------------
   Bouton Ajouter
----------------------------------------------------------------------- */

.show-submit-link.btn,
.show-submit-link {
  font-size: var(--text-sm);
  font-weight: 600;
  min-height: 44px;
  border-radius: var(--radius-md);
}

/* -----------------------------------------------------------------------
   Panneau Géolocalisation
----------------------------------------------------------------------- */

#geo-panel {
  background: linear-gradient(135deg, #f0f4ff 0%, #e8f4fd 100%);
  border: 1px solid #c5d8f8;
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  animation: slideDown 0.2s var(--t);
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

#geo-rayon { cursor: pointer; accent-color: var(--color-primary); }

.geo-preset-btn {
  font-size: var(--text-xs);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-full);
  transition: all var(--t);
  white-space: nowrap;
  min-height: 44px;
}

.geo-preset-btn.active {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

#geo-status-badge {
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
  padding: 0.4rem 0.75rem;
  max-width: 100%;
  word-break: break-word;
  background: rgba(13, 110, 253, 0.08);
  color: #0a58ca;
  border: 1px solid rgba(13, 110, 253, 0.18);
}

/* -----------------------------------------------------------------------
   Spinner inline bouton
----------------------------------------------------------------------- */

.btn-spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.125em;
  border: 0.15em solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
  margin-right: 0.4em;
}

@keyframes btn-spin { to { transform: rotate(360deg); } }

/* -----------------------------------------------------------------------
   Overlay auth
----------------------------------------------------------------------- */

.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.28);
  z-index: 1000;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--t);
  pointer-events: none;
}

.auth-overlay.visible { opacity: 1; pointer-events: auto; }
.auth-forms { position: relative; z-index: 1001; }

.auth-close-btn {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  z-index: 1002;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-forms .form-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
}

.auth-forms .form-control {
  font-size: var(--text-base);
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-md);
  min-height: 48px;
}

/* -----------------------------------------------------------------------
   Formulaire d'annonce
----------------------------------------------------------------------- */

.link-form .form-label {
  font-size: var(--text-sm);
  font-weight: 600;
}

.link-form .form-control {
  font-size: var(--text-base);
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-md);
  min-height: 48px;
}

.link-form textarea.form-control {
  min-height: 100px;
  resize: vertical;
}

/* -----------------------------------------------------------------------
   Adresse autocomplete
----------------------------------------------------------------------- */

.mapbox-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1050;
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 260px;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
}

.mapbox-suggestions li {
  padding: 0.65rem 0.9rem;
  cursor: pointer;
  font-size: var(--text-sm);
  line-height: 1.4;
  border-bottom: 1px solid #f1f3f5;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  min-height: 48px;
}

.mapbox-suggestions li:last-child { border-bottom: none; }
.mapbox-suggestions li:hover,
.mapbox-suggestions li.active { background: #f0f4ff; }
.mapbox-suggestions li .sug-icon { color: var(--color-text-muted); margin-top: 2px; flex-shrink: 0; }
.mapbox-suggestions li .sug-main { font-weight: 600; font-size: var(--text-sm); }
.mapbox-suggestions li .sug-sub {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}

.address-wrap { position: relative; }
.address-verified-icon {
  position: absolute;
  right: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-success);
  font-size: 1rem;
  pointer-events: none;
  display: none;
}
#linkAddress.is-verified { padding-right: 2rem; border-color: var(--color-success); }

#geoBtn {
  min-width: 2.75rem;
  min-height: 44px;
  transition: all var(--t);
}
#geoBtn.active { box-shadow: 0 0 0 0.2rem rgba(13,110,253,0.25); }
#geoBtn i.bi-crosshair { transition: transform 0.3s var(--t); }
#geoBtn:hover i.bi-crosshair { transform: scale(1.15); }

/* -----------------------------------------------------------------------
   Liste des annonces
----------------------------------------------------------------------- */

#annonces-list { padding: 0; }

#annonces-list .list-group-item,
.annonce-item {
  padding: var(--space-4);
  border-color: var(--color-divider);
  transition: background var(--t), box-shadow var(--t);
}

#annonces-list .list-group-item:hover,
.annonce-item:hover {
  background: var(--color-surface-2);
}

.annonce-list-item {
  cursor: pointer;
}

.annonce-title {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--space-1);
  line-height: 1.3;
}

.annonce-meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}

/* -----------------------------------------------------------------------
   Texte tronqué avec « Lire la suite »
----------------------------------------------------------------------- */

.annonce-description-wrap {
  position: relative;
}

.annonce-description {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.65;
  word-break: break-word;
  margin: 0;
}

/* État tronqué : 3 lignes max */
.annonce-description.is-truncated {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

/* Bouton Lire la suite */
.btn-read-more {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  background: none;
  border: none;
  padding: 0.5rem 0;
  margin-top: 0.15rem;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color var(--t), opacity var(--t);
  min-height: 44px;
  line-height: 1;
}

.btn-read-more:hover  { color: var(--color-primary-hover); opacity: 0.85; }
.btn-read-more:active { opacity: 0.7; }

.btn-read-more i {
  font-size: 0.85em;
  transition: transform var(--t);
}

.btn-read-more.expanded i {
  transform: rotate(180deg);
}

/* -----------------------------------------------------------------------
   Carte Mapbox
----------------------------------------------------------------------- */

#map-container {
  width: 100%;
  /* Mobile : soustraire la bottom-nav (~56 px) en plus du reste */
  height: calc(100vh - 240px);
  min-height: 400px;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

@media (min-width: 768px) {
  #map-container {
    /* Desktop : pas de bottom-nav, on revient à l'offset d'origine */
    height: calc(100vh - 180px);
  }
}

.map-popup { max-width: 240px; }

.map-popup h6 {
  font-size: var(--text-sm);
  font-weight: 700;
  margin-bottom: var(--space-1);
}

.map-popup p {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: 0.2rem;
  line-height: 1.5;
}

.map-popup .popup-email { font-size: var(--text-xs); }

.map-marker {
  width: 36px;
  height: 36px;
  background: var(--color-primary);
  border: 3px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform var(--t), background var(--t);
}

.map-marker:hover {
  background: var(--color-primary-hover);
  transform: rotate(-45deg) scale(1.15);
}

.map-marker-inner {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotate(45deg);
  color: #fff;
  font-size: 0.85rem;
}

/* -----------------------------------------------------------------------
   Bottom Nav Bar
----------------------------------------------------------------------- */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1030;
  display: flex;
  align-items: stretch;
  gap: var(--space-1);
  background: var(--color-surface);
  border-top: 1px solid var(--color-divider);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
  padding: 0 var(--space-1) env(safe-area-inset-bottom, 0);
}

.bottom-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.55rem 0.25rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: color var(--t), background var(--t);
  -webkit-tap-highlight-color: transparent;
  min-height: 56px;
  position: relative;
}

.bottom-nav-btn i { font-size: 1.45rem; line-height: 1; }

.bottom-nav-btn.active { color: var(--color-primary); }

.bottom-nav-btn:hover:not(.active) {
  color: var(--color-primary);
  background: var(--color-primary-light);
}

.bottom-nav-btn:active { background: rgba(13,110,253,0.13); }

/* Indicateur actif : barre en haut */
.bottom-nav-btn.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 3px;
  background: var(--color-primary);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

@media (min-width: 768px) {
  .bottom-nav { display: none; }
  .page-wrap  { padding-bottom: var(--space-8); }
}

/* -----------------------------------------------------------------------
   Message vide
----------------------------------------------------------------------- */

#empty-msg {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  padding: var(--space-10) var(--space-4);
}

/* -----------------------------------------------------------------------
   Responsive : ajustements fins
----------------------------------------------------------------------- */

@media (max-width: 575px) {
  header {
    padding-bottom: var(--space-2) !important;
    margin-bottom: var(--space-3) !important;
  }
  .show-submit-link.btn-primary.ms-md-auto {
    width: 100%;
    justify-content: center;
  }
}

/* Entre 576 px et 991 px : "Ajouter" occupe toute la largeur disponible */
@media (min-width: 576px) and (max-width: 991px) {
  .show-submit-link.btn-primary {
    width: 100%;
    justify-content: center;
  }
}

@media (hover: none) {
  .bottom-nav-btn:hover:not(.active) {
    background: initial;
    color: initial;
  }
  .mapbox-suggestions li:hover {
    background: initial;
  }
}

/* Paysage mobile : carte quasi-plein écran, bottom-nav masquée */
@media (max-height: 500px) and (orientation: landscape) {
  #map-container {
    height: calc(100vh - 60px); /* juste le header de la card */
    min-height: 200px;
  }
  .bottom-nav {
    display: none;
  }
  .page-wrap {
    padding-bottom: var(--space-4);
  }
}
