:root {
    /* Thème vert, repris du logo fatoura.net */
    --primary-color: #028a41;
    --primary-hover: #017a36;
    --primary-rgb: 2, 138, 65;
    --primary-bright: #01b75e;
    --primary-subtle: #e7f6ee;
    --primary-border-subtle: #b5e2c8;
    --primary-emphasis: #01652f;
    --secondary-color: #0ea5e9;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* Couleur « primary » de Bootstrap (text-primary, bg-primary, liens...) */
    --bs-primary: var(--primary-color);
    --bs-primary-rgb: var(--primary-rgb);
    --bs-primary-text-emphasis: var(--primary-emphasis);
    --bs-primary-bg-subtle: var(--primary-subtle);
    --bs-primary-border-subtle: var(--primary-border-subtle);
    --bs-link-color: var(--primary-color);
    --bs-link-color-rgb: var(--primary-rgb);
    --bs-link-hover-color: var(--primary-emphasis);
    --bs-link-hover-color-rgb: 1, 101, 47;
    --bs-focus-ring-color: rgba(var(--primary-rgb), 0.25);
}

/* Composants Bootstrap dont le bleu est figé dans bootstrap.min.css */
.btn-outline-primary {
    --bs-btn-color: var(--primary-color);
    --bs-btn-border-color: var(--primary-color);
    --bs-btn-hover-bg: var(--primary-color);
    --bs-btn-hover-border-color: var(--primary-color);
    --bs-btn-active-bg: var(--primary-hover);
    --bs-btn-active-border-color: var(--primary-hover);
    --bs-btn-disabled-color: var(--primary-color);
    --bs-btn-disabled-border-color: var(--primary-color);
    --bs-btn-focus-shadow-rgb: var(--primary-rgb);
}
.btn-primary {
    --bs-btn-active-bg: var(--primary-hover);
    --bs-btn-active-border-color: var(--primary-hover);
    --bs-btn-disabled-bg: var(--primary-color);
    --bs-btn-disabled-border-color: var(--primary-color);
    --bs-btn-focus-shadow-rgb: var(--primary-rgb);
}
.btn-link {
    --bs-btn-color: var(--primary-color);
    --bs-btn-hover-color: var(--primary-emphasis);
    --bs-btn-active-color: var(--primary-emphasis);
}
.nav-pills {
    --bs-nav-pills-link-active-bg: var(--primary-color);
}
.pagination {
    --bs-pagination-color: var(--primary-color);
    --bs-pagination-hover-color: var(--primary-emphasis);
    --bs-pagination-focus-color: var(--primary-emphasis);
    --bs-pagination-focus-box-shadow: 0 0 0 0.25rem rgba(var(--primary-rgb), 0.25);
    --bs-pagination-active-bg: var(--primary-color);
    --bs-pagination-active-border-color: var(--primary-color);
}
.dropdown-menu {
    --bs-dropdown-link-active-bg: var(--primary-color);
}
.list-group {
    --bs-list-group-active-bg: var(--primary-color);
    --bs-list-group-active-border-color: var(--primary-color);
}
.form-check-input:checked,
.form-check-input[type="checkbox"]:indeterminate {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}
.form-check-input:focus {
    border-color: var(--primary-border-subtle);
    box-shadow: 0 0 0 0.25rem rgba(var(--primary-rgb), 0.25);
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    margin-bottom: 1.5rem;
}

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

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    border-radius: 8px;
    padding: 0.6rem 1.2rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
    transform: translateY(-1px);
}

.form-control, .form-select {
    border-radius: 8px;
    border: 1px solid var(--border-color);
    padding: 0.6rem 0.8rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
}

.navbar {
    background: rgba(255, 255, 255, 0.8) !important;
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 0;
}

.navbar-brand {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    color: var(--primary-color) !important;
}

