/* ============================================================================
 * DivestWorld — Legal Pages Polish (v2)
 * Premium look matching Razorpay / Stripe legal page aesthetic.
 * Fixes hero visibility issue from v1; adds elevated content card,
 * refined TOC, tighter callouts, better typography rhythm.
 * ========================================================================== */

:root {
    --legal-accent: #1e3a8a;
    --legal-accent-2: #3b5fd9;
    --legal-accent-soft: #5b8dee;
    --legal-accent-bg: #eff4ff;
    --legal-accent-bg-2: #f5f8ff;
    --legal-text: #0f172a;
    --legal-text-soft: #475569;
    --legal-text-mute: #64748b;
    --legal-border: #e2e8f0;
    --legal-border-soft: #eef2f7;
    --legal-bg: #ffffff;
    --legal-page-bg: #f8fafc;
    --legal-warn-bg: #fff8f1;
    --legal-warn-border: #fb923c;
    --legal-warn-text: #9a3412;
    --legal-warn-strong: #7c2d12;
    --legal-radius: 14px;
    --legal-radius-sm: 8px;
    --legal-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .04);
    --legal-shadow-card: 0 1px 3px rgba(15, 23, 42, .04), 0 8px 32px rgba(15, 23, 42, .06);
    --legal-shadow-hover: 0 4px 12px rgba(15, 23, 42, .08), 0 12px 32px rgba(15, 23, 42, .08);
}

/* ── Override page background to soft slate so the content card pops ────── */
body {
    background: var(--legal-page-bg);
}

/* ── Reading progress bar (fixed top) ───────────────────────────────────── */
.legal-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0%;
    background: linear-gradient(90deg, var(--legal-accent), var(--legal-accent-soft));
    z-index: 9999;
    transition: width .15s ease-out;
    box-shadow: 0 0 8px rgba(91, 141, 238, .35);
    pointer-events: none;
}

/* ── Hero header — DON'T animate or reposition; just refine the existing
   site styling so the h1 / breadcrumb / date stay visible. ───────────── */
.page-header-section { position: relative; }
.page-header-section .hero-content h1,
.page-header-section .hero-content p,
.page-header-section .hero-content .breadcrumb {
    /* Belt-and-braces: if any earlier rule hid these, force them visible. */
    opacity: 1 !important;
    transform: none !important;
    visibility: visible !important;
}

/* ── Pull the legal section close to the hero to kill empty gap ────────── */
.legal-page {
    padding-top: 40px;
    padding-bottom: 96px;
    position: relative;
    z-index: 1;
}
.legal-page .container {
    max-width: 1200px;
}

/* ── Two-column layout: TOC + content card ─────────────────────────────── */
.legal-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 40px;
    align-items: start;
}

/* ── TOC sidebar (sticky) ──────────────────────────────────────────────── */
.legal-toc {
    position: sticky;
    top: 24px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    padding: 22px 14px 22px 18px;
    background: var(--legal-bg);
    border: 1px solid var(--legal-border);
    border-radius: var(--legal-radius);
    font-size: 13.5px;
    box-shadow: var(--legal-shadow);
    scrollbar-width: thin;
    scrollbar-color: var(--legal-border) transparent;
}
.legal-toc::-webkit-scrollbar { width: 6px; }
.legal-toc::-webkit-scrollbar-thumb { background: var(--legal-border); border-radius: 3px; }
.legal-toc__title {
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: .1em;
    color: var(--legal-text-mute);
    font-weight: 600;
    margin: 0 0 14px 4px;
    padding: 0;
}
.legal-toc__list { list-style: none; margin: 0; padding: 0; }
.legal-toc__item { margin: 0; padding: 0; position: relative; }
.legal-toc__link {
    display: block;
    padding: 8px 12px 8px 14px;
    color: var(--legal-text-soft);
    text-decoration: none;
    border-radius: 6px;
    line-height: 1.45;
    font-weight: 500;
    transition: color .18s ease, background .18s ease;
    position: relative;
}
.legal-toc__link::before {
    content: "";
    position: absolute;
    left: -2px;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    height: 0;
    background: var(--legal-accent);
    border-radius: 1px;
    transition: height .25s ease;
}
.legal-toc__link:hover {
    background: var(--legal-accent-bg-2);
    color: var(--legal-accent);
}
.legal-toc__item--active .legal-toc__link {
    background: var(--legal-accent-bg);
    color: var(--legal-accent);
    font-weight: 600;
}
.legal-toc__item--active .legal-toc__link::before {
    height: 22px;
}

