/* ***************** SIDEBAR **************** */
/* Desktop premium : réduite par défaut, développable, mobile inchangé */
:root {
    --sidebar-w-collapsed: 86px;
    --sidebar-w-expanded: clamp(260px, 21vw, 320px);
    --sidebar-w: var(--sidebar-w-collapsed);
    --sidebar-bg: #f7f7f8;
    --sidebar-border: rgba(15, 23, 42, 0.08);
    --sidebar-text: #111827;
    --sidebar-muted: #6b7280;
    --sidebar-hover: #eceff3;
    --sidebar-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --sidebar-collapsed-cell-size: calc(var(--sidebar-w-collapsed) / 3);
    --sidebar-collapsed-grid-line: rgba(194, 230, 250, 0.022);

    --sidebar-logo-deep: rgb(17, 35, 87);
    --sidebar-logo-indigo: rgb(39, 59, 125);
    --sidebar-logo-royal: rgb(43, 88, 176);
    --sidebar-logo-azure: rgb(28, 140, 205);
    --sidebar-logo-cyan: rgb(38, 178, 236);
    --sidebar-logo-ice: rgb(130, 213, 228);
    --sidebar-logo-pale: rgb(228, 244, 255);
}

body.sidebar-expanded {
    --sidebar-w: var(--sidebar-w-expanded);
}

body.sidebar-collapsed {
    --sidebar-w: var(--sidebar-w-collapsed);
}

.sidebar {
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    width: var(--sidebar-w);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    padding: 14px 12px;
    /*border-right: 1px solid var(--sidebar-border);*/
    box-shadow: var(--sidebar-shadow);
    z-index: 802;
    box-sizing: border-box;
    overflow: hidden;
    transition: width 0.24s ease, padding 0.24s ease, box-shadow 0.24s ease;
}

.sidebar-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 48px;
    margin-bottom: 14px;
}

.sidebar-title {
    position: static;
    margin: 0;
    padding: 0;
    flex: 1 1 auto;
    min-width: 0;
    display: block;
    font-size: 1rem;
    font-weight: 700;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    text-decoration: none;
    color: inherit;
}

.sidebar-brand:hover {
    text-decoration: none;
}

.sidebar-brand-icon {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 12px;
    object-fit: cover;
    display: block;
}

.sidebar-brand-text {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 1.02rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.sidebar-toggle {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 1px solid var(--sidebar-border);
    background: #ffffff;
    border-radius: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--sidebar-text);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.sidebar-toggle:hover {
    background-color: var(--sidebar-hover);
    border-color: rgba(15, 23, 42, 0.14);
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.10);
}

.sidebar-toggle:focus-visible {
    outline: none;
    border-color: rgba(37, 99, 235, 0.28);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.10);
}

.sidebar-toggle-icon-wrap {
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.sidebar-toggle-icon {
    display: block;
    line-height: 1;
}

.sidebar-toggle-icon-svg {
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    object-fit: contain;
    opacity: 0.92;
    transition: transform 0.22s ease, opacity 0.2s ease;
}

body.sidebar-expanded .sidebar .sidebar-toggle-icon-svg,
.sidebar.sidebar-expanded .sidebar-toggle-icon-svg {
    transform: scaleX(-1);
    opacity: 1;
}

body.sidebar-collapsed .sidebar .sidebar-toggle,
.sidebar.sidebar-collapsed .sidebar-toggle {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    border-radius: 13px;
}

body.sidebar-collapsed .sidebar .sidebar-toggle-icon-wrap,
.sidebar.sidebar-collapsed .sidebar-toggle-icon-wrap,
body.sidebar-collapsed .sidebar .sidebar-toggle-icon-svg,
.sidebar.sidebar-collapsed .sidebar-toggle-icon-svg {
    width: 19px;
    height: 19px;
    min-width: 19px;
    min-height: 19px;
}

.sidebar-content {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    box-sizing: border-box;
    flex: 1 1 auto;
    min-height: 0;
    padding-top: 0;
}

.sidebar-intro {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    margin-bottom: 16px;
    padding: 0 4px;
    box-sizing: border-box;
}

.sidebar-description {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--sidebar-muted);
}

.sidebar-create-btn {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;
    background-color: #ffffff;
    color: var(--sidebar-text);
    font-size: 0.95rem;
    font-weight: 600;
    border: 1px solid var(--sidebar-border);
    border-radius: 14px;
    cursor: pointer;
    margin-bottom: 18px;
    box-sizing: border-box;
    text-decoration: none;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    box-shadow: none;
}

