/* ============================================
   AI Chatbot - Glassmorphism UI
   Black/White themes + 10% Purple Accent
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=Space+Mono:wght@400;700&display=swap');

/* ---- CSS Variables ---- */
.aichat-wrapper[data-theme="dark"] {
    --bg-base:        rgba(10, 10, 15, 0.95);
    --glass-bg:       rgba(20, 20, 28, 0.85);
    --glass-border:   rgba(255, 255, 255, 0.08);
    --bubble-bot-bg:  rgba(30, 30, 42, 0.9);
    --bubble-user-bg: rgba(120, 60, 200, 0.75);
    --text-primary:   #f0f0f5;
    --text-secondary: #888899;
    --input-bg:       rgba(255, 255, 255, 0.06);
    --input-border:   rgba(255, 255, 255, 0.1);
    --header-bg:      rgba(15, 15, 22, 0.95);
    --send-bg:        rgba(120, 60, 200, 0.9);
    --send-hover:     rgba(140, 80, 220, 1);
    --dot-color:      #7c3aed;
    --shadow:         0 25px 60px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.05);
    --toggle-bg:      rgba(255,255,255,0.08);
    --scrollbar:      rgba(255,255,255,0.1);
    --noise-opacity:  0.03;
}

.aichat-wrapper[data-theme="light"] {
    --bg-base:        rgba(245, 244, 248, 0.97);
    --glass-bg:       rgba(255, 255, 255, 0.75);
    --glass-border:   rgba(0, 0, 0, 0.08);
    --bubble-bot-bg:  rgba(240, 238, 248, 0.95);
    --bubble-user-bg: rgba(110, 50, 190, 0.85);
    --text-primary:   #1a1a2e;
    --text-secondary: #666677;
    --input-bg:       rgba(0, 0, 0, 0.04);
    --input-border:   rgba(0, 0, 0, 0.1);
    --header-bg:      rgba(248, 247, 252, 0.98);
    --send-bg:        rgba(110, 50, 190, 0.9);
    --send-hover:     rgba(130, 70, 210, 1);
    --dot-color:      #6d28d9;
    --shadow:         0 25px 60px rgba(100,80,180,0.15), 0 0 0 1px rgba(110,50,190,0.1);
    --toggle-bg:      rgba(0,0,0,0.06);
    --scrollbar:      rgba(0,0,0,0.1);
    --noise-opacity:  0.015;
}

/* ---- Wrapper ---- */
.aichat-wrapper {
    font-family: 'DM Sans', sans-serif;
    width: 100%;
    max-width: 620px;
    margin: 0 auto;
    border-radius: 24px;
    overflow: hidden;
    background: var(--bg-base);
    box-shadow: var(--shadow);
    border: 1px solid var(--glass-border);
    position: relative;
    transition: background 0.4s ease, box-shadow 0.4s ease;
}

/* Noise texture overlay */
.aichat-wrapper::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
    opacity: var(--noise-opacity);
    pointer-events: none;
    border-radius: 24px;
    z-index: 0;
}

/* ---- Header ---- */
.aichat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--glass-border);
    backdrop-filter: blur(20px);
    position: relative;
    z-index: 1;
}

.aichat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.aichat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(124,58,237,0.8), rgba(80,30,180,0.9));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 4px 15px rgba(124,58,237,0.4);
    animation: avatarPulse 3s ease-in-out infinite;
}

@keyframes avatarPulse {
    0%, 100% { box-shadow: 0 4px 15px rgba(124,58,237,0.4); }
    50%       { box-shadow: 0 4px 25px rgba(124,58,237,0.7); }
}

.aichat-bot-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.aichat-status {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 1px;
}

.aichat-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--dot-color);
    display: inline-block;
    animation: dotBlink 2s ease-in-out infinite;
}

@keyframes dotBlink {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.5; transform: scale(0.8); }
}

/* Theme toggle */
.aichat-theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: var(--toggle-bg);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.aichat-theme-toggle:hover {
    color: var(--text-primary);
    background: rgba(124,58,237,0.2);
    border-color: rgba(124,58,237,0.4);
    transform: rotate(20deg);
}

/* ---- Messages Area ---- */
.aichat-messages {
    height: 380px;
    overflow-y: auto;
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    z-index: 1;
    scroll-behavior: smooth;
}

.aichat-messages::-webkit-scrollbar { width: 4px; }
.aichat-messages::-webkit-scrollbar-track { background: transparent; }
.aichat-messages::-webkit-scrollbar-thumb {
    background: var(--scrollbar);
    border-radius: 4px;
}

/* Message bubbles */
.aichat-msg {
    display: flex;
    animation: msgSlide 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    opacity: 0;
}

@keyframes msgSlide {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.aichat-msg-bot  { justify-content: flex-start; }
.aichat-msg-user { justify-content: flex-end; }

.aichat-bubble {
    max-width: 78%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    position: relative;
    word-break: break-word;
    backdrop-filter: blur(12px);
    transition: background 0.4s ease;
}

.aichat-msg-bot .aichat-bubble {
    background: var(--bubble-bot-bg);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    border-bottom-left-radius: 4px;
}

.aichat-msg-user .aichat-bubble {
    background: var(--bubble-user-bg);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 20px rgba(120,60,200,0.3);
}

/* ---- Typing Indicator ---- */
.aichat-typing {
    padding: 8px 22px 4px;
    display: flex;
    align-items: center;
    gap: 5px;
    position: relative;
    z-index: 1;
}

.aichat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(124, 58, 237, 0.6);
    animation: typingBounce 1.2s ease-in-out infinite;
}

.aichat-typing span:nth-child(2) { animation-delay: 0.2s; }
.aichat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30%            { transform: translateY(-6px); opacity: 1; }
}

/* ---- Input Area ---- */
.aichat-input-area {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid var(--glass-border);
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    position: relative;
    z-index: 1;
}

.aichat-input {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 14px;
    padding: 12px 16px;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
    transition: all 0.3s ease;
}

.aichat-input::placeholder { color: var(--text-secondary); }

.aichat-input:focus {
    border-color: rgba(124, 58, 237, 0.5);
    background: var(--input-bg);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

.aichat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    border: none;
    background: var(--send-bg);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    flex-shrink: 0;
}

.aichat-send-btn:hover {
    background: var(--send-hover);
    transform: scale(1.08) rotate(-5deg);
    box-shadow: 0 6px 20px rgba(124,58,237,0.45);
}

.aichat-send-btn:active {
    transform: scale(0.95);
}

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

/* ---- Responsive ---- */
@media (max-width: 640px) {
    .aichat-messages { height: 300px; }
    .aichat-bubble   { max-width: 88%; font-size: 13px; }
}
