/* ai-chat.css - AI Hebrew Tutor Floating Button & Chat Popup */
/* Dark Theme with Glassmorphism - Matches app style */

/* ============================================
   FLOATING AI BUTTON
   ============================================ */

.ai-chat-button {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed 0%, #3b82f6 100%);
    border: none;
    cursor: pointer;
    z-index: 998;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(124, 58, 237, 0.4),
                0 0 30px rgba(124, 58, 237, 0.2);
    transition: all 0.3s ease;
    animation: ai-button-pulse 2s infinite;
}

.ai-chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(124, 58, 237, 0.5),
                0 0 40px rgba(124, 58, 237, 0.3);
}

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

.ai-chat-button-text {
    color: white;
    font-size: 1rem;
    font-weight: 700;
    font-family: 'Montserrat', 'Inter', sans-serif;
    letter-spacing: 1px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Pulse animation */
@keyframes ai-button-pulse {
    0%, 100% {
        box-shadow: 0 4px 20px rgba(124, 58, 237, 0.4),
                    0 0 30px rgba(124, 58, 237, 0.2);
    }
    50% {
        box-shadow: 0 4px 25px rgba(124, 58, 237, 0.6),
                    0 0 40px rgba(124, 58, 237, 0.4);
    }
}

/* Hide button when chat is open */
.ai-chat-button.hidden {
    opacity: 0;
    visibility: hidden;
    transform: scale(0.8);
}

/* Adjust position when bottom nav is present */
body.has-bottom-nav .ai-chat-button {
    bottom: 170px;
}

/* ============================================
   CHAT POPUP OVERLAY
   ============================================ */

.ai-chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.ai-chat-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   CHAT POPUP CONTAINER
   ============================================ */

.ai-chat-popup {
    position: fixed;
    bottom: 170px;
    right: 30px;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 500px;
    max-height: calc(100vh - 150px);
    background: rgba(22, 27, 34, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5),
                0 0 30px rgba(124, 58, 237, 0.15);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
}

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

/* Adjust position when bottom nav is present */
body.has-bottom-nav .ai-chat-popup {
    bottom: 240px;
}

/* ============================================
   CHAT HEADER
   ============================================ */

.ai-chat-header {
    background: linear-gradient(135deg, #7c3aed 0%, #3b82f6 100%);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

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

.ai-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.ai-chat-title {
    color: white;
    font-size: 1rem;
    font-weight: 700;
    font-family: 'Montserrat', 'Inter', sans-serif;
}

.ai-chat-subtitle {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.75rem;
    margin-top: 2px;
}

.ai-chat-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.2s ease;
}

.ai-chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* ============================================
   CHAT MESSAGES AREA
   ============================================ */

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    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;
}

/* Message bubbles */
.ai-chat-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    animation: message-appear 0.3s ease;
}

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

/* AI message (left aligned) */
.ai-chat-message.ai {
    align-self: flex-start;
    background: rgba(124, 58, 237, 0.2);
    border: 1px solid rgba(124, 58, 237, 0.3);
    color: #e5e7eb;
    border-bottom-left-radius: 4px;
}

/* User message (right aligned) */
.ai-chat-message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

/* System message (center, muted) */
.ai-chat-message.system {
    align-self: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.8rem;
    text-align: center;
    max-width: 90%;
}

/* Error message */
.ai-chat-message.error {
    align-self: center;
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    font-size: 0.85rem;
    text-align: center;
}

/* Limit reached message */
.ai-chat-message.limit {
    align-self: center;
    background: rgba(251, 191, 36, 0.2);
    border: 1px solid rgba(251, 191, 36, 0.3);
    color: #fde68a;
    text-align: center;
    padding: 16px;
}

.ai-chat-message.limit .upgrade-btn {
    display: inline-block;
    margin-top: 10px;
    padding: 8px 20px;
    background: linear-gradient(135deg, #7c3aed 0%, #3b82f6 100%);
    color: white;
    text-decoration: none;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.ai-chat-message.limit .upgrade-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.4);
}

/* Typing indicator */
.ai-chat-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(124, 58, 237, 0.2);
    border: 1px solid rgba(124, 58, 237, 0.3);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    max-width: 100px;
}

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

.ai-chat-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #7c3aed;
    animation: typing-bounce 1.4s infinite;
}

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

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

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

/* ============================================
   CHAT INPUT AREA
   ============================================ */

.ai-chat-input-area {
    padding: 12px 16px 16px;
    background: rgba(13, 17, 23, 0.8);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

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

.ai-chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 12px 18px;
    color: white;
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    min-height: 44px;
    max-height: 100px;
    overflow-y: auto;
    transition: all 0.2s ease;
}

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