/* ── Mobile TOC toggle button ───────────────────────────────────────────── */
.legal-toc-toggle {
    display: none;
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: var(--legal-accent);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(30, 58, 138, .35);
    z-index: 998;
    transition: transform .2s ease, background .2s ease;
}
.legal-toc-toggle:hover { transform: scale(1.05); }

/* ── Content card — elevated, generous padding, breathing room ─────────── */
.legal-content {
    background: var(--legal-bg);
    padding: 44px 56px 48px;
    border-radius: var(--legal-radius);
    border: 1px solid var(--legal-border-soft);
    box-shadow: var(--legal-shadow-card);
    font-size: 15.5px;
    line-height: 1.78;
    color: var(--legal-text);
    letter-spacing: -.005em;
}
.legal-content > p:first-of-type:not(.legal-callout) {
    font-size: 16.5px;
    line-height: 1.7;
    color: var(--legal-text);
    margin-top: 0;
}

/* Paragraphs */
.legal-content p {
    margin: 0 0 18px;
}

/* Section headings */
.legal-content h4 {
    position: relative;
    margin: 44px 0 16px;
    padding: 0;
    font-size: 19px;
    font-weight: 650;
    color: var(--legal-accent);
    letter-spacing: -.012em;
    line-height: 1.35;
    scroll-margin-top: 24px;
}
/* Subtle horizontal divider above each section (except the first) */
.legal-content h4:not(:first-child)::after {
    content: "";
    position: absolute;
    left: 0;
    top: -22px;
    width: 36px;
    height: 2px;
    background: linear-gradient(90deg, var(--legal-accent), transparent);
    border-radius: 2px;
}
/* Hover-revealed permalink */
.legal-content h4 .legal-anchor {
    margin-left: 8px;
    color: var(--legal-accent-soft);
    opacity: 0;
    text-decoration: none;
    font-weight: 400;
    transition: opacity .18s ease;
    font-size: 15px;
}
.legal-content h4:hover .legal-anchor { opacity: .55; }
.legal-content h4 .legal-anchor:hover { opacity: 1; }

/* Lists */
.legal-content ul {
    margin: 0 0 22px;
    padding-left: 22px;
    list-style: none;
}
.legal-content li {
    position: relative;
    margin: 8px 0;
    padding-left: 4px;
}
.legal-content li::before {
    content: "";
    position: absolute;
    left: -16px;
    top: 12px;
    width: 5px;
    height: 5px;
    background: var(--legal-accent-soft);
    border-radius: 50%;
}

.legal-content strong {
    color: var(--legal-text);
    font-weight: 650;
}

.legal-content a {
    color: var(--legal-accent);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px solid rgba(30, 58, 138, .25);
    transition: border-color .18s ease, color .18s ease;
}
.legal-content a:hover {
    border-bottom-color: var(--legal-accent);
    color: var(--legal-accent-2);
}

/* ── "Important" callout (Risk Disclosure opener) ───────────────────────── */
.legal-content .legal-callout {
    background: var(--legal-warn-bg);
    border: 1px solid rgba(251, 146, 60, .3);
    border-left: 4px solid var(--legal-warn-border);
    color: var(--legal-warn-text);
    padding: 18px 22px;
    border-radius: var(--legal-radius-sm);
    margin: 0 0 28px;
    font-size: 15.5px;
    line-height: 1.7;
}
.legal-content .legal-callout strong {
    color: var(--legal-warn-strong);
    font-weight: 650;
}

/* ── Grievance Officer card ─────────────────────────────────────────────── */
.legal-officer-card {
    background: linear-gradient(135deg, var(--legal-accent-bg) 0%, var(--legal-accent-bg-2) 100%);
    border: 1px solid var(--legal-border-soft);
    border-radius: var(--legal-radius-sm);
    padding: 20px 24px;
    margin: 8px 0 20px;
    box-shadow: 0 1px 3px rgba(30, 58, 138, .04);
}
.legal-officer-card ul,
.legal-officer-card .legal-officer-card-inner {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 10px 28px;
}
.legal-officer-card li {
    margin: 0;
    padding-left: 0;
    line-height: 1.55;
}
.legal-officer-card li::before { display: none; }
.legal-officer-card li strong {
    display: inline-block;
    min-width: 90px;
    color: var(--legal-text-soft);
    font-weight: 550;
}

