/**
 * AI Chat Interface Styles
 * Glass morphism design using existing portfolio theme variables
 */

/* Import site fonts */
#ai-chat-container,
#ai-chat-container * {
    font-family: "Merriweather", Georgia, serif;
}

#ai-chat-header h3,
#ai-chat-send,
#ai-chat-close,
label {
    font-family: "Source Sans Pro", Helvetica, sans-serif;
}

/* Chat Button - Fixed position bottom right */
#ai-chat-button {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(24, 191, 239, 0.8), rgba(24, 191, 239, 0.6));
    backdrop-filter: blur(var(--blur-amount));
    -webkit-backdrop-filter: blur(var(--blur-amount));
    border: 2px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    cursor: pointer;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-smooth);
    transform: translateZ(0);
    will-change: transform, box-shadow;
    overflow: hidden;
    padding: 0;
}

#ai-chat-button:hover {
    transform: translateY(-4px) scale(1.05) translateZ(0);
    box-shadow: var(--glass-shadow-lg);
    background: linear-gradient(135deg, rgba(24, 191, 239, 0.9), rgba(24, 191, 239, 0.7));
}

#ai-chat-button:active {
    transform: translateY(-2px) scale(1.02) translateZ(0);
}

#ai-chat-button img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

/* Tooltip */
#ai-chat-tooltip {
    position: fixed;
    bottom: 2.2rem;
    right: 5.5rem;
    background: rgba(33, 41, 49, 0.95);
    backdrop-filter: blur(var(--blur-amount));
    -webkit-backdrop-filter: blur(var(--blur-amount));
    color: rgba(255, 255, 255, 0.95);
    padding: 0.6rem 1rem;
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: var(--glass-shadow);
    border: 1px solid var(--glass-border);
    z-index: 9997;
    opacity: 0;
    visibility: hidden;
    transform: translateX(10px);
    transition: var(--transition-smooth);
    pointer-events: none;
}

#ai-chat-tooltip::after {
    content: '';
    position: absolute;
    right: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid rgba(33, 41, 49, 0.95);
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
}

#ai-chat-button:hover + #ai-chat-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

/* Chat Container */
#ai-chat-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 420px;
    height: 600px;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--glass-shadow-lg);
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    transition: var(--transition-smooth);
    transform: translateY(20px) scale(0.95);
    opacity: 0;
}

#ai-chat-container.active {
    display: flex;
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* Chat Header */
#ai-chat-header {
    background: rgba(24, 191, 239, 0.08);
    border-bottom: 1px solid var(--glass-border);
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#ai-chat-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 900;
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#ai-chat-header .status-indicator {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.6);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

#ai-chat-close {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-smooth);
    color: rgba(255, 255, 255, 0.8);
}

#ai-chat-close:hover {
    background: var(--glass-bg-hover);
    color: rgba(255, 255, 255, 1);
    transform: rotate(90deg);
}

#ai-chat-close i {
    font-size: 16px;
    font-weight: 900;
    display: block;
    line-height: 1;
}

/* Chat Messages Area */
#ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

#ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

#ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

#ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Message Bubble */
.chat-message {
    display: flex;
    gap: 0.75rem;
    animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user {
    flex-direction: row-reverse;
}

.chat-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(24, 191, 239, 0.3), rgba(24, 191, 239, 0.1));
    border: 2px solid rgba(24, 191, 239, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 900;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
}

.chat-message.user .chat-message-avatar {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.1));
    border-color: rgba(255, 255, 255, 0.3);
}

.chat-message-content {
    flex: 1;
    background: var(--glass-bg-hover);
    backdrop-filter: blur(var(--blur-amount));
    -webkit-backdrop-filter: blur(var(--blur-amount));
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    padding: 0.875rem 1rem;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
    line-height: 1.6;
    word-wrap: break-word;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.chat-message.user .chat-message-content {
    background: linear-gradient(135deg, rgba(24, 191, 239, 0.25), rgba(24, 191, 239, 0.15));
    border-color: rgba(24, 191, 239, 0.3);
}

.chat-message-content p {
    margin: 0 0 0.5rem 0;
}

.chat-message-content p:last-child {
    margin-bottom: 0;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 0.5rem;
    padding: 0.875rem 1rem;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: rgba(24, 191, 239, 0.6);
    border-radius: 50%;
    animation: typing 1.4s ease-in-out infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.6;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Chat Input Area */
#ai-chat-input-container {
    border-top: 1px solid var(--glass-border);
    padding: 1rem 1.5rem;
    background: var(--glass-bg);
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

#ai-chat-input {
    flex: 1;
    background: var(--glass-bg-hover);
    backdrop-filter: blur(var(--blur-amount));
    -webkit-backdrop-filter: blur(var(--blur-amount));
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    padding: 0.75rem 1rem;
    color: rgba(255, 255, 255, 0.95);
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    min-height: 44px;
    transition: var(--transition-smooth);
}

#ai-chat-input:focus {
    outline: none;
    border-color: rgba(24, 191, 239, 0.5);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 0 3px rgba(24, 191, 239, 0.1);
}

