/* ==========================================================================
   1. Thème et Variables
   ========================================================================== */

:root {

  --primary: #c5a47e;
  --primary-hover: #b48c62;
  --bg: #f8f9fa;
  --panel: #ffffff;
  --text: #212529;
  --muted: #6c757d;
  --card-br: #e9ecef;
  --table-head: #f1f3f5;
  --ring: rgba(197, 164, 126, 0.3);

  /* Couleurs sémantiques */
  --success-bg: #e6f9f0;
  --success-br: #a6e3c5;
  --success-text: #0a5c34;
  --error-bg: #fff0f0;
  --error-br: #ffc9c9;
  --error-text: #c92a2a;
}

/* ==========================================================================
   2. Styles Globaux et Typographie
   ========================================================================== */

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Montserrat', ui-sans-serif, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  letter-spacing: -0.5px;
}

/* ==========================================================================
   3. Composants de l'interface (UI)
   ========================================================================== */

/* --- Barre de navigation --- */
header {
  position: sticky; top: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--card-br);
  z-index: 10;
}

.nav {
  max-width: 1100px;
  margin: 0 auto;
  padding: .9rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
}

.brand-logo {
  height: 32px;
  width: auto;
  vertical-align: middle;
}

.brand-name {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}

.links {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

/* Style des liens de navigation */
.links a {
  color: var(--text);
  text-decoration: none;
  padding: .45rem .8rem;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: all .2s ease-in-out;
  font-weight: 500;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.links a:hover {
  background: #f1f3f5;
  color: var(--primary-hover);
}
/* Conteneur pour les actions de l'utilisateur (login/logout) */
.nav-user-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-email {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0.45rem 0.7rem;
  margin: 0 0.5rem;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--card-br);
  font-weight: 500;
}

/* --- Boutons --- */
.btn {
    appearance: none;
    border: 1px solid transparent;
    background: var(--primary);
    color: white;
    padding: .7rem 1.2rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s ease-in-out;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0,0,0,.1);
}

.btn.secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--card-br);
}

.btn.secondary:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.btn.small {
  padding: .4rem .8rem;
  font-size: .85rem;
}

/* --- Conteneurs et Cartes --- */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.25rem;
    position: relative;
    z-index: 5;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--card-br);
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,.05);
    position: relative;
    z-index: 5;
}

.card {
  padding: 1.25rem;
  border-radius: 16px;
  border: 1px solid var(--card-br);
  background: var(--panel);
}

/* --- Tableaux --- */
.tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--card-br);
}

.tbl thead th {
  background: var(--table-head);
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--card-br);
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tbl thead th:not(:first-child) {
  border-left: 1px solid var(--card-br);
}

.tbl tbody td {
  padding: 14px;
  border-bottom: 1px solid var(--card-br);
}

.tbl tbody td:not(:first-child) {
  border-left: 1px solid var(--card-br);
}

.tbl tbody tr:last-child td {
  border-bottom: none;
}

.tbl tbody tr:hover td {
  background: #f8f9fa;
}

/* --- Formulaires --- */
.form-input {
  width: 100%;
  padding: .7rem .8rem;
  margin-top: .3rem;
  border-radius: 8px;
  border: 1px solid var(--card-br);
  transition: all .2s ease-in-out;
  font-family: 'Montserrat', sans-serif;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

/* --- Messages Flash --- */
.flash {
  padding: 1rem 1.2rem;
  border-radius: 12px;
  margin: 1rem 0;
  border: 1px solid;
  font-weight: 500;
}

.flash.success { background: var(--success-bg); border-color: var(--success-br); color: var(--success-text); }
.flash.error { background: var(--error-bg); border-color: var(--error-br); color: var(--error-text); }
.flash.warning { background: #fffbeb; border-color: #fde047; color: #b45309; }

/* --- Overlay de chargement --- */
#loading-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background-color: rgba(33, 37, 41, 0.7);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  color: var(--text);
}

.loading-box {
  background: var(--panel);
  padding: 2rem 3rem;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 10px 24px rgba(0,0,0,.1);
}

.loading-box p {
  margin: 0.5rem 0 0 0;
  font-weight: 500;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 5px solid #e9ecef;
  border-top: 5px solid var(--primary);
  border-radius: 50%;
  margin: 0 auto 1rem auto;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Utilitaires */
.muted {
  color: var(--muted);
}

/* ==========================================================================
   4. Styles Spécifiques aux Pages
   ========================================================================== */

/* --- Page d'Upload --- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: 2.5rem;
  border: 2px dashed var(--card-br);
  border-radius: 16px;
  background: var(--bg);
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: all .2s ease-in-out;
}

.dropzone.dragover {
  border-color: var(--primary);
  background: #fdfaf6;
}

/* Conteneurs pour les deux états (prompt vs display) */
#upload-prompt, #file-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

#file-display {
  flex-direction: row;
  justify-content: space-between;
  text-align: left;
}

.file-details {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.file-info {
  display: flex;
  flex-direction: column;
}

.file-name {
  font-weight: 600;
  color: var(--text);
}

.file-size {
  font-size: 0.9rem;
  color: var(--muted);
}

.upload-icon {
  width: 48px;
  height: 48px;
  color: var(--primary);
  stroke-width: 1.5;
}

.file-icon {
  width: 40px;
  height: 40px;
  color: #1d6f42;
}

.remove-file-btn {
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0.5rem;
}
.remove-file-btn:hover {
  color: var(--error-text);
}

/* Style pour le bouton désactivé */
.btn:disabled {
  background: var(--card-br);
  color: var(--muted);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* --- Composants UI Spécifiques --- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: .5rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--card-br);
  background: var(--panel);
  font-size: 0.95rem;
  text-decoration: none;
  color: var(--text);
  transition: all .2s ease-in-out;
}

.chip:hover {
  background: #f1f3f5;
  border-color: var(--primary);
  transform: translateY(-1px);
}

/* C'est la règle la plus importante pour corriger la taille */
.chip .icon {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

/* ==========================================================================
   5. Responsive & Mobile-First
   ========================================================================== */

/* --- Styles par défaut (Mobile) --- */

/* Cacher la navigation de bureau par défaut */
.nav-links-desktop {
  display: none;
}

/* Style du bouton Hamburger */
.hamburger-btn {
  display: block; /* Visible sur mobile */
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  z-index: 1001; /* Doit être au-dessus du menu et de l'overlay */
}
.hamburger-btn svg {
  width: 28px;
  height: 28px;
  color: var(--text);
}

#icon-close {
  display: none; /* Par défaut, on cache l'icône de fermeture */
}

body.menu-open #icon-menu {
  display: none; /* Quand le menu est ouvert, on cache l'icône du menu... */
}

