/*
 * CERTPEB — Design System v2.0
 * Style: Modern SaaS (Linear/Stripe inspired)
 */

/* ============ TOKENS ============ */
:root {
  --primary: #0066ff;
  --primary-dark: #0050cc;
  --primary-light: #e6efff;
  --primary-50: #f5f9ff;

  --bg: #f7f9fc;
  --surface: #ffffff;
  --surface-alt: #fafbfc;

  --text: #0a1a3d;
  --text-strong: #050e24;
  --text-muted: #6b7280;
  --text-soft: #9ca3af;

  --border: #e5e7eb;
  --border-strong: #d1d5db;

  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --info: #3b82f6;
  --info-light: #dbeafe;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 3px rgba(10, 26, 61, 0.06);
  --shadow-md: 0 4px 12px rgba(10, 26, 61, 0.08);
  --shadow-lg: 0 12px 32px rgba(10, 26, 61, 0.12);

  --sidebar-width: 240px;
  --topbar-height: 64px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  --transition: 150ms ease;
}

/* ============ BASE ============ */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text-strong);
  font-weight: 600;
  letter-spacing: -0.01em;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ============ LOGIN ============ */
#login-section {
  min-height: 100vh;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: linear-gradient(135deg, var(--primary-50) 0%, var(--bg) 100%);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px 32px;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  margin-bottom: 12px;
}

.login-brand img {
  width: 100%;
  max-width: 160px;
  height: auto;
  object-fit: contain;
  display: block;
}

.login-brand p {
  color: var(--text-muted);
  margin: 0;
  font-size: 13px;
}

/* ============ APP SHELL (Sidebar + Main) ============ */
#app-section {
  display: none; /* JS bascule en flex après login */
  min-height: 100vh;
  background: var(--bg);
}

#app-section.app-shell-visible {
  display: flex;
}

/* ============ SIDEBAR ============ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand img {
  height: auto;
  width: 100%;
  max-width: 110px;
  object-fit: contain;
  display: block;
}

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

.sidebar-nav .nav-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-soft);
  padding: 16px 12px 8px;
  margin: 0;
  font-weight: 600;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 2px;
  border: none;
  background: transparent;
  text-align: left;
  width: 100%;
}

.sidebar-link i { font-size: 16px; opacity: 0.85; }

.sidebar-link:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.sidebar-link.active {
  background: var(--primary-light);
  color: var(--primary-dark);
  position: relative;
}

.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  margin-bottom: 8px;
}

.user-chip .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
}

.user-chip .user-meta { line-height: 1.2; min-width: 0; }
.user-chip .user-name { font-size: 13px; color: var(--text); font-weight: 600; }
.user-chip .user-role { font-size: 11px; color: var(--text-muted); }

/* ============ FOOTER APP ============ */
.app-footer {
  margin-top: auto;
  padding: 16px 28px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  color: var(--text-soft);
  text-align: center;
}
.app-footer a {
  color: var(--text-muted);
  font-weight: 500;
}
.app-footer a:hover { color: var(--primary); }

.login-footer {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-soft);
  text-align: center;
}
.login-footer a { color: var(--text-muted); font-weight: 500; }
.login-footer a:hover { color: var(--primary); }

@media (max-width: 640px) {
  .app-footer { padding: 14px 16px; font-size: 11px; }
}

/* ============ MAIN CONTENT ============ */
.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-strong);
  margin: 0;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.page-container {
  padding: 28px;
  flex: 1;
}

.page-section[hidden] { display: none !important; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 14px;
  padding: 8px 14px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  line-height: 1.4;
  font-family: var(--font-sans);
}

.btn:focus {
  outline: 2px solid var(--primary-light);
  outline-offset: 2px;
}

.btn-sm {
  padding: 9px 14px;
  font-size: 14px;
  min-height: 38px;
  min-width: 38px;
}
.btn-sm i { font-size: 16px; }

/* Bouton icon-only (sans <span> de texte) */
.btn-sm.btn-icon,
.table .btn-sm,
.text-end .btn-sm {
  padding: 8px;
  min-width: 40px;
}
.table .btn-sm i,
.text-end .btn-sm i { font-size: 17px; }

