/* ─── Reset & Base ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:    #2d5a27;
  --green-lt: #dcfce7;
  --red:      #c0392b;
  --red-lt:   #fdecea;
  --blue:     #1a6fa8;
  --blue-lt:  #e8f2fb;
  --orange:   #d35400;
  --orange-lt:#fef3ec;
  --purple:   #6c3483;
  --purple-lt:#f5eef8;
  --teal:     #1a7a6e;
  --teal-lt:  #e8f8f5;
  --gray:     #6b7280;
  --gray-lt:  #f3f4f6;
  --border:   #e2e8f0;
  --text:     #0f172a;
  --text-muted: #64748b;
  --sidebar-w: 240px;
  --sidebar-bg: #2d5a27;
  --card-bg:    #ffffff;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: #1f2937;
  color: var(--text);
  background: #f9fafb;
  display: -webkit-flex;
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ───────────────────────────────────── */
.sidebar {
  width: 240px;
  width: var(--sidebar-w);
  background: #1a2e1f;
  background: var(--sidebar-bg);
  color: #d1fae5;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  padding: 0 0 12px;
  z-index: 100;
  display: flex;
  flex-direction: column;
}
.sidebar-bottom {
  margin-top: auto;
  border-top: 1px solid rgba(255,255,255,.1);
  padding-top: 4px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  margin-bottom: 8px;
}
.brand-icon { font-size: 28px; }
.brand-title { font-weight: 700; font-size: 13px; color: #fff; line-height: 1.2; }
.brand-sub   { font-size: 11px; color: #86efac; }

.nav-section { margin-top: 8px; }
.nav-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6ee7b7;
  padding: 10px 16px 4px;
}
.nav-toggle {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  padding-right: 14px;
  transition: color .15s;
}
.nav-toggle:hover { color: #a7f3d0; }
.nav-toggle:focus { outline: 2px solid #6ee7b7; outline-offset: -2px; border-radius: 4px; color: #a7f3d0; }
.nav-chevron {
  font-size: 12px;
  transition: transform .2s ease;
  display: inline-block;
}
.nav-collapsible.open .nav-chevron { transform: rotate(180deg); }
.nav-group-body {
  overflow: hidden;
  max-height: 0;
  transition: max-height .25s ease;
}
.nav-collapsible.open .nav-group-body { max-height: 500px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  margin: 1px 8px;
  color: #bbf7d0;
  text-decoration: none;
  border-radius: 6px;
  transition: background .15s, color .15s;
  font-size: 13px;
}
.nav-link:hover  { background: rgba(255,255,255,.1); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 600; }
/* SVG icon support in nav */
.nav-toggle > span:first-child { display: flex; align-items: center; gap: 6px; }
.nav-link svg, .nav-toggle svg { flex-shrink: 0; }
/* Sub-nav items: hide emoji, indent */
.nav-group-body .nav-link { padding-left: 34px; }
.nav-group-body .nav-link .nav-link-icon { display: none; }

.sidebar-user {
  margin: 12px 10px 0;
  padding: 10px 12px;
  background: rgba(255,255,255,.07);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.1);
}
.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.sidebar-user-avatar { font-size: 1.2rem; }
.sidebar-user-name   { font-size: .82rem; font-weight: 600; color: #fff; line-height: 1.2; }
.sidebar-user-role   { font-size: .72rem; color: #86efac; }

/* ─── Main Content ──────────────────────────────── */
.main-content {
  margin-left: 240px;
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  min-width: 0;
}

/* ─── Page Header ───────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -.025em; }

/* ─── Alerts ─────────────────────────────────────── */
.alert {
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-success { background: var(--green-lt);  color: var(--green); border-left: 4px solid var(--green); }
.alert-warning  { background: var(--orange-lt); color: var(--orange); border-left: 4px solid var(--orange); }
.alert-danger   { background: var(--red-lt);    color: var(--red);   border-left: 4px solid var(--red); }
.alert-info     { background: var(--blue-lt);   color: var(--blue);  border-left: 4px solid var(--blue); }

/* ─── Cards ──────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 20px;
  overflow: clip;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--gray-lt);
}
.card-header h2 { font-size: 15px; font-weight: 600; }

/* ─── Stats Grid ─────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.stat-icon  { font-size: 28px; margin-bottom: 8px; }
.stat-value { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

.stat-card.green  { border-top: 3px solid var(--green);  }
.stat-card.red    { border-top: 3px solid var(--red);    }
.stat-card.blue   { border-top: 3px solid var(--blue);   }
.stat-card.orange { border-top: 3px solid var(--orange); }
.stat-card.purple { border-top: 3px solid var(--purple); }
.stat-card.teal   { border-top: 3px solid var(--teal);   }

/* ─── Dashboard Grid ─────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.dashboard-grid .card:last-child { grid-column: 1 / -1; }

/* ─── Table ──────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}
.table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #64748b;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}
.table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: none; }
.table tfoot td {
  padding: 10px 16px;
  border-top: 2px solid var(--border);
  background: var(--gray-lt);
}
.table .actions { text-align: right; white-space: nowrap; }
.row-inactive td { opacity: .55; }

/* ─── Buttons ─────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover       { background: var(--gray-lt); border-color: #d1d5db; }
.btn-primary     { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: #1e401b; border-color: #1e401b; }
.btn-danger      { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #9b2c2c; border-color: #9b2c2c; }
.btn-sm          { padding: 4px 10px; font-size: 12px; }

/* ─── Forms ──────────────────────────────────────── */
.form-card { padding: 24px; }
.form-group { margin-bottom: 16px; display: flex; flex-direction: column; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .04em; }
.form-group small  { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.form-row   { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 16px; }
.form-actions { margin-top: 24px; display: flex; gap: 8px; align-items: center; }
.form-control {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 14px;
  width: 100%;
  transition: border-color .15s;
  background: #fff;
}
.form-control:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(45,90,39,.12); }
textarea.form-control { resize: vertical; }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 20px;
  align-items: flex-end;
}
.inline-form .form-control { width: auto; flex: 1; min-width: 130px; }

.search-bar {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}
.search-bar .form-control { max-width: 380px; }

.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--gray-lt);
}

/* ─── Detail Meta ─────────────────────────────────── */
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  padding: 16px 20px;
}
.meta-item {
  display: flex;
  flex-direction: column;
  min-width: 150px;
  padding: 8px 20px 8px 0;
}
.meta-item span   { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: 2px; }
.meta-item strong { font-size: 15px; }

/* ─── Badges ─────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  background: var(--blue-lt);
  color: var(--blue);
}
.badge-grey { background: var(--gray-lt); color: var(--gray); }

/* ─── Pagination ─────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px;
  border-top: 1px solid var(--border);
}
.page-info { font-size: 13px; color: var(--text-muted); }

/* ─── Utilities ──────────────────────────────────── */
.muted    { color: var(--text-muted); }
.center   { text-align: center; }
.green    { color: var(--green); }
.red      { color: var(--red); }
.amount-large { font-size: 20px; font-weight: 700; color: var(--green); }
.comment-block {
  padding: 10px 20px;
  background: var(--gray-lt);
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
}
code {
  background: var(--gray-lt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: monospace;
  font-size: 12px;
}

/* ─── Page subtitle ─────────────────────────────── */
.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
  font-weight: 400;
}

/* ─── KPI Strip (purchases & other pages) ────────── */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.kpi-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.kpi-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.kpi-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.025em;
  color: var(--text);
  line-height: 1.2;
}
.kpi-unit {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ─── Sidebar Paramètres section ────────────────── */
.sidebar-params {
  border-top: 1px solid rgba(255,255,255,.1);
  padding: 8px 0 4px;
  margin-top: 4px;
}
.sidebar-params-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6ee7b7;
  padding: 10px 16px 4px;
}

