/* ==========================================================================
   🤖 NEXTEDU - AI FAB, MODALS & CHAT UI (v8.0 - Light/Dark Theme Support)
   ========================================================================== */

/* --- 🌗 THEME VARIABLES (The Magic Brain) --- */
:root {
    --ai-overlay-bg: rgba(2, 6, 23, 0.6);
    --ai-modal-bg: rgba(15, 23, 42, 0.85);
    --ai-header-bg: linear-gradient(180deg, rgba(30, 41, 59, 0.9) 0%, rgba(15, 23, 42, 0.9) 100%);
    --ai-border: rgba(255, 255, 255, 0.1);
    --ai-text: #f8fafc;
    --ai-text-muted: #94a3b8;
    --ai-input-bg: rgba(255, 255, 255, 0.05);
    --ai-input-focus: rgba(0, 0, 0, 0.2);
    --ai-ai-msg-bg: rgba(30, 41, 59, 0.6);
    --ai-shadow: rgba(0, 0, 0, 0.5);
    --ai-glass-btn: rgba(30, 41, 59, 0.8);
    --ai-scroll-thumb: rgba(99, 102, 241, 0.3);
}

/* Light Theme Overrides */
[data-theme="light"] {
    --ai-overlay-bg: rgba(148, 163, 184, 0.4);
    --ai-modal-bg: rgba(255, 255, 255, 0.9);
    --ai-header-bg: rgba(248, 250, 252, 0.95);
    --ai-border: rgba(0, 0, 0, 0.08);
    --ai-text: #0f172a;
    --ai-text-muted: #475569;
    --ai-input-bg: rgba(0, 0, 0, 0.04);
    --ai-input-focus: #ffffff;
    --ai-ai-msg-bg: #ffffff;
    --ai-shadow: rgba(148, 163, 184, 0.2);
    --ai-glass-btn: rgba(255, 255, 255, 0.9);
    --ai-scroll-thumb: rgba(99, 102, 241, 0.4);
}

/* --- 1. AI FLOATING ACTION BUTTON (FAB) --- */
.ai-fab-container {
    position: fixed; bottom: calc(var(--bottom-nav-height, 75px) + 20px); right: 20px;
    z-index: 1500; display: flex; flex-direction: column; align-items: flex-end; gap: 15px;
}

.ai-fab-main {
    width: 43px; height: 43px; border-radius: 50%; border: none;
    background:
        linear-gradient(#111827, #111827) padding-box,
        linear-gradient(135deg, #38bdf8, #6366f1, #ec4899, #f59e0b) border-box;
    border: 2px solid transparent;
    color: white;
    font-size: 1.8rem; cursor: pointer; box-shadow: 0 12px 28px rgba(15, 23, 42, 0.35), 0 0 18px rgba(99, 102, 241, 0.28);
    transition: transform 0.25s ease, background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
    display: flex; justify-content: center; align-items: center; position: relative;
    will-change: transform;
}
.ai-fab-main::before {
    content: ''; position: absolute; inset: -6px; border-radius: 50%;
    background: conic-gradient(from 0deg, #38bdf8, #6366f1, #ec4899, #f59e0b, #38bdf8);
    z-index: -1;
    opacity: 0.78;
    animation: ai-neon-ring 6s linear infinite;
}
.ai-fab-main::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    background: #111827;
    z-index: -1;
}
@keyframes ai-neon-ring { to { transform: rotate(360deg); } }
.ai-fab-main:hover { transform: translate3d(0, -2px, 0) scale(1.04); box-shadow: 0 16px 34px rgba(15, 23, 42, 0.42), 0 0 22px rgba(236, 72, 153, 0.25); }
.ai-fab-main.menu-open { transform: translate3d(0, 0, 0) rotate(45deg) scale(0.96); background: var(--ai-modal-bg); color: var(--ai-text); }

/* --- 2. FAB OPTIONS --- */
.ai-options {
    display: flex; flex-direction: column; gap: 12px; opacity: 0; pointer-events: none;
    transform: translate3d(0, 30px, 0) scale(0.8); transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); transform-origin: bottom center;
    will-change: transform, opacity;
}
.ai-options.active { opacity: 1; pointer-events: auto; transform: translate3d(0, 0, 0) scale(1); }

.ai-option-btn {
    width: 48px; height: 48px; border-radius: 50%;
    background: var(--ai-glass-btn); border: 1px solid var(--ai-border);
    color: var(--ai-text); font-size: 1.1rem; cursor: pointer; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    box-shadow: 0 8px 20px var(--ai-shadow); transition: transform 0.25s cubic-bezier(0.25, 0.8, 0.25, 1), background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease; position: relative;
    will-change: transform;
}
.ai-option-btn:hover { background: #6366f1; transform: translate3d(-5px, 0, 0) scale(1.15); color: white; border-color: #8b5cf6; }

/* Tooltips */
.ai-option-btn .tooltip {
    position: absolute; right: 60px; background: var(--ai-modal-bg); color: var(--ai-text);
    padding: 6px 14px; border-radius: 8px; font-size: 0.85rem; font-weight: 600;
    white-space: nowrap; opacity: 0; pointer-events: none; transform: translate3d(15px, 0, 0);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); border: 1px solid var(--ai-border);
    box-shadow: 0 4px 15px var(--ai-shadow);
}
.ai-option-btn:hover .tooltip { opacity: 1; transform: translate3d(0, 0, 0); }

/* --- 3. MODAL OVERLAY & ANIMATIONS --- */
#aiModal {
    position: fixed; inset: 0; background: var(--ai-overlay-bg);
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    z-index: 9999; display: none; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.4s ease;
    transform: translate3d(0, 0, 0);
    will-change: opacity;
}
#aiModal.active { opacity: 1; display: flex !important; }

