/* Page */
@page {
    size: A4;
    margin: 14mm;
}

html, body {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    width: 100%;
    height: auto;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 12.5px;
    color: #111827;
    line-height: 1.35;
    background: #ffffff;
    padding: 10px;
}

/* Couleurs harmonisées */
:root {
    --primary-color: #007f3f;       /* Vert Sénégal (étoile) */
    --primary-light: #e6f4ec;       /* Vert très clair pour fonds */
    --secondary-color: #f4c300;     /* Jaune Sénégal (bande centrale) */
    --secondary-light: #fff9e5;     /* Jaune très clair pour surlignage */
    --accent-color: #d11d1d;        /* Rouge Sénégal (bande droite) */
    --accent-light: #faeaea;
    --success-color: #10c469;       /* Succès (inchangé) */
    --warning-color: #f59e0b;       /* Alerte (inchangé) */
    --danger-color: #ef4444;        /* Erreur (inchangé) */
    --light-bg: #f8fafc;            /* Fond général */
    --lighter-bg: #f1f5f9;
    --border-color: #e2e8f0;
    --border-dark: #cbd5e1;
    --text-color: #111827;
    --text-muted: #64748b;
    --text-light: #94a3b8;
}

/* Titres & textes */
h1, h2, h3, h4, h5, h6 {
    margin: 0.4rem 0;
    color: var(--text-color);
    font-weight: 600;
}

h1 {
    font-size: 19px;
    color: var(--primary-color);
}

h2 {
    font-size: 16px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}

h3 { font-size: 14px; }
h4 { font-size: 13px; }

.muted { color: var(--text-muted); }
.small { font-size: 11px; }
.section { margin-top: 16px; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }
.center { text-align: center; }

/* Cartes modernisées */
.card {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    background: #fff;
    page-break-inside: avoid;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* Tableaux améliorés */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 11.5px;
}

th, td {
    border: 1px solid var(--border-color);
    padding: 8px;
    vertical-align: top;
}

thead th {
    background: var(--lighter-bg);
    text-align: left;
    font-weight: 600;
    color: var(--text-color);
}

tbody tr:nth-child(even) {
    background: var(--light-bg);
}

/* Barre de progression */
.progress {
    width: 100%;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.progress > span {
    display: block;
    height: 100%;
    background: var(--primary-color);
    border-radius: 4px;
}

/* ===== Layout compatible ===== */

/* Conteneur à 2 colonnes */
.cols-2:after {
    content: "";
    display: table;
    clear: both;
}

.cols-2 .col {
    float: left;
    width: 49%;
}

.cols-2 .col + .col {
    margin-left: 2%;
}

/* Conteneur à 3 colonnes */
.cols-3:after {
    content: "";
    display: table;
    clear: both;
}

.cols-3 .col {
    float: left;
    width: 32%;
}

.cols-3 .col + .col {
    margin-left: 2%;
}

/* Conteneur à 4 colonnes */
.cols-4:after {
    content: "";
    display: table;
    clear: both;
}

.cols-4 .col {
    float: left;
    width: 23.5%;
}

.cols-4 .col + .col {
    margin-left: 2%;
}

/* Rangée horizontale */
.row {
    margin-bottom: 12px;
}

.row:last-child {
    margin-bottom: 0;
}

.row > * {
    display: inline-block;
    vertical-align: middle;
    margin-right: 12px;
}

.row > *:last-child {
    margin-right: 0;
}

/* ===== Brand header amélioré ===== */
.brandbar {
    background: linear-gradient(90deg, var(--primary-light), #ffffff);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand-left {
    display: flex;
    align-items: center;
}

.brand-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--primary-color);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    margin-right: 12px;
    flex-shrink: 0;
}

.brand-title {
    line-height: 1.2;
}

.brand-title div:first-child {
    font-weight: 700;
    color: var(--primary-color);
}

.pill {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid var(--border-color);
    background: var(--light-bg);
    color: var(--text-muted);
}

/* Insights */
.insights:after {
    content: "";
    display: table;
    clear: both;
}

.insights .left, .insights .right {
    float: left;
    width: 48%;
}

.insights .right {
    margin-left: 4%;
}

.insight-row {
    margin-bottom: 12px;
}

.insight-row:last-child {
    margin-bottom: 0;
}

.insight-row > * {
    display: inline-block;
    vertical-align: middle;
    margin-right: 16px;
}

.insight-row > *:last-child {
    margin-right: 0;
}

.chip {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    background: var(--primary-light);
    border: 1px solid var(--border-color);
    color: var(--primary-color);
    font-weight: 500;
}

.k-sep {
    height: 1px;
    background: var(--border-color);
    margin: 12px 0;
}