.nav-link {
    font-weight: 500;
    color: var(--text-main) !important;
    padding: 0.5rem 1rem !important;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.nav-link:hover {
    background: rgba(var(--primary-rgb), 0.05);
    color: var(--primary-color) !important;
}

.nav-link.active {
    background: var(--primary-color);
    color: #fff !important;
}

/* Onglets (nav-tabs) : onglet actif en texte vert sur fond blanc, pas en
   pastille verte comme les liens du menu */
.nav-tabs .nav-link {
    border-radius: 6px 6px 0 0;
}

.nav-tabs .nav-link.active {
    background: var(--bs-body-bg);
    color: var(--primary-color) !important;
}

/* Lien « Administration » du menu principal : ambre, pour le distinguer */
/* Mode administration : barre au-dessus du menu, sur toute la largeur */
.admin-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.4rem 1rem;
    background: #fef3c7;
    border-top: 1px solid #fde68a;
    border-bottom: 1px solid #fde68a;
    color: #b45309;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
}

.admin-bar:hover {
    background: #fde68a;
    color: #92400e;
}

.admin-bar.active {
    background: #d97706;
    border-color: #d97706;
    color: #fff;
}

.table {
    border-collapse: separate;
    border-spacing: 0;
}

.table thead th {
    background-color: #f1f5f9;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-color);
    padding: 1rem;
}

.table tbody td {
    padding: 1rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
}

/* Ligne de récapitulatif (totaux) en pied de tableau */
.table tr.table-recap > td {
    --bs-table-bg: rgba(var(--primary-rgb), 0.08);
    --bs-table-color: var(--primary-emphasis);
    border-top: 2px solid var(--primary-color);
    border-bottom: 0;
}

