/**
 * Help Chat Widget - Floating chatbot for website assistance
 * Appears on all pages to provide context-aware help
 */

/* ========== CHAT WIDGET CONTAINER ========== */
.help-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* ========== CHAT TOGGLE BUTTON ========== */
.help-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4), 0 0 40px rgba(139, 92, 246, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.help-chat-toggle::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%);
    border-radius: 50%;
}

.help-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(99, 102, 241, 0.5), 0 0 60px rgba(139, 92, 246, 0.3);
}

.help-chat-toggle:active {
    transform: scale(0.95);
}

.help-chat-toggle .icon {
    width: 28px;
    height: 28px;
    fill: white;
    transition: transform 0.3s ease;
}

.help-chat-toggle.active .icon-chat {
    display: none;
}

.help-chat-toggle.active .icon-close {
    display: block;
}

.help-chat-toggle .icon-close {
    display: none;
}

/* Notification badge */
.help-chat-toggle .notification-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    background: #ef4444;
    border-radius: 50%;
    font-size: 11px;
    font-weight: bold;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #1a1a2e;
    animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ========== CHAT WINDOW ========== */
.help-chat-window {
    position: absolute;
    bottom: 75px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: linear-gradient(180deg, #1a1a2e 0%, #0f0f1a 100%);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 16px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5), 0 0 30px rgba(99, 102, 241, 0.15);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.help-chat-window.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ========== CHAT HEADER ========== */
.help-chat-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15) 0%, rgba(139, 92, 246, 0.1) 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}

.help-chat-avatar {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.help-chat-info {
    flex: 1;
    min-width: 0;
}

.help-chat-title {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    margin: 0;
}

.help-chat-subtitle {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    margin: 2px 0 0 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.help-chat-subtitle .status-dot {
    width: 6px;
    height: 6px;
    background: #22c55e;
    border-radius: 50%;
    animation: pulse-status 2s infinite;
}

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

.help-chat-actions {
    display: flex;
    gap: 8px;
}

.help-chat-action-btn {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.6);
    transition: all 0.2s;
}

.help-chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.help-chat-action-btn svg {
    width: 16px;
    height: 16px;
}

/* ========== CHAT MESSAGES ========== */
.help-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

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

.help-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.help-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Message bubbles */
.help-chat-message {
    max-width: 85%;
    animation: message-appear 0.3s ease;
}

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

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

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

.help-chat-message .bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.help-chat-message.user .bubble {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    border-bottom-right-radius: 4px;
}

.help-chat-message.assistant .bubble {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom-left-radius: 4px;
}

.help-chat-message .bubble a {
    color: #a78bfa;
    text-decoration: underline;
}

/* Inline code */
.help-chat-message .bubble code,
.help-chat-message .bubble .inline-code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}

/* Code blocks */
.help-chat-message .bubble pre.code-block {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    padding: 12px;
    margin: 8px 0;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.help-chat-message .bubble pre.code-block code {
    background: transparent;
    padding: 0;
    font-size: 12px;
    line-height: 1.5;
}

/* Headers in chat */
.help-chat-message .bubble h1,
.help-chat-message .bubble h2,
.help-chat-message .bubble h3,
.help-chat-message .bubble h4,
.help-chat-message .bubble h5,
.help-chat-message .bubble h6 {
    margin: 12px 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
}

.help-chat-message .bubble h1 { font-size: 1.4em; }
.help-chat-message .bubble h2 { font-size: 1.25em; }
.help-chat-message .bubble h3 { font-size: 1.1em; }
.help-chat-message .bubble h4,
.help-chat-message .bubble h5,
.help-chat-message .bubble h6 { font-size: 1em; }

/* Lists */
.help-chat-message .bubble ul,
.help-chat-message .bubble ol {
    margin: 8px 0;
    padding-left: 20px;
}

.help-chat-message .bubble li {
    margin: 4px 0;
    line-height: 1.5;
}

/* Blockquotes */
.help-chat-message .bubble blockquote {
    border-left: 3px solid rgba(255, 255, 255, 0.3);
    margin: 8px 0;
    padding-left: 12px;
    font-style: italic;
    color: rgba(255, 255, 255, 0.8);
}

/* Tables */
.help-chat-message .bubble .md-table {
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 13px;
    width: 100%;
}

.help-chat-message .bubble .md-table th,
.help-chat-message .bubble .md-table td {
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 6px 10px;
    text-align: left;
}

.help-chat-message .bubble .md-table th {
    background: rgba(0, 0, 0, 0.2);
    font-weight: 600;
}

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

/* Strong and emphasis */
.help-chat-message .bubble strong {
    font-weight: 600;
}

.help-chat-message .bubble em {
    font-style: italic;
}

.help-chat-message .bubble del {
    text-decoration: line-through;
    opacity: 0.7;
}

/* Paragraphs */
.help-chat-message .bubble p {
    margin: 0 0 8px 0;
}

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

.help-chat-message .timestamp {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.3);
    margin-top: 4px;
    text-align: right;
}

