/* =====================================================================
   GestInvoice — thème « Corporate clair »
   Chargé APRÈS les <style> de chaque page : il les remplace.
   ===================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --brand: #1a4f76;
    --brand-dark: #123854;
    --brand-soft: rgba(26, 79, 118, .10);
    --accent: #f39c12;

    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --muted: #64748b;

    --kpi-blue: #2563eb;
    --kpi-orange: #ea580c;
    --kpi-teal: #0d9488;
    --kpi-green: #16a34a;
    --kpi-red: #dc2626;
    --kpi-amber: #d97706;
    --kpi-slate: #475569;

    --sb-w: 248px;
    --sb-bg: #0f2a40;
    --sb-bg-2: #143654;
    --sb-text: #b6c6d6;

    --radius: 10px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow-md: 0 4px 14px rgba(15, 23, 42, .08);
    --font: 'Inter', 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Couleur de marque appliquée aux utilitaires Bootstrap « primary »
   (text-primary, bg-primary, badges, liens) */
:root {
    --bs-primary: #1a4f76;
    --bs-primary-rgb: 26, 79, 118;
    --bs-link-color: #1a4f76;
    --bs-link-color-rgb: 26, 79, 118;
    --bs-link-hover-color: #123854;
    --bs-link-hover-color-rgb: 18, 56, 84;
}

/* ---------- Base ---------- */
html { font-size: 15px; }
body {
    font-family: var(--font);
    background-color: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5, h6 { color: var(--text); letter-spacing: -.01em; }
a { color: var(--brand); }
.table, .summary-card, .stat-card, .text-end { font-variant-numeric: tabular-nums; }

/* ---------- Barre latérale ---------- */
.sidebar {
    position: fixed !important;
    top: 0; left: 0; bottom: 0;
    width: var(--sb-w);
    max-width: none;
    height: 100vh;
    padding: 0 !important;
    background: linear-gradient(180deg, var(--sb-bg) 0%, var(--sb-bg-2) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1030;
    transition: width .2s ease, left .25s ease;
}
.sidebar .sb-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 16px 14px 14px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    flex-shrink: 0;
}
.sidebar .sb-logo {
    width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--accent); color: #fff; font-size: .95rem;
}
.sidebar .sb-title { font-weight: 700; font-size: 1.05rem; color: #fff; white-space: nowrap; flex: 1; }
.sidebar .sb-toggle {
    border: 0; background: transparent; color: var(--sb-text);
    width: 30px; height: 30px; border-radius: 6px; flex-shrink: 0;
}
.sidebar .sb-toggle:hover { background: rgba(255, 255, 255, .08); color: #fff; }

.sidebar .sb-nav { flex: 1; overflow-y: auto; padding: 8px 10px 12px; scrollbar-width: thin; }
.sidebar .sb-section {
    font-size: .68rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
    color: rgba(182, 198, 214, .6);
    padding: 14px 10px 6px;
    white-space: nowrap;
}
.sidebar .sb-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px;
    margin: 1px 0;
    border-radius: 7px;
    border-left: 0;
    color: var(--sb-text);
    font-size: .9rem; font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
}
.sidebar .sb-nav a .icon { width: 18px; margin: 0; text-align: center; font-size: .92rem; opacity: .85; flex-shrink: 0; }
.sidebar .sb-nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; border-left: 0; }
.sidebar .sb-nav a.active {
    background: rgba(255, 255, 255, .12); color: #fff; border-left: 0;
    box-shadow: inset 3px 0 0 var(--accent);
}
.sidebar .sb-nav a.active .icon { color: var(--accent); opacity: 1; }

