#aiBtn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 3000;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00ff88, #00ccff);
    border: none;
    cursor: pointer;
    box-shadow: 0 0 20px rgba(0,255,136,0.5), 0 4px 16px rgba(0,0,0,0.4);
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    animation: aiBtnPulse 3s ease-in-out infinite;
}
@keyframes aiBtnPulse {
    0%, 100% { box-shadow: 0 0 20px rgba(0,255,136,0.5), 0 4px 16px rgba(0,0,0,0.4); }
    50%       { box-shadow: 0 0 35px rgba(0,255,136,0.8), 0 4px 20px rgba(0,0,0,0.5); }
}
#aiBtn:hover { transform: scale(1.1); }
#aiBtn.open  { animation: none; background: linear-gradient(135deg, #ff006e, #ff4090); }

#aiPanel {
    position: fixed;
    bottom: 88px;
    right: 24px;
    z-index: 3000;
    width: 360px;
    max-height: 540px;
    background: linear-gradient(145deg, #080d22 0%, #0f1530 100%);
    border: 1.5px solid rgba(0,255,136,0.35);
    border-radius: 16px;
    box-shadow: 0 0 50px rgba(0,255,136,0.12), 0 20px 60px rgba(0,0,0,0.7);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.85) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), opacity 0.2s ease;
    transform-origin: bottom right;
}
#aiPanel.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

#aiPanelHeader {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px 12px;
    border-bottom: 1px solid rgba(0,255,136,0.15);
    background: rgba(0,255,136,0.05);
    flex-shrink: 0;
}
#aiPanelHeader .ai-avatar {
    font-size: 1.6rem;
    line-height: 1;
    filter: drop-shadow(0 0 6px rgba(0,255,136,0.5));
}
.ai-header-text { flex: 1; }
.ai-header-text .ai-name {
    font-family: 'Jersey 15', sans-serif;
    font-size: 1.1rem;
    color: #00ffff;
    letter-spacing: 1px;
    text-shadow: 0 0 8px rgba(0,255,255,0.4);
    display: block;
}
.ai-header-text .ai-status {
    font-family: 'Oxanium', monospace;
    font-size: 0.65rem;
    color: rgba(0,255,136,0.5);
    letter-spacing: 1px;
}
.ai-header-text .ai-status.thinking {
    color: #f5a623;
    animation: aiThinkBlink 0.8s step-end infinite;
}
@keyframes aiThinkBlink { 50% { opacity: 0.3; } }

#aiCloseBtn {
    background: none;
    border: 1px solid rgba(0,255,136,0.2);
    color: rgba(0,255,136,0.4);
    width: 26px;
    height: 26px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}
#aiCloseBtn:hover { color: #00ff88; border-color: #00ff88; background: rgba(0,255,136,0.08); }

#aiMessages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 14px 6px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,255,136,0.2) transparent;
}
#aiMessages::-webkit-scrollbar { width: 3px; }
#aiMessages::-webkit-scrollbar-thumb { background: rgba(0,255,136,0.2); border-radius: 2px; }

.ai-msg {
    display: flex;
    gap: 8px;
    animation: aiMsgIn 0.25s ease;
    max-width: 100%;
}
@keyframes aiMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ai-msg.user { flex-direction: row-reverse; }

.ai-msg-bubble {
    max-width: 84%;
    padding: 9px 12px;
    border-radius: 12px;
    font-family: 'Oxanium', sans-serif;
    font-size: 0.82rem;
    line-height: 1.7;
    word-break: break-word;
}
.ai-msg.bot .ai-msg-bubble {
    background: rgba(0,255,136,0.07);
    border: 1px solid rgba(0,255,136,0.18);
    color: rgba(200,240,255,0.88);
    border-radius: 4px 12px 12px 12px;
}
.ai-msg.user .ai-msg-bubble {
    background: rgba(0,200,255,0.1);
    border: 1px solid rgba(0,200,255,0.25);
    color: rgba(200,240,255,0.9);
    border-radius: 12px 4px 12px 12px;
    white-space: pre-wrap;
}
.ai-msg-avatar {
    font-size: 1.2rem;
    flex-shrink: 0;
    margin-top: 2px;
    line-height: 1;
}

/* ── Markdown rendering styles ── */
.ai-markdown {
    white-space: normal;
}

.ai-markdown br {
    display: block;
    content: '';
    margin-top: 0.1em;
}

.ai-markdown .ai-spacer {
    display: block;
    height: 0.5em;
}

.ai-markdown .ai-line {
    display: inline;
}

/* Headings */
.ai-markdown .ai-heading {
    font-family: 'Jersey 15', sans-serif;
    letter-spacing: 1px;
    margin: 0.5em 0 0.2em;
    line-height: 1.3;
}
.ai-markdown .ai-h1 {
    font-size: 1.05rem;
    color: #00ffff;
    text-shadow: 0 0 8px rgba(0,255,255,0.3);
}
.ai-markdown .ai-h2 {
    font-size: 0.95rem;
    color: #f5a623;
}
.ai-markdown .ai-h3 {
    font-size: 0.88rem;
    color: #00ff88;
}

