/* ============================================================
   RESET COMPLET — Isolation back-office MH Logistics
   Neutralise Bootstrap et tout CSS du site principal
   ============================================================ */

/* Reset all elements */
html, body, div, span, h1, h2, h3, h4, h5, h6, p, a, form,
input, select, textarea, button, label, table, thead, tbody,
tr, th, td, nav, header, main, aside, section, ul, li {
    box-sizing: border-box !important;
}

/* CRITICAL: Reset select et option */
select {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    color: #1f2937 !important;
    background-color: #ffffff !important;
    background-image: none !important;
    -webkit-appearance: menulist !important;
    -moz-appearance: menulist !important;
    appearance: menulist !important;
    height: auto !important;
    min-height: 38px !important;
    line-height: normal !important;
    overflow: visible !important;
}

select option,
select optgroup {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    color: #1f2937 !important;
    background-color: #ffffff !important;
    font-size: 14px !important;
    font-weight: normal !important;
}

/* Reset input */
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="time"],
input[type="color"], input[type="file"], textarea {
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    background-color: #ffffff !important;
    color: #1f2937 !important;
}

/* Reset body pour back-office */
body {
    margin: 0 !important;
    padding: 0 !important;
    font-family: 'Segoe UI', Arial, sans-serif !important;
    font-size: 15px !important;
    color: #1f2937 !important;
    background: #f0f4f8 !important;
}

/* Annuler Bootstrap rows/cols */
.row { margin: 0 !important; }
.col, [class*="col-"] { padding: 0 !important; }

/* ============================================================
   MH LOGISTICS MULTISERVICES — Système de Facturation
   Palette: Bleu marine #1a3c5e + Orange #e8a020
   ============================================================ */

