/* Assistant CoddyRun : t'chat flottant et page /assistant/ */

.as-widget {
    --as-grad: linear-gradient(135deg, #1d9bf0 0%, #5b6cff 55%, #7c4dff 100%);
    --as-ombre: 0 28px 70px rgba(15, 20, 25, .22), 0 4px 14px rgba(15, 20, 25, .08);
    --as-bot-bg: var(--surface2);
    --as-rayon: 20px;
    font-family: var(--font-text);
}

:root[data-theme="dark"] .as-widget {
    --as-ombre: 0 28px 70px rgba(0, 0, 0, .55), 0 4px 14px rgba(0, 0, 0, .3);
    --as-bot-bg: var(--surface2);
}

.as-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------- bouton flottant ---------- */
.as-bulle {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 95;
    height: 46px;
    padding: 0 16px 0 6px;
    border-radius: 999px;
    border: 0;
    background: var(--as-grad);
    color: #fff;
    font: 700 13px/1 var(--font-text);
    letter-spacing: .2px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    box-shadow: 0 12px 30px rgba(76, 108, 255, .38);
    transition: transform .2s cubic-bezier(.2, .9, .3, 1.3), box-shadow .2s, opacity .2s;
}

.as-bulle::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: inherit;
    border: 2px solid rgba(91, 108, 255, .45);
    opacity: 0;
    animation: as-onde 3.2s ease-out 1.5s 3;
    pointer-events: none;
}

@keyframes as-onde {
    0% { opacity: .9; transform: scale(1); }
    70%, 100% { opacity: 0; transform: scale(1.18); }
}

.as-bulle-logo {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .6);
    flex: none;
}

.as-bulle-logo img {
    width: 25px;
    height: 25px;
    display: block;
}

.as-bulle:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 16px 36px rgba(76, 108, 255, .45);
}

.as-bulle:focus-visible {
    outline: 3px solid rgba(91, 108, 255, .5);
    outline-offset: 3px;
}

.as-widget.is-ouvert .as-bulle {
    opacity: 0;
    transform: scale(.85);
    pointer-events: none;
}

/* le bouton « haut de page » passe au-dessus de la bulle */
body.has-assistant .back-to-top {
    bottom: 80px;
}

/* ---------- panneau ---------- */
.as-panneau {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 96;
    width: 360px;
    height: min(540px, calc(100vh - 110px));
    height: min(540px, calc(100dvh - 110px));
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--as-rayon);
    box-shadow: var(--as-ombre);
    overflow: hidden;
    transform-origin: bottom right;
    animation: as-entree .26s cubic-bezier(.2, .9, .3, 1.1);
}

.as-panneau[hidden] {
    display: none;
}

@keyframes as-entree {
    from { opacity: 0; transform: translateY(16px) scale(.94); }
    to { opacity: 1; transform: none; }
}

/* en-tête */
.as-tete {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px 10px 12px;
    background: var(--as-grad);
    color: #fff;
}

.as-tete::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(120% 140% at 100% 0%, rgba(255, 255, 255, .22) 0%, transparent 55%);
    pointer-events: none;
}

.as-avatar {
    position: relative;
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
}

.as-avatar img {
    width: 24px;
    height: 24px;
    display: block;
}

.as-statut {
    position: absolute;
    right: 0;
    bottom: 1px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid #fff;
}

.as-tete-txt {
    position: relative;
    z-index: 1;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.as-tete-txt strong {
    font-family: 'Unbounded', var(--font-text);
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: -.2px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.as-tete-txt span {
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: rgba(255, 255, 255, .85);
}

.as-tete-btn {
    position: relative;
    z-index: 1;
    flex: none;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 0;
    background: rgba(255, 255, 255, .14);
    color: #fff;
    font-size: 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, transform .15s;
}

.as-tete-btn:hover {
    background: rgba(255, 255, 255, .28);
    color: #fff;
}

.as-tete-btn:active {
    transform: scale(.94);
}

/* ---------- fil de la conversation ---------- */
.as-fil {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--border2) transparent;
    background:
        radial-gradient(circle at 1px 1px, var(--border) 1px, transparent 0) 0 0 / 18px 18px,
        var(--surface);
}

.as-fil::-webkit-scrollbar {
    width: 8px;
}

.as-fil::-webkit-scrollbar-thumb {
    background: var(--border2);
    border-radius: 8px;
}

.as-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 100%;
    animation: as-message .22s ease-out;
}