/* Center Modal for Desktop */
.ai-chat-modal {
    width: 95%; max-width: 500px; height: 80vh; max-height: 650px;
    background: var(--ai-modal-bg); border: 1px solid var(--ai-border); color: var(--ai-text);
    border-radius: 24px; display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 25px 50px -12px var(--ai-shadow), 0 0 30px rgba(99, 102, 241, 0.1);
    transform: translate3d(0, 50px, 0) scale(0.95); transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.5s ease;
    will-change: transform, opacity;
}
#aiModal.active .ai-chat-modal { transform: translate3d(0, 0, 0) scale(1); }

.modal-header {
    padding: 16px 20px; border-bottom: 1px solid var(--ai-border);
    display: flex; justify-content: space-between; align-items: center;
    background: var(--ai-header-bg); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.modal-header h2 {
    font-size: 1.2rem; display: flex; align-items: center; gap: 10px; margin: 0;
    color: var(--ai-text); font-weight: 700; font-family: 'Orbitron', sans-serif;
}
.modal-header h2 i { color: #8b5cf6; }

.close-icon {
    background: var(--ai-input-bg); border: 1px solid var(--ai-border);
    color: var(--text-muted); width: 34px; height: 34px; border-radius: 50%; font-size: 1.1rem;
    cursor: pointer; transition: background-color 0.25s ease, color 0.25s ease, transform 0.25s ease; display: flex; justify-content: center; align-items: center;
}
.close-icon:hover { background: #ef4444; color: white; transform: rotate(90deg) scale(1.1) translate3d(0,0,0); border-color: #ef4444; }

.ai-view { flex: 1; display: flex; flex-direction: column; height: 100%; overflow: hidden; }

/* --- 4. PERFECT CHAT CONTAINER --- */
/* --- 4. PERFECT CHAT CONTAINER --- */
.chat-container {
    flex: 1; 
    padding: 20px; 
    overflow-y: auto; 
    display: flex; 
    flex-direction: column; 
    gap: 15px; 
    scroll-behavior: smooth;
    /* Nayi property add karni hai taaki touch devices pe atke na */
    -webkit-overflow-scrolling: touch;
    height: 100%;
}
.chat-container::-webkit-scrollbar { width: 5px; }
.chat-container::-webkit-scrollbar-thumb { background: var(--ai-scroll-thumb); border-radius: 10px; }

/* Chat Bubbles */
.chat-msg {
    width: fit-content; max-width: 85%; padding: 12px 16px; font-size: 0.95rem; line-height: 1.5;
    animation: slideInUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; position: relative;
}
@keyframes slideInUp { 0% { opacity: 0; transform: translateY(15px); } 100% { opacity: 1; transform: translateY(0); } }

.chat-msg.user {
    align-self: flex-end; margin-left: auto;
    background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff;
    font-weight: 500; border-radius: 18px 18px 4px 18px; box-shadow: 0 5px 15px rgba(99, 102, 241, 0.2);
}
.chat-msg.ai {
    align-self: flex-start; margin-right: auto;
    background: var(--ai-ai-msg-bg); border: 1px solid var(--ai-border);
    color: var(--ai-text); border-radius: 18px 18px 18px 4px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    box-shadow: 0 2px 10px var(--ai-shadow);
}
.chat-msg.ai.thinking { background: transparent; border: none; color: #8b5cf6; font-style: italic; box-shadow: none; }

/* Chat Input Bar */
.input-bar {
    flex-shrink: 0; padding: 15px 20px; border-top: 1px solid var(--ai-border);
    display: flex; gap: 10px; background: var(--ai-header-bg); align-items: center;
}
.input-bar input {
    flex: 1; background: var(--ai-input-bg); border: 1px solid var(--ai-border);
    border-radius: 20px; padding: 12px 18px; color: var(--ai-text); font-size: 0.95rem; outline: none; transition: border-color 0.25s ease, background-color 0.25s ease, box-shadow 0.25s ease;
}
.input-bar input:focus { border-color: #8b5cf6; background: var(--ai-input-focus); box-shadow: 0 0 10px rgba(99, 102, 241, 0.1); }
.send-btn {
    width: 45px; height: 45px; min-width: 45px; border-radius: 50%; background: #6366f1; color: #fff;
    border: none; font-size: 1.1rem; cursor: pointer; transition: transform 0.25s cubic-bezier(0.25, 0.8, 0.25, 1), background-color 0.25s ease, box-shadow 0.25s ease; display: flex; justify-content: center; align-items: center; box-shadow: 0 4px 10px rgba(99,102,241,0.3);
    will-change: transform;
}
.send-btn:hover { background: #8b5cf6; transform: scale(1.1) translate3d(3px, 0, 0); }

/* --- 5. GRAMMAR & TRANSLATE UI --- */
.grammar-container { flex: 1; padding: 20px; display: flex; flex-direction: column; gap: 15px; overflow-y: auto; }
.lang-selector { display: flex; background: var(--ai-input-bg); padding: 5px; border-radius: 12px; border: 1px solid var(--ai-border); }
.lang-selector label { flex: 1; text-align: center; padding: 10px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 0.9rem; color: var(--ai-text-muted); transition: 0.3s; }
.lang-selector input[type="radio"] { display: none; }
.lang-selector label:has(input:checked) { background: #6366f1; color: #fff; box-shadow: 0 2px 10px rgba(99,102,241,0.3); }

.grammar-container textarea {
    width: 100%; background: var(--ai-input-bg); border: 1px solid var(--ai-border); border-radius: 16px;
    padding: 15px; color: var(--ai-text); font-size: 1rem; resize: none; outline: none; min-height: 150px; transition: 0.3s;
}
.grammar-container textarea:focus { border-color: #6366f1; background: var(--ai-input-focus); }
.action-btn {
    width: 100%; padding: 14px; background: linear-gradient(135deg, #6366f1, #8b5cf6); border: none; border-radius: 12px;
    color: #fff; font-weight: 700; font-size: 1rem; cursor: pointer; transition: transform 0.25s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.25s ease; display: flex; justify-content: center; align-items: center; gap: 10px;
    will-change: transform;
}
.action-btn:hover { transform: translate3d(0, -2px, 0); box-shadow: 0 8px 20px rgba(99,102,241,0.4); }

.result-box { margin-top: 10px; padding: 15px; background: rgba(16, 185, 129, 0.1); border: 1px solid rgba(16, 185, 129, 0.2); border-radius: 12px; display: none; }
.result-box small { display: block; color: #10b981; font-weight: 700; margin-bottom: 8px; }
.output-text { font-size: 1rem; line-height: 1.5; color: var(--ai-text); }

/* --- 6. iOS BOTTOM SHEET FOR MOBILE --- */
@media screen and (max-width: 600px) {
    #aiModal { align-items: flex-end; }
    
    .ai-chat-modal { 
        width: 100%; max-width: 100%; height: 85dvh !important; max-height: 85dvh !important; 
        border-radius: 24px 24px 0 0; 
        border: none; border-top: 1px solid var(--ai-border);
        transform: translateY(100%);
    }
    #aiModal.active .ai-chat-modal { transform: translateY(0); }
    
    /* Drag handle */
    .modal-header::before {
        content: ''; position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
        width: 40px; height: 5px; background: var(--ai-text-muted); opacity: 0.5; border-radius: 10px;
    }
    .modal-header { padding-top: 22px; }

    .ai-fab-container { bottom: calc(var(--bottom-nav-height, 70px) + 15px); right: 15px; }
    .ai-fab-main { width: 45px; height: 45px; font-size: 1.5rem; }
    .ai-option-btn { width: 45px; height: 45px; font-size: 1.1rem; }
    .ai-option-btn .tooltip { right: 55px; }
}
