/* ================================================================
   AFFAS – AI Chat Widget v2 · Premium Design
   ================================================================ */

/* ── Toggle Button ────────────────────────────────────────────── */
#ai-chat-container {
    position: fixed;
    z-index: 1100;
}

.ai-chat-toggle {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00d4ff 0%, #00ffa3 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #050814;
    box-shadow:
        0 0 28px rgba(0, 212, 255, 0.5),
        0 8px 24px rgba(0,0,0,0.4);
    transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1),
                box-shadow 0.3s ease,
                background 0.4s ease;
    z-index: 1101;
    overflow: hidden;
}

.ai-chat-toggle:hover {
    transform: scale(1.12) rotate(-8deg);
    box-shadow:
        0 0 40px rgba(0, 212, 255, 0.7),
        0 12px 32px rgba(0,0,0,0.5);
}

.ai-chat-toggle i {
    transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1);
    position: relative;
    z-index: 2;
}

.ai-chat-toggle.active {
    background: linear-gradient(135deg, #f43f5e, #be123c);
    box-shadow:
        0 0 28px rgba(244,63,94,0.5),
        0 8px 24px rgba(0,0,0,0.4);
}

.ai-chat-toggle.active i {
    transform: rotate(180deg);
}

/* Pulse ring */
.ai-chat-toggle-pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(0,212,255,0.6);
    animation: toggle-ring 2s ease-in-out infinite;
    pointer-events: none;
}

.ai-chat-toggle.active .ai-chat-toggle-pulse {
    border-color: rgba(244,63,94,0.6);
}

@keyframes toggle-ring {
    0%, 100% { transform: scale(1); opacity: 0.7; }
    50%      { transform: scale(1.3); opacity: 0; }
}

/* ── Chat Popup ───────────────────────────────────────────────── */
.ai-chat-popup {
    position: fixed;
    bottom: 6.5rem;
    right: 2rem;
    width: 390px;
    max-height: 580px;
    background: rgba(8, 12, 28, 0.98);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    border: 1px solid rgba(0, 212, 255, 0.15);
    border-radius: 24px;
    box-shadow:
        0 30px 80px rgba(0,0,0,0.8),
        0 0 60px rgba(0,212,255,0.06),
        inset 0 1px 0 rgba(255,255,255,0.08);
    display: flex;
    flex-direction: column;
    z-index: 1100;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1),
                opacity 0.28s ease;
    overflow: hidden;
}

.ai-chat-popup.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}

/* ── Header ───────────────────────────────────────────────────── */
.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid rgba(0,212,255,0.1);
    background: linear-gradient(135deg, rgba(0,212,255,0.06) 0%, rgba(0,255,163,0.03) 100%);
    flex-shrink: 0;
}

.ai-chat-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-chat-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.ai-chat-avatar {
    font-size: 2.2rem;
    line-height: 1;
    filter: drop-shadow(0 0 10px rgba(0,212,255,0.6));
    display: block;
}

.ai-chat-status-dot {
    position: absolute;
    bottom: 0;
    right: -2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid rgba(8, 12, 28, 0.98);
    box-shadow: 0 0 8px #22c55e;
}

.ai-chat-name {
    font-family: var(--font-display, 'Outfit', sans-serif);
    font-weight: 700;
    font-size: 1.05rem;
    background: linear-gradient(135deg, var(--cyan, #00d4ff), var(--green, #00ffa3));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 0.01em;
}

.ai-chat-subtitle {
    font-size: 0.72rem;
    color: var(--text-muted, #94a3b8);
    margin-top: 2px;
}

.ai-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-chat-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.06);
    color: var(--text-dim, #64748b);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.ai-chat-header-btn:hover {
    background: rgba(244,63,94,0.1);
    border-color: rgba(244,63,94,0.2);
    color: var(--danger, #f43f5e);
}

.ai-chat-close {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.06);
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.ai-chat-close:hover {
    background: rgba(244,63,94,0.12);
    border-color: rgba(244,63,94,0.25);
    color: var(--danger, #f43f5e);
}

/* ── Messages ─────────────────────────────────────────────────── */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    max-height: 340px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,212,255,0.15) transparent;
}

.ai-chat-messages::-webkit-scrollbar { width: 4px; }
.ai-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0,212,255,0.15);
    border-radius: 4px;
}

.ai-message {
    display: flex;
    flex-direction: column;
    max-width: 86%;
    animation: msg-in 0.3s cubic-bezier(0.34,1.56,0.64,1) forwards;
}