/* Inline code */
.ai-markdown .ai-inline-code {
    font-family: 'Oxanium', monospace;
    font-size: 0.78rem;
    background: rgba(0,255,136,0.1);
    border: 1px solid rgba(0,255,136,0.25);
    color: #00ff88;
    padding: 1px 5px;
    border-radius: 3px;
    white-space: nowrap;
}

/* Fenced code blocks */
.ai-markdown .ai-code-block {
    margin: 0.6em 0;
    border-radius: 7px;
    overflow: hidden;
    border: 1px solid rgba(0,255,136,0.22);
    background: #06080f;
}

.ai-markdown .ai-code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 10px;
    background: rgba(0,255,136,0.07);
    border-bottom: 1px solid rgba(0,255,136,0.15);
    min-height: 26px;
}

.ai-markdown .ai-code-lang {
    font-family: 'Oxanium', monospace;
    font-size: 0.65rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: rgba(0,255,136,0.45);
}

.ai-markdown .ai-code-copy {
    font-family: 'Oxanium', monospace;
    font-size: 0.65rem;
    background: transparent;
    border: 1px solid rgba(0,255,136,0.25);
    color: rgba(0,255,136,0.5);
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    margin-left: auto;
}
.ai-markdown .ai-code-copy:hover {
    color: #00ff88;
    border-color: #00ff88;
    background: rgba(0,255,136,0.08);
}

.ai-markdown .ai-code-block pre {
    margin: 0;
    padding: 10px 12px;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,255,136,0.2) transparent;
}
.ai-markdown .ai-code-block pre::-webkit-scrollbar { height: 3px; }
.ai-markdown .ai-code-block pre::-webkit-scrollbar-thumb { background: rgba(0,255,136,0.2); border-radius: 2px; }

.ai-markdown .ai-code-block code {
    font-family: 'Oxanium', monospace;
    font-size: 0.78rem;
    line-height: 1.8;
    color: #a8e6cf;
    white-space: pre;
    display: block;
}

/* Lists */
.ai-markdown .ai-list {
    margin: 0.4em 0 0.4em 1.1em;
    padding: 0;
}
.ai-markdown .ai-list li {
    margin: 0.2em 0;
    color: rgba(200,240,255,0.85);
    line-height: 1.65;
}
.ai-markdown ul.ai-list {
    list-style: none;
    margin-left: 0.4em;
}
.ai-markdown ul.ai-list li::before {
    content: '▸';
    color: #00ff88;
    font-size: 0.7rem;
    margin-right: 6px;
    vertical-align: middle;
}
.ai-markdown ol.ai-list {
    list-style: decimal;
    padding-left: 1.2em;
}
.ai-markdown ol.ai-list li::marker {
    color: #f5a623;
    font-size: 0.78rem;
}

/* Strong / em / del */
.ai-markdown strong {
    color: #fff;
    font-weight: 700;
}
.ai-markdown em {
    color: rgba(200,240,255,0.75);
    font-style: italic;
}
.ai-markdown del {
    opacity: 0.5;
    text-decoration: line-through;
}

/* HR */
.ai-markdown .ai-hr {
    border: none;
    border-top: 1px solid rgba(0,255,136,0.15);
    margin: 0.6em 0;
}

/* ── Typing indicator ── */
.ai-typing-indicator {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 10px 14px;
}
.ai-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(0,255,136,0.5);
    animation: aiDotBounce 1.2s ease-in-out infinite;
}
.ai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes aiDotBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40%           { transform: translateY(-6px); opacity: 1; }
}

#aiSuggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 6px 14px 2px;
    flex-shrink: 0;
}
.ai-suggestion {
    font-family: 'Oxanium', monospace;
    font-size: 0.7rem;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(0,255,136,0.05);
    border: 1px solid rgba(0,255,136,0.2);
    color: rgba(0,255,136,0.55);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.ai-suggestion:hover {
    background: rgba(0,255,136,0.12);
    border-color: rgba(0,255,136,0.5);
    color: #00ff88;
}

#aiInputRow {
    display: flex;
    gap: 7px;
    padding: 10px 12px 12px;
    border-top: 1px solid rgba(0,255,136,0.12);
    background: rgba(0,0,0,0.2);
    flex-shrink: 0;
}
#aiInput {
    flex: 1;
    background: rgba(0,0,0,0.35);
    border: 1px solid rgba(0,255,136,0.22);
    border-radius: 8px;
    color: rgba(200,240,255,0.9);
    font-family: 'Oxanium', monospace;
    font-size: 0.82rem;
    padding: 8px 11px;
    outline: none;
    resize: none;
    height: 38px;
    max-height: 100px;
    line-height: 1.5;
    transition: border-color 0.15s;
    overflow-y: hidden;
}
#aiInput:focus { border-color: rgba(0,255,136,0.5); }
#aiInput::placeholder { color: rgba(0,255,136,0.2); }
#aiSendBtn {
    background: #00ff88;
    color: #040e12;
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 38px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
    box-shadow: 0 0 10px rgba(0,255,136,0.3);
}
#aiSendBtn:hover { background: #33ffaa; box-shadow: 0 0 18px rgba(0,255,136,0.55); }
#aiSendBtn:disabled { opacity: 0.4; cursor: not-allowed; }