/* Ruban latéral */
.ribbon {
    position: relative;
    border-left: 4px solid var(--primary-color);
    padding-left: 12px;
    margin-bottom: 12px;
}

/* Composantes et activités - Version compatible */
.composante-card {
    background: white;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid var(--border-color);
    page-break-inside: avoid;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.composante-header {
    margin-bottom: 16px;
}

.composante-info {
    margin-bottom: 12px;
}

.composante-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary-color);
    margin: 0 0 8px 0;
}

.composante-meta {
    color: var(--text-muted);
    font-size: 11.5px;
    line-height: 1.4;
}

.composante-stats {
    margin: 12px 0;
}

.stat-badge {
    display: inline-block;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 11px;
    background: var(--light-bg);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    margin-right: 8px;
    margin-bottom: 8px;
}

.stat-badge:last-child {
    margin-right: 0;
}

.activities-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

/* Grille d'activités compatible */
.activities-container {
    margin-top: 12px;
}

.activity-row {
    margin-bottom: 12px;
}

.activity-row:after {
    content: "";
    display: table;
    clear: both;
}

.activity-col {
    float: left;
    width: 48%;
    margin-right: 4%;
}

.activity-col:nth-child(2n) {
    margin-right: 0;
}

.activity-card {
    background: var(--light-bg);
    padding: 12px;
    border-radius: 6px;
    border-left: 3px solid var(--primary-color);
    height: 100%;
    page-break-inside: avoid;
}

.activity-title {
    font-weight: 600;
    margin: 0 0 8px 0;
    color: var(--text-color);
    font-size: 12px;
}

.activity-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 8px;
    line-height: 1.3;
}

.progress-container {
    background: var(--border-color);
    border-radius: 4px;
    height: 6px;
    margin: 8px 0;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--success-color);
    border-radius: 4px;
}

.activity-status {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 500;
    margin-top: 4px;
}

.status-completed {
    background: #dcfce7;
    color: #166534;
}

.status-in-progress {
    background: #ffedd5;
    color: #9a3412;
}

.status-planned {
    background: var(--light-bg);
    color: var(--text-muted);
}

.status-delayed {
    background: #fee2e2;
    color: #b91c1c;
}

/* Légende */
.legend-item {
    display: inline-block;
    margin-right: 12px;
    margin-bottom: 8px;
    font-size: 11px;
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    margin-right: 4px;
    display: inline-block;
    vertical-align: middle;
}

/* Utilitaires */
.text-success { color: var(--success-color); }
.text-warning { color: var(--warning-color); }
.text-danger { color: var(--danger-color); }
.text-primary { color: var(--primary-color); }

.bg-success { background: #dcfce7; }
.bg-warning { background: #ffedd5; }
.bg-danger { background: #fee2e2; }
.bg-primary { background: var(--primary-light); }

/* Ruptures de page */
.pb-avoid {
    page-break-inside: avoid;
}

.page-break {
    page-break-before: always;
}

/* Media print */
@media print {
    body {
        margin: 0;
        padding: 0;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .card,
    .composante-card,
    .activity-card {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .brandbar {
        background: #f8fafc !important;
    }

    /* Éviter les coupures dans les titres */
    h1, h2, h3, h4 {
        page-break-after: avoid;
    }
}

/* Fallback pour flexbox si nécessaire */
.flex-container {
    display: block;
}

.flex-container > * {
    display: inline-block;
    vertical-align: top;
}

/* Espacements cohérents */
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }

.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }

.p-1 { padding: 4px; }
.p-2 { padding: 8px; }
.p-3 { padding: 12px; }
.p-4 { padding: 16px; }


/* Styles spécifiques pour le Gantt */
.gantt-container {
    margin: 15px 0;
    padding: 10px;
    background: var(--light-bg);
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.gantt-period {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 11px;
    color: var(--text-muted);
}

.gantt-track {
    height: 20px;
    background: #e2e8f0;
    border-radius: 10px;
    position: relative;
    overflow: hidden;
    margin: 5px 0;
}

.gantt-bar {
    position: absolute;
    height: 100%;
    background: var(--primary-color);
    border-radius: 10px;
    min-width: 4px;
}

.gantt-milestone {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--danger-color);
    border-radius: 50%;
    top: 4px;
    transform: translateX(-50%);
}

.gantt-today {
    position: absolute;
    width: 2px;
    height: 24px;
    background: var(--danger-color);
    top: -2px;
    transform: translateX(-50%);
}

.gantt-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 5px;
    font-size: 10px;
    color: var(--text-muted);
}

.gantt-activity {
    margin: 8px 0;
    font-size: 11px;
}

.gantt-activity-name {
    font-weight: 600;
    margin-bottom: 2px;
}

.gantt-activity-dates {
    color: var(--text-muted);
    font-size: 10px;
}