/* =============================================================================
   GÉNÉRATEUR DRF — BAD · Design System Premium v2
   ============================================================================= */

/* --- Reset & Foundation --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --radius-pill: 999px;
  --app-header-height: 72px;
  --sticky-stepper-top: 72px;
  --stepper-height: 74px;
  --wizard-nav-height: 70px;
  --navbar-h: 48px;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:  0 4px 20px rgba(37,99,235,.08), 0 2px 8px rgba(0,0,0,.04);
  --shadow-lg:  0 12px 40px rgba(37,99,235,.12), 0 4px 16px rgba(0,0,0,.06);
  --shadow-xl:  0 24px 64px rgba(0,0,0,.14), 0 8px 24px rgba(0,0,0,.06);
  --shadow-btn: 0 4px 14px rgba(37,99,235,.35);
  --shadow-btn-hover: 0 8px 24px rgba(37,99,235,.45);

  /* Transitions */
  --transition: 0.22s cubic-bezier(.4,0,.2,1);
  --transition-slow: 0.4s cubic-bezier(.4,0,.2,1);
  --transition-spring: 0.35s cubic-bezier(.34,1.56,.64,1);

  /* Light palette */
  --bg:             #f0f4ff;
  --bg-card:        #ffffff;
  --bg-hover:       #f1f5fd;
  --bg-selected:    #eef4ff;
  --border:         #e4e9f5;
  --border-focus:   #3b82f6;
  --border-strong:  #c7d4f0;
  --text:           #131929;
  --text-secondary: #4b5680;
  --text-muted:     #8892b0;

  /* Brand */
  --primary:        #2563eb;
  --primary-hover:  #1d4ed8;
  --primary-bg:     #dbeafe;
  --primary-text:   #1e40af;
  --accent:         #7c3aed;
  --accent-light:   #a78bfa;
  --accent-bg:      #ede9fe;

  /* Semantic */
  --success:        #059669;
  --success-bg:     #d1fae5;
  --success-text:   #065f46;
  --danger:         #dc2626;
  --danger-bg:      #fee2e2;
  --warning:        #d97706;
  --warning-bg:     #fef3c7;

  /* Gradients */
  --gradient-brand:    linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  --gradient-brand-r:  linear-gradient(135deg, #7c3aed 0%, #2563eb 100%);
  --gradient-card:     linear-gradient(180deg, #ffffff 0%, #f8faff 100%);
  --gradient-bg:       radial-gradient(ellipse 80% 60% at 50% -10%, rgba(37,99,235,.12) 0%, transparent 70%),
                       radial-gradient(ellipse 60% 40% at 90% 80%, rgba(124,58,237,.08) 0%, transparent 60%);
  --gradient-success:  linear-gradient(135deg, #059669 0%, #0d9488 100%);

  /* Stepper */
  --stepper-bg:     #e4e9f5;
  --stepper-active: #2563eb;
  --stepper-done:   #059669;

  /* Modal */
  --modal-backdrop: rgba(8, 15, 40, 0.65);

  /* Dropzone */
  --dropzone-bg:     #f8faff;
  --dropzone-border: #c7d4f0;
  --dropzone-hover:  #eef4ff;
}

body.dark {
  --bg:             #090c18;
  --bg-card:        #111527;
  --bg-hover:       #171c32;
  --bg-selected:    #1a2340;
  --border:         #232842;
  --border-focus:   #3b82f6;
  --border-strong:  #2e3556;
  --text:           #e6eaf6;
  --text-secondary: #8892b0;
  --text-muted:     #5a6480;
  --primary:        #4f8ef7;
  --primary-hover:  #60a5fa;
  --primary-bg:     #1a2f5a;
  --primary-text:   #93c5fd;
  --accent:         #9d74f0;
  --accent-light:   #c4b5fd;
  --accent-bg:      #261850;
  --success:        #34d399;
  --success-bg:     #052e1e;
  --success-text:   #6ee7b7;
  --danger:         #f87171;
  --danger-bg:      #3b0c0c;
  --warning:        #fbbf24;
  --warning-bg:     #2d1a00;
  --gradient-card:  linear-gradient(180deg, #111527 0%, #0d1020 100%);
  --gradient-bg:    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(79,142,247,.15) 0%, transparent 70%),
                    radial-gradient(ellipse 60% 40% at 90% 80%, rgba(157,116,240,.1) 0%, transparent 60%);
  --stepper-bg:     #232842;
  --modal-backdrop: rgba(0, 0, 0, 0.8);
  --dropzone-bg:    #0e1124;
  --dropzone-border:#232842;
  --dropzone-hover: #1a2340;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.3);
  --shadow-md:  0 4px 20px rgba(0,0,0,.35);
  --shadow-lg:  0 12px 40px rgba(0,0,0,.45);
  --shadow-xl:  0 24px 64px rgba(0,0,0,.55);
  --shadow-btn: 0 4px 14px rgba(79,142,247,.4);
  --shadow-btn-hover: 0 8px 24px rgba(79,142,247,.5);
}

html {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  height: 100vh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  transition: background var(--transition-slow), color var(--transition-slow);
  position: relative;
  overflow: hidden;
}

/* Background decorative layer */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--gradient-bg);
  pointer-events: none;
  z-index: 0;
}

h1, h2, h3, h4, h5, h6, strong { color: inherit; }

/* =============================================================================
   HEADER
   ============================================================================= */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-card);
  border-bottom: 1px solid rgba(228, 233, 245, 0.8);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  transition: background var(--transition);
}

body.dark .app-header {
  background: var(--bg-card);
  border-bottom-color: rgba(35, 40, 66, 0.8);
}

/* Gradient accent line on header bottom */
.app-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0; right: 0;
  height: 2px;
  background: var(--gradient-brand);
  opacity: 0;
  transition: opacity var(--transition);
}

.app-header.scrolled::after { opacity: 1; }

