/* =============================================
   UTOPIA LEGAL PAGES
   Shared styles for Terms / Privacy / Cookies.
   Pairs with styles.css (CSS variables + theme).
   Mobile-first, light + dark theme aware.
   ============================================= */

:root {
    --legal-header-height: 64px;
    --legal-max-width: 760px;
    --legal-toc-width: 240px;
    --legal-radius-card: 1.25rem;
    --legal-warning-bg: rgba(239, 68, 68, 0.12);
    --legal-warning-border: rgba(239, 68, 68, 0.32);
    --legal-warning-fg: #ef4444;
    --legal-note-bg: rgba(59, 130, 246, 0.08);
    --legal-note-border: rgba(59, 130, 246, 0.25);
    --legal-table-stripe: rgba(255, 255, 255, 0.03);
}

[data-theme="light"] {
    --legal-warning-bg: rgba(239, 68, 68, 0.08);
    --legal-warning-border: rgba(239, 68, 68, 0.28);
    --legal-warning-fg: #b91c1c;
    --legal-note-bg: rgba(59, 130, 246, 0.07);
    --legal-note-border: rgba(59, 130, 246, 0.22);
    --legal-table-stripe: rgba(15, 23, 42, 0.03);
}

/* =============================================
   PAGE FRAME
   ============================================= */
html { scroll-behavior: smooth; }

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 16px;
    line-height: 1.7;
    letter-spacing: -0.005em;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Compensate for sticky header when jumping to a section. */
section[id] { scroll-margin-top: calc(var(--legal-header-height) + 16px); }

/* =============================================
   TOP HEADER
   ============================================= */
.legal-top-header {
    position: sticky;
    top: 0;
    z-index: var(--z-nav);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    height: var(--legal-header-height);
    padding: 0 16px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-primary);
}

@media (min-width: 768px) {
    .legal-top-header { padding: 0 32px; }
}

.legal-back-btn,
.legal-theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-primary);
    background: transparent;
    color: var(--text-primary);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
    padding: 0;
}
.legal-back-btn:hover,
.legal-theme-toggle:hover {
    background: var(--bg-card);
    border-color: var(--blue-500);
}
.legal-back-btn:active,
.legal-theme-toggle:active { transform: scale(0.96); }

.legal-back-btn .material-symbols-outlined,
.legal-theme-toggle .material-symbols-outlined { font-size: 22px; }

.legal-theme-toggle .theme-icon {
    width: 20px;
    height: 20px;
    display: none;
    color: var(--text-primary);
}
[data-theme="dark"] .legal-theme-toggle .sun-icon { display: block; }
[data-theme="light"] .legal-theme-toggle .moon-icon { display: block; }

.legal-brand-logo {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    height: 40px;
}
.legal-brand-logo img {
    height: 28px;
    width: auto;
    display: block;
}

/* =============================================
   MAIN LAYOUT
   ============================================= */
.legal-page {
    width: 100%;
    max-width: var(--legal-max-width);
    margin: 0 auto;
    padding: 32px 20px max(48px, env(safe-area-inset-bottom));
    box-sizing: border-box;
}

@media (min-width: 768px) {
    .legal-page {
        padding: 48px 32px 96px;
    }
}

@media (min-width: 1180px) {
    /* Two-column layout: sticky TOC on the left, content on the right. */
    .legal-page {
        max-width: calc(var(--legal-max-width) + var(--legal-toc-width) + 80px);
        display: grid;
        grid-template-columns: var(--legal-toc-width) 1fr;
        gap: 64px;
        align-items: start;
    }
    .legal-hero,
    .legal-body,
    .legal-footer { grid-column: 2; }
    .legal-toc { grid-column: 1; grid-row: 1 / span 3; }
}

/* =============================================
   HERO
   ============================================= */
.legal-hero {
    margin-bottom: 32px;
}

.legal-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--legal-note-bg);
    color: var(--blue-500);
    border: 1px solid var(--legal-note-border);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 16px;
}

.legal-title {
    font-family: 'Manrope', 'Inter', sans-serif;
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 900;
    line-height: 1.1;
    letter-spacing: -0.025em;
    color: var(--text-primary);
    margin: 0 0 12px;
}

.legal-effective {
    font-size: 14px;
    color: var(--text-tertiary);
    margin: 0 0 20px;
}

