/* =============================================================
   The new frame (docs/redesign/BRIEF.md, key `frame`).
   Loaded through templates/partials/_frame_head.html, only when
   redesign_on('frame') is true. It dresses the pages that have
   not been rebuilt in the redesign's header, footer and display
   face; the middle of each page keeps its own CSS. Two kinds:

   body.rd-framed          pages on templates/site/base.html
                           (content in <main id="main">)
   body.rd-framed.rd-framed--own
                           standalone pages that carried their own
                           copy of the old nav: str_rules_hub.html,
                           str_rules/*.html, public/str_compare.html
                           (no #main; section 4)

   <body> never gets `rd` (rd.css's page-wide rules are for
   rd_base.html pages). The header and footer sit in
   <div class="rd rd-frame ...">, so every `.rd ...` rule in
   rd.css reaches those two and nothing else.
   ============================================================= */

/* ---------- 1. the two wrappers: what body.rd gives a redesigned page ---------- */
.rd-frame {
  font-family: var(--rd-sans);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: normal;
  color: var(--brand-body);
  text-rendering: optimizeLegibility;
}
/* base.html resets every link (`a { text-decoration: none; color: inherit }`); a
   redesigned page starts from the browser default. :where() keeps this at the
   weight of a bare `a`, so every rd.css rule still wins over it. */
:where(.rd-frame) a { text-decoration: underline; }
/* A page's own bare `p { color: ... }` (the STR county pages have one) must not
   recolour the footer's paragraphs: they take the footer's colour, as on a
   redesigned page, where no rule names a bare <p>. */
.rd-frame p { color: inherit; }

/* ---------- 2. the old nav was fixed; this header is in the flow ----------
   Pages on site/base.html open with a hero or band whose top padding made
   room for the fixed, see-through nav. With the header in the flow that room
   would be an empty band under it, so on those pages <main> is pulled up by
   --rdf-crop and the header (opaque, z-index 900 in rd.css) covers the part
   that was only ever padding. What is left between the header and the first
   line of the page is 28px or more at every width (measured per hero class,
   320 to 1440 wide, on the local prod copy).

   The list is the hero classes that are known to leave that room, and it
   counts only when the hero is the first thing in <main> (nothing before it
   but <style> / <script>): a page that is not on the list, or that prints
   something above its hero, keeps all of its top padding. That is a taller
   band, never text under the header. Four pages left no room at all (their
   first line sat under the old nav) and are deliberately not listed:
   /browse/ (.browse-hero), /properties/sold/ (.sold-hero), the 404 page
   (.not-found-page) and /app (an unclassed section).
   tests/test_redesign_frame.py fails when a template on site/base.html opens
   with a class that is in neither group.
   (Safari does not re-run the "first thing in <main>" part when a script
   inserts an element above the hero after load; nothing does that today.
   Anything printed above a hero must come from the server.) */
body.rd-framed { --rdf-crop: 0px; }
body.rd-framed:has(#main > :is(
    .about-hero, .agent-hero, .agents-hero, .announcements-hero, .blog-hero, .blog-index-hero,
    .cma-hero, .cmp-hero, .contact-hero, .faq-hero, .hero, .hp-hero, .hs-hero, .hub-hero,
    .hvt-hero, .inv-band, .join-hero, .legal-hero, .lux-hero, .meet-hero, .mm, .nbh-hero,
    .olp, .reviews-hero, .sell-hero, .sp-hero, .spoke-hero, .str-hero, .vr-hero
  ):not(:not(style, script, link, noscript, template) ~ *)) { --rdf-crop: 80px; }
@media (max-width: 480px) {
  body.rd-framed:has(#main > :is(
    .about-hero, .agent-hero, .agents-hero, .announcements-hero, .blog-hero, .blog-index-hero,
    .cma-hero, .cmp-hero, .contact-hero, .faq-hero, .hero, .hp-hero, .hs-hero, .hub-hero,
    .hvt-hero, .inv-band, .join-hero, .legal-hero, .lux-hero, .meet-hero, .mm, .nbh-hero,
    .olp, .reviews-hero, .sell-hero, .sp-hero, .spoke-hero, .str-hero, .vr-hero
  ):not(:not(style, script, link, noscript, template) ~ *)) { --rdf-crop: 72px; }
  /* the old homepage hero (site/home.html, only when `home` is off) centres its text and leaves
     81px at 390 wide but 4px at 320: no pull-up on phones (same selector weight as the list, so it wins by order) */
  body.rd-framed:has(#main > .hero:not(:not(style, script, link, noscript, template) ~ *)) { --rdf-crop: 0px; }
}
/* /join/ styled the old nav short and solid, and leaves no room under 769px */
@media (max-width: 768px) {
  body.rd-framed:has(#main > .join-hero:not(:not(style, script, link, noscript, template) ~ *)) { --rdf-crop: 0px; }
}
body.rd-framed #main { margin-top: calc(-1 * var(--rdf-crop)); }

/* Sticky rails sat 100px down to clear the fixed nav; nothing is fixed now.
   (site/market_map.html measures the nav itself and already falls back to 12px.) */
body.rd-framed .blog-sidebar,
body.rd-framed .blog-index-sidebar { top: 24px; }
/* In-page links: land with the heading clear of the top edge (was 90px for the nav). */
body.rd-framed #main [id] { scroll-margin-top: 16px; }

/* ---------- 3. display face on the old pages' headings and stat numerals ----------
   Only the face and its weight change: sizes, colours and spacing stay the
   page's own. !important because the pages set `font-weight: 800` on their
   headings from many selectors (and CMS bodies inline it); Fraunces is drawn
   for 400. Left on the old face: the market map's 13px uppercase section
   labels (.mm-sec h3), which are labels, not display text. */
body.rd-framed #main :is(h1, h2, h3):not(.mm-sec h3) {
  font-family: var(--rd-serif) !important;
  font-weight: 400 !important;
}
body.rd-framed #main :is(
    .stat-item .stat-number, .sp-stat .n, .hvt-stat-num, .hp-count-num, .hero-stat .num,
    .cmp-stat .sv, .lux-stat .sv, .sold-stat .sv, .snap-num, .sell-results .result-number) {
  font-family: var(--rd-serif) !important;
  font-weight: 400 !important;
  font-variant-numeric: lining-nums;
}

/* ---------- 4. standalone pages (body.rd-framed--own) ----------
   partials/_site_nav.html and str_rules_hub.html printed a fixed nav of their
   own; public/str_compare.html made the same partial sticky and in the flow.

   Room for the fixed nav: the STR rules hub and the seven county pages open
   with <header class="hero"> (top padding 7rem / 8rem above 768px). Above
   768px that hero is pulled up 80px under the header, leaving 41px (hub) and
   51px (county pages) between the header and the first line. At 768px and
   below their heroes left no room (the first line sat under the old nav:
   57px and 43px from the top), so nothing is pulled up there. The hero must
   come straight after the header's own anchor and script, so anything a page
   prints above its hero switches the pull-up off. str_compare needs none. */
@media (min-width: 769px) {
  body.rd-framed--own > #rd-frame-content + script + header.hero { margin-top: -80px; }
}
body.rd-framed--own [id]:not(.rd-frame *) { scroll-margin-top: 16px; }
body.rd-framed--own :is(h1, h2, h3):not(.rd-frame *) {
  font-family: var(--rd-serif) !important;
  font-weight: 400 !important;
}
