/* ==========================================================================
   Module : Responsive Mobile & Animations AJAX
   ========================================================================== */

/* --- Corrections Layout & Overrides --- */
main.site-main:has(.ttb-forum-wrapper),
main.site-main > .content-area:has(.ttb-forum-wrapper) {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* Styles pour le wrapper principal */
.ttb-forum-wrapper {
    width: 100% !important;
    max-width: var(--max-width-forum) !important;
    min-width: 0 !important;
    margin-left: auto !important;
    margin-right: auto !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
    position: relative;
}

/* Conteneurs internes au forum */
.ttb-forum-wrapper .ttb-content-wrapper-outer,
.ttb-forum-wrapper .ttb-main-container,
.ttb-forum-wrapper .ttb-content-area {
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
}

/* Styles spécifiques pour mobile */
@media (max-width: 991.98px) {
    .ttb-forum-wrapper {
        max-width: 100vw !important;
        padding-left: var(--space-sm, 8px);
        padding-right: var(--space-sm, 8px);
    }

    .ttb-sidebar-left {
        box-sizing: border-box !important;
    }
}

/* Styles pour la classe de correction JS */
.ttb-forum-wrapper.js-layout-corrected {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

/* --- Responsive Mobile (max-width: 991.98px) --- */
@media (max-width: 991.98px) {
    body, html {
        overflow-x: hidden;
    }
    main.site-main,
    div.content-area {
        max-width: 100vw !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }
}

@media (max-width: 991.98px) {

    .ttb-forum-wrapper.js-layout-corrected {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

    /* Affichage du bouton de bascule mobile */
    .ttb-mobile-sidebar-toggle-btn {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        position: fixed;
        right: 15px;
        left: auto;
        bottom: 37.5vh;
        z-index: 1050;
        background-color: var(--clr-accent-gold);
        color: var(--clr-bg-page);
        border: none;
        clip-path: var(--chamfer-sm);
        width: 2.5rem;
        height: auto;
        min-height: 4.375rem;
        padding: var(--space-sm) 0.25rem;
        cursor: pointer;
        box-shadow: 0 2px 6px rgba(0,0,0,0.25);
        opacity: 0.85;
        transition: background-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    }

    /* Icône hamburger animée (3 barres → croix) */
    .ttb-hamburger-icon {
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        width: 22px;
        height: 22px;
    }
    .ttb-hamburger-icon span {
        display: block;
        width: 100%;
        height: 2px;
        background-color: currentColor;
        border-radius: 1px;
        transition: transform 0.3s ease, opacity 0.3s ease;
    }
    .ttb-mobile-sidebar-toggle-btn.ttb-sidebar-is-open .ttb-hamburger-icon span:nth-child(1) {
        transform: translateY(7px) rotate(45deg);
    }
    .ttb-mobile-sidebar-toggle-btn.ttb-sidebar-is-open .ttb-hamburger-icon span:nth-child(2) {
        opacity: 0;
    }
    .ttb-mobile-sidebar-toggle-btn.ttb-sidebar-is-open .ttb-hamburger-icon span:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg);
    }

    /* Étiquette texte du bouton */
    .ttb-toggle-label {
        font-size: 0.5625rem;
        font-weight: 700;
        letter-spacing: 0.1em;
        text-transform: uppercase;
        line-height: 1;
    }
    .ttb-mobile-sidebar-toggle-btn.ttb-sidebar-is-open .ttb-toggle-label {
        display: none;
    }

    .ttb-mobile-sidebar-toggle-btn:hover,
    .ttb-mobile-sidebar-toggle-btn:focus,
    .ttb-mobile-sidebar-toggle-btn.ttb-sidebar-is-open {
        background-color: var(--clr-accent-gold-darker);
        box-shadow: 0 4px 10px rgba(0,0,0,0.3);
        opacity: 1;
    }

    .ttb-sidebar-left {
        position: fixed !important;
        left: 0;
        right: auto;
        top: 0;
        height: 100vh !important;
        width: 280px !important;
        max-width: 85% !important;
        z-index: 1040 !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease-out, box-shadow 0.3s ease-out !important;
        overflow-y: auto !important;
        box-shadow: none !important;
        background-color: var(--clr-bg-sidebar) !important;
        clip-path: none !important;
        padding-top: calc(var(--space-md) + 2.5rem) !important;
        padding-left: var(--space-md) !important;
        padding-right: var(--space-md) !important;
        padding-bottom: var(--space-md) !important;
        box-sizing: border-box !important;
    }

    .ttb-sidebar-left.ttb-sidebar-is-open {
        transform: translateX(0) !important;
        box-shadow: 5px 0 15px rgba(0,0,0,0.2) !important;
    }

    /* Bouton de fermeture interne à la sidebar */
    .ttb-sidebar-close-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        position: absolute !important;
        top: var(--space-sm);
        right: var(--space-sm);
        background: transparent;
        border: none;
        color: var(--clr-text-secondary);
        width: 2.5rem;
        height: 2.5rem;
        padding: 0;
        cursor: pointer;
        z-index: 10;
    }
    .ttb-sidebar-close-btn:hover {
        color: var(--clr-text-link-hover);
    }
    .ttb-sidebar-close-btn svg {
         width: 1.5rem;
         height: 1.5rem;
         fill: currentColor;
    }

    body.ttb-mobile-sidebar-active::after {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0,0,0,0.5);
        z-index: 1030;
    }

    .ttb-main-container {
         gap: 0;
    }
    .ttb-content-area {
        width: 100%;
        margin-left: 0;
    }

    .ttb-header-bar .boards-nav {
        display: grid;
        grid-template-columns: auto auto;
        grid-template-rows: auto auto auto;
        column-gap: var(--space-md);
        row-gap: var(--space-sm);
        align-items: center;
    }
    .ttb-header-bar .boards-nav .sort-by-label {
        display: none;
    }
    .ttb-header-bar .boards-nav a:not(.ttb-refresh-btn) {
        grid-column: 1;
        margin-left: 0;
        justify-self: start;
        padding-bottom: 2px;
    }
    .ttb-header-bar .boards-nav a:not(.ttb-refresh-btn)::after {
        will-change: transform;
    }
    .ttb-header-bar .boards-nav .ttb-sort-tooltip-trigger {
        grid-column: 2;
        grid-row: 1;
        align-self: start;
        justify-self: center;
        margin-left: 0;
    }
    .ttb-header-bar .boards-nav .ttb-refresh-btn {
        grid-column: 2;
        grid-row: 3;
        align-self: end;
        justify-self: center;
        margin-left: 0;
    }

    .ttb-thread-item {
        display: grid;
        grid-template-columns: auto auto 1fr;
        grid-template-rows: auto auto auto;
        column-gap: var(--space-md);
        row-gap: var(--space-xs);
        align-items: start;
        padding: var(--space-md) 0;
    }

    .ttb-thread-item {
        display: grid;
        grid-template-columns: auto auto 1fr;
        grid-template-rows: auto auto auto;
        column-gap: var(--space-md);
        row-gap: var(--space-xs);
        align-items: center;
    }


    .ttb-thread-vote-display {
        grid-column: 1;
        grid-row: 1 / span 3;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        align-self: center;
    }
    .ttb-thread-vote-display .ttb-vote-count {
        font-size: var(--font-size-lg);
        margin-bottom: 2px;
        line-height: 1;
    }
    .ttb-thread-vote-display .ttb-vote-label {
        font-size: 0.625rem;
        text-transform: uppercase;
        color: var(--clr-text-secondary);
        display: block;
    }
    .ttb-thread-vote-display .vote-score-details {
        display: none !important;
    }
    .ttb-thread-vote-display:hover .vote-score-net {
        opacity: 1;
        visibility: visible;
    }

    .ttb-thread-avatar {
        grid-column: 2;
        grid-row: 1 / span 3;
        display: flex;
        align-items: center;
        align-self: center;
    }
    .ttb-thread-avatar img {
        width: 44px;
        height: 44px;
    }

    .ttb-thread-main-content {
        grid-column: 3;
        grid-row: 1 / span 2;
        display: flex;
        flex-direction: column;
        justify-content: center;
        min-width: 0;
    }

    .ttb-thread-main-content .title {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        font-size: var(--font-size-lg);
        line-height: 1.3;
        margin-bottom: var(--space-xs);
    }
    .ttb-thread-main-content .title a {
        display: block;
        color: var(--clr-text-heading);
    }
     .ttb-thread-main-content .title a:hover {
        color: var(--clr-text-link-hover);
    }
    .ttb-thread-main-content .title .ttb-pinned-icon {
        display: inline-block;
        vertical-align: middle;
        margin-right: var(--space-xs);
        font-size: 0.9em;
    }


    .ttb-thread-main-content .meta {
        font-size: var(--font-size-sm);
        color: var(--clr-text-secondary);
        line-height: 1.4;
    }

    .ttb-thread-stats {
        grid-column: 3;
        grid-row: 3;
        display: flex;
        align-items: center;
        gap: var(--space-md);
        padding-top: var(--space-sm);
    }

    .ttb-thread-locked-icon {
        font-size: var(--font-size-base);
        color: var(--clr-text-secondary);
    }

    .ttb-thread-stats .stat-item {
        display: flex;
        flex-direction: row;
        align-items: baseline;
        gap: var(--space-xs);
        min-width: auto;
    }
    .ttb-thread-stats .stat-item .count {
        font-size: var(--font-size-sm);
        color: var(--clr-text-primary);
    }
    .ttb-thread-stats .stat-item .label {
        font-size: calc(var(--font-size-sm) * 0.85);
        text-transform: uppercase;
        color: var(--clr-text-secondary);
    }
}

