/* ==========================================================================
   BIBLIOTHÈQUE DE MODÈLES — Feuille de style dédiée
   --------------------------------------------------------------------------
   S'appuie sur ../../css/theme.css (chargé en amont dans le HTML) :
     couleurs : --bg-primary/secondary/tertiary/elevated, --surface,
                --surface-hover/active, --border-subtle/default/strong,
                --text-primary/secondary/tertiary/inverse,
                --accent, --accent-hover, --accent-soft,
                --success, --warning, --danger, --danger-soft
     typo     : --font-sans, --font-mono, --fs-xs/sm/md/lg/xl
     rayons   : --radius-sm/md/lg/xl
     ombres   : --shadow-xs/sm/md/lg
     transitions : --t-fast/base/slow
   ========================================================================== */

:root {
    /* Inter est chargé via Google Fonts dans le HTML de cette page */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, sans-serif;

    /* Tailles fluides du hero */
    --text-xl-fluid: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
    --text-2xl-fluid: clamp(2rem, 1.2rem + 2.5vw, 3.5rem);

    /* Coin plein (absent de theme.css) */
    --radius-full: 9999px;

    /* Largeur de contenu commune */
    --tpl-max-width: 1280px;
    --tpl-gutter: clamp(1rem, 4vw, 2.5rem);
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body {
    min-height: 100dvh;
    font-family: var(--font-sans);
    font-size: var(--fs-md);
    color: var(--text-primary);
    background: var(--bg-primary);
    line-height: 1.6;
}

img,
svg {
    display: block;
    max-width: 100%;
}

button {
    cursor: pointer;
    background: none;
    border: none;
    font: inherit;
    color: inherit;
}

a,
button,
[role='button'],
input,
select {
    transition: color var(--t-base), background var(--t-base),
                border-color var(--t-base), box-shadow var(--t-base),
                opacity var(--t-base);
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: var(--radius-sm);
}

::selection {
    background: var(--accent-soft);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: color-mix(in srgb, var(--bg-primary) 92%, transparent);
    backdrop-filter: blur(16px) saturate(1.4);
    border-bottom: 1px solid var(--border-subtle);
}

.header-inner {
    max-width: var(--tpl-max-width);
    margin: 0 auto;
    padding: 0 var(--tpl-gutter);
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    text-decoration: none;
    color: var(--text-primary);
}

.logo-text {
    font-weight: 700;
    font-size: var(--fs-sm);
    letter-spacing: -0.02em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.badge {
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-weight: 600;
    padding: 0.2em 0.55em;
    border-radius: var(--radius-full);
    background: var(--bg-tertiary);
    color: var(--accent);
    border: 1px solid var(--border-default);
}

.theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
}

.theme-toggle:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

/* ── Hero ─────────────────────────────────────────────────────────────────── */
.hero {
    text-align: center;
    padding: clamp(3rem, 8vw, 6rem) var(--tpl-gutter) clamp(2rem, 5vw, 3.5rem);
}

.hero-title {
    font-size: var(--text-2xl-fluid);
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1.05;
    margin-bottom: 0.75rem;
}

.accent {
    color: var(--accent);
}

.hero-sub {
    font-size: var(--fs-md);
    color: var(--text-secondary);
    max-width: 60ch;
    margin: 0 auto 2rem;
}

.stats-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
}

.stat {
    text-align: center;
}

.stat-num {
    display: block;
    font-size: var(--text-xl-fluid);
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    line-height: 1;
}

.stat-label {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.stat-sep {
    width: 1px;
    height: 40px;
    background: var(--border-subtle);
}

/* ── Barre de contrôles ───────────────────────────────────────────────────── */
.controls {
    max-width: var(--tpl-max-width);
    margin: 0 auto;
    padding: 0 var(--tpl-gutter) 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.search-wrap {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 240px;
    max-width: 400px;
}

.search-icon {
    position: absolute;
    left: 0.875rem;
    color: var(--text-tertiary);
    pointer-events: none;
}

#search {
    width: 100%;
    padding: 0.625rem 2.5rem;
    border-radius: var(--radius-lg);
    border: 1.5px solid var(--border-default);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: var(--fs-sm);
    font-family: var(--font-sans);
}

#search:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

#search::placeholder {
    color: var(--text-tertiary);
}

