/* common.css — styles partagés extraits des <style> inline.
   Permet à la CSP style-src de rester relativement stricte tout en gardant
   l'identité visuelle GeneOne. */

/* ── Utilitaires de couleur de la marque GeneOne ──────────────────── */
.text-brand-light   { color: #25b566; }
.text-brand-medium  { color: #23995e; }
.text-brand-dark    { color: #167e47; }
.text-brand-deepest { color: #218353; }
.text-brand-leaf    { color: #29b957; }
.text-brand-cta     { color: #20ad5e; }
.text-brand-link    { color: #0076b6; }
.text-brand-sage    { color: #505e19; }
.text-brand-forest  { color: #225f3a; }

/* Stats dashboard modération */
.text-stat-running  { color: #ffc107; }   /* en cours */
.text-stat-done     { color: #6c757d; }   /* terminé / neutre */
.text-stat-valid    { color: #28a745; }   /* validé / succès */
.text-stat-invalid  { color: #dc3545; }   /* rejeté / erreur */

html[data-theme="dark"] .text-brand-light   { color: #2fcf78; }
html[data-theme="dark"] .text-brand-medium  { color: #2fcf78; }
html[data-theme="dark"] .text-brand-dark    { color: #5dd991; }
html[data-theme="dark"] .text-brand-deepest { color: #5dd991; }
html[data-theme="dark"] .text-brand-leaf    { color: #2fcf78; }
html[data-theme="dark"] .text-brand-cta     { color: #2fcf78; }
html[data-theme="dark"] .text-brand-link    { color: #5aa0ff; }
html[data-theme="dark"] .text-brand-sage    { color: #b9c97a; }
html[data-theme="dark"] .text-brand-forest  { color: #6cc78a; }

/* ── Skip-link accessibilité ──────────────────────────────────────── */
.skip-link {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10000;
    background-color: #167e47;
    color: #fff;
    padding: 0.5rem 1rem;
    text-decoration: none;
    font-weight: 700;
    border-radius: 0 0 0.5rem 0;
    transform: translateY(-200%);
    transition: transform 0.2s ease;
}

.skip-link:focus {
    transform: translateY(0);
    outline: 3px solid #ffcc00;
    outline-offset: 2px;
    color: #fff;
}

/* main reçoit le focus quand on clique le skip-link — éviter l'outline visible */
main#main-content:focus {
    outline: none;
}

/* ── Contraste suffisant pour les boutons CTA ────────────────────── */
.btn-cta:focus-visible {
    outline: 3px solid #167e47;
    outline-offset: 2px;
}

/* ════════════════════════════════════════════════════════════════════
   MODE SOMBRE
   Activé via : <html data-theme="dark"> (toggle géré par common.js + bouton)
   Détection : prefers-color-scheme:dark si rien n'est stocké en localStorage.
   ════════════════════════════════════════════════════════════════════ */

:root {
    --bg-page:       #ffffff;
    --bg-card:       #f8fff6;
    --bg-elevated:   #ffffff;
    --text-primary:  #212529;
    --text-muted:    #6c757d;
    --border-color:  #dee2e6;
    --accent-green:  #25b566;
    --accent-green-dark: #167e47;
    --link-color:    #007bff;
    --shadow-card:   0 6px 24px 0 #b1e9c87c;
}

html[data-theme="dark"] {
    --bg-page:       #121417;
    --bg-card:       #1c2026;
    --bg-elevated:   #242a31;
    --text-primary:  #e8e6e3;
    --text-muted:    #9aa0a6;
    --border-color:  #3a4049;
    --accent-green:  #2fcf78;
    --accent-green-dark: #26a55f;
    --link-color:    #5aa0ff;
    --shadow-card:   0 6px 24px 0 rgba(0, 0, 0, 0.6);
}

html[data-theme="dark"] body,
html[data-theme="dark"] {
    background-color: var(--bg-page);
    color: var(--text-primary);
}

html[data-theme="dark"] .geneone-card,
html[data-theme="dark"] .terms-container,
html[data-theme="dark"] .account-section {
    background-color: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-card);
}

html[data-theme="dark"] .card,
html[data-theme="dark"] .modal-content {
    background-color: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-color);
}

html[data-theme="dark"] .text-muted {
    color: var(--text-muted) !important;
}

html[data-theme="dark"] .table {
    color: var(--text-primary);
    --bs-table-bg: transparent;
}

html[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > td {
    background-color: rgba(255, 255, 255, 0.03);
    color: var(--text-primary);
}

html[data-theme="dark"] tr.result-row:hover td {
    background-color: #3a3000 !important;
}

html[data-theme="dark"] .navbar {
    background-color: var(--bg-elevated) !important;
    border-bottom: 1px solid var(--border-color);
}

html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select {
    background-color: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-color);
}

html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus {
    background-color: var(--bg-elevated);
    color: var(--text-primary);
}

html[data-theme="dark"] a {
    color: var(--link-color);
}

html[data-theme="dark"] a:hover {
    color: #8ec0ff;
}

/* ════════════════════════════════════════════════════════════════════
   DARK MODE — overrides specifiques pour les surfaces "oubliees"
   (styles.css applique des gradients/couleurs en mode clair par defaut,
   il faut les neutraliser explicitement en dark).
   ════════════════════════════════════════════════════════════════════ */

/* 1. Background body : styles.css utilise la shorthand `background:` avec
   un linear-gradient, qui ecrase `background-color`. On force la couleur
   en dark via `background:` aussi (et `background-image: none` au cas ou). */
html[data-theme="dark"] body {
    background: var(--bg-page) !important;
    background-image: none !important;
    color: var(--text-primary);
}

/* 2. Footer : .footer-plant a un gradient clair + une bordure verte clairs */
html[data-theme="dark"] .footer-plant {
    background: var(--bg-elevated) !important;
    background-image: none !important;
    border-top: 3px solid var(--border-color);
    color: var(--text-primary);
}
html[data-theme="dark"] .footer-plant a,
html[data-theme="dark"] .footer-plant .text-success {
    color: var(--accent-green) !important;
}

/* 3. Form selects : Bootstrap 5.3 utilise les variables CSS --bs-body-bg,
   --bs-form-select-bg et --bs-form-select-bg-img qui surchargent nos regles
   classiques. On les redefinit globalement EN DARK pour que tout select
   (departement, commune, n'importe quel form-select) prenne le theme.
   On met aussi des regles ciblees avec !important au cas ou une CSS plus
   specifique se gliserait. */
html[data-theme="dark"] {
    --bs-body-bg: var(--bg-page);
    --bs-body-color: var(--text-primary);
    --bs-secondary-bg: var(--bg-elevated);
    --bs-tertiary-bg: var(--bg-elevated);
    --bs-border-color: var(--border-color);
    /* Fleche du select recoloree en clair (sinon invisible sur fond sombre) */
    --bs-form-select-bg-img: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23e8e6e3' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3E%3C/svg%3E");
}
html[data-theme="dark"] .form-select,
html[data-theme="dark"] .form-control {
    background-color: var(--bg-elevated) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}
/* Options du dropdown (rendu Chromium ; Firefox utilise le rendu OS) */
html[data-theme="dark"] .form-select option {
    background-color: var(--bg-elevated);
    color: var(--text-primary);
}
/* Placeholder + focus state pour rester lisibles */
html[data-theme="dark"] .form-control::placeholder { color: var(--text-muted); }
html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus {
    background-color: var(--bg-elevated) !important;
    color: var(--text-primary) !important;
    border-color: var(--accent-green) !important;
    box-shadow: 0 0 0 .2rem rgba(47, 207, 120, .25);
}

/* 4. Autres surfaces "claires" residuelles de styles.css */
html[data-theme="dark"] .section-infos {
    background: var(--bg-card) !important;
    background-image: none !important;
    color: var(--text-primary);
    box-shadow: var(--shadow-card);
}
html[data-theme="dark"] .hero-bg {
    background: var(--bg-elevated) !important;
    background-image: none !important;
    color: var(--text-primary);
}
html[data-theme="dark"] .navbar {
    /* .navbar a un background: rgba(255,255,255,0.94) hardcode en clair */
    background: var(--bg-elevated) !important;
}

/* Bouton de bascule (positionné dans la navbar) */
.theme-toggle-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 999px;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-right: 0.5rem;
    transition: background-color 0.2s, color 0.2s;
}

.theme-toggle-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

html[data-theme="dark"] .theme-toggle-btn:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.theme-toggle-btn .icon-dark,
.theme-toggle-btn .icon-light {
    display: inline;
}

html[data-theme="dark"] .theme-toggle-btn .icon-dark { display: none; }
html:not([data-theme="dark"]) .theme-toggle-btn .icon-light { display: none; }


/* ── Layout vertical : footer collé en bas ──────────────────────────── */
html, body {
    height: 100%;
    margin: 0;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

main.content {
    flex: 1;
}

footer {
    flex-shrink: 0;
}

/* ── Containers "fiche" / "search" / "login" ───────────────────────── */
.geneone-card {
    background: #f8fff6;
    border-radius: 1.1rem;
    box-shadow: 0 6px 24px 0 #b1e9c87c;
    padding: 2rem;
    margin-top: 2rem;
    margin-bottom: 2rem;
}

/* ── Overlay de chargement (login, recherche, etc.) ────────────────── */
#loader-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(248, 255, 246, 0.9);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

#loader-overlay.is-visible {
    display: flex;
}

#loader-overlay .progress {
    height: 20px;
    width: 300px;
    background-color: #e9ecef;
}

#loader-overlay .progress-bar {
    background-color: #6aaa81;
}

#loader-overlay h4 {
    color: #3a6b4a;
    margin-bottom: 1rem;
}

/* ── Bouton CTA cohérent ───────────────────────────────────────────── */
.btn-cta {
    background-color: #28a745;
    color: white;
}

.btn-cta:hover {
    background-color: #218838;
    color: white;
}

/* ── Overlay confirmation import (index.html) ──────────────────────── */
.confirmation-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    visibility: hidden;
}

.confirmation-overlay.show {
    visibility: visible;
}

.confirmation-content {
    background-color: white;
    padding: 2rem;
    border-radius: 0.5rem;
    max-width: 500px;
    width: 90%;
    position: relative;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.confirmation-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6c757d;
}

.confirmation-close:hover {
    color: #343a40;
}

/* ── Select2 calé sur la hauteur d'un form-select ─────────────────── */
.select2-container--bootstrap-5 .select2-selection--single {
    height: 2.25rem;
    padding: .375rem .75rem;
}

.select2-container--bootstrap-5 .select2-selection__rendered {
    line-height: 1.5;
}

.select2-container--bootstrap-5 .select2-selection__arrow {
    height: 2.25rem;
    top: 0;
}

.select2-container {
    width: 100% !important;
}

/* ── Container des pages légales (CGU, CGV, confidentialité, cookies) ── */
.terms-container {
    max-width: 800px;
    margin: 50px auto;
    padding: 30px;
    background-color: #ffffff;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.terms-container h1 {
    text-align: center;
    margin-bottom: 30px;
}

.terms-container h2 {
    margin-top: 20px;
    font-size: 1.5rem;
}

.terms-container p,
.terms-container ul {
    line-height: 1.6;
}

/* ── Tables triables (compte, mod_*) ──────────────────────────────── */
th.sortable {
    cursor: pointer;
    user-select: none;
}

th .arrow {
    font-size: 0.85em;
}

.table-striped tbody tr.result-row:hover td,
tr.result-row:hover td {
    background-color: #ffeeb7 !important;
    cursor: pointer;
}

.account-section {
    background: #f8fff6;
    border-radius: 1.1rem;
    box-shadow: 0 6px 24px 0 #b1e9c87c;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

/* ── CMP / bannière cookies CNIL ──────────────────────────────────── */
.cookie-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(20, 30, 30, 0.88);
    display: none;
    align-items: center;
    justify-content: center;
}

.cookie-overlay.is-visible { display: flex; }

.cookie-modal {
    background: #ffffff;
    max-width: 420px;
    border-radius: 10px;
    padding: 32px 22px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    text-align: center;
    margin: auto;
}

.cookie-modal p { font-size: 1rem; margin: 1em 0; }

.cookie-modal a {
    color: #0076b6;
    text-decoration: underline;
    font-size: 0.95em;
}

.cookie-actions { margin-top: 2em; }

.cookie-actions .btn {
    min-width: 110px;
    margin: 0 7px;
}

.cookie-customize-list {
    text-align: left;
    margin-bottom: 16px;
}

.cookie-customize-list > div { margin: 6px 0; }

.btn-manage-cookies {
    position: fixed;
    bottom: 22px;
    right: 22px;
    z-index: 999;
    display: none;
    padding: 10px 16px;
    font-size: 0.95em;
    border: none;
    border-radius: 8px;
    background: #e9f6fc;
    color: #00557e;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
    cursor: pointer;
}

html[data-theme="dark"] .cookie-modal {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

html[data-theme="dark"] .cookie-modal a {
    color: var(--link-color);
}

html[data-theme="dark"] .btn-manage-cookies {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

/* ── Toggle vues fiche / arbre ────────────────────────────────────── */
.view-toggle-links {
    margin: 10px 0;
    padding: 5px 0;
    display: flex;
    gap: 15px;
    justify-content: left;
}

.view-toggle-links a {
    text-decoration: none;
    font-weight: bold;
    color: #007bff;
    padding: 5px 10px;
    border-radius: 4px;
    transition: background-color 0.3s;
}

.view-toggle-links a:hover {
    background-color: #e9ecef;
    color: #0056b3;
}

.view-toggle-links a.active {
    background-color: #007bff;
    color: white;
}

/* ── Lien "Voir document" dans l'arbre ────────────────────────────── */
.acte-doc-link {
    color: #007bff;
    text-decoration: none;
}

.acte-doc-link:hover {
    color: #0056b3;
    text-decoration: underline;
}

html[data-theme="dark"] .acte-doc-link {
    color: var(--link-color);
}
