/* ================================================
   AI ASSISTANT — floating chat widget (Claude-powered)
================================================ */
.ai-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--z-ai-widget);
}

/* --- Floating trigger button --- */
.ai-fab {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 2px solid rgba(232, 238, 248, .18);
    background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
    box-shadow: 0 0 20px rgba(59, 130, 246, .55), 0 0 40px rgba(29, 78, 216, .35), 0 0 60px rgba(29, 78, 216, .18);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}

body.has-fine-pointer .ai-fab {
    cursor: none;
}

.ai-fab:hover {
    transform: scale(1.08) rotate(4deg);
    box-shadow: 0 0 30px rgba(59, 130, 246, .75), 0 0 50px rgba(29, 78, 216, .5), 0 0 70px rgba(29, 78, 216, .25);
}

.ai-fab::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: linear-gradient(to bottom, rgba(255, 255, 255, .25), transparent 60%);
    opacity: .35;
    pointer-events: none;
}

.ai-fab-ping {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--blue);
    opacity: .22;
    animation: ai-ping 2s cubic-bezier(0, 0, .2, 1) infinite;
    pointer-events: none;
}

.ai-fab-icon {
    position: relative;
    z-index: 1;
    display: flex;
    color: #fff;
    transition: transform var(--dur-base) var(--ease-out);
}

.ai-fab-icon svg {
    width: 28px;
    height: 28px;
}

.ai-fab-icon .ai-icon-close {
    display: none;
}

.ai-widget.is-open .ai-fab {
    transform: rotate(90deg);
}

.ai-widget.is-open .ai-fab:hover {
    transform: rotate(90deg) scale(1.08);
}

.ai-widget.is-open .ai-fab-icon .ai-icon-bot {
    display: none;
}

.ai-widget.is-open .ai-fab-icon .ai-icon-close {
    display: flex;
}

@keyframes ai-ping {

    75%,
    100% {
        transform: scale(1.15);
        opacity: 0;
    }
}

/* --- Chat panel --- */
.ai-panel {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: min(400px, calc(100vw - 48px));
    height: min(600px, calc(100vh - 140px));
    transform-origin: bottom right;
    opacity: 0;
    transform: scale(.85) translateY(16px);
    pointer-events: none;
    transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) cubic-bezier(.175, .885, .32, 1.275);
}

.ai-widget.is-open .ai-panel {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

.ai-panel-inner {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    border-radius: 22px;
    background: linear-gradient(160deg, rgba(10, 20, 40, .94) 0%, rgba(6, 12, 24, .97) 100%);
    border: 1px solid var(--border-chr);
    box-shadow: 0 24px 60px rgba(0, 0, 0, .55), 0 0 0 1px rgba(59, 130, 246, .06);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    overflow: hidden;
}

.ai-panel-glow {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(59, 130, 246, .06), transparent, rgba(59, 130, 246, .04));
    pointer-events: none;
}

/* Header */
.ai-header {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 16px 16px 14px 18px;
    border-bottom: 1px solid var(--border-chr);
    flex-shrink: 0;
}

.ai-status {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.ai-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
    color: #fff;
    box-shadow: 0 0 12px rgba(59, 130, 246, .45);
}

.ai-avatar svg {
    width: 18px;
    height: 18px;
}

.ai-status-name {
    display: block;
    font-family: var(--f-head);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: .2px;
}

.ai-status-line {
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: var(--f-body);
    font-size: 11.5px;
    color: var(--text-sec);
}

.ai-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    animation: ai-pulse 2s ease-in-out infinite;
}

@keyframes ai-pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: .4;
    }
}

.ai-header-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.ai-close,
.ai-reset {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-sec);
    cursor: pointer;
    transition: background var(--dur-fast) ease, color var(--dur-fast) ease, transform var(--dur-fast) ease;
}

body.has-fine-pointer .ai-close,
body.has-fine-pointer .ai-reset {
    cursor: none;
}

.ai-close:hover,
.ai-reset:hover {
    background: rgba(192, 212, 232, .1);
    color: var(--text);
}

.ai-reset:hover {
    transform: rotate(-45deg);
}

.ai-close svg,
.ai-reset svg {
    width: 16px;
    height: 16px;
}

/* Messages */
.ai-messages {
    position: relative;
    z-index: 1;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 16px;
    scroll-behavior: smooth;
}

.ai-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-messages::-webkit-scrollbar-thumb {
    background: rgba(192, 212, 232, .15);
    border-radius: 3px;
}

.ai-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
    animation: ai-msg-in .3s var(--ease-out);
}

