/* Admin AI — soft blue/purple chat dock (reference UI) */
:root {
    --ai-blue: #4f7cff;
    --ai-blue-deep: #3b6af5;
    --ai-violet: #8b7cf6;
    --ai-violet-deep: #6d5ef5;
    --ai-sky: #6eb6ff;
    --ai-mist: #eef3ff;
    --ai-fog: #f6f8fd;
    --ai-ink: #1e2a4a;
    --ai-muted: #7a849c;
    --ai-card: #ffffff;
    --ai-bot-bubble: #ffffff;
    --ai-user-from: #5b8cff;
    --ai-user-to: #6d5ef5;
    --ai-radius: 24px;
    --ai-grad: linear-gradient(115deg, #6eb6ff 0%, #6d8dff 45%, #8b7cf6 100%);
}

.admin-ai-root {
    position: fixed !important;
    left: 1.25rem !important;
    right: auto !important;
    bottom: 1.35rem !important;
    z-index: 20000 !important;
    font-family: inherit;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.85rem;
}

.admin-ai-root > * {
    pointer-events: auto;
}

/* —— FAB —— */
.admin-ai-fab {
    width: 3.55rem !important;
    height: 3.55rem !important;
    border-radius: 50% !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 1.45rem !important;
    padding: 0 !important;
    position: relative !important;
    color: #fff !important;
    background: var(--ai-grad) !important;
    border: none !important;
    box-shadow:
        0 12px 28px rgba(79, 124, 255, 0.38),
        0 0 0 0 rgba(109, 94, 245, 0.35) !important;
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.28s ease !important;
    animation: aiFabPulse 3s ease-out infinite;
    overflow: hidden;
}

.admin-ai-fab.is-open {
    animation: none;
    background: linear-gradient(145deg, #5b8cff, #4f6ef0) !important;
}

.admin-ai-fab::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.32), transparent 55%);
    pointer-events: none;
}

.admin-ai-fab .admin-ai-fab-icon,
.admin-ai-fab > i {
    position: relative;
    z-index: 1;
    width: 1.55rem;
    height: 1.55rem;
    display: block;
    line-height: 1;
}

.admin-ai-fab > i {
    font-size: 1.55rem;
    width: auto;
    height: auto;
}

.admin-ai-fab .admin-ai-fab-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.admin-ai-fab:hover {
    transform: translateY(-3px) scale(1.05) !important;
    animation: none;
    box-shadow: 0 16px 34px rgba(79, 124, 255, 0.45) !important;
}

.admin-ai-fab:active {
    transform: scale(0.95) !important;
}

.admin-ai-fab-label {
    display: none;
}

@keyframes aiFabPulse {
    0% {
        box-shadow:
            0 12px 28px rgba(79, 124, 255, 0.38),
            0 0 0 0 rgba(109, 94, 245, 0.4);
    }
    70% {
        box-shadow:
            0 12px 28px rgba(79, 124, 255, 0.22),
            0 0 0 14px rgba(109, 94, 245, 0);
    }
    100% {
        box-shadow:
            0 12px 28px rgba(79, 124, 255, 0.38),
            0 0 0 0 rgba(109, 94, 245, 0);
    }
}

/* —— Panel —— */
.admin-ai-panel {
    width: min(400px, calc(100vw - 1.75rem));
    height: min(600px, calc(100vh - 5.5rem));
    background: var(--ai-card);
    border-radius: var(--ai-radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(109, 141, 255, 0.14);
    box-shadow:
        0 28px 64px rgba(30, 42, 74, 0.16),
        0 2px 0 rgba(255, 255, 255, 0.85) inset;
    transform-origin: bottom left;
    animation: aiPanelIn 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes aiPanelIn {
    from {
        opacity: 0;
        transform: translate3d(-12px, 24px, 0) scale(0.94);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
    }
}

/* —— Header —— */
.admin-ai-header {
    background: var(--ai-grad);
    color: #fff;
    padding: 1.05rem 1rem;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.65rem;
    position: relative;
    overflow: hidden;
}

.admin-ai-header::before {
    content: "";
    position: absolute;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.22), transparent 70%);
    top: -70px;
    left: -40px;
    animation: aiHeaderGlow 6s ease-in-out infinite alternate;
}

