.aa-widget {
    --aa-primary: #e1061b;
    --aa-primary-dark: #b90518;
    --aa-primary-light: #ff5a6a;
    --aa-primary-soft: rgba(225, 6, 27, .1);
    --aa-fab-red: var(--aa-primary);
    --aa-fab-red-dark: var(--aa-primary-dark);
    --aa-fab-red-glow: rgba(225, 6, 27, .4);
    --aa-radius: 18px;
    position: fixed !important;
    right: clamp(12px, 2vw, 22px) !important;
    bottom: clamp(72px, 9vw, 88px) !important;
    z-index: 99990 !important;
    font-family: 'Segoe UI', system-ui, sans-serif;
    pointer-events: none;
}
.aa-widget * { box-sizing: border-box; }
.aa-widget .aa-fab,
.aa-widget .aa-panel,
.aa-widget .aa-overlay { pointer-events: auto; }

.aa-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .28);
    z-index: -1;
    opacity: 0;
    transition: opacity .25s ease;
}
.aa-widget.open .aa-overlay {
    display: block;
    opacity: 1;
}

.aa-fab {
    position: relative;
    width: 62px;
    height: 62px;
    border: none;
    border-radius: 50%;
    padding: 0;
    background: linear-gradient(155deg, var(--aa-primary-light) 0%, var(--aa-fab-red) 42%, var(--aa-fab-red-dark) 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 12px 24px var(--aa-fab-red-glow), 0 4px 10px rgba(0, 0, 0, .16);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    animation: aaBallBounce 1.35s cubic-bezier(.45, .05, .35, .95) infinite;
    transition: transform .2s ease, box-shadow .2s ease;
    overflow: visible;
}
.aa-fab__shadow {
    position: absolute;
    left: 50%;
    bottom: -5px;
    width: 40px;
    height: 8px;
    margin-left: -20px;
    border-radius: 50%;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, .22) 0%, transparent 72%);
    animation: aaBallShadow 1.35s cubic-bezier(.45, .05, .35, .95) infinite;
    pointer-events: none;
    z-index: -1;
}
.aa-fab__bot {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    animation: aaBotWiggle 2.7s ease-in-out infinite;
}
.aa-fab__svg {
    width: 48px;
    height: 48px;
    display: block;
    filter: drop-shadow(0 2px 5px rgba(0, 0, 0, .2));
}
.aa-fab:hover {
    animation-play-state: paused;
    transform: translateY(-4px) scale(1.04);
}

@keyframes aaBallBounce {
    0%, 100% { transform: translateY(0) scale(1.03, .97); }
    38% { transform: translateY(-14px) scale(.96, 1.04); }
    64% { transform: translateY(-6px) scale(.99, 1.01); }
}
@keyframes aaBallShadow {
    0%, 100% { transform: scale(1); opacity: .8; }
    38% { transform: scale(.6); opacity: .35; }
    64% { transform: scale(.85); opacity: .55; }
}
@keyframes aaBotWiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-2deg); }
    75% { transform: rotate(2deg); }
}

.aa-panel {
    position: absolute;
    right: 0;
    bottom: 70px;
    width: min(380px, calc(100vw - 20px));
    height: min(560px, calc(100dvh - 100px));
    max-height: calc(100dvh - 100px);
    background: #fff;
    border-radius: var(--aa-radius);
    box-shadow: 0 18px 48px rgba(15, 23, 42, .18);
    display: none;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(14px) scale(.97);
    transition: opacity .24s ease, transform .24s ease;
    border: 1px solid rgba(15, 23, 42, .08);
}
.aa-widget.open .aa-panel {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
}
.aa-widget.open .aa-fab {
    opacity: 0;
    pointer-events: none;
    transform: scale(.8);
    animation: none;
}
.aa-widget.expanded .aa-panel {
    width: min(440px, calc(100vw - 20px));
    height: min(680px, calc(100dvh - 48px));
    max-height: calc(100dvh - 48px);
}

.aa-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 14px;
    background: linear-gradient(135deg, var(--aa-primary-light) 0%, var(--aa-primary) 50%, var(--aa-primary-dark) 100%);
    color: #fff;
    flex: 0 0 auto;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
}
.aa-panel__brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.aa-panel__avatar,
.aa-join__avatar,
.aa-msg__avatar {
    background: linear-gradient(145deg, #ff5a6a 0%, #e1061b 55%, #b90518 100%);
}
.aa-panel__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: contain;
    background: #fff;
    flex-shrink: 0;
    padding: 3px;
}
.aa-panel__brand strong {
    display: block;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}
.aa-panel__status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    opacity: .92;
    margin-top: 1px;
}
.aa-panel__status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
}
.aa-panel__actions { display: flex; gap: 4px; flex-shrink: 0; }
.aa-icon-btn {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 8px;
    background: rgba(255,255,255,.16);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
}
.aa-icon-btn:hover { background: rgba(255,255,255,.28); }

.aa-panel__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 12px 12px 6px;
    background: #f8fafc;
    -webkit-overflow-scrolling: touch;
}
.aa-join {
    text-align: center;
    margin-bottom: 10px;
    padding: 2px 0 6px;
}
.aa-join__avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: contain;
    margin-bottom: 6px;
    border: 2px solid var(--aa-primary);
    background: #fff;
    padding: 4px;
}
.aa-join p {
    margin: 0;
    font-size: 11px;
    color: #64748b;
    line-height: 1.4;
}

