/* =============================================================================
   TitanShield legal documents (Terms of Service, Privacy Policy)
   -----------------------------------------------------------------------------
   Scoped entirely under .tsl-doc so nothing here can leak into the global
   .legal-page rules still used by legal_notice.html and dpa.html.

   Read mode: the visitor has to UNDERSTAND this document, so the whole layout
   is built around comprehension of a long reference text - a persistent table
   of contents, citable numbered sections, a 68ch measure, and real tables
   instead of prose for anything the reader will scan rather than read.

   Tokens are the shipped TitanShield dark theme (DESIGN.md): board-case
   #101216, board-face #1a1d22, hairline #2c3138, flap-ink #eef1ee,
   flap-ink-dim #8f99a3, text-tertiary #6b6966, resolved #00d972.
   Rectilinear, 2px radius, hairlines only, zero shadow, zero gradient.
   ============================================================================= */

.tsl-doc {
    --background: #101216;
    --surface: #1a1d22;
    --surface-raised: #20242a;
    --border-subtle: #2c3138;
    --border-strong: #3a4048;
    --text-primary: #eef1ee;
    --text-secondary: #8f99a3;
    --text-tertiary: #6b6966;
    --accent: #00d972;
    --accent-hover: #25e88b;
    --accent-ink: #03170d;
    --accent-dim: rgba(0, 217, 114, 0.08);
    --warn: #f0983a;
    --font-mono: "Martian Mono", ui-monospace, "SF Mono", Menlo, monospace;

    background: var(--background);
    color: var(--text-primary);
    font-family: "Titillium Web", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 17px;
    line-height: 1.68;
    -webkit-font-smoothing: antialiased;

    /* Full bleed: base.html wraps page content in a padded container, which
       left the document background as a floating slab with two visible edges.
       A legal document is the whole page, not a card sitting on one. */
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
}

/* -----------------------------------------------------------------------------
   Reclaiming the global theme
   -----------------------------------------------------------------------------
   Three app-wide rules would otherwise land on this document and each one is
   wrong here:
     1. animations.css sets `h1 { background: var(--gradient-primary);
        -webkit-text-fill-color: transparent }`, so every H1 renders as gradient
        text. DESIGN.md bans gradient text: emphasis comes from weight and size.
     2. v4-theme.css sets `h1..h6 { font-family: var(--font-display) }` where
        --font-display is Outfit, not the Titillium Web this project's design
        system actually specifies.
     3. v4-theme.css sets `[data-theme="dark"] a:not(...)` to #00d972, an
        attribute+element selector that outranks a single class, which turned
        every table-of-contents entry and every body link into the same loud
        green. The accent belongs on real links, at the accent value #00d972,
        not on navigation text.
   Scoped under .tsl-doc, so no other page is affected.
   -------------------------------------------------------------------------- */

.tsl-doc h1,
.tsl-doc h2,
.tsl-doc h3,
.tsl-doc h4 {
    font-family: "Titillium Web", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: none;
    -webkit-background-clip: border-box;
    background-clip: border-box;
    -webkit-text-fill-color: currentColor;
    color: var(--text-primary);
    /* A global rule centres every h2. Centred headings over a 68ch measure
       break the left edge the eye tracks down a long document. */
    text-align: left;
}

/* html and body carry `overflow-x: hidden` app-wide (base.css, layout.css and
   others), which turns them into scroll containers and silently kills
   `position: sticky` on the table of contents: it stuck to a container that
   never scrolls, so the rail simply slid off the top of the page. `clip` does
   the same visual job without establishing a scroll container, so the rail
   stays put. Scoped with :has() to these two documents only. */
html:has(.tsl-doc),
body:has(.tsl-doc) { overflow-x: clip; }

/* The dark-mode link rule scores (0,5,1) because of its four :not() arguments,
   which no reasonable class selector can outrank. !important is the honest
   tool here: these declarations restate the same values already set further
   down the file, purely to win against a global rule that should never have
   applied to a document surface. */
.tsl-doc a { -webkit-text-fill-color: currentColor; }
.tsl-doc .tsl-lang a { color: var(--text-secondary) !important; }
.tsl-doc .tsl-lang a:hover { color: var(--text-primary) !important; }
.tsl-doc .tsl-toc a { color: var(--text-secondary) !important; }
.tsl-doc .tsl-toc a:hover { color: var(--text-primary) !important; }
.tsl-doc .tsl-toc a.is-current { color: var(--accent) !important; }
.tsl-doc .tsl-article a { color: var(--accent) !important; }
.tsl-doc .tsl-article a:hover { color: var(--accent-hover) !important; }
.tsl-doc .tsl-article h2 .tsl-anchor { color: var(--text-tertiary) !important; }
.tsl-doc .tsl-contact a { color: var(--accent) !important; }
.tsl-doc .tsl-foot a { color: var(--text-secondary) !important; }
.tsl-doc .tsl-foot a:hover { color: var(--text-primary) !important; }
.tsl-doc .tsl-skip { color: var(--accent-ink) !important; }