#ai-chat-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

#ai-chat-send {
    background: linear-gradient(135deg, rgba(24, 191, 239, 0.8), rgba(24, 191, 239, 0.6));
    border: 1px solid rgba(24, 191, 239, 0.5);
    border-radius: var(--border-radius);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-smooth);
    color: #ffffff;
    flex-shrink: 0;
}

#ai-chat-send:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(24, 191, 239, 0.9), rgba(24, 191, 239, 0.7));
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(24, 191, 239, 0.4);
}

#ai-chat-send:active:not(:disabled) {
    transform: translateY(0);
}

#ai-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#ai-chat-send i {
    font-size: 16px;
    font-weight: 900;
    display: block;
    line-height: 1;
}

/* Welcome Message */
.welcome-message {
    background: linear-gradient(135deg, rgba(24, 191, 239, 0.15), rgba(24, 191, 239, 0.05));
    border: 1px solid rgba(24, 191, 239, 0.3);
    border-radius: var(--border-radius);
    padding: 1.25rem;
    margin-bottom: 0.5rem;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    font-size: 0.9rem;
    line-height: 1.6;
}

/* Mobile Responsive */
@media screen and (max-width: 736px) {
    #ai-chat-button {
        bottom: 1.5rem;
        right: 1.5rem;
        width: 56px;
        height: 56px;
    }
    
    #ai-chat-button img {
        width: 100%;
        height: 100%;
    }
    
    #ai-chat-tooltip {
        display: none;
    }
    
    #ai-chat-container {
        bottom: 0;
        right: 0;
        left: 0;
        top: auto;
        width: 100%;
        height: 85vh;
        max-height: 700px;
        border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
        margin: 0;
    }
    
    #ai-chat-header {
        padding: 1rem 1.25rem;
    }
    
    #ai-chat-messages {
        padding: 1rem;
    }
    
    #ai-chat-input-container {
        padding: 0.875rem 1rem;
    }
}

/* Tablet */
@media screen and (min-width: 737px) and (max-width: 980px) {
    #ai-chat-container {
        width: 380px;
        height: 550px;
    }
}

/* Streaming cursor animation */
.streaming-message .cursor {
    display: inline-block;
    animation: blink 1s step-end infinite;
    color: rgba(24, 191, 239, 0.8);
    margin-left: 2px;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Markdown content styling */
.chat-message-content h1,
.chat-message-content h2,
.chat-message-content h3,
.chat-message-content h4,
.chat-message-content h5,
.chat-message-content h6 {
    font-family: "Source Sans Pro", Helvetica, sans-serif;
    font-weight: 900;
    margin: 0.75rem 0 0.5rem 0;
    color: rgba(255, 255, 255, 0.95);
}

.chat-message-content h1 { font-size: 1.5rem; }
.chat-message-content h2 { font-size: 1.3rem; }
.chat-message-content h3 { font-size: 1.1rem; }

.chat-message-content p {
    margin: 0.5rem 0;
}

.chat-message-content ul,
.chat-message-content ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.chat-message-content li {
    margin: 0.25rem 0;
}

.chat-message-content a {
    color: rgba(24, 191, 239, 0.9);
    text-decoration: underline;
    transition: var(--transition-smooth);
}

.chat-message-content a:hover {
    color: rgba(24, 191, 239, 1);
}

.chat-message-content blockquote {
    border-left: 3px solid rgba(24, 191, 239, 0.5);
    padding-left: 1rem;
    margin: 0.75rem 0;
    font-style: italic;
    opacity: 0.9;
}

/* Code blocks */
.chat-message-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.2rem 0.4rem;
    border-radius: 0.25rem;
    font-family: "Courier New", monospace;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.95);
}

.chat-message-content pre {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    padding: 1rem;
    margin: 0.75rem 0;
    overflow-x: auto;
    max-width: 100%;
}

.chat-message-content pre code {
    background: transparent;
    padding: 0;
    font-size: 0.8rem;
    line-height: 1.5;
    display: block;
}

/* KaTeX math styling */
.chat-message-content .katex {
    font-size: 1.05em;
}

.chat-message-content .katex-display {
    margin: 1rem 0;
    overflow-x: auto;
    overflow-y: hidden;
}

/* Tables */
.chat-message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.75rem 0;
    font-size: 0.85rem;
}

.chat-message-content table th,
.chat-message-content table td {
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.5rem;
    text-align: left;
}

.chat-message-content table th {
    background: rgba(24, 191, 239, 0.2);
    font-weight: 900;
}

.chat-message-content table tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

/* Horizontal rule */
.chat-message-content hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    margin: 1rem 0;
}

/* Error Message */
.error-message {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--border-radius);
    padding: 0.875rem 1rem;
    color: rgba(255, 200, 200, 0.95);
    font-size: 0.875rem;
    margin: 0.5rem 0;
}
