:root {
  --navy: #0B2545;
  --navy-light: #133A66;
  --orange: #E87A00;
  --orange-light: #FFE9CC;
  --grey-50: #F9FAFB;
  --grey-100: #F4F6F8;
  --grey-200: #E5E7EB;
  --grey-300: #D1D5DB;
  --grey-500: #6B7280;
  --grey-700: #374151;
  --grey-900: #111827;
  --green: #059669;
  --green-light: #D1FAE5;
  --red: #DC2626;
  --red-light: #FEE2E2;
  --shadow-sm: 0 1px 2px rgba(11,37,69,0.05);
  --shadow: 0 1px 3px rgba(11,37,69,0.06), 0 8px 24px rgba(11,37,69,0.05);
  --shadow-lg: 0 20px 50px rgba(11,37,69,0.15);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, #F4F6F8 0%, #E8EDF2 100%);
  color: var(--grey-700);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--navy); text-decoration: none; }
a:hover { color: var(--orange); }

/* ===== TOP NAV ===== */
.topnav {
  background: white;
  border-bottom: 1px solid var(--grey-200);
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow-sm);
}
.topnav-inner {
  max-width: 1280px; margin: 0 auto;
  padding: 0 24px; height: 60px;
  display: flex; align-items: center; gap: 32px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 16px; color: var(--navy);
}
.brand-icon {
  width: 34px; height: 34px; background: var(--navy);
  color: white; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-links a {
  padding: 8px 14px; border-radius: 8px;
  color: var(--grey-700); font-weight: 500; font-size: 13.5px;
  transition: all 0.15s;
}
.nav-links a:hover { background: var(--grey-100); color: var(--navy); }
.nav-user { display: flex; align-items: center; gap: 8px; }
.nav-user-link {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 6px; border-radius: 999px;
  background: var(--grey-100);
}
.nav-user-link:hover { background: var(--grey-200); color: var(--navy); }
.nav-user-avatar {
  width: 28px; height: 28px; background: var(--navy);
  color: white; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.nav-user-name { font-size: 13px; font-weight: 600; color: var(--navy); }
.nav-logout {
  width: 34px; height: 34px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--grey-500); font-size: 18px;
}
.nav-logout:hover { background: var(--red-light); color: var(--red); }

/* ===== MAIN ===== */
.main {
  flex: 1; max-width: 1280px; width: 100%;
  margin: 0 auto; padding: 28px 24px;
}
.appfooter {
  text-align: center; padding: 20px;
  font-size: 11.5px; color: #9CA3AF;
}

/* ===== TYPO ===== */
h1 { font-size: 24px; font-weight: 800; color: var(--navy); letter-spacing: -0.02em; }
h2 { font-size: 18px; font-weight: 700; color: var(--navy); margin-bottom: 14px; }
h3 { font-size: 14px; font-weight: 700; color: var(--navy); }
.page-header { margin-bottom: 24px; display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.page-header p { color: var(--grey-500); font-size: 13.5px; margin-top: 4px; }

/* ===== CARDS ===== */
.card { background: white; border-radius: 16px; padding: 22px; box-shadow: var(--shadow); }
.card-tight { padding: 16px; }
.card-flush { padding: 0; overflow: hidden; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 11.5px; color: var(--grey-500);
  margin-bottom: 5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 13px;
  font-size: 13.5px; font-family: inherit;
  border: 1px solid var(--grey-300); border-radius: 9px;
  outline: none; color: var(--navy); background: white;
  transition: all 0.15s;
}
.form-textarea { resize: vertical; min-height: 90px; line-height: 1.55; }
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(232,122,0,0.12);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .form-row, .form-row-3 { grid-template-columns: 1fr; } }
.form-hint { font-size: 11.5px; color: var(--grey-500); margin-top: 4px; }
.section-title {
  display: flex; align-items: center; gap: 8px;
  color: var(--navy); font-weight: 700; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-top: 22px; margin-bottom: 12px;
  padding-bottom: 8px; border-bottom: 1px solid var(--grey-200);
}
.section-title:first-child { margin-top: 0; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; font-size: 13px; font-weight: 600;
  font-family: inherit; border-radius: 10px;
  cursor: pointer; transition: all 0.15s;
  border: 1px solid var(--grey-300); background: white; color: var(--navy);
  text-decoration: none;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); color: var(--navy); }