/* ─── Sidebar user avatar (initials) ────────────── */
.sidebar-user-avatar-initials {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ─── Collapsible filter panel ───────────────────── */
.filters-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.25rem;
  cursor: pointer;
  user-select: none;
}
.filters-toggle:hover { background: var(--gray-lt); border-radius: var(--radius); }
.filters-toggle-left {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
}
.filters-toggle-chevron {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .82rem;
  color: var(--text-muted);
}
.filters-panel-body {
  padding: .75rem 1.25rem 1rem;
  border-top: 1px solid var(--border);
}

/* ─── Category pill bar ──────────────────────────── */
.cat-pill-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--border);
}
.cat-pill {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .28rem .7rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  background: #f1f5f9;
  color: #475569;
  transition: background .12s, color .12s;
}
.cat-pill:hover:not(.active) { background: #e2e8f0; color: #334155; }
.cat-pill.active { color: #fff; }
.cat-pill-count { opacity: .58; font-weight: 400; font-size: .9em; }

/* ─── Purchases table header hierarchy ───────────── */
.purchases-table thead th.th-primary {
  font-weight: 700;
  color: var(--text);
  font-size: .73rem;
  text-transform: uppercase;
  letter-spacing: .055em;
}
.purchases-table thead th.th-secondary {
  font-weight: 500;
  color: var(--text-muted);
  font-size: .73rem;
  text-transform: uppercase;
  letter-spacing: .055em;
}

/* ─── Category color bar (table row) ────────────── */
.cat-color-bar {
  display: inline-block;
  width: 3px;
  height: 20px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ─── Row actions (hover-only) ───────────────────── */
.purchase-row .row-actions { opacity: 0; transition: opacity .15s; }
.purchase-row:hover .row-actions { opacity: 1; }
.data-row .row-actions { opacity: 0; transition: opacity .15s; }
.data-row:hover .row-actions { opacity: 1; }

/* ─── Mobile header (hamburger) ─────────────────── */
.mobile-header {
  display: none;
  -webkit-align-items: center;
  align-items: center;
  gap: 12px;
  background: #1a2e1f;
  background: var(--sidebar-bg);
  color: #fff;
  padding: 12px 16px;
  margin: -16px -16px 16px;
}
.hamburger-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.hamburger-btn:hover { background: rgba(255,255,255,.12); }
.mobile-header-title { font-weight: 700; font-size: 14px; }

/* ─── Sidebar overlay backdrop ──────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 99;
}
.sidebar-overlay.open { display: block; }

/* ─── Responsive tablette (769px – 1024px) ───────── */
@media (min-width: 769px) and (max-width: 1024px) {
  .main-content {
    padding: 16px 20px;
    max-width: 100%;
  }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

/* ─── Responsive mobile (≤ 768px) ───────────────── */
@media (max-width: 768px) {
  .sidebar {
    -webkit-transform: translateX(-100%);
    transform: translateX(-100%);
    -webkit-transition: -webkit-transform .25s ease;
    transition: transform .25s ease;
    width: 260px;
    z-index: 100;
  }
  .sidebar.open {
    -webkit-transform: translateX(0);
    transform: translateX(0);
  }

  .main-content { margin-left: 0; padding: 16px; }
  .mobile-header { display: -webkit-flex; display: flex; }

  .dashboard-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
