/* Sondages publics (Phase 12). Feuille dediee, chargee uniquement sur les pages /sondages
   (voir templates/surveys/_base.html) : le CSS Tailwind compile (style.css) n'est pas
   reconstruit a chaque nouveau composant, ces quelques regles n'y dependent donc de rien.
   Couleurs de la charte : bleu #0a2540, terracotta #b65330, or #d4af37. */

/* Reponse a une question a choix : carte cliquable, mise en evidence une fois cochee */
.sv-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    background: #f9fafb;
    color: #374151;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s, box-shadow 0.2s;
}
.sv-option:hover {
    border-color: #b65330;
    background: #fff;
}
.sv-option:has(input:checked) {
    border-color: #b65330;
    background: #fdf3ee;
    box-shadow: 0 0 0 1px #b65330;
}
.sv-option:focus-within {
    outline: 2px solid #d4af37;
    outline-offset: 2px;
}
.sv-option input {
    flex: none;
    width: 1.15rem;
    height: 1.15rem;
    accent-color: #b65330;
}

/* Note de 1 a 5 : les vraies cases radio restent dans le DOM (clavier, lecteurs d'ecran) */
.sv-rating {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.sv-rating label {
    position: relative;
    cursor: pointer;
}
.sv-rating input {
    position: absolute;
    opacity: 0;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}
.sv-rating span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    background: #f9fafb;
    font-weight: 700;
    color: #0a2540;
    transition: border-color 0.2s, background-color 0.2s, color 0.2s;
}
.sv-rating label:hover span {
    border-color: #b65330;
    background: #fff;
}
.sv-rating input:checked + span {
    border-color: #b65330;
    background: #b65330;
    color: #fff;
}
.sv-rating input:focus-visible + span {
    outline: 2px solid #d4af37;
    outline-offset: 2px;
}

/* Echelle de satisfaction (5 niveaux) : boutons libelles, sur une ligne des que la place le
   permet, empiles sur mobile */
.sv-scale {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
}
@media (min-width: 640px) {
    .sv-scale {
        grid-template-columns: repeat(5, 1fr);
    }
}
.sv-scale label {
    position: relative;
    cursor: pointer;
}
.sv-scale input {
    position: absolute;
    opacity: 0;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}
.sv-scale span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 3rem;
    height: 100%;
    padding: 0.5rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    background: #f9fafb;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    color: #0a2540;
    transition: border-color 0.2s, background-color 0.2s, color 0.2s;
}
.sv-scale label:hover span {
    border-color: #b65330;
    background: #fff;
}
.sv-scale input:checked + span {
    border-color: #b65330;
    background: #b65330;
    color: #fff;
}
.sv-scale input:focus-visible + span {
    outline: 2px solid #d4af37;
    outline-offset: 2px;
}

/* Textes rediges dans le back-office : les retours a la ligne sont conserves */
.sv-intro,
.sv-help {
    white-space: pre-line;
}
.sv-intro {
    line-height: 1.7;
}

/* Titre de section du questionnaire */
.sv-section {
    padding-top: 1.5rem;
    border-top: 2px solid #b65330;
}

/* Precision ecrite du choix « Autre » */
.sv-other {
    margin-top: 0.25rem;
}

/* Synthese des echelles de satisfaction : score moyen par critere */
.sv-summary-row + .sv-summary-row {
    margin-top: 1rem;
}
.sv-summary-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    margin-bottom: 0.3rem;
    font-size: 0.875rem;
}
.sv-summary-label {
    color: #374151;
}
.sv-summary-value {
    font-weight: 700;
    color: #0a2540;
    white-space: nowrap;
}
.sv-summary-muted {
    margin-top: 0.2rem;
    font-size: 0.75rem;
    color: #6b7280;
}

/* Questionnaire par etapes (survey-form.js) */
.sv-progress {
    scroll-margin-top: 6rem; /* sous la barre de navigation fixe */
}
.sv-progress-text {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.25rem 1rem;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #374151;
}
.sv-progress-text [data-progress-step] {
    color: #b65330;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.sv-progress-track {
    height: 0.4rem;
    overflow: hidden;
    border-radius: 9999px;
    background: #e5e7eb;
}
.sv-progress-track > span {
    display: block;
    height: 100%;
    border-radius: 9999px;
    background: #b65330;
    transition: width 0.3s ease;
}
.sv-step-nav {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}
/* .btn impose un display : sans cela, l'attribut hidden resterait sans effet */
.sv-step-nav [hidden],
[data-submit-area][hidden],
[data-step][hidden] {
    display: none !important;
}
.sv-step-notice {
    text-align: center;
}

