/* Assistant AGETIC — charte : teal #009A96, teal foncé #007C78, teal clair #E6F5F4, dark #2A2E35, bg #F8FAFC */
:root {
    --afc-primary: #009A96;
    --afc-primary-dark: #007C78;
    --afc-primary-light: #E6F5F4;
    --afc-dark: #2A2E35;
    --afc-bg: #FFFFFF;
    --afc-bg-soft: #F8FAFC;
    --afc-text: #2A2E35;
    --afc-muted: #6B7280;
    --afc-border: #E5E7EB;
    --afc-radius: 18px;
    --afc-font: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --afc-font-title: 'Roboto', 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

.afc-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

#afc-chatbox-root {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99990;
    font-family: var(--afc-font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--afc-text);
}
#afc-chatbox-root *, #afc-chatbox-root *::before, #afc-chatbox-root *::after { box-sizing: border-box; }

/* ---- Bulle ---- */
#afc-toggle {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: #fff;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 0 3px var(--afc-primary), 0 10px 25px rgba(0, 154, 150, 0.35), 0 2px 6px rgba(0, 0, 0, 0.12);
    transition: transform .2s ease, box-shadow .2s ease, background .25s ease;
    padding: 0;
    margin: 0;
    outline: none;
}
#afc-toggle:hover { transform: translateY(-2px) scale(1.04); box-shadow: inset 0 0 0 3px var(--afc-primary-dark), 0 14px 30px rgba(0, 154, 150, 0.4), 0 3px 8px rgba(0, 0, 0, 0.14); }
#afc-toggle:focus-visible { box-shadow: inset 0 0 0 3px var(--afc-primary), 0 0 0 4px rgba(0, 154, 150, 0.35); }
#afc-toggle img.afc-ico-logo { width: 40px; height: 40px; object-fit: contain; display: block; }
.afc-open #afc-toggle { background: linear-gradient(135deg, var(--afc-primary) 0%, var(--afc-primary-dark) 100%); }
#afc-toggle .afc-ico { width: 28px; height: 28px; position: absolute; transition: opacity .2s ease, transform .25s ease; }
#afc-toggle .afc-ico-close { opacity: 0; transform: rotate(-90deg) scale(.6); }
.afc-open #afc-toggle img.afc-ico-logo { opacity: 0; transform: rotate(90deg) scale(.6); }
.afc-open #afc-toggle .afc-ico-close { opacity: 1; transform: rotate(0) scale(1); }

#afc-toggle .afc-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--afc-primary-dark);
    color: #fff;
    border: 2px solid #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
    animation: afc-pop .5s ease both;
}
.afc-open #afc-toggle .afc-badge { display: none; }

/* Halo discret pour attirer l'œil (une fois, puis calme) */
#afc-toggle::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(0, 154, 150, .45);
    animation: afc-pulse 2.4s ease-out 3;
}

/* ---- Panneau ---- */
#afc-panel {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 370px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 120px);
    background: var(--afc-bg);
    border-radius: var(--afc-radius);
    box-shadow: 0 24px 60px rgba(42, 46, 53, 0.22), 0 4px 14px rgba(42, 46, 53, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--afc-border);
    transform-origin: bottom right;
    animation: afc-rise .25s cubic-bezier(.2, .8, .3, 1) both;
}
#afc-panel[hidden] { display: none; }

/* ---- En-tête ---- */
#afc-header {
    background: linear-gradient(135deg, var(--afc-primary) 0%, var(--afc-primary-dark) 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.afc-header-id { display: flex; align-items: center; gap: 12px; min-width: 0; }
.afc-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: #fff;
    object-fit: contain;
    padding: 4px;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .15);
    display: block;
}
.afc-avatar-fallback { display: flex; align-items: center; justify-content: center; color: var(--afc-primary-dark); font-family: var(--afc-font-title); font-weight: 900; font-size: 18px; }
.afc-title { font-family: var(--afc-font-title); font-weight: 700; font-size: 15px; letter-spacing: .01em; line-height: 1.2; }
.afc-status { font-size: 12px; opacity: .9; display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.afc-dot { width: 8px; height: 8px; border-radius: 50%; background: #7CF2C1; box-shadow: 0 0 0 3px rgba(124, 242, 193, .3); display: inline-block; }

#afc-header button {
    background: rgba(255, 255, 255, .14);
    border: none;
    color: #fff;
    width: 34px; height: 34px;
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s ease;
    flex-shrink: 0;
}
#afc-header button:hover { background: rgba(255, 255, 255, .26); }
#afc-header button svg { width: 18px; height: 18px; }

/* ---- Messages ---- */
#afc-messages {
    flex: 1;
    padding: 16px 14px 8px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--afc-bg-soft);
    scroll-behavior: smooth;
}
#afc-messages::-webkit-scrollbar { width: 6px; }
#afc-messages::-webkit-scrollbar-thumb { background: rgba(42, 46, 53, .15); border-radius: 3px; }

