/* ============================================
   LIVE QUIZ — Page Bibliothèque partagée (v7.8.9)
   Palette de l'interface enseignant (index.css), en jetons :
   :root (clair) et [data-theme="dark"] (même clé localStorage
   'live_quiz_theme' que index.html). Aucune couleur hors des jetons,
   sauf le blanc des boutons pleins.
   ============================================ */

@import "fonts.css";

:root {
    --primary: #1155D6;
    --primary-light: #4d80e8;
    --primary-dark: #0d44b5;
    --primary-glow: rgba(17, 85, 214, 0.22);
    --accent-text: #0f766e;
    --accent-soft: rgba(14, 165, 160, 0.09);
    --accent-line: rgba(14, 165, 160, 0.4);
    /* Étiquettes du tableau : discipline (bleu), niveau (violet), mot-clé (accent). */
    --disc-text: #0d44b5;
    --disc-soft: rgba(17, 85, 214, 0.08);
    --disc-line: rgba(17, 85, 214, 0.35);
    --level-text: #6d28d9;
    --level-soft: rgba(124, 58, 237, 0.08);
    --level-line: rgba(124, 58, 237, 0.35);

    --bg-page: #f0f2f8;
    --bg-card: #ffffff;
    --bg-subtle: #f7f8fc;
    --bg-input: #f4f5fa;
    --bg-header: rgba(255, 255, 255, 0.85);

    --text-primary: #1a1a2e;
    --text-secondary: #334155;
    --text-muted: #475569;
    --text-on-primary: #ffffff;

    --border: #dce3f0;
    --shadow-sm: 0 2px 8px rgba(17, 85, 214, 0.06);
    --shadow-md: 0 4px 20px rgba(17, 85, 214, 0.08);
    --shadow-lg: 0 8px 40px rgba(17, 85, 214, 0.12);

    --error: #d63031;
    --error-bg: #fde8e8;
    --overlay: rgba(0, 0, 0, 0.5);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-pill: 999px;
    --transition-fast: 0.15s ease;
}

[data-theme="dark"] {
    --primary-light: #7aa2f2;
    --bg-page: #0f172a;
    --bg-card: #1e293b;
    --bg-subtle: #273449;
    --bg-input: #0f172a;
    --bg-header: rgba(15, 23, 42, 0.85);

    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;

    --border: rgba(148, 163, 184, 0.22);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);

    --accent-text: #5eead4;
    --accent-soft: rgba(94, 234, 212, 0.1);
    --accent-line: rgba(94, 234, 212, 0.35);
    --disc-text: #a5c0f7;
    --disc-soft: rgba(122, 162, 242, 0.12);
    --disc-line: rgba(122, 162, 242, 0.4);
    --level-text: #c4b5fd;
    --level-soft: rgba(167, 139, 250, 0.12);
    --level-line: rgba(167, 139, 250, 0.4);
    --error: #f87171;
    --error-bg: rgba(214, 48, 49, 0.18);
    --overlay: rgba(0, 0, 0, 0.65);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

/* ---------- En-tête ---------- */
.bib-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 32px;
    background: var(--bg-header);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}

.bib-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    color: inherit;
    text-decoration: none;
}

/* Le logo est une tuile carrée à fond transparent : affichée telle quelle. */
.bib-logo-tile {
    display: block;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.bib-logo-tile img {
    display: block;
    width: 100%;
    height: 100%;
}

.bib-logo-words {
    display: flex;
    flex-direction: column;
}

.bib-logo-text {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.02em;
}

[data-theme="dark"] .bib-logo-text {
    color: var(--primary-light);
}

.bib-logo-sub {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

.bib-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.bib-nav-link {
    padding: 8px 14px;
    border-radius: var(--radius-pill);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.bib-nav-link:hover,
.bib-nav-link:focus-visible {
    background: var(--primary-glow);
    color: var(--text-primary);
}

.bib-icon-btn {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
}

.bib-icon-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
}

/* ---------- Contenu ---------- */
.bib-main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 32px 20px 48px;
}

.bib-intro {
    margin-bottom: 24px;
}

.bib-intro h1 {
    margin: 0 0 8px;
    font-size: 2rem;
    font-weight: 900;
    letter-spacing: -0.03em;
    color: var(--text-primary);
}

.bib-intro h1 i {
    color: var(--accent-text);
}

.bib-intro p {
    max-width: 760px;
    margin: 0;
    font-size: 1rem;
    color: var(--text-muted);
}

/* ---------- Barre de recherche ---------- */
.bib-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    margin-bottom: 16px;
}

