/* Global Styles & Animations */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic:wght@100;200;300;400;500;600;700;800;900&family=Inter:wght@400;600&family=IBM+Plex+Sans+Arabic:wght@400;600&display=swap');

/* Cosmic Neural Background */
@keyframes cosmic-drift {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

@keyframes float-particles {

    0%,
    100% {
        transform: translateY(0) translateX(0);
        opacity: 0.3;
    }

    50% {
        transform: translateY(-20px) translateX(10px);
        opacity: 0.6;
    }
}

body {
    background-color: #212121;
    background-image:
        radial-gradient(circle at 15% 50%, rgba(49, 204, 49, 0.08) 0%, transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(37, 162, 37, 0.05) 0%, transparent 25%),
        linear-gradient(135deg, #212121 0%, #1b1b1b 100%);
    background-size: 200% 200%;
    animation: cosmic-drift 20s ease infinite;
    font-family: "Noto Sans Arabic", "Inter", "IBM Plex Sans Arabic", system-ui, sans-serif;
    font-weight: 400;
    line-height: 1.6;
    font-size: clamp(0.95rem, 0.92rem + 0.25vw, 1rem);
    color: #e2e8f0;
}

body.rtl {
    direction: ltr;
}

body.rtl #sidebar {
    direction: ltr;
    text-align: left;
    left: 0;
    right: auto;
}

body.rtl main {
    direction: rtl;
}

/* Keep input + book selector fixed LTR even in Arabic */
body.rtl #input-area,
body.rtl #book-selector-wrap,
body.rtl #input-row,
body.rtl #branch-book-selector,
body.rtl #book-dropdown-menu,
body.rtl #book-dropdown-list,
body.rtl #chat-input,
body.rtl #attach-btn,
body.rtl #send-btn {
    direction: ltr;
    text-align: left;
}

body.rtl #current-book-label {
    margin-left: 0;
    margin-right: 0.25rem;
}

/* Keep chat rows in English-style layout (user right, AI left) across UI languages */
#messages-container {
    direction: ltr;
}

#messages-container>div {
    direction: ltr;
}

#sidebar {
    transition:
        width 260ms cubic-bezier(0.22, 1, 0.36, 1),
        transform 260ms cubic-bezier(0.22, 1, 0.36, 1),
        box-shadow 260ms ease;
    will-change: width, transform;
}

.welcome-simple {
    position: relative;
    width: 100%;
    min-height: 55vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    text-align: center;
    padding: clamp(2rem, 5vw, 3.5rem);
}

.welcome-orb {
    position: absolute;
    width: 220px;
    height: 220px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(49, 204, 49, 0.15), transparent 60%);
    filter: blur(6px);
    opacity: 0.6;
    pointer-events: none;
}

.welcome-title {
    font-family: "Playfair Display", serif;
    font-weight: 500;
    font-size: clamp(2.2rem, 2rem + 1.8vw, 3.6rem);
    color: #f1f5f9;
    letter-spacing: -0.01em;
}

.welcome-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.75rem;
    border-radius: 999px;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.welcome-subtitle {
    max-width: 520px;
    font-size: clamp(1rem, 0.95rem + 0.4vw, 1.15rem);
    color: rgba(255, 255, 255, 0.72);
}

.welcome-hint {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.45);
}


@media (prefers-reduced-motion: reduce) {
    .welcome-orb {
        filter: none;
    }
}

/* Custom Scrollbar for Webkit */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #0B0F0E;
    /* Dark background matching body */
}

::-webkit-scrollbar-thumb {
    background: rgba(49, 204, 49, 0.2);
    /* Subtle green tint */
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(49, 204, 49, 0.4);
}

/* Glassmorphism 2.0 - The "Holographic" Feel */
.glass-panel {
    background: rgba(22, 26, 25, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow:
        0 4px 30px rgba(0, 0, 0, 0.1),
        inset 0 0 0 1px rgba(255, 255, 255, 0.05);
    position: relative;
    overflow: hidden;
}

/* Subtle Noise Texture for depth */
.glass-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.05'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: -1;
    opacity: 0.4;
}

/* Enhanced Physics Card - The "Hero" Element */
.physics-card {
    background: linear-gradient(145deg, rgba(21, 26, 24, 0.95), rgba(10, 12, 11, 0.98));
    border: 1px solid rgba(49, 204, 49, 0.3);
    border-radius: 1rem;
    position: relative;
    overflow: hidden;
    box-shadow:
        0 10px 30px -5px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(49, 204, 49, 0.1),
        0 0 20px rgba(49, 204, 49, 0.05);
    margin: 1.5rem 0;
    width: 100%;
    max-width: 450px;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

.physics-card:hover {
    transform: translateY(-5px) scale(1.01);
    box-shadow:
        0 20px 40px -5px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(49, 204, 49, 0.4),
        0 0 30px rgba(49, 204, 49, 0.15);
}

.physics-card::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg,
            transparent,
            rgba(49, 204, 49, 0.05),
            transparent);
    transform: rotate(45deg);
    animation: shimmer 6s infinite linear;
    pointer-events: none;
}