.app-header-inner {
  max-width: 1180px;
  min-height: var(--app-header-height);
  margin: 0 auto;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon svg {
  width: 42px;
  height: 42px;
  display: block;
  filter: drop-shadow(0 4px 12px rgba(37,99,235,.35));
}

.app-header-text h1 {
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

body.dark .app-header-text h1 {
  background: linear-gradient(135deg, #60a5fa 0%, #a78bfa 100%);
  -webkit-background-clip: text;
  background-clip: text;
}

.app-header-text .subtitle {
  font-size: 0.73rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.01em;
  margin-top: 1px;
}

.app-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-badges {
  display: flex;
  gap: 5px;
}

.header-badges span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 22px;
  font-size: 0.68rem;
  font-weight: 800;
  border-radius: var(--radius-xs);
  background: var(--primary-bg);
  color: var(--primary-text);
  letter-spacing: 0.04em;
  border: 1px solid rgba(37,99,235,.15);
  transition: all var(--transition);
}

.header-badges span:hover {
  background: var(--gradient-brand);
  color: #fff;
  border-color: transparent;
  transform: translateY(-1px);
}

/* Header buttons shared */
.theme-toggle,
.history-toggle,
.logout-toggle {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: all var(--transition);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0 12px;
  white-space: nowrap;
}

.theme-toggle { width: 36px; padding: 0; }

.theme-toggle:hover,
.history-toggle:hover,
.logout-toggle:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.theme-toggle svg,
.history-toggle svg,
.logout-toggle svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.icon-moon { display: none; }
body.dark .icon-sun { display: none; }
body.dark .icon-moon { display: block; }

.auth-chip {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  background: var(--gradient-brand);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.app-logo {
  height: 34px;
  width: auto;
  object-fit: contain;
  border-radius: var(--radius-xs);
}

/* =============================================================================
   LOGIN
   ============================================================================= */
.login-view {
  flex: 1;
  min-height: calc(100vh - 64px);
  display: grid;
  place-items: center;
  padding: 48px 24px;
  position: relative;
  z-index: 1;
}

.login-view[hidden] { display: none; }

.login-panel {
  width: min(440px, 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  box-shadow: var(--shadow-xl);
  padding: 36px;
  position: relative;
  overflow: hidden;
}

.login-panel::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--gradient-brand);
}

.login-panel-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.login-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--gradient-brand);
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  box-shadow: var(--shadow-btn);
  flex-shrink: 0;
}

.login-panel h2 {
  font-size: 1.3rem;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.login-panel > .form-field + .form-field { margin-top: 16px; }
.login-panel p { margin-top: 3px; color: var(--text-muted); font-size: 0.85rem; }

.password-requirements {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.login-submit { width: 100%; margin-top: 8px; }

/* =============================================================================
   STEPPER
   ============================================================================= */
.stepper {
  position: sticky;
  top: var(--sticky-stepper-top);
  z-index: 90;
  height: var(--stepper-height);
  min-height: 74px;
  background: rgba(255,255,255,0.82);
  border-bottom: 1px solid rgba(228, 233, 245, 0.8);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  padding: 0 28px;
  transition: background var(--transition);
}

body.dark .stepper {
  background: rgba(17, 21, 39, 0.85);
  border-bottom-color: rgba(35, 40, 66, 0.8);
}

.stepper-inner {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  padding: 22px 0 18px;
}

.stepper-track {
  position: absolute;
  top: 37px;
  left: 36px;
  right: 36px;
  height: 3px;
  background: var(--stepper-bg);
  border-radius: 2px;
}

.stepper-progress {
  position: absolute;
  top: 37px;
  left: 36px;
  height: 3px;
  width: 0;
  background: var(--gradient-brand);
  border-radius: 2px;
  transition: width 0.55s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 0 8px rgba(37,99,235,.5);
}

.step-dot {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  outline: none;
}

.dot-num {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--bg-card);
  border: 2.5px solid var(--stepper-bg);
  color: var(--text-muted);
  transition: all var(--transition-spring);
}

.dot-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  transition: color var(--transition);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.step-dot.active .dot-num {
  background: var(--gradient-brand);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 0 0 5px var(--primary-bg), var(--shadow-btn);
  animation: dotPulse 0.45s cubic-bezier(.34,1.56,.64,1);
}

.step-dot.active .dot-label {
  color: var(--primary);
  font-weight: 700;
}

.step-dot.done .dot-num {
  background: var(--success);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 0 0 4px var(--success-bg);
}

.step-dot.done .dot-label { color: var(--success); }

.step-dot.done .dot-num::after {
  content: '';
  width: 10px;
  height: 6px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
  display: block;
}

.step-dot.done .dot-num span { display: none; }

@keyframes dotPulse {
  0%   { transform: scale(0.8); }
  60%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* =============================================================================
   MAIN CONTENT
   ============================================================================= */
main {
  flex: 0 0 auto;
  max-width: 820px;
  height: calc(100vh - var(--app-header-height) - var(--stepper-height) - var(--wizard-nav-height));
  width: 100%;
  margin: 0 auto;
  padding: 28px 24px;
  position: relative;
  z-index: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.wizard-step {
  display: none;
  animation: stepIn 0.38s cubic-bezier(.4,0,.2,1);
}

.wizard-step.active { display: block; }

@keyframes stepIn {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Step card */
.step-card {
  background: var(--gradient-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

/* Subtle top accent */
.step-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--gradient-brand);
  opacity: 0.6;
}

.step-header {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 28px;
}

.step-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  background: var(--gradient-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-btn);
}

.step-icon svg {
  width: 24px;
  height: 24px;
  stroke: #fff;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.step-icon-generate {
  background: linear-gradient(135deg, var(--accent) 0%, #2563eb 100%);
  box-shadow: 0 4px 14px rgba(124,58,237,.4);
}

.step-header h2 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 5px;
  line-height: 1.2;
}

.step-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.demande-form-grid {
  gap: 12px 16px;
  margin-bottom: 12px;
}

.demande-form-grid-primary {
  margin-bottom: 12px;
}

.demande-form-grid-details {
  align-items: start;
  margin-bottom: 14px;
}

.demande-form-grid-details .form-field {
  min-width: 0;
}

/* =============================================================================
   PROJECT / BENEFICIARY GRID
   ============================================================================= */
.beneficiary-step-search {
  margin: -8px 0 14px;
}

.beneficiary-step-search-shell {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.beneficiary-step-search-shell:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3.5px var(--primary-bg);
}

.beneficiary-step-search-shell svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke: var(--text-muted);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

.beneficiary-step-search-input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  padding: 10px 0;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: transparent;
}

.beneficiary-step-search-input::placeholder {
  color: var(--text-muted);
}

.beneficiary-step-search-clear {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--radius-xs);
  background: var(--bg-hover);
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition), transform var(--transition);
}

.beneficiary-step-search-clear:hover {
  color: var(--danger);
  background: var(--danger-bg);
  transform: scale(1.04);
}

.beneficiary-step-search-clear[hidden] {
  display: none;
}

.beneficiary-step-search-count {
  margin-top: 7px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.beneficiary-step-empty {
  grid-column: 1 / -1;
}

.beneficiary-step-empty span {
  color: var(--text-muted);
  font-weight: 500;
}

.project-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
  width: 100%;
}

.project-card {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: all var(--transition-spring);
  background: var(--bg-card);
  width: 100%;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.project-card::after {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--gradient-brand);
  opacity: 0;
  transition: opacity var(--transition);
}

