/* ========================================================
   Components : boutons, formulaires, tables, modals, KPI
   ======================================================== */

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  font-family: inherit;
  line-height: 1.2;
}
.btn:focus-visible { outline: 2px solid var(--gold-500); outline-offset: 2px; }

.btn-primary { background: var(--navy-800); color: var(--surface); }
.btn-primary:hover { background: var(--navy-900); }

.btn-secondary { background: var(--surface); color: var(--navy-800); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-soft); border-color: var(--navy-500); }

.btn-success { background: var(--success); color: var(--surface); }
.btn-success:hover { filter: brightness(0.95); }

.btn-danger { background: var(--danger); color: var(--surface); }
.btn-danger:hover { filter: brightness(0.95); }

.btn-warning { background: var(--gold-500); color: var(--navy-900); }
.btn-warning:hover { background: var(--gold-600); color: var(--surface); }

.btn-ghost { background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-soft); color: var(--navy-800); }

.btn-sm { padding: 6px 10px; font-size: var(--text-xs); }
.btn-lg { padding: 12px 22px; font-size: var(--text-md); }
.btn-block { width: 100%; }

.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* === FORMS === */
.form-group { margin-bottom: var(--space-4); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.form-row.cols-3 { grid-template-columns: repeat(3, 1fr); }

label { display: block; font-weight: 600; font-size: var(--text-sm); margin-bottom: var(--space-1); color: var(--navy-800); }
label .required { color: var(--danger); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="tel"], input[type="search"], input[type="url"],
select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--navy-500);
  box-shadow: 0 0 0 3px rgba(10, 92, 179, 0.15);
}
textarea { resize: vertical; min-height: 80px; font-family: inherit; }

.form-help { font-size: var(--text-xs); color: var(--text-soft); margin-top: var(--space-1); }
.form-error { font-size: var(--text-xs); color: var(--danger); margin-top: var(--space-1); }

/* === TABLES === */
.table-wrapper { background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.table-wrapper table { width: 100%; border-collapse: collapse; }
.table-wrapper th {
  background: var(--navy-50);
  color: var(--navy-800);
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-weight: 700;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--navy-100);
}
.table-wrapper td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
}
.table-wrapper tr:last-child td { border-bottom: none; }
.table-wrapper tr:hover td { background: var(--surface-soft); }
.table-wrapper td.num, .table-wrapper th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrapper td.actions { white-space: nowrap; text-align: right; }
.table-wrapper td.actions .btn { padding: 4px 8px; }

.empty-state {
  text-align: center;
  padding: var(--space-10) var(--space-4);
  color: var(--text-soft);
}
.empty-state .icon { font-size: 48px; margin-bottom: var(--space-3); }

/* === KPI CARDS === */
.kpi-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--navy-700);
  transition: box-shadow 0.15s;
}
.kpi-card:hover { box-shadow: var(--shadow); }
.kpi-card .label { font-size: var(--text-xs); text-transform: uppercase; color: var(--text-soft); letter-spacing: 0.5px; font-weight: 600; }
.kpi-card .value { font-size: var(--text-2xl); font-weight: 700; color: var(--navy-800); margin-top: var(--space-2); line-height: 1; }
.kpi-card .delta { font-size: var(--text-xs); margin-top: var(--space-2); color: var(--text-soft); }
.kpi-card .delta.positive { color: var(--success); font-weight: 600; }
.kpi-card .delta.negative { color: var(--danger); font-weight: 600; }
.kpi-card.success { border-left-color: var(--success); }
.kpi-card.warning { border-left-color: var(--warning); }
.kpi-card.danger { border-left-color: var(--danger); }
.kpi-card.info { border-left-color: var(--info); }

/* === BADGES (statuts) === */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-draft { background: var(--surface-soft); color: var(--text-soft); }
.badge-pending, .badge-sent { background: var(--warning-bg); color: var(--warning); }
.badge-accepted, .badge-paid, .badge-validated, .badge-received { background: var(--success-bg); color: var(--success); }
.badge-cancelled, .badge-rejected, .badge-overdue { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }

/* === CARDS === */
.card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}
.card-header h3 { color: var(--navy-800); }

/* === MODALS === */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 26, 77, 0.5);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
  animation: fadeIn 0.15s;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 700px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s;
}
.modal.modal-lg { max-width: 1000px; }
.modal.modal-xl { max-width: 1300px; }
.modal-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-header h2 { color: var(--navy-800); font-size: var(--text-xl); }
.modal-close {
  background: none; border: 0; font-size: 28px; cursor: pointer;
  color: var(--text-soft); width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
}
.modal-close:hover { background: var(--surface-soft); color: var(--navy-800); }
.modal-body { padding: var(--space-6); }
.modal-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* === TOAST === */
#toast-container {
  position: fixed; top: var(--space-5); right: var(--space-5);
  z-index: 200; display: flex; flex-direction: column; gap: var(--space-2);
}
.toast {
  background: var(--surface);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 280px;
  display: flex; align-items: center; gap: var(--space-2);
  border-left: 4px solid var(--navy-700);
  animation: slideInRight 0.2s;
}
.toast.success { border-left-color: var(--success); }
.toast.warning { border-left-color: var(--warning); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--info); }
@keyframes slideInRight { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }

/* === UTILITAIRES === */
.text-soft { color: var(--text-soft); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-nowrap { white-space: nowrap; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }
.justify-between { justify-content: space-between; }
.items-center { align-items: center; }

/* === FILTRES === */
.filters {
  display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center;
  padding: var(--space-3); background: var(--surface); border-radius: var(--radius);
  margin-bottom: var(--space-4); box-shadow: var(--shadow-sm);
}
.filters input, .filters select { width: auto; min-width: 180px; }