/* Revolutionized Typing Animation - "Neural Pulse" */
@keyframes neuralPulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 0.4;
        box-shadow: 0 0 0 rgba(49, 204, 49, 0);
    }

    50% {
        transform: scale(1.2);
        opacity: 1;
        box-shadow: 0 0 10px rgba(49, 204, 49, 0.5);
    }
}

.typing-dot {
    animation: neuralPulse 1.4s infinite ease-in-out;
    width: 6px;
    height: 6px;
    background-color: #32CD32;
    border-radius: 50%;
    display: inline-block;
    margin: 0 2px;
}

.typing-dot.delay-1 {
    animation-delay: 0.2s;
}

.typing-dot.delay-2 {
    animation-delay: 0.4s;
}

/* Revolutionary Markdown Styling */
.prose {
    color: #e2e8f0;
    max-width: 720px;
    margin: 0 auto;
}


/* ============================= */
/* 🔥 DARIS Teaching Hierarchy */
/* ============================= */

/* Main Lesson Title */
.prose h1 {
    font-size: clamp(1.8rem, 1.6rem + 1vw, 2.4rem);
    font-weight: 800;
    line-height: 1.3;
    margin-top: 1.8em;
    margin-bottom: 0.8em;
    color: #ffffff;
}

/* Section Titles */
.prose h2 {
    font-size: clamp(1.4rem, 1.2rem + 0.6vw, 1.6rem);
    font-weight: 700;
    margin-top: 1.5em;
    margin-bottom: 0.6em;
}

/* Sub Titles */
.prose h3 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-top: 1.2em;
    margin-bottom: 0.4em;
    color: #e8f4e8;
}

/* Paragraph spacing for teaching rhythm */
.prose p {
    margin-bottom: 1.2em;
    line-height: 1.9;
    font-weight: 400;
}

/* Important Concept Box (🔑) */
.prose blockquote {
    background: rgba(49, 204, 49, 0.08);
    border-left: 3px solid #32CD32;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 1.2em 0;
    font-weight: 500;
}

/* Highlight Important Words */
.prose strong {
    font-weight: 700;
    color: #ffffff;
}

/* Horizontal Divider – Lesson Break */
.prose hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    margin: 2.2em 0;
}

/* Question Section Styling */
.prose h2:has(+ p strong) {
    color: #4ade80;
}


.prose h1 {
    animation: fadeSlide 0.4s ease forwards;
}

@keyframes fadeSlide {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

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



/* Glowing Underline for Headings */
.prose h2::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 40px;
    height: 2px;
    background: linear-gradient(90deg, #32CD32, transparent);
    border-radius: 2px;
}

.prose p {
    margin-bottom: 1em;
    line-height: 1.8;
}

.prose ul {
    list-style-type: disc;
    list-style-position: outside;
    padding-left: 1.25em;
    margin-bottom: 1em;
}

.prose ul li {
    margin-bottom: 0.5em;
}

.prose blockquote strong {
    color: #4ade80;
}

.prose ol {
    list-style-type: decimal;
    padding-left: 1.5em;
    margin-bottom: 1em;
    color: #a0aec0;
}

/* Message content lists always RTL (content is Arabic regardless of UI language) */
.msg-content ol,
.msg-content ul {
    direction: rtl;
}

.msg-content ol {
    padding-left: 0;
    padding-right: 1.5em;
}

.msg-content ul {
    padding-left: 0;
    padding-right: 1.25em;
}

/* But keep English code examples LTR inside lists */
.msg-content li>code {
    direction: ltr;
    display: inline-block;
    unicode-bidi: embed;
}

.prose strong {
    color: #fff;
    font-weight: 600;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

/* Code Blocks - "Terminal Mode" */
.prose pre {
    background: #0d1110 !important;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.75rem;
    padding: 1rem;
    margin: 1.5rem 0;
    overflow-x: auto;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
}

.prose code {
    background: rgba(49, 204, 49, 0.1);
    color: #4ade80;
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 0.9em;
}

.prose pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

.prose hr {
    border-color: rgba(255, 255, 255, 0.1);
    margin-top: 2.5em;
    margin-bottom: 2.5em;
}

/* AI Response Typography - Optimized for Reading */
.msg-content {
    font-size: clamp(1rem, 0.95rem + 0.4vw, 1.08rem);
    line-height: 1.9;
    letter-spacing: 0.015em;
}


/* User message bubble - dark style */
.user-msg-bubble {
    background: linear-gradient(145deg, rgba(18, 23, 22, 0.96), rgba(10, 13, 12, 0.98));
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow:
        0 10px 24px rgba(0, 0, 0, 0.32),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

/* AI Actions (Copy, Like, Dislike, Share) */
.ai-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: transparent;
    border: 1px solid transparent;
    color: rgba(255, 255, 255, 0.4);
    font-size: 0;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.1);
}

.action-btn i {
    width: 16px;
    height: 16px;
    stroke-width: 2px;
}

/* Hide input textarea scrollbar (cross-browser) */
#chat-input {
    scrollbar-width: none;
    /* Firefox */
}