/* ── Smooth scroll-reveal animation ─────────────────────────────────────── */
.legal-content > p,
.legal-content > ul,
.legal-content > h4,
.legal-content > .legal-officer-card,
.legal-content > .legal-callout {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .45s ease, transform .45s ease;
}
.legal-content .is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* ── Floating "back to top" button ──────────────────────────────────────── */
.legal-back-top {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 44px;
    height: 44px;
    border: 1px solid var(--legal-border);
    border-radius: 50%;
    background: var(--legal-bg);
    color: var(--legal-accent);
    font-size: 16px;
    cursor: pointer;
    box-shadow: var(--legal-shadow-hover);
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity .25s ease, transform .25s ease, background .2s ease, color .2s ease, visibility 0s .25s;
    z-index: 998;
    line-height: 1;
}
.legal-back-top.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition: opacity .25s ease, transform .25s ease, background .2s ease, color .2s ease;
}
.legal-back-top:hover {
    background: var(--legal-accent);
    color: #fff;
    transform: translateY(-3px);
    border-color: var(--legal-accent);
}

html { scroll-behavior: smooth; }

/* ── Tablet (< 1100px): collapse layout ─────────────────────────────────── */
@media (max-width: 1099px) {
    .legal-content { padding: 36px 40px 40px; }
    .legal-layout { gap: 28px; }
    .legal-toc { padding: 18px 12px 18px 14px; font-size: 13px; }
}

/* ── Mobile (< 768px): drawer-style TOC ─────────────────────────────────── */
@media (max-width: 767px) {
    .legal-page { margin-top: 0; padding-top: 32px; padding-bottom: 64px; }
    .legal-layout { grid-template-columns: 1fr; gap: 0; }

    .legal-toc {
        position: fixed;
        top: 0; right: 0; bottom: 0;
        height: 100vh;
        max-height: 100vh;
        width: min(320px, 88vw);
        border-radius: 0;
        border: none;
        border-left: 1px solid var(--legal-border);
        box-shadow: -8px 0 32px rgba(15, 23, 42, .15);
        transform: translateX(100%);
        transition: transform .3s ease;
        z-index: 999;
        padding-top: 64px;
    }
    .legal-toc.is-open { transform: translateX(0); }

    .legal-toc-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .legal-toc-toggle.is-open { background: #ef4444; }

    .legal-content {
        padding: 28px 22px 32px;
        font-size: 15px;
        border-radius: var(--legal-radius-sm);
    }
    .legal-content h4 { font-size: 17.5px; margin-top: 36px; }
    .legal-content h4:not(:first-child)::after { width: 28px; }
    .legal-content > p:first-of-type:not(.legal-callout) { font-size: 15.5px; }
    .legal-officer-card { padding: 16px 18px; }
    .legal-officer-card ul { grid-template-columns: 1fr; gap: 6px; }
    .legal-callout { padding: 14px 16px; }
}

/* ── Print: clean output ────────────────────────────────────────────────── */
@media print {
    body { background: #fff !important; }
    .legal-progress, .legal-toc, .legal-toc-toggle, .legal-back-top,
    .page-header-section .breadcrumb { display: none !important; }
    .legal-page { margin: 0 !important; padding: 0 !important; }
    .legal-layout { grid-template-columns: 1fr !important; gap: 0 !important; }
    .legal-content {
        font-size: 11pt;
        line-height: 1.5;
        color: #000;
        padding: 0;
        background: transparent;
        border: none;
        box-shadow: none;
    }
    .legal-content h4 {
        color: #000;
        break-after: avoid;
        page-break-after: avoid;
    }
    .legal-content h4:not(:first-child)::after { display: none; }
    .legal-content > * { opacity: 1 !important; transform: none !important; }
    .legal-content a { color: #000; text-decoration: underline; border: none; }
    .legal-callout { background: #fff !important; border: 1.5px solid #999 !important; color: #000 !important; }
    .legal-callout strong { color: #000 !important; }
    .legal-officer-card { background: #fff !important; border: 1px solid #999 !important; }
    html { scroll-behavior: auto; }
}

/* ── Respect reduced-motion preference ──────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    .legal-content > * { opacity: 1 !important; transform: none !important; transition: none !important; }
    .legal-progress, .legal-back-top, .legal-toc-toggle, .legal-toc__link {
        transition: none !important;
    }
}
