/* Premium AI Chatbot Styling - Synchronized with Portfolio Theme */
html {
    --chat-primary: var(--accent-color);
    --chat-bg: rgba(255, 255, 255, 0.05);
    --chat-glass: rgba(9, 10, 15, 0.85);
    --chat-border: var(--card-border);
    --chat-text: var(--text-primary);
    --chat-text-dim: var(--text-secondary);
}

html.dark {
    --chat-glass: rgba(9, 10, 15, 0.95);
    --bot-msg-bg: rgba(255, 255, 255, 0.05);
}

html.light {
    --chat-glass: rgba(255, 255, 255, 0.95);
    --chat-bg: rgba(0, 0, 0, 0.03);
    --bot-msg-bg: #f1f5f9;
    --chat-border: rgba(0, 0, 0, 0.15);
    /* Stronger border */
}

#chatbot-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 1000;
    font-family: 'Inter', sans-serif;
}

/* Floating Action Button */
.chatbot-tooltip {
    position: absolute;
    bottom: 85px;
    right: 0;
    background: var(--gradient-primary);
    background-size: 400% 400%;
    animation: gradientShimmer 8s ease infinite;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 12px 22px;
    border-radius: 14px;
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
    white-space: nowrap;
    box-shadow: 0 10px 30px rgba(212, 175, 55, 0.3), inset 0 0 15px rgba(255, 255, 255, 0.1);
    opacity: 0;
    transform: translateY(10px) scale(0.9);
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
    z-index: 999;
}

@keyframes gradientShimmer {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

.chatbot-tooltip:not(.wiggle) {
    animation: floatingTooltip 3s ease-in-out infinite, gradientShimmer 8s ease infinite;
}

@keyframes floatingTooltip {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-6px);
    }
}

/* Tooltip Animations */
@keyframes wiggle {

    0%,
    100% {
        transform: rotate(0deg) scale(1.05);
    }

    25% {
        transform: rotate(3deg) scale(1.05);
    }

    75% {
        transform: rotate(-3deg) scale(1.05);
    }
}

.chatbot-tooltip.wiggle {
    animation: wiggle 0.5s ease-in-out infinite;
}

.chatbot-tooltip.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    animation: pulse 2s infinite ease-in-out, fabBounce 3s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    }

    50% {
        box-shadow: 0 10px 35px rgba(168, 85, 247, 0.4);
    }
}

.chatbot-tooltip::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 25px;
    width: 12px;
    height: 12px;
    background: rgba(168, 85, 247, 0.9);
    border-right: 1px solid rgba(255, 255, 255, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    transform: rotate(45deg);
}

.chatbot-tooltip.ar {
    right: auto;
    left: 0;
}

.chatbot-tooltip.ar::after {
    right: auto;
    left: 25px;
}

.chatbot-fab {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), inset 0 0 0 2px var(--accent-color);
    transition: all 0.4s cubic-bezier(0.2, 1, 0.3, 1);
    border: none;
    position: relative;
    z-index: 1000;
    overflow: hidden;
}

.fab-profile-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    padding: 3px;
    transition: transform 0.4s ease;
}

.chatbot-fab:hover .fab-profile-img {
    transform: scale(1.1);
}

.chatbot-fab::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    background: var(--accent-color);
    z-index: -1;
    opacity: 0.3;
    animation: fabPulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes fabBounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

@keyframes fabPulse {
    0% {
        transform: scale(1);
        opacity: 0.5;
    }

    100% {
        transform: scale(1.4);
        opacity: 0;
    }
}

.chatbot-fab i {
    animation: iconGlow 2s ease-in-out infinite;
}

@keyframes iconGlow {

    0%,
    100% {
        text-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
    }

    50% {
        text-shadow: 0 0 20px rgba(255, 255, 255, 1), 0 0 30px rgba(168, 85, 247, 0.5);
    }
}

.chatbot-fab:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 15px 40px rgba(212, 175, 55, 0.3), inset 0 0 0 3px var(--accent-color);
    color: #ffffff;
}

.chatbot-fab .notification-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: #ff4d4d;
    border: 2px solid white;
    border-radius: 50%;
}

