/*
 * The assistant of the public site (resources/views/components/student-part/chatbot.blade.php) : a launcher at the
 * bottom right, a panel in the manner of Intercom on a computer, the whole screen on a phone. The colours follow the
 * theme of the site (light or dark).
 */
.cfp-chatbot {
    --cfp-chat-primary: var(--bs-primary, #066ac9);
    --cfp-chat-primary-rgb: var(--bs-primary-rgb, 6, 106, 201);
    --cfp-chat-bg: var(--bs-body-bg, #fff);
    --cfp-chat-soft: var(--bs-tertiary-bg, #f5f7fa);
    --cfp-chat-text: var(--bs-body-color, #24292d);
    --cfp-chat-muted: var(--bs-secondary-color, #6c757d);
    --cfp-chat-border: var(--bs-border-color, #e5e7eb);
    --cfp-chat-radius: 18px;
    --cfp-chat-gap: 24px;
    font-family: inherit;
}

/* An element hidden by the script stays hidden, whatever its display. */
.cfp-chatbot [hidden] {
    display: none !important;
}

/* The launcher, above the button « back to top » of the site. */
.cfp-chatbot-launcher {
    position: fixed;
    right: var(--cfp-chat-gap);
    bottom: 96px;
    z-index: 1046;
    display: grid;
    place-items: center;
    width: 60px;
    height: 60px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--cfp-chat-primary);
    color: #fff;
    font-size: 1.6rem;
    box-shadow: 0 6px 24px rgba(var(--cfp-chat-primary-rgb), .45), 0 2px 6px rgba(0, 0, 0, .15);
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease;
}

.cfp-chatbot-launcher:hover {
    transform: scale(1.06);
}

.cfp-chatbot-launcher:focus-visible,
.cfp-chatbot button:focus-visible,
.cfp-chatbot a:focus-visible {
    outline: 3px solid rgba(var(--cfp-chat-primary-rgb), .45);
    outline-offset: 2px;
}

.cfp-chatbot-launcher i {
    grid-area: 1 / 1;
    line-height: 1;
    transition: transform .25s ease, opacity .2s ease;
}

.cfp-chatbot-launcher-close {
    opacity: 0;
    transform: rotate(-90deg) scale(.6);
}

.cfp-chatbot.is-open .cfp-chatbot-launcher-open {
    opacity: 0;
    transform: rotate(90deg) scale(.6);
}

.cfp-chatbot.is-open .cfp-chatbot-launcher-close {
    opacity: 1;
    transform: none;
}

/* The invitation next to the launcher. */
.cfp-chatbot-teaser {
    position: fixed;
    right: var(--cfp-chat-gap);
    bottom: 168px;
    z-index: 1046;
    max-width: 260px;
    animation: cfp-chat-rise .35s ease both;
}

.cfp-chatbot-teaser[hidden] {
    display: none;
}

.cfp-chatbot-teaser-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--cfp-chat-border);
    border-radius: 16px 16px 4px 16px;
    background: var(--cfp-chat-bg);
    color: var(--cfp-chat-text);
    text-align: left;
    font-size: .9rem;
    line-height: 1.4;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .12);
    cursor: pointer;
}

.cfp-chatbot-teaser-close {
    position: absolute;
    top: -10px;
    left: -10px;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--cfp-chat-border);
    border-radius: 50%;
    background: var(--cfp-chat-bg);
    color: var(--cfp-chat-muted);
    font-size: 1rem;
    cursor: pointer;
}

/* The panel. */
.cfp-chatbot-panel {
    position: fixed;
    right: var(--cfp-chat-gap);
    bottom: 168px;
    z-index: 1047;
    display: flex;
    flex-direction: column;
    width: 400px;
    height: min(680px, calc(100dvh - 192px));
    min-height: 360px;
    margin: 0;
    /* The site pads every section. */
    padding: 0;
    overflow: hidden;
    border-radius: var(--cfp-chat-radius);
    background: var(--cfp-chat-bg);
    color: var(--cfp-chat-text);
    box-shadow: 0 12px 48px rgba(0, 0, 0, .18), 0 2px 8px rgba(0, 0, 0, .08);
    transform-origin: bottom right;
    animation: cfp-chat-open .22s ease both;
}

.cfp-chatbot-panel[hidden] {
    display: none;
}

.cfp-chatbot-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 12px 16px 18px;
    background: linear-gradient(135deg, var(--cfp-chat-primary), rgba(var(--cfp-chat-primary-rgb), .82));
    color: #fff;
}

.cfp-chatbot-identity {
    flex: 1;
    min-width: 0;
}

