/* ==========================================================================
   Component: Legal Modal (Refactored Clean v10.0)
   ========================================================================== */

/* --- 1. Global Overflow Lock --- */
body.no-scroll {
    overflow: hidden !important;
    padding-right: 0 !important;
    /* Prevent layout shift */
}

/* --- 2. Modal Overlay (Fixed Wrapper) --- */
.lw-modal-overlay.glass-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10000;
    /* High Z-Index */

    background: rgba(0, 0, 0, 0.6);
    /* Dim background */
    backdrop-filter: blur(8px);
    /* Glass effect */

    display: flex;
    align-items: center;
    justify-content: center;

    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;

    /* PREVENT global touches */
    touch-action: auto !important;
    /* ALLOW touch events */
}

.lw-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* --- 3. Modal Content Box (The Window) --- */
.legal-modal-content {
    position: relative;
    width: 90%;
    max-width: 900px;
    height: 85vh;
    /* Standard fixed height */
    max-height: 900px;

    background: #0a0a0f;
    /* Fallback */
    background: var(--lw-panel-bg, rgba(15, 15, 20, 0.95));
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    box-shadow: 0 50px 100px -20px rgba(0, 0, 0, 0.8);

    display: flex;
    flex-direction: column;
    /* Vertical Flex Layout */
    overflow: hidden;
    /* Hide anything spilling out of the box rounded corners */
}

/* Light Mode Background */
html.light-mode .legal-modal-content {
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    border-color: rgba(0, 0, 0, 0.1);
}

/* --- 4. Close Button --- */
.lw-modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.lw-modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

html.light-mode .lw-modal-close {
    color: #333;
    background: rgba(0, 0, 0, 0.05);
}

html.light-mode .lw-modal-close:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* --- 5. Modal Body (THE SCROLLABLE AREA) --- */
.lw-modal-body {
    flex: 1;
    /* Take remaining height */
    overflow-y: scroll !important;
    /* Always enable scrolling */
    overflow-x: hidden;
    position: relative;
    padding: 0;
    /* Reset */

    /* Scroll Isolation */
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    /* iOS Momentum */
    touch-action: pan-y;
    /* Vertical scroll only */

    /* Scrollbar Styling: HIDDEN */
    scrollbar-width: none !important;
    /* Firefox */
    -ms-overflow-style: none !important;
    /* IE */
}

/* Scrollbar Webkit: HIDDEN */
.lw-modal-body::-webkit-scrollbar {
    width: 0 !important;
    height: 0 !important;
    display: none !important;
    background: transparent !important;
}

.lw-modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.lw-modal-body::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

.lw-modal-body::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.6);
}

/* Light Mode Scrollbar */
html.light-mode .lw-modal-body {
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

html.light-mode .lw-modal-body::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
}

html.light-mode .lw-modal-body::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.4);
}

/* --- 6. Content Injection Overrides (Crucial Fixes) --- */
/* Target the injected container specifically inside the modal */
#legal-modal-body .legal-container {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: auto !important;

    /* V10 FIX: Ensure no overflow restrictions on the child */
    overflow: visible !important;

    /* KILL THE GLOBAL MARGIN that causes layout breakage */
    margin: 0 !important;

    /* Text Alignment and Padding */
    text-align: left !important;
    /* Force Left */
    /* Add internal padding for aesthetics */
    padding: 60px 40px 100px 40px !important;

    /* Remove transparency effects if double-applied */
    background: transparent !important;
    backdrop-filter: none !important;
    border: none !important;
    box-shadow: none !important;
}

/* Typography inside modal */
#legal-modal-body h1,
#legal-modal-body h2,
#legal-modal-body h3,
#legal-modal-body p,
#legal-modal-body li {
    text-align: left !important;
    margin-left: 0 !important;
}

/* Typography inside modal */
#legal-modal-body h1 {
    margin-top: 0;
    font-size: 2rem;
    line-height: 1.2;
    padding-right: 40px;
    /* Space for close button */
    margin-bottom: 2rem !important;
    /* Spacing after title */
}

#legal-modal-body h2 {
    font-size: 1.4rem;
    margin-top: 2.5rem !important;
    /* Space above section */
    margin-bottom: 1rem !important;
    /* Space below section title */
    color: #fff;
    opacity: 1;
}

#legal-modal-body p,
#legal-modal-body li {
    font-size: 1rem;
    line-height: 1.6;
    opacity: 0.8;
    margin-bottom: 1rem !important;
}

/* --- 7. Light Mode Text Overrides (Fix Visibility) --- */
/* Target BOTH html and body classes to be 100% sure */
html.light-mode #legal-modal-body,
body.light-mode #legal-modal-body,
html.light-mode #legal-modal-body *,
body.light-mode #legal-modal-body * {
    color: #111 !important;
}

/* Explicit overrides if needed */
html.light-mode #legal-modal-body h1,
body.light-mode #legal-modal-body h1 {
    color: #000 !important;
}

html.light-mode #legal-modal-body p,
body.light-mode #legal-modal-body p {
    color: #333 !important;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .legal-modal-content {
        width: 100%;
        height: 100%;
        /* Fullscreen on mobile */
        max-height: 100%;
        border-radius: 0;
        border: none;
    }

    #legal-modal-body .legal-container {
        padding: 80px 20px 120px 20px !important;
    }
}