.btn-primary { background: var(--navy); color: white; border: none; box-shadow: 0 2px 8px rgba(11,37,69,0.2); }
.btn-primary:hover { background: var(--navy-light); color: white; box-shadow: 0 4px 14px rgba(11,37,69,0.28); }
.btn-orange { background: var(--orange); color: white; border: none; box-shadow: 0 2px 8px rgba(232,122,0,0.25); }
.btn-orange:hover { background: #d36e00; color: white; }
.btn-danger { background: var(--red); color: white; border: none; }
.btn-danger:hover { background: #b91c1c; color: white; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }
.btn-ghost { background: transparent; border: none; color: var(--grey-500); }
.btn-ghost:hover { background: var(--grey-100); color: var(--navy); box-shadow: none; transform: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-group { display: flex; gap: 10px; flex-wrap: wrap; }

/* ===== FLASH ===== */
.flash {
  max-width: 1280px; margin: 16px auto 0;
  padding: 12px 20px; border-radius: 10px;
  font-size: 13.5px; font-weight: 500;
  display: flex; align-items: center; gap: 10px;
}
.flash-success { background: var(--green-light); color: #065F46; border-left: 3px solid var(--green); }
.flash-error { background: var(--red-light); color: #991B1B; border-left: 3px solid var(--red); }
.flash-info { background: #DBEAFE; color: #1E40AF; border-left: 3px solid #2563EB; }

/* ===== STATS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: white; border-radius: 14px; padding: 18px;
  box-shadow: var(--shadow-sm); border-left: 3px solid var(--orange);
}
.stat-label { font-size: 11.5px; color: var(--grey-500); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 800; color: var(--navy); margin-top: 4px; letter-spacing: -0.02em; }
.stat-sub { font-size: 11.5px; color: var(--grey-500); margin-top: 2px; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; background: white; border-radius: 14px; box-shadow: var(--shadow); }
table.app-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.app-table th {
  text-align: left; padding: 12px 16px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--grey-500); font-weight: 700;
  border-bottom: 1px solid var(--grey-200); background: var(--grey-50);
}
.app-table td { padding: 14px 16px; border-bottom: 1px solid var(--grey-100); color: var(--grey-700); }
.app-table tr:last-child td { border-bottom: none; }
.app-table tr:hover td { background: var(--grey-50); }
.app-table .num { font-family: 'SF Mono', Menlo, monospace; font-size: 12px; color: var(--navy); font-weight: 600; }
.app-table-empty { padding: 60px 20px; text-align: center; color: var(--grey-500); }

/* ===== BADGE ===== */
.badge {
  display: inline-flex; align-items: center; padding: 3px 10px;
  border-radius: 999px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.badge-draft { background: var(--grey-200); color: var(--grey-700); }
.badge-sent { background: #DBEAFE; color: #1E40AF; }
.badge-signed { background: var(--green-light); color: #065F46; }
.badge-paid { background: #C7F4D2; color: #14532D; border: 1px solid #16A34A; }
.badge-lost { background: var(--red-light); color: #991B1B; }
.badge-pending { background: #FEF3C7; color: #92400E; border: 1px solid #F59E0B; }
.badge-rejected { background: var(--red-light); color: #991B1B; }
.badge-pending { background: #FED7AA; color: #92400E; border: 1px solid var(--orange); }
.badge-rejected { background: var(--red-light); color: #991B1B; border: 1px solid var(--red); }
.badge-admin { background: var(--navy); color: white; }
.badge-commercial { background: var(--orange-light); color: #92400E; }

/* ===== LOGIN ===== */
.login-page {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: white; border-radius: 20px; padding: 40px;
  box-shadow: var(--shadow-lg); width: 100%; max-width: 420px;
}
.login-logo {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 28px;
}
.login-logo .brand-icon { width: 44px; height: 44px; font-size: 22px; border-radius: 11px; }
.login-logo h1 { font-size: 20px; }
.login-logo p { font-size: 12.5px; color: var(--grey-500); margin-top: 2px; }

/* ===== GENERATOR (2 colonnes) ===== */
.gen-grid { display: grid; grid-template-columns: minmax(0, 420px) 1fr; gap: 22px; }
@media (max-width: 1000px) { .gen-grid { grid-template-columns: 1fr; } }

.email-preview {
  background: white; border-radius: 16px; padding: 22px;
  box-shadow: var(--shadow);
}
.email-preview-header {
  display: flex; justify-content: space-between; align-items: center;
  padding-bottom: 14px; margin-bottom: 14px;
  border-bottom: 1px solid var(--grey-200);
}
.email-preview-title { font-weight: 700; color: var(--navy); font-size: 13.5px; }
.email-meta { font-size: 11.5px; color: var(--grey-500); }
.email-subject-line { margin-bottom: 14px; font-size: 13px; }
.email-subject-line .label { color: var(--grey-500); margin-right: 8px; }
.email-subject-line .value { color: var(--navy); font-weight: 600; }
.email-body {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12.5px; color: var(--grey-700);
  white-space: pre-wrap; word-break: break-word;
  line-height: 1.65; max-height: 540px; overflow-y: auto;
  padding: 18px; background: var(--grey-50); border-radius: 10px;
}

.recap-box {
  margin-top: 18px; padding: 14px;
  background: var(--grey-100); border-radius: 12px;
  border-left: 3px solid var(--orange);
}
.recap-label { font-size: 11px; color: var(--grey-500); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.recap-title { font-size: 14px; color: var(--navy); font-weight: 700; }
.recap-sub { font-size: 11.5px; color: var(--grey-500); margin-top: 2px; }

/* ===== PROFILE / CONFIG ===== */
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 900px) { .profile-grid { grid-template-columns: 1fr; } }

.email-method-card {
  border: 2px solid var(--grey-200); border-radius: 12px;
  padding: 18px; transition: all 0.15s;
}
.email-method-card.active { border-color: var(--orange); background: #FFF9F0; }
.email-method-card h3 { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.email-method-card .status { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.email-method-card .status.on { background: var(--green-light); color: #065F46; }
.email-method-card .status.off { background: var(--grey-200); color: var(--grey-500); }
.email-method-card p { font-size: 12.5px; color: var(--grey-500); margin-bottom: 12px; line-height: 1.5; }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--navy); color: white;
  padding: 12px 22px; border-radius: 12px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  transition: transform 0.3s ease;
  z-index: 1000;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast-success { background: var(--green); }
.toast-error { background: var(--red); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(11,37,69,0.5);
  display: none; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: white; border-radius: 16px; padding: 28px;
  max-width: 480px; width: 100%; box-shadow: var(--shadow-lg);
}
.modal h2 { margin-bottom: 8px; }
.modal p { color: var(--grey-500); font-size: 13px; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
