/* ── Components: cards, stats, tables, buttons, forms, badges, modals, etc. ── */

/* ── Main Content ─────────────────────────────────────── */

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px;
  max-width: 1200px;
  min-width: 0;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

/* ── Cards ────────────────────────────────────────────── */

.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  margin-bottom: 20px;
  animation: fadeInUp 0.35s ease backwards;
}

.card:nth-child(2) { animation-delay: 0.04s; }
.card:nth-child(3) { animation-delay: 0.08s; }
.card:nth-child(4) { animation-delay: 0.12s; }

.card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.1px;
}

/* ── Stats cards (dashboard) ──────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  text-align: left;
  border-left: 3px solid var(--primary);
  transition: box-shadow var(--transition), transform var(--transition);
  animation: fadeInUp 0.35s ease backwards;
}

.stat-card:nth-child(1) { animation-delay: 0s; }
.stat-card:nth-child(2) { animation-delay: 0.04s; }
.stat-card:nth-child(3) { animation-delay: 0.08s; }
.stat-card:nth-child(4) { animation-delay: 0.12s; }
.stat-card:nth-child(5) { animation-delay: 0.16s; }
.stat-card:nth-child(6) { animation-delay: 0.2s; }

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.stat-card .stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}

.stat-card .stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}

/* ── Tables ───────────────────────────────────────────── */

.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  background: var(--bg);
  color: var(--text-light);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  border-bottom: 2px solid var(--border);
}

th:first-child { border-radius: 0; }
th:last-child { border-radius: 0; }

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
  color: var(--text);
}

tr:hover td {
  background: var(--bg);
}

tr.cloturee td {
  background: var(--primary-50);
  color: var(--text-light);
}

tr.cloturee:hover td {
  background: var(--success-light);
}

/* ── Buttons ──────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover {
  background: var(--bg);
  border-color: var(--text-muted);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  background: white;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-light);
  transition: all var(--transition-fast);
}

.btn-icon svg {
  width: 15px;
  height: 15px;
  stroke-width: 1.75;
}

.btn-icon:hover {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text);
}
.btn-icon.danger:hover {
  background: var(--danger-light);
  color: var(--danger);
  border-color: #FECACA;
}

/* ── Forms ────────────────────────────────────────────── */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  color: var(--text);
  background: white;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22,128,60,0.12);
}

/* ── Badges ───────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: var(--success-light); color: #16803C; }
.badge-warning { background: var(--warning-light); color: #B45309; }
.badge-danger { background: var(--danger-light); color: #DC2626; }
.badge-info { background: var(--info-light); color: #2563EB; }

/* ── Modal ────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: white;
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 90%;
  max-width: 700px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.2s ease;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--bg);
  color: var(--text);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

/* ── Config list items ────────────────────────────────── */

.config-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--bg);
  transition: border-color var(--transition-fast);
}

.config-item:hover {
  border-color: var(--border);
}

.config-item input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}

.config-item input:focus {
  outline: none;
  border-color: var(--primary);
}

.config-item .code-input { width: 70px; font-weight: 600; }
.config-item .name-input { flex: 1; min-width: 150px; }
.config-item .num-input { width: 80px; text-align: right; }

/* ── Progress bars ────────────────────────────────────── */

.progress-bar {
  height: 8px;
  background: var(--border-light);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar .fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.progress-bar .fill.green { background: var(--success); }
.progress-bar .fill.orange { background: var(--warning); }
.progress-bar .fill.red { background: var(--danger); }

/* ── Empty state ──────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 14px; }

/* ── Toast notification ───────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  background: var(--text);
  color: white;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  transition: opacity 0.3s, transform 0.3s;
}

.toast.hidden {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}

/* ── Rentabilite panels ───────────────────────────────── */

.renta-panel {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 16px;
  border-left: 4px solid var(--primary);
}

.renta-panel.renta-ok {
  background: var(--success-light);
  border-left-color: var(--success);
}

.renta-panel.renta-warn {
  background: var(--warning-light);
  border-left-color: var(--warning);
}

.renta-panel.renta-danger {
  background: var(--danger-light);
  border-left-color: var(--danger);
}

.renta-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.renta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.renta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.renta-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.renta-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ── Offline indicator ─────────────────────────────────── */
body.is-offline .sidebar::after {
  content: 'HORS-LIGNE';
  display: block;
  text-align: center;
  background: #D97706;
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 4px;
  letter-spacing: 1px;
}

/* ── Mode lecture seule (dirigeant) ──────────────────── */
.readonly-mode .btn-primary,
.readonly-mode .btn-icon.danger,
.readonly-mode [data-action="showCreateAffaire"],
.readonly-mode [data-action="showCreateBDC"],
.readonly-mode [data-action="showCreatePointage"],
.readonly-mode [data-action="exportAffairesCSV"],
.readonly-mode [data-action="exportBDCCSV"],
.readonly-mode [data-action="exportPointagesCSV"],
.readonly-mode [data-action="deleteDemandeFromPage"],
.readonly-mode [data-action="editPointage"],
.readonly-mode [data-action="deletePointage"],
.readonly-mode [data-page="parametres"] {
  display: none !important;
}
