/* ============================================
   MOBILE-FIRST RESPONSIVE DESIGN (27 nov 2025)
   Base styles for mobile, media queries for larger screens
   ============================================ */

/* Mobile-first base font size */
html {
    font-size: 14px;
}

@media (min-width: 768px) {
    html {
        font-size: 15px;
    }
}

@media (min-width: 1024px) {
    html {
        font-size: 16px;
    }
}

/* Variables CSS - Couleurs CEE */
:root {
    --primary-color: #00b4d5;     /* Bleu CEE principal */
    --primary-light: #003D7A;     /* Bleu CEE foncé (hover) */
    --success-color: #7ac043;     /* Vert Énergie */
    --success-dark: #5a9a2f;      /* Vert Énergie foncé */
    --warning-color: #d97706;
    --danger-color: #dc2626;
    --secondary-color: #6b7280;
    --light-bg: #f9fafb;
    --white: #ffffff;
    --border-color: #e5e7eb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-muted: #6b7280;        /* Same as text-secondary for compatibility */
    --bg-primary: #ffffff;        /* Background primary (white) */
    --bg-secondary: #f3f4f6;      /* Background secondary (light gray) */
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

/* Reset et base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: white;
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 0.875rem;
}

/* Header */
.header {
    background: var(--white);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-content {
    margin: 0;
    padding: 0 1rem;  /* Mobile first */
    display: flex;
    justify-content: flex-start;
    align-items: center;
}

@media (min-width: 1024px) {
    .header-content {
        padding: 0 2rem 0 calc(70px + 1rem);  /* Desktop avec sidebar */
    }
}

.header h1 {
    color: var(--primary-color);
    font-size: 1.25rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header h1 i {
    margin-right: 0.5rem;
}

/* Mobile: smaller header title to fit on one line */
@media (max-width: 768px) {
    .header h1 {
        font-size: 0.95rem;
    }

    .header h1 i {
        display: none;  /* Hide book icon on mobile */
    }
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--success-color);
    font-size: 0.875rem;
    font-weight: 500;
}

.status-indicator .fa-circle {
    font-size: 0.5rem;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Container principal - Mobile first */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

@media (min-width: 768px) {
    .container {
        padding: 1.25rem;
    }
}

/* Container full-width (sans padding latéral) */
.container-fullwidth {
    max-width: 100%;
    margin: 0;
    padding: 0;
}

/* Sections - Mobile first */
.section {
    background: var(--white);
    border-radius: 0;  /* Mobile: coins carrés */
    box-shadow: var(--shadow);
    overflow: hidden;
}

@media (min-width: 768px) {
    .section {
        border-radius: 8px;
    }
}

.section-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background: #f9fafb;
    color: #00b4d5;
}

.section-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: #00b4d5;
}

.section-header p {
    opacity: 0.7;
    font-size: 0.9rem;
    color: #000000;
}

/* Zone d'upload */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--light-bg);
}

.upload-zone:hover {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
}

.upload-zone.drag-over {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
    transform: scale(1.02);
}

.upload-content i {
    font-size: 2rem;
    color: var(--secondary-color);
    margin-bottom: 0.5rem;
}

.upload-content h3 {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.upload-content p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* Analyse des documents */
.document-analysis {
    padding: 2rem;
    border-top: 1px solid var(--border-color);
}

.document-analysis h3 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 600;
}

.document-category {
    margin-bottom: 2rem;
}

.document-category h4 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
}

.document-list {
    display: grid;
    gap: 1rem;
}

.document-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--white);
    transition: all 0.2s ease;
}

.document-item:hover {
    box-shadow: var(--shadow);
}

.document-item.attestation {
    border-left: 4px solid var(--success-color);
    background: rgba(5, 150, 105, 0.02);
}

.document-item.reference {
    border-left: 4px solid var(--primary-color);
    background: rgba(37, 99, 235, 0.02);
}

.document-item.uncategorized {
    border-left: 4px solid var(--warning-color);
    background: rgba(217, 119, 6, 0.02);
}

.document-icon {
    width: 3rem;
    height: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: white;
    font-size: 1.25rem;
}

.document-item.attestation .document-icon { background: var(--success-color); }
.document-item.reference .document-icon { background: var(--primary-color); }
.document-item.uncategorized .document-icon { background: var(--warning-color); }

.document-info {
    flex-grow: 1;
}