@keyframes msg-in {
    from { opacity: 0; transform: translateY(10px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ai-message-user {
    align-self: flex-end;
}

.ai-message-bot {
    align-self: flex-start;
}

.ai-msg-time {
    font-size: 0.65rem;
    color: var(--text-dim, #64748b);
    opacity: 0.6;
    margin-top: 4px;
    padding: 0 4px;
}

.ai-message-user .ai-msg-time {
    text-align: right;
}

/* ── Message Bubbles ──────────────────────────────────────────── */
.ai-message-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 0.88rem;
    line-height: 1.6;
    word-break: break-word;
    position: relative;
}

.ai-message-user .ai-message-bubble {
    background: linear-gradient(135deg, rgba(0,212,255,0.2), rgba(0,255,163,0.1));
    border: 1px solid rgba(0,212,255,0.22);
    color: var(--text, #fff);
    border-bottom-right-radius: 6px;
}

.ai-message-bot .ai-message-bubble {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.07);
    color: var(--text, #fff);
    border-bottom-left-radius: 6px;
}

.ai-message-bot .ai-message-bubble strong {
    color: var(--cyan, #00d4ff);
}

/* Inline code */
.ai-inline-code {
    background: rgba(0,212,255,0.1);
    border: 1px solid rgba(0,212,255,0.15);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: var(--font-mono, monospace);
    font-size: 0.82rem;
    color: var(--cyan, #00d4ff);
}

/* ── Thinking Indicator ──────────────────────────────────────── */
.ai-thinking .ai-message-bubble {
    padding: 12px 16px;
}

.ai-dots {
    display: flex;
    gap: 5px;
    align-items: center;
}

.ai-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--cyan, #00d4ff);
    opacity: 0.3;
    animation: dot-bounce 1.2s infinite ease-in-out;
}

.ai-dots span:nth-child(2) { animation-delay: 0.15s; }
.ai-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes dot-bounce {
    0%, 80%, 100% { opacity: 0.3; transform: scale(1) translateY(0); }
    40%           { opacity: 1;   transform: scale(1.2) translateY(-4px); }
}

/* ── Formula Link Button ─────────────────────────────────────── */
.ai-formula-link {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 8px 12px;
    background: linear-gradient(135deg, rgba(0,212,255,0.08), rgba(0,255,163,0.05));
    border: 1px solid rgba(0,212,255,0.2);
    border-radius: 12px;
    color: var(--cyan, #00d4ff);
    font-size: 0.8rem;
    font-family: var(--font-main, 'Inter', sans-serif);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    width: 100%;
    text-align: left;
}

.ai-formula-link:hover {
    background: linear-gradient(135deg, rgba(0,212,255,0.15), rgba(0,255,163,0.08));
    transform: translateX(4px);
    box-shadow: 0 4px 16px rgba(0,212,255,0.2);
    border-color: rgba(0,212,255,0.35);
}

.ai-formula-link i {
    font-size: 0.9rem;
    flex-shrink: 0;
    animation: spin-slow 4s linear infinite;
}

@keyframes spin-slow {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ── Suggestion Chips ────────────────────────────────────────── */
.ai-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 14px 12px;
    flex-shrink: 0;
}

.ai-suggest-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid rgba(0,212,255,0.15);
    background: rgba(0,212,255,0.05);
    color: var(--text-muted, #94a3b8);
    font-size: 0.75rem;
    font-family: var(--font-main, 'Inter', sans-serif);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.ai-suggest-chip:hover {
    background: rgba(0,212,255,0.12);
    border-color: rgba(0,212,255,0.3);
    color: var(--cyan, #00d4ff);
    transform: translateY(-1px);
}

.ai-suggest-chip i {
    font-size: 0.7rem;
    opacity: 0.7;
}

/* ── Input Area ───────────────────────────────────────────────── */
.ai-chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid rgba(255,255,255,0.06);
    background: rgba(0,0,0,0.2);
    flex-shrink: 0;
}

.ai-chat-input {
    flex: 1;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 14px;
    padding: 10px 16px;
    color: var(--text, #fff);
    font-size: 0.88rem;
    font-family: var(--font-main, 'Inter', sans-serif);
    outline: none;
    transition: border-color 0.25s, background 0.25s, box-shadow 0.25s;
}

.ai-chat-input:focus {
    border-color: rgba(0,212,255,0.35);
    background: rgba(0,212,255,0.04);
    box-shadow: 0 0 0 3px rgba(0,212,255,0.08);
}

.ai-chat-input::placeholder {
    color: var(--text-dim, #64748b);
}

.ai-chat-send {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--cyan, #00d4ff), #0095b8);
    border: none;
    border-radius: 14px;
    color: #050814;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.92rem;
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
    flex-shrink: 0;
}

.ai-chat-send:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0,212,255,0.4);
}

.ai-chat-send:active {
    transform: scale(0.95);
}

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

/* ── Formula Card Highlight ───────────────────────────────────── */
@keyframes ai-card-glow {
    0%   { box-shadow: none; outline: 2px solid transparent; }
    25%  { box-shadow: 0 0 0 3px var(--cyan, #00d4ff), 0 0 40px rgba(0,212,255,0.4); outline: 2px solid var(--cyan, #00d4ff); }
    75%  { box-shadow: 0 0 0 3px var(--cyan, #00d4ff), 0 0 40px rgba(0,212,255,0.4); outline: 2px solid var(--cyan, #00d4ff); }
    100% { box-shadow: none; outline: 2px solid transparent; }
}

.formula-card.ai-highlight {
    animation: ai-card-glow 2.2s ease forwards;
}

/* ── Mobile Responsive ───────────────────────────────────────── */
@media (max-width: 480px) {
    .ai-chat-popup {
        right: 10px;
        left: 10px;
        bottom: 5.25rem;
        width: auto;
        max-height: 72vh;
        border-radius: 20px;
    }

    .ai-chat-toggle {
        bottom: 1.25rem;
        right: 1.25rem;
        width: 52px;
        height: 52px;
        font-size: 1.3rem;
    }

    .ai-chat-messages {
        max-height: calc(72vh - 180px);
        padding: 12px;
    }

    .ai-chat-header {
        padding: 12px 14px;
    }

    .ai-chat-avatar {
        font-size: 1.8rem;
    }

    .ai-chat-suggestions {
        padding: 0 12px 10px;
    }

    .ai-suggest-chip {
        font-size: 0.7rem;
        padding: 5px 10px;
    }

    .ai-chat-input-area {
        padding: 10px 12px;
    }

    .ai-chat-input {
        padding: 9px 14px;
        font-size: 0.85rem;
    }

    .ai-chat-send {
        width: 40px;
        height: 40px;
    }

    .ai-chat-header-btn {
        width: 28px;
        height: 28px;
        font-size: 0.7rem;
    }
}

@media (max-width: 360px) {
    .ai-chat-popup {
        right: 6px;
        left: 6px;
    }
}

/* ── Light Theme ──────────────────────────────────────────────── */
body.light-theme .ai-chat-popup {
    background: rgba(248,250,252,0.98);
    border-color: rgba(2,132,199,0.15);
    box-shadow: 0 30px 80px rgba(0,0,0,0.12), 0 0 60px rgba(2,132,199,0.04);
}

body.light-theme .ai-chat-header {
    background: linear-gradient(135deg, rgba(2,132,199,0.06) 0%, rgba(0,200,150,0.03) 100%);
    border-color: rgba(2,132,199,0.1);
}

body.light-theme .ai-chat-status-dot {
    border-color: rgba(248,250,252,0.98);
}

body.light-theme .ai-message-bot .ai-message-bubble {
    background: rgba(0,0,0,0.03);
    border-color: rgba(0,0,0,0.06);
    color: var(--text);
}

body.light-theme .ai-message-user .ai-message-bubble {
    background: linear-gradient(135deg, rgba(2,132,199,0.12), rgba(2,132,199,0.06));
    border-color: rgba(2,132,199,0.2);
}

body.light-theme .ai-chat-input {
    background: rgba(0,0,0,0.03);
    border-color: rgba(0,0,0,0.08);
    color: var(--text);
}

body.light-theme .ai-chat-input:focus {
    border-color: rgba(2,132,199,0.35);
    background: rgba(2,132,199,0.03);
}

body.light-theme .ai-chat-input-area {
    background: rgba(0,0,0,0.03);
    border-color: rgba(0,0,0,0.06);
}

body.light-theme .ai-suggest-chip {
    background: rgba(2,132,199,0.04);
    border-color: rgba(2,132,199,0.12);
    color: var(--text-dim);
}

body.light-theme .ai-suggest-chip:hover {
    background: rgba(2,132,199,0.1);
    border-color: rgba(2,132,199,0.25);
    color: var(--cyan);
}

body.light-theme .ai-chat-header-btn,
body.light-theme .ai-chat-close {
    background: rgba(0,0,0,0.03);
    border-color: rgba(0,0,0,0.06);
    color: var(--text-dim);
}

body.light-theme .ai-chat-toggle {
    box-shadow:
        0 0 24px rgba(2,132,199,0.3),
        0 8px 24px rgba(0,0,0,0.12);
}

body.light-theme .ai-inline-code {
    background: rgba(2,132,199,0.08);
    border-color: rgba(2,132,199,0.12);
    color: var(--cyan);
}
