/* ============================================
   Devotec - Design premium & professionnel
   Application facturation commerciale
   ============================================ */

:root {
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-darker: #1e3a8a;
    --primary-light: #3b82f6;
    --accent-color: #059669;
    --accent-light: #10b981;
    --secondary-color: #64748b;
    --success-color: #059669;
    --warning-color: #d97706;
    --danger-color: #dc2626;
    --info-color: #0891b2;
    --dark-color: #0f172a;
    --slate-800: #1e293b;
    --light-color: #f8fafc;
    --border-color: #e2e8f0;
    --text-color: #334155;
    --text-muted: #64748b;
    --shadow: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-sm: 0 2px 6px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 10px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 20px -6px rgba(0,0,0,0.08);
    --shadow-card: 0 1px 2px rgba(0,0,0,0.04);
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --sidebar-width: 220px;
    --header-height: 56px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
    max-width: 100%;
    font-size: 12px;
}

/* Zoom par défaut 67% : le même rendu qu’avec « Zoom 67 % » dans le navigateur */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f4f6f9;
    color: var(--text-color);
    line-height: 1.5;
    overflow-x: hidden;
    max-width: 100%;
    font-size: 1rem;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--primary-dark);
}

/* ============================================
   Layout
   ============================================ */
.wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

/* Sidebar - style premium */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(185deg, var(--primary-darker) 0%, #0f172a 45%, #020617 100%);
    color: white;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.3s ease;
    z-index: 1000;
    box-shadow: 4px 0 24px rgba(0,0,0,0.12);
}
.sidebar::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 1px;
    height: 100%;
    background: linear-gradient(180deg, rgba(255,255,255,0.08) 0%, transparent 50%);
    pointer-events: none;
}

/* Sidebar réduite (icônes seules) */
.sidebar.collapsed {
    width: 72px;
}

.sidebar.collapsed .sidebar-logo-wrap {
    height: 90px;
    min-height: 90px;
    padding: 6px;
    overflow: visible;
}

.sidebar.collapsed .sidebar-logo-wrap .sidebar-logo {
    width: 100% !important;
    max-width: 100% !important;
    height: 78px !important;
    min-height: 60px !important;
    max-height: 78px !important;
}

.sidebar.collapsed .menu-label,
.sidebar.collapsed .sidebar-version {
    opacity: 0;
    height: 0;
    padding: 0;
    margin: 0;
    overflow: hidden;
    pointer-events: none;
}

.sidebar.collapsed .sidebar-menu a {
    justify-content: center;
    padding: 14px;
}

.sidebar.collapsed .sidebar-menu a i {
    margin: 0;
    font-size: 1.25rem;
}

/* En mode réduit, masquer le texte des liens (tout ce qui n'est pas l'icône) */
.sidebar.collapsed .sidebar-menu a {
    font-size: 0;
}

.sidebar.collapsed .sidebar-menu a i {
    font-size: 1.25rem;
}

