/* ================= RESET ================= */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}

body {
    background: #eef5ff;
    height: 100dvh;
    overflow: hidden;
}

/* ================= HEADER ================= */
header {
    height: 60px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: 0 4px 16px rgba(0,0,0,.08);
    position: relative;
    z-index: 100;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo i {
    font-size: 24px;
    color: #3b82f6;
}

.logo h2 {
    color: #2563eb;
    font-size: 20px;
    white-space: nowrap;
}

/* Hamburger button (mobile only) */
#menuToggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    color: #2563eb;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: background .2s;
}

#menuToggle:hover {
    background: #eff6ff;
}

.nav-buttons {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap;
}

.nav-buttons select {
    padding: 7px 10px;
    border-radius: 8px;
    border: 1px solid #ccc;
    background: white;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    font-size: 13px;
    max-width: 160px;
}

.nav-buttons button {
    padding: 8px 16px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    white-space: nowrap;
}

#loginBtn {
    background: white;
    color: #2563eb;
    border: 2px solid #2563eb;
}

#registerBtn {
    background: #2563eb;
    color: white;
}

#logoutBtn {
    background: #ef4444;
    color: white;
}

#adminBtn {
    background: #7c3aed;
    color: white;
}

#userGreeting {
    font-weight: 600;
    color: #2563eb;
    font-size: 13px;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ================= CONTAINER ================= */
.container {
    display: flex;
    height: calc(100dvh - 60px);
    position: relative;
    overflow: hidden;
}

/* ================= SIDEBAR OVERLAY (mobile) ================= */
#sidebarOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 199;
}

#sidebarOverlay.show {
    display: block;
}

/* ================= SIDEBAR ================= */
aside {
    width: 300px;
    min-width: 300px;
    background: white;
    padding: 20px 16px;
    box-shadow: 5px 0 15px rgba(0,0,0,.05);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0;
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    z-index: 200;
    flex-shrink: 0;
}

.history {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

.history-header h3 {
    font-size: 20px;
    font-weight: 700;
}

#newChatBtn {
    background: #2563eb;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    white-space: nowrap;
}

#newChatBtn:hover {
    background: #1d4ed8;
}

.section-title {
    margin-top: 18px;
    margin-bottom: 10px;
    font-size: 14px;
    color: #64748b;
    font-weight: 600;
}

/* Ligne titre "Documents" + bouton "+" dossier */
.section-title-row {
    margin-top: 18px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.small-add-btn {
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 8px;
    background: #e5edff;
    color: #2563eb;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: background .2s;
}

.small-add-btn:hover {
    background: #dbeafe;
}

/* SEARCH */
#searchChat {
    width: 100%;
    height: 40px;
    padding: 0 14px;
    border: 1px solid #ddd;
    border-radius: 10px;
    outline: none;
    font-size: 14px;
    margin-bottom: 12px;
}

#searchChat:focus {
    border-color: #2563eb;
}

/* CHAT LIST */
#historyList,
#documentList {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    background: #f4f7ff;
    padding: 11px 13px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    transition: background .2s;
}

.history-item:hover {
    background: #dbeafe;
}

.history-item.active {
    background: #2563eb;
    color: white;
}

.delete-chat {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    padding: 2px 6px;
}

.chat-actions{

    display:flex;
    align-items:center;
    gap:5px;

}


.chat-actions button{

    width:28px;
    height:28px;

    border:none;

    border-radius:7px;

    background:white;

    color:#64748b;

    cursor:pointer;

    display:flex;
    align-items:center;
    justify-content:center;

    font-size:12px;

}



.chat-actions button:hover{

    background:#e0e7ff;

    color:#2563eb;

}



.history-item.active .chat-actions button{

    background:white;

    color:#2563eb;

}


.chat-title-text{

    flex:1;

    overflow:hidden;

    white-space:nowrap;

    text-overflow:ellipsis;

    margin-right:8px;

}

.empty-history {
    color: #999;
    font-size: 13px;
}

/* ================= DOCUMENTS / FOLDERS ================= */

.folder-group {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 8px;
    margin-bottom: 6px;
}

.folder-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 4px 6px 4px;
}