.admin-ai-header::after {
    content: "";
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.16), transparent 70%);
    bottom: -50px;
    right: 12%;
}

@keyframes aiHeaderGlow {
    from { opacity: 0.55; transform: translate(0, 0); }
    to { opacity: 1; transform: translate(14px, 8px); }
}

.admin-ai-header-text {
    flex: 1;
    min-width: 0;
    position: relative;
    z-index: 1;
    text-align: right;
    padding-top: 0.1rem;
}

.admin-ai-header-text strong {
    display: block;
    font-size: 1.08rem;
    font-weight: 700;
    line-height: 1.3;
}

.admin-ai-header-text small {
    display: block;
    opacity: 0.92;
    font-size: 0.72rem;
    line-height: 1.55;
    margin-top: 0.28rem;
}

.admin-ai-header-icon-btn {
    width: 2.05rem;
    height: 2.05rem;
    border: none;
    border-radius: 0.7rem;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    transition: background 0.2s ease, transform 0.2s ease;
    padding: 0;
}

.admin-ai-header-icon-btn.static {
    pointer-events: none;
}

.admin-ai-header-icon-btn svg {
    width: 1.05rem;
    height: 1.05rem;
    display: block;
}

button.admin-ai-header-icon-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

/* —— Avatars —— */
.admin-ai-avatar {
    width: 2.15rem;
    height: 2.15rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1rem;
    color: #fff;
    position: relative;
}

.admin-ai-avatar svg {
    width: 1.1rem;
    height: 1.1rem;
    display: block;
}

.admin-ai-avatar.bot {
    background: var(--ai-grad);
    box-shadow:
        0 4px 12px rgba(79, 124, 255, 0.28),
        0 0 0 2px rgba(255, 255, 255, 0.95);
}

.admin-ai-avatar.user {
    background: linear-gradient(145deg, #9aa8c7 0%, #6b7896 100%);
    box-shadow:
        0 4px 12px rgba(107, 120, 150, 0.28),
        0 0 0 2px rgba(255, 255, 255, 0.95);
    color: #fff;
}

/* —— Messages —— */
.admin-ai-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.15rem 0.95rem 0.85rem;
    background:
        radial-gradient(80% 50% at 100% 0%, rgba(110, 182, 255, 0.12), transparent 55%),
        radial-gradient(70% 45% at 0% 100%, rgba(139, 124, 246, 0.1), transparent 50%),
        linear-gradient(180deg, var(--ai-fog) 0%, #fff 100%);
    scroll-behavior: smooth;
}

.admin-ai-messages::-webkit-scrollbar {
    width: 5px;
}
.admin-ai-messages::-webkit-scrollbar-thumb {
    background: rgba(122, 132, 156, 0.3);
    border-radius: 999px;
}

.admin-ai-empty {
    text-align: center;
    padding: 1.35rem 0.2rem 0.85rem;
    animation: aiMsgIn 0.4s ease both;
}

.admin-ai-empty-icon {
    width: 4.6rem;
    height: 4.6rem;
    margin: 0 auto 1.05rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 50% 40%, rgba(110, 182, 255, 0.35), transparent 65%),
        radial-gradient(circle at 50% 60%, rgba(139, 124, 246, 0.28), transparent 70%);
    box-shadow: 0 0 0 10px rgba(110, 182, 255, 0.08);
    position: relative;
}

