/* AI Code Review & Rewrite Agent - Custom Styles */

/* ========== MOBILE FRIENDLY ========== */
/* Safe area for notched devices (e.g. iPhone) */
.safe-area-pad {
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    padding-top: max(0.75rem, env(safe-area-inset-top));
}
/* Prevent horizontal overflow on small screens */
body { overflow-x: hidden; }
/* Touch-friendly: remove tap highlight, improve scroll */
@media (hover: none) and (pointer: coarse) {
    button, a, [role="button"], input, select, textarea {
        -webkit-tap-highlight-color: transparent;
    }
    .overflow-x-auto { -webkit-overflow-scrolling: touch; }
}
/* Code blocks: horizontal scroll on mobile */
pre, .markdown-content pre {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
/* Minimum touch target (44px) for interactive elements */
@media (max-width: 640px) {
    .min-h-\[44px\] { min-height: 44px; }
}

/* Theme: light mode (when data-theme="light" on html) */
[data-theme="light"] body { background: #f1f5f9; color: #1e293b; }
[data-theme="light"] .bg-slate-950 { background: #f1f5f9 !important; }
[data-theme="light"] .text-slate-100 { color: #1e293b !important; }
[data-theme="light"] .bg-slate-900\/80 { background: rgba(248,250,252,0.9) !important; }
[data-theme="light"] .border-slate-700 { border-color: rgba(203,213,225,0.5) !important; }
[data-theme="light"] .bg-slate-800 { background: #e2e8f0 !important; }

/* Light theme: code editor (textarea) */
[data-theme="light"] .code-input-theme,
[data-theme="light"] textarea#codeInput {
    background: #f8fafc !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}
[data-theme="light"] .code-input-theme::placeholder,
[data-theme="light"] textarea#codeInput::placeholder {
    color: #94a3b8 !important;
}

/* Light theme: rewritten code output (pre/code) */
[data-theme="light"] .code-output-theme,
[data-theme="light"] #rewriteOutput,
[data-theme="light"] #rewriteOutput code {
    background: #f1f5f9 !important;
    color: #1e293b !important;
}
[data-theme="light"] #rewriteOutput .hljs {
    background: #f1f5f9 !important;
}

/* Light theme: markdown review content and code blocks */
[data-theme="light"] .markdown-theme,
[data-theme="light"] .markdown-content {
    color: #334155 !important;
}
[data-theme="light"] .markdown-content code {
    background: rgba(6, 182, 212, 0.12) !important;
    color: #0e7490 !important;
}
[data-theme="light"] .markdown-content pre {
    background: #e2e8f0 !important;
    border: 1px solid #cbd5e1 !important;
}
[data-theme="light"] .markdown-content pre code {
    background: none !important;
    color: #1e293b !important;
}

/* Light theme: review improvements & explanation */
[data-theme="light"] .review-improvements-section .improvement-card {
    background: rgba(226, 232, 240, 0.8) !important;
    border-color: rgba(148, 163, 184, 0.5) !important;
}
[data-theme="light"] .review-improvements-section .improvement-card .check-icon { color: #059669; }
[data-theme="light"] #reviewExplanation {
    background: #f1f5f9 !important;
    color: #475569 !important;
    border-color: #cbd5e1 !important;
}

/* Light theme: review/rewrite empty state backgrounds */
[data-theme="light"] #reviewEmpty,
[data-theme="light"] #rewriteEmpty {
    background: #f8fafc !important;
    color: #64748b !important;
}

/* Chat FAB - safe area for notched devices */
.chat-fab-safe {
    bottom: max(1.5rem, env(safe-area-inset-bottom));
    right: max(1.5rem, env(safe-area-inset-right));
}
/* Chat slide-out panel */
.chat-panel.open { transform: translateX(0); }
#chatOverlay.open { opacity: 1; pointer-events: auto; }
/* Chat message bubbles */
.chat-msg-user {
    background: #0891b2; color: #0f172a; border-radius: 1rem; border-bottom-right-radius: 0.25rem;
    padding: 0.5rem 1rem; font-size: 0.875rem; max-width: 85%; margin-left: auto;
}
.chat-msg-ai {
    background: rgba(30, 41, 59, 0.8); color: #e2e8f0; border-radius: 1rem; border-bottom-left-radius: 0.25rem;
    padding: 0.5rem 1rem; font-size: 0.875rem; max-width: 85%; margin-right: auto;
    border: 1px solid rgba(71, 85, 105, 0.5);
}
[data-theme="light"] .chat-msg-user { background: #0891b2; color: #fff; }
[data-theme="light"] .chat-msg-ai { background: #e2e8f0; color: #1e293b; border-color: #cbd5e1; }
[data-theme="light"] #chatInput {
    background: #f8fafc !important; color: #0f172a !important; border-color: #cbd5e1 !important;
}
[data-theme="light"] #chatInput::placeholder { color: #94a3b8 !important; }
/* Loading overlay active state */
#loadingOverlay.active { opacity: 1 !important; visibility: visible !important; }

/* Glassmorphism & soft shadows */
.glass { background: rgba(15, 23, 42, 0.7); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.shadow-soft { box-shadow: 0 4px 24px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06); }

/* Button and card animations */
.btn-hover { transition: transform 0.2s ease, box-shadow 0.2s ease; }
.btn-hover:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(6,182,212,0.2); }
.card-hover { transition: transform 0.25s ease, box-shadow 0.25s ease; }
.card-hover:hover { transform: translateY(-1px); box-shadow: 0 12px 28px rgba(0,0,0,0.15); }

/* Syntax highlighting overrides */
.hljs {
    background: transparent !important;
    padding: 0 !important;
}

/* Markdown content styling */
.markdown-content h3 {
    font-weight: 600;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

.markdown-content ul {
    list-style: disc;
    margin-left: 1.5rem;
    margin-bottom: 0.75rem;
}

.markdown-content li {
    margin-bottom: 0.25rem;
}

.markdown-content code {
    background: rgba(34, 211, 238, 0.15);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
}

.markdown-content pre {
    background: #0f172a;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin: 0.75rem 0;
}

.markdown-content pre code {
    background: none;
    padding: 0;
}

/* Severity indicators for code review */
.severity-critical {
    border-left: 4px solid #f43f5e;
}

.severity-high {
    border-left: 4px solid #f59e0b;
}

.severity-medium {
    border-left: 4px solid #22d3ee;
}

.severity-low {
    border-left: 4px solid #10b981;
}

/* Key Improvements & Explanation section */
.review-improvements-section .improvement-card {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(100, 116, 139, 0.3);
    border-radius: 0.5rem;
}

.review-improvements-section .improvement-card .check-icon {
    color: #10b981;
    flex-shrink: 0;
    margin-top: 0.125rem;
}

/* ========== 3D AUTH (Login / Sign Up flip card) ========== */
/* Semi-transparent so bubble background shows through on login/signup */
#loginScreen.auth-3d-screen {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.72) 0%, rgba(139, 92, 246, 0.72) 50%, rgba(217, 70, 239, 0.72) 100%);
}

#loginScreen .auth-container-3d {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px;
    perspective: 1200px;
    width: 100%;
}
@media (min-width: 640px) {
    #loginScreen .auth-container-3d { padding: 20px; }
}