/* The app-wide theme toggle has no meaning here: these pages are dark only. */
.tsl-doc ~ #themeToggle,
body:has(.tsl-doc) #themeToggle { display: none !important; }

/* Nothing in this document casts a shadow. */
.tsl-doc, .tsl-doc * { box-shadow: none !important; }

.tsl-doc .tsl-skip {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
    padding: 10px 18px;
    z-index: 100;
}
.tsl-doc .tsl-skip:focus {
    left: 1rem;
    top: 1rem;
}

/* ---------------------------------------------------------------- masthead */

.tsl-masthead {
    max-width: 1180px;
    margin: 0 auto;
    padding: 3.5rem 1.5rem 0;
}

.tsl-lang {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.76rem;
    letter-spacing: 0.04em;
    margin-bottom: 2rem;
}
.tsl-doc .tsl-lang a,
.tsl-doc .tsl-lang span {
    padding: 4px 10px;
    border: 1px solid var(--border-subtle);
    border-radius: 2px;
    text-decoration: none;
    color: var(--text-secondary);
}
.tsl-doc .tsl-lang a:hover { color: var(--text-primary); border-color: var(--border-strong); }
.tsl-doc .tsl-lang [aria-current="true"] { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); font-weight: 700; }

.tsl-masthead h1 {
    font-size: clamp(2rem, 5vw, 3.4rem);
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.06;
    margin: 0 0 0.9rem;
    color: var(--text-primary);
    max-width: 20ch;
}

.tsl-standfirst {
    font-size: 1.12rem;
    color: var(--text-secondary);
    max-width: 62ch;
    margin: 0 0 1.6rem;
    line-height: 1.6;
}

.tsl-dates {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 2rem;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.02em;
    color: var(--text-secondary);
    padding-bottom: 2.5rem;
    border-bottom: 1px solid var(--border-subtle);
    margin: 0;
}
.tsl-dates b { color: var(--text-primary); font-weight: 400; }

/* ------------------------------------------------------------- facts block */
/* Hairline rows, not cards: the reader scans a label/value ledger. */

.tsl-facts {
    margin: 2.5rem 0 0;
    border: 1px solid var(--border-subtle);
    border-radius: 2px;
    background: var(--surface);
}
.tsl-facts-title {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-subtle);
    margin: 0;
}
.tsl-fact {
    display: grid;
    grid-template-columns: 15rem 1fr;
    gap: 1.5rem;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
    align-items: baseline;
}
.tsl-fact:last-child { border-bottom: 0; }
.tsl-fact dt {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 0;
    overflow-wrap: break-word;
}
.tsl-fact dd {
    margin: 0;
    font-size: 1.02rem;
    color: var(--text-primary);
    min-width: 0;
    overflow-wrap: break-word;
}
@media (max-width: 760px) {
    .tsl-fact { grid-template-columns: 1fr; gap: 0.3rem; }
}

/* ----------------------------------------------------------------- layout */

.tsl-body {
    max-width: 1180px;
    margin: 0 auto;
    padding: 3rem 1.5rem 6rem;
    display: grid;
    grid-template-columns: 15rem minmax(0, 1fr);
    gap: 3.5rem;
    align-items: start;
}
@media (max-width: 1020px) {
    .tsl-body { grid-template-columns: minmax(0, 1fr); gap: 2rem; }
}

/* --------------------------------------------------------- table of contents */