.admin-ai-empty-face {
    width: 2.85rem;
    height: 2.85rem;
    border-radius: 50%;
    background: linear-gradient(160deg, #5b6fd8 0%, #4a3f9e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.42rem;
    box-shadow: 0 10px 22px rgba(74, 63, 158, 0.35);
}

.admin-ai-empty-face i {
    width: 0.42rem;
    height: 0.42rem;
    border-radius: 50%;
    background: #fff;
    display: block;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.15);
}

.admin-ai-empty h6 {
    margin: 0 0 0.4rem;
    color: var(--ai-ink);
    font-weight: 700;
    font-size: 1.18rem;
}

.admin-ai-empty p {
    margin: 0 0 1.2rem;
    color: var(--ai-muted);
    font-size: 0.84rem;
    line-height: 1.7;
    max-width: 19rem;
    margin-inline: auto;
}

.admin-ai-suggestions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    text-align: right;
}

.admin-ai-suggest-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    border: 1px solid rgba(109, 141, 255, 0.16);
    background: #fff;
    border-radius: 1rem;
    padding: 0.75rem 0.65rem 0.7rem;
    min-height: 7.2rem;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    text-align: right;
}

.admin-ai-suggest-card:hover {
    transform: translateY(-3px);
    border-color: rgba(109, 141, 255, 0.4);
    box-shadow: 0 12px 24px rgba(79, 124, 255, 0.12);
}

.admin-ai-suggest-icon {
    width: 1.7rem;
    height: 1.7rem;
    border-radius: 0.55rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ai-violet-deep);
    background: linear-gradient(145deg, rgba(110, 182, 255, 0.18), rgba(139, 124, 246, 0.18));
    font-size: 0.95rem;
}

.admin-ai-suggest-title {
    color: var(--ai-ink);
    font-size: 0.74rem;
    font-weight: 700;
    line-height: 1.45;
}

.admin-ai-suggest-hint {
    color: var(--ai-muted);
    font-size: 0.64rem;
    line-height: 1.4;
    margin-top: auto;
}

/* —— Message rows —— */
.admin-ai-msg {
    display: flex;
    align-items: flex-end;
    gap: 0.55rem;
    margin-bottom: 1rem;
    animation: aiMsgIn 0.34s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes aiMsgIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.admin-ai-msg.bot {
    justify-content: flex-start;
}

.admin-ai-msg.user {
    justify-content: flex-end;
}

.admin-ai-msg-body {
    max-width: min(78%, 290px);
    display: flex;
    flex-direction: column;
    gap: 0.28rem;
}

.admin-ai-msg.user .admin-ai-msg-body {
    align-items: flex-end;
}

.admin-ai-msg.bot .admin-ai-msg-body {
    align-items: flex-start;
}

.admin-ai-msg-meta {
    font-size: 0.68rem;
    color: var(--ai-muted);
    padding-inline: 0.4rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.admin-ai-bubble {
    padding: 0.78rem 1rem;
    border-radius: 1.15rem;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.9rem;
    line-height: 1.7;
    position: relative;
}

.admin-ai-msg.bot .admin-ai-bubble {
    background: var(--ai-bot-bubble);
    color: var(--ai-ink);
    border: 1px solid rgba(109, 141, 255, 0.12);
    border-bottom-right-radius: 0.3rem;
    box-shadow:
        0 6px 18px rgba(30, 42, 74, 0.06),
        0 1px 0 rgba(255, 255, 255, 0.9) inset;
}

.admin-ai-msg.user .admin-ai-bubble {
    background: linear-gradient(145deg, var(--ai-user-from) 0%, var(--ai-user-to) 100%);
    color: #fff;
    border-bottom-left-radius: 0.3rem;
    box-shadow:
        0 8px 20px rgba(79, 124, 255, 0.24),
        0 1px 0 rgba(255, 255, 255, 0.15) inset;
}

.admin-ai-bubble.typing {
    padding: 0.9rem 1.1rem;
    min-width: 3.6rem;
}

.admin-ai-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.2rem;
}

.admin-ai-link-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
    border: 1px solid rgba(109, 141, 255, 0.18);
    border-radius: 999px;
    padding: 0.38rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ai-blue-deep);
    background: var(--ai-mist);
    transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.admin-ai-link-chip:hover {
    transform: translateY(-1px);
    background: var(--ai-blue-deep);
    border-color: var(--ai-blue-deep);
    color: #fff;
}