@keyframes as-message {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

.as-moi {
    justify-content: flex-end;
}

.as-msg-avatar {
    flex: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid var(--border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(15, 20, 25, .08);
}

.as-msg-avatar img {
    width: 17px;
    height: 17px;
}

.as-bulle-msg {
    max-width: 90%;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 16px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text);
    overflow-wrap: anywhere;
}

.as-bot .as-bulle-msg {
    background: var(--as-bot-bg);
    border: 1px solid var(--border);
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 10px rgba(15, 20, 25, .04);
}

.as-moi .as-bulle-msg {
    background: var(--as-grad);
    color: #fff;
    border-bottom-right-radius: 6px;
    white-space: pre-wrap;
    box-shadow: 0 6px 16px rgba(76, 108, 255, .25);
}

.as-bulle-msg p {
    margin: 0 0 8px;
}

.as-bulle-msg p:last-child,
.as-bulle-msg ul:last-child {
    margin-bottom: 0;
}

.as-bulle-msg ul {
    margin: 0 0 8px;
    padding-left: 18px;
}

.as-bulle-msg li {
    margin: 3px 0;
}

.as-bulle-msg li::marker {
    color: var(--accent);
}

.as-bulle-msg strong {
    font-weight: 700;
}

.as-bulle-msg code {
    font-family: var(--font-mono);
    font-size: .93em;
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: 5px;
    padding: 1px 5px;
    color: var(--accent5);
}

.as-bulle-msg .code-wrap,
.as-bulle-msg pre.code-block {
    margin: 10px 0 !important;
}

.as-bulle-msg pre.code-block {
    padding: 10px 12px;
    font-size: 11px;
    line-height: 1.7;
    max-width: 100%;
    border-radius: 10px;
    background: var(--code-bg);
    border: 1px solid var(--border);
}

.as-bulle-msg .code-wrap pre.code-block {
    margin: 0 !important;
}

.as-bulle-msg .code-copy {
    opacity: 1;
}

/* en-tête d'une réponse */
.as-source-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 6px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .4px;
    text-transform: uppercase;
    background: rgba(29, 155, 240, .1);
    color: var(--accent);
}

.as-source-badge .mdi {
    font-size: 12px;
}

.as-source-badge.is-faq {
    background: rgba(124, 77, 255, .1);
    color: var(--accent5);
}

.as-source-badge.is-support {
    background: rgba(0, 186, 124, .12);
    color: var(--accent2);
}

.as-titre-fiche {
    display: block;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
    font-size: 12.5px;
    line-height: 1.4;
}

.as-discret,
.as-source {
    color: var(--text-dim);
    font-size: 11.5px;
}

.as-intro {
    color: var(--text-dim);
    font-style: italic;
}

.as-bulle-msg .as-titre,
.as-bulle-msg .version-section {
    margin-top: 12px;
}

.as-lien {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 10px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid rgba(29, 155, 240, .3);
    background: rgba(29, 155, 240, .06);
    font-size: 11.5px;
    font-weight: 700;
    color: var(--accent);
    text-decoration: none;
    transition: background .15s, border-color .15s;
}

.as-lien:hover {
    background: rgba(29, 155, 240, .14);
    border-color: var(--accent);
}

/* ---------- accueil ---------- */
.as-accueil .as-msg-avatar {
    display: none;
}

.as-accueil-carte {
    width: 100%;
    text-align: center;
    padding: 2px 4px 0;
    font-size: 11.5px;
    line-height: 1.6;
    color: var(--text-dim);
}

.as-accueil-logo {
    width: 54px;
    height: 54px;
    margin: 2px auto 8px;
    border-radius: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 26px rgba(76, 108, 255, .18);
    transform: rotate(-4deg);
}

.as-accueil-logo img {
    width: 38px;
    height: 38px;
}

.as-accueil-titre {
    font-family: 'Unbounded', var(--font-text);
    font-size: 15px !important;
    font-weight: 800;
    color: var(--text);
    margin: 0 auto 6px !important;
    letter-spacing: -.4px;
}

.as-accueil-carte > p {
    margin: 0 auto 12px;
    max-width: 320px;
}

.as-accueil-carte strong {
    color: var(--text);
}

/* questions proposées */
.as-puces {
    display: grid;
    gap: 5px;
    margin-top: 8px;
    text-align: left;
}

