/**
 * CSS Analyse Communale - Version Tableaux Organisés
 */

/* ========== CONTENEUR PRINCIPAL ========== */
.commune-analysis {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ========== HEADER ========== */
.commune-header {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    padding: 30px;
    border-radius: 16px;
    margin-bottom: 30px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.commune-header h2 {
    color: #f1f5f9;
    margin: 0 0 10px 0;
    font-size: 32px;
    font-weight: 700;
}

.commune-location {
    color: #94a3b8;
    margin: 0;
    font-size: 16px;
}

/* ========== SECTIONS ========== */
.section-sru,
.section-demo,
.section-logements,
.section-evolution {
    background: rgba(30, 41, 59, 0.95);
    padding: 30px;
    border-radius: 16px;
    margin-bottom: 30px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.section-sru h3,
.section-demo h3,
.section-logements h3,
.section-evolution h3 {
    color: #f1f5f9;
    margin: 0 0 24px 0;
    font-size: 24px;
    font-weight: 700;
    padding-bottom: 12px;
    border-bottom: 2px solid rgba(59, 130, 246, 0.6);
}

/* ========== TITRE SECTION SRU ========== */
.sru-section-title {
    color: #f1f5f9;
    margin: 0 0 24px 0;
    font-size: 24px;
    font-weight: 700;
    padding-bottom: 12px;
    border-bottom: 2px solid rgba(59, 130, 246, 0.6);
}

/* ========== CARTE HORS ZONE SRU ========== */
.sru-hors-zone-card {
    display: flex;
    gap: 20px;
    padding: 24px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2) 0%, rgba(37, 99, 235, 0.15) 100%);
    border: 2px solid rgba(59, 130, 246, 0.5);
    border-radius: 16px;
    margin-bottom: 20px;
}

.sru-hors-zone-icon {
    font-size: 48px;
    flex-shrink: 0;
}

.sru-hors-zone-content h3 {
    color: #93c5fd;
    margin: 0 0 12px 0;
    font-size: 20px;
    border: none;
    padding: 0;
}

.sru-hors-zone-content p {
    color: #cbd5e1;
    line-height: 1.6;
    margin: 0 0 12px 0;
}

.sru-hors-zone-note {
    color: #94a3b8;
    font-size: 14px;
    font-weight: 600;
}

/* ========== CARTE STATUT PRINCIPAL SRU ========== */
.sru-status-card {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 28px;
    border-radius: 16px;
    margin-bottom: 28px;
    border: 3px solid;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.sru-status-card.sru-status-ok {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2) 0%, rgba(5, 150, 105, 0.15) 100%);
    border-color: rgba(16, 185, 129, 0.5);
}

.sru-status-card.sru-status-deficit {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.2) 0%, rgba(220, 38, 38, 0.15) 100%);
    border-color: rgba(239, 68, 68, 0.5);
}

.sru-status-icon {
    font-size: 56px;
    flex-shrink: 0;
}

.sru-status-text {
    flex: 1;
}

.sru-status-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
}

.sru-status-ok .sru-status-title {
    color: #6ee7b7;
}

.sru-status-deficit .sru-status-title {
    color: #fca5a5;
}

.sru-status-description {
    color: #cbd5e1;
    font-size: 15px;
    line-height: 1.5;
}

/* ========== GRILLE DE CARTES SRU ========== */
.sru-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.sru-card {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2) 0%, rgba(37, 99, 235, 0.15) 100%);
    border: 2px solid rgba(59, 130, 246, 0.4);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.2);
}

.sru-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.3);
    border-color: rgba(59, 130, 246, 0.6);
}

.sru-card-warning {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.2) 0%, rgba(220, 38, 38, 0.15) 100%);
    border-color: rgba(239, 68, 68, 0.5);
}

.sru-card-prelevement {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2) 0%, rgba(217, 119, 6, 0.15) 100%);
    border-color: rgba(245, 158, 11, 0.5);
}

.sru-card-icon {
    font-size: 36px;
    flex-shrink: 0;
}

.sru-card-content {
    flex: 1;
    min-width: 0;
}

.sru-card-label {
    color: #94a3b8;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.sru-card-value {
    color: #93c5fd;
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 6px;
    line-height: 1.2;
}

.sru-card-value.value-ok {
    color: #6ee7b7;
}

.sru-card-value.value-deficit {
    color: #fca5a5;
}

.sru-card-value.value-money {
    color: #fcd34d;
}

.sru-card-sublabel {
    color: #64748b;
    font-size: 12px;
}

/* ========== INFOS COMPLÉMENTAIRES SRU ========== */
.sru-info-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
    padding: 16px;
    background: rgba(15, 23, 42, 0.6);
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.sru-info-item {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 250px;
}

