:root {
  /* Couleurs de la charte : valeurs par défaut, remplacées par config.php → 'theme' (voir theme_css() dans app/helpers.php) */
  --brand: #46B5EA;
  --brand-rgb: 70, 181, 234;
  --brand-hover: #3C9AC7;
  --brand-active: #3891BB;
  --brand-light: #A3DAF5;
  --brand-dropzone: #9FD3EC;
  --brand-subtle: #DAF0FB;
  --brand-border-subtle: #B5E1F7;
  --brand-emphasis: #1C485E;
  --brand-tint: #E3F3FB;
  --brand-tint-soft: #F5FBFE;
  --brand-dark: #0B86C6;
  --brand-dark-rgb: 11, 134, 198;
  --brand-dark-hover: #0972A8;
  --brand-dark-active: #096B9E;
  --brand-dark-active-rgb: 9, 107, 158;
  --brand-dark-tint: #EEF7FC;
  --brand-accent: #C2E616; /* couleur secondaire : soulignement du menu actif */
  --ink: #1d2831;
  --bs-body-font-family: "Rubik", system-ui, -apple-system, "Segoe UI", sans-serif;
  --bs-body-color: var(--ink);
  --bs-link-color: var(--brand-dark);
  --bs-link-color-rgb: var(--brand-dark-rgb);
  --bs-link-hover-color: var(--brand-dark-active);
  --bs-link-hover-color-rgb: var(--brand-dark-active-rgb);

  /* Couleur "primary" de Bootstrap */
  --bs-primary: var(--brand);
  --bs-primary-rgb: var(--brand-rgb);
  --bs-primary-text-emphasis: var(--brand-emphasis);
  --bs-primary-bg-subtle: var(--brand-subtle);
  --bs-primary-border-subtle: var(--brand-border-subtle);
}

