.thread-header {
    padding: 0;
    margin-bottom: 1.5em;
}

/* --- Top bar --- */
.thread-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

/* Avatar */
.thread-ai-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--secondary-color), #a78bfa);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.12);
}

.thread-ai-avatar i {
    color: #fff;
    font-size: 1rem;
}

.thread-ai-avatar::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #22c55e;
    border-radius: 50%;
    border: 2px solid #fff;
}

/* 2-line info block */
.thread-ai-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    flex: 1;
}

/* Line 1: name */
.thread-ai-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-color, #222);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Line 2: subtitle with date */
.thread-ai-line2 {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.76rem;
    color: #999;
    line-height: 1.2;
}

/* Right badges group */
.thread-badges {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    flex-shrink: 0;
    align-self: center;
}

/* Sources badge (mobile only) */
.thread-sources-mobile {
    display: none;
    align-items: center;
    gap: 4px;
    font-size: 0.65rem;
    font-weight: 600;
    color: #888;
    background: #f0f0f2;
    padding: 6px 10px;
    border-radius: 5px;
    white-space: nowrap;
}

.thread-sources-mobile i {
    font-size: 0.55rem;
    color: #aaa;
}

/* Badge IA */
.thread-ai-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #fff;
    background: linear-gradient(135deg, var(--secondary-color), #a78bfa);
    padding: 6px 10px;
    border-radius: 5px;
    white-space: nowrap;
}

.thread-ai-badge i {
    font-size: 0.58rem;
}

/* --- Divider --- */
.thread-divider {
    border: none;
    border-top: 1px solid #eee;
    margin: 0 0 14px 0;
}

/* --- Question title --- */
.thread-question {
    font-size: 1.85em;
    font-weight: 700;
    line-height: 1.25;
    color: var(--title-color, #111);
    margin: 0 0 14px 0;
    letter-spacing: -0.02em;
}

/* --- Sources row (desktop) --- */
.thread-sources {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #f8f8fa;
    border-radius: 8px;
    border: 1px solid #eeecf1;
}

.thread-sources-label {
    font-size: 0.73rem;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}

.thread-sources-label i {
    font-size: 0.75rem;
    color: #999;
}

.thread-source-pills {
    display: flex;
    gap: 5px;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    align-items: center;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

.thread-source-pills::-webkit-scrollbar {
    display: none;
}

.thread-source-pills:focus-visible {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
    border-radius: 6px;
}

.thread-source-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 20px;
    padding: 3px 9px 3px 5px;
    font-size: 0.7rem;
    color: #555;
    text-decoration: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    cursor: default;
    white-space: nowrap;
}

.thread-source-pill:hover {
    border-color: var(--secondary-color);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.thread-source-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--secondary-color);
    color: #fff;
    font-size: 0.58rem;
    font-weight: 700;
    flex-shrink: 0;
}

.thread-sources-open {
    flex-shrink: 0;
    border: 1px solid #dfdce6;
    background: #fff;
    color: #5f5b6b;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.thread-sources-open:hover {
    border-color: var(--secondary-color);
    color: var(--secondary-color);
    background: #f9ffff;
}

.thread-sources-open:focus-visible {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
}

/* --- Thread sources list in sidebar --- */
.thread-sidebar-sources {
    display: grid;
    grid-row-gap: 10px;
}

.sidebar .msx-source {
    border-radius: 10px;
    padding: 10px;
    grid-template-columns: 1fr 18px !important;
}

.sidebar .msx-source__title {
    display: -webkit-box;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.sidebar .msx-source__snippet {
    display: -webkit-box;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.sidebar .msx-source__num {
    display: none !important;
}

/* --- Mobile --- */
@media (max-width: 600px) {
    .thread-header {
        margin-bottom: 0.8em;
    }

    .thread-topbar {
        gap: 8px;
        margin-bottom: 10px;
    }

    .thread-ai-avatar {
        width: 32px;
        height: 32px;
    }

    .thread-ai-avatar i {
        font-size: 0.85rem;
    }

    .thread-ai-avatar::after {
        width: 8px;
        height: 8px;
        border-width: 1.5px;
    }

    .thread-ai-name {
        font-size: 0.82rem;
    }

    .thread-ai-line2 {
        font-size: 0.68rem;
    }

    .thread-ai-badge {
        padding: 5px 8px;
        font-size: 0.63rem;
    }

    .thread-sources-mobile {
        display: inline-flex;
        padding: 5px 8px;
        font-size: 0.6rem;
    }

    .thread-question {
        font-size: 1.25em;
        margin: 0 0 10px 0;
    }

    .thread-sources {
        display: none;
    }
}

/* =========================================
   TABLE SCROLLER (wrapper) + TABLE STYLES
   (center-align ALL table content)
   ========================================= */

.table-scroll {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, .10);
    background: #fff;
    margin: 18px 0;
}

.table-scroll::-webkit-scrollbar {
    height: 10px;
}

.table-scroll::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, .06);
    border-radius: 999px;
}

.table-scroll::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, .22);
    border-radius: 999px;
}

.table-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, .32);
}

@media (max-width: 768px) {
    .table-scroll {
        background-image:
            linear-gradient(to right, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0)),
            linear-gradient(to left, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0));
        background-position: left center, right center;
        background-repeat: no-repeat;
        background-size: 20px 100%, 20px 100%;
        background-attachment: local, local;
    }
}

/* Keep table as a real table (no display hacks) */
.post-content-area .table-scroll>table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    min-width: 100%;
    margin: 0;
    background: transparent;
    border: 0;
}

/* Head */
.post-content-area .table-scroll>table thead th {
    background: rgba(0, 0, 0, .04);
    font-weight: 850;
    color: rgba(17, 24, 39, .92);
    border-bottom: 1px solid rgba(0, 0, 0, .10);
}

/* Center-align EVERYTHING (th + td) */
.post-content-area .table-scroll>table th,
.post-content-area .table-scroll>table td {
    padding: 12px 12px;
    text-align: center;
    /* ✅ center */
    vertical-align: middle;
    /* ✅ center vertically */
    border-bottom: 1px solid rgba(0, 0, 0, .08);
}

/* If a cell has a pill/button, keep it nicely centered too */
.post-content-area .table-scroll>table th .msx-inline-pill,
.post-content-area .table-scroll>table td .msx-inline-pill {
    margin: 0 auto;
    display: inline-flex;
    justify-content: center;
}

/* Zebra + hover */
.post-content-area .table-scroll>table tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, .02);
}

.post-content-area .table-scroll>table tbody tr:last-child td {
    border-bottom: 0;
}

/* Mobile: force horizontal scrolling */
@media (max-width: 768px) {
    .post-content-area .table-scroll>table {
        min-width: 720px;
    }

    .post-content-area .table-scroll>table th,
    .post-content-area .table-scroll>table td {
        white-space: nowrap;
        font-size: 0.92em;
    }
}
