/* ============================================================
   Ma Commune Back-Office — Feuille de style principale
   ============================================================ */

/* --- Variables & Reset ------------------------------------ */
:root {
  --primary:     #174b3a;
  --primary-dark:#0e3127;
  --primary-light:#dcebdd;
  --secondary:   #2d6f86;
  --accent:      #d2a13a;
  --laterite:    #a64b2a;
  --success:     #2f7d50;
  --warning:     #d48b2c;
  --danger:      #c94b3c;
  --info:        #2d6f86;
  --gray-50:     #f4f1e7;
  --gray-100:    #efe7d7;
  --gray-200:    #d8d0c2;
  --gray-400:    #8d958f;
  --gray-600:    #5e6c67;
  --gray-800:    #183229;
  --white:       #ffffff;
  --sidebar-w:   260px;
  --header-h:    64px;
  --radius:      18px;
  --shadow:      0 10px 24px rgba(14,49,39,.08);
  --shadow-md:   0 20px 50px rgba(14,49,39,.16);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Manrope', system-ui, sans-serif;
  background:
    radial-gradient(circle at top right, rgba(210,161,58,.12), transparent 28%),
    linear-gradient(180deg, #f7f3ea 0%, var(--gray-50) 100%);
  color: var(--gray-800);
  font-size: 14px;
  line-height: 1.6;
}
body.nav-open { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

.category-mark {
  --category-accent: #174b3a;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: color-mix(in srgb, var(--category-accent) 12%, #fff);
  border: 1px solid color-mix(in srgb, var(--category-accent) 26%, #fff);
  box-shadow: 0 10px 24px rgba(14,49,39,.08);
  overflow: hidden;
}
.category-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.category-mark--sm { width: 40px; height: 40px; border-radius: 13px; }
.category-mark--md { width: 52px; height: 52px; border-radius: 16px; }
.category-mark--lg { width: 68px; height: 68px; border-radius: 22px; }

.category-preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.category-preset {
  position: relative;
  border: 1px solid #e6decf;
  border-radius: 18px;
  padding: 12px;
  background: #fffdf8;
  cursor: pointer;
  transition: border-color .15s, transform .15s, box-shadow .15s, background .15s;
}
.category-preset:hover {
  border-color: var(--primary);
  box-shadow: 0 12px 26px rgba(14,49,39,.08);
  transform: translateY(-1px);
}
.category-preset.is-selected {
  border-color: var(--primary);
  background: #f7fbf9;
  box-shadow: 0 14px 28px rgba(23,75,58,.12);
}
.category-preset input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.category-preset-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.category-preset-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
}
.category-preset-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--gray-800);
  margin-bottom: 4px;
}
.category-preset-text {
  font-size: 12px;
  color: var(--gray-600);
  line-height: 1.45;
}

/* --- Layout ------------------------------------------------ */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background:
    radial-gradient(circle at top, rgba(210,161,58,.16), transparent 26%),
    linear-gradient(180deg, #0e3127 0%, #174b3a 52%, #2d6f86 100%);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  flex: 0 0 48px;
  box-shadow: 0 8px 18px rgba(0,0,0,.18);
}
.sidebar-brand .brand-name {
  color: #fff;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: .3px;
  font-family: 'Merriweather', serif;
}
.sidebar-brand .brand-sub  { color: #d7e7df; font-size: 11px; }
.brand-territory {
  color: rgba(255,255,255,.6);
  font-size: 10px;
  margin-top: 2px;
  letter-spacing: .8px;
  text-transform: uppercase;
}

.sidebar-nav { flex: 1; padding: 16px 12px; }
.nav-section-title {
  color: var(--gray-400); font-size: 10px; font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase;
  padding: 12px 8px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 12px;
  color: #cbd5e1; font-weight: 500;
  transition: background .15s, color .15s;
  margin-bottom: 2px;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-item.active {
  background: rgba(255,255,255,.13);
  color: #fff;
  border: 1px solid rgba(255,255,255,.14);
}
.nav-item .nav-icon { font-size: 18px; width: 22px; text-align: center; }
.nav-item .nav-badge {
  margin-left: auto; background: var(--danger);
  color: #fff; font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: 20px;
}

.sidebar-footer {
  padding: 16px; border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-user { display: flex; align-items: center; gap: 10px; }
.sidebar-user .avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,.18); display: flex;
  align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px;
}
.sidebar-user .user-name  { color: #fff; font-weight: 600; font-size: 13px; }
.sidebar-user .user-role  { color: var(--gray-400); font-size: 11px; }
.sidebar-user .logout-btn {
  margin-left: auto; color: var(--gray-400);
  font-size: 18px; cursor: pointer;
  transition: color .15s;
}
.sidebar-user .logout-btn:hover { color: var(--danger); }

/* Main content */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

/* Top header */
.topbar {
  min-height: var(--header-h); background: rgba(255,252,246,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center;
  padding: 0 28px; gap: 16px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1;
}
.topbar-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--gray-200);
  border-radius: 14px;
  background: rgba(255,255,255,.92);
  color: var(--gray-800);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(14,49,39,.08);
}
.topbar-menu-btn:hover {
  background: var(--gray-50);
}
.topbar-heading { flex: 1; padding: 14px 0; }
.topbar-kicker {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--primary);
  font-weight: 800;
}
.topbar-title {
  font-size: 24px;
  font-weight: 900;
  color: var(--gray-800);
  font-family: 'Merriweather', serif;
  line-height: 1.2;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 999px;
  background: var(--gray-100);
  color: var(--gray-600);
}
.topbar-separator { opacity: .45; }
.quick-search-form { display:flex; align-items:center; }
.quick-search-input {
  padding: 9px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: 999px;
  font-size: .85rem;
  width: 240px;
  outline: none;
  background: rgba(255,255,255,.85);
}
.quick-search-input:focus {
  border-color: var(--secondary);
  box-shadow: 0 0 0 4px rgba(45,111,134,.12);
}