.project-card:hover {
  border-color: var(--border-focus);
  background: var(--bg-selected);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.project-card:hover::after { opacity: 1; }

.project-card.selected {
  border-color: var(--primary);
  background: var(--bg-selected);
  box-shadow: 0 0 0 3px var(--primary-bg), var(--shadow-sm);
  transform: translateY(-1px);
}

.project-card.selected::after { opacity: 1; }

.project-card-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-xs);
  background: var(--gradient-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.82rem;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(37,99,235,.3);
  letter-spacing: 0.02em;
}

.project-card-info {
  flex: 1;
  min-width: 0;
}

.project-card-name {
  font-weight: 700;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  max-width: 100%;
  letter-spacing: -0.01em;
}

.project-card-detail {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.project-card-check {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition-spring);
}

.project-card.selected .project-card-check {
  background: var(--gradient-brand);
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(37,99,235,.35);
}

.project-card.selected .project-card-check::after {
  content: '';
  width: 9px;
  height: 5.5px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
  display: block;
}

.btn-edit-card,
.btn-delete-card {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--text-muted);
  border-radius: var(--radius-xs);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  flex-shrink: 0;
}

.btn-edit-card { margin-left: auto; margin-right: 2px; }
.btn-delete-card { margin-right: 6px; }

.btn-edit-card:hover {
  background: var(--primary-bg);
  color: var(--primary);
  transform: scale(1.1);
}

.btn-delete-card:hover {
  background: var(--danger-bg);
  color: var(--danger);
  transform: scale(1.1);
}

.btn-edit-card svg,
.btn-delete-card svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Create new button */
.btn-create-new {
  width: 100%;
  padding: 14px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--primary);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  transition: all var(--transition);
  font-family: var(--font);
  letter-spacing: -0.01em;
}

.btn-create-new:hover {
  border-color: var(--primary);
  background: var(--primary-bg);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn-create-new svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
}

/* =============================================================================
   WIZARD NAVIGATION BAR
   ============================================================================= */
.wizard-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 80;
  background: rgba(255,255,255,0.88);
  border-top: 1px solid rgba(228,233,245,.9);
  padding: 14px 28px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  min-height: var(--wizard-nav-height);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
}

body.dark .wizard-nav {
  background: rgba(17, 21, 39, 0.9);
  border-top-color: rgba(35,40,66,.9);
}

.btn-nav {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 28px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  transition: all var(--transition);
  letter-spacing: -0.01em;
}

.btn-nav:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn-nav svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-next {
  background: var(--gradient-brand);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-btn);
  padding: 10px 36px;
}

.btn-nav.btn-next:hover {
  opacity: 0.92;
  transform: translateY(-2px);
  box-shadow: var(--shadow-btn-hover);
}

/* Step counter in nav */
.wizard-nav-counter {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 40px;
  text-align: center;
  letter-spacing: 0.02em;
}

/* =============================================================================
   FORM ELEMENTS
   ============================================================================= */
.form-section { margin-bottom: 24px; }

.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  letter-spacing: 0.01em;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.form-field.full { grid-column: 1 / -1; }

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg-card);
  transition: all var(--transition);
  outline: none;
}

.form-input:hover {
  border-color: var(--border-strong);
}

.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3.5px var(--primary-bg);
}

textarea.form-input {
  resize: vertical;
  min-height: 64px;
  line-height: 1.6;
}

select.form-input {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 38px;
}

.form-input.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-bg);
}

.field-error {
  min-height: 18px;
  margin-top: 5px;
  color: var(--danger);
  font-size: 0.76rem;
  line-height: 1.35;
}

.field-hint {
  min-height: 18px;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.field-hint.auto {
  color: var(--primary);
}

/* =============================================================================
   RADIO CARDS (Step 2)
   ============================================================================= */
.radio-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.radio-card {
  display: block;
  cursor: pointer;
}

.radio-card input { display: none; }

.radio-card-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition-spring);
  background: var(--bg-card);
  position: relative;
  overflow: hidden;
}

.radio-card-inner::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--gradient-brand);
  transform: scaleY(0);
  transition: transform var(--transition);
  transform-origin: bottom;
}

.radio-card:hover .radio-card-inner {
  border-color: var(--primary);
  background: var(--bg-selected);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.radio-card:hover .radio-card-inner::before { transform: scaleY(1); }

.radio-card input:checked + .radio-card-inner {
  border-color: var(--primary);
  background: var(--bg-selected);
  box-shadow: 0 0 0 3px var(--primary-bg), var(--shadow-sm);
}

.radio-card input:checked + .radio-card-inner::before { transform: scaleY(1); }

/* Radio icon */
.radio-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-xs);
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}

.radio-icon svg {
  width: 20px;
  height: 20px;
  stroke: var(--text-muted);
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke var(--transition);
}

.radio-card:hover .radio-icon,
.radio-card input:checked + .radio-card-inner .radio-icon {
  background: var(--primary-bg);
}

.radio-card:hover .radio-icon svg,
.radio-card input:checked + .radio-card-inner .radio-icon svg {
  stroke: var(--primary);
}

.radio-circle {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-spring);
}

.radio-card input:checked + .radio-card-inner .radio-circle {
  border-color: var(--primary);
  background: var(--primary);
}

.radio-card input:checked + .radio-card-inner .radio-circle::after {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
}

.radio-card-inner strong {
  font-size: 0.88rem;
  font-weight: 700;
  display: block;
  letter-spacing: -0.01em;
}

.radio-card-inner small {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
  font-weight: 500;
}

/* =============================================================================
   INFO BANNER
   ============================================================================= */
.info-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--primary-bg);
  color: var(--primary-text);
  font-size: 0.85rem;
  font-weight: 500;
  margin-top: 16px;
  transition: all var(--transition);
  border: 1px solid rgba(37,99,235,.15);
}

.info-banner.hidden { display: none; }

.info-banner svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  flex-shrink: 0;
}

.info-banner.warning {
  background: var(--warning-bg);
  color: var(--warning);
  border-color: rgba(217,119,6,.15);
}

/* =============================================================================
   DROPZONE (Step 4)
   ============================================================================= */
.dropzone-area { display: grid; gap: 16px; }

.dropzone {
  border: 2px dashed var(--dropzone-border);
  border-radius: var(--radius);
  background: var(--dropzone-bg);
  transition: all var(--transition);
  overflow: hidden;
  position: relative;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background: var(--dropzone-hover);
  box-shadow: 0 0 0 4px var(--primary-bg);
}

.dropzone.has-file {
  border-color: var(--success);
  border-style: solid;
  background: var(--success-bg);
}

.dropzone-inner {
  padding: 36px 28px;
  text-align: center;
  cursor: pointer;
  position: relative;
}