.invoice-header {
    background: linear-gradient(135deg, #ffffff 0%, #f1f5f9 100%);
    padding: 2rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

.total-section {
    background: #f1f5f9;
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.badge {
    padding: 0.5em 0.8em;
    border-radius: 6px;
    font-weight: 500;
}

/* Auth Pages */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f8faff 0%, #eef2f7 100%);
    padding: 2rem;
}

.auth-card {
    width: 100%;
    max-width: 450px;
    border: none;
    border-radius: 1.5rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

.auth-card .card-body {
    padding: 3rem 2.5rem;
}

.auth-logo {
    font-family: 'Outfit', sans-serif;
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary-color);
    letter-spacing: -1px;
    margin-bottom: 2rem;
    text-align: center;
}

/* Images de la marque (brand_image(), include/assets.php) */
.brand-logo {
    display: block;
    width: auto;
    max-width: 100%;
}
.brand-logo--nav { height: 30px; }
.brand-logo--auth { height: 44px; margin: 0 auto; }
.brand-banniere {
    display: block;
    width: 100%;
    max-width: 720px;
    height: auto;
}

.auth-logo i {
    font-size: 1.8rem;
    margin-right: 0.5rem;
    vertical-align: middle;
}

/* Utility Classes */
.fs-xs { font-size: 0.75rem; }
.fw-medium { font-weight: 500; }

.btn-icon {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 10px;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    transform: translateY(-2px);
}

.btn-light-primary { background-color: rgba(var(--primary-rgb), 0.1); color: var(--primary-color); border: none; }
.btn-light-primary:hover { background-color: var(--primary-color); color: white; }

.btn-light-danger { background-color: rgba(239, 68, 68, 0.1); color: #ef4444; border: none; }
.btn-light-danger:hover { background-color: #ef4444; color: white; }

.btn-light-success { background-color: rgba(34, 197, 94, 0.1); color: #22c55e; border: none; }
.btn-light-success:hover,
.btn-light-success.show { background-color: #22c55e; color: white; }

/* Bouton menu des exports TTN (journal) : même hauteur que .btn-icon */
.btn-ttn {
    height: 38px;
    display: inline-flex;
    align-items: center;
    padding: 0 10px;
    font-size: 0.8rem;
    font-weight: 600;
}

.btn-light-info { background-color: rgba(14, 165, 233, 0.1); color: #0ea5e9; border: none; }
.btn-light-info:hover { background-color: #0ea5e9; color: white; }

.btn-white {
    background-color: white;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.bg-primary-subtle { background-color: rgba(var(--primary-rgb), 0.1) !important; }
.bg-warning-subtle { background-color: rgba(245, 158, 11, 0.1) !important; }

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Company Badge */
.company-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.4rem 0.8rem;
    background: rgba(var(--primary-rgb), 0.05);
    border: 1px solid rgba(var(--primary-rgb), 0.1);
    border-radius: 10px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-color);
    transition: all 0.2s ease;
    text-decoration: none;
}

.company-badge:hover {
    background: rgba(var(--primary-rgb), 0.1);
    transform: translateY(-1px);
    color: var(--primary-color);
}

.company-badge i {
    font-size: 1rem;
    margin-right: 0.5rem;
}

/* Aperçu en-tête facture (fiche société) */
.invoice-header-preview-sheet {
    position: relative;
    font-family: Arial, Helvetica, sans-serif;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    max-width: 210mm;
    margin: 0 auto;
    box-shadow: inset 0 0 0 1px #f1f5f9;
}

.preview-cachet {
    position: absolute;
    right: 17.5mm;
    bottom: 22mm;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.preview-cachet img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.invoice-header-preview-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    min-height: 30mm;
}

.invoice-header-preview-logo {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    background: #fff;
}

.invoice-header-preview-logo img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.invoice-header-preview-company {
    flex: 1;
    max-width: 90mm;
    text-align: right;
    font-size: 9pt;
    line-height: 1.35;
    color: #000;
}

.preview-company-name {
    font-size: 25pt;
    font-weight: bold;
    margin-bottom: 0.35rem;
}

.preview-company-address,
.preview-company-contact,
.preview-company-mf {
    margin-bottom: 0.2rem;
}

.preview-separator {
    border: 0;
    border-top: 1px solid #5c5c5c;
    margin: 1rem 0 0.75rem;
}

.invoice-header-preview-meta {
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    font-size: 10pt;
}

.preview-invoice-left {
    flex: 1;
}

.preview-invoice-title {
    font-size: 14pt;
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.preview-invoice-right {
    flex: 1;
    text-align: right;
    max-width: 90mm;
}

.preview-client-label {
    font-size: 9pt;
    font-weight: bold;
    color: #646464;
    margin-bottom: 0.2rem;
}

.preview-client-name {
    font-size: 11pt;
    font-weight: bold;
}

.preview-client-address,
.preview-client-mf {
    font-size: 10pt;
}

.preview-lines-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    font-size: 8pt;
}

.preview-lines-table th,
.preview-lines-table td {
    border: 1px solid #5c5c5c;
    padding: 0.35rem 0.4rem;
    vertical-align: top;
}

.preview-lines-table thead th {
    background: #808080;
    color: #fff;
    font-weight: bold;
    text-align: center;
}

.preview-lines-table tbody tr:nth-child(even) {
    background: #e0ebff;
}

.preview-lines-table .text-center {
    text-align: center;
}

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

.preview-footer-blocks {
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    margin-top: 1.25rem;
    font-size: 9pt;
}

.preview-vat-title {
    font-weight: bold;
    color: #646464;
    font-size: 9pt;
    margin-bottom: 0.35rem;
}

.preview-vat-table {
    border-collapse: collapse;
    font-size: 8pt;
}

.preview-vat-table th,
.preview-vat-table td {
    border-bottom: 1px solid #ccc;
    padding: 0.25rem 0.5rem;
}

.preview-vat-table thead th {
    background: #f5f5f5;
}

.preview-totals-block {
    min-width: 220px;
    margin-left: auto;
}

.preview-total-row {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-bottom: 0.2rem;
}

.preview-total-row span {
    min-width: 120px;
    text-align: right;
}

.preview-grand-total {
    margin-top: 0.35rem;
    padding: 0.35rem 0;
    font-size: 12pt;
    font-weight: bold;
    border: 1px solid #ccc;
    background: #f0f0f0;
    padding-right: 0.5rem;
}

.preview-amount-words {
    margin-top: 1rem;
    font-size: 10pt;
}

.preview-notes {
    margin-top: 1rem;
    font-size: 9pt;
}

.preview-notes-title {
    font-weight: bold;
    font-size: 10pt;
    margin-bottom: 0.25rem;
}

.preview-page-footer {
    margin-top: 1.25rem;
    text-align: center;
    font-size: 8pt;
    font-style: italic;
    color: #969696;
}

#toastContainer {
    z-index: 11000;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: min(100%, 560px);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0;
    pointer-events: none;
}

#toastContainer .toast {
    pointer-events: auto;
}

.app-toast {
    width: 100%;
    border: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.app-toast-inner {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    padding: 1rem 1.15rem;
}

.app-toast-icon {
    font-size: 1.35rem;
    flex-shrink: 0;
    margin-top: 0.1rem;
}

.app-toast-text {
    flex: 1;
    min-width: 0;
}

.app-toast-title {
    display: block;
    font-family: 'Outfit', sans-serif;
    font-size: 0.95rem;
    margin-bottom: 0.15rem;
}

.app-toast-message {
    display: block;
    font-size: 0.92rem;
    line-height: 1.45;
}

.app-toast .btn-close {
    flex-shrink: 0;
    margin-top: 0.15rem;
    opacity: 0.85;
}

.app-toast .btn-close:hover {
    opacity: 1;
}

.app-toast--danger {
    background: #dc2626;
    color: #fff;
}

.app-toast--warning {
    background: #f59e0b;
    color: #422006;
}

.app-toast--success {
    background: #16a34a;
    color: #fff;
}

.app-toast--info {
    background: var(--primary-color);
    color: #fff;
}

.entity-lookup-panel--loading {
    border-color: var(--primary-color) !important;
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.18);
    background: rgba(var(--primary-rgb), 0.08) !important;
}

.entity-lookup-status {
    display: flex;
    align-items: center;
    color: var(--primary-color);
    font-weight: 500;
    font-size: 0.92rem;
}

/* Tableau de bord — vignette de la société : logo ou initiales */
.societe-logo {
    flex: 0 0 auto;
    min-width: 48px;
    max-width: 112px;
    height: 48px;
    padding: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: 1px solid var(--border-color, #e2e8f0);
    background: #fff;
    overflow: hidden;
}

.societe-logo img {
    max-width: 102px;
    max-height: 38px;
    object-fit: contain;
}

.societe-logo-initiales {
    width: 48px;
    background: var(--primary-subtle);
    border-color: var(--primary-border-subtle);
    color: var(--primary-emphasis);
    font-weight: 700;
    font-size: 1rem;
}

.min-w-0 {
    min-width: 0;
}

/* Fiche société — mise en page */
.societe-fields-stack .form-label {
    margin-bottom: 0.35rem;
}

.societe-media-preview {
    min-height: 7rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.societe-side-panel {
    display: flex;
    flex-direction: column;
}

.societe-pdf-viewer {
    background: #e2e8f0;
    border-radius: var(--radius);
    box-shadow: 0 4px 20px rgb(0 0 0 / 0.06);
}

.societe-pdf-viewer__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: #fff;
    border-bottom: 1px solid var(--border-color);
}

.societe-pdf-viewer__title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #1e293b;
}

.societe-pdf-viewer__subtitle {
    font-size: 0.75rem;
    color: #64748b;
}

.societe-pdf-viewer__frame {
    padding: 1rem;
    overflow-x: auto;
    overflow-y: visible;
}

.societe-pdf-viewer__content {
    display: flex;
    justify-content: center;
}

.societe-pdf-viewer__content .invoice-header-preview-sheet {
    width: 210mm;
    min-height: 297mm;
    max-width: none;
    margin: 0;
    box-sizing: border-box;
    box-shadow: 0 10px 25px rgb(0 0 0 / 0.08);
    display: flex;
    flex-direction: column;
}

.societe-pdf-viewer__content .preview-page-footer {
    margin-top: auto;
    padding-top: 1.5rem;
}

/* Page large (journal) : 80 % de la largeur des grands écrans (≥ 1600 px),
   96 % en dessous pour que le tableau tienne sans défilement horizontal.
   Sous 992 px, pleine largeur comme .container-fluid. */
@media (min-width: 992px) {
    .container-80 {
        max-width: 96%;
    }
}
@media (min-width: 1600px) {
    .container-80 {
        max-width: 80%;
    }
}

/* Saisie : la description détaillée allonge la ligne, les champs restent
   alignés en haut, sur la désignation (champs de 45 px de haut) */
#invoiceLinesTable > tbody > tr > td {
    vertical-align: top !important;
}

#invoiceLinesTable .row-total {
    display: inline-block;
    line-height: 45px;
}

#invoiceLinesTable .delete-btn {
    margin-top: 3px;
}