kbd {
    position: absolute;
    right: 0.75rem;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-tertiary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: 4px;
    padding: 0.15em 0.4em;
    pointer-events: none;
}

.select-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.select-wrap select {
    appearance: none;
    padding: 0.55rem 2.25rem 0.55rem 0.875rem;
    border-radius: var(--radius-lg);
    border: 1.5px solid var(--border-default);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    max-width: 240px;
}

.select-wrap select:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.select-wrap select:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.select-wrap::after {
    content: '';
    position: absolute;
    right: 0.9rem;
    width: 0.45rem;
    height: 0.45rem;
    border-right: 1.8px solid var(--text-tertiary);
    border-bottom: 1.8px solid var(--text-tertiary);
    transform: translateY(-2px) rotate(45deg);
    pointer-events: none;
}

.view-toggle {
    display: flex;
    gap: 0.25rem;
    margin-left: auto;
}

.view-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    border: 1.5px solid var(--border-default);
    background: var(--bg-secondary);
}

.view-btn:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.view-btn.active {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-soft);
}

/* ── Filtres par catégorie ────────────────────────────────────────────────── */
.filter-bar {
    max-width: var(--tpl-max-width);
    margin: 0 auto;
    padding: 0 var(--tpl-gutter) 0.75rem;
}

.filter-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.9rem;
    border-radius: var(--radius-full);
    font-size: var(--fs-xs);
    font-weight: 600;
    letter-spacing: 0.01em;
    border: 1.5px solid var(--border-default);
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.filter-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.filter-btn.active {
    background: var(--accent);
    color: var(--text-inverse);
    border-color: var(--accent);
}

.filter-btn .filter-count {
    font-size: 10px;
    font-weight: 700;
    padding: 0.05em 0.4em;
    border-radius: var(--radius-full);
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
}

.filter-btn.active .filter-count {
    background: color-mix(in srgb, var(--text-inverse) 22%, transparent);
    color: var(--text-inverse);
}

.filter-btn svg {
    flex-shrink: 0;
}

.results-count {
    max-width: var(--tpl-max-width);
    margin: 0 auto;
    padding: 0 var(--tpl-gutter) 0.75rem;
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    font-weight: 500;
}

.category-hint {
    max-width: var(--tpl-max-width);
    margin: 0 auto;
    padding: 0 var(--tpl-gutter) 1rem;
    font-size: var(--fs-sm);
    color: var(--text-tertiary);
    font-style: italic;
}

/* ── Grille de cartes ─────────────────────────────────────────────────────── */
.templates-grid {
    max-width: var(--tpl-max-width);
    margin: 0 auto;
    padding: 0 var(--tpl-gutter) 4rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
}

.templates-grid.view-list {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

/* ── Chargement progressif ────────────────────────────────────────────────── */
/* La grille garde son grand rembourrage bas quand elle se termine ; quand la
   suite reste à venir, c'est le bloc « afficher plus » qui referme la page. */
.templates-grid:has(+ .load-more:not([hidden])) {
    padding-bottom: 1.75rem;
}

.load-more {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 0 var(--tpl-gutter) 4rem;
}

.load-more[hidden] {
    display: none;
}

.load-more-count {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
}

/* ── Carte modèle ─────────────────────────────────────────────────────────── */
.tpl-card {
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border: 1.5px solid var(--border-default);
    border-radius: var(--radius-xl);
    overflow: hidden;
    cursor: pointer;
    text-align: left;
    transition: transform var(--t-base), box-shadow var(--t-base),
                border-color var(--t-base);

    /* Une carte hors écran n'est pas mise en page tant qu'on ne l'approche pas.
       Le mot-clé « auto » de contain-intrinsic-size fait retenir au navigateur
       la hauteur réellement mesurée au premier passage : la barre de défilement
       ne bouge plus une fois la carte parcourue. */
    content-visibility: auto;
    contain-intrinsic-size: auto 340px;
}

.tpl-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent);
}