#chat-input::-webkit-scrollbar {
    /* Chrome/Safari */
    display: none;
}

/* Ensure chat scrollbar is on the right side */
#scroll-container {
    direction: ltr;
}

#scroll-container>* {
    direction: ltr;
}

/* Usage badge in hero that can float to top-center */
.physics-law {
    padding: 12px 16px;
    border-radius: 12px;
    background: transparent;
}

.physics-law .law-formula {
    text-align: center;
    font-size: 1.2rem;
    margin-bottom: 12px;
    color: #e8f4e8;
}

.physics-law .law-variables {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    direction: rtl;
}

.physics-law .var-item {
    flex: 1 1 0;
    text-align: center;
}

.physics-law .var-head {
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
    margin-bottom: 6px;
}

.physics-law .var-symbol {
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
}

.physics-law .var-name {
    opacity: .9;
}

.physics-law .var-unit {
    color: rgba(255, 255, 255, 0.6);
    font-size: .9rem;
}




.backdrop-visible {
    opacity: 1 !important;
}

.hero-usage-badge {
    position: relative;
    transition: top 280ms cubic-bezier(0.22, 1, 0.36, 1), transform 280ms cubic-bezier(0.22, 1, 0.36, 1), left 280ms cubic-bezier(0.22, 1, 0.36, 1);
    will-change: top, transform, left;
}

.hero-usage-badge.floating {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%) scale(0.96);
    z-index: 60;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    background: rgba(49, 204, 49, 0.08);
}

/* Mobile Layout Fixes */
@media (max-width: 767px) {
    #sidebar {
        width: 280px;
        /* Standard mobile sidebar width */
    }

    .msg-content {
        font-size: 0.95rem;
        /* Readable on mobile */
    }

    /* Improve touch targets */
    button,
    .action-btn {
        min-height: 44px;
    }
}

.ai-typing {
    display: flex;
    gap: 6px;
}

.ai-typing span {
    width: 6px;
    height: 6px;
    background: rgba(255, 255, 255, .5);
    border-radius: 999px;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.ai-typing span:nth-child(2) {
    animation-delay: .15s;
}

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

@keyframes typingBounce {

    0%,
    80%,
    100% {
        transform: scale(.6);
        opacity: .4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}





/* تأكد المعادلة نفسها LTR */
.msg-content .katex-display .katex {
    margin: 0 auto;
}

/* Force math equations LTR and centered */
.msg-content .katex-display,
.msg-content mjx-container,
.prose .katex-display {
    direction: ltr !important;
    text-align: center !important;
    unicode-bidi: embed;
}

/* If using plain text equations inside paragraphs */
.msg-content p:has(.katex) {
    direction: ltr !important;
    text-align: center !important;
}

/* Fix numbers and inline math in RTL Arabic text */
.msg-content .katex,
.msg-content span:has(> .katex) {
    direction: ltr;
    display: inline-block;
    unicode-bidi: embed;
}

/* Fix inline equations written as plain text */
.msg-content p,
.msg-content li {
    unicode-bidi: plaintext;
}

/* Override: Arabic content lists must be RTL regardless */
.msg-content ol li,
.msg-content ul li {
    direction: rtl;
    unicode-bidi: embed;
}

/* Fix bold-numbered paragraphs that AI generates instead of ol (e.g. **1. since**) */
.msg-content p>strong:first-child {
    display: block;
    direction: rtl;
    text-align: right;
}

/* English examples in Arabic lessons - make inline code readable, not terminal-style */
.msg-content p>code,
.msg-content li>code,
.msg-content blockquote code {
    background: rgba(255, 255, 255, 0.07);
    color: #e2e8f0;
    padding: 0.15em 0.5em;
    border-radius: 4px;
    font-family: "Noto Sans Arabic", "Inter", system-ui, sans-serif;
    font-size: 1em;
    direction: ltr;
    display: inline-block;
    unicode-bidi: embed;
    border: 1px solid rgba(255, 255, 255, 0.1);
}