/* ============================================================
   QUICKPAY SA — Feuille de styles principale
   assets/css/app.css
   ============================================================ */

/* ---- RESET & BASE ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Arial, sans-serif; background: #f0f2f5; color: #1a1a2e; font-size: 13px; }

:root {
  --blue:   #1565C0;
  --bl:     #E3F2FD;
  --green:  #2E7D32;
  --red:    #C62828;
  --orange: #E65100;
  --gray:   #455A64;
  --gl:     #ECEFF1;
  --border: #CFD8DC;
  --sh:     0 2px 8px rgba(0,0,0,0.12);
}

/* ---- HEADER ---- */
.header { background: var(--blue); color: #fff; padding: 13px 20px; display: flex; align-items: center; justify-content: space-between; }
.header h1 { font-size: 16px; font-weight: 700; }
.header-sub { font-size: 11px; opacity: .75; margin-top: 1px; }

/* ---- NAV TABS ---- */
.app-nav { background: #0D47A1; display: flex; gap: 0; padding: 0 16px; }
.nav-tab { padding: 12px 20px; color: rgba(255,255,255,0.7); cursor: pointer; font-size: 13px; font-weight: 600; border-bottom: 3px solid transparent; transition: all .15s; white-space: nowrap; }
.nav-tab:hover { color: #fff; background: rgba(255,255,255,0.08); }
.nav-tab.active { color: #fff; border-bottom-color: #64B5F6; }

/* ---- PAGE LAYOUT ---- */
.page { display: none; height: calc(100vh - 95px); }
.page.active { display: flex; }

/* Le dashboard est un empilement vertical de blocs (KPI / graphiques / liste),
   pas un layout sidebar+contenu comme les autres pages : il a besoin de sa
   propre direction de flex, sinon les blocs s'alignent en ligne et s'étirent
   sur toute la hauteur de l'écran (page "trop grande"). */
#page-dashboard { flex-direction: column; overflow-y: auto; padding: 16px 20px; align-items: stretch; }
.mgmt-page { display: none; height: calc(100vh - 95px); flex-direction: column; }
.mgmt-page.active { display: flex; }

/* ---- TOOLBAR ---- */
.mgmt-toolbar { display: flex; gap: 10px; padding: 14px 20px; background: #fff; border-bottom: 1px solid var(--border); align-items: center; flex-wrap: wrap; }
.mgmt-content { flex: 1; overflow-y: auto; padding: 16px 20px; }
.search-wrap { flex: 1; min-width: 180px; position: relative; max-width: 320px; }
.search-wrap input { width: 100%; padding: 7px 10px 7px 32px; border: 1.5px solid var(--border); border-radius: 6px; font-size: 12px; outline: none; }
.search-wrap input:focus { border-color: var(--blue); }
.search-icon { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: #aaa; font-size: 14px; }

/* ---- TABLES DE GESTION ---- */
.mgmt-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: var(--sh); font-size: 12.5px; }
.mgmt-table thead th { background: var(--blue); color: #fff; padding: 10px 12px; text-align: left; font-weight: 600; font-size: 11.5px; white-space: nowrap; }
.mgmt-table tbody tr { border-bottom: 1px solid #F0F4F8; transition: background .1s; }
.mgmt-table tbody tr:hover { background: #F8FBFF; }
.mgmt-table td { padding: 9px 12px; vertical-align: middle; }
.mgmt-table td.td-mono { font-family: monospace; font-size: 11px; color: var(--gray); }

/* ---- BADGES & BOUTONS ---- */
.badge-sm { display: inline-block; padding: 2px 7px; border-radius: 10px; font-size: 10.5px; font-weight: 600; }
.btn-sm { border: none; background: none; cursor: pointer; padding: 4px 7px; border-radius: 4px; font-size: 13px; transition: background .1s; }
.btn-sm-edit  { color: var(--blue); }  .btn-sm-edit:hover  { background: var(--bl); }
.btn-sm-del   { color: var(--red); }   .btn-sm-del:hover   { background: #FFEBEE; }
.btn-sm-view  { color: var(--green); } .btn-sm-view:hover  { background: #E8F5E9; }
.btn-primary  { background: var(--blue); color: #fff; border: none; padding: 8px 16px; border-radius: 6px; font-weight: 700; font-size: 12.5px; cursor: pointer; white-space: nowrap; }
.btn-primary:hover { background: #0D47A1; }
.btn-secondary { background: var(--gl); color: var(--gray); border: none; padding: 8px 14px; border-radius: 6px; font-weight: 600; font-size: 12.5px; cursor: pointer; }
.empty-state { text-align: center; padding: 48px 20px; color: #aaa; }
.empty-state .es-icon { font-size: 40px; margin-bottom: 10px; }

/* ---- STATUT BADGES ---- */
.st-brouillon { background: #FFF3E0; color: #E65100; }
.st-genere    { background: #E3F2FD; color: #1565C0; }
.st-imprime   { background: #E8F5E9; color: #2E7D32; }
.st-archive   { background: #ECEFF1; color: #455A64; }

/* ---- BÉNÉFICIAIRES ACCORDION ---- */
.benef-comptes { margin-top: 6px; padding-left: 12px; border-left: 3px solid var(--bl); }
.benef-compte-row { display: flex; gap: 6px; align-items: center; padding: 5px 0; border-bottom: 1px solid #f0f4f8; font-size: 11.5px; }
.benef-compte-row:last-child { border-bottom: none; }

/* ---- FORMULAIRE VIREMENT (sidebar) ---- */
.sidebar { width: 360px; min-width: 330px; background: #fff; border-right: 1px solid var(--border); padding: 16px; overflow-y: auto; flex-shrink: 0; }
.preview-area { flex: 1; background: #dde1e8; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; align-items: center; }
.s-title { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--blue); margin: 14px 0 7px; padding-bottom: 3px; border-bottom: 2px solid var(--bl); }
.s-title:first-child { margin-top: 0; }

.form-row { margin-bottom: 9px; }
.form-row label { display: block; font-size: 10.5px; font-weight: 600; color: var(--gray); margin-bottom: 3px; text-transform: uppercase; letter-spacing: .3px; }
.req { color: var(--red); }
.form-row input,
.form-row select,
.form-row textarea { width: 100%; padding: 7px 9px; border: 1.5px solid var(--border); border-radius: 6px; font-size: 12.5px; outline: none; transition: border .15s; font-family: Arial, sans-serif; background: #fff; }
.form-row input:focus, .form-row select:focus { border-color: var(--blue); }
.form-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }

/* ---- SÉLECTION COMPTE/BANQUE ---- */
.compte-sel { border: 1.5px solid var(--border); border-radius: 7px; padding: 8px 10px; cursor: pointer; margin-bottom: 6px; transition: all .15s; display: flex; align-items: center; gap: 8px; }
.compte-sel:hover, .compte-sel.selected { border-color: var(--blue); background: var(--bl); }
.compte-sel-info { flex: 1; min-width: 0; }
.compte-sel-label { font-weight: 700; font-size: 12px; }
.compte-sel-rib { font-family: monospace; font-size: 10px; color: var(--gray); }
.compte-sel-banque { font-size: 10.5px; color: var(--blue); font-weight: 600; }

/* ---- RÉFÉRENCE ---- */
.ref-preview { font-size: 11px; color: var(--blue); background: var(--bl); border-radius: 4px; padding: 3px 8px; margin-top: 3px; font-family: monospace; }

/* ---- SIGNATAIRES (formulaire virement) ---- */
.sig-block-form { background: #f8fafc; border: 1.5px solid var(--border); border-radius: 7px; padding: 8px 10px; margin-bottom: 6px; }
.sig-block-title { font-size: 10.5px; font-weight: 700; color: var(--blue); margin-bottom: 7px; display: flex; justify-content: space-between; }

/* ---- LISTE BÉNÉFICIAIRES (formulaire virement) ---- */
.benef-sel-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1.5px solid var(--border); border-radius: 6px; margin-bottom: 5px; transition: all .15s; }
.benef-sel-nom { font-weight: 700; font-size: 12px; flex: 1; }
.benef-sel-rib { font-family: monospace; font-size: 10px; color: var(--gray); }
.btn-add-benef-vir { width: 100%; padding: 7px; border: 1.5px dashed var(--blue); border-radius: 6px; background: var(--bl); color: var(--blue); font-weight: 700; font-size: 12px; cursor: pointer; margin-bottom: 5px; }
.montant-row { display: flex; gap: 6px; align-items: center; }
.montant-row input { flex: 1; }
.btn-remove-benef-vir { background: none; border: none; color: var(--red); cursor: pointer; font-size: 16px; padding: 2px 4px; flex-shrink: 0; }

/* ---- TOTAL & ACTIONS ---- */
.total-box { background: var(--bl); border: 1.5px solid var(--blue); border-radius: 6px; padding: 8px 12px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.total-lbl { font-size: 11.5px; font-weight: 700; color: var(--blue); }
.total-amt { font-size: 14px; font-weight: 700; color: var(--blue); }
.btn-gen { width: 100%; padding: 10px; background: var(--blue); color: #fff; border: none; border-radius: 8px; font-size: 13px; font-weight: 700; cursor: pointer; margin-bottom: 5px; }
.btn-gen:hover { background: #0D47A1; }
.btn-print { width: 100%; padding: 8px; background: var(--green); color: #fff; border: none; border-radius: 8px; font-size: 12px; font-weight: 700; cursor: pointer; }

/* ---- PICKER BÉNÉFICIAIRES ---- */
.benef-picker-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; }
.benef-picker-item { padding: 10px 12px; border-bottom: 1px solid #f0f4f8; cursor: pointer; transition: background .1s; }
.benef-picker-item:hover { background: var(--bl); }
.benef-picker-item:last-child { border-bottom: none; }
.bpi-nom { font-weight: 700; font-size: 12.5px; }
.bpi-sub { font-size: 11px; color: var(--gray); margin-top: 2px; }
.compte-picker { display: flex; flex-direction: column; gap: 5px; margin-top: 8px; }
.compte-picker-item { border: 1.5px solid var(--border); border-radius: 6px; padding: 8px 10px; cursor: pointer; transition: all .15s; font-size: 12px; }
.compte-picker-item:hover, .compte-picker-item.selected { border-color: var(--blue); background: var(--bl); }

/* ---- COMPTES BÉNÉFICIAIRES (modal) ---- */
.cb-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.cb-item { background: #f8fafc; border: 1.5px solid var(--border); border-radius: 7px; padding: 8px 10px; position: relative; }
.cb-item-title { font-size: 10.5px; font-weight: 700; color: var(--blue); margin-bottom: 7px; display: flex; justify-content: space-between; }
.cb-grid  { display: grid; grid-template-columns: 1fr 1fr;       gap: 0 8px; }
.cb-grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr;   gap: 0 8px; }
.btn-add-cb { width: 100%; padding: 6px; border: 1.5px dashed var(--blue); border-radius: 6px; background: var(--bl); color: var(--blue); font-weight: 700; font-size: 11.5px; cursor: pointer; margin-bottom: 4px; }

/* ---- DOCUMENT (aperçu A4) ---- */
.doc-wrapper { background: #fff; width: 794px; min-height: 1122px; padding: 60px 72px 100px; box-shadow: 0 4px 24px rgba(0,0,0,0.18); position: relative; font-family: Arial, sans-serif; font-size: 11pt; line-height: 1.6; }
.doc-wrapper.with-entete { padding: 200px 72px 260px 160px; background-image: url('../img/entete-quickpay.png'); background-size: cover; background-position: top left; background-repeat: no-repeat; }
.doc-dest { text-align: right; margin-top: 0; margin-bottom: 6px; line-height: 2; color: #000; }
.doc-dest strong { display: block; font-size: 11.5pt; color: #000; }
.doc-date  { text-align: right; font-size: 10.5pt; margin-bottom: 16px; color: #000; }
.doc-ref   { font-size: 10.5pt; margin-bottom: 2px; color: #000; }
.doc-objet { font-size: 10.5pt; margin-bottom: 18px; color: #000; }
.doc-salut { font-size: 10.5pt; margin-bottom: 10px; color: #000; }
.doc-body p { font-size: 10.5pt; line-height: 1.75; margin-bottom: 12px; text-align: justify; color: #000; }
.doc-footer-simple { position: absolute; bottom: 100px; left: 200px; right: 100px; border-top: 1.5px solid #000; padding-top: 6px; font-size: 8pt; color: #555; display: flex; justify-content: space-between; }
.doc-footer-plain  { position: absolute; bottom: 24px;  left: 72px;  right: 72px;  border-top: 1.5px solid #000; padding-top: 6px; font-size: 8pt; color: #555; display: flex; justify-content: space-between; }

/* ---- TABLEAU DES VIREMENTS (dans le document) ---- */
.vtable { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 9.5pt; }
.vtable th { background: #fff; color: #000; padding: 7px 6px; text-align: center; font-weight: 700; font-size: 9pt; border: 1px solid #000; }
.vtable td { padding: 6px; border: 1px solid #000; text-align: center; vertical-align: middle; color: #000; }
.vtable tr:nth-child(even) td { background: #fff; color: #000; }
.vtable .tdl { text-align: left; }
.vtable .tdm { font-weight: 700; text-align: right; }
.vtable tfoot td { background: #fff; font-weight: 700; border: 1px solid #000; border-top: 2px solid #000; }

/* ---- BLOC SIGNATURES (dans le document) ---- */
.doc-sig-row { display: flex; justify-content: space-around; align-items: flex-start; margin-top: 48px; gap: 16px; }
.doc-sig-block { text-align: center; flex: 1; max-width: 220px; }
.doc-sig-line { border-bottom: 1.5px solid #000; width: 180px; margin: 0 auto 8px; display: block; }
.doc-sig-nom { font-weight: 700; font-size: 11pt; text-decoration: underline; }
.doc-sig-titre { font-size: 9.5pt; color: #333; margin-top: 2px; }

/* ---- MODALS ---- */
.mo { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 300; align-items: center; justify-content: center; }
.mo.open { display: flex; }
.modal { background: #fff; border-radius: 12px; width: 520px; max-width: 96vw; max-height: 92vh; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,0.25); }
.modal.wide   { width: 680px; }
.modal.narrow { width: 400px; }
.mh { background: var(--blue); color: #fff; padding: 13px 18px; border-radius: 12px 12px 0 0; display: flex; justify-content: space-between; align-items: center; }
.mh h2 { font-size: 14px; font-weight: 700; }
.btn-x { background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; line-height: 1; }
.mb { padding: 16px 18px; }
.mf { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.btn-ok     { background: var(--blue); color: #fff; border: none; padding: 8px 20px; border-radius: 6px; font-weight: 700; font-size: 12.5px; cursor: pointer; }
.btn-cancel { background: var(--gl); color: var(--gray); border: none; padding: 8px 14px; border-radius: 6px; font-weight: 600; font-size: 12.5px; cursor: pointer; }

/* ---- TOAST ---- */
.toast { position: fixed; bottom: 20px; right: 20px; background: #323232; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 12.5px; z-index: 500; opacity: 0; transform: translateY(8px); transition: all .25s; pointer-events: none; max-width: 340px; }
.toast.show    { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
.toast.warning { background: var(--orange); }

/* ---- LOADING OVERLAY ---- */
.loading-overlay { position: fixed; inset: 0; background: rgba(255,255,255,0.7); z-index: 400; display: none; align-items: center; justify-content: center; }
.loading-overlay.show { display: flex; }
.spinner { width: 40px; height: 40px; border: 4px solid var(--bl); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- IMPRESSION ---- */
@media print {
  .header, .app-nav, .sidebar, .apercu-hint { display: none !important; }
  .page.active { display: block !important; }
  .preview-area { padding: 0; background: #fff; display: block; }
  .doc-wrapper { box-shadow: none; width: 210mm !important; min-height: unset !important; transform: none !important; }
  .doc-wrapper.with-entete { background-image: url('../img/entete-quickpay.png') !important; background-size: cover !important; background-position: top left !important; background-repeat: no-repeat !important; -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  .doc-footer-plain, .doc-footer-simple { display: none !important; }
  body { background: #fff; }
  @page { margin: 0; size: A4 portrait; }
}

/* ============================================================
   DOCUMENT DE VIREMENT — Design professionnel amélioré
   ============================================================ */

/* ---- En-tête sans image (mode sans entête) ---- */
.doc-letterhead {
  margin-bottom: 28px;
}
.doc-lh-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.doc-lh-logo-icon {
  width: 44px;
  height: 44px;
  background: #1565C0;
  color: #fff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}
.doc-lh-company {
  font-size: 16pt;
  font-weight: 900;
  color: #1565C0;
  letter-spacing: 1px;
}
.doc-lh-tagline {
  font-size: 8pt;
  color: #455A64;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-top: 1px;
}
.doc-lh-divider {
  height: 2px;
  background: linear-gradient(to right, #1565C0, #E3F2FD);
  border-radius: 2px;
}

/* ---- Bloc destinataire redesigné ---- */
.doc-dest {
  text-align: right;
  margin-bottom: 20px;
  color: #000;
}
.doc-dest-inner {
  display: inline-block;
  text-align: left;
  border-left: 3px solid #1565C0;
  padding: 8px 0 8px 14px;
  line-height: 1.8;
}
.doc-dest-inner strong {
  display: block;
  font-size: 11.5pt;
  font-weight: 700;
  color: #000;
}
.doc-dest-inner span {
  display: block;
  font-size: 10pt;
  color: #333;
}

/* ---- Méta-bloc référence/date ---- */
.doc-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e0e0e0;
}
.doc-meta-ref {
  display: flex;
  align-items: center;
  gap: 6px;
}
.doc-meta-label {
  font-size: 8.5pt;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: #1565C0;
  background: #E3F2FD;
  padding: 2px 7px;
  border-radius: 3px;
}
.doc-meta-value {
  font-size: 10pt;
  font-weight: 700;
  font-family: monospace;
  color: #000;
}
.doc-meta-date {
  font-size: 10pt;
  color: #000;
  font-style: italic;
}

/* ---- Objet ---- */
.doc-objet-block {
  margin-bottom: 16px;
  font-size: 10.5pt;
  color: #000;
}
.doc-objet-label {
  font-weight: 700;
  margin-right: 4px;
}
.doc-objet-text {
  text-decoration: underline;
}

/* ---- Salutation ---- */
.doc-salut {
  font-size: 10.5pt;
  margin-bottom: 10px;
  color: #000;
}

/* ---- Corps de la lettre ---- */
.doc-body p {
  font-size: 10.5pt;
  line-height: 1.75;
  margin-bottom: 12px;
  text-align: justify;
  color: #000;
}
.doc-body-closing {
  margin-top: 14px;
}
.doc-rib-highlight {
  font-family: monospace;
  font-size: 10pt;
  background: #f5f5f5;
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid #ddd;
}

/* ---- Tableau des virements ---- */
.vtable {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 9.5pt;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 0 0 1px #000;
}
.vt-th {
  background: #1a1a1a;
  color: #ffffff;
  padding: 9px 8px;
  font-weight: 700;
  font-size: 8.5pt;
  text-transform: uppercase;
  letter-spacing: .5px;
  border: 1px solid #000;
}
.vt-td {
  padding: 7px 8px;
  border: 1px solid #ccc;
  vertical-align: middle;
  color: #000;
}
.vt-row-even { background: #ffffff; }
.vt-row-odd  { background: #f7f9fc; }
.vt-left   { text-align: left; }
.vt-center { text-align: center; }
.vt-right  { text-align: right; }
.vt-mono   { font-family: monospace; font-size: 8.5pt; color: #333; }
.vt-amount { font-weight: 700; font-size: 10pt; white-space: nowrap; }
.vt-benef-name { font-weight: 600; }
.vt-bank-badge {
  display: inline-block;
  background: #E3F2FD;
  color: #1565C0;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 8pt;
  font-weight: 700;
}
.vt-foot-label {
  text-align: right;
  font-weight: 800;
  padding: 9px 10px;
  background: #1a1a1a;
  color: #fff;
  font-size: 9pt;
  text-transform: uppercase;
  letter-spacing: .5px;
  border: 1px solid #000;
}
.vt-foot-amount {
  text-align: right;
  font-weight: 800;
  font-size: 11pt;
  padding: 9px 8px;
  background: #1565C0;
  color: #fff;
  border: 1px solid #000;
  white-space: nowrap;
}

/* ---- Bloc signatures redesigné ---- */
.doc-sig-row {
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  gap: 20px;
}
.doc-sig-block {
  text-align: center;
  flex: 1;
  max-width: 240px;
}
.doc-sig-label {
  font-size: 8.5pt;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: #1565C0;
  margin-bottom: 4px;
}
.doc-sig-space {
  height: 52px; /* Espace pour la signature manuscrite */
}
.doc-sig-line {
  display: block;
  border-bottom: 1.5px solid #000;
  width: 100%;
  margin: 0 auto 6px;
}
.doc-sig-nom {
  font-weight: 700;
  font-size: 10.5pt;
  text-decoration: underline;
  color: #000;
}

/* ---- Pied de page du document ---- */
.doc-footer-simple,
.doc-footer-plain {
  position: absolute;
  bottom: 60px;
  left: 160px;
  right: 72px;
  border-top: 1.5px solid #ccc;
  padding-top: 6px;
  font-size: 7.5pt;
  color: #888;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.doc-footer-plain {
  left: 72px;
  bottom: 28px;
}

/* ---- Surcharges impression ---- */
@media print {
  .vt-bank-badge { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  .vt-th, .vt-foot-label, .vt-foot-amount, .doc-lh-logo-icon {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .doc-lh-divider { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}

/* ============================================================
   RESPONSIVE — Tablette & Mobile
   À coller à la fin de assets/css/app.css
   ============================================================ */

/* Empêche tout débordement horizontal parasite de la page */
html, body { max-width: 100%; overflow-x: hidden; }

/* ==================== TABLETTE (<=1024px) ==================== */
@media (max-width: 1024px) {
  .sidebar { width: 300px; min-width: 260px; }
}

/* ==================== MOBILE (<=768px) ==================== */
@media (max-width: 768px) {
  body { font-size: 12px; }

  /* Header : passe en colonne, infos utilisateur en dessous du titre */
  .header { flex-direction: column; align-items: flex-start; gap: 8px; padding: 10px 14px; }
  .header h1 { font-size: 14px; }
  .header > div:last-child { width: 100%; justify-content: space-between; }

  /* Navigation : scroll horizontal plutôt que de casser la mise en page */
  .app-nav { overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 0 8px; }
  .app-nav::-webkit-scrollbar { height: 4px; }
  .nav-tab { padding: 10px 14px; font-size: 12px; flex-shrink: 0; }

  /* Pages avec sidebar (virement) : empile au lieu de côte à côte */
  .page.active,
  .mgmt-page.active { flex-direction: column; height: auto; min-height: calc(100vh - 95px); }

  .sidebar {
    width: 100%;
    min-width: 0;
    max-height: 50vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  /* Aperçu du document : scroll horizontal pour voir tout le A4
     (pas de scale CSS ici, pour ne pas perturber la génération PDF/html2pdf) */
  .preview-area { padding: 12px; width: 100%; overflow-x: auto; }

  /* Toolbar de gestion (recherche + bouton ajouter) */
  .mgmt-toolbar { padding: 10px 14px; }
  .search-wrap { max-width: none; width: 100%; }
  .mgmt-content { padding: 12px 14px; }

  /* Tableaux larges : scroll horizontal plutôt que débordement de la page */
  .mgmt-content { overflow-x: auto; }
  .mgmt-table { min-width: 640px; }

  /* Formulaires : une seule colonne */
  .form-grid2,
  .cb-grid,
  .cb-grid3 { grid-template-columns: 1fr; }

  /* Modals : occupe presque tout l'écran, marges réduites */
  .modal, .modal.wide, .modal.narrow { width: 94vw; }
  .mb { padding: 14px; }

  /* Signatures du document : empilent si pas la place */
  .doc-sig-row { flex-wrap: wrap; gap: 24px; }
  .doc-sig-block { max-width: 100%; flex: 1 1 200px; }
}

/* ==================== TRÈS PETIT ÉCRAN (<=480px) ==================== */
@media (max-width: 480px) {
  .header h1 { font-size: 13px; }
  .header-sub { display: none; }
  .nav-tab { padding: 9px 11px; font-size: 11px; }

  .total-amt { font-size: 13px; }
  .btn-gen, .btn-print { font-size: 11.5px; }

  .compte-sel { flex-direction: column; align-items: flex-start; }
  .montant-row { flex-wrap: wrap; }
}