.tpl-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ── Aperçus : cadrage automatique ─────────────────────────────────────────
   modeles-app.js mesure chaque image au chargement et pose sur son conteneur
   la classe de cadrage adaptée à son format (fit-cover / fit-top /
   fit-contain), la variable --preview-ratio, et un fond clair ou sombre
   (on-light / on-dark) pour que la capture reste lisible dans les deux thèmes.
   -------------------------------------------------------------------------- */
.tpl-card-media,
.modal-media {
    --preview-bg: var(--bg-tertiary);
}

.tpl-card-media.on-light,
.modal-media.on-light {
    --preview-bg: #ffffff;
}

.tpl-card-media.on-dark,
.modal-media.on-dark {
    --preview-bg: #0f1419;
}

.tpl-card-media {
    position: relative;
    background: var(--preview-bg);
    border-bottom: 1px solid var(--border-subtle);
    aspect-ratio: 16 / 10;
    overflow: hidden;
}

.tpl-card-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

/* Visuel vertical : cadrer le haut du diagramme est plus parlant qu'un centre coupé */
.tpl-card-media.fit-top img {
    object-position: center top;
}

/* Panorama : trop large pour un recadrage, on montre le diagramme entier */
.tpl-card-media.fit-contain img {
    object-fit: contain;
    padding: 0.5rem;
}

/* Dégradé discret signalant un aperçu recadré — la suite est visible en grand */
.tpl-card-media.is-cropped::after {
    content: '';
    position: absolute;
    inset: auto 0 0 0;
    height: 32%;
    pointer-events: none;
    background: linear-gradient(to bottom,
                transparent,
                color-mix(in srgb, var(--preview-bg) 75%, transparent));
}

.tpl-card-media img.is-placeholder {
    object-fit: contain;
    padding: 0.5rem;
}

.tpl-card-type {
    position: absolute;
    top: 0.625rem;
    left: 0.625rem;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    padding: 0.25em 0.55em;
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--bg-secondary) 88%, transparent);
    backdrop-filter: blur(6px);
    color: var(--accent);
    border: 1px solid var(--border-default);
}

.tpl-card-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.tpl-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
}

.tpl-card-name {
    font-size: var(--fs-sm);
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.35;
}

.tpl-card-desc {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    line-height: 1.55;
    flex: 1;
}

.tpl-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding-top: 0.25rem;
}

/* Vue liste */
.view-list .tpl-card {
    flex-direction: row;
    align-items: stretch;
    border-radius: var(--radius-lg);
    contain-intrinsic-size: auto 112px;
}

.view-list .tpl-card-media {
    aspect-ratio: auto;
    width: 150px;
    flex-shrink: 0;
    border-bottom: none;
    border-right: 1px solid var(--border-subtle);
}

/* La vignette épouse la hauteur de la ligne : sortie du flux, elle ne peut pas
   étirer la carte au format d'un aperçu vertical. */
.view-list .tpl-card-media img {
    position: absolute;
    inset: 0;
}

.view-list .tpl-card-type {
    display: none;
}

.view-list .tpl-card-body {
    padding: 0.875rem 1rem;
}

/* ── Pastilles ────────────────────────────────────────────────────────────── */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 0.25em 0.6em;
    border-radius: var(--radius-full);
    white-space: nowrap;
    flex-shrink: 0;
}

.pill-type {
    font-family: var(--font-mono);
    background: var(--accent-soft);
    color: var(--accent);
    letter-spacing: 0;
    text-transform: none;
}