.document-name {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.document-meta {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.document-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.document-status.valid {
    color: var(--success-color);
}

.document-status.warning {
    color: var(--warning-color);
}

.document-status.info {
    color: var(--primary-color);
}

.no-documents {
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
    padding: 2rem;
    background: var(--light-bg);
    border-radius: 6px;
    margin: 0;
}

.add-more-section {
    margin-top: 2rem;
    text-align: center;
    padding: 1rem;
    border: 1px dashed var(--border-color);
    border-radius: 6px;
    background: var(--light-bg);
}

/* Barre d'actions - Mobile first */
.action-bar {
    padding: 1rem;
    background: var(--light-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;  /* Mobile: stack verticalement */
    gap: 1rem;
    text-align: center;
}

@media (min-width: 768px) {
    .action-bar {
        padding: 1.5rem 2rem;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        text-align: left;
    }
}

.action-info {
    font-weight: 500;
    color: var(--text-secondary);
}

.action-buttons {
    display: flex;
    flex-direction: column;  /* Mobile: boutons empilés */
    gap: 0.5rem;
    width: 100%;
}

@media (min-width: 768px) {
    .action-buttons {
        flex-direction: row;
        gap: 1rem;
        width: auto;
    }
}

.action-buttons .btn {
    width: 100%;
    justify-content: center;
}

@media (min-width: 768px) {
    .action-buttons .btn {
        width: auto;
    }
}

/* Boutons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    font-size: 0.875rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #1d4ed8;
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #4b5563;
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #047857;
}

/* Progression */
.global-progress {
    padding: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.progress-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
}

#global-percentage {
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--primary-color);
}

.progress-bar {
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), #3b82f6);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Progression des attestations */
.attestations-progress {
    padding: 2rem;
}

.attestation-item {
    margin-bottom: 2rem;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--white);
}

.attestation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.attestation-name {
    font-weight: 600;
    font-size: 1rem;
}

.attestation-status {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
}

.attestation-status.pending {
    background: rgba(107, 114, 128, 0.1);
    color: var(--secondary-color);
}

.attestation-status.running {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary-color);
}

.attestation-status.completed {
    background: rgba(5, 150, 105, 0.1);
    color: var(--success-color);
}

.attestation-progress {
    margin-bottom: 0.5rem;
}

.attestation-progress .progress-bar {
    height: 6px;
    margin-bottom: 0.5rem;
}

.current-step {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Barre de conformité par étape */
.conformity-bar {
    margin: 1rem 0;
}

.conformity-steps {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    position: relative;
    margin: 0 20px; /* Marge pour que les cercles ne débordent pas */
}

.conformity-steps::before {
    content: '';
    position: absolute;
    top: 12px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--border-color);
    z-index: 0;
}

.conformity-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    position: relative;
    z-index: 1;
    flex: 1;
}

.step-circle {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--border-color);
    border: 2px solid white;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.step-circle.pending {
    background: var(--border-color) !important;
}

.step-circle.high-conformity {
    background: var(--success-color) !important;
}

.step-circle.medium-conformity {
    background: #f59e0b !important; /* Orange */
}

.step-circle.low-conformity {
    background: var(--danger-color) !important;
}

.step-circle.in-progress {
    background: var(--primary-color) !important;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.step-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.2;
    max-width: 60px;
}

/* Résultats - Mobile first */
.summary-cards {
    display: grid;
    grid-template-columns: 1fr;  /* Mobile: stack verticalement */
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

@media (min-width: 768px) {
    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
        padding: 1.5rem;
    }
}

@media (min-width: 1024px) {
    .summary-cards {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        padding: 2rem;
    }
}

.summary-card {
    text-align: center;
    padding: 1.5rem;
    border-radius: 8px;
    background: var(--light-bg);
}

.summary-card.success { border-left: 4px solid var(--success-color); }
.summary-card.danger { border-left: 4px solid var(--danger-color); }
.summary-card.warning { border-left: 4px solid var(--warning-color); }
.summary-card.primary { border-left: 4px solid var(--primary-color); }

.summary-number {
    font-size: 2rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.summary-label {
    color: var(--text-secondary);
    font-weight: 500;
}

/* Table des résultats - Mobile first */
.results-table {
    padding: 1rem;
}

@media (min-width: 768px) {
    .results-table {
        padding: 2rem;
    }
}

/* Container scrollable pour tableaux sur mobile */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -1rem;
    padding: 0 1rem;
}

@media (min-width: 768px) {
    .table-responsive {
        margin: 0;
        padding: 0;
    }
}

.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    min-width: 500px;  /* Force scroll sur mobile si trop de colonnes */
}

@media (min-width: 768px) {
    .table {
        min-width: auto;
    }
}

.table th,
.table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    background: var(--light-bg);
    font-weight: 600;
}

.table tr:hover {
    background: rgba(0, 0, 0, 0.02);
}

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-badge.conforme {
    background: rgba(5, 150, 105, 0.1);
    color: var(--success-color);
}

.status-badge.non-conforme {
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger-color);
}