.dropzone-icon-wrap {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  transition: all var(--transition);
}

.dropzone:hover .dropzone-icon-wrap,
.dropzone.dragover .dropzone-icon-wrap {
  background: var(--primary-bg);
  transform: scale(1.05);
}

.dropzone.has-file .dropzone-icon-wrap {
  background: var(--success-bg);
}

.dropzone-inner svg {
  width: 32px;
  height: 32px;
  stroke: var(--text-muted);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke var(--transition);
}

.dropzone:hover .dropzone-inner svg,
.dropzone.dragover .dropzone-inner svg {
  stroke: var(--primary);
}

.dropzone.has-file .dropzone-inner svg {
  stroke: var(--success);
}

.dropzone-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}

.dropzone-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.dropzone-format {
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg-hover);
  display: inline-block;
  padding: 3px 12px;
  border-radius: var(--radius-pill);
  font-weight: 500;
  letter-spacing: 0.01em;
}

.dropzone-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dropzone-status {
  padding: 0;
  font-size: 0.85rem;
  transition: all var(--transition);
}

.dropzone-status:not(:empty) {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.dropzone.has-file .dropzone-status:not(:empty) {
  background: transparent;
  border-color: rgba(5,150,105,.2);
}

.dropzone-status .ok-line {
  color: var(--success);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dropzone-status .ok-line::before {
  content: '✓';
  width: 20px;
  height: 20px;
  background: var(--success);
  color: #fff;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 900;
  flex-shrink: 0;
}

.dropzone-status .err-line {
  color: var(--danger);
  font-weight: 600;
}

.import-settings {
  padding: 18px 20px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.import-settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.import-settings .form-label { font-size: 0.72rem; }

.import-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.import-actions button { min-height: 38px; }

.import-preview { margin-top: 14px; overflow: hidden; }

.import-preview-title {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 600;
}

.import-preview-table-wrap {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg-card);
}

.import-preview table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.74rem;
}

.import-preview th,
.import-preview td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  vertical-align: top;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.import-preview th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
}

.import-preview-empty {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* =============================================================================
   RECAP (Step 5)
   ============================================================================= */
.recap-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 32px;
}

.recap-item {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.recap-item::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--gradient-brand);
  opacity: 0.5;
}

.recap-item:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.recap-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
}

.recap-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

/* =============================================================================
   GENERATE ZONE (Step 5)
   ============================================================================= */
.generate-zone {
  text-align: center;
  padding-top: 8px;
}

.btn-generate {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 17px 48px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--gradient-brand);
  color: #fff;
  font-family: var(--font);
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-btn);
  letter-spacing: -0.02em;
  position: relative;
  overflow: hidden;
}

.btn-generate::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,.15) 0%, transparent 50%);
  opacity: 0;
  transition: opacity var(--transition);
}

.btn-generate:hover:not(:disabled)::after { opacity: 1; }

.btn-generate:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: var(--shadow-btn-hover);
}

.btn-generate:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none;
}

.btn-generate svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.generate-buttons-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.btn-new-request {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 13px 28px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: -0.01em;
}

.btn-new-request[hidden] { display: none; }

.btn-new-request:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn-new-request svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.generate-status {
  margin-top: 20px;
  font-size: 0.9rem;
  min-height: 24px;
  font-weight: 500;
}

.generate-status.pending { color: var(--primary); }
.generate-status.ok { color: var(--success); font-weight: 700; }
.generate-status.error { color: var(--danger); }

/* =============================================================================
   MODALS
   ============================================================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--modal-backdrop);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-overlay.open {
  display: flex;
  animation: fadeIn 0.2s ease;
}

#app-dialog-overlay {
  z-index: 320;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 600px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: modalSlide 0.3s cubic-bezier(.34,1.56,.64,1);
  position: relative;
}

.modal::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--gradient-brand);
  border-radius: var(--radius) var(--radius) 0 0;
}

.modal-lg { max-width: 720px; }

@keyframes modalSlide {
  from { opacity: 0; transform: translateY(24px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.modal-close {
  width: 34px;
  height: 34px;
  border: none;
  background: var(--bg-hover);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition);
  font-weight: 400;
  line-height: 1;
}

.modal-close:hover {
  background: var(--danger-bg);
  color: var(--danger);
  transform: scale(1.1);
}

.modal-body { padding: 26px; }

.modal-fieldset {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px;
  margin-bottom: 16px;
  background: var(--bg-hover);
}

body.dark .modal-fieldset { background: rgba(255,255,255,.02); }

.modal-fieldset legend {
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--primary);
  padding: 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

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

.btn-secondary {
  padding: 10px 22px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg-card);
  color: var(--text);
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-primary-modal {
  padding: 10px 22px;
  border: none;
  border-radius: var(--radius-xs);
  background: var(--gradient-brand);
  color: #fff;
  font-family: var(--font);
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 2px 10px rgba(37,99,235,.3);
}

.btn-primary-modal:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(37,99,235,.4);
}

.btn-primary-modal:disabled {
  opacity: 0.58;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.modal-status {
  text-align: center;
  font-size: 0.85rem;
  margin-top: 12px;
  min-height: 20px;
  font-weight: 500;
}

.modal-status.ok      { color: var(--success); font-weight: 700; }
.modal-status.error   { color: var(--danger); }
.modal-status.pending { color: var(--primary); }

/* =============================================================================
   HISTORY PANEL — Scroll isolé sur le corps du tableau
   ============================================================================= */

/* Le panneau occupe 95% de la fenêtre pour un confort maximal */
.history-panel {
  max-width: min(1200px, calc(100vw - 32px));
  width: 95vw;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* empêche le scroll global du modal */
  padding: 0;
}

/* En-tête figée — reste visible en toutes circonstances */
.history-header-fixed {
  flex: 0 0 auto;
}

/* Zone de filtres figée — recherche + statut restent accessibles */
.history-filters-fixed {
  flex: 0 0 auto;
  padding: 16px 24px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.history-toolbar { margin-bottom: 12px; }

.history-status {
  min-height: 20px;
  margin-bottom: 10px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.history-status.pending { color: var(--primary); }
.history-status.ok      { color: var(--success); }
.history-status.error   { color: var(--danger); }

/* Zone scrollable — UNIQUEMENT les lignes du tableau défilent */
.history-body-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
}

/* IMPORTANT — HISTORIQUE RESPONSIVE
   La page historique doit rester lisible sans scroll horizontal.
   Les textes longs ne doivent jamais élargir le tableau.
   Les actions doivent être regroupées ou compactées.
   Les détails complets doivent être disponibles via l’action “Voir”. */

.history-table-wrap {
  width: 100%;
  background: var(--bg-card);
  overflow-x: visible; /* permet aux dropdowns de déborder */
  padding-bottom: 20px; /* marge de confort */
}

.history-table {
  width: 100% !important;
  min-width: unset !important;
  border-collapse: collapse;
  font-size: 0.82rem;
  table-layout: fixed; /* Force le respect des largeurs */
}

/* En-têtes et cellules */
.history-table th,
.history-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  white-space: normal;
  word-wrap: break-word;
  word-break: break-word;
  overflow: hidden;
}