#loginScreen .auth-container-3d *,
#loginScreen .auth-container-3d *::before,
#loginScreen .auth-container-3d *::after {
    box-sizing: border-box;
}

#loginScreen .auth-3d-form-wrapper {
    position: relative;
    width: 100%;
    max-width: 420px;
    min-height: min(680px, 85vh);
    perspective: 1200px;
    transform-style: preserve-3d;
}

#loginScreen .auth-3d-form-container {
    position: relative;
    width: 100%;
    min-height: min(680px, 85vh);
    transform-style: preserve-3d;
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

#loginScreen .auth-3d-form-container.flipped {
    transform: rotateY(180deg);
}

#loginScreen .auth-3d-form-side {
    position: absolute;
    width: 100%;
    min-height: min(680px, 85vh);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 24px;
    padding: 32px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.03), 0 2px 4px rgba(0, 0, 0, 0.04), 0 12px 24px rgba(0, 0, 0, 0.08), 0 24px 48px rgba(0, 0, 0, 0.12), 0 48px 96px rgba(0, 0, 0, 0.08);
    transform-style: preserve-3d;
}

#loginScreen .auth-3d-signup {
    transform: rotateY(0deg) translateZ(0);
}

#loginScreen .auth-3d-login {
    transform: rotateY(180deg) translateZ(0);
}

#loginScreen .auth-3d-form-header {
    text-align: center;
    margin-bottom: 24px;
}

#loginScreen .auth-3d-form-title {
    font-size: 28px;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 8px 0;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

#loginScreen .auth-3d-form-subtitle {
    color: #64748b;
    font-size: 14px;
    margin: 0;
}

#loginScreen .auth-3d-form-group {
    margin-bottom: 16px;
}

#loginScreen .auth-3d-form-label {
    display: block;
    color: #334155;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
}

#loginScreen .auth-3d-form-input {
    width: 100%;
    padding: 14px 18px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 16px;
    color: #1e293b;
    background: rgba(255, 255, 255, 0.8);
    transition: all 0.3s ease;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