.afc-msg {
    max-width: 84%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    animation: afc-fade .25s ease both;
}
.afc-msg-user {
    align-self: flex-end;
    background: var(--afc-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.afc-msg-bot {
    align-self: flex-start;
    background: #fff;
    color: var(--afc-text);
    border: 1px solid var(--afc-border);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(42, 46, 53, .05);
}

.afc-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--afc-primary-light);
    color: var(--afc-primary-dark) !important;
    font-weight: 600;
    font-size: 13px;
    text-decoration: none !important;
    border: 1px solid rgba(0, 154, 150, .25);
    transition: background .15s ease, color .15s ease, transform .15s ease;
}
.afc-link::after { content: '→'; font-weight: 700; }
.afc-link:hover { background: var(--afc-primary); color: #fff !important; transform: translateX(2px); }

/* ---- Indicateur de frappe ---- */
.afc-typing { display: flex; gap: 5px; padding: 12px 16px; }
.afc-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--afc-primary); opacity: .35; animation: afc-blink 1s infinite ease-in-out; }
.afc-typing span:nth-child(2) { animation-delay: .15s; }
.afc-typing span:nth-child(3) { animation-delay: .3s; }

/* ---- Saisie ---- */
#afc-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--afc-border);
    background: #fff;
    flex-shrink: 0;
}
#afc-input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--afc-border);
    border-radius: 999px;
    padding: 10px 16px;
    font-family: var(--afc-font);
    font-size: 14px;
    color: var(--afc-text);
    background: var(--afc-bg-soft);
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
    box-shadow: none;
    margin: 0;
    height: auto;
    line-height: 1.4;
}
#afc-input::placeholder { color: #9CA3AF; }
#afc-input:focus { border-color: var(--afc-primary); box-shadow: 0 0 0 3px rgba(0, 154, 150, .18); background: #fff; }
#afc-form button {
    width: 42px; height: 42px;
    border-radius: 50%;
    background: var(--afc-primary);
    color: #fff;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background .15s ease, transform .15s ease;
}
#afc-form button svg { width: 18px; height: 18px; }
#afc-form button:hover { background: var(--afc-primary-dark); transform: scale(1.05); }

.afc-footnote {
    font-size: 10.5px;
    color: var(--afc-muted);
    text-align: center;
    padding: 0 12px 8px;
    background: #fff;
    letter-spacing: .01em;
}

/* ---- Animations ---- */
@keyframes afc-rise { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes afc-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes afc-blink { 0%, 80%, 100% { opacity: .35; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@keyframes afc-pulse { 0% { box-shadow: 0 0 0 0 rgba(0, 154, 150, .5); } 100% { box-shadow: 0 0 0 18px rgba(0, 154, 150, 0); } }
@keyframes afc-pop { from { transform: scale(0); } to { transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
    #afc-panel, .afc-msg, .afc-badge, #afc-toggle::before, .afc-typing span { animation: none !important; }
    #afc-toggle, .afc-link, #afc-form button { transition: none; }
}

/* ---- Mobile : panneau quasi plein écran ---- */
@media (max-width: 639px) {
    #afc-chatbox-root { bottom: 16px; right: 16px; }
    #afc-toggle { width: 54px; height: 54px; }
    #afc-toggle img.afc-ico-logo { width: 36px; height: 36px; }
    #afc-panel {
        position: fixed;
        left: 12px; right: 12px; bottom: 84px;
        width: auto; max-width: none;
        height: auto;
        max-height: calc(100vh - 100px);
        max-height: calc(100dvh - 100px);
        transform-origin: bottom right;
    }
}