/* Bouton pour agrandir la barre quand elle est réduite */
.sidebar-expand-btn {
    display: none;
    position: absolute;
    top: 10px;
    right: 8px;
    z-index: 10;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: rgba(255,255,255,0.2);
    color: #fff;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}
.sidebar-expand-btn:hover {
    background: rgba(255,255,255,0.35);
}
.sidebar.collapsed .sidebar-expand-btn {
    display: flex !important;
}
.sidebar.collapsed .sidebar-header {
    position: relative;
}

.sidebar-menu a i {
    flex-shrink: 0;
    width: 22px;
    text-align: center;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

/* Logo sidebar – cadre lumineux bleu/teal comme à l’origine */
@keyframes sidebar-logo-glow {
    0%, 100% {
        box-shadow:
            0 0 15px rgba(6, 182, 212, 0.7),
            0 0 30px rgba(59, 130, 246, 0.5),
            0 0 0 2px rgba(56, 189, 248, 0.8);
    }
    50% {
        box-shadow:
            0 0 25px rgba(6, 182, 212, 0.9),
            0 0 45px rgba(59, 130, 246, 0.6),
            0 0 0 3px rgba(56, 189, 248, 1);
    }
}

.sidebar-logo-wrap {
    /* Intérieur du cadre logo : blanc cassé */
    background: #f8fafc;
    border-radius: 16px;
    padding: 8px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 110px;
    min-height: 110px;
    border: 2px solid rgba(56, 189, 248, 0.75);
    position: relative;
    overflow: visible;
    animation: sidebar-logo-glow 2.5s ease-in-out infinite;
    transition: transform 0.2s ease;
    opacity: 1;
    visibility: visible;
}
.sidebar-logo-wrap:hover {
    transform: scale(1.02);
    animation-duration: 1.8s;
}
.sidebar-logo-wrap::before {
    display: none;
}
.sidebar-logo-wrap::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 10%;
    right: 10%;
    height: 3px;
    background: linear-gradient(90deg, transparent, rgba(6, 182, 212, 0.9), var(--accent-color), rgba(6, 182, 212, 0.9), transparent);
    border-radius: 0 0 14px 14px;
    opacity: 0.9;
    pointer-events: none;
}

/* Le logo remplit tout l’espace du cadre (il « joue » dedans) */
/* mix-blend-mode: multiply = le fond blanc du logo (JPEG) se fond dans le bleu de la sidebar */
.sidebar-header .sidebar-logo {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    max-height: 100% !important;
    object-fit: contain;
    object-position: center;
    opacity: 1 !important;
    visibility: visible !important;
    mix-blend-mode: multiply;
}

@media (max-width: 768px) {
    @keyframes sidebar-logo-glow-mobile {
        0%, 100% {
            box-shadow: 0 0 12px rgba(6, 182, 212, 0.7), 0 0 25px rgba(59, 130, 246, 0.5), 0 0 0 2px rgba(56, 189, 248, 0.8);
        }
        50% {
            box-shadow: 0 0 20px rgba(6, 182, 212, 0.9), 0 0 35px rgba(59, 130, 246, 0.6), 0 0 0 3px rgba(56, 189, 248, 1);
        }
    }
    .sidebar-logo-wrap {
        height: 110px !important;
        min-height: 110px !important;
        padding: 8px;
        border: 2px solid rgba(56, 189, 248, 0.75);
        animation: sidebar-logo-glow-mobile 2.5s ease-in-out infinite;
    }
    .sidebar-header .sidebar-logo {
        width: 100% !important;
        height: 100% !important;
        min-height: 0 !important;
        max-height: 100% !important;
        object-fit: contain !important;
        object-position: center !important;
        mix-blend-mode: multiply;
    }
    .sidebar-header {
        padding-left: 20px;
        padding-right: 20px;
    }
}

.sidebar-header {
    overflow: visible;
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    color: rgba(255,255,255,0.95);
}

.sidebar-header h2 i {
    color: var(--accent-color);
    font-size: 1.1rem;
}

.sidebar-menu a:hover {
    background: #eef4ff; /* bleu très faible, presque blanc */
    color: #1e40af;
    border-left-color: rgba(59, 130, 246, 0.5);
}
.sidebar-menu a:hover i {
    color: #1e40af;
}
.sidebar-menu a.active {
    background: #eef4ff;
    color: #1e40af;
    border-left: 3px solid rgba(59, 130, 246, 0.6);
    font-weight: 600;
}
.sidebar-menu a.active i {
    color: #1e40af;
}

.sidebar-menu {
    padding: 12px 0;
}

.sidebar-menu ul {
    list-style: none;
}

.sidebar-menu li {
    margin-bottom: 5px;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    color: rgba(255,255,255,0.7);
    transition: all 0.2s;
    border-left: 3px solid transparent;
    font-size: 0.95rem;
}

.sidebar-menu a i {
    width: 24px;
    margin-right: 12px;
    font-size: 1.1rem;
}

.menu-label {
    padding: 15px 20px 10px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.4);
}

.sidebar-version {
    position: absolute;
    bottom: 12px;
    left: 20px;
    font-size: 0.7rem;
    color: rgba(255,255,255,0.35);
}

/* Voile menu mobile (actif uniquement ≤768px, voir @media) */
.sidebar-overlay {
    display: none;
    pointer-events: none;
}

/* Main Content – reste dans l’écran sans débordement horizontal */
.main-content {
    margin-left: 220px;
    flex: 1 1 0;
    min-height: 100vh;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    transition: margin-left 0.3s ease;
}

/* Contenu quand la sidebar est réduite */
.wrapper.sidebar-collapsed .main-content {
    margin-left: 72px;
}

/* Header */
.header {
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 0 rgba(0,0,0,0.06);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid rgba(0,0,0,0.04);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

#toggleSidebar {
    flex-shrink: 0;
}
.toggle-sidebar-label {
    margin-left: 6px;
}
@media (max-width: 480px) {
    .toggle-sidebar-label { display: none; }
}

.header-left h1 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--dark-color);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px 8px 10px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: var(--radius-lg);
    cursor: pointer;
    border: 1px solid rgba(0,0,0,0.06);
    transition: box-shadow 0.2s;
}
.user-menu:hover {
    box-shadow: var(--shadow-sm);
}

.user-menu img {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    object-fit: cover;
}

/* Content Area */
.content {
    padding: 14px 18px;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
}

/* ============================================
   Cards - style pro
   ============================================ */
.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    margin-bottom: 12px;
    border: 1px solid rgba(0,0,0,0.04);
    overflow: hidden;
}

.card-header {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(0,0,0,0.04);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--slate-800);
    letter-spacing: -0.01em;
}

.card-body {
    padding: 12px 14px;
}

.card-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--light-color);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ============================================
   Stats Cards - design premium tableau de bord
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 10px 12px;
    box-shadow: var(--shadow-card);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: box-shadow 0.2s ease;
    border: 1px solid rgba(0,0,0,0.04);
    position: relative;
}
.stat-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.stat-card::before {
    display: none;
}

.stat-icon {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}
.stat-icon.blue { background: rgba(37, 99, 235, 0.1); color: var(--primary-color); }
.stat-icon.green { background: rgba(34, 197, 94, 0.1); color: var(--success-color); }
.stat-icon.orange { background: rgba(245, 158, 11, 0.1); color: var(--warning-color); }
.stat-icon.red { background: rgba(239, 68, 68, 0.1); color: var(--danger-color); }