.tsl-toc {
    /* The app navbar is fixed at 60px. The rail and every jump-link target
       clear it, so nothing ever lands underneath the header. */
    position: sticky;
    top: 5rem;
    max-height: calc(100vh - 7rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    font-size: 0.88rem;
    line-height: 1.4;
    border-left: 1px solid var(--border-subtle);
}
.tsl-toc h2 {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin: 0 0 0.9rem;
    padding-left: 1rem;
    font-weight: 400;
}
.tsl-toc ol {
    list-style: none;
    counter-reset: tsl-toc;
    margin: 0;
    padding: 0;
}
.tsl-toc li { counter-increment: tsl-toc; }
.tsl-doc .tsl-toc a {
    display: block;
    padding: 7px 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-left: 1px solid transparent;
    margin-left: -1px;
    overflow-wrap: break-word;
}
.tsl-doc .tsl-toc a::before {
    content: counter(tsl-toc) ".";
    font-family: var(--font-mono);
    font-size: 0.76rem;
    color: var(--text-secondary);
    margin-right: 0.55rem;
}
.tsl-doc .tsl-toc a:hover { color: var(--text-primary); background: var(--surface); }
.tsl-doc .tsl-toc a.is-current {
    color: var(--accent);
    border-left-color: var(--accent);
    background: var(--accent-dim);
}
.tsl-doc .tsl-toc a.is-current::before { color: var(--accent); }

/* On narrow screens the rail becomes a collapsed index at the top. */
@media (max-width: 1020px) {
    .tsl-toc {
        position: static;
        max-height: none;
        border-left: 0;
        border: 1px solid var(--border-subtle);
        border-radius: 2px;
        background: var(--surface);
        padding: 1rem 0.25rem;
    }
    .tsl-toc h2 { padding-left: 1rem; }
    .tsl-toc a { border-left: 0; }
}

/* ---------------------------------------------------------------- article */

.tsl-article {
    max-width: 68ch;
    counter-reset: tsl-sec;
    min-width: 0;
}

.tsl-article section {
    counter-increment: tsl-sec;
    padding-top: 2.75rem;
    margin-bottom: 0.5rem;
    scroll-margin-top: 5rem;
}
.tsl-article section:first-child { padding-top: 0; }

.tsl-article h2 {
    font-size: clamp(1.3rem, 2.6vw, 1.7rem);
    font-weight: 700;
    letter-spacing: -0.015em;
    line-height: 1.15;
    color: var(--text-primary);
    margin: 0 0 1.1rem;
    padding-bottom: 0.7rem;
    border-bottom: 1px solid var(--border-subtle);
    overflow-wrap: break-word;
}
/* The section number is a citation handle ("see section 7.2"), not decoration. */
.tsl-article h2::before {
    content: counter(tsl-sec) ". ";
    font-family: var(--font-mono);
    font-size: 0.78em;
    color: var(--accent);
    font-weight: 700;
}

.tsl-article h3 {
    font-size: 1.04rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 2rem 0 0.6rem;
    letter-spacing: -0.005em;
}
.tsl-article h3 .tsl-ref {
    font-family: var(--font-mono);
    font-size: 0.82em;
    font-weight: 400;
    color: var(--text-secondary);
    margin-right: 0.5rem;
}

.tsl-article p {
    margin: 0 0 1.05rem;
    color: var(--text-secondary);
    overflow-wrap: break-word;
}
.tsl-article p strong,
.tsl-article li strong { color: var(--text-primary); font-weight: 600; }

.tsl-article ul,
.tsl-article ol.tsl-list {
    margin: 0 0 1.15rem;
    padding-left: 1.15rem;
    color: var(--text-secondary);
}
.tsl-article li { margin-bottom: 0.5rem; overflow-wrap: break-word; }
.tsl-article ul li::marker { color: var(--text-tertiary); }

.tsl-doc .tsl-article a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid rgba(0, 217, 114, 0.35);
}
.tsl-doc .tsl-article a:hover { color: var(--accent-hover); border-bottom-color: var(--accent-hover); }

.tsl-article code {
    font-family: var(--font-mono);
    font-size: 0.86em;
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    border-radius: 2px;
    padding: 1px 5px;
    color: var(--text-primary);
    overflow-wrap: break-word;
}

/* Anchor affordance: visible on hover and on keyboard focus, never a decoration. */
.tsl-doc .tsl-anchor {
    font-family: var(--font-mono);
    font-size: 0.7em;
    color: var(--text-tertiary);
    margin-left: 0.6rem;
    opacity: 0;
    border-bottom: 0 !important;
    transition: opacity 120ms ease-out;
}
.tsl-article h2:hover .tsl-anchor,
.tsl-anchor:focus-visible { opacity: 1; }

/* ----------------------------------------------------------------- tables */

.tsl-tablewrap {
    overflow-x: auto;
    margin: 0 0 1.4rem;
    border: 1px solid var(--border-subtle);
    border-radius: 2px;
}
.tsl-table {
    width: 100%;
    min-width: 34rem;
    border-collapse: collapse;
    font-size: 0.9rem;
    line-height: 1.45;
    background: var(--surface);
}
.tsl-table caption {
    text-align: left;
    padding: 12px 16px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border-subtle);
}
.tsl-table th,
.tsl-table td {
    padding: 11px 16px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border-subtle);
}
.tsl-table thead th {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 400;
    background: var(--surface-raised);
    white-space: nowrap;
}
.tsl-table tbody th {
    font-weight: 600;
    color: var(--text-primary);
}
.tsl-table td { color: var(--text-secondary); }
.tsl-table tbody tr:last-child th,
.tsl-table tbody tr:last-child td { border-bottom: 0; }

