/**
 * AI Chat Panel Styles
 * 
 * Dark theme chat interface matching the simulator design
 * Positioned fixed in bottom-right corner
 */

/* ============================================================================
   AI Chat Toggle Button (Floating)
   ============================================================================ */

.ai-chat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, hsl(240, 6%, 10%) 0%, hsl(240, 4%, 16%) 100%);
    border: 2px solid hsl(var(--border));
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.05);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-chat-toggle:hover {
    transform: translateY(-2px) scale(1.05);
    border-color: hsl(var(--primary));
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5), 0 0 20px hsl(var(--primary) / 0.2);
}

.ai-chat-toggle:active {
    transform: translateY(0) scale(0.98);
}

.ai-chat-toggle.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

.ai-chat-toggle-icon {
    width: 28px;
    height: 28px;
    color: hsl(var(--foreground));
    transition: color 0.2s ease;
}

.ai-chat-toggle:hover .ai-chat-toggle-icon {
    color: hsl(var(--primary));
}

.ai-chat-toggle-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    background: hsl(var(--success));
    border-radius: 50%;
    border: 2px solid hsl(var(--background));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: hsl(var(--success-foreground));
    animation: ai-chat-pulse 2s ease-in-out infinite;
}

@keyframes ai-chat-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

/* ============================================================================
   AI Chat Panel
   ============================================================================ */

.ai-chat-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 500px;
    max-height: calc(100vh - 100px);
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    z-index: 101;
    overflow: hidden;
    transform: scale(0.95) translateY(10px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-chat-panel.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    visibility: visible;
}

.ai-chat-panel.collapsed {
    transform: scale(0.95) translateY(10px);
    opacity: 0;
    visibility: hidden;
}

/* ============================================================================
   AI Chat Header
   ============================================================================ */

.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, hsl(var(--muted) / 0.5) 0%, hsl(var(--card)) 100%);
    border-bottom: 1px solid hsl(var(--border));
    cursor: pointer;
    user-select: none;
}

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

.ai-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, hsl(var(--primary)) 0%, hsl(240, 50%, 40%) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.ai-chat-avatar-icon {
    width: 20px;
    height: 20px;
    color: hsl(var(--primary-foreground));
}

.ai-chat-title-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ai-chat-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: hsl(var(--foreground));
    line-height: 1.2;
}

.ai-chat-status {
    font-size: 0.6875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-chat-status.connected {
    color: hsl(var(--success));
}

.ai-chat-status.disconnected {
    color: hsl(var(--muted-foreground));
}

.ai-chat-status.reconnecting {
    color: hsl(45, 90%, 50%);
    animation: ai-chat-status-pulse 1.5s ease-in-out infinite;
}

.ai-chat-status.error {
    color: hsl(0, 70%, 60%);
}

@keyframes ai-chat-status-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

.ai-chat-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    transition: all 0.15s ease;
}

.ai-chat-close:hover {
    background: hsl(var(--muted));
    color: hsl(var(--foreground));
}

.ai-chat-close-icon {
    width: 18px;
    height: 18px;
}

/* Context indicator dot */
.ai-chat-context-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: hsl(var(--muted-foreground));
    margin-right: 4px;
    transition: background 0.3s ease;
}

.ai-chat-context-indicator.active {
    background: hsl(var(--success));
    animation: ai-chat-indicator-pulse 2s ease-in-out infinite;
}

@keyframes ai-chat-indicator-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 hsl(var(--success) / 0.4); }
    50% { opacity: 0.8; box-shadow: 0 0 0 4px hsl(var(--success) / 0); }
}

/* ============================================================================
   AI Chat Messages Container
   ============================================================================ */

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: hsl(var(--background));
    scrollbar-width: thin;
    scrollbar-color: hsl(var(--border)) transparent;
}

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

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

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: hsl(var(--border));
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: hsl(var(--muted-foreground));
}

/* ============================================================================
   AI Chat Message Bubbles
   ============================================================================ */

.ai-chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: ai-chat-message-in 0.3s ease;
}

@keyframes ai-chat-message-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

.ai-chat-message.system {
    align-self: center;
    align-items: center;
    max-width: 100%;
}

.ai-chat-message-content {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.875rem;
    line-height: 1.5;
    word-wrap: break-word;
}