.btn-lg { padding: 12px 20px; font-size: 15px; min-height: 44px; }

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-color: var(--primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }

.btn-success {
  background: var(--success);
  color: white;
  border-color: var(--success);
}
.btn-success:hover { background: #0e9c6e; border-color: #0e9c6e; color: white; }

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

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

.btn-outline-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger-light);
}
.btn-outline-danger:hover { background: var(--danger-light); }

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

.btn-outline-secondary {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-outline-secondary:hover { background: var(--surface-alt); color: var(--text); }

/* ============ FORMS ============ */
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.form-label.small { font-size: 12px; }

.form-control,
input[type="text"].form-control,
input[type="email"].form-control,
input[type="password"].form-control,
input[type="number"].form-control,
input[type="date"].form-control,
input[type="time"].form-control,
textarea.form-control,
select.form-control,
select.form-select {
  display: block;
  width: 100%;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  font-family: var(--font-sans);
  transition: var(--transition);
}

.form-control:focus,
textarea.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-control[readonly] { background: var(--surface-alt); }

textarea.form-control { resize: vertical; min-height: 80px; }

/* ============ CARDS ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-body { padding: 18px; }

.ods-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
}

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

.ods-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 4px;
}

.ods-card-ref {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.ods-card-client {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-strong);
  margin: 0;
}

.ods-card-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.ods-card-meta i { width: 14px; opacity: 0.7; }

.ods-card-types {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.ods-card-type {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-alt);
  padding: 4px 8px;
  border-radius: 6px;
  display: inline-block;
}

.ods-card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.ods-card-actions .btn { flex: 1; min-width: fit-content; }

/* ============ BADGES ============ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-success, .bg-success { background: var(--success-light); color: #047857; }
.badge-warning, .bg-warning { background: var(--warning-light); color: #92400e; }
.badge-danger, .bg-danger { background: var(--danger-light); color: #b91c1c; }
.badge-info, .bg-info { background: var(--info-light); color: #1d4ed8; }
.badge-neutral, .bg-secondary { background: var(--surface-alt); color: var(--text-muted); }

.type-pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary-dark);
  white-space: nowrap;
}

/* ============ TABS ============ */
.nav-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  padding: 0;
  margin: 0 0 20px;
  list-style: none;
}

.nav-tabs .nav-item { margin-bottom: -1px; }

.nav-tabs .nav-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--text-muted);
  background: transparent;
  font-weight: 500;
  font-size: 14px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  transition: var(--transition);
}

.nav-tabs .nav-link:hover { color: var(--text); background: var(--surface-alt); }

.nav-tabs .nav-link.active {
  background: var(--surface);
  border-color: var(--border);
  border-bottom-color: var(--surface);
  color: var(--primary);
  font-weight: 600;
}

/* ============ TABLES ============ */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.table thead th {
  background: var(--surface-alt);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--text);
  vertical-align: middle;
}

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

.table .text-end { text-align: right; }

.table-responsive {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.table-responsive .table { border: none; border-radius: 0; }

/* ============ MISSION CARDS (grille responsive) ============ */
.mission-search-bar {
  margin: 16px 0 12px;
}
.mission-search-bar .input-group-text {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-muted);
}
.mission-search-bar input.form-control {
  border-color: var(--border);
}
.mission-search-bar input.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.12);
}

.mission-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.empty-state.full-width {
  grid-column: 1 / -1;
}

.mission-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

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

.mission-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.mission-card-ref {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.mission-card-date {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.mission-card-client {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.mission-card-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-strong);
  line-height: 1.3;
  word-break: break-word;
}

.mission-card-email {
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-all;
}
.mission-card-email i { margin-right: 4px; }

/* Adresse du bien : violet/indigo pour ressortir, distinct des badges bleus
   et des chips de rapport vertes */
.mission-card-address {
  font-size: 12px;
  color: #6d28d9;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.mission-card-address i { margin-right: 4px; opacity: 1; }

.ods-card-address {
  color: #6d28d9;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.ods-card-address i { opacity: 1; }

.mission-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mission-invoice-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mission-card-status {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  border: 1px dashed var(--border-strong);
  background: var(--surface-alt);
  color: var(--text-muted);
  align-self: flex-start;
}

.status-chip i { font-size: 14px; }

.status-chip-report {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.35);
  border-style: solid;
  color: #047857;
}

.status-chip-alert {
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.4);
  border-style: solid;
  color: #92400e;
  font-weight: 600;
}

.status-chip-forced {
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.35);
  border-style: solid;
  color: #4338ca;
  font-weight: 600;
}

