/* ============================================================
   Tableaux pédagogiques — surcharges DA Habari sur Tabulator
   ============================================================ */

/* ── Toolbar admin ────────────────────────────────────────── */

.habari-tableau-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    margin-bottom: 8px;
    background: #f6f7f7;
    border: 1px solid #c3c4c7;
    border-radius: 0;
}

.habari-tableau-toolbar .habari-tableau-label {
    font-weight: 600;
    font-size: 12px;
}

.habari-tableau-toolbar select {
    margin: 0 6px 0 0;
}

.habari-tableau-toolbar .habari-tableau-sep {
    width: 1px;
    height: 22px;
    background: #c3c4c7;
    margin: 0 4px;
}

.habari-tableau-toolbar .button {
    font-size: 12px;
    border-radius: 0;
}

.habari-tableau-color {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
}

.habari-tableau-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    cursor: pointer;
}

.habari-tableau-color input[type="color"] {
    width: 28px;
    height: 24px;
    padding: 0;
    border: 1px solid #8c8f94;
    background: #fff;
    cursor: pointer;
}

/* ── Conteneur Tabulator ──────────────────────────────────── */

#habari-tableau-editor {
    background: #fff;
    border: 1px solid #c3c4c7;
}

/* ── Handle numéros de ligne (#) ─────────────────────────── */

#habari-tableau-editor .habari-rh-cell {
    background: #f6f7f7 !important;
    color: #8c8f94;
    font-size: 11px;
    cursor: pointer;
    user-select: none;
}

#habari-tableau-editor .habari-rh-cell:hover {
    background: #e5e7e9 !important;
    color: #1a1a1a;
}

/* ── Sélection ligne (clic sur le numéro) ────────────────── */

.tabulator-row.habari-row-selected > .tabulator-cell {
    background: rgba(3, 34, 77, 0.08) !important;
}

/* ── Sélection colonne (clic sur l'en-tête) ─────────────── */

.tabulator .tabulator-header .tabulator-col.habari-col-selected {
    background: rgba(3, 34, 77, 0.15) !important;
}

.tabulator-cell.habari-col-selected {
    background: rgba(3, 34, 77, 0.06) !important;
}

/* Reset border-radius Tabulator (DA Habari = angles droits) */
.tabulator,
.tabulator .tabulator-header,
.tabulator .tabulator-header .tabulator-col,
.tabulator .tabulator-cell,
.tabulator .tabulator-footer,
.tabulator-edit-list,
.tabulator-popup,
.tabulator-menu {
    border-radius: 0 !important;
}

/* Fond neutre, accent navy au focus uniquement.
   Mêmes paddings entête / corps pour que l'utilisateur règle lui-même les largeurs. */

.tabulator,
.tabulator .tabulator-header,
.tabulator .tabulator-row {
    background: #fff;
}

.tabulator .tabulator-header {
    border-bottom: 1px solid #e5e5e5;
}

