/* Fiches (demande d'accès, étude, travaux, DOE, conventionnement) : badge de statut, avatar, libellés */

.fiche-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border-radius: 9px;
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.fiche-status-pill .fiche-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.fiche-status-pill.status-warning { background: #FFFBEB; border: 1.5px solid #FDE68A; color: #92400E; }
.fiche-status-pill.status-warning .fiche-status-dot { background: #D97706; }

.fiche-status-pill.status-success { background: #F0FDF4; border: 1.5px solid #BBF7D0; color: #166534; }
.fiche-status-pill.status-success .fiche-status-dot { background: #16A34A; }

.fiche-status-pill.status-danger { background: #FEF2F2; border: 1.5px solid #FECACA; color: #991B1B; }
.fiche-status-pill.status-danger .fiche-status-dot { background: #DC2626; }

.fiche-status-pill.status-secondary { background: #F8FAFC; border: 1.5px solid #E2E8F0; color: #475569; }
.fiche-status-pill.status-secondary .fiche-status-dot { background: #94A3B8; }

.fiche-status-pill.status-info { background: #ECFEFF; border: 1.5px solid #A5F3FC; color: #155E75; }
.fiche-status-pill.status-info .fiche-status-dot { background: #0891B2; }

.fiche-field-label {
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: #94A3B8;
    display: block;
}

.fiche-org-avatar {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    object-fit: contain;
    background: #F1F5F9;
}

/* ===== Dark Mode ===== */
[data-bs-theme="dark"] .fiche-status-pill.status-warning { background: #664d03; border-color: #ffc107; color: #fff3cd; }
[data-bs-theme="dark"] .fiche-status-pill.status-warning .fiche-status-dot { background: #ffc107; }

[data-bs-theme="dark"] .fiche-status-pill.status-success { background: #0f5132; border-color: #198754; color: #d1e7dd; }
[data-bs-theme="dark"] .fiche-status-pill.status-success .fiche-status-dot { background: #198754; }

[data-bs-theme="dark"] .fiche-status-pill.status-danger { background: #842029; border-color: #dc3545; color: #f8d7da; }
[data-bs-theme="dark"] .fiche-status-pill.status-danger .fiche-status-dot { background: #dc3545; }

[data-bs-theme="dark"] .fiche-status-pill.status-secondary { background: #495057; border-color: #6c757d; color: #dee2e6; }
[data-bs-theme="dark"] .fiche-status-pill.status-secondary .fiche-status-dot { background: #adb5bd; }

[data-bs-theme="dark"] .fiche-status-pill.status-info { background: #055160; border-color: #0dcaf0; color: #cff4fc; }
[data-bs-theme="dark"] .fiche-status-pill.status-info .fiche-status-dot { background: #0dcaf0; }

[data-bs-theme="dark"] .fiche-field-label {
    color: #adb5bd;
}

[data-bs-theme="dark"] .fiche-org-avatar {
    background: #2b3035;
}

/* ===== Tracé demandé (départ A, arrivée B) ===== */
.trace-demande-pastille,
.trace-demande-marqueur {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #fff;
    font-weight: 700;
}

.trace-demande-pastille {
    width: 20px;
    height: 20px;
    font-size: 11px;
}

.trace-demande-marqueur {
    font-size: 13px;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

/* Leaflet pose .leaflet-marker-icon (display: block), chargé après cette feuille :
   sans cette règle plus précise, la lettre n'est plus centrée dans le marqueur. */
.leaflet-marker-icon.trace-demande-marqueur {
    display: flex;
    box-sizing: border-box;
    line-height: 1;
}

.trace-demande-pastille--depart,
.trace-demande-marqueur--depart { background: #16a34a; }

.trace-demande-pastille--arrivee,
.trace-demande-marqueur--arrivee { background: #dc2626; }

.trace-demande-recherche {
    position: relative;
}

/* La liste passe au-dessus de la carte, isolée dans son propre contexte d'empilement. */
.trace-demande-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 10;
    margin-top: 2px;
    max-height: 240px;
    overflow-y: auto;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
}

.trace-demande-suggestion {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
}

.trace-demande-suggestion:hover,
.trace-demande-suggestion.active {
    background: var(--bs-tertiary-bg);
}

.trace-demande-carte {
    position: relative;
    isolation: isolate;
    height: 480px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--bs-border-color);
}

.trace-demande-carte--modifiable .leaflet-container {
    cursor: crosshair;
}

/* Tuiles hors zone traversées par le tracé : les propriétés CSS l'emportent sur les attributs SVG de Leaflet. */
.trace-demande-tuile-hors-zone {
    stroke: #d97706;
    fill: #f59e0b;
    fill-opacity: 0.15;
}

[data-bs-theme="dark"] .trace-demande-tuile-hors-zone {
    stroke: #fbbf24;
    fill: #fbbf24;
    fill-opacity: 0.2;
}

/* Tuile hors zone que l'opérateur peut découvrir : survol plus marqué, sélection en vert comme sur la carte principale. */
.trace-demande-tuile-hors-zone--selectionnable {
    cursor: pointer;
    transition: fill-opacity 0.15s ease, stroke-width 0.15s ease;
}

.trace-demande-tuile-hors-zone--selectionnable:hover {
    fill-opacity: 0.35;
    stroke-width: 3;
}

.trace-demande-tuile-hors-zone--selectionnee,
[data-bs-theme="dark"] .trace-demande-tuile-hors-zone--selectionnee {
    stroke: #10b981;
    fill: #10b981;
    fill-opacity: 0.45;
    stroke-dasharray: none;
    stroke-width: 3;
}

.trace-demande-tuile-hors-zone--selectionnee:hover {
    fill-opacity: 0.6;
}

@media (max-width: 575.98px) {
    .trace-demande-carte {
        height: 320px;
    }
}

/* ===== Tracé Routing (résultat du calcul) ===== */
.trace-routing-carte {
    position: relative;
    isolation: isolate;
    height: 480px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--bs-border-color);
}

/* Trait de couleur d'une étape (légende, tableau) ; tireté gris pour les raccordements. */
.trace-routing-trait {
    display: inline-block;
    flex-shrink: 0;
    width: 18px;
    height: 4px;
    border-radius: 2px;
    /* Liseré aux couleurs du thème : garde visibles les teintes proches du fond de la carte (#1e293b en sombre) */
    box-shadow: 0 0 0 1px var(--bs-border-color);
}

.trace-routing-trait--raccordement {
    background: repeating-linear-gradient(90deg, #64748b 0 4px, transparent 4px 7px);
    /* Le pointillé encadré se lirait comme un trait plein */
    box-shadow: none;
}

.trace-routing-etapes {
    min-width: 520px;
}

.trace-routing-etapes td,
.trace-routing-etapes th {
    white-space: nowrap;
}

/* Le libellé d'étape peut passer à la ligne, les nombres jamais. */
.trace-routing-etapes td:nth-child(2) {
    white-space: normal;
    min-width: 160px;
}

@media (max-width: 575.98px) {
    .trace-routing-carte {
        height: 320px;
    }
}

/* ===== Fiches (demande d'accès, étude, travaux, DOE) : cartes sobres, en-tête, étapes, informations, indicateurs ===== */
.fiche-carte {
    --bs-card-border-color: var(--bs-border-color);
    --bs-card-border-radius: 12px;
    --bs-card-inner-border-radius: 11px;
    --bs-card-bg: var(--bs-body-bg);
    box-shadow: none;
}

.fiche-carte-entete {
    padding: 14px 20px;
    border-bottom: 1px solid var(--bs-border-color);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
}

.fiche-carte-entete h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.fiche-carte-corps {
    padding: 16px 20px;
}

.fiche-retour {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    font-size: 13px;
    color: var(--bs-secondary-color);
    text-decoration: none;
}

.fiche-retour:hover {
    color: var(--bs-body-color);
}

.fiche-lien {
    display: inline-flex;
    align-items: center;
    font-size: 13px;
    font-weight: 500;
    color: var(--bs-link-color);
    text-decoration: none;
    white-space: nowrap;
}

.fiche-lien:hover {
    color: var(--bs-link-hover-color);
    text-decoration: underline;
}

/* Lien d'action porté par un bouton (suppression d'un document) */
button.fiche-lien {
    padding: 0;
    border: 0;
    background: none;
}

button.fiche-lien:disabled {
    opacity: 0.5;
    pointer-events: none;
}

.fiche-lien--danger,
.fiche-lien--danger:hover {
    color: var(--bs-danger);
}

[data-bs-theme="dark"] .fiche-lien--danger,
[data-bs-theme="dark"] .fiche-lien--danger:hover {
    color: var(--bs-danger-text-emphasis);
}

.fiche-liens {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
}

/* En-tête : référence, projet, parties, statut et actions principales */
.fiche-entete-corps {
    padding: 20px 24px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.fiche-entete-titre {
    min-width: 0;
    flex: 1 1 320px;
}

.fiche-reference {
    font-size: 12px;
    letter-spacing: 0.02em;
    color: var(--bs-secondary-color);
    overflow-wrap: anywhere;
}

.fiche-titre {
    margin: 2px 0 6px;
    font-size: 20px;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.fiche-parties {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
    color: var(--bs-secondary-color);
}

.fiche-partie {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
    color: var(--bs-body-color);
    min-width: 0;
}

.fiche-aide {
    margin-top: 8px;
    font-size: 13px;
    color: var(--bs-secondary-color);
}

.fiche-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

/* Les formulaires d'une seule action se rangent avec les autres boutons. */
.fiche-actions form {
    display: contents;
}

.fiche-statut {
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 12px;
}

.fiche-refus,
.fiche-alerte {
    border-radius: 12px;
}

/* Bloc séparé du précédent par un filet, dans une carte */
.fiche-separe {
    padding-top: 16px;
    border-top: 1px solid var(--bs-border-color);
}

/* Étapes horizontales (défilent sur mobile) */
.fiche-etapes {
    padding: 14px 20px;
}

.fiche-etapes-liste {
    display: flex;
    margin: 0;
    padding: 0 0 2px;
    list-style: none;
    overflow-x: auto;
}

.fiche-etape {
    flex: 1 0 auto;
    min-width: 130px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--bs-secondary-color);
    font-size: 13px;
}

.fiche-etape:last-child {
    flex-grow: 0;
}

.fiche-etape-point {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--bs-border-color);
    display: grid;
    place-items: center;
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 600;
}

.fiche-etape-texte {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
    white-space: nowrap;
}

.fiche-etape-libelle {
    color: inherit;
    text-decoration: none;
}

a.fiche-etape-libelle:hover {
    color: var(--bs-link-hover-color);
    text-decoration: underline;
}

/* Étape de la fiche affichée : pas de lien, libellé en gras à la couleur de la marque */
.fiche-etape--ici .fiche-etape-libelle {
    font-weight: 700;
    color: var(--bs-primary-text-emphasis);
}

.fiche-etape-detail {
    font-size: 11px;
    color: var(--bs-secondary-color);
    font-weight: 400;
}

.fiche-etape-trait {
    flex: 1;
    min-width: 16px;
    height: 2px;
    margin: 0 8px;
    background: var(--bs-border-color);
}

.fiche-etape--done .fiche-etape-point {
    background: var(--bs-success);
    border-color: var(--bs-success);
    color: #fff;
}

.fiche-etape--done .fiche-etape-trait {
    background: var(--bs-success);
}

.fiche-etape--done,
.fiche-etape--current {
    color: var(--bs-body-color);
}

.fiche-etape--current {
    font-weight: 600;
}

.fiche-etape--current .fiche-etape-point {
    border-color: var(--bs-primary);
    color: var(--bs-primary);
}

.fiche-etape--rejected .fiche-etape-point,
.fiche-etape--abandoned .fiche-etape-point {
    background: var(--bs-danger);
    border-color: var(--bs-danger);
    color: #fff;
}

.fiche-etape--rejected,
.fiche-etape--abandoned {
    color: var(--bs-danger-text-emphasis);
    font-weight: 600;
}

/* Délai du projet, sous les étapes */
.fiche-delai {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--bs-border-color);
    font-size: 12px;
    color: var(--bs-secondary-color);
}

.fiche-delai-piste {
    flex: 1 1 160px;
    height: 6px;
    border-radius: 999px;
    background: var(--bs-tertiary-bg);
    overflow: hidden;
}

.fiche-delai-remplissage {
    height: 100%;
    border-radius: inherit;
    background: var(--bs-primary);
}

.fiche-delai-valeur {
    font-weight: 700;
    color: var(--bs-primary-text-emphasis);
}

.fiche-delai--retard .fiche-delai-remplissage { background: var(--bs-danger); }
.fiche-delai--retard .fiche-delai-valeur { color: var(--bs-danger-text-emphasis); }

/* Carte « Informations » : liste compacte */
.fiche-liste {
    display: grid;
    grid-template-columns: minmax(130px, 200px) minmax(0, 1fr);
    gap: 10px 16px;
    margin: 0;
}

.fiche-liste dt {
    font-weight: 400;
    color: var(--bs-secondary-color);
}

.fiche-liste dd {
    margin: 0;
    font-weight: 500;
    min-width: 0;
    overflow-wrap: anywhere;
}

.fiche-texte {
    white-space: pre-line;
    font-weight: 400 !important;
}

@media (max-width: 575.98px) {
    .fiche-liste {
        grid-template-columns: minmax(0, 1fr);
        gap: 2px;
    }

    .fiche-liste dd {
        margin-bottom: 10px;
    }
}

.fiche-blocs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--bs-border-color);
}

.fiche-sous-titre {
    font-weight: 600;
}

.fiche-zone {
    position: relative;
    isolation: isolate;
    height: 300px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--bs-border-color);
}

.fiche-fichier {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--bs-border-color);
    border-radius: 10px;
    font-weight: 500;
}

.fiche-fichier-nom {
    flex: 1 1 200px;
    min-width: 0;
}

/* Les formulaires d'un lien d'action se rangent avec les autres liens. */
.fiche-fichier form {
    display: contents;
}

/* Dépôt d'un document : type, fichier et bouton sur une ligne dès le format tablette */
.fiche-depot {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.fiche-depot-libelle {
    color: var(--bs-secondary-color);
}

.fiche-carte-corps + .fiche-depot,
.fiche-carte-corps .fiche-depot:not(:first-child) {
    padding-top: 16px;
    border-top: 1px solid var(--bs-border-color);
}

@media (min-width: 576px) {
    .fiche-depot-type {
        flex: 0 0 210px;
    }
}

.fiche-fichier-icone {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    background: var(--bs-tertiary-bg);
    color: var(--bs-secondary-color);
}

/* Récapitulatif du tracé avant validation (état de réussite) */
.fiche-succes {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    background: var(--bs-success-bg-subtle);
    color: var(--bs-success-text-emphasis);
}

/* Indicateurs du tracé Routing */
.fiche-kpis {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

@media (max-width: 575.98px) {
    .fiche-kpis {
        grid-template-columns: minmax(0, 1fr);
    }
}

.fiche-kpi {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--bs-tertiary-bg);
    min-width: 0;
}

.fiche-kpi-libelle {
    font-size: 12px;
    color: var(--bs-secondary-color);
}

.fiche-kpi-valeur {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
}

.fiche-kpi-valeur--texte {
    font-size: 15px;
}

.fiche-kpi-detail {
    font-size: 12px;
    color: var(--bs-secondary-color);
}

/* Bascule des notifications dans l'en-tête de la discussion */
.notification-preference-compacte .form-check-label {
    white-space: nowrap;
}

/* Mobile : marges intérieures réduites */
@media (max-width: 575.98px) {
    .fiche-entete-corps,
    .fiche-etapes {
        padding: 16px;
    }

    .fiche-carte-entete,
    .fiche-carte-corps {
        padding-left: 16px;
        padding-right: 16px;
    }
}