/* Erreur de validation sur une question */
.sv-invalid {
    border-color: #fca5a5;
}
.sv-error {
    margin-top: 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #b91c1c;
}

/* Barres de resultats */
.sv-bar {
    height: 0.75rem;
    overflow: hidden;
    border-radius: 9999px;
    background: #e5e7eb;
}
.sv-bar > span {
    display: block;
    height: 100%;
    border-radius: 9999px;
    background: #b65330;
    transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.sv-bar-rating > span {
    background: #d4af37;
}

@media (prefers-reduced-motion: reduce) {
    .sv-option,
    .sv-rating span,
    .sv-scale span,
    .sv-bar > span {
        transition: none;
    }
}

/* Petits utilitaires absents du CSS Tailwind compile */
.sv-normal {
    font-weight: 400;
}
.sv-row {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
@media (min-width: 640px) {
    .sv-row {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

/* --- Graphiques et mise a jour en direct (survey-results.js) --- */

.sv-chart {
    position: relative;
    width: 100%;
}
.sv-chart:empty {
    display: none;
}

/* Une fois le graphique dessine, les lignes de texte restent pour les lecteurs d'ecran
   (alternative accessible, tenue a jour) mais ne sont plus affichees en double. */
.sv-charted .sv-rows {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Pastille "En direct" : point fixe + libelle (jamais la couleur seule) */
.sv-live {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #374151;
}
.sv-live-dot {
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 9999px;
    background: #6b7280;
}
.sv-live[data-state="live"] .sv-live-dot {
    background: #2d5a27;
    animation: sv-pulse 2s ease-in-out infinite;
}
.sv-live[data-state="offline"] .sv-live-dot {
    background: #b65330;
}
@keyframes sv-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(45, 90, 39, 0.45); }
    50% { box-shadow: 0 0 0 5px rgba(45, 90, 39, 0); }
}

/* Notification "nouvelle reponse" */
.sv-toast {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    z-index: 1080;
    max-width: calc(100vw - 2rem);
    padding: 0.75rem 1.25rem;
    border-radius: 0.75rem;
    background: #0a2540;
    color: #fff;
    font-size: 0.875rem;
    font-weight: 600;
    box-shadow: 0 10px 25px rgba(10, 37, 64, 0.25);
    opacity: 0;
    transform: translate(-50%, 0.75rem);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}
.sv-toast-in {
    opacity: 1;
    transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
    .sv-live[data-state="live"] .sv-live-dot {
        animation: none;
    }
    .sv-toast {
        transition: none;
    }
}

/* --- Liste des sondages (/sondages) --- */

.sv-icon {
    flex: none;
    width: 1.15rem;
    height: 1.15rem;
    color: #b65330;
}
.sv-icon-sm {
    flex: none;
    width: 0.95rem;
    height: 0.95rem;
}

/* Chiffres cles sous l'en-tete */
.sv-kpis {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-top: -5.5rem;          /* chevauche le bas de l'en-tete */
    margin-bottom: 3.5rem;
    position: relative;
    z-index: 10;
}
.sv-kpi {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 1.25rem 0.75rem;
    border-radius: 1rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    box-shadow: 0 10px 25px rgba(10, 37, 64, 0.08);
    text-align: center;
}
.sv-kpi-value {
    display: flex;
    align-items: center;
    min-height: 2.25rem;
    font-family: var(--font-serif, Georgia, serif);
    font-size: 1.9rem;
    font-weight: 700;
    line-height: 1;
    color: #0a2540;
}
.sv-kpi-icon {
    width: 1.9rem;
    height: 1.9rem;
    color: #2d5a27;
}
.sv-kpi-label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    color: #6b7280;
}
@media (min-width: 640px) {
    .sv-kpi-label { font-size: 0.85rem; }
}

.sv-list-title {
    margin-bottom: 1rem;
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #6b7280;
}

/* Fiche d'un sondage ouvert */
.sv-card {
    overflow: hidden;
    border-radius: 1.25rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-top: 4px solid #b65330;
    box-shadow: 0 1px 3px rgba(10, 37, 64, 0.06);
    transition: box-shadow 0.25s, transform 0.25s;
}
.sv-card:hover {
    box-shadow: 0 18px 40px rgba(10, 37, 64, 0.10);
    transform: translateY(-2px);
}
.sv-card-body {
    padding: 1.5rem;
}
@media (min-width: 768px) {
    .sv-card-body { padding: 2rem 2.25rem; }
}
.sv-card-title {
    margin: 1rem 0 0.75rem;
    font-family: var(--font-serif, Georgia, serif);
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.3;
    color: #0a2540;
}
@media (min-width: 768px) {
    .sv-card-title { font-size: 1.6rem; }
}
.sv-card-title a:hover {
    color: #b65330;
}
.sv-card-text {
    color: #4b5563;
    line-height: 1.7;
}

.sv-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.sv-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.7rem;
    border-radius: 9999px;
    background: #f3f4f6;
    font-size: 0.75rem;
    font-weight: 600;
    color: #374151;
}
.sv-badge-open {
    background: #ecf3ea;
    color: #2d5a27;
}
.sv-badge-open .sv-live-dot {
    background: #2d5a27;
    animation: sv-pulse 2s ease-in-out infinite;
}
.sv-badge-urgent {
    background: #fdf3ee;
    color: #b65330;
}
.sv-badge-done {
    background: #0a2540;
    color: #fff;
}

/* Faits cles : questions, duree, participants, dates */
.sv-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding: 1rem;
    border-radius: 0.9rem;
    background: #f9fafb;
}
@media (min-width: 768px) {
    .sv-facts { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.sv-fact {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: #4b5563;
}
.sv-fact strong {
    color: #0a2540;
}

/* Themes abordes (sections du questionnaire) */
.sv-topics {
    margin-top: 1.5rem;
}
.sv-topics-title {
    margin-bottom: 0.6rem;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #6b7280;
}
.sv-topics ul {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.sv-topics li {
    padding: 0.35rem 0.75rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    font-size: 0.8rem;
    color: #374151;
}

/* Pied de fiche : actions + partage */
.sv-card-footer {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding: 1.25rem 1.5rem;
    border-top: 1px solid #f3f4f6;
    background: #fcfcfd;
}
@media (min-width: 768px) {
    .sv-card-footer {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 1.25rem 2.25rem;
    }
}
.sv-card-footer .btn {
    gap: 0.4rem;
}
.sv-share {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}
.sv-share-label {
    margin-right: 0.25rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #6b7280;
}
/* Le partage natif (menu du telephone) n'apporte rien sur ordinateur, ou les icones suffisent */
@media (hover: hover) and (pointer: fine) {
    .sv-native-share { display: none; }
}
.sv-thanks {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 600;
    color: #2d5a27;
}

/* Sondage a venir */
.sv-mini {
    padding: 1.25rem 1.5rem;
    border: 1px dashed #d1d5db;
    border-radius: 1rem;
    background: #fff;
}
.sv-mini-title {
    margin: 0.75rem 0 0.25rem;
    font-family: var(--font-serif, Georgia, serif);
    font-weight: 700;
    color: #0a2540;
}
.sv-mini-meta {
    font-size: 0.8rem;
    color: #6b7280;
}

/* Comment ca marche */
.sv-how {
    padding: 2rem 1.5rem;
    border-radius: 1.25rem;
    background: #0a2540;
    color: #fff;
}
@media (min-width: 768px) {
    .sv-how { padding: 2.5rem; }
}
.sv-how-title {
    margin-bottom: 1.75rem;
    font-family: var(--font-serif, Georgia, serif);
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
}
.sv-how-grid {
    display: grid;
    gap: 1.5rem;
}
@media (min-width: 768px) {
    .sv-how-grid { grid-template-columns: repeat(3, 1fr); }
}
.sv-how-item h3 {
    margin: 0.75rem 0 0.35rem;
    font-weight: 700;
    color: #d4af37;
}
.sv-how-item p {
    font-size: 0.9rem;
    line-height: 1.6;
    color: #cbd5e1;
}
.sv-how-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.1);
}
.sv-how-icon .sv-icon {
    color: #d4af37;
}

/* Invitation a partager (page de remerciement) */
.sv-share-cta {
    margin-top: 2rem;
    padding: 1.5rem;
    border-radius: 1rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    text-align: center;
}
.sv-share-cta .sv-share {
    justify-content: center;
    margin-top: 1rem;
}

@media (prefers-reduced-motion: reduce) {
    .sv-card { transition: none; }
    .sv-card:hover { transform: none; }
    .sv-badge-open .sv-live-dot { animation: none; }
}

/* --- Mise en page elargie (ordinateur) --- */

/* Deux colonnes generiques (sondages a venir, remerciement + partage) */
.sv-grid-2 {
    display: grid;
    gap: 1.5rem;
}
@media (min-width: 768px) {
    .sv-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.sv-thanks-top .sv-share-cta {
    margin-top: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.sv-thanks-top:not(.sv-grid-2) {
    max-width: 48rem;
    margin-left: auto;
    margin-right: auto;
}

/* Resultats : 2 questions par ligne a partir de 1024 px ; sections et syntheses sur toute la largeur */
.sv-results-grid {
    display: grid;
    gap: 1.5rem;
    align-items: start;
}
@media (min-width: 1024px) {
    .sv-results-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .sv-results-grid > .sv-span-all { grid-column: 1 / -1; }
}
.sv-results-grid > .sv-section {
    margin-top: 1rem;
}
.sv-results-grid > .sv-section:first-child {
    margin-top: 0;
}
.sv-results-grid-admin {
    gap: 1rem;
}

/* Synthese des criteres : 2 colonnes de lignes sur grand ecran */
@media (min-width: 1024px) {
    .sv-summary-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        column-gap: 3rem;
        row-gap: 1rem;
    }
    .sv-summary-grid .sv-summary-row + .sv-summary-row { margin-top: 0; }
}

/* Formulaire : choix courts sur 2 colonnes */
.sv-options {
    display: grid;
    gap: 0.5rem;
}
@media (min-width: 768px) {
    .sv-options-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .sv-options-2 .sv-other,
    .sv-options-2 .sr-only { grid-column: 1 / -1; }
}

.sv-topics .sv-topics-more {
    border-style: dashed;
    color: #6b7280;
}

/* --- Cartes de resultats (page publique et back-office) --- */

.sv-card-result {
    height: 100%;
    padding: 1.5rem;
    border: 1px solid #e5e7eb;
    border-radius: 1rem;
    background: #fff;
    box-shadow: 0 1px 2px rgba(10, 37, 64, 0.05);
}
@media (min-width: 768px) {
    .sv-card-result { padding: 1.75rem 2rem; }
}
.sv-result-title {
    font-family: var(--font-serif, Georgia, serif);
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.4;
    color: #0a2540;
}
.sv-result-meta {
    margin: 0.25rem 0 1.25rem;
    font-size: 0.75rem;
    color: #6b7280;
}

/* Barres de repartition */
.sv-result-row + .sv-result-row {
    margin-top: 0.9rem;
}
.sv-result-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    margin-bottom: 0.35rem;
}
.sv-result-label {
    font-size: 0.875rem;
    line-height: 1.35;
    color: #374151;
}
.sv-result-value {
    flex: none;
    font-size: 0.875rem;
    font-weight: 700;
    color: #0a2540;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.sv-result-count {
    margin-left: 0.3rem;
    font-weight: 400;
    color: #9ca3af;
}
.sv-result-row .sv-bar {
    height: 0.6rem;
    background: #f1f2f4;
}
.sv-result-row .sv-bar > span {
    background: #e2a48d; /* meme teinte, attenuee : la reponse en tete ressort */
}
.sv-result-row.sv-leader .sv-bar > span {
    background: #b65330;
}
.sv-result-row.sv-leader .sv-result-label {
    font-weight: 600;
    color: #0a2540;
}

/* Score moyen (notes et echelles) */
.sv-score {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.5rem;
    margin-bottom: 1.1rem;
}
.sv-score-value {
    font-family: var(--font-serif, Georgia, serif);
    font-size: 1.9rem;
    font-weight: 700;
    line-height: 1;
    color: #b65330;
}
.sv-score-max {
    font-size: 0.9rem;
    color: #9ca3af;
}
.sv-score-label {
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    background: #fdf3ee;
    font-size: 0.75rem;
    font-weight: 600;
    color: #b65330;
}

/* Grille : cartes d'une meme ligne a la meme hauteur */
.sv-results-grid {
    align-items: stretch;
}
.sv-results-grid > .sv-section {
    align-self: end;
    margin-bottom: -0.25rem;
}

/* Back-office : listes de reponses libres bornees en hauteur */
.sv-text-list {
    max-height: 22rem;
    overflow-y: auto;
}
.sv-results-grid-admin > .card {
    height: 100%;
    margin-bottom: 0;
}

/* Question conditionnelle masquee (survey-form.js) */
fieldset[hidden] {
    display: none !important;
}

/* Option « Je ne sais pas » sous une note ou une echelle */
.sv-na-option {
    margin-top: 0.6rem;
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
    font-size: 0.875rem;
    color: #6b7280;
}
@media (min-width: 640px) {
    .sv-na-option { display: inline-flex; }
}

/* Resultats : « Je ne sais pas » et question conditionnelle */
.sv-na-note,
.sv-condition-note {
    margin-top: 0.9rem;
    font-size: 0.75rem;
    color: #6b7280;
}
.sv-condition-note {
    margin: -0.75rem 0 1.1rem;
    font-style: italic;
}