.ai-chat-input:focus {
    outline: none;
    border-color: rgba(124, 58, 237, 0.5);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

.ai-chat-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed 0%, #3b82f6 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.ai-chat-send:hover:not(:disabled) {
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.4);
}

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

.ai-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(255, 255, 255, 0.2);
}

/* Send icon arrow */
.ai-chat-send svg {
    width: 20px;
    height: 20px;
    transform: rotate(-45deg);
    margin-left: 2px;
}

/* ============================================
   LOGIN PROMPT (for non-logged users)
   ============================================ */

.ai-chat-login-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    flex: 1;
}

.ai-chat-login-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.ai-chat-login-title {
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.ai-chat-login-text {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9rem;
    margin-bottom: 20px;
    line-height: 1.5;
}

.ai-chat-login-btn {
    display: inline-block;
    padding: 12px 30px;
    background: linear-gradient(135deg, #7c3aed 0%, #3b82f6 100%);
    color: white;
    text-decoration: none;
    border-radius: 25px;
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.ai-chat-login-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.4);
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */

@media (max-width: 480px) {
    .ai-chat-button {
        bottom: 90px;
        right: 20px;
        width: 52px;
        height: 52px;
    }

    .ai-chat-button-text {
        font-size: 0.9rem;
    }

    body.has-bottom-nav .ai-chat-button {
        bottom: 160px;
    }

    .ai-chat-popup {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 60px);
        max-height: calc(100vh - 60px);
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
    }

    .ai-chat-popup.active {
        transform: translateY(0);
    }

    body.has-bottom-nav .ai-chat-popup {
        height: calc(100vh - 130px);
        bottom: 70px;
    }

    .ai-chat-header {
        padding: 14px 16px;
    }

    .ai-chat-messages {
        padding: 12px;
    }

    .ai-chat-input-area {
        padding: 10px 12px 14px;
    }
}

/* ============================================
   MARKDOWN STYLES IN AI MESSAGES
   ============================================ */

/* Inline code */
.ai-chat-message .inline-code {
    background: rgba(124, 58, 237, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.85em;
    color: #e5c07b;
}

/* Hebrew text highlight */
.ai-chat-message .hebrew-text {
    font-family: 'SBL Hebrew', 'Frank Ruehl CLM', 'David', 'Times New Roman', serif;
    font-size: 1.2em;
    color: #a78bfa;
    direction: rtl;
    display: inline-block;
    background: rgba(167, 139, 250, 0.1);
    padding: 1px 6px;
    border-radius: 3px;
}

/* Lists in AI messages */
.ai-chat-message .ai-list {
    margin: 8px 0;
    padding-left: 20px;
}

.ai-chat-message .ai-list li {
    margin: 4px 0;
}

.ai-chat-message li {
    margin: 4px 0;
    padding-left: 4px;
}

/* Bold and italic */
.ai-chat-message strong {
    color: #f9fafb;
    font-weight: 600;
}

.ai-chat-message em {
    font-style: italic;
    color: #d1d5db;
}

/* ============================================
   FULLSCREEN MODE (Desktop)
   ============================================ */

.ai-chat-popup.fullscreen {
    position: fixed;
    top: 20px;
    left: 20px;
    right: 20px;
    bottom: 20px;
    width: auto;
    max-width: none;
    height: auto;
    max-height: none;
    border-radius: 20px;
    transform: none;
}

.ai-chat-popup.fullscreen.active {
    transform: none;
}

.ai-chat-popup.fullscreen .ai-chat-messages {
    padding: 24px 40px;
}

.ai-chat-popup.fullscreen .ai-chat-message {
    max-width: 70%;
    font-size: 1rem;
}

.ai-chat-popup.fullscreen .ai-chat-input-area {
    padding: 16px 40px 24px;
}

.ai-chat-popup.fullscreen .ai-chat-input {
    font-size: 1rem;
    padding: 14px 20px;
}

/* Fullscreen toggle button */
.ai-chat-fullscreen-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s ease;
    margin-right: 8px;
}

.ai-chat-fullscreen-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

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

/* Header buttons container */
.ai-chat-header-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ============================================
   DARK MODE SUPPORT (already dark by default)
   ============================================ */

/* If someone has prefers-color-scheme: light, we still want dark chat */
@media (prefers-color-scheme: light) {
    .ai-chat-popup {
        background: rgba(22, 27, 34, 0.98);
    }
}