.mission-card-reason {
  font-size: 13px;
  background: var(--surface-alt);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
}
.mission-card-reason strong { color: var(--danger); margin-right: 4px; }
.mission-card-reason em { font-style: italic; color: var(--text-muted); }

.mission-card-foot {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.mission-card-worker {
  font-size: 12px;
  color: var(--text-muted);
}
.mission-card-worker i { margin-right: 4px; }

.mission-card-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* Sur petit écran : une seule colonne */
@media (max-width: 540px) {
  .mission-cards-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .mission-card {
    padding: 16px;
  }
  .mission-card-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

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

.empty-state .icon {
  font-size: 40px;
  color: var(--text-soft);
  margin-bottom: 8px;
}

.empty-state h4 {
  margin: 0 0 4px;
  font-size: 15px;
  color: var(--text);
  font-weight: 600;
}

.empty-state p {
  margin: 0;
  font-size: 13px;
}

/* ============ MODAL OVERRIDES ============ */
.modal-content {
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  border-bottom: 1px solid var(--border);
  padding: 18px 24px;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-strong);
}

.modal-body { padding: 24px; }

.modal-footer {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  margin: 24px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.section-title:first-child { margin-top: 0; }

/* ============ ALERTS ============ */
.alert {
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid;
}

.alert-info, .alert-light {
  background: var(--info-light);
  border-color: rgba(59, 130, 246, 0.2);
  color: #1e40af;
}

.alert-danger {
  background: var(--danger-light);
  border-color: rgba(239, 68, 68, 0.2);
  color: #991b1b;
}

/* ============ SIGNATURE CANVAS ============ */
canvas {
  border: 1px dashed var(--border-strong);
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  touch-action: none;
  width: 100%;
  height: 130px;
  display: block;
}

/* ============ PAGINATION ============ */
.pagination {
  display: flex;
  gap: 4px;
  justify-content: center;
  list-style: none;
  padding: 0;
  margin: 24px 0 0;
}

.page-item .page-link {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-muted);
  background: var(--surface);
  cursor: pointer;
  transition: var(--transition);
}

.page-item:not(.disabled) .page-link:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-light);
}

.page-item.disabled .page-link {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

/* ============ UTILITIES ============ */
.text-muted { color: var(--text-muted) !important; }
.text-primary { color: var(--primary) !important; }
.text-danger { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }
.text-soft { color: var(--text-soft) !important; }

.bg-light { background: var(--surface-alt) !important; }
.bg-white { background: var(--surface) !important; }

.border { border: 1px solid var(--border) !important; }
.border-bottom { border-bottom: 1px solid var(--border) !important; }
.border-end { border-right: 1px solid var(--border) !important; }

.rounded { border-radius: var(--radius) !important; }
.rounded-sm { border-radius: var(--radius-sm) !important; }

/* Compatibilité avec les classes Bootstrap inline existantes */
.text-info { color: var(--info) !important; }
.text-end { text-align: right; }
.text-center { text-align: center; }

/* ============ HAMBURGER & BACKDROP ============ */
.btn-hamburger {
  display: none;
  font-size: 22px;
  padding: 6px 10px;
  margin-right: 8px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 26, 61, 0.4);
  z-index: 49;
  opacity: 0;
  transition: opacity 200ms ease;
}

.sidebar-backdrop.open {
  display: block;
  opacity: 1;
}

/* ============ RESPONSIVE TABLET (≤ 992px) ============ */
@media (max-width: 992px) {
  .btn-hamburger { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 250ms ease;
    z-index: 50;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    width: 100%;
  }

  #app-section.app-shell-visible {
    display: block;
  }
}