.admin-ai-typing {
    display: inline-flex;
    gap: 0.3rem;
    align-items: center;
}

.admin-ai-typing span {
    width: 0.36rem;
    height: 0.36rem;
    border-radius: 50%;
    background: var(--ai-violet);
    animation: aiDot 1.05s ease-in-out infinite;
}

.admin-ai-typing span:nth-child(2) { animation-delay: 0.14s; }
.admin-ai-typing span:nth-child(3) { animation-delay: 0.28s; }

@keyframes aiDot {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
    40% { transform: translateY(-5px); opacity: 1; }
}

/* —— Composer —— */
.admin-ai-composer {
    padding: 0.75rem 0.85rem 0.95rem;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(109, 141, 255, 0.1);
}

.admin-ai-input {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: #fff;
    border: 1px solid rgba(122, 132, 156, 0.22);
    border-radius: 1.15rem;
    padding: 0.35rem 0.35rem 0.35rem 0.65rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.admin-ai-input:focus-within {
    border-color: rgba(79, 124, 255, 0.55);
    box-shadow: 0 0 0 3px rgba(79, 124, 255, 0.14);
}

.admin-ai-input .form-control {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 0.5rem 0.35rem;
    font-size: 0.88rem;
    color: var(--ai-ink);
}

.admin-ai-input .form-control::placeholder {
    color: #9aa3b8;
}

.admin-ai-input .form-control:focus {
    box-shadow: none !important;
}

.admin-ai-send {
    width: 2.45rem;
    height: 2.45rem;
    border: none;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1rem;
    background: var(--ai-grad);
    box-shadow: 0 8px 18px rgba(79, 124, 255, 0.3);
    transition: transform 0.2s ease, filter 0.2s ease, opacity 0.2s ease;
    flex-shrink: 0;
}

.admin-ai-send:hover:not(:disabled) {
    transform: translateY(-1px) scale(1.04);
    filter: brightness(1.06);
}

.admin-ai-send:disabled {
    opacity: 0.4;
    box-shadow: none;
}

.admin-ai-error {
    color: #9b4a4a;
    background: #fdf2f2;
    border: 1px solid #f0d4d4;
    border-radius: 0.8rem;
    font-size: 0.78rem;
    padding: 0.48rem 0.7rem;
    margin-bottom: 0.45rem;
}

/* —— Header button —— */
.admin-ai-header-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-inline-end: 0.75rem;
    white-space: nowrap;
    border-radius: 999px !important;
    background: var(--ai-grad) !important;
    border: none !important;
    box-shadow: 0 6px 16px rgba(79, 124, 255, 0.28);
    transition: transform 0.2s ease, box-shadow 0.2s ease !important;
}

.admin-ai-header-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 22px rgba(79, 124, 255, 0.36);
}

.admin-ai-header-btn .admin-ai-hdr-icon {
    width: 1rem;
    height: 1rem;
}

@media (max-width: 420px) {
    .admin-ai-suggestions {
        grid-template-columns: 1fr;
    }

    .admin-ai-suggest-card {
        min-height: 0;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.45rem 0.6rem;
    }

    .admin-ai-suggest-title,
    .admin-ai-suggest-hint {
        flex: 1 1 calc(100% - 2.4rem);
    }

    .admin-ai-suggest-hint {
        margin-top: 0;
        padding-inline-start: 2.3rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .admin-ai-fab,
    .admin-ai-panel,
    .admin-ai-msg,
    .admin-ai-empty,
    .admin-ai-header::before {
        animation: none !important;
    }
}