.folder-title {
    font-size: 13px;
    font-weight: 600;
    color: #334155;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.folder-title i {
    color: #2563eb;
}

.folder-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pdf-item {
    background: white;
    padding: 9px 10px;
    border-radius: 10px;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    transition: background .2s;
}

.pdf-item:hover {
    background: #eff6ff;
}

.pdf-item span {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
}

.pdf-item span i {
    color: #ef4444;
    flex-shrink: 0;
}

.move-folder-select {
    max-width: 92px;
    font-size: 11px;
    padding: 4px 6px;
    border-radius: 7px;
    border: 1px solid #e2e8f0;
    background: white;
    color: #64748b;
    outline: none;
    font-family: inherit;
    cursor: pointer;
}

aside::-webkit-scrollbar { width: 5px; }
aside::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }

/* ================= CHAT ================= */
.chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    min-width: 0;
    overflow: hidden;
}

/* ================= CHAT MESSAGES BEAUTIFICATION ================= */
.messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 10px 8px 10px 4px;
}

.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
.messages::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.bot,
.user {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    animation: msgSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes msgSlideUp {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.user {
    justify-content: flex-end;
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s ease;
}

.avatar:hover {
    transform: scale(1.05);
}

.user .avatar {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: white;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.3);
}

.bot .avatar {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    color: white;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.bubble {
    max-width: 82%;
    padding: 15px 20px;
    border-radius: 20px;
    line-height: 1.65;
    font-size: 14.5px;
    word-break: break-word;
    white-space: pre-wrap;
    position: relative;
}

.userBubble {
    width: fit-content;
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    color: #ffffff;
    border-bottom-right-radius: 5px;
    box-shadow: 0 6px 18px rgba(37, 99, 235, 0.22);
}

.bot .bubble {
    width: fit-content;
    min-width: 280px;
    max-width: 84%;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 5px;
    color: #1e293b;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.04);
}

/* SOURCES BOX */
.sources-box {
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px dashed #e2e8f0;
}

.sources-header-title {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sources-chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.source-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.2s, transform 0.15s;
}

.source-badge:hover {
    background: #dbeafe;
    transform: translateY(-1px);
}

/* TYPING / LOADING BUBBLE */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 16px;
}

.typing-dot {
    width: 7px;
    height: 7px;
    background: #6366f1;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ================= INPUT ================= */
.input-area-wrapper {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.attached-pdfs-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow-x: auto;
    padding: 4px 2px;
}

.attached-pdfs-bar::-webkit-scrollbar {
    height: 4px;
}
.attached-pdfs-bar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.pdf-chip {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 210px;
    max-width: 280px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    animation: fadeInChip 0.25s ease-out;
}

@keyframes fadeInChip {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.pdf-chip-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: #2563eb;
    background: #f8fafc;
    flex-shrink: 0;
}

.pdf-chip-icon.loading {
    border-top-color: #2563eb;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.pdf-chip-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pdf-chip-title {
    font-weight: 600;
    font-size: 13px;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pdf-chip-sub {
    font-size: 11px;
    color: #64748b;
    font-weight: 500;
}

.pdf-chip-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: #94a3b8;
    font-size: 16px;
    padding: 2px;
    border-radius: 50%;
    transition: color 0.15s;
}

.pdf-chip-remove:hover {
    color: #ef4444;
}

.input-area {
    background: white;
    padding: 10px 14px;
    border-radius: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 6px 18px rgba(0,0,0,.08);
}

.mic-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 17px;
    color: #64748b;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mic-btn:hover {
    background: #f1f5f9;
    color: #2563eb;
}

.input-area input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    font-family: inherit;
    min-width: 0;
}

.plus,
.send {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    flex-shrink: 0;
    transition: opacity .2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.plus:hover, .send:hover { opacity: .85; }

.plus {
    background: #e5edff;
    color: #2563eb;
}

.send {
    background: #2563eb;
    color: white;
}

/* ================= MODALS ================= */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    justify-content: center;
    align-items: center;
    z-index: 500;
    padding: 16px;
}

.modal-content {
    width: 100%;
    max-width: 420px;
    background: white;
    border-radius: 18px;
    padding: 28px 24px;
    position: relative;
}