.sidebar-create-btn img.create-icon {
    width: 20px;
    height: 20px;
    min-width: 20px;
    vertical-align: middle;
    filter: brightness(0) saturate(100%) invert(42%) sepia(92%) saturate(5577%) hue-rotate(15deg) brightness(231%) contrast(178%);
}

.sidebar-create-btn:hover {
    background-color: var(--sidebar-hover);
    border-color: rgba(15, 23, 42, 0.14);
    color: var(--sidebar-text);
    text-decoration: none;
}

.sidebar-history-toolbar {
    width: 100%;
    padding: 0 2px 10px;
    box-sizing: border-box;
}

.sidebar-history-search {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    background: #ffffff;
    border: 1px solid var(--sidebar-border);
    border-radius: 14px;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.sidebar-history-search:focus-within {
    border-color: rgba(37, 99, 235, 0.24);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
}

.sidebar-history-search-icon {
    color: #9ca3af;
    font-size: 0.92rem;
    line-height: 1;
    flex: 0 0 auto;
}

.sidebar-history-search-input {
    width: 100%;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--sidebar-text);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.76rem;
    line-height: 1.3;
    padding: 0;
}

.sidebar-history-search-input::placeholder {
    color: #9ca3af;
}

.sidebar-history-empty {
    margin: 0 2px 12px;
    padding: 12px;
    border: 1px dashed var(--sidebar-border);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.75);
    color: var(--sidebar-muted);
    font-size: 0.74rem;
    line-height: 1.45;
    text-align: center;
}

.sidebar-history {
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    padding: 0 2px 12px;
    box-sizing: border-box;
    font-family: 'Montserrat', sans-serif;
    color: var(--sidebar-text);
    overflow-y: auto;
}

.sidebar-history::-webkit-scrollbar {
    width: 6px;
}

.sidebar-history::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-history::-webkit-scrollbar-thumb {
    background-color: rgba(15, 23, 42, 0.16);
    border-radius: 999px;
}

.sidebar-history::-webkit-scrollbar-thumb:hover {
    background-color: rgba(15, 23, 42, 0.28);
}

.questions-container {
    display: block;
}

.history-date {
    margin-bottom: 8px;
    padding-top: 6px;
}

.history-date p {
    font-family: 'Montserrat', sans-serif;
    cursor: pointer;
    font-style: normal;
    text-align: left;
    font-weight: 700;
    font-size: 0.66rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin: 0;
    color: #9ca3af;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    padding: 0 12px;
    border-radius: 14px;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.history-item:hover {
    background-color: var(--sidebar-hover);
}

.history-main-link {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    text-decoration: none;
    color: inherit;
}

.history-main-link:hover {
    text-decoration: none;
    color: inherit;
}

.history-assistant-avatar-wrap {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    border-radius: 999px;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
}

.history-assistant-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.history-main-copy {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.history-summary {
    display: block;
    color: var(--sidebar-text);
    font-size: 0.79rem;
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-question-raw {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    color: var(--sidebar-muted);
    font-size: 0.68rem;
    line-height: 1.35;
}

.history-inline-thumb {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    border-radius: 10px;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.08);
}

.history-inline-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.history-item .delete-history {
    cursor: pointer;
    color: #94a3b8;
    background-color: transparent;
    border-radius: 10px;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    font-size: 1rem;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.history-item .delete-history:hover {
    color: var(--sidebar-text);
    background-color: #ffffff;
    border-color: var(--sidebar-border);
}

.sidebar-info {
    text-align: left;
    width: 100%;
    border-top: 1px solid var(--sidebar-border);
    padding-top: 16px;
    margin-top: auto;
}

.sidebar-info h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--sidebar-text);
    margin: 0 0 10px;
}

.sidebar-info p {
    font-size: 0.82rem;
    color: var(--sidebar-muted);
    margin: 0 0 14px;
    line-height: 1.5;
    text-align: left;
}

.sidebar-learn-more-btn,
.sidebar-register-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 12px 14px;
    border-radius: 14px;
    text-align: center;
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 600;
    box-sizing: border-box;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.sidebar-learn-more-btn {
    background-color: #ffffff;
    color: var(--sidebar-text);
    border: 1px solid var(--sidebar-border);
    margin-bottom: 10px;
}

.sidebar-learn-more-btn:hover {
    background-color: var(--sidebar-hover);
}

.sidebar-register-btn {
    background-color: #111827;
    color: #ffffff;
    border: 1px solid #111827;
    margin-top: 0;
    margin-bottom: 0;
}

.sidebar-register-btn:hover {
    background-color: #000000;
}

.sidebar-user-info {
    font-family: 'Montserrat', sans-serif;
    display: flex;
    align-items: center;
    position: static;
    width: 100%;
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--sidebar-border);
    box-sizing: border-box;
}

