/* =========================================
   VARIABLES & DESIGN SYSTEM
   ========================================= */
:root {
    --primary: #2c3e50;
    --primary-light: #34495e;
    --accent: #3498db;
    --accent-hover: #2980b9;
    --bg-body: #f4f7f6;
    --bg-card: #ffffff;
    --text-main: #2c3e50;
    --text-muted: #7f8c8d;
    --border: #dcdde1;
    
    /* Status Colors */
    --color-success: #27ae60;
    --color-warning: #f39c12;
    --color-danger: #e74c3c;
    --color-info: #3498db;
    --color-gray: #95a5a6;

    /* Risk Levels */
    --risk-low: #27ae60;
    --risk-medium: #f1c40f;
    --risk-high: #e67e22;
    --risk-critical: #c0392b;

    --sidebar-width: 260px;
    --shadow: 0 4px 6px rgba(0,0,0,0.05);
    --radius: 8px;
    --transition: all 0.3s ease;
}

/* =========================================
   RESET & BASE
   ========================================= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    line-height: 1.6;
}

h1, h2, h3 { margin-bottom: 1rem; font-weight: 600; }
ul { list-style: none; }
a { text-decoration: none; color: inherit; }

/* =========================================
   LAYOUT (SIDEBAR & MAIN)
   ========================================= */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--primary);
    color: white;
    height: 100vh;
    position: fixed;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    z-index: 100;
}

.sidebar-header {
    padding-bottom: 2rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 2rem;
}

.sidebar-header h2 { font-size: 1.4rem; margin-bottom: 0.5rem; }

.badge {
    background: rgba(255,255,255,0.2);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    text-transform: uppercase;
}

.main-nav li { margin-bottom: 0.5rem; }

.main-nav a {
    display: block;
    padding: 0.8rem 1rem;
    border-radius: var(--radius);
    transition: var(--transition);
    font-size: 0.95rem;
    opacity: 0.8;
}

.main-nav a:hover, .main-nav a.active {
    background-color: var(--accent);
    opacity: 1;
    transform: translateX(5px);
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 2rem;
    max-width: calc(100vw - var(--sidebar-width));
}

/* =========================================
   PAGES & CARDS
   ========================================= */
.page {
    animation: fadeIn 0.4s ease-out;
    max-width: 1200px;
    margin: 0 auto;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.dashboard-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border-top: 4px solid var(--accent);
}

.wide-card { grid-column: 1 / -1; }
.highlight-card { background: linear-gradient(135deg, #ffffff 0%, #f0f9ff 100%); }
.alert-card { border-top-color: var(--color-danger); }

/* =========================================
   COMPONENTS (KPI, PROGRESS, BUTTONS)
   ========================================= */
.dashboard-value { font-size: 2.5rem; font-weight: bold; color: var(--primary); margin: 0.5rem 0; }

.progress-bar {
    background: #eee;
    height: 12px;
    border-radius: 6px;
    overflow: hidden;
    margin: 1rem 0;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    transition: width 1s ease-in-out;
}

.progress-fill.success { background: var(--color-success); }

.mini-kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 1rem;
    text-align: center;
}

.mini-kpi-grid div { display: flex; flex-direction: column; }
.mini-kpi-grid strong { font-size: 1.2rem; }
.mini-kpi-grid span { font-size: 0.75rem; color: var(--text-muted); }

button {
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

button#save, button#addExigenceBtn, button#addRisqueBtn, button#addActionBtn, button#saveAction {
    background-color: var(--color-success);
    color: white;
}

button#cancel { background-color: var(--color-gray); color: white; }
button#exportExcelBtn { background-color: #1d6f42; color: white; }
button#exportPdfBtn { background-color: #c0392b; color: white; }

button:hover { opacity: 0.9; transform: translateY(-1px); }
button:active { transform: translateY(0); }

/* =========================================
   TABLES & DATA
   ========================================= */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-top: 1.5rem;
}

.data-table th, .data-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th { background: #f8f9fa; font-weight: 600; text-transform: uppercase; font-size: 0.8rem; letter-spacing: 1px; }
.clickable-row:hover { background-color: #f0f7ff; cursor: pointer; }

/* Status Badges */
.status {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: capitalize;
}

.status-conforme { background: #d4edda; color: #155724; }
.status-partiellement-conforme { background: #fff3cd; color: #856404; }
.status-non-conforme { background: #f8d7da; color: #721c24; }
.status-non-applicable { background: #e2e3e5; color: #383d41; }

/* =========================================
   FORMS
   ========================================= */
.form-group { margin-bottom: 1.2rem; display: flex; flex-direction: column; }
.form-group label { margin-bottom: 0.5rem; font-weight: 600; font-size: 0.9rem; }
.form-group input, .form-group select, .form-group textarea {
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
}

.form-group textarea { min-height: 100px; resize: vertical; }

.checkbox-line { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; cursor: pointer; }
.checkbox-group { background: #f9f9f9; padding: 1rem; border-radius: var(--radius); max-height: 200px; overflow-y: auto; }

/* =========================================
   MATRICE DES RISQUES
   ========================================= */
.risk-matrix { border-collapse: separate; border-spacing: 5px; margin: 2rem 0; width: 100%; }
.matrix-axis { padding: 10px; background: var(--primary); color: white; border-radius: 4px; font-size: 0.8rem; text-transform: capitalize; text-align: center; }
.matrix-cell { width: 18%; height: 100px; border-radius: 4px; vertical-align: top; padding: 5px; transition: var(--transition); }

.matrix-low { background-color: #c8e6c9; }
.matrix-medium { background-color: #fff9c4; }
.matrix-high { background-color: #ffccbc; }

.matrix-risk {
    background: white;
    padding: 4px 8px;
    border-radius: 3px;
    margin-bottom: 4px;
    font-size: 0.75rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    cursor: pointer;
    border-left: 3px solid var(--accent);
}

.matrix-legend { display: flex; gap: 20px; margin-top: 1rem; }
.legend { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.legend::before { content: ""; width: 20px; height: 20px; border-radius: 3px; }
.legend.low::before { background: #c8e6c9; }
.legend.medium::before { background: #fff9c4; }
.legend.high::before { background: #ffccbc; }

/* =========================================
   SYNTHESE DIRECTION
   ========================================= */
.synthese-message {
    padding: 1.5rem;
    border-radius: var(--radius);
    margin-bottom: 2rem;
    font-weight: 600;
    font-size: 1.1rem;
    border-left: 6px solid;
}

.synthese-message.info { background: #e3f2fd; color: #0d47a1; border-color: #2196f3; }
.synthese-message.warning { background: #fff3e0; color: #e65100; border-color: #ff9800; }
.synthese-message.danger { background: #ffebee; color: #b71c1c; border-color: #f44336; }

.big-kpi { font-size: 3.5rem; font-weight: 800; color: var(--primary); line-height: 1; margin-bottom: 0.5rem; }

/* =========================================
   TOAST NOTIFICATIONS
   ========================================= */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
}

.toast {
    background: var(--primary);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    margin-bottom: 10px;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast.success { border-left: 5px solid var(--color-success); }
.toast.error { border-left: 5px solid var(--color-danger); }

/* =========================================
   PRINT / PDF STYLES
   ========================================= */
@media print {
    .no-print { display: none !important; }
    body { background: white; }
    .sidebar { display: none !important; }
    .main-content { margin-left: 0 !important; width: 100% !important; padding: 0 !important; }
    .dashboard-card, .data-table, .synthese-card { box-shadow: none !important; border: 1px solid #eee !important; }
    .status { border: 1px solid #ccc !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .matrix-cell { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}