.bib-search {
    position: relative;
    flex: 1 1 320px;
    min-width: 0;
}

.bib-search i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.bib-search input {
    width: 100%;
    padding: 12px 14px 12px 40px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--bg-card);
    color: var(--text-primary);
    font: inherit;
    font-size: 0.95rem;
}

.bib-search input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.bib-active-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 6px 6px 12px;
    border: 1px solid var(--accent-line);
    border-radius: var(--radius-pill);
    background: var(--accent-soft);
    color: var(--accent-text);
    font-size: 0.85rem;
    font-weight: 700;
}

.bib-active-tag--discipline {
    border-color: var(--disc-line);
    background: var(--disc-soft);
    color: var(--disc-text);
}

.bib-active-tag--niveau {
    border-color: var(--level-line);
    background: var(--level-soft);
    color: var(--level-text);
}

.bib-active-tag button {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.bib-active-tag button:hover {
    background: var(--accent-line);
}

.bib-count {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* ---------- Boutons ---------- */
.bib-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    font: inherit;
    font-size: 0.86rem;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
    transition: box-shadow var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}

.bib-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.bib-btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: var(--text-on-primary);
    box-shadow: 0 4px 12px var(--primary-glow);
}

.bib-btn-primary:hover:not(:disabled) {
    box-shadow: 0 6px 18px var(--primary-glow);
}

.bib-btn-secondary {
    background: var(--accent-soft);
    border-color: var(--accent-line);
    color: var(--accent-text);
}

.bib-btn-ghost {
    background: var(--bg-card);
    border-color: var(--border);
    color: var(--text-secondary);
}

.bib-btn-ghost:hover:not(:disabled),
.bib-btn-secondary:hover:not(:disabled) {
    border-color: var(--primary);
}

.bib-btn-danger {
    background: var(--error-bg);
    border-color: var(--error);
    color: var(--error);
}

.bib-btn-danger:hover:not(:disabled) {
    box-shadow: 0 4px 12px var(--error-bg);
}

.bib-btn.is-busy i {
    animation: bib-spin 0.9s linear infinite;
}

.bib-btn:focus-visible,
.bib-sort:focus-visible,
.bib-tag:focus-visible,
.bib-report:focus-visible {
    outline: 3px solid var(--primary-glow);
    outline-offset: 2px;
}

/* ---------- Statut (chargement, erreur, vide) ---------- */
.bib-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 48px 20px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    text-align: center;
    color: var(--text-secondary);
}

.bib-status:empty {
    display: none;
}

.bib-status > i {
    font-size: 2rem;
    color: var(--text-muted);
}

.bib-status--error > i {
    color: var(--error);
}

.bib-status p {
    max-width: 520px;
    margin: 0;
}

.bib-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: bib-spin 0.9s linear infinite;
}

@keyframes bib-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ---------- Tableau ---------- */
.bib-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    box-shadow: var(--shadow-md);
}

.bib-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.bib-table th {
    padding: 0;
    background: var(--bg-subtle);
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

.bib-sort {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
}

.bib-sort i {
    color: var(--text-muted);
    opacity: 0.6;
}

.bib-table th[aria-sort="ascending"] .bib-sort,
.bib-table th[aria-sort="descending"] .bib-sort {
    color: var(--text-primary);
}

.bib-table th[aria-sort="ascending"] .bib-sort i,
.bib-table th[aria-sort="descending"] .bib-sort i {
    color: var(--primary);
    opacity: 1;
}

[data-theme="dark"] .bib-table th[aria-sort="ascending"] .bib-sort i,
[data-theme="dark"] .bib-table th[aria-sort="descending"] .bib-sort i {
    color: var(--primary-light);
}

.bib-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    color: var(--text-secondary);
}