/* Page content */
.page-content { padding: 28px; flex: 1; }
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  border: none;
  background: rgba(14,49,39,.45);
  z-index: 90;
}

.page-hero {
  background:
    linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 58%, var(--secondary) 100%);
  color: #fff;
  border-radius: 28px;
  padding: 28px;
  margin-bottom: 24px;
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 18px;
  box-shadow: var(--shadow-md);
}
.page-hero-kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #f2d58c;
  font-weight: 800;
  margin-bottom: 8px;
}
.page-hero-title {
  font-size: 30px;
  line-height: 1.15;
  font-family: 'Merriweather', serif;
  font-weight: 900;
  margin-bottom: 12px;
}
.page-hero-text {
  max-width: 620px;
  color: rgba(255,255,255,.84);
  font-size: 14px;
}
.page-hero-metrics {
  display: grid;
  gap: 10px;
  align-content: center;
}
.hero-chip {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 18px;
  padding: 14px 16px;
}
.hero-chip-value {
  display: block;
  font-size: 24px;
  font-weight: 900;
}
.hero-chip-label {
  display: block;
  font-size: 12px;
  color: rgba(255,255,255,.76);
  margin-top: 4px;
}

/* --- Cards ------------------------------------------------- */
.card {
  background: rgba(255,253,248,.92); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px;
  margin-bottom: 24px;
  border: 1px solid #ece4d5;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; padding-bottom: 16px;
  border-bottom: 1px solid var(--gray-200);
}
.card-title { font-size: 16px; font-weight: 700; color: var(--gray-800); }

/* --- Stats KPI --------------------------------------------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 28px; }
.stat-card {
  background: rgba(255,253,248,.92); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 24px;
  display: flex; align-items: center; gap: 16px;
  border: 1px solid #ece4d5;
}
.stat-icon {
  width: 52px; height: 52px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; flex-shrink: 0;
}
.stat-icon.canopy   { background: #dcebdd; }
.stat-icon.leaf     { background: #dcebdd; }
.stat-icon.awara    { background: #f4e2b2; }
.stat-icon.river    { background: #dce6ea; }
.stat-icon.sand     { background: #efe7d7; }
.stat-icon.laterite { background: #edd7cf; }
.stat-value { font-size: 28px; font-weight: 800; color: var(--gray-800); line-height: 1; }
.stat-label { font-size: 13px; color: var(--gray-600); margin-top: 4px; }

/* --- Tables ------------------------------------------------ */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: #f8f3e8; padding: 10px 14px;
  text-align: left; font-size: 12px; font-weight: 700;
  color: var(--gray-600); text-transform: uppercase;
  letter-spacing: .5px; border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
tbody tr:hover { background: #fbf7ef; }
tbody tr:last-child td { border-bottom: none; }

/* --- Badges ------------------------------------------------ */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-blue   { background: #dce6ea; color: #2d6f86; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-yellow { background: #f4e2b2; color: #9f6816; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-purple { background: #edd7cf; color: #8d3f23; }

/* --- Buttons ----------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 12px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  border: none; transition: opacity .15s, transform .1s;
  text-decoration: none;
}
.btn:hover { opacity: .88; text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-success   { background: var(--success); color: #fff; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-danger    { background: var(--danger);  color: #fff; }
.btn-outline   { background: transparent; border: 1.5px solid var(--gray-200); color: var(--gray-800); }
.btn-sm        { padding: 5px 12px; font-size: 12px; }
.btn-icon      { padding: 7px; border-radius: 8px; }

/* --- Forms ------------------------------------------------- */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-800); margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--gray-200); border-radius: 14px;
  font-size: 14px; color: var(--gray-800);
  background: rgba(255,252,246,.92); transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--secondary); box-shadow: 0 0 0 4px rgba(45,111,134,.12); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 90px; }

/* --- Filters bar ------------------------------------------ */
.filters-bar {
  display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap; margin-bottom: 20px;
}
.filters-bar .form-control { width: auto; min-width: 160px; }
.search-input { min-width: 240px !important; }