/* ============ RESPONSIVE MOBILE (≤ 640px) ============ */
@media (max-width: 640px) {
  .topbar { padding: 0 12px; height: 56px; }
  .topbar-title { font-size: 16px; max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .page-container { padding: 14px; }

  .ods-card-actions { gap: 4px; }
  .ods-card-actions .btn { padding: 8px 10px; font-size: 13px; }

  .modal-dialog {
    margin: 8px;
  }
  .modal-body { padding: 16px; }
  .modal-header { padding: 14px 16px; }
  .modal-footer { padding: 12px 16px; flex-wrap: wrap; }
  .modal-footer .btn { flex: 1; }

  .nav-tabs { overflow-x: auto; flex-wrap: nowrap; }
  .nav-tabs .nav-link { white-space: nowrap; font-size: 13px; padding: 8px 12px; }

  .table thead th { padding: 10px 12px; font-size: 11px; }
  .table tbody td { padding: 10px 12px; font-size: 13px; }

  .d-none-mobile { display: none !important; }

  .topbar-actions .btn { padding: 8px 12px; }

  .invoice-summary .invoice-row { padding: 10px 12px; }

  .login-card { padding: 28px 22px; }
}

/* ============ MODAL ÉLARGI — TABLETTE EN MODE PORTRAIT ============ */
/* En portrait (iPad…), Bootstrap plafonne .modal-lg à 500px : on l'élargit
   pour exploiter la largeur disponible et aérer le formulaire mission. */
@media (min-width: 700px) and (max-width: 1024px) and (orientation: portrait) {
  .modal-lg {
    max-width: calc(100vw - 40px);
    margin-left: auto;
    margin-right: auto;
  }
}

/* ============ SIGNATURE PLEIN ÉCRAN ============ */
.signature-fullscreen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1100;
  display: flex;
  flex-direction: column;
}

.signature-fullscreen[hidden] {
  display: none;
}

.signature-fullscreen-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 15px;
}

.signature-fullscreen-canvas {
  flex: 1;
  width: 100%;
  height: auto;
  background: var(--surface);
  border: none !important;
  border-radius: 0 !important;
  touch-action: none;
}

.signature-fullscreen-footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.signature-fullscreen-footer .btn {
  flex: 1;
  padding: 14px;
  font-size: 15px;
}

/* ============ TOUCH UX (tactile = encore plus grand) ============ */
@media (max-width: 1280px), (pointer: coarse) {
  /* Apple HIG : zone tactile 44pt minimum */
  .btn-sm {
    min-height: 44px;
    min-width: 44px;
    padding: 11px 16px;
    font-size: 15px;
  }
  .btn-sm i { font-size: 19px; }

  .btn-sm.btn-icon,
  .table .btn-sm,
  .text-end .btn-sm {
    padding: 10px;
    min-width: 44px;
  }
  .table .btn-sm i,
  .text-end .btn-sm i { font-size: 20px; }

  /* Onglets, sidebar, nav */
  .nav-tabs .nav-link { min-height: 44px; padding: 12px 18px; font-size: 15px; }
  .nav-tabs .nav-link i { font-size: 17px; }
  .sidebar-link { min-height: 48px; font-size: 15px; }
  .sidebar-link i { font-size: 19px; }

  /* Cellules de tables avec actions : espacement visuel */
  td.text-end {
    white-space: nowrap;
    min-width: 200px;
  }
  td.text-end .btn-sm { margin: 0 3px; }

  /* Actions dans les cartes ODS */
  .ods-card-actions { gap: 8px; }
  .ods-card-actions .btn { min-height: 44px; font-size: 14px; }
  .ods-card-actions .btn i { font-size: 18px; }

  /* Cartes ODS plus aérées en tactile */
  .ods-card { padding: 20px; }
  .ods-card-client { font-size: 17px; }
}

/* Très petit écran : empiler intelligemment */
@media (max-width: 640px) {
  td.text-end { min-width: 160px; }
  td.text-end .btn-sm { margin: 3px; }
}

/* ============ ICON HELPERS ============ */
.icon-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 14px;
}

