/* AI Mastery Hub Chatbot Styles */

/* Chat Button */
.ai-chat-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0065F3 0%, #0052CC 100%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: none;
    box-shadow: 0 8px 32px rgba(0, 101, 243, 0.3);
    cursor: pointer;
    z-index: 9998;
    transition: all 0.3s ease;
    animation: pulse 2s ease-in-out;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.ai-chat-btn svg {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.ai-chat-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 40px rgba(0, 101, 243, 0.4);
}

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

.ai-chat-btn-text {
    display: none;
}

.ai-chat-btn-content {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

/* Chat Window - Enhanced positioning and z-index */
.ai-chat-window {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 80px);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(0, 101, 243, 0.2);
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
    z-index: 999999;
    display: flex;
    flex-direction: column;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    transition: all 0.3s ease;
    animation: slideIn 0.3s ease-out;
}

.ai-chat-window.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px) scale(0.95);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
.ai-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: linear-gradient(135deg, #0065F3 0%, #0052CC 100%);
    color: white;
    border-radius: 16px 16px 0 0;
    font-weight: 600;
}

.ai-chat-title {
    font-size: 16px;
}

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

.ai-chat-expand,
.ai-chat-reset {
    background: none;
    border: none;
    color: white;
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s, transform 0.2s;
    opacity: 0.9;
}

.ai-chat-expand:hover,
.ai-chat-reset:hover {
    background: rgba(255, 255, 255, 0.2);
    opacity: 1;
}

.ai-chat-expand:hover {
    transform: scale(1.1);
}

.ai-chat-reset:hover {
    transform: rotate(-30deg);
}

.ai-chat-expand .hidden,
.ai-chat-reset .hidden {
    display: none;
}

.ai-chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.ai-chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Zen Mode (Full Screen) */
.ai-chat-window.zen-mode {
    width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    bottom: 0 !important;
    right: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    background: rgba(255, 255, 255, 0.98);
}

.ai-chat-window.zen-mode .ai-chat-header {
    border-radius: 0 !important;
    padding: 20px calc(15% + 20px);
}

.ai-chat-window.zen-mode .ai-chat-messages {
    padding: 40px 15%;
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
}

.ai-chat-window.zen-mode .ai-chat-input-container {
    padding: 30px 15%;
    background: white;
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
    border-top: none;
}

.ai-chat-window.zen-mode .ai-chat-input {
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

.ai-chat-window.zen-mode .ai-chat-footer {
    padding: 20px 15%;
    text-align: center;
}

/* Hide expand on mobile */
@media (max-width: 768px) {
    .ai-chat-expand {
        display: none;
    }
}

/* Messages Container */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.ai-chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 101, 243, 0.3);
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 101, 243, 0.5);
}

/* Messages */
.ai-message {
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

.ai-message-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 16px;
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 14px;
}

.ai-message-user .ai-message-bubble {
    background: #0065F3;
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-message-ai .ai-message-bubble {
    background: #F3F4F6;
    color: #1F2937;
    border-bottom-left-radius: 4px;
}

.ai-message-bubble a {
    color: inherit;
    text-decoration: underline;
    font-weight: 500;
}

.ai-message-bubble a:hover {
    opacity: 0.8;
}

/* Persona Selection */
.ai-persona-selection {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 15px;
    width: 100%;
}

.ai-persona-chip {
    display: flex;
    align-items: center;
    gap: 12px;
    background: white;
    border: 1px solid rgba(0, 101, 243, 0.2);
    border-radius: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.ai-persona-chip:hover {
    background: rgba(0, 101, 243, 0.05);
    border-color: #0065F3;
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(0, 101, 243, 0.1);
}

.persona-icon {
    font-size: 20px;
}

.persona-label {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
}

/* Rendered HTML elements in messages */
.ai-message-bubble h1,
.ai-message-bubble h2,
.ai-message-bubble h3 {
    margin: 0.5em 0 0.3em 0;
    font-weight: 600;
}

.ai-message-bubble h1 {
    font-size: 1.2em;
}

.ai-message-bubble h2 {
    font-size: 1.1em;
}

.ai-message-bubble h3 {
    font-size: 1em;
}

.ai-message-bubble p {
    margin: 0.5em 0;
}

.ai-message-bubble ul {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.ai-message-bubble li {
    margin: 0.3em 0;
}

.ai-message-bubble strong {
    font-weight: 600;
}

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

/* Conversation Starters */
.ai-conversation-starters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    max-width: 85%;
}

.ai-starter-chip {
    background: white;
    border: 1px solid #E5E7EB;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13px;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    /* Fixed overflow: Allow wrapping and limit width */
    white-space: normal;
    word-break: break-word;
    text-align: left;
}

.ai-starter-chip:hover {
    background: #F9FAFB;
    border-color: #0065F3;
    color: #0065F3;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 101, 243, 0.15);
}

.ai-starter-chip:active {
    transform: translateY(0);
}

/* AI Response Suggestion Chips */
.ai-suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    max-width: 100%;
}

.ai-suggestion-chip {
    background: white;
    border: 1px solid #E5E7EB;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13px;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    white-space: normal;
    word-break: break-word;
    text-align: left;
    max-width: 100%;
}

.ai-suggestion-chip:hover {
    background: #F9FAFB;
    border-color: #0065F3;
    color: #0065F3;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 101, 243, 0.15);
}

.ai-suggestion-chip:active {
    transform: translateY(0);
}

/* Sources */
.ai-message-sources {
    font-size: 12px;
    color: #6B7280;
    margin-top: 4px;
    padding-left: 8px;
}

.ai-message-sources a {
    color: #0065F3;
    text-decoration: none;
    font-weight: 500;
}

.ai-message-sources a:hover {
    text-decoration: underline;
}

/* Note Badge for non-curated responses */
.ai-note-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #6B7280;
    margin-top: 8px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 6px;
    font-style: italic;
}