/* User message bubble */
.ai-chat-message.user .ai-chat-message-content {
    background: linear-gradient(135deg, hsl(var(--primary)) 0%, hsl(240, 50%, 40%) 100%);
    color: hsl(var(--primary-foreground));
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* AI message bubble */
.ai-chat-message.ai .ai-chat-message-content {
    background: hsl(var(--muted));
    color: hsl(var(--foreground));
    border: 1px solid hsl(var(--border));
    border-bottom-left-radius: 4px;
}

/* System message */
.ai-chat-message.system {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    font-style: italic;
    padding: 8px 12px;
    background: hsl(var(--muted) / 0.5);
    border-radius: 12px;
}

/* Message time */
.ai-chat-message-time {
    font-size: 0.6875rem;
    color: hsl(var(--muted-foreground));
    margin-top: 4px;
    padding: 0 4px;
}

/* Message formatting */
.ai-chat-message-content strong {
    font-weight: 600;
}

.ai-chat-message-content em {
    font-style: italic;
}

.ai-chat-message-content code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8125rem;
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
}

.ai-chat-message.ai .ai-chat-message-content code {
    background: hsl(var(--background));
}

.ai-chat-message-content pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.ai-chat-message-content pre code {
    background: none;
    padding: 0;
}

.ai-chat-message-content a {
    color: hsl(200, 80%, 60%);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.ai-chat-message-content a:hover {
    color: hsl(200, 80%, 70%);
}

.ai-chat-message.user .ai-chat-message-content a {
    color: hsl(200, 100%, 80%);
}

/* ============================================================================
   Typing Indicator
   ============================================================================ */

.ai-chat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 16px;
    background: hsl(var(--muted));
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    animation: ai-chat-message-in 0.3s ease;
}

.ai-chat-typing-dot {
    width: 8px;
    height: 8px;
    background: hsl(var(--muted-foreground));
    border-radius: 50%;
    animation: ai-chat-typing-bounce 1.4s ease-in-out infinite;
}

.ai-chat-typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.ai-chat-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-chat-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes ai-chat-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
}

/* ============================================================================
   AI Chat Input Area
   ============================================================================ */

.ai-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    background: hsl(var(--card));
    border-top: 1px solid hsl(var(--border));
}

.ai-chat-input-wrapper {
    flex: 1;
    position: relative;
}

.ai-chat-input {
    width: 100%;
    min-height: 44px;
    max-height: 120px;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 0.875rem;
    color: hsl(var(--foreground));
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: 22px;
    resize: none;
    outline: none;
    transition: all 0.2s ease;
    scrollbar-width: thin;
    scrollbar-color: hsl(var(--border)) transparent;
}

.ai-chat-input:focus {
    border-color: hsl(var(--primary));
    box-shadow: 0 0 0 3px hsl(var(--primary) / 0.1);
}

.ai-chat-input::placeholder {
    color: hsl(var(--muted-foreground));
}

.ai-chat-input::-webkit-scrollbar {
    width: 4px;
}

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

.ai-chat-input::-webkit-scrollbar-thumb {
    background: hsl(var(--border));
    border-radius: 2px;
}

.ai-chat-send {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: hsl(var(--primary));
    border: none;
    border-radius: 50%;
    color: hsl(var(--primary-foreground));
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.ai-chat-send:hover {
    background: hsl(var(--primary) / 0.9);
    transform: scale(1.05);
}

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

.ai-chat-send:disabled {
    background: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
    cursor: not-allowed;
    transform: none;
}

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

/* ============================================================================
   Responsive Design
   ============================================================================ */

@media (max-width: 480px) {
    .ai-chat-panel {
        left: 10px;
        right: 10px;
        bottom: 10px;
        width: auto;
        max-width: none;
        height: 60vh;
        max-height: 60vh;
        border-radius: 12px;
    }

    .ai-chat-toggle {
        bottom: 10px;
        right: 10px;
        width: 48px;
        height: 48px;
    }

    .ai-chat-toggle-icon {
        width: 24px;
        height: 24px;
    }
}

@media (max-height: 600px) {
    .ai-chat-panel {
        height: 70vh;
        max-height: 70vh;
    }
}

/* ============================================================================
   Reduced Motion Support
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
    .ai-chat-toggle,
    .ai-chat-panel,
    .ai-chat-message,
    .ai-chat-typing-dot,
    .ai-chat-context-indicator,
    .ai-chat-status.reconnecting {
        animation: none;
        transition: none;
    }
}

/* ============================================================================
   High Contrast Mode Support
   ============================================================================ */

@media (prefers-contrast: high) {
    .ai-chat-panel {
        border-width: 2px;
    }

    .ai-chat-message-content {
        border-width: 2px;
    }

    .ai-chat-input:focus {
        box-shadow: 0 0 0 4px hsl(var(--primary) / 0.3);
    }
}