.as-puce {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    border: 1px solid var(--border2);
    background: var(--surface);
    color: var(--text);
    border-radius: 10px;
    padding: 7px 10px;
    font: 500 11.5px/1.35 var(--font-text);
    cursor: pointer;
    text-align: left;
    transition: border-color .15s, color .15s, background .15s, transform .15s;
}

.as-puce > span {
    flex: 1;
}

.as-puce .mdi {
    flex: none;
    font-size: 15px;
    color: var(--accent);
}

.as-puce:hover {
    border-color: var(--accent);
    background: rgba(29, 155, 240, .05);
    transform: translateX(2px);
}

.as-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.as-autres {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px dashed var(--border2);
}

.as-autres-titre {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--text-dimmer);
}

/* avis */
.as-avis {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-dim);
}

.as-avis > span {
    margin-right: 2px;
}

.as-avis button {
    border: 1px solid var(--border2);
    background: var(--surface);
    color: var(--text-dim);
    border-radius: 999px;
    padding: 4px 11px;
    font: 600 11px/1.4 var(--font-text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color .15s, border-color .15s, background .15s;
}

.as-avis button[data-utile="1"]:hover {
    color: var(--accent2);
    border-color: var(--accent2);
    background: rgba(0, 186, 124, .08);
}

.as-avis button[data-utile="0"]:hover {
    color: var(--err);
    border-color: var(--err);
    background: rgba(244, 33, 46, .06);
}

.as-avis.is-oui,
.as-avis.is-non {
    gap: 6px;
    font-weight: 600;
}

.as-avis.is-oui {
    color: var(--accent2);
}

.as-avis.is-non {
    color: var(--text-dim);
}

.as-support {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 12px;
    padding: 9px 14px;
    border-radius: 12px;
    background: var(--as-grad);
    color: #fff !important;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 6px 16px rgba(76, 108, 255, .28);
    transition: transform .15s, box-shadow .15s;
}

.as-support:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(76, 108, 255, .35);
}

/* réponses reprises du support */
.as-bulle-msg .fr-ligne-vide {
    height: 1em;
    margin: 0;
}

.as-bulle-msg a:not(.as-lien):not(.as-support) {
    color: var(--accent);
    overflow-wrap: anywhere;
}

/* « en train d'écrire » */
.as-attente .as-bulle-msg {
    display: inline-flex;
    gap: 5px;
    padding: 14px 16px;
}

.as-attente i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    opacity: .35;
    animation: as-point 1s infinite ease-in-out;
}

.as-attente i:nth-child(2) { animation-delay: .15s; }
.as-attente i:nth-child(3) { animation-delay: .3s; }

@keyframes as-point {
    0%, 80%, 100% { opacity: .3; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-4px); }
}

