/*
 * Legal pages — Terms of Service and Privacy Policy
 * (resources/views/frontend/pages/legal/layout.blade.php and the two pages using it).
 *
 * Hand-written: the public site's Tailwind bundle is purged from an old build. Tokens match
 * public/css/how-it-works.css so these pages read as part of the same site.
 */

.legal {
    --legal-ink: #0f172a;
    --legal-ink-2: #334155;
    --legal-muted: #475569;
    --legal-faint: #64748b;
    --legal-line: #e2e8f0;
    --legal-soft: #f8fafc;
    --legal-brand: #2563eb;
    --legal-brand-ink: #1d4ed8;
    --legal-brand-soft: #eff6ff;
    --legal-ease: cubic-bezier(0.16, 1, 0.3, 1);
    --legal-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 28px -14px rgba(15, 23, 42, 0.18);

    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    color: var(--legal-ink);
    background: #fff;
    overflow-x: clip;
}

.legal *,
.legal *::before,
.legal *::after {
    box-sizing: border-box;
}

.legal-wrap {
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 1rem;
}

@media (min-width: 768px) {
    .legal-wrap {
        padding: 0 1.5rem;
    }
}

/* ── Hero ─────────────────────────────────────────────────────────────── */

.legal-hero {
    padding: 128px 0 40px;
    text-align: center;
    background:
        radial-gradient(55% 80% at 12% 0%, rgba(37, 99, 235, 0.13), rgba(37, 99, 235, 0) 60%),
        radial-gradient(45% 70% at 92% 8%, rgba(13, 148, 136, 0.1), rgba(13, 148, 136, 0) 60%),
        linear-gradient(180deg, #f5f9ff 0%, #ffffff 100%);
}

.legal-hero .legal-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.legal-pill {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    border: 1px solid #bfdbfe;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.7);
    color: var(--legal-brand-ink);
    font-size: var(--type-caption);
    font-weight: 600;
}

.legal-hero__title {
    margin: 16px 0 0;
    font-family: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
    font-size: var(--type-title);
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.03em;
    text-wrap: balance;
}

.legal-hero__lead {
    max-width: 40rem;
    margin: 16px 0 0;
    color: var(--legal-muted);
    font-size: var(--type-lead);
    line-height: 1.65;
    text-wrap: pretty;
}

.legal-hero__meta {
    margin: 12px 0 0;
    color: var(--legal-faint);
    font-size: var(--type-small);
}

/* Terms ⇄ Privacy */
.legal-switch {
    display: inline-flex;
    gap: 4px;
    margin-top: 28px;
    padding: 4px;
    border: 1px solid var(--legal-line);
    border-radius: var(--radius-full);
    background: #fff;
    box-shadow: var(--legal-shadow);
    max-width: 100%;
}

.legal-switch a {
    padding: 9px 18px;
    border-radius: var(--radius-full);
    color: var(--legal-muted);
    font-size: var(--type-small);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.2s var(--legal-ease), color 0.2s var(--legal-ease);
}

.legal-switch a:hover {
    color: var(--legal-ink);
    background: var(--legal-soft);
}

.legal-switch a[aria-current='page'] {
    background: var(--legal-brand);
    color: #fff;
}

@media (max-width: 380px) {
    .legal-switch a {
        padding: 9px 12px;
        font-size: var(--type-caption);
    }
}

/* ── Body: contents list + article ────────────────────────────────────── */

.legal-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
    padding-top: 32px;
    padding-bottom: 88px;
    counter-reset: legal-toc;
}

@media (min-width: 1024px) {
    .legal-body {
        grid-template-columns: 240px minmax(0, 1fr);
        gap: 56px;
        padding-top: 48px;
    }
}

.legal-toc__list {
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: legal-toc;
}

.legal-toc__list li {
    counter-increment: legal-toc;
}

.legal-toc__list a {
    display: flex;
    gap: 10px;
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    color: var(--legal-muted);
    font-size: var(--type-small);
    line-height: 1.4;
    text-decoration: none;
    transition: background-color 0.2s var(--legal-ease), color 0.2s var(--legal-ease);
}

.legal-toc__list a::before {
    content: counter(legal-toc);
    min-width: 1.25em;
    color: var(--legal-faint);
    font-variant-numeric: tabular-nums;
}

.legal-toc__list a:hover {
    background: var(--legal-soft);
    color: var(--legal-ink);
}