.stat-info h4 {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 2px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-info .value {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--slate-800);
    letter-spacing: -0.02em;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn i {
    font-size: 0.9rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}
.btn-primary:hover {
    background: var(--primary-dark);
    color: white;
}

.btn-success {
    background: var(--accent-color);
    color: white;
}
.btn-success:hover {
    background: #047857;
    color: white;
}

.btn-warning {
    background: #d97706;
    color: white;
}
.btn-warning:hover {
    background: #b45309;
    color: white;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
    color: white;
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
}
.btn-outline:hover {
    background: var(--light-color);
    border-color: var(--primary-light);
    color: var(--primary-dark);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 1rem;
}

.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

/* ============================================
   Dashboard premium - cartes Ventes / Achats
   ============================================ */
.dashboard-hero-card {
    border: none;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-card);
    transition: transform 0.2s, box-shadow 0.25s;
}
.dashboard-hero-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px -8px rgba(0,0,0,0.12);
}
.dashboard-hero-card .card-header {
    padding: 16px 20px;
    border-bottom: none;
    font-weight: 600;
}
.dashboard-hero-card .card-body {
    padding: 14px 16px;
}
.dashboard-hero-card .card-body .value {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.dashboard-hero-card.sales .card-header { background: linear-gradient(135deg, #dbeafe 0%, #eff6ff 100%); color: var(--primary-dark); }
.dashboard-hero-card.purchases .card-header { background: linear-gradient(135deg, #fef3c7 0%, #fffbeb 100%); color: #92400e; }

/* Empty state - message vide élégant */
.empty-state {
    text-align: center;
    padding: 28px 20px;
    color: var(--text-muted);
    font-size: 0.95rem;
}
.empty-state::before {
    content: '';
    display: block;
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    background: var(--light-color);
    border-radius: 50%;
    opacity: 0.8;
}
.card-body > .text-muted.text-center {
    padding: 20px 16px;
    font-size: 0.85rem;
    color: var(--text-muted);
    background: #fafafa;
    border-radius: var(--radius);
    margin: 0;
}

/* État vide liste (devis, factures, etc.) - compact et doux */
.empty-list-state {
    padding: 28px 20px !important;
    text-align: center;
    color: var(--text-muted);
}
.empty-list-state .empty-icon {
    font-size: 2rem;
    opacity: 0.25;
    margin-bottom: 10px;
}
.empty-list-state p {
    margin: 0 0 10px;
    font-size: 0.9rem;
}
.empty-list-state .btn {
    margin-top: 4px;
}

/* ============================================
   Forms
   ============================================ */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--dark-color);
}

.form-control {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.08);
}

.form-control::placeholder {
    color: var(--text-muted);
}

textarea.form-control {
    min-height: 120px;
    resize: vertical;
}

select.form-control {
    cursor: pointer;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.form-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 5px;
}

/* ============================================
   Tables
   ============================================ */
.table-responsive {
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

/* Mobile : forcer un vrai scroll horizontal sur les tableaux “historiques” */
@media (max-width: 768px) {
    .table-responsive {
        overflow-x: auto;
        overflow-y: hidden;
        touch-action: pan-x pan-y;
    }
    .table-responsive > .table {
        /* Empêche le tableau de se “compresser” et active le drag horizontal */
        min-width: 720px;
    }
    .table-responsive > .document-info-table,
    .table-responsive > .document-table {
        min-width: 720px;
    }

    /* Les règles "width:100% !important" des documents peuvent bloquer le scroll :
       en mobile on force une largeur mini scrollable. */
    .document-invoice .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    .document-invoice .table-responsive > .document-info-table,
    .document-invoice .table-responsive > .document-table {
        min-width: 720px !important;
        width: auto !important;
    }

    /* Empêche les colonnes de se compresser (sinon pas de scroll) */
    .document-invoice .document-info-table th,
    .document-invoice .document-info-table td,
    .document-invoice .document-table th,
    .document-invoice .document-table td {
        white-space: nowrap;
    }
    /* La désignation peut rester lisible */
    .document-invoice .document-table th:first-child,
    .document-invoice .document-table td:first-child {
        white-space: normal;
    }

    /* IMPORTANT: .card a overflow:hidden (bloque le scroll interne sur mobile) */
    .document-invoice.card {
        overflow: visible !important;
    }
    .document-invoice.card .card-body {
        overflow: visible !important;
    }
    .document-invoice .table-responsive {
        overflow-x: auto !important;
        overflow-y: hidden !important;
    }

    /* Barres d'actions (Retour / Modifier / Imprimer...) : ne pas couper, autoriser retour à la ligne */
    .no-print.d-flex.flex-wrap {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    .no-print.d-flex.flex-wrap .btn {
        flex: 1 1 auto;
        max-width: 100%;
        white-space: nowrap;
    }
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    background: var(--light-color);
    font-weight: 600;
    color: var(--dark-color);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.table tbody tr:hover {
    background: rgba(37, 99, 235, 0.02);
}

.table .actions {
    display: flex;
    gap: 8px;
}

/* Colonne Unité (facture / devis) : lisibilité */
.unit-cell {
    vertical-align: top;
}
.unit-cell-inner {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 78px;
}
.unit-cell-inner .item-unit-select,
.unit-cell-inner .item-unit {
    display: block;
    width: 78px !important;
    min-width: 78px;
}

/* ============================================
   Badges / Status
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-draft { background: #e2e8f0; color: #475569; }
.badge-sent { background: #dbeafe; color: #1d4ed8; }
.badge-accepted { background: #dcfce7; color: #16a34a; }
.badge-rejected { background: #fee2e2; color: #dc2626; }
.badge-expired { background: #fef3c7; color: #d97706; }
.badge-converted { background: #f3e8ff; color: #7c3aed; }
.badge-paid { background: #dcfce7; color: #16a34a; }
.badge-partial { background: #fef3c7; color: #d97706; }
.badge-overdue { background: #fee2e2; color: #dc2626; }
.badge-cancelled { background: #f1f5f9; color: #64748b; }
.badge-confirmed { background: #dbeafe; color: #1d4ed8; }
.badge-in_progress { background: #fef3c7; color: #d97706; }
.badge-delivered { background: #dcfce7; color: #16a34a; }
.badge-danger { background: #fee2e2; color: #dc2626; }
.badge-warning { background: #fef3c7; color: #d97706; }

/* Tranches de prix dans le catalogue produits */
.product-price-tiers {
    display: flex;
    flex-wrap: wrap;
    flex-direction: column;
    gap: 4px;
}
.product-price-tiers .tier-badge {
    display: inline-block;
    font-size: 0.8rem;
    padding: 2px 8px;
    background: #e0f2fe;
    color: #0369a1;
    border-radius: 4px;
    white-space: nowrap;
    max-width: 100%;
}
.product-price-tiers .tier-badge:hover {
    background: #bae6fd;
}

/* ============================================
   Alerts
   ============================================ */
.alert {
    padding: 15px 20px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.alert-success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.alert-info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

/* ============================================
   Pagination
   ============================================ */
.pagination {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin-top: 20px;
}

.pagination a,
.pagination span {
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-color);
    transition: all 0.2s;
}

.pagination a:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.pagination .active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* ============================================
   Modal
   ============================================ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: white;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(-20px);
    transition: transform 0.3s;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.2rem;
    font-weight: 600;
}

.modal-content {
    background: white;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

/* Modale catalogue produits : fond clair */
.modal-overlay.modal-light .modal-content,
#productModal.modal-overlay .modal-content {
    background: #ffffff;
    border: 1px solid #e0e4e8;
    box-shadow: 0 12px 48px rgba(0,0,0,0.15);
}
#productModal .modal-header {
    background: #f0f4f8;
    border-bottom: 1px solid #e0e4e8;
}
#productModal .modal-body {
    background: #fafbfc;
}
#productModal .table {
    background: #fff;
}
#productModal .table thead th {
    background: #e8ecf0;
    color: #2c3e50;
    font-weight: 600;
}
#productModal .table tbody tr:hover {
    background: #f5f7f9;
}

