/* ===== RESET & BASE ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --brand: #0a5c36;
  --brand-light: #0f7a49;
  --brand-xlight: #e6f4ed;
  --accent: #f0a500;
  --accent-light: #fff8e6;
  --danger: #d93025;
  --danger-light: #fce8e6;
  --success: #1e8e3e;
  --success-light: #e6f4ea;
  --neutral-50: #f8f9fa;
  --neutral-100: #f1f3f4;
  --neutral-200: #e8eaed;
  --neutral-300: #dadce0;
  --neutral-500: #9aa0a6;
  --neutral-700: #5f6368;
  --neutral-900: #1a1a2e;
  --sidebar-w: 260px;
  --topbar-h: 64px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.12);
}

body {
  font-family: 'Space Grotesk', sans-serif;
  background: var(--neutral-100);
  color: var(--neutral-900);
  overflow-x: hidden;
}

/* ===== APP SHELL ===== */
.app { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--neutral-900);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: width .3s ease;
  z-index: 100;
  flex-shrink: 0;
}

.sidebar.collapsed { width: 72px; }
.sidebar.collapsed .nav-label,
.sidebar.collapsed .logo-title,
.sidebar.collapsed .logo-sub,
.sidebar.collapsed .user-name,
.sidebar.collapsed .user-role,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .nav-badge { display: none; }
.sidebar.collapsed .logo { justify-content: center; }
.sidebar.collapsed .nav-btn { justify-content: center; padding: 14px; }
.sidebar.collapsed .user-info { justify-content: center; }

.sidebar-header {
  padding: 20px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon {
  width: 40px; height: 40px;
  background: var(--brand-light);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: white;
  flex-shrink: 0;
}
.logo-title { color: white; font-weight: 700; font-size: 16px; line-height: 1.2; }
.logo-sub { color: rgba(255,255,255,.45); font-size: 11px; font-weight: 400; }

.sidebar-toggle {
  background: none; border: none; color: rgba(255,255,255,.5);
  cursor: pointer; font-size: 18px; padding: 4px;
}
.sidebar-toggle:hover { color: white; }

.nav { flex: 1; padding: 16px 12px; }

.nav-section-label {
  font-size: 10px; font-weight: 600; letter-spacing: 1.2px;
  color: rgba(255,255,255,.3); padding: 12px 8px 6px;
  text-transform: uppercase;
}

.nav-btn {
  width: 100%; display: flex; align-items: center; gap: 12px;
  background: none; border: none; color: rgba(255,255,255,.65);
  padding: 11px 12px; border-radius: 8px; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 500;
  transition: all .2s; text-align: left; margin-bottom: 2px;
  position: relative;
}
.nav-btn:hover { background: rgba(255,255,255,.07); color: white; }
.nav-btn.active { background: var(--brand-light); color: white; }
.nav-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }

.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: var(--neutral-900);
  font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 20px; min-width: 22px; text-align: center;
}
.nav-badge.danger { background: var(--danger); color: white; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.user-info { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--brand-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: white; flex-shrink: 0;
}
.user-name { color: white; font-size: 13px; font-weight: 600; }
.user-role { color: rgba(255,255,255,.4); font-size: 11px; }

/* ===== MAIN ===== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-h);
  background: white;
  border-bottom: 1px solid var(--neutral-200);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  position: sticky; top: 0; z-index: 50;
}
.page-title { font-size: 20px; font-weight: 700; color: var(--neutral-900); }
.breadcrumb { font-size: 12px; color: var(--neutral-500); margin-top: 2px; }

.topbar-right { display: flex; align-items: center; gap: 14px; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--neutral-100); border: 1px solid var(--neutral-200);
  border-radius: 8px; padding: 8px 14px; width: 260px;
}
.search-box input {
  border: none; background: none; outline: none;
  font-family: inherit; font-size: 13px; width: 100%;
}
.date-badge {
  background: var(--brand-xlight); color: var(--brand);
  font-size: 12px; font-weight: 600; padding: 6px 14px; border-radius: 20px;
}

.content { flex: 1; padding: 28px; overflow-y: auto; }

/* ===== KPI CARDS ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--neutral-200);
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--brand-light);
}
.kpi-card.accent::before { background: var(--accent); }
.kpi-card.danger::before { background: var(--danger); }
.kpi-card.success::before { background: var(--success); }

.kpi-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .8px; color: var(--neutral-500); margin-bottom: 8px; }
.kpi-value { font-size: 26px; font-weight: 700; color: var(--neutral-900); font-family: 'DM Mono', monospace; line-height: 1; }
.kpi-value.sm { font-size: 20px; }
.kpi-sub { font-size: 12px; color: var(--neutral-500); margin-top: 6px; }
.kpi-icon { position: absolute; right: 18px; top: 18px; font-size: 26px; opacity: .15; }

/* ===== CHARTS GRID ===== */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
@media (max-width: 900px) { .charts-grid { grid-template-columns: 1fr; } }

.chart-card {
  background: white; border-radius: var(--radius); padding: 22px;
  box-shadow: var(--shadow); border: 1px solid var(--neutral-200);
}
.chart-title { font-size: 14px; font-weight: 700; color: var(--neutral-900); margin-bottom: 16px; }
.chart-container { position: relative; }

/* ===== TABLES ===== */
.table-card {
  background: white; border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--neutral-200);
  overflow: hidden; margin-bottom: 20px;
}
.table-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--neutral-200);
}
.table-title { font-size: 15px; font-weight: 700; }
.table-subtitle { font-size: 12px; color: var(--neutral-500); margin-top: 2px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--neutral-50);
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .6px; color: var(--neutral-700);
  padding: 12px 16px; text-align: left;
  border-bottom: 1px solid var(--neutral-200);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--neutral-100); transition: background .15s; }