/* Mission types checkboxes container */
.mission-types-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  padding: 12px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.mission-type-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
}

.mission-type-option:hover { background: var(--surface); }

.mission-type-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  margin: 0;
}

.mission-type-option label {
  cursor: pointer;
  margin: 0;
  font-size: 13px;
  flex: 1;
}

/* Type de mission personnalisé : bouton de suppression */
.mission-type-custom { padding-right: 4px; }

.mission-type-del {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 4px;
  line-height: 1;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  transition: var(--transition);
}
.mission-type-del:hover {
  background: var(--danger-light);
  color: var(--danger);
}

/* Bloc d'ajout manuel d'un type de mission */
.mission-type-add {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.mission-type-add input { flex: 1; }
.mission-type-add .btn { white-space: nowrap; flex-shrink: 0; }

/* Bandeau de révision du modal mission : icône d'en-tête alignée avec le texte
   (le texte multi-lignes reste aligné au lieu de revenir sous l'icône) */
#ods-revision-notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
#ods-revision-notice > i {
  margin-top: 2px;
  flex-shrink: 0;
}

/* ============ DASHBOARD ============ */
.dashboard-greeting {
  margin-bottom: 20px;
}
.dashboard-greeting h3 {
  margin: 0 0 4px;
  font-size: 22px;
}
.dashboard-greeting p {
  margin: 0;
  font-size: 14px;
}

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

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.kpi-card:hover {
  box-shadow: var(--shadow-md);
}

.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.kpi-primary .kpi-icon { background: var(--primary-light); color: var(--primary); }
.kpi-success .kpi-icon { background: var(--success-light); color: #047857; }
.kpi-warning .kpi-icon { background: var(--warning-light); color: #92400e; }
.kpi-info    .kpi-icon { background: var(--info-light); color: #1d4ed8; }

.kpi-content { min-width: 0; }
.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
  margin-bottom: 2px;
}
.kpi-value {
  font-size: 26px;
  font-weight: 600;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.dashboard-alerts {
  margin-bottom: 24px;
}
.dashboard-alerts:empty { display: none; }

.alert-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 992px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}

.shortcut-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.shortcut-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-sans);
  text-align: center;
  min-height: 90px;
}

.shortcut-btn i {
  font-size: 24px;
  color: var(--primary);
}

.shortcut-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}
.shortcut-btn:hover i {
  color: var(--primary-dark);
}

.recent-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.recent-item:last-child { border-bottom: none; }
.recent-item .recent-meta { min-width: 0; flex: 1; }
.recent-item .recent-ref {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}
.recent-item .recent-client {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============ INTL-TEL-INPUT (téléphone avec drapeau) ============ */
.iti {
  width: 100%;
  display: block;
}
.iti__tel-input {
  width: 100%;
  padding-left: 90px !important;
}
.iti__country-list {
  max-height: 220px;
  font-family: var(--font-sans);
  font-size: 13px;
}

/* ============ INPUT + BOUTON RAPIDE ============ */
.input-with-action {
  display: flex;
  gap: 4px;
}

.input-with-action .form-control {
  flex: 1;
  min-width: 0;
}

.input-with-action .btn-quick {
  flex-shrink: 0;
  min-width: 40px;
  padding: 9px 12px;
}

.input-with-action .btn-quick i { font-size: 16px; }

/* ============ AUTOCOMPLETE ============ */
.autocomplete-wrapper {
  position: relative;
}

.autocomplete-dropdown {
  position: absolute;
  top: calc(100% - 18px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  max-height: 280px;
  overflow-y: auto;
  z-index: 1080;
}

.autocomplete-dropdown[hidden] { display: none; }

/* Variante adresse : pas de champ d'aide sous l'input → collé au bord bas */
.autocomplete-dropdown.addr {
  top: 100%;
  margin-top: 2px;
}

.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover,
.autocomplete-item.highlighted {
  background: var(--primary-light);
}

.autocomplete-item .ac-name {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}
.autocomplete-item .ac-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.autocomplete-item .ac-meta span:not(:last-child)::after {
  content: '·';
  margin-left: 8px;
  opacity: 0.5;
}

.autocomplete-empty,
.autocomplete-loading {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

/* ============ DROPZONE (upload) ============ */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 36px 16px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-alt);
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.dropzone:hover {
  border-color: var(--primary);
  background: var(--primary-50);
}

.dropzone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.dropzone i {
  font-size: 36px;
  color: var(--primary);
  margin-bottom: 4px;
}

.dropzone strong {
  font-weight: 600;
  color: var(--text);
}

.dropzone small {
  color: var(--text-muted);
}

/* ============ REPORT CARD (état uploaded) ============ */
.report-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.report-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--danger-light);
  color: var(--danger);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.report-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  word-break: break-word;
}