.tabulator .tabulator-header .tabulator-col {
    background: transparent;
    color: var(--habari-dark-1, #1a1a1a);
    font-weight: 600;
    border-right: 1px solid #ececec;
}

.tabulator .tabulator-cell {
    padding: 8px 12px;
    font-family: inherit;
    font-size: 14px;
    color: var(--habari-dark-1, #1a1a1a);
}

/* L'entête : padding sur l'élément interne pour que l'input d'édition
   remplisse toute la cellule (pas d'espace mort autour). */
.tabulator .tabulator-header .tabulator-col .tabulator-col-content {
    padding: 0;
}

.tabulator .tabulator-header .tabulator-col .tabulator-col-title-holder,
.tabulator .tabulator-header .tabulator-col .tabulator-col-title {
    padding: 0;
}

.tabulator .tabulator-header .tabulator-col .tabulator-col-title {
    padding: 8px 12px;
    font-family: inherit;
    font-size: 14px;
    color: var(--habari-dark-1, #1a1a1a);
    width: 100%;
    box-sizing: border-box;
}

.tabulator .tabulator-row {
    border-bottom: 1px solid #ececec;
    min-height: 0;
}

.tabulator .tabulator-cell {
    border-right: 1px solid #ececec;
    white-space: normal;       /* autorise le wrap du contenu */
    overflow: visible;
    text-overflow: clip;
    height: auto !important;   /* hauteur s'adapte au contenu */
}

/* Focus / cellule active : juste un liseré navy 1 px, pas de fond */
.tabulator .tabulator-cell.habari-tableau-active,
.tabulator .tabulator-cell.tabulator-editing,
.tabulator .tabulator-header .tabulator-col.tabulator-editing {
    box-shadow: inset 0 0 0 1px var(--habari-secondary-navy, #03224D);
    background: #fff;
}

.tabulator .tabulator-cell.tabulator-editing input,
.tabulator .tabulator-cell.tabulator-editing textarea,
.tabulator .tabulator-header .tabulator-col.tabulator-editing input,
.tabulator .tabulator-header .tabulator-col-title input {
    margin: 0 !important;
    padding: 8px 12px !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    outline: none !important;
    min-height: 0 !important;
    line-height: 1.4 !important;
    font: inherit !important;
    color: inherit !important;
    width: 100% !important;
    height: 100% !important;
    box-sizing: border-box !important;
}

/* La cellule en édition n'ajoute pas son propre padding —
   l'input fait toute la taille de la cellule. */
.tabulator .tabulator-cell.tabulator-editing {
    padding: 0 !important;
}

.tabulator .tabulator-header .tabulator-col.tabulator-editing .tabulator-col-title {
    padding: 0;
}

/* Footer / pagination */
.tabulator .tabulator-footer {
    background: #f6f7f7;
    border-top: 1px solid #c3c4c7;
    color: var(--habari-dark-2, #333);
    font-size: 13px;
}

.tabulator .tabulator-footer .tabulator-footer-contents {
    flex-wrap: wrap;
    gap: 4px;
}

.tabulator .tabulator-footer .tabulator-paginator {
    flex-wrap: wrap;
    gap: 4px;
    row-gap: 6px;
}

.tabulator .tabulator-footer .tabulator-page {
    border-radius: 0;
    background: #fff;
    border: 1px solid #c3c4c7;
    color: var(--habari-dark-1, #1a1a1a);
    margin: 0 2px;
    padding: 4px 10px;
    white-space: nowrap;
}

.tabulator .tabulator-footer .tabulator-page.active {
    background: var(--habari-primary-brand, #9E2E2E);
    color: #fff;
    border-color: var(--habari-primary-brand, #9E2E2E);
}

.tabulator .tabulator-footer .tabulator-page:not(.disabled):hover {
    background: var(--habari-primary-brand, #9E2E2E);
    color: #fff;
}

/* ── Responsive tableau ────────────────────────────────────── */

@media screen and (max-width: 640px) {
    .apprendre-tableau-search input {
        max-width: 100%;
    }

    .tabulator .tabulator-footer {
        font-size: 12px;
    }

    .tabulator .tabulator-footer .tabulator-page {
        padding: 4px 7px;
        margin: 0 1px;
    }

    /* Raccourcir "Précédent" → "‹" et "Suivant" → "›" sur mobile */
    .tabulator .tabulator-footer .tabulator-page[data-page="prev"] {
        font-size: 0;
    }
    .tabulator .tabulator-footer .tabulator-page[data-page="prev"]::after {
        content: '‹';
        font-size: 14px;
    }
    .tabulator .tabulator-footer .tabulator-page[data-page="next"] {
        font-size: 0;
    }
    .tabulator .tabulator-footer .tabulator-page[data-page="next"]::after {
        content: '›';
        font-size: 14px;
    }

    /* Masquer Premier / Dernier sur petits écrans */
    .tabulator .tabulator-footer .tabulator-page[data-page="first"],
    .tabulator .tabulator-footer .tabulator-page[data-page="last"] {
        display: none;
    }
}

/* ── Frontend wrap ────────────────────────────────────────── */

.apprendre-tableau-wrap {
    margin: 24px 0;
}

.apprendre-tableau-title {
    font-family: var(--habari-font-heading, Georgia, serif);
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 10px;
    color: var(--habari-dark-1, #1a1a1a);
}

.apprendre-tableau {
    background: #fff;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Barre de recherche frontend (injectée par JS) */
.apprendre-tableau-search {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.apprendre-tableau-search input {
    flex: 1;
    max-width: 320px;
    padding: 8px 12px;
    border: 1px solid #c3c4c7;
    border-radius: 0;
    font-size: 14px;
    background: #fff;
}

.apprendre-tableau-search input:focus {
    outline: 2px solid var(--habari-primary-brand, #9E2E2E);
    outline-offset: -1px;
}

/* Verrou LM+ */
.apprendre-tableau-locked {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    background: #f6f7f7;
    border: 1px dashed #8c8f94;
    color: var(--habari-dark-2, #333);
    font-style: italic;
    margin: 24px 0;
}

.apprendre-tableau-locked .habari-apprendre-lock {
    font-size: 14px;
    flex-shrink: 0;
}

/* ── Hover lignes ─────────────────────────────────────────── */

@media (hover: hover) and (pointer: fine) {
    .tabulator-row.tabulator-selectable:hover {
        background-color: var(--habari-primary-brand-off, #f9ecea);
        cursor: pointer;
    }
}