/* ---------- saisie ---------- */
.as-form {
    padding: 8px 10px 6px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.as-saisie {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 4px 4px 4px 12px;
    border: 1.5px solid var(--border2);
    border-radius: 14px;
    background: var(--surface2);
    transition: border-color .15s, box-shadow .15s, background .15s;
}

.as-saisie:focus-within {
    border-color: var(--accent);
    background: var(--surface);
    box-shadow: 0 0 0 4px rgba(29, 155, 240, .12);
}

.as-champ {
    flex: 1;
    min-width: 0;
    resize: none;
    max-height: 110px;
    border: 0;
    background: transparent;
    color: var(--text);
    padding: 6px 0;
    font: 12.5px/1.45 var(--font-text);
    outline: none;
}

.as-champ::placeholder {
    color: var(--text-dimmer);
}

.as-envoyer {
    flex: none;
    width: 32px;
    height: 32px;
    border-radius: 11px;
    border: 0;
    background: var(--as-grad);
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(76, 108, 255, .3);
    transition: transform .15s, opacity .15s;
}

.as-envoyer:hover {
    transform: scale(1.06);
}

.as-envoyer:disabled {
    opacity: .5;
    cursor: default;
    transform: none;
}

.as-pied {
    margin: 4px 0 0;
    text-align: center;
    font-size: 10px;
    color: var(--text-dimmer);
}

/* ---------- page /assistant/ : le t'chat dans la page ---------- */
.as-widget.as-plein .as-panneau {
    position: relative;
    right: auto;
    bottom: auto;
    width: 100%;
    height: min(700px, calc(100vh - 170px));
    height: min(700px, calc(100dvh - 170px));
    min-height: 460px;
    z-index: 1;
    animation: none;
    box-shadow: 0 18px 50px rgba(15, 20, 25, .08);
}

.as-widget.as-plein .as-fil {
    padding: 24px 22px 12px;
}

.as-widget.as-plein .as-bulle-msg {
    max-width: 80%;
    font-size: 13px;
}

.as-widget.as-plein .as-puces {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
}

.as-widget.as-plein .as-accueil-carte > p {
    max-width: 460px;
}

@media (max-width: 600px) {
    .as-bulle {
        right: 14px;
        bottom: 14px;
        height: 54px;
        width: 54px;
        padding: 0;
        justify-content: center;
    }

    .as-bulle-txt {
        display: none;
    }

    body.has-assistant .back-to-top {
        bottom: 78px;
    }

    .as-widget:not(.as-plein) .as-panneau {
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        height: calc(100vh - 48px);
        height: calc(100dvh - 48px);
        border-radius: 20px 20px 0 0;
        border-bottom: 0;
        transform-origin: bottom center;
    }

    .as-widget.as-plein .as-panneau {
        height: calc(100dvh - 140px);
        min-height: 400px;
    }

    .as-widget.as-plein .as-fil {
        padding: 18px 12px 10px;
    }

    .as-bulle-msg,
    .as-widget.as-plein .as-bulle-msg {
        max-width: 90%;
    }

    .as-widget.as-plein .as-puces {
        grid-template-columns: 1fr;
    }

    .as-champ {
        font-size: 16px; /* pas de zoom automatique sur iPhone */
    }

    .as-pied {
        display: none;
    }

    .as-form {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

@media (prefers-reduced-motion: reduce) {
    .as-bulle,
    .as-bulle::before,
    .as-panneau,
    .as-msg,
    .as-attente i {
        animation: none !important;
        transition: none !important;
    }
}

@media print {
    .as-widget:not(.as-plein) {
        display: none;
    }
}

/* indice de confiance */
.as-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.as-meta .as-source-badge {
    margin-bottom: 0;
}

.as-confiance {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--text-dim);
    cursor: help;
}

.as-jauge {
    width: 46px;
    height: 6px;
    border-radius: 999px;
    background: var(--border2);
    overflow: hidden;
}

.as-jauge i {
    display: block;
    height: 100%;
    border-radius: inherit;
    transition: width .5s ease-out;
}

.as-confiance.is-haute { color: var(--accent2); }
.as-confiance.is-haute .as-jauge i { background: var(--accent2); }
.as-confiance.is-moyenne { color: var(--accent4); }
.as-confiance.is-moyenne .as-jauge i { background: var(--accent4); }
.as-confiance.is-basse { color: var(--err); }
.as-confiance.is-basse .as-jauge i { background: var(--err); }

/* questions sans compte */
.as-quota-accueil {
    display: block;
    max-width: 330px;
    margin: 0 auto 10px !important;
    padding: 7px 12px;
    border-radius: 12px;
    line-height: 1.5;
    background: rgba(255, 122, 0, .08);
    border: 1px solid rgba(255, 122, 0, .22);
    font-size: 11px;
    color: var(--text-dim);
}

.as-quota-accueil a,
.as-quota a {
    color: var(--accent);
    font-weight: 700;
}

.as-quota {
    display: block;
    margin: 10px 0 0 !important;
    padding-top: 8px;
    border-top: 1px dashed var(--border2);
    line-height: 1.5;
    font-size: 10.5px;
    color: var(--text-dimmer);
}

.as-limite {
    text-align: center;
    padding: 4px 2px;
}

.as-limite-icone {
    width: 44px;
    height: 44px;
    margin: 0 auto 8px;
    border-radius: 14px;
    background: var(--as-grad);
    color: #fff;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(76, 108, 255, .3);
}

.as-limite-titre {
    font-weight: 800;
    font-size: 13.5px;
    color: var(--text);
    margin-bottom: 4px !important;
}

.as-limite p {
    color: var(--text-dim);
}

.as-limite-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

.as-limite-actions .as-lien,
.as-limite-actions .as-support {
    margin-top: 6px;
}

.as-quota .mdi,
.as-quota-accueil .mdi {
    margin-right: 3px;
}