.sidebar .sb-user {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px;
    border-top: 1px solid rgba(255, 255, 255, .08);
    flex-shrink: 0;
}
.sidebar .sb-avatar {
    width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, .14); color: #fff; font-weight: 600; font-size: .8rem;
}
.sidebar .sb-user-info { flex: 1; min-width: 0; line-height: 1.2; }
.sidebar .sb-user-name { color: #fff; font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .sb-user-role { color: var(--sb-text); font-size: .74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .sb-user a.sb-logout {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; padding: 0; border-radius: 7px; border-left: 0;
    color: #fca5a5; font-size: .95rem; flex-shrink: 0;
}
.sidebar .sb-user a.sb-logout:hover { background: rgba(252, 165, 165, .12); color: #fecaca; border-left: 0; }

/* Menu replié (icônes seules) — grand écran uniquement */
@media (min-width: 769px) {
    body.sb-collapsed { --sb-w: 68px; }
    body.sb-collapsed .sidebar .nav-label,
    body.sb-collapsed .sidebar .sb-logo { display: none; }
    body.sb-collapsed .sidebar .sb-brand { justify-content: center; padding-left: 14px; }
    body.sb-collapsed .sidebar .sb-toggle i { transform: rotate(180deg); }
    body.sb-collapsed .sidebar .sb-section { font-size: 0; padding: 10px 0 4px; }
    body.sb-collapsed .sidebar .sb-section::after { content: ''; display: block; height: 1px; margin: 0 8px; background: rgba(255, 255, 255, .10); }
    body.sb-collapsed .sidebar .sb-nav a { justify-content: center; padding: 10px 0; }
    body.sb-collapsed .sidebar .sb-nav a .icon { font-size: 1.02rem; }
    body.sb-collapsed .sidebar .sb-user { flex-direction: column; padding: 10px 0; gap: 6px; }
}

/* ---------- Zone de contenu ---------- */
.main-content {
    flex: 0 0 auto;
    margin-left: var(--sb-w);
    width: calc(100% - var(--sb-w));
    max-width: none;
    min-height: 100vh;
    padding: 24px 28px 40px;
    transition: margin-left .2s ease, width .2s ease;
}

/* En-tête de page */
.navbar-custom {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    padding: 0 0 16px;
    margin-bottom: 22px;
    border-bottom: 1px solid var(--border);
}
.navbar-custom.bg-white { background-color: transparent !important; }   /* factures.php */
.navbar-custom h2 { font-size: 1.35rem; font-weight: 600; margin: 0 !important; }
.navbar-custom h2 i { color: var(--brand); font-size: 1.1rem; }
.navbar-custom > div { display: flex; flex-wrap: wrap; gap: 8px; }
.navbar-custom h2.text-warning { color: var(--text) !important; }   /* editer_facture.php */
.navbar-custom h2.text-warning i { color: var(--accent); }

/* Sous-titre de section dans une page */
.section-title { font-size: 1rem; font-weight: 600; color: var(--text); }

/* ---------- Cartes KPI ---------- */
.summary-card, .stat-card {
    --kpi: var(--brand);
    position: relative;
    background: var(--surface) !important;
    color: var(--text) !important;
    border: 1px solid var(--border);
    border-top: 4px solid var(--kpi);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 16px 18px;
    margin-bottom: 20px;
}
.summary-card h6, .stat-card p {
    font-size: .72rem !important; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
    color: var(--muted); opacity: 1 !important; margin-bottom: 10px !important;
}
.summary-card .d-flex { gap: 10px; align-items: baseline; font-size: .84rem; line-height: 1.35; margin-bottom: 2px; }
.row > [class*="col"] > .summary-card { height: calc(100% - 20px); }   /* cartes d'une même ligne à hauteur égale */
.summary-card .d-flex > span:last-child { white-space: nowrap; margin-left: auto; font-weight: 600; }
.summary-card .fs-3, .summary-card .fs-4 { font-size: 1.45rem !important; color: var(--kpi); white-space: nowrap; }
.summary-card .fs-3 small, .summary-card .fs-4 small { color: var(--muted); font-size: .8rem !important; font-weight: 500; }
.summary-card .small, .summary-card .opacity-75 { color: var(--muted); opacity: 1 !important; }
.summary-card hr { border-color: var(--border); opacity: 1; margin: 10px 0 !important; }
.stat-card h3 { font-size: 1.5rem !important; font-weight: 700; color: var(--text); white-space: nowrap; }
.stat-card .stat-icon { color: var(--kpi); opacity: .18; font-size: 1.9rem; top: 16px; right: 18px; }

.bg-facture, .bg-blue, .kpi-blue       { --kpi: var(--kpi-blue); }
.bg-ras, .kpi-orange                   { --kpi: var(--kpi-orange); }
.kpi-teal                              { --kpi: var(--kpi-teal); }
.bg-net, .bg-green, .kpi-green         { --kpi: var(--kpi-green); }
.bg-avoir, .kpi-red                    { --kpi: var(--kpi-red); }
.bg-yellow, .kpi-amber                 { --kpi: var(--kpi-amber); }
.stat-card.bg-dark, .kpi-slate         { --kpi: var(--kpi-slate); }

/* ---------- Tableaux ---------- */
.table-custom {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.table-responsive.table-custom { overflow: auto; }   /* annule l'overflow:hidden des pages */
.table-custom .table { margin-bottom: 0; }
.table-custom .table, .card .table { font-size: .9rem; }
.table td.text-end { white-space: nowrap; }   /* un montant ne se coupe jamais */
.table .btn, .table .badge { white-space: nowrap; }
.table-custom td.text-primary, .table-custom td.doc-number { white-space: nowrap; }   /* n° de document */
.table > thead.table-light th, .card .table > thead th {
    background-color: #f8fafc;
    color: var(--muted);
    font-size: .72rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}
.price-tag { color: var(--text); font-weight: 600; }   /* services.php */
.table-custom thead th {
    background-color: #f8fafc;
    color: var(--muted);
    font-size: .72rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
    white-space: nowrap;
    vertical-align: bottom;
}
.table-custom tbody td { padding: 9px 12px; vertical-align: middle; border-color: var(--border); }
.table-custom tbody tr:last-child td { border-bottom: 0; }

/* Zone à hauteur limitée : barre de défilement toujours visible + en-tête fixe */
.table-scroll { max-height: calc(100vh - 170px); scrollbar-color: #94a3b8 #f1f5f9; }
.table-responsive::-webkit-scrollbar { height: 11px; width: 11px; }
.table-responsive::-webkit-scrollbar-track { background: #f1f5f9; }
.table-responsive::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 6px; border: 2px solid #f1f5f9; }
.table-responsive::-webkit-scrollbar-thumb:hover { background: #64748b; }
.table-scroll thead th { position: sticky; top: 0; z-index: 2; }

/* Tableau dense (rapports financiers) */
.table-dense { font-size: .82rem; }
.table-dense thead th { white-space: normal; padding: 8px 8px; line-height: 1.25; }
.table-dense tbody td { padding: 7px 8px; }
.table-dense td.text-end, .table-dense td:first-child, .table-dense td.fw-bold { white-space: nowrap; }

/* Lignes d'avoir */
.avoir-row td { color: #b91c1c; background-color: #fef2f2 !important; }

/* ---------- Composants Bootstrap ---------- */
.card, .card-custom {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    background-color: var(--surface);
    color: var(--text);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}
.btn { border-radius: 8px; font-weight: 500; font-size: .875rem; }
.btn-primary {
    --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-dark); --bs-btn-hover-border-color: var(--brand-dark);
    --bs-btn-active-bg: var(--brand-dark); --bs-btn-active-border-color: var(--brand-dark);
    --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-hover-color: #fff;
    --bs-btn-active-bg: var(--brand-dark); --bs-btn-active-border-color: var(--brand-dark); --bs-btn-active-color: #fff;
}
.btn-sm { border-radius: 6px; }
.d-flex > .btn, .d-flex > a.btn { white-space: nowrap; flex-shrink: 0; }   /* boutons à côté d'un titre */
.modal-title { font-weight: 600; font-size: 1.05rem; }

/* Libellés de formulaire : une seule couleur (les pages mélangeaient bleu / vert / rouge) */
.form-label.text-primary, .form-label.text-success, .form-label.text-danger, .form-label.text-warning { color: #334155 !important; }
.form-label i { color: var(--muted); }

/* Bloc des totaux (creer_facture.php / editer_facture.php) */
.totals-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 16px 18px;
    font-size: .92rem;
}
.totals-box .tax-line { color: var(--muted); border-bottom: 1px dashed var(--border); padding: 4px 0; margin-bottom: 4px; }
.totals-box .tax-negative { color: #b91c1c; }
.totals-box .grand-total {
    font-size: 1.3rem; font-weight: 700; color: var(--brand);
    border-top: 2px solid var(--border); margin-top: 10px; padding-top: 10px;
}
.form-control, .form-select { border-color: var(--border-strong); border-radius: 8px; font-size: .9rem; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-label { font-weight: 500; font-size: .85rem; color: #334155; }
.badge { font-weight: 600; border-radius: 6px; padding: .38em .6em; }
.alert { border-radius: 8px; }
.modal-content { border: 0; border-radius: 12px; box-shadow: var(--shadow-md); }
.dropdown-menu { border-color: var(--border); border-radius: 8px; box-shadow: var(--shadow-md); font-size: .9rem; }

/* ---------- Onglets (parametres.php) ---------- */
.settings-tabs { border-bottom: 1px solid var(--border); gap: 4px; }
.settings-tabs .nav-link {
    color: var(--muted); font-weight: 500; font-size: .9rem;
    border: 0; border-bottom: 2px solid transparent; border-radius: 0;
    padding: 10px 14px; margin-bottom: -1px; background: transparent;
}
.settings-tabs .nav-link:hover { color: var(--text); border-bottom-color: var(--border-strong); }
.settings-tabs .nav-link.active { color: var(--brand); border-bottom-color: var(--brand); background: transparent; }

/* Aperçu du calcul d'une taxe (parametres.php) */
.tax-actions .btn { white-space: nowrap; }
.calc-preview {
    background: #f8fafc;
    border: 1px dashed var(--border-strong);
    border-radius: 8px;
    padding: 12px 14px;
}
.calc-preview code, .form-text code.js-formula {
    color: var(--brand); background: #fff;
    border: 1px solid var(--border); border-radius: 6px;
    padding: 2px 8px; font-size: .85rem;
}
.sim-ht { width: 130px; }
.sim-table { font-size: .85rem; background: transparent; }
.sim-table td { padding: 4px 8px; background: transparent; }
.sim-table td:last-child { white-space: nowrap; }
.sim-table tr.sim-total td { font-weight: 600; border-top: 1px solid var(--border); }
.sim-table tr.sim-net td { color: var(--brand); font-weight: 700; }
.sim-table tr.sim-new td { background-color: rgba(243, 156, 18, .14) !important; font-weight: 600; }

/* ---------- Import de factures fournisseurs (achats_import.php) ---------- */
.imp-drop {
    display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
    border: 2px dashed var(--border-strong); border-radius: var(--radius);
    background: #f8fafc; color: var(--muted);
    padding: 26px 16px; cursor: pointer; transition: background .15s, border-color .15s;
}
.imp-drop:hover, .imp-drop.is-over { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.imp-card .form-label { font-size: .75rem; margin-bottom: 2px; }
.imp-thumb { width: 160px; flex-shrink: 0; text-align: center; }
.imp-thumb-box { border: 1px solid var(--border); border-radius: 6px; background: #fff; min-height: 90px; overflow: hidden; margin-bottom: 4px; }
.imp-thumb-box canvas, .imp-thumb-box img { display: block; width: 100%; height: auto; }
.imp-body { min-width: 0; }
.imp-card .is-guess { border-color: var(--accent); background-color: #fffbeb; }
.imp-card.imp-done { opacity: .75; border-color: #86efac; }
.imp-lp, .lp-box { color: var(--text); }
.lp-box:empty { display: none; }
.lp-box { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
@media (max-width: 768px) { .imp-thumb { width: 100%; } .imp-thumb-box { max-width: 220px; margin: 0 auto 4px; } }

/* ---------- Page de connexion ---------- */
.login-card { border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-md); overflow: hidden; }
.login-card .card-header {
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: #fff; border-bottom: 0; padding: 26px 20px;
}
.login-card .card-header h3 { color: #fff; font-weight: 700; }

/* ---------- Mobile ---------- */
.mobile-menu-btn { display: none; }
@media (max-width: 768px) {
    .sidebar { width: 264px !important; left: -280px !important; box-shadow: var(--shadow-md); }
    .sidebar.open { left: 0 !important; }
    .sidebar .sb-toggle { display: none; }
    .main-content { margin-left: 0 !important; width: 100% !important; max-width: 100% !important; padding: 12px !important; }
    .navbar-custom { padding: 0 0 12px !important; border-radius: 0 !important; }
    .navbar-custom h2 { font-size: 1.1rem !important; }
    .mobile-menu-btn {
        display: inline-flex !important; align-items: center; justify-content: center;
        background: var(--brand); color: #fff; border: 0; border-radius: 8px;
        width: 38px; height: 38px; margin-right: 8px;
    }
    .mobile-overlay { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 1029; }
    .mobile-overlay.open { display: block; }
    .table-scroll { max-height: none; }
}

/* ---------- Impression ---------- */
@media print {
    .sidebar, .mobile-menu-btn, .mobile-overlay, .navbar-custom .btn, form .btn { display: none !important; }
    .main-content { margin: 0 !important; width: 100% !important; padding: 0 !important; }
    .table-responsive, .table-scroll { max-height: none !important; overflow: visible !important; }
    body { background: #fff; }
}