.sru-info-icon {
    font-size: 18px;
}

.sru-info-label {
    color: #94a3b8;
    font-size: 14px;
    font-weight: 500;
}

.sru-info-value {
    color: #e2e8f0;
    font-size: 14px;
    font-weight: 600;
}

/* ========== BARRE DE PROGRESSION SRU ========== */
.sru-progress-container {
    background: rgba(15, 23, 42, 0.6);
    padding: 24px;
    border-radius: 16px;
    border: 2px solid rgba(148, 163, 184, 0.2);
    margin-bottom: 20px;
}

.sru-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.sru-progress-title {
    color: #e2e8f0;
    font-size: 16px;
    font-weight: 600;
}

.sru-progress-percent {
    color: #94a3b8;
    font-size: 14px;
}

.sru-progress-percent strong {
    color: #f1f5f9;
    font-size: 18px;
}

.sru-progress-bar {
    position: relative;
    height: 24px;
    background: rgba(148, 163, 184, 0.3);
    border-radius: 12px;
    overflow: visible;
    margin-bottom: 32px;
}

.sru-progress-fill {
    height: 100%;
    border-radius: 12px;
    transition: width 1s ease;
}

.sru-progress-fill.progress-ok {
    background: linear-gradient(90deg, #10b981 0%, #059669 100%);
}

.sru-progress-fill.progress-deficit {
    background: linear-gradient(90deg, #f97316 0%, #ea580c 100%);
}

.sru-progress-markers {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.sru-marker {
    position: absolute;
    top: 100%;
    transform: translateX(-50%);
    margin-top: 8px;
}

.sru-marker-label {
    display: block;
    padding: 4px 10px;
    background: #1e293b;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    white-space: nowrap;
}

.sru-marker-current .sru-marker-label {
    background: #3b82f6;
}

.sru-marker-target .sru-marker-label {
    background: #64748b;
}

.sru-progress-legend {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-top: 8px;
}

.sru-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #94a3b8;
    font-size: 13px;
}

.sru-legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.sru-legend-dot.current {
    background: #3b82f6;
}

.sru-legend-dot.target {
    background: #64748b;
}

/* ========== SOURCE SRU ========== */
.sru-source {
    text-align: center;
    padding: 12px;
    background: rgba(15, 23, 42, 0.6);
    border-radius: 8px;
    color: #94a3b8;
    font-size: 13px;
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.sru-source a {
    color: #60a5fa;
    text-decoration: none;
    font-weight: 600;
}

.sru-source a:hover {
    text-decoration: underline;
    color: #93c5fd;
}

/* ========== STATS DÉMOGRAPHIE - 2 COLONNES FIXES ========== */
.demo-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2) 0%, rgba(37, 99, 235, 0.15) 100%);
    padding: 32px;
    border-radius: 12px;
    text-align: center;
    border: 2px solid rgba(59, 130, 246, 0.4);
    transition: all 0.3s;
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.2);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(59, 130, 246, 0.3);
    border-color: rgba(59, 130, 246, 0.6);
}

.stat-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.stat-value {
    font-size: 36px;
    font-weight: 700;
    color: #93c5fd;
    margin-bottom: 8px;
}

.stat-label {
    color: #94a3b8;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.stat-trend {
    color: #6ee7b7;
    font-size: 14px;
    margin-top: 8px;
    font-weight: 600;
}