.bib-table tbody tr:last-child td {
    border-bottom: none;
}

.bib-table tbody tr:hover td {
    background: var(--bg-subtle);
}

/* Colonne Quiz : toute la largeur restante (les colonnes Discipline et Niveaux
   sont devenues des étiquettes) ; les autres colonnes prennent leur largeur utile. */
.bib-col-quiz,
.bib-cell-quiz {
    width: 100%;
    min-width: 320px;
}

.bib-cell-nowrap {
    white-space: nowrap;
}

.bib-cell-author {
    min-width: 110px;
    max-width: 200px;
    overflow-wrap: anywhere;
}

.bib-title {
    display: block;
    font-size: 0.98rem;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

/* Deux lignes de description au plus : la ligne reste lisible d'un coup d'œil. */
.bib-desc {
    display: -webkit-box;
    margin: 4px 0 0;
    overflow: hidden;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    font-size: 0.84rem;
    color: var(--text-muted);
}

.bib-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 6px;
}

.bib-tag {
    padding: 1px 9px;
    border: 1px solid var(--accent-line);
    border-radius: var(--radius-pill);
    background: var(--accent-soft);
    color: var(--accent-text);
    font: inherit;
    font-size: 0.74rem;
    font-weight: 700;
    line-height: 1.5;
    cursor: pointer;
}

.bib-tag:hover {
    border-color: var(--accent-text);
}

.bib-tag--discipline {
    border-color: var(--disc-line);
    background: var(--disc-soft);
    color: var(--disc-text);
}

.bib-tag--discipline:hover {
    border-color: var(--disc-text);
}

.bib-tag--niveau {
    border-color: var(--level-line);
    background: var(--level-soft);
    color: var(--level-text);
}

.bib-tag--niveau:hover {
    border-color: var(--level-text);
}

.bib-cell-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.bib-none {
    color: var(--text-muted);
}

.bib-cell-date {
    white-space: nowrap;
}

.bib-cell-actions {
    white-space: nowrap;
}

/* « Charger » puis « Signaler » en dessous, de même largeur. */
.bib-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}

.bib-btn.bib-report {
    padding: 4px 12px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.bib-btn.bib-report:hover:not(:disabled) {
    border-color: var(--error);
    background: var(--error-bg);
    color: var(--error);
}

/* Sous 760 px, chaque ligne devient une carte ; l'intitulé de colonne passe
   devant la valeur (data-label posé par bibliotheque.js). */
@media (max-width: 760px) {
    .bib-header {
        padding: 10px 16px;
    }

    .bib-nav-link span {
        display: none;
    }

    .bib-main {
        padding: 24px 16px 40px;
    }

    .bib-intro h1 {
        font-size: 1.6rem;
    }

    .bib-table-wrap {
        overflow: visible;
        border: none;
        background: transparent;
        box-shadow: none;
    }

    .bib-table thead {
        display: none;
    }

    .bib-table,
    .bib-table tbody,
    .bib-table tr,
    .bib-table td {
        display: block;
        width: 100%;
    }

    .bib-table tr {
        margin-bottom: 14px;
        padding: 14px 16px;
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        background: var(--bg-card);
        box-shadow: var(--shadow-sm);
    }

    .bib-table td {
        display: flex;
        gap: 10px;
        padding: 4px 0;
        border-bottom: none;
    }

    .bib-table tbody tr:hover td {
        background: transparent;
    }

    .bib-table td[data-label]::before {
        content: attr(data-label);
        flex: 0 0 96px;
        font-size: 0.74rem;
        font-weight: 800;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        color: var(--text-muted);
    }

    .bib-table td.bib-cell-quiz {
        display: block;
        min-width: 0;
        padding-bottom: 8px;
    }

    .bib-table td.bib-cell-author {
        max-width: none;
    }

    .bib-table td.bib-cell-quiz::before {
        display: none;
    }

    .bib-cell-num {
        text-align: left;
    }

    .bib-table td.bib-cell-actions {
        justify-content: flex-end;
        padding-top: 10px;
    }

    .bib-actions {
        flex: 1;
        flex-direction: row;
    }

    .bib-cell-actions .bib-load {
        flex: 1;
    }
}

/* ---------- Mes quiz partagés ---------- */
.bib-mine {
    margin-top: 40px;
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
}

.bib-mine h2 {
    margin: 0 0 6px;
    font-size: 1.15rem;
    color: var(--text-primary);
}

.bib-mine h2 i {
    color: var(--accent-text);
}

.bib-mine-desc,
.bib-mine-empty {
    margin: 0 0 12px;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.bib-mine-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0 0 12px;
    padding: 0;
    list-style: none;
}

.bib-mine-list:empty {
    display: none;
}

.bib-mine-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-subtle);
}