.aa-msg { display: flex; gap: 7px; margin-bottom: 10px; align-items: flex-start; }
.aa-msg--bot .aa-msg__bubble {
    background: #fff;
    border: 1px solid #e2e8f0;
    color: #1e293b;
    border-bottom-left-radius: 4px;
}
.aa-msg--user { flex-direction: row-reverse; align-items: flex-end; }
.aa-msg--user .aa-msg__bubble {
    background: linear-gradient(135deg, var(--aa-primary-light) 0%, var(--aa-primary) 55%, var(--aa-primary-dark) 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, .12);
}
.aa-msg__avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: contain;
    flex-shrink: 0;
    margin-top: 2px;
    background: #fff;
    padding: 2px;
    border: 1px solid #e2e8f0;
}
.aa-msg__bubble {
    max-width: 86%;
    min-width: 0;
    padding: 8px 10px 6px;
    border-radius: 14px;
    font-size: 12px;
    line-height: 1.45;
    box-shadow: 0 1px 6px rgba(15,39,68,.05);
    display: flex;
    flex-direction: column;
    gap: 0;
}
.aa-msg__name {
    display: inline-block;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--aa-primary);
    margin-bottom: 4px;
}
.aa-msg__text {
    font-size: 12px;
    line-height: 1.5;
    word-break: break-word;
}
.aa-msg__meta {
    display: block;
    margin-top: 5px;
    font-size: 9px;
    opacity: .45;
    text-align: right;
}
.aa-msg__refs {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 6px;
}
.aa-msg__ref-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    max-width: 100%;
    padding: 3px 7px;
    border-radius: 999px;
    background: var(--aa-primary-soft);
    border: 1px solid rgba(0, 0, 0, .06);
    color: var(--aa-primary) !important;
    text-decoration: none;
    font-size: 9px;
    font-weight: 600;
    line-height: 1.3;
}
.aa-msg__action {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 8px;
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--aa-primary);
    color: #fff !important;
    font-size: 11px;
    font-weight: 700;
    text-decoration: none;
    align-self: flex-start;
}

.aa-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.aa-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--aa-primary);
    animation: aaDot 1.2s infinite ease-in-out;
}
.aa-typing span:nth-child(2) { animation-delay: .15s; }
.aa-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes aaDot {
    0%, 80%, 100% { transform: translateY(0); opacity: .45; }
    40% { transform: translateY(-4px); opacity: 1; }
}

.aa-panel__foot {
    flex: 0 0 auto;
    padding: 0;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    position: relative;
    z-index: 2;
}
.aa-quick-wrap {
    padding: 8px 10px 0;
    background: linear-gradient(180deg, #fafbfc 0%, #fff 100%);
}
.aa-quick-label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #94a3b8;
    margin-bottom: 6px;
    padding-left: 2px;
}
.aa-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    max-height: 72px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
}
.aa-quick:empty { display: none; }

.aa-quick-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    width: auto;
    max-width: 100%;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #334155;
    border-radius: 999px;
    padding: 5px 10px 5px 5px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    text-align: left;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
    box-shadow: 0 1px 3px rgba(15,39,68,.04);
    flex: 0 1 auto;
}
.aa-quick-btn:hover {
    border-color: var(--aa-primary);
    box-shadow: 0 3px 10px var(--aa-primary-soft);
    transform: translateY(-1px);
}
.aa-quick-btn:active { transform: translateY(0); }
.aa-quick-btn__icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 10px;
    flex-shrink: 0;
}
.aa-quick-btn__text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

.aa-form {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 10px 10px 12px;
    background: #fff;
    border-top: 1px solid #f1f5f9;
}
.aa-input {
    flex: 1;
    min-width: 0;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    padding: 10px 14px;
    font-size: 13px;
    outline: none;
    background: #f8fafc;
    line-height: 1.3;
}
.aa-input:focus {
    border-color: var(--aa-primary);
    background: #fff;
    box-shadow: 0 0 0 3px var(--aa-primary-soft);
}
.aa-send {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--aa-primary-light) 0%, var(--aa-primary) 55%, var(--aa-primary-dark) 100%);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    box-shadow: 0 3px 10px var(--aa-fab-red-glow);
}
.aa-send:disabled { opacity: .45; cursor: default; }

body.aa-chat-open {
    overflow: hidden;
    touch-action: none;
}
@media (min-width: 576px) {
    body.aa-chat-open {
        overflow: auto;
        touch-action: auto;
    }
}

@media (max-width: 575px) {
    .aa-widget {
        bottom: 68px !important;
        right: 8px !important;
    }
    .aa-panel {
        width: calc(100vw - 16px);
        right: -4px;
        bottom: 66px;
        height: min(78dvh, 620px);
        max-height: calc(100dvh - 80px);
    }
    .aa-fab { width: 56px; height: 56px; }
    .aa-fab__svg { width: 42px; height: 42px; }
    .aa-panel__brand strong { max-width: 160px; font-size: 12px; }
    .aa-quick-btn__text { max-width: 110px; }
    .aa-widget.open .aa-overlay { display: block; }
}

@media (prefers-reduced-motion: reduce) {
    .aa-fab, .aa-fab__shadow, .aa-fab__bot { animation: none; }
}