@keyframes ai-msg-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-msg--user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ai-msg--assistant,
.ai-msg--error {
    align-self: flex-start;
}

.ai-msg-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 2px;
}

.ai-msg--assistant .ai-msg-avatar {
    background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
    color: #fff;
}

.ai-msg--assistant .ai-msg-avatar svg {
    width: 14px;
    height: 14px;
}

.ai-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-family: var(--f-body);
    font-size: 13.5px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-msg--user .ai-msg-bubble {
    background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ai-msg--assistant .ai-msg-bubble {
    background: rgba(192, 212, 232, .07);
    border: 1px solid var(--border-chr);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.ai-msg--error .ai-msg-bubble {
    background: rgba(239, 68, 68, .1);
    border: 1px solid rgba(239, 68, 68, .3);
    color: #FCA5A5;
}

.ai-msg-bubble a {
    color: var(--blue);
    text-decoration: underline;
}

.ai-md-p {
    margin: 0;
}

.ai-md-p+.ai-md-p,
.ai-md-p+.ai-md-list,
.ai-md-list+.ai-md-p {
    margin-top: 10px;
}

.ai-md-list {
    margin: 0;
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-md-list li {
    padding-left: 2px;
}

.ai-msg-bubble strong {
    font-weight: 700;
    color: inherit;
}

.ai-msg--assistant.is-typing .ai-msg-bubble {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 13px 14px;
}

.ai-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-sec);
    animation: ai-typing-bounce 1.2s infinite ease-in-out;
}

.ai-typing-dot:nth-child(2) {
    animation-delay: .15s;
}

.ai-typing-dot:nth-child(3) {
    animation-delay: .3s;
}

@keyframes ai-typing-bounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: .5;
    }

    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Suggested prompts (welcome state) */
.ai-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
    padding-left: 34px;
}

.ai-suggestion {
    padding: 6px 12px;
    font-family: var(--f-body);
    font-size: 12px;
    color: var(--chrome);
    background: rgba(192, 212, 232, .05);
    border: 1px solid var(--border-chr);
    border-radius: 20px;
    cursor: pointer;
    transition: background var(--dur-fast) ease, color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}

body.has-fine-pointer .ai-suggestion {
    cursor: none;
}

.ai-suggestion:hover {
    background: rgba(59, 130, 246, .12);
    border-color: rgba(59, 130, 246, .3);
    color: var(--text);
}

/* Input bar */
.ai-inputbar {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--border-chr);
    flex-shrink: 0;
}

.ai-textarea {
    flex: 1;
    max-height: 120px;
    padding: 10px 14px;
    border: 1px solid var(--border-chr);
    border-radius: 14px;
    outline: none;
    resize: none;
    background: rgba(192, 212, 232, .04);
    font-family: var(--f-body);
    font-size: 13.5px;
    line-height: 1.5;
    color: var(--text);
    transition: border-color var(--dur-fast) ease, background var(--dur-fast) ease;
}

.ai-textarea:focus {
    border-color: rgba(59, 130, 246, .4);
    background: rgba(192, 212, 232, .06);
}

.ai-textarea::placeholder {
    color: var(--text-sec);
}

.ai-textarea:disabled {
    opacity: .5;
}

.ai-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(29, 78, 216, .35);
    transition: transform var(--dur-fast) ease, box-shadow var(--dur-fast) ease, opacity var(--dur-fast) ease;
}

body.has-fine-pointer .ai-send {
    cursor: none;
}

.ai-send svg {
    width: 17px;
    height: 17px;
}

.ai-send:hover:not(:disabled) {
    transform: scale(1.06);
    box-shadow: 0 10px 24px rgba(29, 78, 216, .5);
}

.ai-send:active:not(:disabled) {
    transform: scale(.94);
}

.ai-send:disabled {
    opacity: .4;
    cursor: not-allowed;
    box-shadow: none;
}

/* Footer disclaimer */
.ai-footer {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 16px 12px;
    font-family: var(--f-body);
    font-size: 10.5px;
    color: var(--text-sec);
    flex-shrink: 0;
}

.ai-footer a {
    color: var(--blue);
    text-decoration: none;
    white-space: nowrap;
}

.ai-footer a:hover {
    text-decoration: underline;
}

@media (max-width: 480px) {
    .ai-widget {
        bottom: 18px;
        right: 18px;
    }

    .ai-panel {
        width: calc(100vw - 24px);
        height: min(70vh, 600px);
        right: -6px;
    }

    .ai-footer span {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {

    .ai-fab-ping,
    .ai-status-dot,
    .ai-typing-dot,
    .ai-msg {
        animation: none !important;
    }
}