.ai-note-badge svg {
    opacity: 0.7;
}

/* Loading Animation */
.ai-loading-dots span {
    animation: blink 1.4s infinite;
}

.ai-loading-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-loading-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes blink {

    0%,
    60%,
    100% {
        opacity: 1;
    }

    30% {
        opacity: 0.3;
    }
}

/* Input Container */
.ai-chat-input-container {
    display: flex;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    background: white;
}

.ai-chat-input {
    flex: 1;
    padding: 12px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    font-family: inherit;
    font-size: 14px;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    max-height: 120px;
}

.ai-chat-input:focus {
    border-color: #0065F3;
}

.ai-chat-input:disabled {
    background: #F3F4F6;
    cursor: not-allowed;
}

.ai-chat-send {
    width: 44px;
    height: 44px;
    border: none;
    background: #0065F3;
    color: white;
    border-radius: 12px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ai-chat-send:hover:not(:disabled) {
    background: #0052CC;
    transform: translateY(-1px);
}

.ai-chat-send:disabled {
    background: #9CA3AF;
    cursor: not-allowed;
}

/* Footer */
.ai-chat-footer {
    padding: 12px 20px;
    text-align: center;
    font-size: 11px;
    color: #9CA3AF;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    background: white;
    border-radius: 0 0 16px 16px;
}

.ai-privacy-info {
    cursor: help;
    text-decoration: underline dotted;
    transition: color 0.2s;
}

.ai-privacy-info:hover {
    color: #0065F3;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .ai-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        animation: slideUp 0.3s ease-out;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }

        to {
            transform: translateY(0);
        }
    }

    .ai-chat-btn {
        bottom: 20px !important;
        right: 20px !important;
        left: auto !important;
        width: 60px !important;
        height: 60px !important;
        border-radius: 50% !important;
        margin: 0 !important;
        border: none !important;
        box-shadow: 0 8px 32px rgba(0, 101, 243, 0.3) !important;
        z-index: 9998 !important;
        background: linear-gradient(135deg, #0065F3 0%, #0052CC 100%) !important;
    }

    .ai-chat-btn-hidden {
        transform: scale(0) !important;
        opacity: 0 !important;
    }

    .ai-chat-btn-content {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 100% !important;
        height: 100% !important;
    }

    .ai-chat-btn-text {
        display: none !important;
    }

    .ai-chat-btn svg {
        width: 24px !important;
        height: 24px !important;
    }

    .ai-chat-header {
        border-radius: 0;
    }

    .ai-chat-footer {
        border-radius: 0;
    }

    .ai-chat-close {
        width: 36px;
        height: 36px;
        font-size: 32px;
    }

    .ai-message-bubble {
        max-width: 85%;
    }

    .ai-conversation-starters {
        max-width: 90%;
    }

    .ai-starter-chip {
        font-size: 12px;
        padding: 7px 12px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .ai-chat-window {
        background: rgba(31, 41, 55, 0.95);
        border-color: rgba(0, 101, 243, 0.3);
    }

    .ai-chat-messages::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.05);
    }

    .ai-message-ai .ai-message-bubble {
        background: #374151;
        color: #F3F4F6;
    }

    .ai-chat-input-container {
        background: #1F2937;
        border-top-color: rgba(255, 255, 255, 0.1);
    }

    .ai-chat-input {
        background: #374151;
        color: #F3F4F6;
        border-color: rgba(255, 255, 255, 0.1);
    }

    .ai-chat-input:focus {
        border-color: #0065F3;
    }

    .ai-chat-footer {
        background: #1F2937;
        border-top-color: rgba(255, 255, 255, 0.05);
    }

    .ai-starter-chip {
        background: #374151;
        border-color: #4B5563;
        color: #F3F4F6;
    }

    .ai-starter-chip:hover {
        background: #4B5563;
        border-color: #0065F3;
        color: #60A5FA;
    }

    .ai-paywall-overlay {
        background: rgba(31, 41, 55, 0.95) !important;
        border-color: rgba(255, 255, 255, 0.1) !important;
    }

    .ai-paywall-content h3 {
        color: white !important;
    }

    .ai-paywall-content p,
    .ai-id-label {
        color: #9CA3AF !important;
    }

    .ai-waitlist-form input {
        background: #1F2937 !important;
        border-color: #4B5563 !important;
        color: white !important;
    }

    .ai-id-btn {
        background: #374151 !important;
        color: white !important;
        border-color: #4B5563 !important;
    }
}