/* ========== PYRAMIDE DES ÂGES ========== */
.pyramide-ages {
    background: rgba(15, 23, 42, 0.6);
    padding: 24px;
    border-radius: 12px;
    margin-top: 30px;
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.pyramide-ages h4 {
    margin-top: 0;
    color: #e2e8f0;
    font-size: 18px;
    font-weight: 600;
}

/* ========== TABLEAU LOGEMENTS ========== */
.logements-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-bottom: 24px;
    background: rgba(15, 23, 42, 0.6);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.logements-table tr {
    border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.logements-table tr:last-child {
    border-bottom: none;
}

.logements-table td {
    padding: 20px 24px;
}

.logements-table .log-icon {
    font-size: 32px;
    text-align: center;
    width: 80px;
}

.logements-table .log-label {
    color: #94a3b8;
    font-size: 14px;
    font-weight: 600;
}

.logements-table .log-value {
    color: #e2e8f0;
    font-size: 24px;
    font-weight: 700;
    text-align: right;
}

/* ========== GRAPHIQUES ========== */
#pyramideAgesChart,
#logementsChart,
#evolutionChart {
    max-height: 400px;
    margin: 20px 0;
}

/* ========== MESSAGES ========== */
.info-message {
    background: rgba(59, 130, 246, 0.15);
    color: #93c5fd;
    padding: 16px 20px;
    border-radius: 8px;
    border-left: 4px solid #3b82f6;
    margin: 16px 0;
    font-size: 15px;
    font-weight: 500;
}

.note {
    color: #94a3b8;
    font-size: 13px;
    font-style: italic;
    margin-top: 12px;
}

.error-message {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    padding: 20px;
    border-radius: 12px;
    border-left: 4px solid #ef4444;
    text-align: center;
}

.error-message p {
    margin: 0;
    font-size: 16px;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .commune-analysis {
        padding: 15px;
    }
    
    .commune-header {
        padding: 20px;
    }
    
    .commune-header h2 {
        font-size: 24px;
    }
    
    .section-sru,
    .section-demo,
    .section-logements,
    .section-evolution {
        padding: 20px;
    }
    
    .demo-stats {
        grid-template-columns: 1fr;
    }
    
    .sru-table .sru-label,
    .sru-table .sru-value {
        display: block;
        width: 100%;
    }
    
    .stat-value,
    .log-value {
        font-size: 24px;
    }
    
    .sru-status-banner {
        flex-direction: column;
        text-align: center;
    }
}

/* ========== ANIMATIONS ========== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.commune-analysis > * {
    animation: fadeIn 0.5s ease-out;
}

.commune-analysis > *:nth-child(1) { animation-delay: 0.1s; }
.commune-analysis > *:nth-child(2) { animation-delay: 0.2s; }
.commune-analysis > *:nth-child(3) { animation-delay: 0.3s; }
.commune-analysis > *:nth-child(4) { animation-delay: 0.4s; }
.commune-analysis > *:nth-child(5) { animation-delay: 0.5s; }

/* ========== SECTION RPLS - STYLE SOMBRE ========== */
.section-rpls {
    background: rgba(30, 41, 59, 0.95) !important;
    padding: 30px !important;
    border-radius: 16px !important;
    margin-bottom: 30px !important;
    border: 1px solid rgba(148, 163, 184, 0.3) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3) !important;
}

.section-rpls h3 {
    color: #f1f5f9 !important;
    margin: 0 0 24px 0 !important;
    font-size: 24px !important;
    font-weight: 700 !important;
    padding-bottom: 12px !important;
    border-bottom: 2px solid rgba(139, 92, 246, 0.6) !important;
}

/* ===== 2 CARTES HORIZONTALES ===== */
.rpls-cards-row {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 20px !important;
    margin-bottom: 30px !important;
}

.rpls-card {
    display: flex !important;
    align-items: center !important;
    gap: 20px !important;
    padding: 24px 28px !important;
    border-radius: 12px !important;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2) 0%, rgba(124, 58, 237, 0.15) 100%) !important;
    border: 2px solid rgba(139, 92, 246, 0.4) !important;
    box-shadow: 0 2px 10px rgba(139, 92, 246, 0.2) !important;
}

.rpls-card-icon {
    font-size: 48px !important;
    line-height: 1 !important;
}

.rpls-card-content {
    flex: 1 !important;
}

.rpls-card-value {
    font-size: 2rem !important;
    font-weight: 700 !important;
    color: #c4b5fd !important;
    font-family: 'JetBrains Mono', monospace !important;
    line-height: 1.2 !important;
}

.rpls-card-label {
    color: #94a3b8 !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    margin-top: 4px !important;
}

.rpls-card-detail {
    color: #64748b !important;
    font-size: 12px !important;
    margin-top: 6px !important;
}

/* Carte Taux SRU - OK (vert) */
.rpls-card.taux-ok {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2) 0%, rgba(5, 150, 105, 0.15) 100%) !important;
    border-color: rgba(16, 185, 129, 0.5) !important;
    box-shadow: 0 2px 10px rgba(16, 185, 129, 0.2) !important;
}

.rpls-card.taux-ok .rpls-card-value {
    color: #6ee7b7 !important;
}

/* Carte Taux SRU - Déficit (orange) */
.rpls-card.taux-deficit {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2) 0%, rgba(217, 119, 6, 0.15) 100%) !important;
    border-color: rgba(245, 158, 11, 0.5) !important;
    box-shadow: 0 2px 10px rgba(245, 158, 11, 0.2) !important;
}

.rpls-card.taux-deficit .rpls-card-value {
    color: #fcd34d !important;
}