/* En-têtes sticky dans le conteneur scrollable */
.history-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 700;
  white-space: nowrap;
}

/* Définition des largeurs de colonnes */
.history-table th:nth-child(1),
.history-table td:nth-child(1) {
  width: 9%; /* N° demande */
}
.history-table th:nth-child(2),
.history-table td:nth-child(2) {
  width: 13%; /* Financement */
}
.history-table th:nth-child(3),
.history-table td:nth-child(3) {
  width: 23%; /* Bénéficiaire */
}
.history-table th:nth-child(4),
.history-table td:nth-child(4) {
  width: 12%; /* Type */
}
/* IMPORTANT — HISTORIQUE / DATE
   La date doit toujours rester sur une seule ligne.
   Ne pas laisser la colonne Date couper 25/06/2026 sur deux lignes. */
.history-table th:nth-child(5),
.history-table td:nth-child(5) {
  width: 11%; /* Date */
  white-space: nowrap;
}
.history-table th:nth-child(6),
.history-table td:nth-child(6) {
  width: 15%; /* Montants */
}
.history-table th:nth-child(7),
.history-table td:nth-child(7) {
  width: 120px; /* Statut */
  min-width: 120px;
  text-align: center;
  overflow: visible;
  white-space: nowrap;
}
.history-table th:nth-child(8),
.history-table td:nth-child(8) {
  width: 125px; /* Largeur stable pour le bouton Actions */
  text-align: right;
  overflow: visible; /* empêche le rognage du dropdown */
}

.history-table tbody tr:hover { background: var(--bg-hover); }
.history-table tr:last-child td { border-bottom: none; }

/* Troncature intelligente du bénéficiaire */
.beneficiary-name-col {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  font-weight: 500;
  cursor: help;
}

/* Double ligne pour montants */
.amounts-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.76rem;
}
.amount-row {
  display: flex;
  justify-content: space-between;
  gap: 6px;
}
.amount-label {
  color: var(--text-secondary);
  font-weight: 700;
}
.amount-val {
  font-weight: 600;
}

/* Statuts */
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  max-width: 100%;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.status-draft      { color: var(--text-secondary); background: var(--bg-hover); }
.status-validated,
.status-generated  { color: var(--primary-text);   background: var(--primary-bg); }
.status-sent       { color: var(--warning);         background: var(--warning-bg); }
.status-accepted   { color: var(--success-text);    background: var(--success-bg); }
.status-rejected   { color: var(--danger);          background: var(--danger-bg); }
/* Conservé pour compatibilité de tests */
.history-actions {
  display: inline-flex;
}

.history-action {
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
  transition: color var(--transition);
}
.history-action:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

.history-missing {
  color: var(--warning);
  font-weight: 600;
}

/* Custom Dropdown d'Actions */
.dropdown {
  position: relative;
  display: inline-block;
  text-align: left;
}

.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 100;
  min-width: 170px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  box-shadow: var(--shadow-lg);
  padding: 6px 0;
  margin-top: 4px;
  animation: slideUp 0.15s ease;
}

.dropdown.open .dropdown-menu {
  display: block;
}

.dropdown-menu.fixed-portal {
  position: fixed !important;
  z-index: 99999 !important;
  margin: 0 !important;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.dropdown-item:hover {
  background: var(--bg-hover);
}

.dropdown-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.dropdown-item.btn-delete {
  color: var(--danger);
}
.dropdown-item.btn-delete:hover {
  background: var(--danger-bg);
}

.dropdown-item svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  flex-shrink: 0;
}

.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

.dropdown-header {
  padding: 4px 16px;
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.status-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-indicator.status-draft      { background: var(--text-secondary); }
.status-indicator.status-validated  { background: var(--success-text); }
.status-indicator.status-generated  { background: var(--primary); }
.status-indicator.status-sent       { background: var(--warning); }
.status-indicator.status-accepted   { background: var(--success-text); }
.status-indicator.status-rejected   { background: var(--danger); }

.dropdown-toggle svg.icon-arrow {
  width: 12px;
  height: 12px;
  transition: transform var(--transition);
}

.dropdown.open .dropdown-toggle svg.icon-arrow {
  transform: rotate(180deg);
}

/* Positionnement intelligent pour s'ouvrir vers le haut */
.dropdown.open-up .dropdown-menu {
  top: auto;
  bottom: 100%;
  margin-top: 0;
  margin-bottom: 4px;
  animation: slideDown 0.15s ease;
}

/* Style dédié au bouton Actions de l'historique */
.history-action-btn {
  white-space: nowrap !important;
  min-width: 95px;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px !important;
  border: 1.5px solid var(--border) !important;
  border-radius: var(--radius-xs) !important;
  background: var(--bg-card) !important;
  color: var(--text) !important;
  font-size: 0.82rem !important;
  font-weight: 600 !important;
  cursor: pointer;
  transition: all var(--transition);
}

.history-action-btn:hover {
  background: var(--bg-hover) !important;
  border-color: var(--border-strong) !important;
}

.history-action-btn svg.icon-arrow {
  width: 10px;
  height: 10px;
  margin-left: 2px;
  flex-shrink: 0;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

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

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* MODE RESPONSIVE EN CARTES */
@media (max-width: 768px) {
  .history-table-wrap {
    overflow-x: visible;
  }
  
  .history-table, 
  .history-table thead, 
  .history-table tbody, 
  .history-table th, 
  .history-table td, 
  .history-table tr {
    display: block;
    width: 100% !important;
  }
  
  .history-table thead {
    display: none; /* cache les en-têtes */
  }
  
  .history-table tr {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    padding: 16px;
    box-shadow: var(--shadow-sm);
  }
  
  .history-table td {
    border-bottom: none;
    padding: 8px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: right;
    overflow: visible;
  }
  
  .history-table td:first-child {
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
    margin-bottom: 8px;
    font-size: 0.95rem;
  }
  
  .history-table td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--text-secondary);
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-right: 12px;
    text-align: left;
  }
  
  .beneficiary-name-col {
    -webkit-line-clamp: unset;
    text-align: right;
    max-width: 60%;
  }
  
  .history-table td:nth-child(8) {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-top: 8px;
    justify-content: flex-end;
  }
  
  .history-table td:nth-child(8)::before {
    display: none; /* cache le label Actions */
  }
}