/* Modale catalogue : large pour tout voir sans glisser à droite/gauche */
.modal-product-tall {
    max-width: min(960px, 96vw) !important;
    max-height: 88vh !important;
    min-height: 400px;
}
#productModal .modal-products-list,
.modal-products-list {
    max-height: 65vh;
    min-height: 320px;
    overflow-y: auto;
    overflow-x: visible;
}
/* Pas de défilement horizontal dans la modale produits */
#productModal .modal-products-list .table-responsive {
    overflow-x: visible;
}
#productModal .modal-products-list .table {
    width: 100%;
    table-layout: fixed;
}
#productModal .modal-products-list .table th:nth-child(1),
#productModal .modal-products-list .table td:nth-child(1) { width: 10%; }   /* Réf */
#productModal .modal-products-list .table th:nth-child(2),
#productModal .modal-products-list .table td:nth-child(2) { width: 22%; } /* Nom */
#productModal .modal-products-list .table th:nth-child(3),
#productModal .modal-products-list .table td:nth-child(3) { width: 12%; }   /* Quantité */
#productModal .modal-products-list .table th:nth-child(4),
#productModal .modal-products-list .table td:nth-child(4) { width: 14%; }  /* Prix */
#productModal .modal-products-list .table th:nth-child(5),
#productModal .modal-products-list .table td:nth-child(5) { width: 12%; }   /* Total */
#productModal .modal-products-list .table th:nth-child(6),
#productModal .modal-products-list .table td:nth-child(6) { width: 8%; }    /* TVA */
#productModal .modal-products-list .table th:nth-child(7),
#productModal .modal-products-list .table td:nth-child(7) { width: 22%; }  /* Action */
#productModal .modal-products-list .table td { overflow: hidden; }
#productModal .modal-products-list .table td:nth-child(1) { white-space: nowrap; text-overflow: ellipsis; }
#productModal .modal-products-list .table td:nth-child(2) { white-space: normal; word-break: break-word; }
#productModal .modal-products-list .table td:nth-child(7) { white-space: nowrap; overflow: visible; }

.btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.btn-close:hover {
    background: var(--light-color);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ============================================
   Login Page
   ============================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #1e40af 0%, #1e3a8a 50%, #172554 100%);
    background-attachment: fixed;
}

