/* ============================================================
   AI Assistant — Floating Widget for Personal Center
   Brand: Purple #4A3A6B, Gold #D4AF37
   Hand-drawn style (CSS only, no emoji/SVG)
   ============================================================ */

/* ---- Floating Trigger Button ---- */
.ai-assistant-trigger {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9998;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4A3A6B 0%, #6B5B8B 100%);
    border: 2.5px solid #D4AF37;
    box-shadow: 0 6px 24px rgba(74, 58, 107, 0.35), 0 0 0 4px rgba(212, 175, 55, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    animation: ai-pulse 2.5s ease-in-out infinite;
}

.ai-assistant-trigger:hover {
    transform: scale(1.1);
    border-color: #E8D87A;
    box-shadow: 0 8px 32px rgba(74, 58, 107, 0.45), 0 0 0 8px rgba(212, 175, 55, 0.2);
}

.ai-assistant-trigger:active {
    transform: scale(0.95);
}

/* ---- Hand-drawn AI icon (pure CSS) ---- */
.ai-icon {
    position: relative;
    width: 26px;
    height: 26px;
}

.ai-icon::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 18px;
    height: 18px;
    transform: translate(-50%, -50%) rotate(45deg);
    background: #D4AF37;
    border-radius: 3px;
    box-shadow: 0 0 8px rgba(212, 175, 55, 0.5);
}

.ai-icon::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    transform: translate(-50%, -50%);
    background: #4A3A6B;
    border-radius: 50%;
    box-shadow: 0 0 4px rgba(74, 58, 107, 0.6);
}

/* ---- Pulse animation ---- */
@keyframes ai-pulse {
    0%, 100% { box-shadow: 0 6px 24px rgba(74, 58, 107, 0.35), 0 0 0 4px rgba(212, 175, 55, 0.15); }
    50% { box-shadow: 0 6px 28px rgba(74, 58, 107, 0.45), 0 0 0 10px rgba(212, 175, 55, 0.05); }
}

/* ---- Chat Window Overlay ---- */
.ai-assistant-panel {
    position: fixed;
    bottom: 100px;
    right: 28px;
    z-index: 9999;
    width: 400px;
    max-width: calc(100vw - 56px);
    height: 560px;
    max-height: calc(100vh - 140px);
    background: #fff;
    border-radius: 20px;
    border: 2px solid #D4AF37;
    box-shadow: 0 20px 60px rgba(74, 58, 107, 0.25), 0 0 0 6px rgba(74, 58, 107, 0.04);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: ai-slide-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    /* Hand-drawn sketch border */
    border-radius: 22px 18px 20px 19px;
}

.ai-assistant-panel.open {
    display: flex;
}

@keyframes ai-slide-up {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- Panel Header ---- */
.ai-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, #4A3A6B, #6B5B8B);
    color: #fff;
    flex-shrink: 0;
}

.ai-panel-title {
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-panel-title .ai-icon-small {
    width: 20px;
    height: 20px;
    position: relative;
    flex-shrink: 0;
}

.ai-panel-title .ai-icon-small::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    transform: translate(-50%, -50%) rotate(45deg);
    background: #D4AF37;
    border-radius: 2px;
}

.ai-panel-title .ai-icon-small::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 6px;
    height: 6px;
    transform: translate(-50%, -50%);
    background: #4A3A6B;
    border-radius: 50%;
}

.ai-panel-close {
    width: 32px;
    height: 32px;
    border: 1.5px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    line-height: 1;
}

.ai-panel-close:hover {
    background: rgba(255,255,255,0.2);
    border-color: #D4AF37;
}

/* ---- Messages Area ---- */
.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #FAF7F2;
    scroll-behavior: smooth;
}

.ai-message {
    display: flex;
    gap: 10px;
    max-width: 88%;
    animation: msg-in 0.25s ease-out;
}

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

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

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

.ai-message .msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

.ai-message.user .msg-avatar {
    background: #4A3A6B;
    color: #D4AF37;
}

.ai-message.assistant .msg-avatar {
    background: #D4AF37;
    color: #4A3A6B;
}

.msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.65;
    word-break: break-word;
}

.ai-message.user .msg-bubble {
    background: #4A3A6B;
    color: #fff;
    border-bottom-right-radius: 4px;
    border: 1.5px solid #5B4B7B;
}

.ai-message.assistant .msg-bubble {
    background: #fff;
    color: #2D2A24;
    border: 1.5px solid #E6DFD0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

/* ---- Typing Indicator ---- */
.ai-typing-indicator {
    align-self: flex-start;
    display: none;
    padding: 10px 16px;
    background: #fff;
    border: 1.5px solid #E6DFD0;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}

.ai-typing-indicator.active {
    display: flex;
    gap: 5px;
    align-items: center;
}

.ai-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #D4AF37;
    animation: dot-bounce 1.4s 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 dot-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.3; }
    40% { transform: translateY(-6px); opacity: 1; }
}

/* ---- Quick Questions ---- */
.ai-quick-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 12px;
    flex-shrink: 0;
}

.ai-quick-btn {
    padding: 7px 14px;
    border: 1.5px solid #D4D0E0;
    border-radius: 20px;
    background: #fff;
    color: #4A3A6B;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    /* Hand-drawn sketch feel */
    border-radius: 20px 16px 18px 19px;
}

.ai-quick-btn:hover {
    border-color: #D4AF37;
    background: #FDF8E6;
    color: #4A3A6B;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(212, 175, 55, 0.15);
}

.ai-quick-btn:active {
    transform: translateY(0);
}

/* ---- Input Area ---- */
.ai-input-area {
    display: flex;
    gap: 10px;
    padding: 12px 16px 16px;
    border-top: 1px solid #E6DFD0;
    flex-shrink: 0;
    background: #fff;
}

.ai-input-area textarea {
    flex: 1;
    min-height: 44px;
    max-height: 100px;
    padding: 10px 14px;
    border: 1.5px solid #D4D0E0;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    resize: none;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
    /* Hand-drawn sketch feel */
    border-radius: 14px 12px 14px 13px;
}

.ai-input-area textarea:focus {
    border-color: #D4AF37;
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.12);
}

.ai-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid #D4AF37;
    background: #4A3A6B;
    color: #D4AF37;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.ai-send-btn:hover {
    background: #5B4B7B;
    border-color: #E8D87A;
    color: #E8D87A;
    transform: scale(1.05);
}

.ai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
    .ai-assistant-trigger {
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
    }

    .ai-assistant-panel {
        bottom: 84px;
        right: 12px;
        width: calc(100vw - 24px);
        height: 480px;
        max-height: calc(100vh - 120px);
        border-radius: 16px;
    }

    .ai-quick-questions {
        padding: 0 12px 8px;
    }

    .ai-quick-btn {
        padding: 5px 10px;
        font-size: 11px;
    }

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

/* ---- Scrollbar ---- */
.ai-messages::-webkit-scrollbar {
    width: 5px;
}

.ai-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-messages::-webkit-scrollbar-thumb {
    background: #D4D0E0;
    border-radius: 10px;
}

.ai-messages::-webkit-scrollbar-thumb:hover {
    background: #B8B0C8;
}