/* ===== GRAPHIQUE RPLS ===== */
.rpls-chart-wrapper {
    background: rgba(15, 23, 42, 0.6) !important;
    padding: 24px !important;
    border-radius: 12px !important;
    border: 1px solid rgba(148, 163, 184, 0.2) !important;
    margin-bottom: 30px !important;
    max-width: 500px !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

#rplsChart {
    max-width: 400px !important;
    margin: 0 auto !important;
}

/* ===== TITRE DU TABLEAU ===== */
.rpls-table-title {
    color: #e2e8f0 !important;
    font-size: 18px !important;
    font-weight: 600 !important;
    margin: 0 0 16px 0 !important;
}

/* ===== TABLEAU RPLS - STYLE STATS-TABLE ===== */
.rpls-table-container {
    overflow-x: auto !important;
    border-radius: 12px !important;
    background: rgba(15, 23, 42, 0.7) !important;
    border: 1px solid rgba(148, 163, 184, 0.2) !important;
}

.rpls-table {
    width: 100% !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    background: transparent !important;
    min-width: 500px !important;
}

/* En-tête violet */
.rpls-table thead {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%) !important;
}

.rpls-table th {
    color: #ffffff !important;
    font-weight: 600 !important;
    padding: 1rem 1.25rem !important;
    text-align: left !important;
    font-size: 0.9rem !important;
    border: none !important;
    background: transparent !important;
}

.rpls-table th.text-right {
    text-align: right !important;
}

/* Corps du tableau */
.rpls-table tbody {
    background: rgba(15, 23, 42, 0.4) !important;
}

.rpls-table td {
    padding: 0.875rem 1.25rem !important;
    border-bottom: 1px solid rgba(148, 163, 184, 0.15) !important;
    color: #e2e8f0 !important;
    vertical-align: middle !important;
    background: transparent !important;
}

.rpls-table td.text-right {
    text-align: right !important;
    font-family: 'JetBrains Mono', monospace !important;
}

/* Lignes de détail */
.rpls-row-item td {
    background: transparent !important;
    padding-left: 1.5rem !important;
    color: #cbd5e1 !important;
}

.rpls-row-item:hover td {
    background: rgba(139, 92, 246, 0.1) !important;
}

/* Pastille de couleur */
.rpls-color-dot {
    display: inline-block !important;
    width: 12px !important;
    height: 12px !important;
    border-radius: 50% !important;
    margin-right: 10px !important;
    vertical-align: middle !important;
    box-shadow: 0 0 8px currentColor !important;
}

/* Code de financement */
.rpls-code {
    color: #64748b !important;
    font-size: 11px !important;
    margin-left: 6px !important;
}

/* ===== LIGNES DE SOUS-TOTAL - MISE EN AVANT ===== */
.rpls-row-subtotal td {
    background: rgba(139, 92, 246, 0.18) !important;
    padding: 1rem 1.25rem !important;
    border-bottom: 2px solid rgba(139, 92, 246, 0.4) !important;
    color: #f1f5f9 !important;
}

.rpls-row-subtotal td:first-child {
    position: relative !important;
    padding-left: 1.5rem !important;
}

.rpls-subtotal-marker {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    width: 4px !important;
    border-radius: 0 2px 2px 0 !important;
}

.rpls-row-subtotal strong {
    color: #c4b5fd !important;
    font-size: 0.95rem !important;
}

.rpls-row-subtotal td.text-right {
    color: #c4b5fd !important;
    font-weight: 600 !important;
}

.rpls-group-desc {
    font-size: 11px !important;
    color: #94a3b8 !important;
    font-weight: normal !important;
    margin-top: 3px !important;
}

/* ===== LIGNE TOTAL ===== */
.rpls-row-total td {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%) !important;
    color: #ffffff !important;
    font-size: 1rem !important;
    padding: 1rem 1.25rem !important;
    border: none !important;
}

.rpls-row-total td strong {
    color: #ffffff !important;
}

/* ===== SOURCE RPLS ===== */
.rpls-source {
    margin-top: 16px !important;
    text-align: right !important;
    color: #94a3b8 !important;
    font-size: 12px !important;
}

/* ===== RESPONSIVE RPLS ===== */
@media (max-width: 768px) {
    .rpls-cards-row {
        grid-template-columns: 1fr !important;
    }

    .rpls-card {
        padding: 20px !important;
    }

    .rpls-card-value {
        font-size: 1.5rem !important;
    }

    .rpls-card-icon {
        font-size: 36px !important;
    }

    .rpls-table {
        font-size: 13px !important;
        min-width: 400px !important;
    }

    .rpls-table th,
    .rpls-table td {
        padding: 0.75rem 1rem !important;
    }

    .rpls-row-item td {
        padding-left: 1rem !important;
    }
}