.report-meta strong {
  font-size: 14px;
  color: var(--text);
}

.report-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.report-list .report-card {
  flex-wrap: wrap;
}

.report-list .report-meta {
  flex: 1 1 200px;
}

.report-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

/* ============ PROGRESS ============ */
.progress {
  background: var(--surface-alt);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  background: var(--primary);
  transition: width 200ms ease;
  height: 100%;
}

/* ============ INVOICE SUMMARY ============ */
.invoice-cell {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: flex-start;
}

.invoice-recap {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-top: 12px;
}

.invoice-recap-section {
  margin-bottom: 18px;
}
.invoice-recap-section:last-child { margin-bottom: 0; }

.invoice-recap-section h6 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 8px;
  font-weight: 600;
}

.invoice-recap-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px dashed var(--border);
  gap: 12px;
}
.invoice-recap-row:last-child { border-bottom: none; }
.invoice-recap-row .label { color: var(--text-muted); flex-shrink: 0; }
.invoice-recap-row .value { color: var(--text); font-weight: 500; text-align: right; }
.invoice-recap-row .value.amount { font-variant-numeric: tabular-nums; }
.invoice-recap-row .value.highlight { color: var(--primary); font-weight: 700; font-size: 15px; }
.invoice-cell .invoice-num {
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
  background: var(--surface-alt);
  padding: 2px 6px;
  border-radius: 4px;
}

.invoice-summary {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.invoice-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface);
  font-size: 13px;
}

.invoice-row .label {
  color: var(--text-muted);
  font-weight: 500;
}

.invoice-row strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Spinner Bootstrap minimal override */
.spinner-border {
  display: inline-block;
  width: 28px;
  height: 28px;
  vertical-align: text-bottom;
  border: 3px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spinner-border .75s linear infinite;
}

.spinner-border.text-primary { color: var(--primary); }

@keyframes spinner-border {
  to { transform: rotate(360deg); }
}

/* ============ LOGS SYSTÈME (admin) ============ */
.logs-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 8px;
}
.logs-kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
}
.logs-kpi i {
  font-size: 26px;
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}
.logs-kpi-info  i { background: var(--info-light);    color: var(--info); }
.logs-kpi-warn  i { background: var(--warning-light); color: var(--warning); }
.logs-kpi-error i { background: var(--danger-light);  color: var(--danger); }
.logs-kpi-value { font-size: 22px; font-weight: 700; color: var(--text-strong); line-height: 1.1; }
.logs-kpi-label { font-size: 12px; color: var(--text-muted); }

.logs-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin: 16px 0 12px;
}

.logs-table { font-size: 13px; }
.logs-table th { background: var(--surface-alt); }
.logs-table .log-date { white-space: nowrap; color: var(--text-muted); }
.logs-table .log-source { font-size: 11px; }
.logs-table .log-message {
  word-break: break-word;
  font-family: 'SFMono-Regular', Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  color: var(--text);
}
.logs-table .log-row-error .log-message { color: var(--danger); }
.logs-table .log-row-warn  .log-message { color: #b45309; }

.log-details {
  margin-top: 6px;
  font-size: 11.5px;
}
.log-details summary {
  cursor: pointer;
  color: var(--primary);
  user-select: none;
}
.log-stack, .log-context {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin-top: 6px;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 11.5px;
  color: var(--text-muted);
}

.logs-pm2-output {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-family: 'SFMono-Regular', Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  max-height: 70vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