.cfp-chatbot-identity h2 {
    margin: 0;
    overflow: hidden;
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.cfp-chatbot-identity p {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 2px 0 0;
    font-size: .8rem;
    opacity: .9;
}

.cfp-chatbot-online {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #3ddc84;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .35);
}

.cfp-chatbot-icon {
    display: grid;
    place-items: center;
    flex: none;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
}

.cfp-chatbot-icon:hover {
    background: rgba(255, 255, 255, .16);
}

.cfp-chatbot-avatar {
    display: grid;
    place-items: center;
    flex: none;
    width: 28px;
    height: 28px;
    overflow: hidden;
    border-radius: 50%;
    background: #fff;
    color: var(--cfp-chat-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

.cfp-chatbot-avatar img {
    width: 100%;
    height: 100%;
    padding: 3px;
    object-fit: contain;
}

.cfp-chatbot-avatar-lg {
    width: 42px;
    height: 42px;
    font-size: 1.3rem;
}

/* The conversation. */
.cfp-chatbot-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    /* The screens change in place : the browser does not keep the former position. */
    overflow-anchor: none;
    padding: 20px 16px 8px;
    background: var(--cfp-chat-bg);
    -webkit-overflow-scrolling: touch;
}

.cfp-chatbot-welcome[hidden] {
    display: none;
}

.cfp-chatbot-hello {
    margin: 0 0 6px;
    color: var(--cfp-chat-text);
    font-size: 1.5rem;
    font-weight: 700;
}

.cfp-chatbot-intro {
    margin: 0 0 20px;
    color: var(--cfp-chat-muted);
    font-size: .92rem;
    line-height: 1.5;
}

.cfp-chatbot-label {
    margin: 0 0 8px;
    color: var(--cfp-chat-muted);
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.cfp-chatbot-suggestions {
    display: flex;
    flex-direction: column;
    margin-bottom: 20px;
    overflow: hidden;
    border: 1px solid var(--cfp-chat-border);
    border-radius: 14px;
}

.cfp-chatbot-suggestion {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 48px;
    padding: 12px 14px;
    border: 0;
    border-bottom: 1px solid var(--cfp-chat-border);
    background: var(--cfp-chat-bg);
    color: var(--cfp-chat-text);
    text-align: left;
    font-size: .92rem;
    cursor: pointer;
    transition: background .15s ease;
}

.cfp-chatbot-suggestion:last-child {
    border-bottom: 0;
}

.cfp-chatbot-suggestion:hover {
    background: var(--cfp-chat-soft);
}

.cfp-chatbot-suggestion i {
    color: var(--cfp-chat-primary);
}

.cfp-chatbot-contact {
    padding: 14px;
    border-radius: 14px;
    background: var(--cfp-chat-soft);
}

.cfp-chatbot-contact-actions {
    display: flex;
    gap: 8px;
}

.cfp-chatbot-contact-actions a {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 6px;
    min-height: 44px;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: .9rem;
    font-weight: 600;
    text-decoration: none;
}

.cfp-chatbot-whatsapp {
    background: #25d366;
    color: #fff !important;
}

.cfp-chatbot-call {
    border: 1px solid var(--cfp-chat-border);
    background: var(--cfp-chat-bg);
    color: var(--cfp-chat-text) !important;
}

/* The conversations kept on the device. */
.cfp-chatbot-label-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.cfp-chatbot-link {
    padding: 0;
    border: 0;
    background: none;
    color: var(--cfp-chat-primary);
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
}

.cfp-chatbot-link:hover {
    text-decoration: underline;
}

.cfp-chatbot-recent {
    margin-bottom: 20px;
}

.cfp-chatbot-conversations {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--cfp-chat-border);
    border-radius: 14px;
}

.cfp-chatbot-conversations:empty {
    display: none;
}

.cfp-chatbot-conversation {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 60px;
    padding: 10px 14px;
    border: 0;
    border-bottom: 1px solid var(--cfp-chat-border);
    background: var(--cfp-chat-bg);
    color: var(--cfp-chat-text);
    text-align: left;
    cursor: pointer;
    transition: background .15s ease;
}

.cfp-chatbot-conversation:last-child {
    border-bottom: 0;
}

.cfp-chatbot-conversation:hover {
    background: var(--cfp-chat-soft);
}

.cfp-chatbot-conversation-text {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

.cfp-chatbot-conversation-text strong,
.cfp-chatbot-conversation-text span {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.cfp-chatbot-conversation-text strong {
    font-size: .9rem;
    font-weight: 600;
}

.cfp-chatbot-conversation-text span {
    color: var(--cfp-chat-muted);
    font-size: .8rem;
}

.cfp-chatbot-conversation-meta {
    flex: none;
    align-self: flex-start;
    margin-top: 2px;
    color: var(--cfp-chat-muted);
    font-size: .75rem;
}

.cfp-chatbot-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(var(--cfp-chat-primary-rgb), .12);
    color: var(--cfp-chat-primary);
    font-weight: 600;
}

.cfp-chatbot-privacy {
    margin: 14px 0 0;
    color: var(--cfp-chat-muted);
    font-size: .78rem;
    text-align: center;
}

/* A past conversation : read only. */
.cfp-chatbot-past {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin: 8px 12px 0;
    padding: 12px;
    border-radius: 14px;
    background: var(--cfp-chat-soft);
    text-align: center;
}

.cfp-chatbot-past p {
    margin: 0;
    color: var(--cfp-chat-muted);
    font-size: .82rem;
}

.cfp-chatbot-new {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    padding: 8px 18px;
    border: 0;
    border-radius: 999px;
    background: var(--cfp-chat-primary);
    color: #fff;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
}

.cfp-chatbot-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cfp-chatbot-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: cfp-chat-rise .2s ease both;
}

.cfp-chatbot-row-user {
    justify-content: flex-end;
}

.cfp-chatbot-message {
    max-width: 82%;
    padding: 10px 14px;
    overflow-wrap: anywhere;
    font-size: .93rem;
    line-height: 1.5;
}

.cfp-chatbot-message p {
    margin: 0;
}

.cfp-chatbot-message p + p,
.cfp-chatbot-message p + ul,
.cfp-chatbot-message ul + p {
    margin-top: 8px;
}

.cfp-chatbot-message ul {
    margin: 0;
    padding-left: 18px;
}

.cfp-chatbot-message li + li {
    margin-top: 3px;
}

.cfp-chatbot-assistant {
    border-radius: 16px 16px 16px 4px;
    background: var(--cfp-chat-soft);
    color: var(--cfp-chat-text);
}

.cfp-chatbot-assistant a {
    color: var(--cfp-chat-primary);
    text-decoration: underline;
}

.cfp-chatbot-user {
    border-radius: 16px 16px 4px 16px;
    background: var(--cfp-chat-primary);
    color: #fff;
    white-space: pre-wrap;
}

.cfp-chatbot-user a {
    color: #fff;
}

/* « The assistant is writing ». */
.cfp-chatbot-typing {
    display: flex;
    gap: 4px;
    padding: 14px 16px;
}

.cfp-chatbot-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--cfp-chat-muted);
    animation: cfp-chat-dot 1.2s infinite ease-in-out;
}

