/* ==========================================================================
   Tribes Market - Legal Pages (/terms & /privacy) Stylesheet
   Follows 4-Tier Framer Hierarchy & fluid clamp() tokens from common.css
   ========================================================================== */

body.legal-page header .header-main {
    max-width: var(--container-max-width, 1280px);
    width: 100%;
    margin: 0 auto;
    padding: 0 var(--gutter-fluid, clamp(12px, 3vw, 28px));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 64px;
    box-sizing: border-box;
}

.legal-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.legal-back-link {
    min-height: 38px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: var(--bg-white);
    color: var(--text-main);
    text-decoration: none;
    font-size: var(--font-small);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.legal-back-link:hover,
.legal-back-link:focus-visible {
    border-color: var(--brand-ochre);
    color: var(--brand-ochre);
    background: var(--bg-surface-elevated);
}

.legal-main {
    flex: 1;
    width: 100%;
    padding: clamp(18px, 3.5vw, 40px) 0;
}

.legal-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: clamp(20px, 3vw, 36px);
    align-items: start;
}

.legal-toc-rail {
    position: sticky;
    top: 84px;
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-card);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    max-height: calc(100vh - 104px);
    overflow-y: auto;
}

.legal-toc-title {
    font-size: var(--font-xs);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin: 0 0 10px 0;
}

.legal-toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.legal-toc-list a {
    display: block;
    padding: 6px 8px;
    border-radius: 7px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--font-small);
    line-height: 1.35;
    font-weight: 500;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.legal-toc-list a:hover,
.legal-toc-list a:focus-visible {
    background: var(--brand-tint-bg);
    color: var(--brand-tint-text);
}

.legal-toc-mobile {
    display: none;
    margin-bottom: 18px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-light);
    border-radius: 10px;
}

.legal-toc-mobile summary {
    padding: 12px 14px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--font-small);
    font-weight: 700;
    color: var(--text-main);
    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(--text-secondary);
    border-bottom: 2px solid var(--text-secondary);
    transform: rotate(45deg);
    transition: transform 0.15s ease;
    margin-right: 4px;
}

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

.legal-toc-mobile .legal-toc-list {
    padding: 0 10px 12px 10px;
    border-top: 1px solid var(--border-light);
    padding-top: 8px;
}

.legal-doc-card {
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-card);
    padding: clamp(18px, 3.5vw, 40px);
    box-shadow: var(--shadow-card);
    min-width: 0;
}

.legal-doc-switcher {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px;
    border-radius: 999px;
    background: var(--bg-surface-subtle);
    border: 1px solid var(--border-light);
    margin-bottom: 20px;
}

.legal-doc-tab {
    min-height: 36px;
    padding: 0 14px;
    border-radius: 999px;
    text-decoration: none;
    font-size: var(--font-small);
    font-weight: 700;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.legal-doc-tab:hover,
.legal-doc-tab:focus-visible {
    color: var(--text-main);
}

.legal-doc-tab.active {
    background: var(--brand-ochre);
    color: #ffffff;
}

:root[data-theme="dark"] .legal-doc-tab.active {
    color: #16191d;
}

.legal-doc-header {
    padding-bottom: 18px;
    margin-bottom: 22px;
    border-bottom: 1px solid var(--border-light);
}

.legal-doc-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: var(--font-heading-hero);
    font-weight: 800;
    color: var(--text-main);
    line-height: 1.2;
    margin: 0 0 12px 0;
}

.legal-meta-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px;
    font-size: var(--font-small);
    color: var(--text-secondary);
    line-height: 1.5;
}

.legal-meta-grid a {
    color: var(--brand-ochre);
    font-weight: 600;
    text-decoration: none;
}

.legal-meta-grid a:hover {
    text-decoration: underline;
}

.legal-summary-box {
    background: var(--brand-tint-bg);
    border: 1px solid var(--brand-tint-border);
    border-radius: 12px;
    padding: clamp(14px, 2.5vw, 20px);
    margin-bottom: clamp(22px, 3vw, 30px);
}

.legal-summary-box h2 {
    font-size: var(--font-heading-card);
    font-weight: 800;
    color: var(--brand-tint-text);
    margin: 0 0 6px 0;
}

.legal-summary-note {
    font-size: var(--font-xs);
    font-style: italic;
    color: var(--text-secondary);
    margin: 0 0 12px 0;
    line-height: 1.45;
}

.legal-summary-box ul {
    margin: 0;
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: var(--font-small);
    color: var(--text-main);
    line-height: 1.55;
}

