/* ===== MICROFINANCE PRO - STYLES ===== */

:root {
  --primary: #1e40af;
  --primary-dark: #1e3a8a;
  --secondary: #0f766e;
  --accent: #d97706;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --bg-light: #f1f5f9;
  --text-dark: #1e293b;
  --border: #e2e8f0;
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-light);
  color: var(--text-dark);
  margin: 0;
  padding: 0;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: 260px;
  background: linear-gradient(180deg, #1e3a8a 0%, #1e40af 100%);
  min-height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  box-shadow: 4px 0 15px rgba(0,0,0,0.2);
}

.sidebar-logo {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo .logo-icon {
  width: 42px;
  height: 42px;
  background: rgba(255,255,255,0.2);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: white;
}

.sidebar-logo h1 {
  color: white;
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
}

.sidebar-logo span {
  color: rgba(255,255,255,0.6);
  font-size: 11px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  font-size: 14px;
  font-weight: 500;
}

.nav-item:hover {
  background: rgba(255,255,255,0.1);
  color: white;
  border-left-color: rgba(255,255,255,0.5);
}

.nav-item.active {
  background: rgba(255,255,255,0.15);
  color: white;
  border-left-color: #fbbf24;
}

.nav-item i { width: 20px; text-align: center; font-size: 15px; }

.nav-section-title {
  padding: 12px 20px 4px;
  color: rgba(255,255,255,0.4);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.nav-sub-item {
  padding: 8px 20px 8px 52px;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.nav-sub-item:hover { color: white; background: rgba(255,255,255,0.08); }
.nav-sub-item.active { color: white; }

/* ===== MAIN CONTENT ===== */
.main-content {
  margin-left: 260px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: white;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.page-content {
  flex: 1;
  padding: 24px;
}

/* ===== CARDS ===== */
.card {
  background: white;
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}

.card-header h2, .card-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body { padding: 20px; }

/* ===== STATS CARDS ===== */
.stat-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
  border-left: 4px solid;
}

.stat-card .stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.stat-card .stat-value {
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 2px;
}

.stat-card .stat-label { font-size: 13px; color: #64748b; font-weight: 500; }

/* ===== TABLES ===== */
.table-container { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  background: #f8fafc;
  padding: 10px 14px;
  text-align: left;
  font-weight: 700;
  color: #64748b;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text-dark);
  vertical-align: middle;
}

tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 6px;
}

.form-label .required { color: var(--danger); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-dark);
  background: white;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

.form-control.error { border-color: var(--danger); }

.form-row {
  display: grid;
  gap: 16px;
}

.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }

.btn-warning { background: var(--accent); color: white; }
.btn-warning:hover { background: #b45309; }

.btn-secondary { background: #64748b; color: white; }
.btn-secondary:hover { background: #475569; }

.btn-outline {
  background: white;
  border: 1.5px solid var(--border);
  color: var(--text-dark);
}

.btn-outline:hover { background: #f8fafc; border-color: var(--primary); color: var(--primary); }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-icon { padding: 7px; width: 34px; height: 34px; justify-content: center; border-radius: 8px; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-success { background: #dcfce7; color: #16a34a; }
.badge-danger { background: #fee2e2; color: #dc2626; }
.badge-warning { background: #fef3c7; color: #d97706; }
.badge-info { background: #dbeafe; color: #2563eb; }
.badge-secondary { background: #f1f5f9; color: #64748b; }
.badge-primary { background: #eff6ff; color: var(--primary); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal {
  background: white;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn 0.3s ease;
}

.modal-lg { max-width: 900px; }
.modal-xl { max-width: 1100px; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: white;
  z-index: 1;
}

.modal-header h3 { margin: 0; font-size: 18px; font-weight: 700; color: var(--text-dark); }

.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: #f8fafc;
  position: sticky;
  bottom: 0;
}

/* ===== ALERTS ===== */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
}

.alert-error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }
.alert-warning { background: #fffbeb; color: #d97706; border: 1px solid #fde68a; }
.alert-info { background: #eff6ff; color: #2563eb; border: 1px solid #bfdbfe; }

/* ===== LOGIN PAGE ===== */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 50%, #0f766e 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: white;
  border-radius: 20px;
  padding: 48px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .logo-circle {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, #1e40af, #0f766e);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: white;
  margin: 0 auto 16px;
  box-shadow: 0 8px 20px rgba(30, 64, 175, 0.4);
}

/* ===== ANALYSIS SECTION ===== */
.analysis-section {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

.analysis-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
}

.result-box {
  background: linear-gradient(135deg, #eff6ff, #dbeafe);
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  margin-bottom: 16px;
}

.result-box .result-label { font-size: 12px; color: #64748b; font-weight: 600; text-transform: uppercase; margin-bottom: 4px; }
.result-box .result-value { font-size: 24px; font-weight: 800; color: var(--primary); }

.decision-favorable { background: linear-gradient(135deg, #f0fdf4, #dcfce7); border-color: #86efac; }
.decision-favorable .result-value { color: var(--success); }
.decision-defavorable { background: linear-gradient(135deg, #fef2f2, #fee2e2); border-color: #fca5a5; }
.decision-defavorable .result-value { color: var(--danger); }
.decision-reserve { background: linear-gradient(135deg, #fffbeb, #fef3c7); border-color: #fde68a; }
.decision-reserve .result-value { color: var(--warning); }

/* ===== ECHÉANCIER ===== */
.echeance-row-paye { background: #f0fdf4 !important; }
.echeance-row-retard { background: #fef2f2 !important; }

/* ===== PRINT / PDF ===== */
@media print {
  .no-print { display: none !important; }
  body { margin: 0; padding: 0; background: white; }
  .print-page { padding: 20px; }
}

/* ===== AGENCE DROPDOWN ===== */
.agence-select-wrapper {
  position: relative;
}

.agence-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: rgba(30,64,175,0.1);
  color: var(--primary);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== TABS ===== */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; gap: 2px; }
.tab {
  padding: 10px 18px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #64748b;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
  border-radius: 8px 8px 0 0;
}
.tab:hover { color: var(--primary); background: #f8fafc; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); background: white; }

/* ===== TOOLTIPS ===== */
.tooltip-wrapper { position: relative; display: inline-block; }
.tooltip { 
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: #1e293b; color: white; font-size: 12px; padding: 4px 8px;
  border-radius: 6px; white-space: nowrap; z-index: 999; pointer-events: none;
  opacity: 0; transition: opacity 0.2s;
}
.tooltip-wrapper:hover .tooltip { opacity: 1; }

/* ===== LOADER ===== */
.loader {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== SEARCH ===== */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box i {
  position: absolute;
  left: 10px;
  color: #94a3b8;
  font-size: 14px;
}

.search-box input {
  padding-left: 34px;
}

/* ===== NUMBER FORMAT ===== */
.amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.amount-positive { color: var(--success); }
.amount-negative { color: var(--danger); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .form-row-2, .form-row-3, .form-row-4 { grid-template-columns: 1fr; }
  .modal { margin: 10px; }
  .page-content { padding: 12px; }
}