.cfp-chatbot-typing span:nth-child(2) {
    animation-delay: .15s;
}

.cfp-chatbot-typing span:nth-child(3) {
    animation-delay: .3s;
}

/* The field. */
.cfp-chatbot-composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin: 8px 12px 0;
    padding: 6px 6px 6px 14px;
    border: 1px solid var(--cfp-chat-border);
    border-radius: 24px;
    background: var(--cfp-chat-bg);
    transition: border-color .15s ease, box-shadow .15s ease;
}

.cfp-chatbot-composer:focus-within {
    border-color: rgba(var(--cfp-chat-primary-rgb), .6);
    box-shadow: 0 0 0 3px rgba(var(--cfp-chat-primary-rgb), .12);
}

.cfp-chatbot-composer textarea {
    flex: 1;
    min-height: 36px;
    max-height: 120px;
    padding: 7px 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--cfp-chat-text);
    font: inherit;
    font-size: .95rem;
    line-height: 1.4;
    resize: none;
}

.cfp-chatbot-send {
    display: grid;
    place-items: center;
    flex: none;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--cfp-chat-primary);
    color: #fff;
    font-size: 1.15rem;
    cursor: pointer;
    transition: opacity .15s ease, transform .15s ease;
}

.cfp-chatbot-send:disabled {
    opacity: .35;
    cursor: default;
}

.cfp-chatbot-send:not(:disabled):hover {
    transform: scale(1.06);
}

.cfp-chatbot-notice {
    margin: 0;
    padding: 6px 16px 10px;
    color: var(--cfp-chat-muted);
    font-size: .7rem;
    text-align: center;
}

/* A phone : the panel takes the whole screen, the launcher hides behind it. */
@media (max-width: 575.98px) {
    .cfp-chatbot {
        --cfp-chat-gap: 16px;
    }

    .cfp-chatbot-launcher {
        bottom: 84px;
        width: 56px;
        height: 56px;
        font-size: 1.45rem;
    }

    .cfp-chatbot-teaser {
        bottom: 152px;
        max-width: calc(100vw - 32px);
    }

    .cfp-chatbot-panel {
        inset: 0;
        width: 100%;
        height: 100%;
        min-height: 0;
        border-radius: 0;
        animation-name: cfp-chat-slide;
    }

    .cfp-chatbot.is-open .cfp-chatbot-launcher {
        display: none;
    }

    .cfp-chatbot-header {
        padding-top: max(14px, env(safe-area-inset-top));
    }

    /* 16 px : the phone does not zoom on the field. */
    .cfp-chatbot-composer textarea {
        font-size: 16px;
    }

    .cfp-chatbot-notice {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .cfp-chatbot-message {
        max-width: 88%;
    }
}

/* The page under the panel does not scroll on a phone. */
@media (max-width: 575.98px) {
    html.cfp-chatbot-locked,
    html.cfp-chatbot-locked body {
        overflow: hidden;
    }
}

@keyframes cfp-chat-open {
    from {
        opacity: 0;
        transform: translateY(12px) scale(.97);
    }
}

@keyframes cfp-chat-slide {
    from {
        transform: translateY(100%);
    }
}

@keyframes cfp-chat-rise {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
}

@keyframes cfp-chat-dot {
    0%, 60%, 100% {
        opacity: .35;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-4px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .cfp-chatbot *,
    .cfp-chatbot *::before {
        animation: none !important;
        transition: none !important;
    }
}
