:root {
  --bg: #f5f8f3;
  --surface: #ffffff;
  --surface-2: #f7faf5;
  --border: #dfe7da;
  --text: #1a202c;
  --text-2: #718096;
  --text-3: #94a3b8;
  --primary: #43743f;
  --primary-2: #56894f;
  --primary-soft: #edf4e9;
  --green: #2f8f57;
  --green-soft: #eaf6ee;
  --red: #e53e3e;
  --red-soft: #fdf2f2;
  --amber: #f6ad55;
  --amber-soft: #fff4e6;
  --blue: #3b82f6;
  --blue-soft: #eff6ff;
  --purple: #8b5cf6;
  --purple-soft: #f5f3ff;
  --gold: #d4af37;
  --gold-soft: #faf4e0;
  --emerald: #0a3d2e;
  --sidebar-w: 248px;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(26, 32, 44, .06);
  --shadow-md: 0 4px 16px rgba(26, 32, 44, .08);
  --shadow-lg: 0 12px 32px rgba(26, 32, 44, .14);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ===== Boutons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border: 1px solid transparent; border-radius: 10px;
  font: 500 14px var(--font); cursor: pointer; transition: all .15s ease;
  text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-2); box-shadow: var(--shadow-md); }
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: #fee2e2; }
.btn-success { background: var(--green-soft); color: #047857; }
.btn-success:hover { background: #d1fae5; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; border-radius: 8px; background: transparent; border: none; cursor: pointer; color: var(--text-2); font-size: 18px; }
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }

/* ===== Login ===== */
.login-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(79, 70, 229, .18), transparent 60%),
    radial-gradient(700px 420px at 90% 110%, rgba(16, 185, 129, .12), transparent 60%),
    var(--bg);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: 20px;
  padding: 40px 36px; box-shadow: var(--shadow-lg); border: 1px solid var(--border);
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 32px; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 13px; background: linear-gradient(135deg, var(--primary), var(--gold));
  color: #fff; font-weight: 800; font-size: 22px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px rgba(67, 116, 63, .35);
}
.login-brand h1 { font-size: 20px; letter-spacing: -.02em; }
.login-brand p { color: var(--text-3); font-size: 13px; }
.field { margin-bottom: 18px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-2); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 13px; border: 1px solid var(--border); border-radius: 10px;
  font: 400 14px var(--font); background: var(--surface); color: var(--text); transition: border .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(67, 116, 63, .18);
}
.form-error {
  background: var(--red-soft); color: var(--red); border: 1px solid #fecaca;
  padding: 9px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 16px;
}
.login-hint { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-3); display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-green { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.dot-red { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }

/* ===== Layout principal ===== */
.main-view { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--emerald); color: #b9d4c6; display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; transition: transform .2s ease;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 20px 20px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-brand .brand-mark { width: 36px; height: 36px; font-size: 17px; border-radius: 10px; }
.sidebar-brand span { font-weight: 700; color: #f5ead0; font-size: 15px; }
.sidebar-nav { flex: 1; padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: #9fc0af; text-decoration: none; font-weight: 500; transition: all .15s;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #f0f5f2; }
.nav-item.active { background: rgba(212, 175, 55, .16); color: #f6df9c; }
.nav-icon { width: 20px; text-align: center; font-size: 15px; }
.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--gold));
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.user-meta { overflow: hidden; }
.user-meta strong { display: block; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { font-size: 11.5px; color: #8fb5a2; text-transform: capitalize; }

.content { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 14px;
  padding: 14px 28px; background: rgba(245, 248, 243, .85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
#menu-toggle { display: none; }
.topbar h2 { font-size: 18px; letter-spacing: -.02em; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-date { color: var(--text-3); font-size: 13px; }
.page-content { padding: 24px 28px 48px; }

/* ===== Badges ===== */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.badge-green { background: var(--green-soft); color: #047857; }
.badge-red { background: var(--red-soft); color: #b91c1c; }
.badge-amber { background: var(--amber-soft); color: #b45309; }
.badge-blue { background: var(--blue-soft); color: #1d4ed8; }
.badge-purple { background: var(--purple-soft); color: #7c3aed; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-outline { background: transparent; border: 1px solid var(--border); color: var(--text-2); }

/* ===== Cartes KPI ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-sm); transition: transform .15s, box-shadow .15s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-label { font-size: 12.5px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin: 6px 0 2px; }
.kpi-sub { font-size: 12px; color: var(--text-3); }
.kpi-icon { float: right; width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 17px; }

/* ===== Cartes génériques ===== */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); margin-bottom: 20px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-title { font-size: 15px; font-weight: 700; }
.card-subtitle { font-size: 12.5px; color: var(--text-3); }
.card-body { padding: 20px; }
.card-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
@media (max-width: 1100px) { .card-grid { grid-template-columns: 1fr; } }

/* ===== Tableaux ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; padding: 10px 16px; font-size: 11.5px; font-weight: 700; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); background: var(--surface-2);
  white-space: nowrap;
}
tbody td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }
.cell-primary { font-weight: 600; }
.cell-muted { color: var(--text-3); font-size: 12.5px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ===== Toolbar recherche ===== */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 9px; font: 400 13.5px var(--font);
  background: var(--surface); color: var(--text); min-width: 180px;
}
.toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(67,116,63,.18); }

/* ===== Pagination ===== */
.pagination { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.pagination-info { flex: 1; color: var(--text-3); font-size: 12.5px; }

/* ===== Chart ===== */
.chart-container { position: relative; }
.chart-empty { color: var(--text-3); font-size: 13px; text-align: center; padding: 40px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2); }
.legend-swatch { width: 11px; height: 11px; border-radius: 3px; }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5); backdrop-filter: blur(3px);
  z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: 16px; width: 100%; max-width: 560px; max-height: 88vh;
  overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal-title { font-size: 15.5px; font-weight: 700; }
.modal-body { padding: 22px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); }
.modal-lg { max-width: 760px; }
.detail-row { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px dashed var(--border); font-size: 13.5px; }
.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--text-3); }
.detail-value { font-weight: 600; text-align: right; word-break: break-word; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 14px; margin-bottom: 18px; }
.detail-cell { background: var(--surface-2, #f8fafc); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.detail-cell .detail-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 4px; }
.detail-section { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 16px; }
.detail-section .card-title { margin-bottom: 10px; }
.table-sm table { font-size: 12.5px; }
.table-sm th { padding: 8px 10px; }
.table-sm td { padding: 8px 10px; }
.mini-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.mini-block { background: var(--surface-2, #f8fafc); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.mini-block-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--text-3); margin-bottom: 6px; }
.mini-item { font-size: 12.5px; padding: 3px 0; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-click { cursor: pointer; }
.row-click:hover td { background: var(--primary-soft); }
.alert-bell { position: relative; }
.alert-badge { position: absolute; top: -4px; right: -4px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--red, #ef4444); color: #fff; font-size: 10.5px; font-weight: 700; align-items: center; justify-content: center; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 100; background: var(--emerald); color: #fff;
  padding: 12px 18px; border-radius: 12px; font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease;
}
.toast-success { background: #065f46; }
.toast-error { background: #991b1b; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== Loading ===== */
.loading { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 60px 0; color: var(--text-3); }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, #eef1f6 25%, #f8fafc 50%, #eef1f6 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ===== Statut pills (table) ===== */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pill-active, .pill-active_paid, .pill-completed, .pill-approved, .pill-verified { background: var(--green-soft); color: #047857; }
.pill-pending, .pill-trialing, .pill-draft, .pill-scheduled, .pill-partially_paid { background: var(--amber-soft); color: #b45309; }
.pill-inactive, .pill-cancelled, .pill-expired, .pill-rejected, .pill-failed, .pill-overdue { background: var(--red-soft); color: #b91c1c; }
.pill-past_due { background: #fef2f2; color: #b91c1c; }
.pill-in_progress, .pill-ongoing { background: var(--blue-soft); color: #1d4ed8; }

/* ===== Avatar row ===== */
.avatar-row { display: flex; align-items: center; gap: 10px; }
.avatar-sm { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; flex-shrink: 0; }

/* ===== Accueil — en-tête de salutation ===== */
.dash-greeting { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; flex-wrap: wrap; }
.dash-greeting h1 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.dash-greeting p { color: var(--text-2); font-size: 13.5px; margin-top: 4px; }
.dash-date-pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border: 1px solid var(--border);
  border-radius: 11px; background: var(--surface); font-size: 13px; font-weight: 600; color: var(--text-2);
  box-shadow: var(--shadow-sm); white-space: nowrap;
}

/* ===== Accueil — mise en page 2 colonnes (principal + panneau latéral) ===== */
.dash-layout { display: flex; gap: 20px; align-items: flex-start; }
.dash-main { flex: 1; min-width: 0; }
.dash-side { width: 300px; flex-shrink: 0; display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 1100px) { .dash-layout { flex-direction: column; } .dash-side { width: 100%; } }

/* ===== Accueil — cartes KPI v2 (icône + tendance) ===== */
.kpi-row-v2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi-card-v2 { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm); }
.kpi-card-v2-top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.kpi-card-v2-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.kpi-card-v2-label { font-size: 12.5px; color: var(--text-2); font-weight: 600; }
.kpi-card-v2-value { font-size: 24px; font-weight: 800; letter-spacing: -.02em; margin-bottom: 4px; }
.kpi-card-v2-trend { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; }
.kpi-card-v2-trend.up { color: #047857; }
.kpi-card-v2-trend.down { color: var(--red); }
.kpi-card-v2-trend-note { color: var(--text-3); font-weight: 500; margin-left: 2px; }

/* ===== Accueil — graphique Performance avec infobulle ===== */
.perf-chart-wrap { position: relative; }
.chart-tooltip {
  position: absolute; pointer-events: none; background: var(--emerald); color: #fff; border-radius: 10px;
  padding: 10px 13px; font-size: 12px; box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .1s;
  transform: translate(-50%, -100%); white-space: nowrap; z-index: 5;
}
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip-date { font-weight: 700; margin-bottom: 4px; padding-bottom: 4px; border-bottom: 1px solid rgba(255,255,255,.2); }
.chart-tooltip-row { display: flex; justify-content: space-between; gap: 14px; color: #d9e8dd; }
.chart-tooltip-row strong { color: #fff; }

/* ===== Accueil — liste de tâches ===== */
.task-list { display: flex; flex-direction: column; }
.task-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .1s;
}
.task-row:last-child { border-bottom: none; }
.task-row:hover { background: var(--surface-2); }
.task-row-icon { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.task-row-body { flex: 1; min-width: 0; }
.task-row-title { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-row-detail { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-row-meta { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.task-row-time { font-size: 12px; color: var(--text-3); }
.task-empty { padding: 32px 20px; text-align: center; color: var(--text-3); font-size: 13px; }

/* ===== Accueil — panneau latéral : profil admin ===== */
.side-profile { text-align: center; padding: 24px 20px; }
.side-profile-avatar {
  width: 76px; height: 76px; border-radius: 50%; margin: 0 auto 14px; position: relative;
  background: linear-gradient(135deg, var(--primary), var(--gold)); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 800;
}
.side-profile-status {
  position: absolute; bottom: 2px; right: 2px; width: 15px; height: 15px; border-radius: 50%;
  background: var(--green); border: 3px solid var(--surface);
}
.side-profile-name { font-size: 15.5px; font-weight: 700; }
.side-profile-role { font-size: 12.5px; color: var(--text-3); margin-top: 2px; text-transform: capitalize; }
.side-profile-refresh {
  margin-top: 16px; display: inline-flex; align-items: center; gap: 7px; padding: 8px 16px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text-2);
  font-size: 12.5px; font-weight: 600; cursor: pointer; transition: all .15s;
}
.side-profile-refresh:hover { background: var(--primary-soft); color: var(--primary); border-color: var(--primary-soft); }

/* ===== Accueil — panneau latéral : activité récente ===== */
.activity-list { display: flex; flex-direction: column; }
.activity-item { display: flex; gap: 11px; padding: 13px 20px; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: none; }
.activity-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; flex-shrink: 0;
}
.activity-body { flex: 1; min-width: 0; }
.activity-line { font-size: 13px; line-height: 1.4; }
.activity-line strong { font-weight: 700; }
.activity-time { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.activity-empty { padding: 28px 20px; text-align: center; color: var(--text-3); font-size: 13px; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .content { margin-left: 0; }
  #menu-toggle { display: block; }
  .page-content { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .topbar-date { display: none; }
}