/* --- Pagination ------------------------------------------- */
.pagination { display: flex; align-items: center; gap: 4px; margin-top: 20px; }
.page-btn {
  padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: 500;
  border: 1.5px solid var(--gray-200); background: var(--white);
  color: var(--gray-800); cursor: pointer; text-decoration: none;
  transition: background .15s;
}
.page-btn:hover { background: var(--gray-100); text-decoration: none; }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-btn.disabled { opacity: .4; pointer-events: none; }

/* --- Alerts ----------------------------------------------- */
.alert {
  padding: 12px 16px; border-radius: 8px; margin-bottom: 20px;
  font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 10px;
}
.alert-success { background: #dcfce7; color: #15803d; border-left: 4px solid var(--success); }
.alert-danger  { background: #fee2e2; color: #b91c1c; border-left: 4px solid var(--danger); }
.alert-info    { background: #dbeafe; color: #1d4ed8; border-left: 4px solid var(--info); }
.alert-warning { background: #fef9c3; color: #a16207; border-left: 4px solid var(--warning); }

/* --- Timeline (historique) -------------------------------- */
.timeline { list-style: none; position: relative; padding-left: 24px; }
.timeline::before { content:''; position:absolute; left:8px; top:0; bottom:0; width:2px; background:var(--gray-200); }
.timeline-item { position: relative; padding-bottom: 20px; }
.timeline-dot {
  position: absolute; left: -20px; top: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--primary); border: 2px solid var(--white);
  box-shadow: 0 0 0 2px var(--primary);
}
.timeline-content { background: var(--gray-50); border-radius: 8px; padding: 12px 14px; }
.timeline-meta { font-size: 12px; color: var(--gray-400); margin-top: 4px; }

/* --- Login page ------------------------------------------- */
.login-page {
  min-height: 100vh; display: flex;
  align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(210,161,58,.18), transparent 28%),
    linear-gradient(135deg, #0e3127 0%, #174b3a 52%, #2d6f86 100%);
}
.login-card {
  background: rgba(255,252,246,.96); border-radius: 28px;
  padding: 40px; width: 100%; max-width: 420px;
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(255,255,255,.22);
}
.login-kicker {
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--primary);
  margin-bottom: 14px;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .logo-icon {
  width: 88px;
  height: 88px;
  margin: 0 auto 10px;
  display: block;
  border-radius: 24px;
  box-shadow: 0 16px 34px rgba(14,49,39,.18);
}
.login-logo .logo-name {
  font-size: 30px;
  font-weight: 900;
  color: var(--primary);
  letter-spacing: .8px;
  font-family: 'Merriweather', serif;
}
.login-logo .logo-sub  { font-size: 13px; color: var(--gray-600); }
.login-intro {
  background: var(--gray-100);
  color: var(--gray-600);
  border-radius: 18px;
  padding: 14px 16px;
  margin-bottom: 20px;
  font-size: 13px;
  line-height: 1.6;
}
.login-footnote {
  text-align: center;
  margin-top: 20px;
  font-size: 12px;
  color: var(--gray-400);
}

/* --- Charts placeholder ----------------------------------- */
.chart-container { position: relative; height: 280px; }

/* --- Responsive ------------------------------------------- */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 20px 44px rgba(14,49,39,.24);
  }
  body.nav-open .sidebar {
    transform: translateX(0);
  }
  body.nav-open .sidebar-overlay {
    display: block;
  }
  .main { margin-left: 0; }
  .topbar {
    padding: 0 20px;
    gap: 12px;
  }
  .topbar-menu-btn {
    display: inline-flex;
  }
  .topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .quick-search-form {
    width: min(280px, 100%);
  }
  .quick-search-input {
    width: 100%;
  }
  .page-content {
    padding: 20px;
  }
  .page-hero {
    grid-template-columns: 1fr;
    padding: 22px;
  }
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px 16px;
  }
  .topbar-left,
  .topbar-actions {
    width: 100%;
  }
  .topbar-actions {
    justify-content: flex-start;
  }
  .topbar-meta {
    width: 100%;
    justify-content: center;
  }
  .quick-search-form {
    display: flex;
    width: 100%;
  }
  .filters-bar {
    align-items: stretch;
  }
  .filters-bar .form-control,
  .search-input {
    width: 100% !important;
    min-width: 0 !important;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .pagination {
    flex-wrap: wrap;
  }
  .btn {
    min-height: 44px;
  }
  .page-content {
    padding: 16px;
  }
  .card,
  .login-card {
    padding: 18px;
  }
  .table-wrapper {
    overflow-x: auto;
  }
  .truncate {
    max-width: 180px;
  }
}

/* --- Misc -------------------------------------------------- */
.text-muted   { color: var(--gray-400); }
.text-small   { font-size: 12px; }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.fw-bold      { font-weight: 700; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.gap-8 { gap: 8px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.w-100 { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