body.menu-open #icon-close {
  display: block; /* affiche l'icône de fermeture */
}

/* Style du menu mobile (le drawer) */
.mobile-menu {
  position: fixed;
  top: 0;
  right: 0;
  width: 280px;
  height: 100%;
  background: var(--panel);
  box-shadow: -5px 0 15px rgba(0,0,0,0.1);
  padding: 6rem 1.5rem 2rem 1.5rem;
  z-index: 1000;
  transform: translateX(100%); /* Caché hors de l'écran */
  transition: transform 0.3s ease-in-out;
  display: flex;
  flex-direction: column; /* Liens les uns en dessous des autres */
  gap: 1rem;
}
.mobile-menu a {
  font-size: 1.1rem;
  font-weight: 600;
  padding: 0.75rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
}
.mobile-menu a:hover {
  background: var(--bg);
}

/* Overlay de l'arrière-plan */
.menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
}

/* État 'ouvert' (quand la classe .menu-open est ajoutée au body) */
body.menu-open .mobile-menu {
  transform: translateX(0); /* Fait apparaître le menu */
}
body.menu-open .menu-overlay {
  opacity: 1;
  visibility: visible; /* Rend l'overlay visible */
}

/* Amélioration pour la scrollbar des tableaux sur mobile */
.card-table-container {
    overflow-x: auto;
}

.mobile-menu-footer {
  margin-top: auto; /* Pousse ce bloc en bas du menu mobile */
  padding-top: 1.5rem;
  border-top: 1px solid var(--card-br);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.mobile-menu-footer .user-email {
  text-align: center;
}

/* Amélioration pour les grilles sur mobile */
@media (max-width: 768px) {
    .grid.cols-2 {
        grid-template-columns: 1fr;
    }
}

/* --- Formulaire de Filtres (Page des Biens) --- */

/* Styles par défaut (Mobile) : tout est empilé verticalement */
.filter-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.filter-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.filter-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* On retire la marge des inputs pour un meilleur alignement */
.filter-inputs .form-input {
  margin-top: 0;
  margin-bottom: 0;
}

/* --- Styles pour Tablettes et plus grand --- */
@media (min-width: 992px) {
  /* Cacher les éléments mobiles */
  .hamburger-btn,
  .mobile-menu,
  .menu-overlay {
    display: none;
  }

  /* Afficher la navigation de bureau */
  .nav-links-desktop {
    display: flex;
    align-items: center;
    width: 100%;
  }

  .nav-user-actions {
    margin-left: auto; /* Pousse les actions à droite */
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  .nav-links-desktop a {
      color: var(--text);
      text-decoration: none;
      padding: .45rem .8rem;
      border-radius: 8px;
      border: 1px solid transparent;
      transition: all .2s ease-in-out;
      font-weight: 500;
      letter-spacing: 0.5px;
      white-space: nowrap;
  }

  .nav-links-desktop a:hover {
      background: #f1f3f5;
      color: var(--primary-hover);
  }

  .filter-form {
    flex-direction: row; /* Bureau: aligne les sections sur une ligne */
    justify-content: space-between;
    align-items: flex-end; /* Aligne les boutons avec le bas des champs */
  }

  .filter-inputs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    flex-grow: 1; /* Permet aux champs de prendre l'espace disponible */
    margin-right: 1rem;
  }

  .filter-actions {
    flex-direction: row; /* Bureau: aligne les boutons sur une ligne */
    gap: 0.75rem;
  }
}