/* --- Animations AJAX --- */
.ttb-content-area {
    animation-duration: 0.4s;
    animation-fill-mode: forwards;
}

@keyframes simple-fade-out-up {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}

@keyframes simple-fade-in {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Light Mode Mobile --- */
@media (max-width: 991.98px) {

    html.light-mode .ttb-sidebar-left {
        background-color: var(--color-component-background) !important;
    }

    html.light-mode .ttb-sidebar-left .ttb-sidebar-section h2,
    html.light-mode .ttb-sidebar-left .ttb-parent-category-title {
        color: var(--color-text-heading, #4A3B31);
        border-bottom-color: var(--clr-divider, #E0D5C1);
    }

    html.light-mode .ttb-sidebar-left .rules-text {
        color: var(--color-text-secondary);
    }

    html.light-mode .ttb-sidebar-left .ttb-parent-category-title.active-parent-group {
        color: var(--clr-accent-gold);
    }

    html.light-mode .ttb-sidebar-left .ttb-boards-list ul li a,
    html.light-mode .ttb-sidebar-left .ttb-child-board-list li a {
        color: var(--color-text-secondary);
    }

    html.light-mode .ttb-sidebar-left .ttb-boards-list ul li a:hover,
    html.light-mode .ttb-sidebar-left .ttb-child-board-list li a:hover,
    html.light-mode .ttb-sidebar-left .ttb-boards-list ul li a.active,
    html.light-mode .ttb-sidebar-left .ttb-child-board-list li a.active {
        color: var(--clr-text-link);
    }

    html.light-mode .ttb-sidebar-left .ttb-hr-separator {
        background-color: var(--clr-divider, #E0D5C1);
    }

    html.light-mode .ttb-sidebar-left .ttb-sidebar-close-btn {
        color: var(--color-text-secondary) !important;
    }

    html.light-mode .ttb-sidebar-left .ttb-sidebar-close-btn:hover {
        color: var(--color-text) !important;
    }

    /* ==========================================================================
       Profondeur commentaires : réduction progressive de l'indentation mobile
       ========================================================================== */

    .ttb-comments-wrapper ol.comment-list ul.children,
    .ttb-comments-wrapper ol.comment-list ol.children {
        margin-left: 8px;
        padding-left: 0.875rem;
    }

    .ttb-comments-wrapper ol.comment-list .children > .ttb-comment-item::before {
        left: -14px;
        width: 10px;
    }

    .ttb-comments-wrapper .children .ttb-thread-line-hitbox {
        left: -8px;
    }

    .ttb-comments-wrapper .children .children .children {
        margin-left: 4px;
        padding-left: 0.625rem;
    }

    .ttb-comments-wrapper .children .children .children > .ttb-comment-item::before {
        left: -10px;
        width: 6px;
    }

    .ttb-comments-wrapper .children .children .children .children {
        margin-left: 0;
        padding-left: 0.5rem;
        border-left-width: 1px;
    }

    .ttb-comments-wrapper .children .children .children .children > .ttb-comment-item::before {
        display: none;
    }

    .ttb-comments-wrapper .children .ttb-thread-toggle-btn {
        width: 1.125rem;
        height: 1.125rem;
        font-size: 0.6875rem;
        line-height: 1.3;
        left: -2px;
    }
}

/* ── Ajustements barre admin WordPress ── */
@media (max-width: 991.98px) {
    .admin-bar .ttb-sidebar-left {
        top: 32px !important;
        height: calc(100vh - 32px) !important;
    }
}
@media (max-width: 782px) {
    .admin-bar .ttb-sidebar-left {
        top: 46px !important;
        height: calc(100vh - 46px) !important;
    }
}