/* Chat Window */
.chatbot-window {
    position: absolute;
    bottom: 85px;
    right: 0;
    width: 380px;
    height: 550px;
    background: var(--chat-glass);
    backdrop-filter: blur(20px);
    border: 1px solid var(--chat-border);
    border-radius: 24px;
    display: none;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    transform-origin: bottom right;
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    opacity: 0;
    transform: translateY(20px) scale(0.9);
}

.light .chatbot-window {
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
}

.light .chat-header-text h3 {
    color: var(--text-primary);
}

.light .chat-header-text span {
    color: var(--text-secondary);
}

.light .message.bot {
    background: var(--bot-msg-bg);
    border-color: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

.light #chat-input {
    background: #fff;
    color: var(--text-primary);
    border-color: rgba(0, 0, 0, 0.1);
}

.chatbot-window.active {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Header */
.chat-header {
    padding: 20px;
    background: rgba(99, 102, 241, 0.1);
    border-bottom: 1px solid var(--chat-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.new-chat-btn {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 16px;
    cursor: pointer;
    opacity: 0.6;
    transition: 0.3s;
}

.new-chat-btn:hover {
    opacity: 1;
    color: var(--chat-primary);
    transform: rotate(-45deg);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    overflow: hidden;
    border: none;
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.5);
}

.chat-profile-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-header-text h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}

.chat-header-text span {
    font-size: 12px;
    opacity: 0.7;
}

.close-chat {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.6;
    transition: 0.3s;
}

.close-chat:hover {
    opacity: 1;
    transform: rotate(90deg);
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scrollbar-width: thin;
}

/* Quick Actions */
.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.05);
    border-top: 1px solid var(--chat-border);
}

.light .quick-actions {
    background: rgba(0, 0, 0, 0.02);
}

.qa-btn {
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    color: var(--chat-text);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.qa-btn:hover {
    background: var(--chat-primary);
    color: white;
    border-color: var(--chat-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    animation: messageIn 0.3s ease-out;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.bot table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 0.85rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    overflow: hidden;
}

.message.bot th,
.message.bot td {
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: left;
}

.message.bot th {
    background: rgba(99, 102, 241, 0.2);
    color: #fff;
}

.message.bot code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9em;
}

.message.bot pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
}

.message.bot {
    align-self: flex-start;
    background: var(--bot-msg-bg);
    color: var(--chat-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--chat-border);
}

.message.bot ul,
.message.bot ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message.bot li {
    margin-bottom: 4px;
}

.message.bot p {
    margin: 0 0 8px 0;
}

.message.bot p:last-child {
    margin-bottom: 0;
}

.message.bot a {
    color: var(--primary-color);
    text-decoration: underline;
}

/* Typing Indicator */
.typing {
    font-style: italic;
    font-size: 12px;
    opacity: 0.7;
    margin-bottom: 10px;
    display: none;
}

/* Input Area */
.chat-input-area {
    padding: 20px;
    border-top: 1px solid var(--chat-border);
    display: flex;
    gap: 10px;
}

#chat-input {
    flex: 1;
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    padding: 12px 15px;
    color: inherit;
    font-size: 14px;
    outline: none;
    transition: 0.3s;
}

#chat-input:focus {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.1);
}

.send-btn {
    background: var(--chat-primary);
    color: white;
    border: none;
    border-radius: 12px;
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.3s;
}

.send-btn:hover {
    transform: scale(1.05);
    background: var(--accent-color);
    filter: brightness(1.1);
}

/* RTL Support */
.dir-rtl .chatbot-window {
    right: auto;
    left: 0;
    transform-origin: bottom left;
}

.dir-rtl #chatbot-container {
    right: auto;
    left: 30px;
}

.dir-rtl .message.bot {
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 4px;
}

.dir-rtl .message.user {
    border-bottom-right-radius: 18px;
    border-bottom-left-radius: 4px;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .chatbot-window {
        width: calc(100vw - 40px);
        height: 70vh;
        bottom: 80px;
    }

    #chatbot-container {
        bottom: 20px;
        right: 20px;
    }

    .dir-rtl #chatbot-container {
        left: 20px;
    }
}