/* Bootstrap 5.3 code #0d6efd en dur dans plusieurs composants : on les réaligne sur --bs-primary */
.btn-primary {
  --bs-btn-bg: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-hover);
  --bs-btn-hover-border-color: var(--brand-hover);
  --bs-btn-focus-shadow-rgb: var(--brand-rgb);
  --bs-btn-active-bg: var(--brand-active);
  --bs-btn-active-border-color: var(--brand-active);
  --bs-btn-disabled-bg: var(--brand);
  --bs-btn-disabled-border-color: var(--brand);
}
.btn-outline-primary {
  --bs-btn-color: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand);
  --bs-btn-hover-border-color: var(--brand);
  --bs-btn-focus-shadow-rgb: var(--brand-rgb);
  --bs-btn-active-bg: var(--brand);
  --bs-btn-active-border-color: var(--brand);
  --bs-btn-disabled-color: var(--brand);
  --bs-btn-disabled-border-color: var(--brand);
}
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
  border-color: var(--brand-light);
  box-shadow: 0 0 0 .25rem rgba(var(--brand-rgb), .25);
}
.form-check-input:checked,
.form-check-input[type=checkbox]:indeterminate {
  background-color: var(--brand);
  border-color: var(--brand);
}
.form-range::-webkit-slider-thumb { background-color: var(--brand); }
.form-range::-moz-range-thumb { background-color: var(--brand); }
.form-range:focus::-webkit-slider-thumb { box-shadow: 0 0 0 1px #fff, 0 0 0 .25rem rgba(var(--brand-rgb), .25); }
.form-range:focus::-moz-range-thumb { box-shadow: 0 0 0 1px #fff, 0 0 0 .25rem rgba(var(--brand-rgb), .25); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--brand); }
.dropdown-menu { --bs-dropdown-link-active-bg: var(--brand); }
.list-group { --bs-list-group-active-bg: var(--brand); --bs-list-group-active-border-color: var(--brand); }
.pagination { --bs-pagination-active-bg: var(--brand); --bs-pagination-active-border-color: var(--brand); --bs-pagination-focus-box-shadow: 0 0 0 .25rem rgba(var(--brand-rgb), .25); }
.progress, .progress-stacked { --bs-progress-bar-bg: var(--brand); }

body { background: #f4f6f8; min-height: 100vh; }

/* Bandeau : bleu foncé de la charte (le cyan #46B5EA est trop clair sous un texte blanc) */
.bg-brand { background: var(--brand-dark) !important; }
.text-brand { color: var(--brand) !important; }
.text-brand-dark { color: var(--brand-dark) !important; }
.border-brand { border-color: var(--brand) !important; }

.btn-brand {
  --bs-btn-color: #fff;
  --bs-btn-bg: var(--brand-dark);
  --bs-btn-border-color: var(--brand-dark);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--brand-dark-hover);
  --bs-btn-hover-border-color: var(--brand-dark-hover);
  --bs-btn-active-bg: var(--brand-dark-active);
  --bs-btn-active-border-color: var(--brand-dark-active);
  --bs-btn-disabled-bg: var(--brand-dark);
  --bs-btn-disabled-border-color: var(--brand-dark);
}

.navbar .nav-link { color: rgba(255, 255, 255, .9); }
/* Logo agrandi ; marges négatives : le SVG a des blancs tout autour, la barre garde sa hauteur */
.navbar-brand { padding-top: 0; padding-bottom: 0; }
.navbar-brand img { height: 48px; width: auto; margin: -.35rem 0 -.35rem -.5rem; }
@media (min-width: 992px) {
  .navbar-brand img { height: 56px; margin-top: -.5rem; margin-bottom: -.5rem; }
}
/* Menu principal aéré : plus d'espace entre les items et après le logo (écrans larges uniquement) */
@media (min-width: 992px) {
  .navbar-brand { margin-right: 2.5rem; }
  .navbar-nav.me-auto { gap: 1.25rem; }
  .navbar-nav .nav-link { padding-left: .6rem; padding-right: .6rem; }
  .navbar-nav .nav-link .bi { margin-right: .2rem; }
}
.navbar .nav-link.active { color: #fff; font-weight: 500; box-shadow: inset 0 -3px 0 var(--brand-accent); }

.auth-card { max-width: 440px; }

/* Onglets de statut */
.status-tabs .nav-link { color: var(--ink); }
.status-tabs .nav-link .badge { background: rgba(0, 0, 0, .08); color: inherit; }
.status-tabs .nav-link.active { background: var(--brand-dark); color: #fff; }
.status-tabs .nav-link.active .badge { background: rgba(255, 255, 255, .25); }

/* Cartes BAT (client) */
.bat-card { color: var(--ink); border-left: 4px solid #ced4da; transition: box-shadow .15s, transform .15s; }
.bat-card:hover { box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .08); transform: translateY(-1px); }
.bat-card.status-pending { border-left-color: var(--brand); }
.bat-card.status-approved { border-left-color: var(--bs-success); }
.bat-card.status-rejected { border-left-color: var(--bs-warning); }
.bat-card .card-footer { color: var(--brand-dark); }

/* Visionneuse */
.pdf-viewer { display: flex; flex-direction: column; height: calc(100vh - 150px); min-height: 420px; }
.pdf-viewer:fullscreen { height: 100vh; border-radius: 0 !important; }
.pdf-toolbar { background: #fafbfc; }
.pdf-pages { flex: 1; overflow: auto; background: #e9ecef; padding: 16px; }
.pdf-page { margin: 0 auto 16px; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }
.pdf-page canvas { display: block; }
.pdf-pages { user-select: none; -webkit-user-select: none; }
@media print { .pdf-viewer { display: none !important; } } /* pas d'impression du BAT depuis le navigateur */

/* Liste « Fichiers à vérifier » */
/* Colonne bornée à la largeur de la carte : sinon elle s'élargit au nom de fichier le plus long (nowrap) et déborde */
.file-list { grid-template-columns: minmax(0, 1fr); }
.file-item {
  min-width: 0;
  display: flex; align-items: center; gap: .6rem; width: 100%; text-align: left;
  padding: .55rem .75rem; border: 1px solid #dee2e6; border-radius: .5rem; background: #fff; color: var(--ink);
}
.file-item:hover { border-color: var(--brand); }
.file-item .bi-file-earmark-pdf-fill { color: #6c757d; }
.file-item.active { border-color: var(--brand-dark); background: var(--brand-dark-tint); color: var(--brand-dark); }
.file-item.active .bi-file-earmark-pdf-fill { color: var(--brand-dark); }
.file-item .file-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.file-item .file-qty { font-size: .75rem; opacity: .8; }
.qty-input { width: auto; flex-wrap: nowrap; }
.qty-input .form-control { width: 6.5rem; }
.dropzone-file .qty-input .form-control { width: 5.5rem; }
.file-item .file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Zones de glisser-déposer des PDF (admin) */
.dropzone-area {
  position: relative; display: flex; align-items: center; justify-content: center; gap: .75rem;
  padding: 1.4rem 1rem; text-align: center; color: var(--brand-dark);
  border: 2px dashed var(--brand-dropzone); border-radius: .6rem; background: #fff; transition: background .15s, border-color .15s;
}
.dropzone-sm .dropzone-area { padding: .6rem .75rem; gap: .5rem; font-size: .875rem; }
.dropzone-area:hover { border-color: var(--brand); background: var(--brand-tint-soft); }
.dropzone-area.is-over { border-color: var(--brand-dark); border-style: solid; background: var(--brand-tint); }
/* Le vrai champ fichier couvre toute la zone, invisible : clic = fenêtre « Parcourir » */
.dropzone-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.dropzone.has-files .dropzone-area { border-color: var(--brand); }
.dropzone-files:not(:empty) { margin-top: .5rem; }
.dropzone-file {
  display: flex; align-items: center; gap: .5rem; padding: .35rem .6rem; margin-bottom: .3rem;
  background: #fff; border: 1px solid #dee2e6; border-radius: .4rem; font-size: .875rem;
}
.dropzone-file .text-truncate { min-width: 0; flex: 1; }

.replace-row.replace-rejected { border: 2px solid #dc3545 !important; background: #fff8f8 !important; box-shadow: 0 0 0 4px rgba(220, 53, 69, .1); }
.replace-row.replace-rejected .dropzone-area { border-color: #ea868f; background: #fdf0f1; color: #b02a37; padding: 1.1rem .75rem; }
.replace-row.replace-rejected .dropzone-area:hover,
.replace-row.replace-rejected .dropzone-area.is-over { border-color: #dc3545; background: #f9dde0; }
.replace-row.replace-approved { border-color: #a3cfbb !important; }
.replace-row.replace-approved .dropzone-area { border-color: #dee2e6; color: #6c757d; }
.file-decision-done { padding: .4rem .6rem; border-radius: .4rem; background: #eaf6ef; cursor: pointer; }

/* Message de l'agence au client : avatar (monogramme) + bulle */
.bat-message { display: flex; align-items: flex-start; gap: .75rem; }
.bat-message-avatar {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%;
  background: var(--brand); display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}
.bat-message-body { min-width: 0; flex: 1; }
.bat-message-from { font-size: .75rem; font-weight: 500; color: var(--brand-dark); margin-bottom: .2rem; }
.bat-message-bubble {
  position: relative; background: var(--brand-dark-tint); border-radius: 0 .75rem .75rem .75rem;
  padding: .6rem .8rem; overflow-wrap: anywhere;
}

/* Résultat de la décision du client : vert = validé, rouge = refusé (l'onglet affiché garde un contour épais) */
.file-item.result-approved { border-color: #75b798; background: #eaf6ef; color: #146c43; }
.file-item.result-approved .bi-file-earmark-pdf-fill { color: #198754; }
.file-item.result-rejected { border-color: #ea868f; background: #fcecee; color: #b02a37; }
.file-item.result-rejected .bi-file-earmark-pdf-fill { color: #dc3545; }
.file-item.result-approved:hover { border-color: #198754; }
.file-item.result-rejected:hover { border-color: #dc3545; }
.file-item.result-approved.active { border-color: #198754; box-shadow: inset 0 0 0 1px #198754; background: #dcf0e4; }
.file-item.result-rejected.active { border-color: #dc3545; box-shadow: inset 0 0 0 1px #dc3545; background: #f9dde0; }
.file-icons { flex-shrink: 0; display: inline-flex; align-items: center; gap: .45rem; font-size: 1.05rem; }
.file-read { flex-shrink: 0; display: inline-flex; color: #c4cad0; }
.file-item.viewed .file-read { color: var(--brand-dark); }
/* Fichier déjà validé et inchangé (nouvelle version après refus) : simple lien sous la liste */
.file-carried { line-height: 1.5; }
.file-carried-link { border: 0; background: none; padding: 0; color: var(--bs-link-color); text-decoration: underline; text-underline-offset: 2px; }
.file-carried-link:hover { color: var(--bs-link-hover-color); }
.file-carried-link.active { color: var(--brand-dark); font-weight: 600; text-decoration: none; }
.file-carried-link.active::before { content: "\25B8\00A0"; } /* ▸ : fichier affiché dans la visionneuse */
.file-read-inline svg { width: 15px; height: 15px; vertical-align: -2px; color: var(--brand-dark); }

@media (max-width: 991.98px) {
  .pdf-viewer { height: 75vh; }
}
@media (min-width: 992px) {
  .bat-side { position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow-y: auto; overflow-x: hidden; }
}

.decision-choice { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.decision-card { border-top: 4px solid var(--brand); }

.timeline li { border-left: 2px solid #dee2e6; padding-left: .75rem; }
/* Historique en accordéon */
.history-item summary {
  list-style: none; cursor: pointer; display: flex; flex-direction: column; gap: .1rem;
  padding: .3rem 1.4rem .3rem 0; position: relative; border-radius: .25rem;
}
.history-item summary::-webkit-details-marker { display: none; }
.history-item summary::after {
  content: "\F282"; font-family: "bootstrap-icons"; position: absolute; right: .2rem; top: .35rem;
  color: #adb5bd; transition: transform .15s;
}
.history-item[open] summary::after { transform: rotate(180deg); }
.history-item summary:hover .history-title { color: var(--brand-dark); }
.history-date { color: #6c757d; font-size: .75rem; }
.history-body { padding: .15rem 0 .5rem; }
.history-body > div + div { margin-top: .15rem; }
.hash { font-size: .75em; }

.info-page h2, .info-modal .info-content h2 { color: var(--brand-dark); }
.info-modal .info-content .h4 { font-size: 1.1rem; }
.info-modal .info-content .h5 { font-size: 1rem; }

/* Pas d'attribut style="" dans le HTML : la CSP les bloque */
.col-name { min-width: 240px; }
/* Nom de client / catégorie non modifié : affiché comme du texte, mêmes dimensions qu'en édition (pas de saut) */
.rename-input[readonly] { background-color: transparent; border-color: transparent; box-shadow: none; cursor: default; }
.client-checks { max-height: 220px; overflow: auto; }
.import-log { max-height: 60vh; overflow: auto; font-size: .8rem; }

/* En-têtes triables de la liste des BAT */
.sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
.sort-link .bi { font-size: .75em; opacity: .35; margin-left: .15rem; }
.sort-link:hover, .sort-link.active { color: var(--brand-dark); }
.sort-link:hover .bi, .sort-link.active .bi { opacity: 1; }
.sort-reset { color: var(--bs-secondary-color); text-decoration: none; }
.sort-reset:hover { color: var(--brand-dark); }

/* Traitement par lot de la liste des BAT */
.bulk-col { width: 2.5rem; }
.bulk-col .form-check-input { margin-top: 0; cursor: pointer; }
.bulk-bar { min-height: 2rem; }

/* Menu profil : entrées de la section « Paramètres » en retrait sous leur titre */
.dropdown-subitem { padding-left: 1.75rem; }

/* Connexion « en tant que » : bandeau bien visible pour ne pas l'oublier */
.impersonation-bar { background: #b42318; color: #fff; }

/* Bloc contact du commercial, sous le message de l'agence (même carte) */
.bat-contact { padding-top: .75rem; padding-bottom: .75rem; }
.bat-contact .min-w-0 { min-width: 0; }
.bat-contact-title { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: #6c757d; margin-bottom: .5rem; }
.bat-contact-avatar {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%;
  background: var(--brand-dark); color: #fff; font-weight: 600; font-size: .9rem;
  display: inline-flex; align-items: center; justify-content: center;
}
/* Téléphone / email : petites lignes cliquables, l'email trop long est tronqué (adresse complète au survol) */
.bat-contact-link {
  display: flex; align-items: center; gap: .5rem; min-width: 0;
  padding: .3rem .55rem; border: 1px solid var(--bs-border-color); border-radius: .375rem;
  color: var(--bs-body-color); text-decoration: none; background: #fff;
}
.bat-contact-link .bi { color: var(--brand-dark); flex-shrink: 0; }
.bat-contact-link:hover { border-color: var(--brand); background: var(--brand-dark-tint); color: var(--brand-dark); }

/* Résultat du BAT (validé / refusé) : barre fixée en bas de l'écran.
   --status-bar-h est mesurée par app.js (la barre peut passer sur 2 lignes) ; la page lui laisse la place. */
.bat-status-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1020;
  padding: .6rem 0; border-top: 1px solid; box-shadow: 0 -2px 8px rgba(0, 0, 0, .06);
}
.bat-status-bar.status-approved { background: var(--bs-success-bg-subtle); border-color: var(--bs-success-border-subtle); color: var(--bs-success-text-emphasis); }
.bat-status-bar.status-rejected { background: var(--bs-warning-bg-subtle); border-color: var(--bs-warning-border-subtle); color: var(--bs-warning-text-emphasis); }
.bat-status-bar.status-approved .bi-check-circle-fill { color: var(--bs-success); }
.bat-status-comment { min-width: 0; flex: 1 1 12rem; }
body.has-status-bar { --status-bar-h: 3rem; padding-bottom: var(--status-bar-h); }
body.has-status-bar .pdf-viewer { height: calc(100vh - 150px - var(--status-bar-h)); }
@media (min-width: 992px) {
  body.has-status-bar .bat-side { max-height: calc(100vh - 100px - var(--status-bar-h)); }
}
@media (max-width: 991.98px) {
  body.has-status-bar .pdf-viewer { height: calc(75vh - var(--status-bar-h)); }
}
body.has-status-bar .pdf-viewer:fullscreen { height: 100vh; } /* le plein écran garde toute la hauteur */

/* Fiche BAT (agence) : lien « Nouvelle version de ce PDF » collé sous son fichier */
.file-new-version { justify-self: end; margin-top: -.3rem; color: var(--brand-dark); text-decoration: none; }
.file-new-version:hover { text-decoration: underline; }

/* Fiche BAT (agence) : n° de devis à côté du titre */
.bat-quote { font-size: .85rem; font-weight: 500; color: var(--ink); background: #fff; border: 1px solid var(--bs-border-color); border-radius: .375rem; padding: .15rem .5rem; white-space: nowrap; }
.bat-quote .bi { color: var(--brand-dark); }