/* =============================================================================
   MODALE DÉTAILS — Grille de lecture
   ============================================================================= */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.detail-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.detail-row:last-child,
.detail-row:nth-last-child(2):nth-child(odd) {
  border-bottom: none;
}

.detail-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  min-width: 120px;
  flex: 0 0 auto;
}

.detail-value {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
  word-break: break-all;
}

/* Responsive : empiler sur petits écrans */
@media (max-width: 600px) {
  .detail-grid { grid-template-columns: 1fr; }
  .history-panel { width: 100vw; max-height: 100vh; }
}



/* =============================================================================
   FOOTER
   ============================================================================= */
.app-footer {
  text-align: center;
  padding: 18px 24px 90px;
  font-size: 0.73rem;
  color: var(--text-muted);
  position: relative;
  z-index: 1;
  letter-spacing: 0.01em;
}

/* =============================================================================
   EMPTY STATE
   ============================================================================= */
.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 52px;
  height: 52px;
  stroke: var(--text-muted);
  fill: none;
  stroke-width: 1.2;
  margin-bottom: 14px;
  opacity: 0.4;
}

.empty-state p { font-size: 0.9rem; font-weight: 500; }

/* =============================================================================
   LOADING SPINNER
   ============================================================================= */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}

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

/* =============================================================================
   STATUS UTILITIES
   ============================================================================= */
.status-ok      { color: var(--success); font-weight: 600; }
.status-error   { color: var(--danger);  font-weight: 500; }
.status-pending { color: var(--primary); }

/* =============================================================================
   RESPONSIVE — MOBILE ≤ 640px
   ============================================================================= */
@media (max-width: 640px) {
  .app-header-inner { padding: 12px 16px; }
  .header-badges { display: none; }
  main { padding: 16px 14px; }
  .step-card { padding: 22px 18px; }
  .form-grid-2 { grid-template-columns: 1fr; }
  .import-settings-grid { grid-template-columns: 1fr 1fr; }
  .import-actions { flex-direction: column; }
  .stepper { padding: 0 16px; }
  .stepper-inner { padding: 16px 0 14px; }
  .dot-label { font-size: 0.56rem; }
  .dot-num { width: 30px; height: 30px; font-size: 0.72rem; }
  .stepper-track, .stepper-progress { top: 31px; }
  .recap-grid { grid-template-columns: 1fr; }
  .radio-group { grid-template-columns: 1fr; }
  .project-grid { grid-template-columns: 1fr; }
  .modal { max-height: 92vh; }
  .history-toggle span { display: none; }
  .history-toggle { width: 36px; padding: 0; }
  .wizard-nav { padding: 12px 16px; }
  .btn-generate { padding: 15px 32px; font-size: 0.95rem; }
  .generate-buttons-row { flex-direction: column; align-items: center; }
  .step-header { flex-direction: column; gap: 12px; }
  .step-header h2 { font-size: 1.2rem; }
}

@media (max-width: 420px) {
  .import-settings-grid { grid-template-columns: 1fr; }
  .brand-cluster .app-header-text .subtitle { display: none; }
}

/* =============================================================================
   SCROLLBAR STYLING
   ============================================================================= */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-pill); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* =============================================================================
   SELECTION COLOR
   ============================================================================= */
::selection { background: var(--primary-bg); color: var(--primary-text); }


/* =============================================================================
   NOUVEAUX STYLES DE L'EXPÉRIENCE UTILISATEUR (UX PROJET)
   ============================================================================= */

/* En-tête : Info Projet Actif */
.header-project-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  padding: 6px 10px 6px 12px;
  border-radius: var(--radius-sm);
  margin-left: 20px;
  margin-right: auto;
}

.header-breadcrumb {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  white-space: nowrap;
}

.breadcrumb-kicker {
  color: var(--text-secondary);
  font-weight: 600;
}

.breadcrumb-link {
  min-width: 0;
  max-width: 260px;
  display: inline-flex;
  align-items: center;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  padding: 2px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color var(--transition);
}