.legal-section,
#data-deletion {
    scroll-margin-top: 84px;
}

.legal-section {
    padding-top: 22px;
    margin-top: 22px;
    border-top: 1px solid var(--border-light);
}

.legal-section:first-of-type {
    padding-top: 0;
    margin-top: 0;
    border-top: none;
}

.legal-section h2 {
    font-size: var(--font-heading-section);
    font-weight: 800;
    color: var(--text-main);
    margin: 0 0 12px 0;
    line-height: 1.3;
}

.legal-section h3 {
    font-size: var(--font-heading-card);
    font-weight: 700;
    color: var(--text-main);
    margin: 16px 0 8px 0;
    line-height: 1.35;
}

.legal-section p {
    font-size: var(--font-body);
    color: var(--text-secondary);
    line-height: 1.65;
    margin: 0 0 12px 0;
    overflow-wrap: break-word;
}

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

.legal-section ul,
.legal-section ol {
    margin: 0 0 14px 0;
    padding-left: 22px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: var(--font-body);
    color: var(--text-secondary);
    line-height: 1.6;
}

.legal-section strong {
    color: var(--text-main);
}

.legal-section a {
    color: var(--brand-ochre);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-word;
}

.legal-section a:hover {
    color: var(--brand-ochre-hover);
}

.legal-code-chip {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 5px;
    background: var(--bg-surface-subtle);
    border: 1px solid var(--border-light);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.86em;
    color: var(--text-main);
}

.legal-callout-note {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-light);
    border-left: 3px solid var(--brand-ochre);
    border-radius: 8px;
    padding: 12px 14px;
    margin: 12px 0;
    font-size: var(--font-small);
    color: var(--text-secondary);
    line-height: 1.55;
}

.visually-hidden {
    position: absolute;
    clip-path: inset(50%);
    overflow: hidden;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    white-space: nowrap;
}

/* Responsive Data Retention Table */
.legal-table-wrapper {
    overflow: auto;
    max-inline-size: 100%;
    container-type: inline-size;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    margin: 14px 0;
    background: var(--bg-white);
}

.legal-table-wrapper:focus-visible {
    outline: 2px solid var(--brand-ochre);
    outline-offset: 2px;
}

.legal-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--font-small);
    text-align: left;
    --label-rule: "Retention & Automated Purge Rule";
}

.legal-table thead th {
    position: sticky;
    inset-block-start: 0;
    z-index: 1;
    background: var(--bg-surface-subtle);
    color: var(--text-main);
    font-weight: 700;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border-strong);
}

.legal-table tbody th,
.legal-table tbody td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: top;
    line-height: 1.5;
}

.legal-table tbody th {
    color: var(--text-main);
    font-weight: 700;
    min-width: 190px;
}

.legal-table tbody td {
    color: var(--text-secondary);
}

.legal-table tbody tr:last-child th,
.legal-table tbody tr:last-child td {
    border-bottom: none;
}

@container (width < 580px) {
    .legal-table,
    .legal-table thead,
    .legal-table tbody,
    .legal-table tr,
    .legal-table th,
    .legal-table td {
        display: block;
    }

    .legal-table thead {
        display: none;
    }

    .legal-table {
        background: transparent;
    }

    .legal-table-wrapper {
        border: none;
        background: transparent;
        overflow: visible;
    }

    .legal-table tbody tr {
        margin-block-end: 10px;
        border: 1px solid var(--border-light);
        border-radius: 10px;
        overflow: hidden;
        background: var(--bg-white);
    }

    .legal-table tbody tr:last-child {
        margin-block-end: 0;
    }

    .legal-table tbody th {
        min-width: 0;
        background: var(--bg-surface-subtle);
        border-bottom: 1px solid var(--border-light);
        padding: 9px 12px;
    }

    .legal-table tbody td {
        border-bottom: none;
        padding: 10px 12px;
    }

    .legal-table tbody td:nth-child(2)::before {
        content: var(--label-rule) ": ";
        font-weight: 700;
        color: var(--text-main);
    }
}

@media (max-width: 920px) {
    .legal-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .legal-toc-rail {
        display: none;
    }

    .legal-toc-mobile {
        display: block;
    }
}

@media (max-width: 579px) {
    .legal-doc-card {
        padding: 16px 14px;
    }

    .legal-doc-switcher {
        width: 100%;
    }

    .legal-doc-tab {
        flex: 1;
        justify-content: center;
        padding: 0 10px;
        font-size: var(--font-xs);
    }

    .legal-back-link {
        padding: 0 10px;
        font-size: var(--font-xs);
    }
}