:root {
  --bleu:        #1a3c5e;
  --bleu-clair:  #2563a8;
  --bleu-bg:     #f0f4f8;
  --orange:      #e8a020;
  --orange-dark: #c4851a;
  --vert:        #16a34a;
  --rouge:       #dc2626;
  --jaune:       #d97706;
  --gris:        #6b7280;
  --gris-clair:  #f3f4f6;
  --blanc:       #ffffff;
  --texte:       #1f2937;
  --bordure:     #e5e7eb;
  --sidebar-w:   260px;
  --header-h:    64px;
  --radius:      8px;
  --shadow:      0 1px 3px rgba(0,0,0,.12);
  --shadow-md:   0 4px 12px rgba(0,0,0,.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: 'Segoe UI', Arial, sans-serif; color: var(--texte); background: var(--bleu-bg); }
a { color: var(--bleu-clair); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── LAYOUT ──────────────────────────────────────────────── */
.app-wrapper { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bleu);
  color: #fff;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  transition: transform .3s;
}
.sidebar-logo {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex;
  align-items: center;
  gap: 12px;
}
.sidebar-logo img { height: 40px; }
.sidebar-logo span { font-size: 1rem; font-weight: 700; color: #fff; }
.sidebar-logo small { display: block; font-size: 11px; color: rgba(255,255,255,.6); }

.sidebar-nav { padding: 16px 0; }
.nav-section { padding: 8px 16px 4px; font-size: 10px; text-transform: uppercase; color: rgba(255,255,255,.4); letter-spacing: 1px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: rgba(255,255,255,.8);
  font-size: 14px;
  transition: all .2s;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav-item.active { background: rgba(232,160,32,.15); color: #fff; border-left-color: var(--orange); font-weight: 600; }
.nav-item svg { opacity: .7; flex-shrink: 0; }
.nav-item.active svg { opacity: 1; }

.nav-badge {
  margin-left: auto;
  background: var(--orange);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
}

/* Main content */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Top header */
.top-header {
  height: var(--header-h);
  background: var(--blanc);
  border-bottom: 1px solid var(--bordure);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.page-breadcrumb { font-size: 13px; color: var(--gris); }
.page-breadcrumb strong { color: var(--texte); }
.header-right { display: flex; align-items: center; gap: 16px; }
.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bleu-bg);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--bleu);
}

/* Page content */
.page-content { padding: 28px; flex: 1; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title { font-size: 1.5rem; font-weight: 700; color: var(--bleu); }
.page-subtitle { color: var(--gris); font-size: 14px; margin-top: 2px; }

/* ── CARDS / STATS ───────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--blanc);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--bordure);
  border-top: 3px solid var(--bleu);
}
.stat-card.orange { border-top-color: var(--orange); }
.stat-card.vert   { border-top-color: var(--vert); }
.stat-card.rouge  { border-top-color: var(--rouge); }
.stat-card.jaune  { border-top-color: var(--jaune); }
.stat-label { font-size: 12px; color: var(--gris); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.stat-value { font-size: 1.8rem; font-weight: 800; color: var(--bleu); }
.stat-card.orange .stat-value { color: var(--orange-dark); }
.stat-card.vert   .stat-value { color: var(--vert); }
.stat-card.rouge  .stat-value { color: var(--rouge); }
.stat-card.jaune  .stat-value { color: var(--jaune); }
.stat-sub { font-size: 12px; color: var(--gris); margin-top: 4px; }

/* ── TABLES ──────────────────────────────────────────────── */
.card {
  background: var(--blanc);
  border-radius: var(--radius);
  border: 1px solid var(--bordure);
  box-shadow: var(--shadow);
  /* overflow: hidden retiré — bloquait les dropdowns select */
  overflow: visible;
}
/* Arrondir seulement le header et le tableau */
.card > table { border-radius: 0; }
.card > .card-header:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--bordure);
  flex-wrap: wrap;
  gap: 10px;
}
.card-title { font-size: 15px; font-weight: 700; color: var(--bleu); }
.card-body { padding: 20px; }

table { width: 100%; border-collapse: collapse; }
thead tr { background: var(--bleu-bg); }
th { padding: 10px 14px; text-align: left; font-size: 12px; font-weight: 700; color: var(--gris); text-transform: uppercase; letter-spacing: .5px; white-space: nowrap; }
td { padding: 12px 14px; font-size: 14px; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
tr:hover td { background: #fafbff; }
tr:last-child td { border-bottom: none; }

/* ── BADGES STATUTS ──────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-bleu      { background: #dbeafe; color: #1d4ed8; }
.badge-vert      { background: #dcfce7; color: #15803d; }
.badge-orange    { background: #fef3c7; color: #92400e; }
.badge-rouge     { background: #fee2e2; color: #991b1b; }
.badge-gris      { background: #f3f4f6; color: #6b7280; }
.badge-violet    { background: #ede9fe; color: #7c3aed; }

/* Statuts spécifiques */
.statut-brouillon      { background: #f3f4f6; color: #6b7280; }
.statut-envoye, .statut-envoyee { background: #dbeafe; color: #1d4ed8; }
.statut-accepte        { background: #dcfce7; color: #15803d; }
.statut-refuse         { background: #fee2e2; color: #991b1b; }
.statut-expire         { background: #fef3c7; color: #92400e; }
.statut-converti       { background: #ede9fe; color: #7c3aed; }
.statut-paye, .statut-payee { background: #dcfce7; color: #15803d; }
.statut-partiellement_payee { background: #fef3c7; color: #92400e; }
.statut-en_retard      { background: #fee2e2; color: #991b1b; }
.statut-annulee        { background: #f3f4f6; color: #6b7280; }
.statut-planifie, .statut-planifié { background: #dbeafe; color: #1d4ed8; }
.statut-en_cours       { background: #fef3c7; color: #92400e; }
.statut-livre, .statut-livré { background: #dcfce7; color: #15803d; }
.statut-probleme, .statut-problème { background: #fee2e2; color: #991b1b; }

/* ── FORMULAIRES ─────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-full { grid-column: 1 / -1; }
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--texte); margin-bottom: 5px; }
.form-label span.required { color: var(--rouge); margin-left: 2px; }
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--bordure);
  border-radius: 6px;
  font-size: 14px;
  color: var(--texte);
  background: #fff;
  transition: border-color .2s;
}
.form-control:focus { outline: none; border-color: var(--bleu-clair); box-shadow: 0 0 0 3px rgba(37,99,168,.1); }
.form-control.small { padding: 6px 8px; font-size: 13px; }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: 12px; color: var(--gris); margin-top: 3px; }
.input-prefix {
  display: flex;
  border: 1px solid var(--bordure);
  border-radius: 6px;
  overflow: hidden;
}
.input-prefix span {
  background: var(--gris-clair);
  border-right: 1px solid var(--bordure);
  padding: 9px 12px;
  font-size: 13px;
  color: var(--gris);
  white-space: nowrap;
}
.input-prefix .form-control { border: none; border-radius: 0; }

/* ── BOUTONS ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .2s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--bleu); color: #fff; }
.btn-primary:hover { background: #142f4d; }
.btn-orange  { background: var(--orange); color: #fff; }
.btn-orange:hover { background: var(--orange-dark); }
.btn-vert    { background: var(--vert); color: #fff; }
.btn-vert:hover { background: #15803d; }
.btn-rouge   { background: var(--rouge); color: #fff; }
.btn-rouge:hover { background: #b91c1c; }
.btn-outline { background: #fff; color: var(--bleu); border: 1px solid var(--bordure); }
.btn-outline:hover { background: var(--bleu-bg); }
.btn-sm  { padding: 6px 12px; font-size: 13px; }
.btn-lg  { padding: 12px 24px; font-size: 15px; }
.btn-icon { padding: 7px; }

/* ── LIGNES DE DEVIS/FACTURE ─────────────────────────────── */
.lignes-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.lignes-table th { background: var(--bleu); color: #fff; padding: 10px 8px; font-size: 12px; }
.lignes-table td { padding: 8px; border-bottom: 1px solid var(--bordure); vertical-align: top; }
.lignes-table tr:last-child td { border-bottom: none; }
.totaux-section { width: 320px; margin-left: auto; }
.total-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.total-row.ttc { font-size: 18px; font-weight: 800; color: var(--bleu); border-top: 2px solid var(--bleu); padding-top: 10px; margin-top: 4px; }

/* ── ALERTES ─────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 6px; font-size: 14px; margin-bottom: 16px; display: flex; align-items: flex-start; gap: 10px; }
.alert-success { background: #f0fdf4; border: 1px solid #86efac; color: #166534; }
.alert-error   { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; }
.alert-warning { background: #fffbeb; border: 1px solid #fcd34d; color: #92400e; }
.alert-info    { background: #eff6ff; border: 1px solid #93c5fd; color: #1d4ed8; }

/* ── FLASH MESSAGES ─────────────────────────────────────── */
.flash-container { position: fixed; top: 80px; right: 20px; z-index: 9999; width: 360px; }
.flash {
  padding: 14px 18px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: slideIn .3s ease;
  display: flex;
  align-items: center;
  gap: 10px;
}
.flash-success { background: #16a34a; color: #fff; }
.flash-error   { background: #dc2626; color: #fff; }
.flash-warning { background: #d97706; color: #fff; }
.flash-info    { background: #2563a8; color: #fff; }
@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── PAGINATION ──────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; align-items: center; padding: 16px 20px; border-top: 1px solid var(--bordure); }
.page-btn { padding: 6px 12px; border: 1px solid var(--bordure); border-radius: 6px; font-size: 13px; background: #fff; color: var(--texte); cursor: pointer; }
.page-btn:hover { background: var(--bleu-bg); }
.page-btn.active { background: var(--bleu); color: #fff; border-color: var(--bleu); }

/* ── MODAL ───────────────────────────────────────────────── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1000; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal {
  background: #fff;
  border-radius: 12px;
  padding: 32px;
  width: 540px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-title { font-size: 1.2rem; font-weight: 700; color: var(--bleu); margin-bottom: 20px; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--bordure); }

/* ── AUTH PAGE ───────────────────────────────────────────── */
.auth-page { min-height: 100vh; background: var(--bleu); display: flex; align-items: center; justify-content: center; }
.auth-card { background: #fff; border-radius: 16px; padding: 48px 40px; width: 420px; max-width: 95vw; box-shadow: 0 24px 60px rgba(0,0,0,.3); }
.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo img { height: 60px; }
.auth-logo h1 { font-size: 1.3rem; font-weight: 700; color: var(--bleu); margin-top: 12px; }
.auth-logo p { color: var(--gris); font-size: 14px; }

/* ── UTILITIES ───────────────────────────────────────────── */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-sm { font-size: 13px; }
.text-gris { color: var(--gris); }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
.hidden { display: none; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── SIGNATURE CANVAS ────────────────────────────────────── */
.signature-area { border: 2px dashed var(--bordure); border-radius: 8px; background: #fafafa; cursor: crosshair; display: block; }

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2,1fr); }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-content { padding: 16px; }
}

/* ── FIX SELECT — Reset complet pour éviter conflits CSS externes ── */
select,
select.form-control,
select option {
    -webkit-appearance: auto !important;
    -moz-appearance: auto !important;
    appearance: auto !important;
    color: #1f2937 !important;
    background-color: #ffffff !important;
    font-size: 14px !important;
    font-family: 'Segoe UI', Arial, sans-serif !important;
    visibility: visible !important;
    display: block !important;
    opacity: 1 !important;
}

select.form-control {
    width: 100% !important;
    padding: 9px 12px !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 6px !important;
    background-image: none !important;
    height: auto !important;
    min-height: 38px !important;
    line-height: normal !important;
}

select.form-control:focus {
    outline: none !important;
    border-color: #2563a8 !important;
    box-shadow: 0 0 0 3px rgba(37,99,168,.1) !important;
}

select.form-control option {
    padding: 8px 12px !important;
    color: #1f2937 !important;
    background: #ffffff !important;
}

/* Fix table dans card sans overflow:hidden */
.card { border-radius: var(--radius); }
.card > table thead tr:first-child th:first-child { border-radius: var(--radius) 0 0 0; }
.card > table thead tr:first-child th:last-child  { border-radius: 0 var(--radius) 0 0; }

/* Fix select dropdown visible partout */
.card, .card-body, .form-grid, .form-group { overflow: visible !important; }
select { position: relative; z-index: 10; }