.breadcrumb-link:hover {
  color: var(--primary-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.breadcrumb-separator {
  color: var(--text-muted);
  font-weight: 800;
}

.breadcrumb-current {
  min-width: 0;
  max-width: 220px;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.active-project-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.active-project-label strong {
  color: var(--primary);
  font-weight: 700;
}

.btn-header-nav {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-header-nav:hover {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  transform: translateY(-1px);
}

/* Vues de l'application */
.app-view {
  flex: 1 1 auto;
  width: 100%;
  max-width: 1100px;
  height: calc(100vh - var(--app-header-height));
  margin: 0 auto;
  padding: 24px 20px;
  animation: fadeIn 0.35s ease;
  z-index: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

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

.view-card {
  background: var(--bg-card);
  background-image: var(--gradient-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

.app-view > .view-card {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.app-view > .view-card:not(.project-history-shell):not(.beneficiaries-shell):not(.dashboard-shell):not(.project-info-shell) {
  overflow-y: auto;
}

.page-title-row {
  align-items: flex-start;
  justify-content: space-between;
}

/* En-tête de vue standard */
.view-header {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 24px;
}

.view-header-with-back {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 24px;
}

.view-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--primary-bg);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.view-icon svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
}

.view-subtitle {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.btn-back {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-back:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-strong);
  transform: translateX(-2px);
}

.btn-back svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.project-history-shell {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.history-page-sticky {
  position: sticky;
  top: 0;
  z-index: 4;
  flex: 0 0 auto;
  padding: 28px 32px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

body.dark .history-page-sticky {
  background: var(--bg-card);
}

.history-page-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: visible;
}

/* TABLEAU DE BORD PROJET */
.dashboard-shell {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.dashboard-sticky {
  flex: 0 0 auto;
  padding: 28px 32px 18px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.dashboard-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 32px 32px;
}

.dashboard-header-container {
  margin-bottom: 20px;
}

.dashboard-title-cluster h2 {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text);
  background: linear-gradient(90deg, var(--text) 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.dashboard-project-subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Grille des statistiques */
.dashboard-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 0;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition: transform var(--transition), box-shadow var(--transition);
}

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

.stat-num {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.financing-numbering-section {
  margin: 0 0 28px;
}

.financing-numbering-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.financing-numbering-header h3 {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
}

.financing-number-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.financing-number-card {
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.financing-number-label {
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.25;
}

.financing-number-ref {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.numbering-values {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.numbering-values div {
  min-width: 0;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 10px;
}

.numbering-values span {
  display: block;
  color: var(--text-secondary);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
}

.numbering-values strong {
  display: block;
  margin-top: 3px;
  color: var(--primary);
  font-size: 1.08rem;
  font-weight: 800;
  line-height: 1.2;
}

.numbering-warning {
  margin-top: 10px;
  color: var(--warning);
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.35;
}

.numbering-empty {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.draft-card {
  margin: 0 0 28px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.draft-card-main {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.draft-card-icon {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
  background: var(--primary-bg);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.draft-card-icon svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
}

.draft-card h3 {
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--text);
}

.draft-card p {
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1.35;
}

.draft-card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.draft-choice-dialog {
  max-width: 520px;
}

.draft-choice-message {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

.draft-choice-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 20px;
}

.draft-choice-actions button {
  width: 100%;
}

/* Grille des actions */
.dashboard-actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.dashboard-action-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: all var(--transition-spring);
  position: relative;
  overflow: hidden;
}

.dashboard-action-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 4px;
  background: var(--gradient-brand);
  opacity: 0;
  transition: opacity var(--transition);
}

.dashboard-action-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
}

.dashboard-action-card:hover::before {
  opacity: 1;
}

.action-card-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.dashboard-action-card:hover .action-card-icon {
  background: var(--primary-bg);
  color: var(--primary);
}

.action-card-icon svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
}

.action-card-text h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.action-card-text p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.4;
}

/* HISTORIQUE DU PROJET EN LIGNE */
.history-filters-inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 0;
}

.history-filters-inline .form-field.search-field {
  min-width: 0;
  width: 100%;
  max-width: none;
}

/* BÉNÉFICIAIRES */
.beneficiaries-shell {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.beneficiaries-sticky {
  position: sticky;
  top: 0;
  z-index: 5;
  flex: 0 0 auto;
  padding: 28px 32px 18px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.beneficiaries-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 0;
}

.beneficiaries-toolbar .search-field {
  flex: 1 1 auto;
  min-width: 0;
  max-width: none;
}

.beneficiary-toolbar-actions {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 12px;
  flex: 0 0 auto;
}

.beneficiaries-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 32px 32px;
}

.beneficiary-list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

.beneficiary-card-skeleton {
  min-height: 168px;
  border-radius: 16px;
}

.beneficiaries-loading-label {
  grid-column: 1 / -1;
  color: var(--text-muted, #64748b);
  font-size: 0.92rem;
  padding: 0.25rem 0;
}

.beneficiaries-load-error {
  grid-column: 1 / -1;
}

.beneficiary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: all var(--transition);
}

.beneficiary-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.beneficiary-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.beneficiary-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  background: var(--accent-bg);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
}

.beneficiary-name-cluster h4 {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.beneficiary-number {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.beneficiary-card-details {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
}

.ben-detail-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.ben-label {
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}

.ben-val {
  text-align: right;
  word-break: break-all;
  font-weight: 500;
}

.beneficiary-card-actions {
  display: flex;
  gap: 10px;
  margin-top: auto;
}

.beneficiary-card-actions button {
  flex: 1;
}

.import-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.import-summary-grid > div {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 14px;
}

.import-summary-grid strong {
  display: block;
  font-size: 1.35rem;
  line-height: 1;
  color: var(--text);
}

.import-summary-grid span {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.beneficiary-import-mapping {
  margin-bottom: 14px;
}

.import-mapping-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.import-mapping-header strong {
  color: var(--text);
  font-size: 0.88rem;
}

.import-mapping-header span {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.import-mapping-table-wrap {
  max-height: 180px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg-card);
}

.import-mapping-table {
  width: 100%;
  min-width: 680px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.78rem;
}

.import-mapping-table th,
.import-mapping-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  text-align: left;
}

.import-mapping-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-hover);
  color: var(--text);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.import-map-missing td {
  color: var(--danger);
}

.import-map-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 78px;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.68rem;
  font-weight: 800;
}

.import-map-pill.ok {
  background: color-mix(in srgb, var(--success) 14%, transparent);
  color: var(--success);
}

.import-map-pill.error {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
}

.import-mapping-ignored {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.beneficiary-import-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  min-height: 180px;
  overflow: hidden;
}

.import-empty {
  padding: 28px;
  text-align: center;
  color: var(--text-muted);
  font-weight: 600;
}

.import-preview-table-wrap {
  max-height: 44vh;
  overflow: auto;
}

.import-preview-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 820px;
  font-size: 0.82rem;
}

.import-preview-table th,
.import-preview-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  text-align: left;
  vertical-align: top;
}

.import-preview-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.import-preview-table td:first-child,
.import-preview-table th:first-child {
  text-align: center;
  width: 72px;
}

.import-status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}

.import-status-pill.importable {
  color: var(--success-text);
  background: var(--success-bg);
}

.import-status-pill.duplicate {
  color: var(--warning);
  background: var(--warning-bg);
}

.import-status-pill.error {
  color: var(--danger);
  background: var(--danger-bg);
}

.app-dialog-message {
  color: var(--text-secondary);
  line-height: 1.6;
  font-weight: 500;
}

.app-dialog-details {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-size: 0.84rem;
  line-height: 1.5;
}

/* INFORMATIONS DU PROJET */
.project-info-details {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.project-info-shell {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.project-info-sticky {
  flex: 0 0 auto;
  padding: 28px 32px 18px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.project-info-sticky .view-header {
  margin-bottom: 0;
}

.project-info-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 32px 32px;
}

.info-section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  background: var(--bg-hover);
  border-radius: var(--radius-md);
  padding: 24px;
  border: 1px solid var(--border);
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.info-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.info-value {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text);
  white-space: pre-line;
}

.project-info-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* Modifs Responsive supplémentaires */
@media (max-width: 768px) {
  .header-project-info {
    display: none !important; /* Cache les infos projet de l'en-tête sur tablette/mobile car l'en-tête est trop étroite */
  }
  .app-view {
    padding: 16px 14px;
  }
  .dashboard-sticky,
  .project-info-sticky {
    padding: 22px 20px 16px;
  }
  .dashboard-scroll,
  .project-info-scroll {
    padding: 20px;
  }
  .dashboard-stats-grid {
    grid-template-columns: 1fr 1fr;
  }
  .draft-card {
    align-items: stretch;
    flex-direction: column;
  }
  .draft-card-actions {
    justify-content: stretch;
  }
  .draft-card-actions button {
    flex: 1 1 160px;
  }
  .beneficiaries-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .beneficiaries-shell {
    height: 100%;
    min-height: 0;
  }
  .beneficiaries-sticky {
    padding: 22px 20px 16px;
  }
  .beneficiaries-scroll {
    padding: 20px;
  }
  .beneficiary-toolbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }
  .beneficiary-toolbar-actions button {
    flex: 1 1 220px;
  }
  .import-summary-grid {
    grid-template-columns: 1fr;
  }
  .project-history-shell {
    height: 100%;
    min-height: 0;
  }
  .history-page-sticky {
    padding: 22px 20px 16px;
  }
}


/* =============================================================================
   IMPORTANT — BUTTON DESIGN SYSTEM
   Aucun bouton visible ne doit rester sans style.
   Utiliser les classes communes : btn-primary, btn-secondary, btn-danger, btn-danger-outline, btn-ghost.
   ============================================================================= */

[hidden] {
  display: none !important;
}

.btn-primary, .btn-secondary, .btn-danger, .btn-danger-outline, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 22px;
  border-radius: var(--radius-xs);
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  text-decoration: none;
}

.btn-primary {
  background: var(--gradient-brand);
  color: #fff;
  box-shadow: 0 2px 10px rgba(37,99,235,.3);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(37,99,235,.4);
}
.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 2px 10px rgba(220,38,38,.2);
}
.btn-danger:hover {
  background: #b91c1c;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(220,38,38,.3);
}
.btn-danger:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-danger-outline {
  background: transparent;
  border: 1.5px solid var(--danger);
  color: var(--danger);
}
.btn-danger-outline:hover {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger-outline:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1.5px solid transparent;
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* Small helper class */
.btn-sm {
  padding: 6px 14px;
  font-size: 0.82rem;
}

/* Icons inside design system buttons */
.btn-primary svg,
.btn-secondary svg,
.btn-danger svg,
.btn-danger-outline svg,
.btn-ghost svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* =============================================================================
   INITIALISATION MULTI-TENANT ET CHARGEMENTS NEUTRES
   ============================================================================= */
.session-loading-view {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

.session-loading-shell {
  width: min(520px, 100%);
  display: grid;
  justify-items: center;
  gap: 20px;
  padding: 42px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--gradient-card);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.session-loading-shell h2 {
  margin-bottom: 6px;
  font-size: 1.35rem;
}

.session-loading-shell p {
  color: var(--text-secondary);
}

.session-loading-mark {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
}

.session-loading-mark span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--primary);
  animation: session-loading-pulse 1s ease-in-out infinite;
}

.session-loading-mark span:nth-child(2) { animation-delay: .14s; }
.session-loading-mark span:nth-child(3) { animation-delay: .28s; }

@keyframes session-loading-pulse {
  0%, 100% { opacity: .3; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-5px); }
}

.skeleton {
  position: relative;
  overflow: hidden;
  min-height: 18px;
  border-radius: var(--radius-xs);
  background: var(--bg-hover);
  border: 1px solid var(--border);
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.65), transparent);
  animation: skeleton-shimmer 1.35s ease-in-out infinite;
}