.status-badge.avec-reserves {
    background: rgba(217, 119, 6, 0.1);
    color: var(--warning-color);
}

/* Actions finales */
.final-actions {
    padding: 2rem;
    text-align: center;
    background: var(--light-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    background: var(--white);
    padding: 2rem;
    border-radius: 8px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.loading-spinner i {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--white);
    border-radius: 8px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--light-bg);
}

.modal-header h3 {
    color: var(--danger-color);
    font-size: 1.125rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    text-align: right;
    border-top: 1px solid var(--border-color);
    background: var(--light-bg);
}

/* Modal étendue pour les détails */
.large-modal {
    max-width: 800px;
    width: 95%;
}

.large-modal .modal-body {
    padding: 0;
    max-height: 70vh;
    overflow-y: auto;
}

/* Détails des étapes */
.steps-overview {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.steps-overview h4 {
    margin-bottom: 1rem;
    font-size: 1rem;
    font-weight: 600;
}

.steps-grid {
    display: grid;
    gap: 0.5rem;
}

.step-button {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--white);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    text-align: left;
    width: 100%;
}

.step-button:hover {
    background: var(--light-bg);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.step-button i {
    color: var(--text-secondary);
    transition: color 0.2s ease;
}

.step-button:hover i {
    color: var(--primary-color);
}

.step-detail-content {
    padding: 1.5rem;
    min-height: 200px;
}

.step-details h4 {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary-color);
    color: var(--primary-color);
    font-size: 1.125rem;
}

.step-summary {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
    padding: 1rem;
    background: var(--light-bg);
    border-radius: 6px;
}

.status-info, .score-info {
    font-weight: 500;
}

.status-info.conforme {
    color: var(--success-color);
}

.status-info.non_conforme {
    color: var(--danger-color);
}

.status-info.conforme_avec_reserves {
    color: var(--warning-color);
}

.controls-section,
.non-conformities-section,
.inconsistencies-section,
.observations-section {
    margin-bottom: 2rem;
}

.controls-section h5,
.non-conformities-section h5,
.inconsistencies-section h5,
.observations-section h5 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.controls-list {
    display: grid;
    gap: 0.5rem;
}

.control-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--light-bg);
    border-radius: 4px;
    font-size: 0.875rem;
}

.control-item i {
    margin-top: 0.1rem;
    flex-shrink: 0;
}

.text-success {
    color: var(--success-color);
}

.text-danger {
    color: var(--danger-color);
}

.control-value {
    color: var(--text-secondary);
    font-style: italic;
}

.non-conformities-list,
.inconsistencies-list,
.observations-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.non-conformity-item,
.inconsistency-item,
.observation-item {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border-left: 4px solid var(--danger-color);
    background: rgba(220, 38, 38, 0.05);
    border-radius: 0 4px 4px 0;
    font-size: 0.875rem;
    line-height: 1.4;
}

.inconsistency-item {
    border-left-color: var(--warning-color);
    background: rgba(217, 119, 6, 0.05);
}

.observation-item {
    border-left-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
}

.error-message {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: rgba(220, 38, 38, 0.1);
    border: 1px solid var(--danger-color);
    border-radius: 6px;
    color: var(--danger-color);
    font-weight: 500;
}

/* Boutons petits */
.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

/* Sections spécifiques aux agents */
.donnees-extraites-section,
.synthese-section,
.decision-finale-section,
.recommandations-section {
    margin-bottom: 2rem;
}

.donnees-extraites-section h5,
.synthese-section h5,
.decision-finale-section h5,
.recommandations-section h5 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.donnee-group {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--light-bg);
    border-radius: 6px;
    border-left: 4px solid var(--primary-color);
}

.donnee-group h6 {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    text-transform: uppercase;
}

.donnee-item {
    padding: 0.25rem 0;
    font-size: 0.875rem;
    border-bottom: 1px solid #e5e7eb;
}

.donnee-item:last-child {
    border-bottom: none;
}

.synthese-content {
    display: grid;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--light-bg);
    border-radius: 6px;
}

.decision-badge {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.875rem;
    text-align: center;
}

.decision-badge.conforme {
    background: rgba(5, 150, 105, 0.1);
    color: var(--success-color);
    border: 2px solid var(--success-color);
}

.decision-badge.conforme-avec-reserves {
    background: rgba(217, 119, 6, 0.1);
    color: var(--warning-color);
    border: 2px solid var(--warning-color);
}

.decision-badge.non-conforme {
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger-color);
    border: 2px solid var(--danger-color);
}

.recommandations-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.recommandation-item {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border-left: 4px solid var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
    border-radius: 0 4px 4px 0;
    font-size: 0.875rem;
    line-height: 1.4;
}