.login-box {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.05);
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo-wrap {
    margin-bottom: 16px;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-logo {
    max-height: 120px;
    max-width: 280px;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

.login-fallback {
    font-size: 1.75rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
}

.login-tagline {
    color: #64748b;
    font-size: 0.95rem;
    margin: 0;
    letter-spacing: 0.02em;
}

.login-header p {
    color: var(--text-muted);
}

.login-btn {
    width: 100% !important;
    padding: 12px 20px;
    font-size: 1rem;
    border-radius: 10px;
    font-weight: 600;
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .sidebar,
    .header,
    .btn,
    .no-print,
    .trial-countdown,
    .trial-active-msg {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .content {
        padding: 0;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    /* Drawer : LTR = hors écran à gauche ; RTL = hors écran à droite (translateX(-100%) + right:0 laissait le menu visible) */
    .sidebar {
        top: 0;
        left: 0;
        right: auto;
        width: 260px;
        max-width: min(260px, 100vw);
        overflow-x: visible;
        transition: transform 0.3s ease;
        transform: translate3d(-100%, 0, 0);
    }

    .sidebar.active {
        transform: translate3d(0, 0, 0);
    }

    html[dir="rtl"] .sidebar {
        left: auto !important;
        right: 0 !important;
        transform: translate3d(100%, 0, 0) !important;
    }

    html[dir="rtl"] .sidebar.active {
        transform: translate3d(0, 0, 0) !important;
    }

    .sidebar.collapsed {
        width: 260px;
    }

    .sidebar.collapsed:not(.active) {
        transform: translate3d(-100%, 0, 0);
    }

    html[dir="rtl"] .sidebar.collapsed:not(.active) {
        transform: translate3d(100%, 0, 0) !important;
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 999;
        background: rgba(15, 23, 42, 0.45);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s ease, visibility 0.25s ease;
        pointer-events: none;
    }

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .wrapper.sidebar-collapsed .main-content {
        margin-left: 0;
    }

    html[dir="rtl"] .main-content {
        margin-right: 0 !important;
    }

    html[dir="rtl"] .wrapper.sidebar-collapsed .main-content {
        margin-right: 0 !important;
    }
    
    .content {
        padding: 12px 14px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Une seule colonne sur mobile (y compris Ventes / Achats) */
    .stats-grid,
    .stats-grid-hero {
        grid-template-columns: 1fr !important;
        width: 100%;
    }
    
    /* Cartes tableau de bord pleine largeur, texte qui wrap */
    .stats-grid .card,
    .stats-grid-hero .card {
        width: 100%;
        min-width: 0;
    }
    
    .dashboard-hero-card .card-header {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .dashboard-hero-card .card-header h3 {
        font-size: 0.9rem;
        word-wrap: break-word;
        min-width: 0;
    }
    
    .dashboard-hero-card .card-body .text-muted,
    .dashboard-hero-card .card-body p {
        font-size: 0.8rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .header {
        padding: 12px 14px;
    }
    
    .header-left h1 {
        font-size: 0.95rem;
    }
}

@media (max-width: 480px) {
    .content {
        padding: 10px 12px;
    }
    
    .stats-grid {
        gap: 8px;
    }
    
    .card-header h3 {
        font-size: 0.9rem;
    }
    
    .btn-group {
        flex-direction: column;
    }
    
    .btn-group .btn {
        width: 100%;
        justify-content: center;
    }
}

/* ============================================
   Utilities
   ============================================ */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success-color); }
.text-danger { color: var(--danger-color); }
.text-warning { color: var(--warning-color); }

.mt-1 { margin-top: 10px; }
.mt-2 { margin-top: 20px; }
.mt-3 { margin-top: 30px; }
.mb-1 { margin-bottom: 10px; }
.mb-2 { margin-bottom: 20px; }
.mb-3 { margin-bottom: 30px; }

.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 10px; }
.gap-2 { gap: 20px; }

/* Document Preview - Format facture/devis (tailles réduites pour écran et PDF) */
.document-preview {
    background: white;
    max-width: 1100px;
    margin: 0 auto;
    padding: 56px;
    box-shadow: var(--shadow-lg);
    font-size: 0.95rem;
}

/* Cartes sous la facture/devis (Documents liés, etc.) : alignées avec le document */
.document-related-card {
    max-width: 1100px;
    margin-left: auto;
    margin-right: auto;
}
.document-related-card .card-header {
    padding: 20px 20px 20px 40px;
}
.document-related-card .card-body {
    padding: 20px 20px 20px 40px;
}

.document-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
}

.document-brand {
    flex: 0 0 auto;
}

.document-logo {
    max-height: 115px;
    max-width: 320px;
    margin-bottom: 12px;
    display: block;
    object-fit: contain;
}

/* Documents : logo seul, plus grand (pas de nom en dessous) */
.document-brand-logo-only .document-logo {
    max-height: 280px;
    max-width: 560px;
    margin-bottom: 0;
}

.document-brand .document-company-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 2px;
}

.document-brand .document-company-slogan {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.document-client-block {
    text-align: left;
    max-width: 280px;
}

.document-client-block .document-client-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.document-client-block p {
    margin: 0 0 2px 0;
    font-size: 0.95rem;
}

.document-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--dark-color);
    margin-bottom: 16px;
    letter-spacing: 0.02em;
}

.document-info-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 24px;
}

.document-info-table th,
.document-info-table td {
    border: 1px solid var(--border-color);
    padding: 10px 12px;
    font-size: 0.9rem;
}

.document-info-table th {
    background: var(--light-color);
    font-weight: 600;
    text-align: center;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.02em;
}

.document-info-table td {
    text-align: center;
}

.document-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--primary-color);
}

.document-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    margin-bottom: 40px;
}

.document-table {
    width: 100%;
    margin-bottom: 24px;
    border-collapse: collapse;
}

.document-table th,
.document-table td {
    border: 1px solid var(--border-color);
    padding: 10px 12px;
    font-size: 0.9rem;
}

.document-table th {
    background: var(--light-color);
    font-weight: 600;
    text-align: center;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.02em;
}

.document-table th:first-child,
.document-table td:first-child {
    text-align: left;
}

.document-table td:nth-child(2),
.document-table td:nth-child(3) {
    text-align: center;
}