.legal-toc__list a[aria-current='location'] {
    background: var(--legal-brand-soft);
    color: var(--legal-brand-ink);
    font-weight: 600;
}

.legal-toc__list a[aria-current='location']::before {
    color: var(--legal-brand);
}

/* Desktop sidebar */
.legal-toc {
    display: none;
}

@media (min-width: 1024px) {
    .legal-toc {
        display: block;
        position: sticky;
        top: 96px;
        align-self: start;
        max-height: calc(100vh - 120px);
        overflow-y: auto;
    }
}

.legal-toc__label {
    margin: 0 0 8px;
    padding: 0 12px;
    color: var(--legal-faint);
    font-size: var(--type-micro);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* Phone / tablet dropdown */
.legal-toc-mobile {
    max-width: 46rem;
    border: 1px solid var(--legal-line);
    border-radius: var(--radius-md);
    background: #fff;
}

@media (min-width: 1024px) {
    .legal-toc-mobile {
        display: none;
    }
}

.legal-toc-mobile summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    font-size: var(--type-ui);
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}

.legal-toc-mobile summary::-webkit-details-marker {
    display: none;
}

.legal-toc-mobile summary::after {
    content: '';
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--legal-faint);
    border-bottom: 2px solid var(--legal-faint);
    transform: rotate(45deg) translateY(-2px);
    transition: transform 0.2s var(--legal-ease);
}

.legal-toc-mobile[open] summary::after {
    transform: rotate(-135deg) translateY(-2px);
}

.legal-toc-mobile .legal-toc__list {
    padding: 0 6px 10px;
    border-top: 1px solid var(--legal-line);
    padding-top: 8px;
}

/* ── Article ──────────────────────────────────────────────────────────── */

.legal-article {
    min-width: 0;
    max-width: 46rem;
    counter-reset: legal-section;
    color: var(--legal-ink-2);
    font-size: var(--type-body);
    line-height: 1.75;
    overflow-wrap: break-word;
}

.legal-summary {
    margin-bottom: 40px;
    padding: 22px 24px;
    border: 1px solid #dbeafe;
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, #f5f9ff 0%, #ffffff 100%);
}

.legal-summary__title {
    margin: 0 0 10px;
    color: var(--legal-ink);
    font-family: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
    font-size: var(--type-card);
    font-weight: 700;
}

.legal-summary ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.legal-summary li {
    position: relative;
    padding-left: 28px;
    margin-top: 8px;
}

.legal-summary li::before {
    content: '';
    position: absolute;
    left: 2px;
    top: 0.45em;
    width: 16px;
    height: 16px;
    border-radius: var(--radius-full);
    background: var(--legal-brand)
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 12.5 4 4 8-9'/%3E%3C/svg%3E")
        center / 11px no-repeat;
}

.legal-summary__note {
    margin: 14px 0 0;
    color: var(--legal-faint);
    font-size: var(--type-caption);
}

.legal-section {
    counter-increment: legal-section;
    scroll-margin-top: 96px;
    padding-top: 8px;
}

.legal-section + .legal-section {
    margin-top: 36px;
    padding-top: 36px;
    border-top: 1px solid var(--legal-line);
}

.legal-section h2 {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin: 0 0 12px;
    color: var(--legal-ink);
    font-family: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
    font-size: clamp(1.25rem, 1.15rem + 0.4vw, 1.5rem);
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -0.015em;
}

.legal-section h2::before {
    content: counter(legal-section);
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    background: var(--legal-brand-soft);
    color: var(--legal-brand-ink);
    font-family: 'Inter', system-ui, sans-serif;
    font-size: var(--type-small);
    font-weight: 700;
    transform: translateY(-2px);
}

.legal-section h3 {
    margin: 22px 0 6px;
    color: var(--legal-ink);
    font-size: var(--type-body);
    font-weight: 600;
}

.legal-section p {
    margin: 0 0 14px;
}

.legal-section ul {
    margin: 0 0 14px;
    padding-left: 1.25rem;
    /* The site's base styles strip list markers; bring them back for readable lists. */
    list-style: disc;
}

.legal-section li {
    margin-top: 6px;
    padding-left: 4px;
}

.legal-section li::marker {
    color: var(--legal-brand);
}

.legal-section strong {
    color: var(--legal-ink);
    font-weight: 600;
}

.legal-article a {
    color: var(--legal-brand-ink);
    text-decoration: underline;
    text-decoration-color: rgba(37, 99, 235, 0.35);
    text-underline-offset: 3px;
    transition: text-decoration-color 0.2s var(--legal-ease);
}