#loginScreen .auth-3d-form-input:focus {
    border-color: #6366f1;
    background: rgba(255, 255, 255, 1);
    transform: translateY(-2px) translateZ(2px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.15);
}

#loginScreen .auth-3d-form-input::placeholder {
    color: #a0aec0;
}

#loginScreen .auth-3d-password-group {
    position: relative;
}

#loginScreen .auth-3d-password-toggle {
    position: absolute;
    right: 10px;
    top: 67%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #a0aec0;
    cursor: pointer;
    padding: 4px;
    transition: color 0.2s;
}

#loginScreen .auth-3d-password-toggle:hover {
    color: #667eea;
}

#loginScreen .auth-3d-password-icon {
    width: 20px;
    height: 20px;
}

#loginScreen .auth-3d-form-options {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    font-size: 14px;
}

#loginScreen .auth-3d-checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

#loginScreen .auth-3d-forgot-link {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

#loginScreen .auth-3d-forgot-link:hover {
    color: #764ba2;
}

#loginScreen .auth-3d-submit-btn {
    width: 100%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 16px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

#loginScreen .auth-3d-submit-btn:hover {
    transform: translateY(-2px) translateZ(4px);
    box-shadow: 0 12px 35px rgba(99, 102, 241, 0.3);
}

#loginScreen .auth-3d-submit-btn:active {
    transform: translateY(0) translateZ(0);
}

#loginScreen .auth-3d-form-divider {
    text-align: center;
    margin: 16px 0;
    position: relative;
    color: #94a3b8;
    font-size: 14px;
}

#loginScreen .auth-3d-form-divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #e2e8f0;
    z-index: 1;
}

#loginScreen .auth-3d-form-divider span {
    background: rgba(255, 255, 255, 0.95);
    padding: 0 16px;
    position: relative;
    z-index: 2;
}

#loginScreen .auth-3d-social-login {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

#loginScreen .auth-3d-social-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.8);
    color: #475569;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s ease;
}

#loginScreen .auth-3d-social-btn:hover {
    border-color: #6366f1;
    background: rgba(255, 255, 255, 1);
    transform: translateY(-2px) translateZ(2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

#loginScreen .auth-3d-social-icon {
    width: 20px;
    height: 20px;
}

#loginScreen .auth-3d-form-switch {
    text-align: center;
    margin-top: 16px;
}

#loginScreen .auth-3d-switch-text {
    color: #64748b;
    font-size: 14px;
    margin: 0;
}

#loginScreen .auth-3d-switch-link {
    color: #6366f1;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s;
}

#loginScreen .auth-3d-switch-link:hover {
    color: #8b5cf6;
}

#loginScreen .auth-3d-terms-text {
    color: #64748b;
    font-size: 12px;
    line-height: 1.4;
    margin-top: 8px;
    margin-bottom: 16px;
}

#loginScreen .auth-3d-terms-link {
    color: #6366f1;
    text-decoration: none;
}

#loginScreen .auth-3d-terms-link:hover {
    text-decoration: underline;
}

#loginScreen .auth-3d-demo-box {
    margin-top: 16px;
    padding: 16px;
    border-radius: 12px;
    background: rgba(102, 126, 234, 0.1);
    border: 1px solid rgba(102, 126, 234, 0.3);
}

#loginScreen .auth-3d-demo-box .auth-3d-form-label {
    margin-bottom: 8px;
}

#loginScreen .auth-3d-demo-btn {
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    background: linear-gradient(135deg, #06b6d4, #059669);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

#loginScreen .auth-3d-demo-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(6, 182, 212, 0.3);
}

/* ========== BUBBLE / PARTICLE BACKGROUND (AI theme) ========== */
/* Full-screen fixed layer; z-index 0 so it sits above body bg but below main content. */
.bubble-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    isolation: isolate;
}

/* Login/signup, verify screens and main content above bubbles */
#loginScreen,
#verifyScreen,
#firebaseVerifyScreen,
#appContent {
    position: relative;
    z-index: 1;
}

/* ========== FIREBASE EMAIL VERIFICATION (link-based) ========== */
/* Shown when user is signed in but email is not verified. Responsive and accessible. */
.firebase-verify-screen {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.72) 0%, rgba(139, 92, 246, 0.72) 50%, rgba(217, 70, 239, 0.72) 100%);
}

.firebase-verify-card {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    transition: box-shadow 0.2s ease;
}

.firebase-verify-card button:focus-visible {
    outline: 2px solid #22d3ee;
    outline-offset: 2px;
}