.sidebar-user-info a {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 8px;
    border-radius: 14px;
    text-decoration: none !important;
    color: inherit;
    box-sizing: border-box;
    transition: background-color 0.2s ease;
}

.sidebar-user-info a:hover {
    background-color: var(--sidebar-hover);
}

.sidebar-user-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 50%;
    margin-right: 0;
    object-fit: cover;
}

.sidebar-user-name {
    display: block;
    color: var(--sidebar-text);
    font-weight: 600;
    font-size: 0.88rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-collapsed-grid {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-rows: var(--sidebar-collapsed-cell-size);
    pointer-events: none;
    overflow: hidden;
}

.sidebar-collapsed-cell {
    position: relative;
    display: block;
    width: 100%;
    height: var(--sidebar-collapsed-cell-size);
    box-shadow:
        inset -1px 0 0 var(--sidebar-collapsed-grid-line),
        inset 0 -1px 0 var(--sidebar-collapsed-grid-line);
}

.sidebar-collapsed-cell::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(
            135deg,
            rgba(186, 234, 246, 0.040) 0%,
            rgba(186, 234, 246, 0.010) 48%,
            rgba(10, 38, 108, 0.012) 100%
        );
}

/* État réduit */
body.sidebar-collapsed .sidebar,
.sidebar.sidebar-collapsed {
    background: transparent;
}

body.sidebar-collapsed .sidebar .sidebar-collapsed-grid,
.sidebar.sidebar-collapsed .sidebar-collapsed-grid {
    display: grid;
}

body.sidebar-collapsed .sidebar > *:not(.sidebar-collapsed-grid),
.sidebar.sidebar-collapsed > *:not(.sidebar-collapsed-grid) {
    position: relative;
    z-index: 1;
}

body.sidebar-collapsed .sidebar .sidebar-topbar,
.sidebar.sidebar-collapsed .sidebar-topbar {
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
}

body.sidebar-collapsed .sidebar .sidebar-brand,
.sidebar.sidebar-collapsed .sidebar-brand {
    justify-content: center;
}

body.sidebar-collapsed .sidebar .sidebar-brand-text,
.sidebar.sidebar-collapsed .sidebar-brand-text,
body.sidebar-collapsed .sidebar .sidebar-description,
.sidebar.sidebar-collapsed .sidebar-description,
body.sidebar-collapsed .sidebar .sidebar-history-toolbar,
.sidebar.sidebar-collapsed .sidebar-history-toolbar,
body.sidebar-collapsed .sidebar .sidebar-history,
.sidebar.sidebar-collapsed .sidebar-history,
body.sidebar-collapsed .sidebar .sidebar-history-empty,
.sidebar.sidebar-collapsed .sidebar-history-empty,
body.sidebar-collapsed .sidebar .sidebar-info,
.sidebar.sidebar-collapsed .sidebar-info,
body.sidebar-collapsed .sidebar .sidebar-user-name,
.sidebar.sidebar-collapsed .sidebar-user-name {
    display: none;
}

body.sidebar-collapsed .sidebar .sidebar-content,
.sidebar.sidebar-collapsed .sidebar-content {
    align-items: center;
}

body.sidebar-collapsed .sidebar .sidebar-create-btn,
.sidebar.sidebar-collapsed .sidebar-create-btn {
    width: 48px;
    min-width: 48px;
    padding: 12px;
    justify-content: center;
    gap: 0;
    font-size: 0;
    border-radius: 14px;
    margin-bottom: 16px;
}

body.sidebar-collapsed .sidebar .sidebar-user-info,
.sidebar.sidebar-collapsed .sidebar-user-info {
    width: 100%;
    border-top: 0;
    padding-top: 0;
}

body.sidebar-collapsed .sidebar .sidebar-user-info a,
.sidebar.sidebar-collapsed .sidebar-user-info a {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

body.sidebar-collapsed .sidebar .sidebar-user-avatar,
.sidebar.sidebar-collapsed .sidebar-user-avatar {
    margin-right: 0;
}

/* Mobile inchangé */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }
}