.bib-mine-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.bib-mine-info strong {
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

.bib-mine-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.bib-key-form {
    margin: 8px 0 16px;
}

.bib-key-form summary {
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-secondary);
}

.bib-key-form form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    margin-top: 12px;
}

.bib-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 200px;
}

.bib-field label {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
}

.bib-field input {
    padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font: inherit;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.bib-field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.bib-key-result {
    flex-basis: 100%;
    min-height: 1.3em;
    margin: 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.bib-key-lost {
    margin: 12px 0 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.bib-key-lost i {
    color: var(--accent-text);
}

.bib-key-lost a {
    font-weight: 700;
    color: var(--accent-text);
    overflow-wrap: anywhere;
}

.bib-rgpd {
    margin: 0;
    padding: 12px 14px;
    border-left: 4px solid var(--accent-text);
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.bib-rgpd i {
    color: var(--accent-text);
}

.bib-rgpd a {
    font-weight: 700;
    color: var(--accent-text);
    overflow-wrap: anywhere;
}

.bib-licence {
    margin: 8px 0 0;
    padding: 10px 14px;
    border-left: 4px solid var(--accent-text);
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.bib-licence i {
    color: var(--accent-text);
    margin-right: 4px;
}

.bib-licence a {
    font-weight: 700;
    color: var(--accent-text);
}

@media (max-width: 560px) {
    .bib-mine {
        padding: 18px 16px;
    }

    .bib-mine-item {
        flex-direction: column;
        align-items: stretch;
    }
}

/* ---------- Fenêtre de dialogue et message bref ---------- */
.bib-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: var(--overlay);
}

.bib-modal {
    width: 100%;
    max-width: 460px;
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    box-shadow: var(--shadow-lg);
}

.bib-modal:focus {
    outline: none;
}

.bib-modal h2 {
    margin: 0 0 8px;
    font-size: 1.15rem;
    color: var(--text-primary);
}

.bib-modal p {
    margin: 0 0 20px;
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}

/* Formulaire de signalement dans la fenêtre */
.bib-modal-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 20px;
}

/* .bib-field a flex: 1 1 200px (formulaire de suppression, en ligne) : en colonne,
   cela donnerait 200 px de haut au champ. */
.bib-modal-body .bib-field {
    flex: none;
}

.bib-report-reasons {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
    padding: 0;
    border: 0;
}

.bib-report-reasons legend {
    margin-bottom: 6px;
    padding: 0;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
}

.bib-radio {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
}

.bib-radio input {
    margin-top: 3px;
    accent-color: var(--primary);
}

.bib-field textarea {
    padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font: inherit;
    font-size: 0.9rem;
    resize: vertical;
}

.bib-field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.bib-modal-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
}

@media (max-width: 480px) {
    .bib-modal-actions .bib-btn {
        flex: 1 1 100%;
    }
}

.bib-toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 1100;
    max-width: calc(100% - 32px);
    padding: 12px 18px;
    border-radius: var(--radius-md);
    background: var(--text-primary);
    color: var(--bg-card);
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    transform: translateX(-50%);
}

@media (prefers-reduced-motion: reduce) {
    .bib-spinner,
    .bib-btn.is-busy i {
        animation-duration: 2.5s;
    }
}