.legal-summary {
    font-size: 17px;
    line-height: 1.7;
    color: var(--text-secondary);
    margin: 0;
    padding: 18px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--legal-radius-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* =============================================
   TABLE OF CONTENTS
   ============================================= */
.legal-toc {
    margin-bottom: 32px;
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--legal-radius-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.legal-toc summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    user-select: none;
}
.legal-toc summary::-webkit-details-marker { display: none; }
.legal-toc summary::after {
    content: 'expand_more';
    font-family: 'Material Symbols Outlined';
    font-size: 22px;
    color: var(--text-tertiary);
    transition: transform 0.2s ease;
}
.legal-toc[open] summary::after { transform: rotate(180deg); }

.legal-toc ol {
    list-style: none;
    margin: 0;
    padding: 6px 8px 14px;
    counter-reset: toc;
}
.legal-toc li {
    counter-increment: toc;
}
.legal-toc a {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 10px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    line-height: 1.45;
    transition: background 0.15s ease, color 0.15s ease;
}
.legal-toc a::before {
    content: counter(toc) ".";
    font-weight: 700;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
    min-width: 22px;
}
.legal-toc a:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

@media (min-width: 1180px) {
    .legal-toc {
        position: sticky;
        top: calc(var(--legal-header-height) + 24px);
        margin-bottom: 0;
        max-height: calc(100vh - var(--legal-header-height) - 48px);
        overflow-y: auto;
    }
    .legal-toc summary {
        pointer-events: none;
        padding-bottom: 8px;
    }
    .legal-toc summary::after { display: none; }
    /* Force open on desktop regardless of <details> state. */
    .legal-toc ol { display: block !important; }
}

/* =============================================
   BODY CONTENT
   ============================================= */
.legal-body {
    font-size: 16px;
    line-height: 1.7;
    color: var(--text-primary);
}

.legal-body section {
    padding: 24px 0;
    border-top: 1px solid var(--border-primary);
}
.legal-body section:first-of-type {
    border-top: none;
    padding-top: 0;
}

.legal-body h2 {
    font-family: 'Manrope', 'Inter', sans-serif;
    font-size: clamp(1.375rem, 2.5vw, 1.625rem);
    font-weight: 800;
    letter-spacing: -0.015em;
    color: var(--text-primary);
    margin: 0 0 16px;
    display: flex;
    align-items: baseline;
    gap: 12px;
    line-height: 1.25;
}
.legal-body h2 .section-num {
    color: var(--blue-500);
    font-variant-numeric: tabular-nums;
    font-weight: 800;
    flex-shrink: 0;
}

.legal-body h3 {
    font-family: 'Manrope', 'Inter', sans-serif;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 24px 0 10px;
    letter-spacing: -0.01em;
}

.legal-body p {
    margin: 0 0 14px;
    color: var(--text-secondary);
}
.legal-body p:last-child { margin-bottom: 0; }

.legal-body strong {
    color: var(--text-primary);
    font-weight: 700;
}

.legal-body em {
    color: var(--text-primary);
    font-style: italic;
}

.legal-body a {
    color: var(--blue-500);
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-thickness: 1px;
    transition: opacity 0.15s ease;
}
.legal-body a:hover { opacity: 0.78; }

.legal-body ul,
.legal-body ol {
    margin: 4px 0 16px;
    padding-left: 22px;
    color: var(--text-secondary);
}
.legal-body li {
    margin-bottom: 8px;
    line-height: 1.65;
}
.legal-body li::marker { color: var(--text-tertiary); }

/* Inline code-style monospace for storage keys, env vars, etc. */
.legal-body code {
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.92em;
    padding: 2px 6px;
    border-radius: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    color: var(--text-primary);
}

/* =============================================
   CALLOUT BOXES (warning / note)
   ============================================= */
.legal-callout {
    display: flex;
    gap: 14px;
    padding: 16px 18px;
    margin: 16px 0;
    border-radius: var(--legal-radius-card);
    border: 1px solid var(--legal-note-border);
    background: var(--legal-note-bg);
}
.legal-callout .callout-icon {
    flex-shrink: 0;
    color: var(--blue-500);
    font-size: 24px;
}
.legal-callout .callout-body {
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.65;
}
.legal-callout .callout-body p { margin: 0 0 8px; color: var(--text-primary); }
.legal-callout .callout-body p:last-child { margin-bottom: 0; }
.legal-callout .callout-title {
    font-weight: 800;
    font-size: 13px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--blue-500);
    margin-bottom: 6px;
    display: block;
}

.legal-warning {
    border-color: var(--legal-warning-border);
    background: var(--legal-warning-bg);
}
.legal-warning .callout-icon { color: var(--legal-warning-fg); }
.legal-warning .callout-title { color: var(--legal-warning-fg); }
.legal-warning .callout-body { color: var(--text-primary); }

/* Used inside warnings/sections for ALL-CAPS legal phrasing.
   Renders the text as small-caps-ish: tight, slightly larger, weight 700. */
.legal-allcaps {
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 700;
    color: var(--text-primary);
}

/* =============================================
   TABLES (used in Cookie Policy)
   ============================================= */
.legal-table-wrap {
    margin: 16px 0 20px;
    overflow-x: auto;
    border: 1px solid var(--border-primary);
    border-radius: var(--legal-radius-card);
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.legal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14.5px;
    min-width: 540px;
}
.legal-table thead th {
    text-align: left;
    padding: 12px 14px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    border-bottom: 1px solid var(--border-primary);
    background: transparent;
}
.legal-table tbody td {
    padding: 12px 14px;
    border-top: 1px solid var(--border-primary);
    color: var(--text-secondary);
    vertical-align: top;
    line-height: 1.55;
}
.legal-table tbody td:first-child { color: var(--text-primary); font-weight: 600; }
.legal-table tbody tr:nth-child(even) td { background: var(--legal-table-stripe); }

/* =============================================
   FOOTER
   ============================================= */
.legal-footer {
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--border-primary);
    font-size: 14px;
    color: var(--text-tertiary);
}
.legal-footer-links {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    margin-bottom: 12px;
}
.legal-footer-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
}
.legal-footer-links a:hover { color: var(--blue-500); }
.legal-footer p { margin: 0; line-height: 1.6; }
.legal-footer p + p { margin-top: 6px; }

/* =============================================
   ACCESSIBILITY
   ============================================= */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    .legal-back-btn,
    .legal-theme-toggle,
    .legal-toc a,
    .legal-toc summary::after { transition: none; }
}

:focus-visible {
    outline: 2px solid var(--blue-500);
    outline-offset: 2px;
    border-radius: 6px;
}