tbody tr:hover { background: var(--neutral-50); }
tbody tr:last-child { border-bottom: none; }
td { padding: 12px 16px; font-size: 13px; vertical-align: middle; }
td.mono { font-family: 'DM Mono', monospace; font-size: 12px; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge.payee { background: var(--success-light); color: var(--success); }
.badge.impaye { background: var(--danger-light); color: var(--danger); }
.badge.attente { background: var(--accent-light); color: #b06a00; }
.badge.partial { background: #e8f0fe; color: #1a73e8; }

/* ===== ALERTS ===== */
.alert-box {
  background: var(--danger-light); border: 1px solid #f5c6c2;
  border-radius: var(--radius); padding: 16px 20px; margin-bottom: 20px;
  display: flex; align-items: flex-start; gap: 12px;
}
.alert-icon { font-size: 20px; flex-shrink: 0; }
.alert-title { font-size: 14px; font-weight: 700; color: var(--danger); }
.alert-body { font-size: 13px; color: #7a1f1a; margin-top: 4px; }

/* ===== TABS ===== */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; background: white; border-radius: 10px; padding: 4px; border: 1px solid var(--neutral-200); display: inline-flex; }
.tab {
  padding: 8px 18px; border-radius: 7px; border: none;
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all .2s; background: none; color: var(--neutral-700);
}
.tab.active { background: var(--brand); color: white; }

/* ===== SEARCH & FILTER ===== */
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-input {
  padding: 8px 14px; border: 1px solid var(--neutral-200); border-radius: 8px;
  font-family: inherit; font-size: 13px; outline: none; background: white;
  transition: border .2s;
}
.filter-input:focus { border-color: var(--brand-light); }

/* ===== PROGRESS ===== */
.progress-bar {
  height: 6px; background: var(--neutral-200); border-radius: 3px; overflow: hidden;
}
.progress-fill { height: 100%; background: var(--brand-light); border-radius: 3px; transition: width .5s; }
.progress-fill.accent { background: var(--accent); }
.progress-fill.danger { background: var(--danger); }

/* ===== STATS ROW ===== */
.stats-row { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.stat-pill {
  background: white; border: 1px solid var(--neutral-200);
  border-radius: 20px; padding: 6px 16px;
  font-size: 12px; font-weight: 600; color: var(--neutral-700);
}
.stat-pill span { color: var(--brand); font-weight: 700; }

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: 60px 20px; color: var(--neutral-500); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: -100%; transition: left .3s; }
  .sidebar.mobile-open { left: 0; }
  .content { padding: 16px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .charts-grid { grid-template-columns: 1fr; }
  .search-box { width: 160px; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--neutral-300); border-radius: 3px; }

/* ===== SECTION TITLE ===== */
.section-title {
  font-size: 16px; font-weight: 700; color: var(--neutral-900);
  margin-bottom: 16px; display: flex; align-items: center; gap: 8px;
}
.section-title::after {
  content: ''; flex: 1; height: 1px; background: var(--neutral-200);
}

/* ===== TOP LIST ===== */
.top-list { }
.top-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--neutral-100);
}
.top-item:last-child { border-bottom: none; }
.top-rank {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--neutral-100); color: var(--neutral-700);
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.top-rank.gold { background: #fff3cd; color: #856404; }
.top-rank.silver { background: #e2e3e5; color: #41464b; }
.top-rank.bronze { background: #fde7d0; color: #7a4100; }
.top-name { flex: 1; font-size: 13px; font-weight: 500; }
.top-amount { font-family: 'DM Mono', monospace; font-size: 12px; font-weight: 600; color: var(--brand); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }
