/* =========================
   MODE CHATBOX
========================= */

#prof-ia-module.pia-chat-mode #pia-progress-wrap,
#prof-ia-module.pia-chat-mode #pia-xp-wrap,
#prof-ia-module.pia-chat-mode #pia-level-badge,
#prof-ia-module.pia-chat-mode #pia-score-badge,
#prof-ia-module.pia-chat-mode #pia-good-count,
#prof-ia-module.pia-chat-mode #pia-bad-count,
#prof-ia-module.pia-chat-mode #difficulty-level {
    display: none !important;
}

#prof-ia-module.pia-chat-mode #pia-stats-box,
#prof-ia-module.pia-chat-mode .pia-stats {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
}

#prof-ia-module.pia-chat-mode .pia-difficulty {
    display: none !important;
}

#prof-ia-module.pia-chat-mode .pia-topbar {
    padding: 12px 16px !important;
}

#prof-ia-module.pia-chat-mode .pia-topbar-title {
    font-size: 1.1rem !important;
}

#prof-ia-module.pia-chat-mode #pia-remaining-badge {
    display: inline-flex !important;
    align-items: center;
    gap: 6px;
    font-weight: 600;
}

/* =========================
   CHATBOX SHELL
========================= */

#prof-ia-module .pia-chatbox-shell {
    height: 100%;
    min-height: 490px;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    overflow: hidden;
}

#prof-ia-module .pia-chat-history {
    height: calc(100vh - 360px);
    min-height: 460px;
    max-height: 760px;
    overflow-y: auto;
    padding: 26px 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scroll-behavior: smooth;
    background: transparent;
}

#prof-ia-module .pia-chat-history::-webkit-scrollbar,
#prof-ia-module .pia-history-list::-webkit-scrollbar {
    width: 8px;
}

#prof-ia-module .pia-chat-history::-webkit-scrollbar-thumb,
#prof-ia-module .pia-history-list::-webkit-scrollbar-thumb {
    background: #c5d6ea;
    border-radius: 999px;
}

#prof-ia-module .pia-chat-empty {
    margin: 40px auto;
    max-width: 600px;
    text-align: center;
    color: #5b6b7c;
    padding: 34px 24px;
    border-radius: 24px;
    background: rgba(255, 255, 255, .84);
    border: 1px solid rgba(217, 229, 242, .95);
    box-shadow: 0 18px 40px rgba(15, 76, 129, .07);
}

#prof-ia-module .pia-chat-empty-icon {
    font-size: 2.2rem;
    margin-bottom: 10px;
}

#prof-ia-module .pia-chat-empty-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--pia-title);
    margin-bottom: 8px;
}

#prof-ia-module .pia-chat-empty-text {
    line-height: 1.65;
    font-size: 14px;
}

#prof-ia-module .pia-chat-row {
    display: flex;
    width: 100%;
    animation: piaFadeInUp .22s ease;
}

#prof-ia-module .pia-chat-row.user {
    justify-content: flex-end;
}

#prof-ia-module .pia-chat-row.assistant {
    justify-content: flex-start;
}

#prof-ia-module .pia-chat-bubble {
    position: relative;
    max-width: min(860px, 84%);
    padding: 15px 17px;
    border-radius: 18px;
    line-height: 1.7;
    font-size: 14.5px;
    word-break: break-word;
    box-shadow: 0 10px 22px rgba(15, 76, 129, .05);
    transition: transform .15s ease, box-shadow .15s ease;
}

#prof-ia-module .pia-chat-bubble:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 28px rgba(15, 76, 129, .08);
}

#prof-ia-module .pia-chat-row.user .pia-chat-bubble {
    background: linear-gradient(135deg, var(--pia-blue), var(--pia-blue-dark));
    color: #fff;
    border: none;
    border-bottom-right-radius: 6px;
}

#prof-ia-module .pia-chat-row.assistant .pia-chat-bubble {
    background: #ffffff;
    color: var(--pia-text);
    border: 1px solid var(--pia-border);
    border-bottom-left-radius: 6px;
}

#prof-ia-module .pia-chat-bubble.long {
    max-width: 100%;
    border-radius: 22px;
}

#prof-ia-module .pia-chat-row.assistant .pia-chat-bubble h1,
#prof-ia-module .pia-chat-row.assistant .pia-chat-bubble h2,
#prof-ia-module .pia-chat-row.assistant .pia-chat-bubble h3 {
    margin: 14px 0 8px;
    color: var(--pia-title);
    line-height: 1.35;
}

#prof-ia-module .pia-chat-row.assistant .pia-chat-bubble p {
    margin: 0 0 10px;
}

#prof-ia-module .pia-chat-row.assistant .pia-chat-bubble ul,
#prof-ia-module .pia-chat-row.assistant .pia-chat-bubble ol {
    margin: 10px 0;
    padding-left: 20px;
}

#prof-ia-module .pia-chat-row.assistant .pia-chat-bubble li {
    margin-bottom: 6px;
}

#prof-ia-module .pia-chat-row.assistant .pia-chat-bubble pre {
    margin: 12px 0;
    padding: 12px 14px;
    border-radius: 14px;
    overflow-x: auto;
    background: #f4f8fc;
    border: 1px solid #e2ebf5;
}

#prof-ia-module .pia-chat-meta {
    font-size: 11px;
    margin-top: 7px;
    opacity: .65;
}

#prof-ia-module .pia-chat-actions {
    margin-top: 8px;
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity .18s ease;
}

#prof-ia-module .pia-chat-row:hover .pia-chat-actions {
    opacity: 1;
}

#prof-ia-module .pia-chat-action-btn {
    font-size: 12px;
    padding: 5px 8px;
    border-radius: 8px;
    border: 1px solid var(--pia-border);
    background: #f8fbff;
    cursor: pointer;
    color: var(--pia-title);
}

#prof-ia-module .pia-chat-action-btn:hover {
    background: #edf5ff;
}

/* =========================
   SAISIE CHAT
========================= */

#prof-ia-module .pia-chat-composer {
    position: sticky;
    bottom: 0;
    z-index: 25;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: end;
    padding: 14px 16px 16px;
    border-top: 1px solid #e8eef6;
    background: rgba(255, 255, 255, .94);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

#prof-ia-module .pia-chat-input {
    min-height: 58px;
    max-height: 180px;
    border-radius: 18px;
    padding: 15px 16px;
    font-size: 14px;
    line-height: 1.5;
    background: #fff;
    border: 1px solid var(--pia-border);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .85);
}

#prof-ia-module .pia-chat-input:focus {
    border-color: #9dc1e4;
    box-shadow: 0 0 0 4px rgba(21, 101, 192, .08);
}

#prof-ia-module .pia-chat-send,
#prof-ia-module #btn-send {
    min-width: 115px;
    min-height: 58px;
    border-radius: 16px;
    padding: 12px 18px;
    font-weight: 800;
    box-shadow: 0 10px 20px rgba(15, 76, 129, .16);
}

/* =========================
   TYPING
========================= */

#prof-ia-module .pia-chat-typing {
    display: inline-flex;
    gap: 5px;
    align-items: center;
}

#prof-ia-module .pia-chat-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #8aa8c7;
    animation: piaBlink 1.2s infinite ease-in-out;
}

#prof-ia-module .pia-chat-dot:nth-child(2) {
    animation-delay: .15s;
}

#prof-ia-module .pia-chat-dot:nth-child(3) {
    animation-delay: .3s;
}

/* =========================
   HISTORIQUE
========================= */

#prof-ia-module .pia-history-box {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e7eef7;
}

#prof-ia-module .pia-history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

#prof-ia-module .pia-history-new-btn {
    width: 100%;
    appearance: none;
    border: none;
    background: linear-gradient(135deg, var(--pia-blue), var(--pia-blue-dark));
    color: #fff;
    border-radius: 14px;
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    transition: .18s ease;
    box-shadow: 0 10px 20px rgba(15, 76, 129, .14);
    text-align: center;
}

#prof-ia-module .pia-history-new-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 24px rgba(15, 76, 129, .18);
}

#prof-ia-module .pia-history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 430px;
    overflow-y: auto;
    padding-right: 3px;
}

#prof-ia-module .pia-history-empty {
    padding: 14px;
    font-size: 13px;
    color: var(--pia-text-soft);
    text-align: center;
    border: 1px dashed var(--pia-border);
    border-radius: 14px;
    background: #f8fbff;
}

#prof-ia-module .pia-history-item-wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px;
    border-radius: 10px;
    margin-bottom: 6px;
    background: #f8f9fa;
}

#prof-ia-module .pia-history-item {
    appearance: none;
    width: 100%;
    border: 1px solid var(--pia-border);
    background: #ffffff;
    border-radius: 14px;
    padding: 12px;
    text-align: left;
    cursor: pointer;
    transition: .18s ease;
}

#prof-ia-module .pia-history-item:hover {
    transform: translateY(-1px);
    border-color: #b8d0e8;
    background: #f8fbff;
    box-shadow: 0 8px 16px rgba(15, 76, 129, .07);
}

#prof-ia-module .pia-history-item.active {
    background: linear-gradient(135deg, #e8f2ff 0%, #dcecff 100%);
    color: var(--pia-title);
    border-color: #bcd3ea;
}

#prof-ia-module .pia-history-title {
    font-size: 13px;
    font-weight: 800;
    line-height: 1.35;
    margin-bottom: 4px;
    display: block;
}

#prof-ia-module .pia-history-preview {
    font-size: 12px;
    line-height: 1.45;
    opacity: .85;
    display: block;
}

#prof-ia-module .pia-history-time {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    opacity: .65;
}

#prof-ia-module .pia-history-actions {
    display: flex;
    gap: 5px;
}

#prof-ia-module .pia-history-action {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    opacity: 0.7;
}

#prof-ia-module .pia-history-action:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* =========================
   FULLSCREEN CHAT
========================= */

#chat-container.pia-fullscreen .pia-chat-history {
    height: auto !important;
    min-height: calc(100vh - 270px) !important;
    max-height: none !important;
    padding: 24px 28px !important;
}

#prof-ia-module.pia-chat-mode .pia-chat-history {
    height: calc(100vh - 240px) !important;
}

/* =========================
   RESPONSIVE CHAT
========================= */

@media (max-width: 768px) {
    #prof-ia-module .pia-chat-history {
        height: auto;
        min-height: 360px;
        max-height: none;
        padding: 18px 14px;
    }

    #prof-ia-module .pia-chat-bubble {
        max-width: 94%;
        font-size: 14px;
    }

    #prof-ia-module #btn-send,
    #prof-ia-module .pia-chat-send {
        width: 100%;
        min-height: 48px;
    }
}