/* Narrow screens: a wide reference table scrolls sideways and the later
   columns get clipped. legal-doc.js labels each cell with its column header and
   adds .is-stacked, so every row becomes a titled card with a label above each
   value: no horizontal scroll, nothing clipped. Without JS the table keeps the
   .tsl-tablewrap horizontal scroll as a fallback. */
@media (max-width: 600px) {
    .tsl-tablewrap:has(.tsl-table.is-stacked) { overflow-x: visible; }
    .tsl-table.is-stacked { min-width: 0; }
    .tsl-table.is-stacked thead {
        position: absolute; width: 1px; height: 1px;
        padding: 0; margin: -1px; overflow: hidden;
        clip: rect(0 0 0 0); white-space: nowrap; border: 0;
    }
    .tsl-table.is-stacked tbody,
    .tsl-table.is-stacked tbody tr,
    .tsl-table.is-stacked tbody th,
    .tsl-table.is-stacked tbody td { display: block; }
    .tsl-table.is-stacked tbody tr {
        padding: 14px 16px;
        border-bottom: 1px solid var(--border-subtle);
    }
    .tsl-table.is-stacked tbody tr:last-child { border-bottom: 0; }
    .tsl-table.is-stacked tbody th[scope="row"] {
        padding: 0 0 0.6rem;
        font-size: 1rem;
        color: var(--text-primary);
        border-bottom: 0;
    }
    .tsl-table.is-stacked tbody td {
        padding: 0.5rem 0 0;
        border-bottom: 0;
        color: var(--text-secondary);
    }
    .tsl-table.is-stacked tbody td::before {
        content: attr(data-label);
        display: block;
        font-family: var(--font-mono);
        font-size: 0.68rem;
        letter-spacing: 0.1em;
        text-transform: uppercase;
        color: var(--text-tertiary);
        margin-bottom: 0.15rem;
    }
    /* A cell with no column header (rare) should not render an empty label. */
    .tsl-table.is-stacked tbody td:not([data-label])::before { content: none; }
}

/* ---------------------------------------------------------------- callout */

.tsl-note {
    border: 1px solid var(--border-subtle);
    border-left: 1px solid var(--accent);
    background: var(--surface);
    border-radius: 2px;
    padding: 16px 20px;
    margin: 0 0 1.4rem;
}
.tsl-note p:last-child { margin-bottom: 0; }
.tsl-note-label {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 0.5rem;
}
.tsl-note--warn { border-left-color: var(--warn); }
.tsl-note--warn .tsl-note-label { color: var(--warn); }

/* ------------------------------------------------------------------ misc */

.tsl-contact {
    border: 1px solid var(--border-subtle);
    border-radius: 2px;
    background: var(--surface);
    padding: 18px 20px;
    margin-bottom: 1.2rem;
}
.tsl-contact dl { margin: 0; display: grid; grid-template-columns: 11rem 1fr; gap: 0.55rem 1.5rem; }
.tsl-contact dt { color: var(--text-secondary); font-size: 0.88rem; }
.tsl-doc .tsl-contact dd { margin: 0; color: var(--text-primary); font-size: 0.9rem; overflow-wrap: break-word; }
@media (max-width: 620px) {
    .tsl-contact dl { grid-template-columns: 1fr; gap: 0.15rem; }
    .tsl-contact dd { margin-bottom: 0.6rem; }
}

.tsl-foot {
    margin-top: 3.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-subtle);
    font-size: 0.88rem;
    color: var(--text-secondary);
}
.tsl-doc .tsl-foot a { color: var(--text-secondary); }

.tsl-doc :focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: no-preference) {
    html:has(.tsl-doc) { scroll-behavior: smooth; }
}

/* ----------------------------------------------------------------- print */
/* Legal documents get printed and attached to procurement files. */

@media print {
    .tsl-doc {
        background: #fff;
        color: #111;
        font-size: 11pt;
    }
    .tsl-toc, .tsl-lang, .tsl-skip, .tsl-anchor { display: none !important; }
    .tsl-body { display: block; padding: 0; }
    .tsl-article { max-width: none; }
    .tsl-doc h1, .tsl-doc h2, .tsl-doc h3 { color: #000; }
    .tsl-article p, .tsl-article li, .tsl-table td { color: #222; }
    .tsl-article section { break-inside: auto; page-break-inside: auto; }
    .tsl-article h2 { break-after: avoid; page-break-after: avoid; }
    .tsl-facts, .tsl-note, .tsl-contact, .tsl-tablewrap, .tsl-table { background: #fff; border-color: #bbb; }
    .tsl-article a { color: #000; border-bottom: 0; }
    .tsl-article a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.85em; color: #555; }
}