.modal-content h2 {
    text-align: center;
    color: #2563eb;
    margin-bottom: 22px;
    font-size: 20px;
}

.modal-content input {
    width: 100%;
    padding: 13px;
    margin-bottom: 13px;
    border: 1px solid #ddd;
    border-radius: 10px;
    font-family: inherit;
    font-size: 14px;
    outline: none;
}

.modal-content input:focus { border-color: #2563eb; }

.modal-content button {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: 10px;
    background: #2563eb;
    color: white;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.close {
    position: absolute;
    right: 16px;
    top: 10px;
    font-size: 26px;
    cursor: pointer;
    color: #64748b;
    line-height: 1;
}

/* ================= TABLET (≤ 900px) ================= */
@media (max-width: 900px) {
    aside {
        position: fixed;
        top: 60px;
        left: 0;
        height: calc(100dvh - 60px);
        transform: translateX(-100%);
        box-shadow: 6px 0 24px rgba(0,0,0,.15);
    }

    aside.open {
        transform: translateX(0);
    }

    #menuToggle {
        display: flex;
    }

    .bubble {
        max-width: 80%;
    }

    .chat {
        padding: 14px;
    }
}

/* ================= PHONE (≤ 480px) ================= */
@media (max-width: 480px) {
    header {
        height: 56px;
        padding: 0 12px;
    }

    .logo h2 {
        font-size: 16px;
    }

    .logo i {
        font-size: 20px;
    }

    .nav-buttons select {
        max-width: 100px;
        font-size: 11px;
        padding: 5px 6px;
    }

    .nav-buttons button {
        padding: 7px 10px;
        font-size: 12px;
    }

    #userGreeting {
        max-width: 70px;
        font-size: 12px;
    }

    .container {
        height: calc(100dvh - 56px);
    }

    aside {
        top: 56px;
        height: calc(100dvh - 56px);
        width: 280px;
        min-width: 280px;
    }

    .chat {
        padding: 10px;
    }

    .bubble {
        max-width: 86%;
        font-size: 13px;
        padding: 11px 13px;
    }

    .avatar {
        width: 34px;
        height: 34px;
        font-size: 16px;
    }

    .input-area {
        padding: 9px 10px;
        gap: 8px;
        border-radius: 14px;
    }

    .input-area input {
        font-size: 14px;
    }

    .plus, .send {
        width: 38px;
        height: 38px;
        font-size: 14px;
    }

    .messages {
        gap: 14px;
    }

    .modal-content {
        padding: 22px 16px;
        border-radius: 14px;
    }

    .modal-content h2 {
        font-size: 18px;
        margin-bottom: 16px;
    }
}
.doc-chat-tag {
    font-size: 10px;
    color: #94a3b8;
    font-style: italic;
    margin-left: 6px;
    white-space: nowrap;
}

/* ================= DRAG AND DROP OVERLAY ================= */
.chat {
    position: relative;
}

.drop-overlay {
    position: absolute;
    inset: 0;
    background: rgba(37, 99, 235, 0.92);
    backdrop-filter: blur(4px);
    z-index: 150;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    margin: 10px;
}

.drop-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.drop-overlay-content {
    text-align: center;
    color: white;
    padding: 30px;
    border: 3px dashed rgba(255, 255, 255, 0.7);
    border-radius: 20px;
    max-width: 80%;
    animation: pulseDrop 1.8s infinite ease-in-out;
}

@keyframes pulseDrop {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

.drop-overlay-content i {
    font-size: 54px;
    margin-bottom: 16px;
    color: white;
}

.drop-overlay-content h3 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 6px;
}

.drop-overlay-content p {
    font-size: 14px;
    opacity: 0.9;
}

/* FOLDER DRAG OVER & UPLOAD */
.folder-group {
    transition: transform 0.2s, border-color 0.2s, background-color 0.2s;
}

.folder-group.drag-over-folder {
    border: 2px dashed #2563eb !important;
    background: #eff6ff !important;
    transform: scale(1.02);
}

.upload-to-folder {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 7px;
    background: #dbeafe;
    color: #2563eb;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: background 0.2s, color 0.2s;
}

.upload-to-folder:hover {
    background: #2563eb;
    color: white;
}