body.dark .skeleton::after {
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.08), transparent);
}

@keyframes skeleton-shimmer { to { transform: translateX(100%); } }

.project-card-skeleton {
  min-height: 118px;
  border-radius: var(--radius-md);
}

.stat-card-skeleton {
  min-height: 96px;
}

.dashboard-title-skeleton {
  width: min(320px, 72vw);
  height: 30px;
}

.stats-refreshing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: .78rem;
}

.dashboard-stats-grid.is-refreshing::after {
  content: 'Actualisation…';
  position: absolute;
  right: 0;
  top: -24px;
  color: var(--text-muted);
  font-size: .76rem;
}

.dashboard-stats-grid.is-refreshing {
  position: relative;
}

.load-error {
  grid-column: 1 / -1;
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-secondary);
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .session-loading-mark span,
  .skeleton::after {
    animation: none;
  }
}

/* =============================================================================
   BARRE DE NAVIGATION PRINCIPALE PROJET (PROJECT-NAVBAR)
   ============================================================================= */
.project-navbar {
  position: sticky;
  top: var(--app-header-height, 56px);
  z-index: 90;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: background var(--transition);
}

body.dark .project-navbar {
  background: var(--bg-card);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.project-navbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 6px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
}

.project-navbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.project-active-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.project-active-badge {
  display: inline-flex;
  align-items: center;
  max-width: 200px;
  padding: 3px 10px;
  background: var(--primary-bg);
  color: var(--primary-text);
  border: 1px solid rgba(37, 99, 235, 0.2);
  border-radius: var(--radius-xs);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-navbar-toggle {
  display: none;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg-card);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  align-items: center;
  gap: 6px;
}

.project-navbar-toggle svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.project-navbar-menu {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-grow: 1;
  justify-content: flex-start;
  margin-left: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.project-navbar-menu::-webkit-scrollbar { display: none; }

.nav-item-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
  border-radius: var(--radius-xs);
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition);
  position: relative;
}

.nav-item-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  flex-shrink: 0;
  transition: stroke var(--transition);
}

.nav-item-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-item-btn.active {
  background: var(--primary-bg);
  color: var(--primary-text);
  font-weight: 700;
}

.nav-item-btn.active svg {
  stroke: var(--primary);
}

.nav-item-btn.active::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 14px;
  right: 14px;
  height: 2px;
  background: var(--primary);
  border-radius: 2px 2px 0 0;
}

.project-navbar-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.btn-change-project {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--bg-card);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}

.btn-change-project:hover {
  background: var(--bg-hover);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-change-project svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* Responsive mobile navigation */
@media (max-width: 960px) {
  .project-navbar-inner {
    flex-wrap: wrap;
    padding: 8px 16px;
  }
  .project-navbar-toggle {
    display: inline-flex;
  }
  .project-navbar-menu {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    margin-left: 0;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }
  .project-navbar-menu.open {
    display: flex;
  }
  .nav-item-btn {
    width: 100%;
    justify-content: flex-start;
    padding: 10px 14px;
  }
  .nav-item-btn.active::after {
    display: none;
  }
}

/* =============================================================================
   ZONE DE FILTRES D'HISTORIQUE (HISTORY-FILTER-BAR)
   ============================================================================= */
.history-filter-bar {
  margin-bottom: 16px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}

.filter-bar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text);
}

.filter-bar-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-bar-title svg {
  width: 16px;
  height: 16px;
  stroke: var(--primary);
  stroke-width: 2;
  fill: none;
}

.filter-bar-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.filter-count-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  background: var(--primary-bg);
  color: var(--primary-text);
  border: 1px solid rgba(37, 99, 235, 0.2);
  border-radius: 20px;
  font-size: 0.76rem;
  font-weight: 700;
}

.btn-reset-filters {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-reset-filters:hover {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger);
}

.btn-reset-filters svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px 14px;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.filter-input {
  height: 34px !important;
  font-size: 0.8rem !important;
  padding: 0 10px !important;
  border-radius: var(--radius-xs) !important;
}