.legal-article a:hover {
    text-decoration-color: currentColor;
}

/* A highlighted aside within a section — e.g. the role a clause applies to. */
.legal-callout {
    margin: 0 0 16px;
    padding: 14px 16px;
    border-left: 3px solid var(--legal-brand);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--legal-soft);
    font-size: var(--type-ui);
}

.legal-callout p:last-child {
    margin-bottom: 0;
}

/* Two-column "what / why" lists in the privacy policy. */
.legal-table {
    width: 100%;
    margin: 4px 0 18px;
    border: 1px solid var(--legal-line);
    border-radius: var(--radius-md);
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    font-size: var(--type-ui);
    line-height: 1.6;
}

.legal-table th,
.legal-table td {
    padding: 12px 14px;
    text-align: left;
    vertical-align: top;
}

.legal-table th {
    background: var(--legal-soft);
    color: var(--legal-ink);
    font-size: var(--type-caption);
    font-weight: 600;
}

.legal-table tr + tr td,
.legal-table thead + tbody tr td {
    border-top: 1px solid var(--legal-line);
}

.legal-table td:first-child {
    width: 34%;
    color: var(--legal-ink);
    font-weight: 600;
}

/* Phones: stack each row so nothing scrolls sideways. */
@media (max-width: 640px) {
    .legal-table thead {
        display: none;
    }

    .legal-table,
    .legal-table tbody,
    .legal-table tr,
    .legal-table td {
        display: block;
        width: 100%;
    }

    .legal-table td:first-child {
        width: 100%;
        padding-bottom: 2px;
    }

    .legal-table td + td {
        padding-top: 0;
    }

    .legal-table tr + tr td:first-child {
        border-top: 1px solid var(--legal-line);
    }

    .legal-table tbody tr td + td {
        border-top: 0;
    }
}

/* ── Contact card ─────────────────────────────────────────────────────── */

.legal-contact {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-top: 48px;
    padding: 24px;
    border-radius: var(--radius-lg);
    background: var(--legal-ink);
    color: #cbd5e1;
}

@media (min-width: 640px) {
    .legal-contact {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 28px 32px;
    }
}

.legal-contact__title {
    margin: 0 0 6px;
    color: #fff;
    font-family: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
    font-size: var(--type-subsection);
    font-weight: 700;
}

.legal-contact p {
    margin: 0;
    font-size: var(--type-ui);
    line-height: 1.6;
}

.legal-contact a:not(.legal-btn) {
    color: #93c5fd;
}

.legal-contact__address {
    margin-top: 8px !important;
    color: #94a3b8;
    font-size: var(--type-caption) !important;
}

.legal-btn {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    height: 46px;
    padding: 0 22px;
    border-radius: var(--radius-full);
    background: #fff;
    color: var(--legal-ink) !important;
    font-size: var(--type-ui);
    font-weight: 600;
    text-decoration: none !important;
    transition: transform 0.2s var(--legal-ease), background-color 0.2s var(--legal-ease);
}

.legal-btn:hover {
    background: var(--legal-brand-soft);
    transform: translateY(-1px);
}

/* ── Back to top ──────────────────────────────────────────────────────── */

.legal-top {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 30;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--legal-line);
    border-radius: var(--radius-full);
    background: #fff;
    color: var(--legal-ink);
    box-shadow: var(--legal-shadow);
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity 0.25s var(--legal-ease), transform 0.25s var(--legal-ease);
}

.legal-top.is-visible {
    opacity: 1;
    pointer-events: auto;
    transform: none;
}

.legal-top svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ── Focus, motion, print ─────────────────────────────────────────────── */

.legal a:focus-visible,
.legal summary:focus-visible {
    outline: 2px solid var(--legal-brand);
    outline-offset: 2px;
    border-radius: var(--radius-xs);
}

@media (prefers-reduced-motion: reduce) {
    .legal *,
    .legal *::before,
    .legal *::after {
        transition: none !important;
    }
}

@media print {
    .legal-hero {
        padding: 0 0 16px;
        background: none;
    }

    .legal-switch,
    .legal-toc,
    .legal-toc-mobile,
    .legal-top,
    .legal-contact .legal-btn {
        display: none !important;
    }

    .legal-body {
        display: block;
        padding: 0;
    }

    .legal-contact {
        background: none;
        color: inherit;
        border: 1px solid var(--legal-line);
    }

    .legal-contact__title {
        color: inherit;
    }
}