@media (max-width: 480px) {
    .firebase-verify-screen .text-2xl { font-size: 1.35rem; }
    .firebase-verify-card { padding: 1rem 1.25rem !important; }
}

/* Banner shown when user lands back from verification link */
.email-verified-banner {
    background: linear-gradient(90deg, rgba(16, 185, 129, 0.2), rgba(6, 182, 212, 0.2));
    border-bottom: 1px solid rgba(16, 185, 129, 0.4);
    color: #10b981;
    padding: 0.5rem 1rem;
    text-align: center;
    font-size: 0.875rem;
    font-weight: 500;
}

.email-verified-banner.hidden { display: none; }

/* Individual bubble: circle with soft glow. GPU-friendly (transform + opacity only where possible). */
.bubble {
    position: absolute;
    border-radius: 50%;
    opacity: 0.45;
    /* Animation: gentle float; duration/delay set by JS for variety */
    animation: bubble-float 18s ease-in-out infinite;
}

/* Soft cyan glow - AI accent */
.bubble--cyan {
    background: radial-gradient(circle at 30% 30%, rgba(34, 211, 238, 0.5), rgba(6, 182, 212, 0.2));
    box-shadow: 0 0 40px 20px rgba(34, 211, 238, 0.15);
}

/* Soft blue */
.bubble--blue {
    background: radial-gradient(circle at 30% 30%, rgba(59, 130, 246, 0.45), rgba(37, 99, 235, 0.2));
    box-shadow: 0 0 40px 20px rgba(59, 130, 246, 0.12);
}

/* Soft purple */
.bubble--purple {
    background: radial-gradient(circle at 30% 30%, rgba(139, 92, 246, 0.4), rgba(124, 58, 237, 0.2));
    box-shadow: 0 0 40px 20px rgba(139, 92, 246, 0.12);
}

/* Float keyframes: subtle movement so bubbles feel organic. Transform-only for performance. */
@keyframes bubble-float {
    0%, 100% {
        transform: translate(0, 0) scale(1);
    }
    25% {
        transform: translate(20px, -25px) scale(1.03);
    }
    50% {
        transform: translate(-15px, 20px) scale(0.97);
    }
    75% {
        transform: translate(15px, 15px) scale(1.02);
    }
}

/* Respect user motion preference: reduce or disable animation on low-motion devices */
@media (prefers-reduced-motion: reduce) {
    .bubble {
        animation: none;
        opacity: 0.2;
    }
}

/* Optional: slightly fewer/smaller bubbles on very small viewports (customize in JS too) */
@media (max-width: 640px) {
    .bubble {
        opacity: 0.28;
    }
}

/* ========== WELCOME MODAL (post-signup, once) ========== */
/* Overlay: centered, behind loading overlay. Hidden by default. */
.welcome-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(10, 14, 23, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0.35s ease;
}

.welcome-modal-overlay.is-visible {
    opacity: 1;
    visibility: visible;
}

/* Card: glassmorphism + glow, 3D tilt container, floating animation */
.welcome-modal-card {
    position: relative;
    width: 100%;
    max-width: 420px;
    padding: 2rem 2rem 2.5rem;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(34, 211, 238, 0.2);
    border-radius: 24px;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.05),
        0 25px 50px rgba(0, 0, 0, 0.3),
        0 0 60px 20px rgba(34, 211, 238, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    transform-style: preserve-3d;
    transform: scale(0.85) translateZ(0);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.35s ease;
    animation: welcome-float 6s ease-in-out infinite;
}

.welcome-modal-overlay.is-visible .welcome-modal-card {
    transform: scale(1) translateZ(0);
    opacity: 1;
}

/* Subtle floating motion for the card (keeps scale 1 when visible) */
@keyframes welcome-float {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-8px) scale(1); }
}

/* Close button */
.welcome-modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    color: #94a3b8;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
}

.welcome-modal-close:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #e2e8f0;
}

.welcome-modal-content {
    text-align: center;
}

.welcome-modal-emoji {
    font-size: 3rem;
    display: block;
    margin-bottom: 0.75rem;
}

.welcome-modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #f1f5f9;
    margin: 0 0 0.5rem 0;
    background: linear-gradient(135deg, #67e8f9, #22d3ee);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-modal-subtitle {
    font-size: 0.9375rem;
    color: #94a3b8;
    margin: 0;
    line-height: 1.5;
}

@media (max-width: 640px) {
    .welcome-modal-card {
        padding: 1.5rem 1.25rem 2rem;
    }
    .welcome-modal-title {
        font-size: 1.25rem;
    }
    .welcome-modal-subtitle {
        font-size: 0.875rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .welcome-modal-card {
        animation: none;
    }
}
