/* ==========================================================
   JeGereMaLoc THEME v5 - Responsive & harmonisé (desktop + mobile)
   ========================================================== */

/* === Couleurs globales === */
:root {
  --bg: #f7f9f7;
  --card: #ffffff;
  --text: #0b1e0b;
  --muted: #5e6d5e;
  --border: #e2e8e2;
  --green-light: #b9e4c9;
  --green-mid: #5fcf7c;
  --green-dark: #2b8a58;
  --grad: linear-gradient(135deg, var(--green-mid), var(--green-dark));
  --btn: var(--green-dark);
  --btn-hover: #1f573a;
  --danger: #e11d48;
  --ok: #10b981;
}

/* === Mode sombre === */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f120f;
    --card: #1c1f1c;
    --text: #e6f1e6;
    --muted: #a3b9a3;
    --border: #2a352a;
    --green-light: #3ca76a;
    --green-mid: #2b8a58;
    --green-dark: #1e603d;
  }
}

/* === Base === */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}

/* ==========================================================
   HEADER
   ========================================================== */
.header {
  background: var(--grad);
  color: #fff;
  padding: 10px 16px;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
}
.logo {
  height: 44px;
  width: auto;
}
.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
}
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.user-info .btn {
  padding: 8px 14px;
  font-size: 14px;
}

/* ==========================================================
   SIDEBAR
   ========================================================== */
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--grad);
  color: #f0fff6;
  padding: 16px;
  height: calc(100vh - 56px);
  overflow-y: auto;
  position: sticky;
  top: 56px;
  z-index: 10;
  transition: left .3s ease;
}
.sidebar a {
  display: block;
  color: #f0fff6;
  padding: 10px 12px;
  border-radius: 10px;
  transition: background .2s ease;
}
.sidebar a:hover { background: rgba(255,255,255,0.15); }
.sidebar a.active {
  background: #fff;
  color: var(--green-dark);
  font-weight: 700;
}

/* ==========================================================
   LAYOUT / CONTENT
   ========================================================== */
.layout {
  display: flex;
  flex-direction: row;
  min-height: calc(100vh - 56px);
}
.content {
  flex: 1;
  background: var(--bg);
  padding: 24px;
  min-width: 0;
  overflow-x: auto;
  z-index: 1;
}

/* ==========================================================
   FOOTER
   ========================================================== */
.footer {
  background: var(--green-dark);
  color: #f4fff6;
  text-align: center;
  padding: 20px;
  margin-top: 30px;
}

/* ==========================================================
   BUTTONS
   ========================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all .2s ease;
}
.btn.primary {
  background: var(--btn);
  color: #fff;
  border: none;
}
.btn.primary:hover { background: var(--btn-hover); }
.btn.danger {
  background: var(--danger);
  color: #fff;
  border: none;
}
.btn.ghost {
  background: transparent;
  color: var(--green-dark);
  border: 1px solid var(--green-dark);
}
.btn.ghost:hover { background: var(--green-light); }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* Uniformisation de la hauteur */
.btn, input[type="submit"], button {
  min-height: 42px;
  line-height: 1.4;
}

/* ==========================================================
   GRID & FORMS
   ========================================================== */
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.field { display: flex; flex-direction: column; }
.field label {
  font-weight: 600;
  color: var(--green-dark);
  margin-bottom: 4px;
}
.field input, .field select, .field textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  background: var(--card);
  width: 100%;
}
.field textarea { resize: vertical; min-height: 80px; }

.actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

/* ==========================================================
   TABLES
   ========================================================== */
.table-wrapper { width: 100%; overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}
.table th, .table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}
.table th {
  text-transform: uppercase;
  font-weight: 600;
  color: var(--green-dark);
  background: #f5f9f5;
}
.table tr:hover td { background: rgba(0,0,0,0.02); }

/* ==========================================================
   BADGES & TOOLBAR
   ========================================================== */
.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px;
  background: #e6f5ec;
  color: #2b855e;
  font-weight: 600;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

/* ==========================================================
   RESPONSIVE
   ========================================================== */
@media (max-width: 1024px) {
  .layout { flex-direction: column; }
  .content { padding: 16px; max-width: 100%; }
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .menu-toggle { display: inline-block; }
  .sidebar {
    position: fixed;
    top: 56px;
    left: -100%;
    width: 220px;
    height: calc(100vh - 56px);
    z-index: 200;
    transition: left .3s ease;
  }
  body.menu-open .sidebar { left: 0; }
  body.menu-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 150;
  }
  .content {
    padding: 12px;
    width: 100%;
  }
  .btn { width: 100%; justify-content: center; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .form-row { grid-template-columns: 1fr; }
  .actions { justify-content: center; width: 100%; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .table { min-width: unset; font-size: 13px; }
  .table.responsive thead { display: none; }
  .table.responsive tr {
    display: block;
    margin-bottom: 10px;
    border-bottom: 2px solid var(--border);
  }
  .table.responsive td {
    display: flex;
    justify-content: space-between;
    padding: 8px 10px;
    border: none;
  }
  .table.responsive td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--green-dark);
  }
}
/* Icônes seules sur mobile : ne s'applique qu'aux boutons .btn.icon */
@media (max-width: 768px) {
  .btn.icon span {
    display: none;
  }
  .btn.icon i {
    font-size: 18px;
  }
  .btn.icon {
    min-width: 42px;
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 50%;
    justify-content: center;
  }

  /* Boutons textuels : largeur et lisibilité adaptées */
  .btn:not(.icon) {
    width: 100%;
    max-width: 300px;
    font-size: 1rem;
    padding: 12px 18px;
    white-space: nowrap;
  }
}
/* === BOUTON DÉCONNEXION === */
.logout-btn {
  background: var(--danger);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.3s;
  text-decoration: none;
}
.logout-btn:hover {
  background: #b91c3a;
}

/* Texte du nom utilisateur */
.username {
  color: #fff;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* === Mode mobile : icône seule pour déconnexion === */
@media (max-width: 768px) {
  .logout-btn span {
    display: none; /* Cache le texte */
  }
  .logout-btn {
    padding: 10px;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    justify-content: center;
  }
  .logout-btn i {
    font-size: 18px;
  }
  .username {
    display: none; /* Cache le nom utilisateur sur mobile pour alléger */
  }
}