.help-chat-message.assistant .timestamp {
    text-align: left;
}

/* Typing indicator */
.help-chat-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    max-width: fit-content;
    align-self: flex-start;
}

.help-chat-typing .dots {
    display: flex;
    gap: 4px;
}

.help-chat-typing .dot {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    animation: typing-dot 1.4s infinite;
}

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

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

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

/* Welcome message */
.help-chat-welcome {
    text-align: center;
    padding: 20px;
    color: rgba(255, 255, 255, 0.5);
}

.help-chat-welcome .icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.help-chat-welcome h4 {
    color: rgba(255, 255, 255, 0.8);
    margin: 0 0 8px 0;
    font-size: 16px;
}

.help-chat-welcome p {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
}

/* Quick actions */
.help-chat-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
    justify-content: center;
}

.help-quick-btn {
    padding: 8px 14px;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 20px;
    color: #a78bfa;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.help-quick-btn:hover {
    background: rgba(99, 102, 241, 0.25);
    border-color: rgba(99, 102, 241, 0.5);
    transform: translateY(-1px);
}

/* ========== CHAT INPUT ========== */
.help-chat-input-area {
    padding: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
}

.help-chat-input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.help-chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px 16px;
    color: white;
    font-size: 14px;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    line-height: 1.4;
    font-family: inherit;
    transition: border-color 0.2s;
}

.help-chat-input:focus {
    outline: none;
    border-color: rgba(99, 102, 241, 0.5);
}

.help-chat-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.help-chat-send-btn {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.help-chat-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

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

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

.help-chat-send-btn svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* ========== MOBILE RESPONSIVE ========== */
@media (max-width: 480px) {
    .help-chat-widget {
        bottom: 16px;
        right: 16px;
    }
    
    .help-chat-toggle {
        width: 54px;
        height: 54px;
    }
    
    .help-chat-window {
        bottom: 70px;
        width: calc(100vw - 32px);
        height: calc(100vh - 100px);
        right: -8px;
        border-radius: 12px;
    }
    
    .help-chat-header {
        padding: 12px 16px;
    }
    
    .help-chat-messages {
        padding: 12px;
    }
    
    .help-chat-input-area {
        padding: 12px;
    }
}

/* ========== REDUCED MOTION ========== */
@media (prefers-reduced-motion: reduce) {
    .help-chat-toggle,
    .help-chat-window,
    .help-chat-message,
    .help-quick-btn,
    .help-chat-send-btn {
        transition: none;
    }
    
    .help-chat-typing .dot,
    .help-chat-subtitle .status-dot,
    .notification-badge {
        animation: none;
    }
}

/* ========== HIGH CONTRAST MODE ========== */
@media (prefers-contrast: high) {
    .help-chat-window {
        border: 2px solid white;
    }
    
    .help-chat-message.assistant .bubble {
        border: 1px solid white;
    }
    
    .help-chat-input {
        border: 1px solid white;
    }
}