/* Paywall Overlay Redesign */
.ai-chat-input-wrapper {
    position: relative;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.ai-paywall-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(8px);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: slideUp 0.3s ease-out;
}

.ai-paywall-overlay.hidden {
    display: none;
}

.ai-paywall-content {
    padding: 20px;
    width: 100%;
    max-width: 340px;
    text-align: center;
}

.ai-paywall-header h3 {
    margin: 0;
    font-size: 18px;
    color: #111827;
}

.ai-paywall-header p {
    margin: 4px 0 16px 0;
    font-size: 13px;
    color: #6B7280;
}

.ai-waitlist-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.ai-waitlist-form input {
    padding: 10px 12px;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.ai-waitlist-form input:focus {
    border-color: #0065F3;
}

.ai-waitlist-form button {
    padding: 10px;
    background: #0065F3;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.ai-waitlist-form button:hover {
    background: #0052CC;
}

.ai-rescue-box {
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    padding-top: 16px;
}

.ai-id-label {
    display: block;
    font-size: 11px;
    color: #9CA3AF;
    margin-bottom: 8px;
}

.ai-id-label strong {
    color: #374151;
    font-family: monospace;
    background: #F3F4F6;
    padding: 2px 4px;
    border-radius: 4px;
}

.ai-id-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.ai-id-btn {
    padding: 6px 10px;
    font-size: 11px;
    border: 1px solid #E5E7EB;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
    color: #374151;
}

.ai-id-btn:hover {
    border-color: #0065F3;
    color: #0065F3;
    background: rgba(0, 101, 243, 0.02);
}

.success-view .success-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.ai-paywall-close-btn {
    margin-top: 16px;
    padding: 8px 16px;
    background: #F3F4F6;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: #4B5563;
    font-weight: 500;
}

.ai-paywall-close-btn:hover {
    background: #E5E7EB;
}

/* Fix for standard tracker */
.ai-query-tracker {
    padding: 8px 20px;
    font-size: 11px;
    color: #6B7280;
    font-weight: 500;
    background: #F9FAFB;
    text-align: right;
}

/* Training & Privacy Notice */
.ai-training-notice {
    padding: 8px 16px;
    background: #fefce8;
    border-top: 1px solid #fef08a;
    font-size: 10px;
    color: #854d0e;
    text-align: center;
    line-height: 1.3;
}

@media (prefers-color-scheme: dark) {
    .ai-training-notice {
        background: #422006;
        border-top-color: #713f12;
        color: #fef08a;
    }
}

.dark-theme .ai-training-notice {
    background: #422006;
    border-top-color: #713f12;
    color: #fef08a;
}

/* Welcome Hook (Bubble) Styles */
.ai-welcome-bubble {
    position: fixed;
    bottom: 95px;
    /* Positioned above the FAB */
    right: 20px;
    z-index: 9997;
    cursor: pointer;
    animation: bubbleSlideIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-width: 200px;
}

.ai-welcome-content {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(0, 101, 243, 0.1);
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    display: flex;
    align-items: flex-start;
    gap: 8px;
    position: relative;
    font-family: inherit;
}

.ai-welcome-text {
    font-size: 13px;
    line-height: 1.4;
    color: #1F2937;
    font-weight: 500;
}

.ai-welcome-close {
    background: none;
    border: none;
    color: #9CA3AF;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    margin-top: -2px;
    transition: color 0.2s;
}

.ai-welcome-close:hover {
    color: #4B5563;
}

.ai-welcome-arrow {
    position: absolute;
    bottom: -8px;
    right: 25px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid rgba(255, 255, 255, 0.95);
}

.ai-fade-out {
    animation: bubbleFadeOut 0.3s forwards;
}

@keyframes bubbleSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes bubbleFadeOut {
    from {
        opacity: 1;
        transform: scale(1);
    }

    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

/* Dark Mode for Bubble */
@media (prefers-color-scheme: dark) {
    .ai-welcome-content {
        background: rgba(31, 41, 55, 0.95);
        border-color: rgba(255, 255, 255, 0.1);
    }

    .ai-welcome-text {
        color: #F3F4F6;
    }

    .ai-welcome-arrow {
        border-top-color: rgba(31, 41, 55, 0.95);
    }
}

.dark-theme .ai-welcome-content {
    background: rgba(31, 41, 55, 0.95);
    border-color: rgba(255, 255, 255, 0.1);
}

.dark-theme .ai-welcome-text {
    color: #F3F4F6;
}

.dark-theme .ai-welcome-arrow {
    border-top-color: rgba(31, 41, 55, 0.95);
}

/* Mobile Adjustment */
@media (max-width: 768px) {
    .ai-welcome-bubble {
        bottom: 85px;
        right: 15px;
        max-width: 180px;
    }
}