.document-table td:nth-child(4),
.document-table td:nth-child(5) {
    text-align: right;
}

.document-totals {
    margin-left: auto;
    width: 320px;
    margin-bottom: 32px;
}

.document-totals table {
    width: 100%;
    border-collapse: collapse;
}

.document-totals td {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    font-size: 0.95rem;
}

.document-totals tr.total-row td {
    font-size: 1.1rem;
    font-weight: 700;
    border-top: 2px solid var(--dark-color);
}

.document-amount-words {
    margin-top: 14px;
    font-size: 0.95rem;
    color: var(--text-color);
}

.document-footer {
    margin-top: 40px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.document-footer p {
    margin: 0 0 4px 0;
}

/* ========== Facture : visage société (design premium) ========== */
.document-invoice {
    border-radius: var(--radius-lg);
    overflow: visible;
    border: 1px solid var(--border-color);
    padding-bottom: 24px;
}

.document-invoice .document-top {
    padding-bottom: 24px;
    margin-bottom: 28px;
    border-bottom: 3px solid #e2e8f0;
}

.document-invoice .document-brand .document-company-name {
    font-size: 1.15rem;
    font-weight: 800;
    color: #1e293b;
    letter-spacing: -0.02em;
}

.document-invoice .document-brand-logo-only .document-logo {
    max-height: 280px;
    max-width: 560px;
}

/* Cadre « Facturé à » : largeur réduite, hauteur inchangée */
.document-invoice .document-client-cadre {
    display: block;
    min-width: 260px;
    max-width: 380px;
    margin-top: 28px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: linear-gradient(165deg, #ffffff 0%, #f8fafc 50%, #f1f5f9 100%);
    box-shadow: 0 4px 14px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.05);
    border-left: 5px solid #cbd5e1;
}

.document-invoice .document-client-cadre .document-client-block {
    background: transparent;
    padding: 16px 20px;
    border: none;
    border-radius: 0;
    border-left: none;
    box-shadow: none;
    max-width: none;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.document-invoice .document-client-block .document-client-label {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: #1e293b;
    margin-bottom: 8px;
}

.document-invoice .document-client-block p {
    margin: 0 0 2px 0;
    font-size: 0.9rem;
}

/* Titre principal « Devis » / « Facture » */
.document-invoice .document-title,
.document-preview.document-invoice .document-title {
    font-size: 1.15rem !important;
    font-weight: 800;
    color: #1e293b;
    margin-bottom: 14px;
    padding-bottom: 10px;
    padding-top: 4px;
    padding-left: 28px;
    border-bottom: 3px solid var(--border-color);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.document-invoice .document-info-table {
    margin-bottom: 28px;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.document-invoice .document-info-table th {
    background: #f1f5f9 !important;
    color: #1e293b !important;
    padding: 10px 12px;
    font-size: 0.88rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    border: 1px solid #e2e8f0;
    line-height: 1.3;
}

.document-invoice .document-info-table td {
    padding: 10px 12px;
    background: #fafbfc;
    font-size: 0.88rem;
    line-height: 1.3;
}
/* Colonnes DATE et Date d'échéance : largeur min pour que la date s'affiche bien */
.document-invoice .document-info-table th:first-child,
.document-invoice .document-info-table td:first-child,
.document-invoice .document-info-table th:last-child,
.document-invoice .document-info-table td:last-child {
    min-width: 5.5em;
    white-space: nowrap;
}

.document-invoice .document-table {
    margin-bottom: 28px;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.document-invoice .document-table th {
    background: #f1f5f9 !important;
    color: #1e293b !important;
    padding: 10px 12px;
    font-size: 0.88rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    border: 1px solid #e2e8f0;
    line-height: 1.3;
}

.document-invoice .document-table tbody tr:nth-child(even) {
    background: #fafbfc;
}

.document-invoice .document-table tbody tr:hover {
    background: #f1f5f9;
}

.document-invoice .document-table td {
    padding: 10px 12px;
    font-size: 0.88rem;
    border-color: #e2e8f0;
    line-height: 1.35;
}

/* Photo produit à côté de la désignation (devis, facture) */
.document-designation-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}
/* Réservation d’une largeur fixe pour la vignette (image ou vide) pour aligner toutes les désignations */
.document-designation-thumb {
    flex-shrink: 0;
    width: 24px;
    min-width: 24px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}
.document-product-img {
    flex-shrink: 0;
    width: 24px !important;
    height: 24px !important;
    max-width: 24px !important;
    max-height: 24px !important;
    min-width: 24px;
    min-height: 24px;
    object-fit: contain;
    border: 1px solid #e2e8f0;
    border-radius: 3px;
    display: block;
}
.document-designation-text {
    flex: 1;
    min-width: 0;
}

.document-invoice .document-totals {
    width: 380px;
    margin-bottom: 36px;
}

.document-invoice .document-totals table {
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.document-invoice .document-totals td {
    padding: 10px 14px;
    font-size: 0.9rem;
    border-color: var(--border-color);
}

.document-invoice .document-totals tr.document-totals-tva td {
    background: #f1f5f9;
    font-weight: 600;
    color: var(--dark-color);
}

.document-invoice .document-totals tr.total-row td {
    background: #e2e8f0 !important;
    color: #1e293b !important;
    font-size: 0.95rem;
    font-weight: 700;
    border: 1px solid #cbd5e1;
    padding: 10px 14px;
}

/* Zone totaux : phrase « Arrêtée la présente facture » + conditions à gauche, tableau des montants à droite, alignés en bas */
.document-invoice .document-totals-zone {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: flex-end;
    gap: 16px;
    margin-top: 32px;
    margin-bottom: 36px;
    margin-left: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}
.document-invoice .document-totals-zone .document-amount-words-zone {
    flex: 1 1 auto !important;
    min-width: 260px !important;
    max-width: min(420px, 50%) !important;
    padding: 12px 16px 12px 10px;
    background: #f8fafc;
    border-radius: 12px;
    border-left: 4px solid #94a3b8;
    overflow-wrap: break-word;
    word-wrap: break-word;
    box-sizing: border-box;
}
.document-invoice .document-totals-zone .document-amount-words-zone p {
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.35;
    font-style: italic;
    color: #475569;
    overflow-wrap: break-word;
    word-wrap: break-word;
}
.document-invoice .document-totals-zone .document-amount-words-zone p:first-child {
    font-style: normal;
    color: #1e293b;
}
.document-invoice .document-totals-zone .document-totals {
    flex: 1 1 auto !important;
    min-width: 340px !important;
    margin-left: 32px;
    box-sizing: border-box;
    display: flex;
    justify-content: flex-end;
}
.document-invoice .document-totals-zone .document-totals table {
    width: 340px;
    max-width: 100%;
}
.document-invoice .document-totals-zone .document-amount-words-zone strong {
    color: #1e293b;
    font-style: normal;
}

.document-invoice .document-amount-words {
    margin-top: 16px;
    padding: 12px 16px;
    background: var(--light-color);
    border-radius: var(--radius);
    border-left: 4px solid var(--accent-color);
    font-style: italic;
    text-align: left;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.document-invoice .document-footer {
    margin-top: 20px;
    margin-bottom: 0;
    padding: 12px 20px 14px;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: #475569;
    text-align: center;
}

.document-invoice .document-footer p {
    margin: 0 0 4px 0;
}

.document-invoice .document-footer p:last-child {
    margin-bottom: 0;
}

/* Bon de livraison : alignement comme la facture */
.document-invoice .document-delivery-client {
    display: block !important;
    min-width: 260px;
    max-width: 380px;
    margin-top: 28px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: linear-gradient(165deg, #fff 0%, #f8fafc 50%, #f1f5f9 100%);
    box-shadow: 0 4px 14px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.05);
    border-left: 5px solid #cbd5e1;
}
.document-invoice .document-delivery-info th,
.document-invoice .document-delivery-info td {
    text-align: center !important;
}
.document-invoice .document-delivery-totals.document-totals-zone {
    display: flex !important;
    flex-direction: row !important;
    justify-content: flex-end !important;
    margin-top: 32px;
    margin-bottom: 36px;
    width: 100%;
}
.document-invoice .document-delivery-totals .document-totals {
    flex: 0 0 340px !important;
    width: 340px !important;
    min-width: 340px !important;
    margin-left: 0 !important;
}
.document-invoice .document-delivery-totals .document-totals table {
    width: 100%;
}

/* Contenu page facture : flex pour pousser le pied en bas */
.invoice-view-content {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 220px);
}
.invoice-view-content .document-page-footer {
    margin-top: auto;
}

/* Pied de page entreprise : tout en bas, même taille que "Arrêtée la présente facture..." (0.8rem) */
.document-page-footer {
    max-width: 900px;
    margin: 24px auto 0;
    padding: 16px 40px 24px;
    text-align: center;
    color: #475569;
    font-size: 0.8rem;
    line-height: 1.4;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}
.document-page-footer p {
    margin: 0 0 4px 0;
}
.document-page-footer p:last-child {
    margin-bottom: 0;
}

/* Corps du document (pour pousser le pied en bas à l'impression) */
.document-body {
    /* rien à l'écran */
}

/* Phrase « Arrêtée la présente facture... » tout en bas, après le pied de page */
.document-invoice .document-amount-words-bottom {
    margin-top: 24px;
    margin-bottom: 0;
    padding: 12px 0 0 0;
    border-left: none;
    text-align: left;
}

/* Impression : format A4 pleine page */
@media print {
    @page {
        size: A4 portrait;
        margin: 6mm;
    }
    html, body {
        width: 198mm !important;
        min-width: 198mm !important;
        max-width: 198mm !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff;
    }
    .wrapper, .main-content, .content {
        margin: 0 !important;
        padding: 0 !important;
        width: 198mm !important;
        max-width: 198mm !important;
        min-width: 198mm !important;
    }
    .no-print, .sidebar, .topbar, .btn, .alert, .trial-countdown, .trial-active-msg { display: none !important; }

    /*
     * Chaque .document-preview.document-invoice = 1 page imprimée.
     * Structure :
     *   ┌─────────────────────────┐
     *   │  document-body          │  (contenu : en-tête, articles, totaux…)
     *   │  document-footer        │  (coordonnées entreprise, toujours en bas)
     *   └─────────────────────────┘
     */
    .document-preview {
        box-shadow: none !important;
        padding: 0 !important;
        width: 198mm !important;
        max-width: 198mm !important;
        min-width: 198mm !important;
        margin: 0 !important;
        height: auto !important;
        display: block !important;
        overflow: visible !important;
    }
    /* Chaque bloc = une page physique */
    .document-preview.document-invoice {
        page-break-after: always;
    }
    .document-preview.document-invoice:last-of-type {
        page-break-after: auto;
    }
    .document-invoice {
        overflow: visible !important;
        padding-bottom: 0 !important;
    }
    .document-preview .document-body {
        display: block;
        overflow: visible;
    }
    /* Pied de page (coordonnées) : collé juste après le contenu */
    .document-preview .document-footer {
        margin-top: 0 !important;
        overflow: visible;
    }

    /* ── Tailles et espacements à l'impression ── */
    .document-invoice .document-top {
        margin-bottom: 10px !important;
        padding-bottom: 8px !important;
    }
    .document-invoice .document-brand-logo-only .document-logo,
    .document-invoice .document-logo,
    .document-brand-logo-only .document-logo,
    .document-logo {
        max-height: 110px !important;
        max-width: 320px !important;
    }
    .document-invoice .document-client-cadre {
        margin-top: 8px !important;
    }
    .document-invoice .document-title,
    .document-preview.document-invoice .document-title {
        font-size: 1rem !important;
        margin-bottom: 8px !important;
        padding-bottom: 6px !important;
        padding-left: 20px !important;
    }
    .document-invoice .document-client-block .document-client-label {
        font-size: 0.75rem !important;
    }
    .document-invoice .document-client-block p {
        font-size: 0.85rem !important;
    }
    .document-invoice .document-info-table,
    .document-invoice .document-table {
        margin-bottom: 10px !important;
        width: 100% !important;
    }
    .document-invoice .document-info-table th,
    .document-invoice .document-info-table td,
    .document-invoice .document-table th,
    .document-invoice .document-table td {
        padding: 6px 8px !important;
        font-size: 0.8rem !important;
        line-height: 1.2 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .document-invoice .document-info-table th,
    .document-invoice .document-table th {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .document-invoice .document-table thead {
        display: table-header-group;
    }
    .document-invoice .document-table tr {
        page-break-inside: avoid;
    }
    .document-invoice .document-table {
        page-break-inside: auto;
    }
    .document-designation-thumb {
        width: 18px !important;
        min-width: 18px !important;
    }
    .document-product-img {
        width: 18px !important;
        height: 18px !important;
        max-width: 18px !important;
        max-height: 18px !important;
    }
    /* Totaux : juste après les articles, sans décalage */
    .document-invoice .document-totals {
        margin-top: 8px !important;
        margin-bottom: 8px !important;
        width: 340px !important;
        max-width: 340px !important;
        page-break-inside: avoid;
    }
    .document-invoice .document-totals td {
        padding: 6px 10px !important;
        font-size: 0.85rem !important;
    }
    .document-invoice .document-totals tr.document-totals-tva td {
        background: #f1f5f9 !important;
        font-weight: 600 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .document-invoice .document-totals tr.total-row td {
        padding: 6px 10px !important;
        font-size: 0.88rem !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .document-invoice .document-footer {
        margin-top: 10px !important;
        padding: 8px 0 0 !important;
        background: transparent !important;
        border: none !important;
        border-top: 1px solid #e2e8f0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        font-size: 0.72rem !important;
    }
    .document-invoice .document-footer p {
        margin: 0 0 3px 0 !important;
    }
    /* Ne pas couper ces blocs en plein milieu */
    .document-invoice .document-top,
    .document-invoice .document-info-table {
        page-break-inside: avoid;
    }
    /* Conditions de règlement : supprimer margin-bottom en impression */
    .invoice-conditions {
        margin-bottom: 0 !important;
        margin-top: 8px !important;
    }
    .document-page-footer {
        margin-top: 12px !important;
        padding: 8px 14px !important;
        font-size: 0.7rem !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .document-page-footer p {
        margin: 0 0 2px 0 !important;
    }
}

/* ============================================
   RTL — العربية
   ============================================ */
[dir="rtl"] body {
    font-family: 'Tajawal', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
[dir="rtl"] .sidebar {
    left: auto !important;
    right: 0 !important;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12) !important;
}
[dir="rtl"] .sidebar::after {
    right: auto;
    left: 0;
}
[dir="rtl"] .main-content {
    margin-left: 0 !important;
    margin-right: 220px !important;
}
[dir="rtl"] .wrapper.sidebar-collapsed .main-content {
    margin-right: 72px !important;
}
[dir="rtl"] .sidebar-menu a {
    border-left: none;
    border-right: 3px solid transparent;
}
[dir="rtl"] .sidebar-menu a.active {
    border-left: none;
    border-right: 3px solid rgba(59, 130, 246, 0.6);
}
[dir="rtl"] .sidebar-menu a:hover {
    border-left-color: transparent;
    border-right-color: rgba(59, 130, 246, 0.5);
}
[dir="rtl"] .sidebar-menu a i {
    margin-right: 0;
    margin-left: 12px;
}
[dir="rtl"] .sidebar-expand-btn {
    right: auto;
    left: 8px;
}
[dir="rtl"] .sidebar-version {
    left: auto;
    right: 20px;
}
[dir="rtl"] .toggle-sidebar-label {
    margin-left: 0;
    margin-right: 6px;
}
[dir="rtl"] .header {
    flex-direction: row-reverse;
}
[dir="rtl"] .header-left {
    flex-direction: row-reverse;
}
[dir="rtl"] .header-right {
    flex-direction: row-reverse;
}
[dir="rtl"] .admin-notif-dropdown {
    right: auto;
    left: 0;
}