/* Catégories — une teinte par univers */
.cat-vie-quotidienne { background: #eff6ff; color: #1d4ed8; }
.cat-education       { background: #f5f3ff; color: #6d28d9; }
.cat-entreprise      { background: #eef2ff; color: #4338ca; }
.cat-projet          { background: #ecfdf5; color: #047857; }
.cat-sante           { background: #fef2f2; color: #b91c1c; }
.cat-administratif   { background: #f8fafc; color: #475569; }
.cat-associatif      { background: #fff7ed; color: #c2410c; }
.cat-commerce        { background: #fffbeb; color: #b45309; }
.cat-science         { background: #ecfeff; color: #0e7490; }
.cat-mathematiques   { background: #f7fee7; color: #4d7c0f; }
.cat-technique       { background: #fdf2f8; color: #9d174d; }

[data-theme='dark'] .cat-vie-quotidienne { background: rgba(59, 130, 246, 0.14); color: #93c5fd; }
[data-theme='dark'] .cat-education       { background: rgba(139, 92, 246, 0.14); color: #c4b5fd; }
[data-theme='dark'] .cat-entreprise      { background: rgba(99, 102, 241, 0.15); color: #a5b4fc; }
[data-theme='dark'] .cat-projet          { background: rgba(16, 185, 129, 0.13); color: #6ee7b7; }
[data-theme='dark'] .cat-sante           { background: rgba(239, 68, 68, 0.13); color: #fca5a5; }
[data-theme='dark'] .cat-administratif   { background: rgba(148, 163, 184, 0.13); color: #cbd5e1; }
[data-theme='dark'] .cat-associatif      { background: rgba(249, 115, 22, 0.13); color: #fdba74; }
[data-theme='dark'] .cat-commerce        { background: rgba(245, 158, 11, 0.13); color: #fcd34d; }
[data-theme='dark'] .cat-science         { background: rgba(6, 182, 212, 0.13); color: #67e8f9; }
[data-theme='dark'] .cat-mathematiques   { background: rgba(132, 204, 22, 0.14); color: #bef264; }
[data-theme='dark'] .cat-technique       { background: rgba(236, 72, 153, 0.13); color: #f9a8d4; }

/* Niveaux de difficulté */
.diff {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-tertiary);
    white-space: nowrap;
}

.diff-dots {
    display: inline-flex;
    gap: 2px;
}

.diff-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--border-strong);
}

.diff-dot.on {
    background: var(--accent);
}

/* ── État vide ────────────────────────────────────────────────────────────── */
.empty-state {
    max-width: 420px;
    margin: 4rem auto;
    text-align: center;
    color: var(--text-secondary);
    padding: 0 1.5rem;
}

.empty-state svg {
    margin: 0 auto 1rem;
    opacity: 0.4;
}

.empty-state p {
    font-size: var(--fs-md);
    margin-bottom: 1rem;
}

.btn-reset {
    padding: 0.45rem 1rem;
    border-radius: var(--radius-full);
    border: 1.5px solid var(--border-default);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    font-weight: 600;
}

.btn-reset:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

/* ── Modale de détail ─────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal[hidden] {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: oklch(0 0 0 / 0.65);
    backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 250ms ease;
}

.modal.open .modal-backdrop {
    opacity: 1;
}

.modal-panel {
    position: relative;
    z-index: 1;
    background: var(--bg-secondary);
    border: 1.5px solid var(--border-default);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 780px;
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: translateY(16px) scale(0.97);
    opacity: 0;
    transition: transform 250ms cubic-bezier(0.16, 1, 0.3, 1), opacity 250ms ease;
}

.modal.open .modal-panel {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 2;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    background: color-mix(in srgb, var(--bg-tertiary) 92%, transparent);
    border: 1px solid var(--border-default);
    backdrop-filter: blur(6px);
}

.modal-close:hover {
    color: var(--text-primary);
    background: var(--surface-active);
}

/* Le bandeau épouse le format de l'aperçu, borné pour rester lisible sans
   repousser le titre du modèle hors de l'écran. */
.modal-media {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-subtle);
    aspect-ratio: var(--preview-ratio, 16 / 7);
    min-height: 9rem;
    max-height: min(48vh, 26rem);
    padding: 0.75rem;
    overflow: hidden;
}

/* L'aperçu est montré en entier, à sa taille réelle tant qu'elle tient dans le
   bandeau : pas de recadrage et pas d'agrandissement qui le rendrait flou. Le
   fond détecté est porté par l'image elle-même, comme une feuille posée sur le
   bandeau — les captures au fond transparent restent ainsi contrastées. */
.modal-media img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    background: var(--preview-bg);
    border-radius: var(--radius-md);
}

.modal-media img.is-placeholder {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 1rem;
}

.modal-header {
    padding: 1.5rem 1.5rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
}

.modal-tags {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.modal-title {
    font-size: var(--fs-xl);
    font-weight: 800;
    letter-spacing: -0.025em;
    margin-bottom: 0.5rem;
    line-height: 1.25;
}

.modal-desc {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    line-height: 1.65;
}

.modal-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-tertiary);
    margin-bottom: 0.7rem;
}

.usage-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.usage-list li {
    position: relative;
    padding-left: 1.4rem;
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    line-height: 1.55;
}

.usage-list li::before {
    content: '';
    position: absolute;
    left: 0.25rem;
    top: 0.6em;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
}

.chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.chip {
    font-size: var(--fs-xs);
    padding: 0.25em 0.65em;
    border-radius: var(--radius-full);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}

/* ── Bloc de code ─────────────────────────────────────────────────────────── */
.code-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.7rem;
}

.code-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-action {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.42rem 0.85rem;
    border-radius: var(--radius-md);
    font-size: var(--fs-xs);
    font-weight: 600;
    border: 1.5px solid var(--border-default);
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.btn-action:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.btn-action.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--text-inverse);
}

.btn-action.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: var(--text-inverse);
}

.btn-action.is-done {
    border-color: var(--success);
    color: var(--success);
    background: color-mix(in srgb, var(--success) 12%, transparent);
}

.btn-action[hidden] {
    display: none;
}

.code-block-wrap {
    position: relative;
}

.code-block-wrap pre {
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    line-height: 1.7;
    color: var(--text-primary);
    overflow-x: auto;
    max-height: 340px;
    white-space: pre;
    tab-size: 4;
}

/* ── Notification ─────────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    transform: translate(-50%, 1rem);
    z-index: 300;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    border-radius: var(--radius-full);
    background: var(--bg-elevated);
    border: 1.5px solid var(--border-default);
    box-shadow: var(--shadow-lg);
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-primary);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-base), transform var(--t-base);
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

.toast svg {
    color: var(--success);
}

/* ── Pied de page ─────────────────────────────────────────────────────────── */
.footer {
    text-align: center;
    padding: 2.5rem 1.5rem;
    border-top: 1px solid var(--border-subtle);
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
}

.footer a {
    color: var(--accent);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
    color: var(--accent-hover);
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
    .stats-row { gap: 1rem; }
    .controls { flex-direction: column; align-items: stretch; }
    .search-wrap { max-width: 100%; }
    .select-wrap select { max-width: none; width: 100%; }
    .view-toggle { display: none; }
    .templates-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
    kbd { display: none; }
    .modal { padding: 0; }
    .modal-panel { max-width: none; max-height: 100dvh; height: 100dvh; border-radius: 0; border: none; }
    /* Le format de l'aperçu reste piloté par l'image, on limite juste sa hauteur */
    .modal-media { max-height: 38vh; }
    .code-head { align-items: stretch; flex-direction: column; }
    .code-actions { flex-wrap: wrap; }
    .btn-action { flex: 1; justify-content: center; }
}

/* ── Animations ───────────────────────────────────────────────────────────── */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* L'apparition n'anime que le haut de la grille : au-delà, les cartes arrivent
   déjà hors écran et l'animation ne coûterait que du travail de composition. */
.tpl-card:nth-child(-n + 24) {
    animation: fadeInUp 220ms ease both;
}

@media (prefers-reduced-motion: reduce) {
    .tpl-card:nth-child(-n + 24) { animation: none; }
    * { transition-duration: 0.01ms !important; }
}

/* ── Mode intégré dans SireneFlux (iframe) ────────────────────────────────── */
html.is-iframe .header,
html.is-iframe .footer {
    display: none;
}

html.is-iframe body {
    min-height: 100%;
}

html.is-iframe .hero {
    padding-top: clamp(1.5rem, 3vw, 2.5rem);
    padding-bottom: clamp(1rem, 2vw, 1.75rem);
}

html.is-iframe .hero-title {
    font-size: var(--fs-xl);
}

html.is-iframe .hero-sub {
    margin-bottom: 1.25rem;
}

html.is-iframe .templates-grid,
html.is-iframe .load-more {
    padding-bottom: 2.5rem;
}
