/* Site shell for the digital edition of
   "Macroprudential policies and homeownership rates".
   Layout: fixed top bar, left contents rail, 720px reading column. */

:root {
  --font-ui: "Bricolage Grotesque", "Helvetica Neue", Arial, system-ui, sans-serif;
  --font-serif: "Newsreader", Georgia, "Times New Roman", serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ink: #1c2224;
  --ink-soft: #4b5457;
  --muted: #667074;
  --muted-light: #8b9497;
  --accent: #c4452a;
  --accent-ink: #99361f;
  --annotation: #b8760a;
  --note: #1b6e7e;
  --note-tint: #1b6e7e14;
  --rule: #e2e5e0;
  --rule-strong: #c9cec6;
  --bg: #ffffff;
  --bg-panel: #f7f7f7;
  --bg-inset: #ececec;
  --bg-inset-hover: #e2e2e2;
  --header-h: 56px;
  --nav-w: 230px;
  --read-max: 720px;
  --wide-max: 1100px;
  --gutter: 2.5rem;
  /* chart tokens: the palette of the explorable deck (Presentation/03_ExplorableDeck/theme/deck.scss) */
  --series-1: #c4452a;
  --series-2: #1b6e7e;
  --series-3: #b8760a;
  --series-4: #6b4fa8;
  --series-5: #667074;
  --chart-grid: #e2e5e0;
  --chart-axis: #c9cec6;
  --chart-muted: #667074;
  --chart-ink: #1c2224;
  --chart-ink-2: #4b5457;
  --chart-surface: #ffffff;
  --neg: #c4452a;
  --pos: #1b6e7e;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
.skip { position: absolute; left: -999px; top: 0; background: #fff; padding: .5rem; }
.skip:focus { left: .5rem; z-index: 100; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-h);
  display: flex; align-items: center; gap: 1rem; padding: 0 1.25rem;
  background: rgba(255,255,255,.96); border-bottom: 1px solid var(--rule);
  z-index: 50; backdrop-filter: blur(6px);
}
.nav-toggle {
  display: none; font: inherit; font-size: 13px; font-weight: 500; color: var(--ink-soft);
  background: var(--bg-inset); border: 1px solid var(--rule-strong); border-radius: 4px;
  padding: .3rem .6rem; cursor: pointer;
}
.site-title { font-weight: 600; font-size: 14px; color: var(--ink); letter-spacing: .01em; }
.top-links { margin-left: auto; display: flex; gap: 1.25rem; font-size: 13px; }
.top-links a { color: var(--ink-soft); }

/* ---------- layout ---------- */
.layout { display: flex; padding-top: var(--header-h); min-height: 100vh; }
.sidebar {
  width: var(--nav-w); flex: none; position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h)); overflow-y: auto;
  border-right: 1px solid var(--rule); background: var(--bg-panel);
}
.sidebar-inner { padding: 1.25rem 1rem 2rem 1.25rem; }
.sidebar-title { display: block; font-family: var(--font-serif); font-weight: 600; font-size: 15px; line-height: 1.3; color: var(--ink); margin-bottom: 1rem; }
.nav-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.nav-list li a { display: flex; gap: .5rem; padding: .32rem .4rem .32rem .3rem; color: var(--ink-soft); border-radius: 4px; line-height: 1.3; }
.nav-list li a:hover { background: var(--bg-inset); text-decoration: none; }
.nav-list li.active a { color: var(--accent-ink); font-weight: 600; background: #c4452a14; }
.nav-num { flex: none; width: 2.2em; color: var(--muted-light); font-variant-numeric: tabular-nums; font-size: 12px; padding-top: 1px; }
.nav-list li.active .nav-num { color: var(--accent-ink); }
.nav-group { margin: 1rem 0 .3rem .3rem; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sidebar-foot { margin-top: 1.5rem; font-size: 11px; color: var(--muted-light); }

.main { flex: 1; min-width: 0; }
.read {
  max-width: var(--read-max); margin: 0 auto; padding: 2.5rem var(--gutter) 3rem;
  font-family: var(--font-serif); font-size: 16.5px; line-height: 1.7; color: var(--ink);
}
body.wide .read { max-width: var(--wide-max); }
.read p { margin: 0 0 1.1em; }
.read h1 { font-family: var(--font-ui); font-weight: 700; font-size: 30px; line-height: 1.2; margin: 0 0 1.2rem; letter-spacing: -.01em; }
.read h1 + h1 { margin-top: 3rem; }
.read h2 { font-family: var(--font-ui); font-weight: 600; font-size: 20px; line-height: 1.3; margin: 2.2rem 0 .8rem; }
.read h3 { font-family: var(--font-ui); font-weight: 600; font-size: 17px; margin: 1.8rem 0 .6rem; }
.read h4.runin { font-family: var(--font-ui); font-weight: 600; font-size: 15px; margin: 1.4rem 0 .3rem; }
.sec-num { display: inline-block; color: var(--muted-light); font-weight: 500; margin-right: .45em; }
h1 .sec-num:empty, h2 .sec-num:empty { display: none; }
.read h1 .sec-num { font-size: 22px; vertical-align: 3px; margin-right: .3em; }
.read h2 .sec-num { font-size: 15px; margin-right: .3em; }
.read .math.display { display: block; overflow-x: auto; margin: 1em 0; }
.read em { font-style: italic; }
.read ul, .read ol { padding-left: 1.4em; }
.read .cite { color: var(--accent-ink); }
.read a.xref { color: var(--accent-ink); }
.lead { font-size: 18px; color: var(--ink-soft); }

/* ---------- footnotes as inline notes ---------- */
.fn { display: inline; }
.fn-ref {
  font: inherit; font-family: var(--font-ui); font-size: 11px; font-weight: 600; line-height: 1;
  color: var(--note); background: var(--note-tint); border: 0; border-radius: 3px;
  padding: 2px 5px; margin: 0 2px; vertical-align: super; cursor: pointer;
}
.fn-ref[aria-expanded="true"] { background: var(--note); color: #fff; }
.fn-body {
  display: block; margin: .6em 0 1em; padding: .7em .9em; font-family: var(--font-ui);
  font-size: 13.5px; line-height: 1.55; color: var(--ink-soft);
  border-left: 3px solid var(--note); background: var(--note-tint); border-radius: 0 4px 4px 0;
}
.fn-body[hidden] { display: none; }
.fn-num { font-weight: 600; color: var(--note); margin-right: .3em; }
.fn-p { display: block; }
.fn-p + .fn-p { margin-top: .5em; }

/* ---------- figures ---------- */
.paper-figure {
  margin: 2rem calc(-1 * var(--gutter) / 2); padding: 1.2rem 1.25rem 1rem;
  border: 1px solid var(--rule); border-radius: 6px; background: var(--bg);
  font-family: var(--font-ui);
}
.fig-head, .tab-head { display: flex; gap: .6rem; align-items: baseline; margin-bottom: .5rem; font-size: 15px; line-height: 1.35; }
.fig-label, .tab-label { flex: none; font-weight: 700; color: var(--accent-ink); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
.fig-title, .tab-title { font-weight: 600; color: var(--ink); }
.fig-controls { display: flex; flex-wrap: wrap; gap: .4rem .9rem; align-items: center; margin: .2rem 0 .6rem; font-size: 12.5px; color: var(--ink-soft); }
.fig-controls:empty { display: none; }
.fig-chart { min-height: 120px; }
.fig-chart svg { display: block; max-width: 100%; height: auto; }
.fig-chart .chart-grid { display: grid; gap: .6rem 1rem; }
.fig-chart .chart-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.fig-chart .chart-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.fig-chart .chart-cell-title { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin: 0 0 .1rem; }
.fig-notes, .tab-notes { font-size: 12.5px; line-height: 1.5; color: var(--muted); margin-top: .8rem; }
.notes-label { font-weight: 600; color: var(--ink-soft); }
.fig-links { display: flex; flex-wrap: wrap; gap: .3rem 1rem; margin-top: .6rem; font-size: 12.5px; }
.fig-links a, .fig-links button { font: inherit; color: var(--accent-ink); background: none; border: 0; padding: 0; cursor: pointer; }
.fig-links button:hover, .fig-links a:hover { text-decoration: underline; }
.fig-static img { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.fig-table table { width: 100%; }

/* ---------- tables ---------- */
.paper-table {
  margin: 2rem calc(-1 * var(--gutter) / 2); padding: 1.2rem 1.25rem 1rem;
  border: 1px solid var(--rule); border-radius: 6px; font-family: var(--font-ui);
}
.tab-scroll { overflow-x: auto; }
table { border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.est, .paper-table table, .data-table, .fig-table table { width: 100%; }
th, td { padding: .3rem .5rem; text-align: right; vertical-align: top; border-bottom: 1px solid var(--rule); }
th { font-weight: 600; color: var(--ink-soft); }
th:first-child, td:first-child { text-align: left; }
thead th { border-bottom: 1px solid var(--rule-strong); }
tbody th[scope="row"] { font-weight: 400; }
tr.panel th { text-align: left; font-weight: 600; background: var(--bg-panel); color: var(--ink); padding-top: .5rem; }
tr.rule td, tr.rule th { border-top: 1px solid var(--rule-strong); }
td.se, th.se { color: var(--muted); }
sup { font-size: .7em; line-height: 0; }

/* ---------- prev / next ---------- */
.prevnext { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3.5rem; padding-top: 1.2rem; border-top: 1px solid var(--rule); font-family: var(--font-ui); }
.pn { display: flex; flex-direction: column; max-width: 48%; }
.pn.next { text-align: right; margin-left: auto; }
.pn-dir { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.pn-title { font-weight: 600; font-size: 14px; }
.pn:hover { text-decoration: none; }
.pn:hover .pn-title { text-decoration: underline; }

.site-foot { max-width: var(--read-max); margin: 0 auto; padding: 1rem var(--gutter) 3rem; font-size: 12px; color: var(--muted); line-height: 1.5; }
body.wide .site-foot { max-width: var(--wide-max); }

/* ---------- title page ---------- */
.titlepage { font-family: var(--font-ui); }
.edition { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 1rem; }
.titlepage h1.paper-title { font-size: 40px; line-height: 1.1; margin: 0 0 1rem; letter-spacing: -.02em; }
.byline { display: flex; flex-wrap: wrap; gap: 1.5rem; margin: 1rem 0 2rem; }
.byline .name { font-weight: 600; }
.byline .affil { color: var(--muted); font-size: 13px; }
.abstract { font-family: var(--font-serif); font-size: 16.5px; line-height: 1.7; }
.abstract h2 { font-family: var(--font-ui); font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 .5rem; }
.keywords { font-size: 13px; color: var(--muted); margin-top: 1rem; }
.cta { display: inline-flex; align-items: center; gap: .5rem; margin: 1.5rem 0; padding: .6rem 1rem; background: var(--accent); color: #fff; font-weight: 600; border-radius: 4px; font-size: 14px; }
.cta:hover { background: var(--accent-ink); text-decoration: none; }
.hero { margin: 2rem calc(-1 * var(--gutter) / 2) 1rem; padding: 1.25rem; border: 1px solid var(--rule); border-radius: 6px; }
.hero .fig-head { margin-bottom: .2rem; }
.hero-text { font-family: var(--font-serif); font-size: 15px; color: var(--ink-soft); margin: .4rem 0 .8rem; }
.howto { background: var(--bg-panel); border: 1px solid var(--rule); border-radius: 6px; padding: 1rem 1.25rem; font-size: 14px; margin: 2rem 0; }
.howto h2 { margin: 0 0 .5rem; font-size: 14px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.howto ul { margin: 0; padding-left: 1.2em; }
.howto li { margin: .25em 0; }

/* ---------- controls (pills, selects) ---------- */
.ctl { display: flex; flex-wrap: wrap; gap: .5rem 1.2rem; align-items: center; font-family: var(--font-ui); font-size: 13px; }
.ctl-group { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
.ctl-label { color: var(--muted); font-weight: 500; margin-right: .2rem; }
.pill {
  font: inherit; font-size: 12.5px; padding: .22rem .6rem; border-radius: 999px;
  border: 1px solid var(--rule-strong); background: #fff; color: var(--ink-soft); cursor: pointer; line-height: 1.2;
}
.pill:hover { background: var(--bg-inset); }
.pill[aria-pressed="true"], .pill.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill.dim { opacity: .55; }
select, input[type="search"], input[type="number"] {
  font: inherit; font-size: 13px; padding: .3rem .5rem; border: 1px solid var(--rule-strong); border-radius: 4px; background: #fff; color: var(--ink);
  max-width: 100%;
}
.ctl-group { max-width: 100%; min-width: 0; }
.panel .tab-scroll { overflow-x: auto; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; font-size: 12.5px; color: var(--ink-soft); margin: .3rem 0 .5rem; }
.legend .key { display: inline-flex; align-items: center; gap: .4rem; }
.legend .swatch { width: 18px; height: 3px; border-radius: 2px; display: inline-block; }
.legend .swatch.area { height: 10px; opacity: .35; }
.legend .swatch.dot { width: 9px; height: 9px; border-radius: 50%; }

/* tooltip */
.tip {
  position: fixed; pointer-events: none; z-index: 60; background: #fff; border: 1px solid var(--rule-strong);
  border-radius: 4px; box-shadow: 0 4px 16px #0000001f; padding: .45rem .6rem; font-family: var(--font-ui); font-size: 12px;
  color: var(--ink); max-width: 320px; line-height: 1.4;
}
.tip .t-title { font-weight: 600; margin-bottom: .2rem; }
.tip .t-row { display: flex; gap: .5rem; align-items: center; }
.tip .t-key { width: 14px; height: 3px; border-radius: 2px; flex: none; }
.tip .t-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.tip .t-lab { color: var(--muted); }

/* chart text */
.chart text { font-family: var(--font-ui); fill: var(--chart-ink-2); font-size: 11.5px; }
.chart .axis path, .chart .axis line { stroke: var(--chart-axis); shape-rendering: crispEdges; }
.chart .grid line { stroke: var(--chart-grid); shape-rendering: crispEdges; }
.chart .grid path { display: none; }
.chart .zero { stroke: var(--chart-ink-2); stroke-width: 1; }
.chart .axis-title { fill: var(--chart-muted); font-size: 11px; }
.chart .label { font-size: 11px; fill: var(--chart-ink-2); }
.chart .annot { fill: var(--annotation); font-size: 11px; }

/* ---------- explorer layout ---------- */
.explorer h1 { font-family: var(--font-ui); }
.panel { border: 1px solid var(--rule); border-radius: 6px; padding: 1rem 1.25rem; margin: 1.2rem 0; font-family: var(--font-ui); background: #fff; }
.panel h2 { font-family: var(--font-ui); font-size: 16px; margin: 0 0 .6rem; }
.panel h3 { font-family: var(--font-ui); font-size: 13.5px; margin: 1rem 0 .4rem; color: var(--ink-soft); }
.panel p { font-family: var(--font-ui); font-size: 13.5px; color: var(--ink-soft); margin: 0 0 .7em; }
.panel.sticky-controls { position: sticky; top: calc(var(--header-h) + 8px); z-index: 10; background: #fff; box-shadow: 0 4px 12px #0000000d; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; margin: .6rem 0 1rem; }
.stat { background: var(--bg-panel); border-radius: 6px; padding: .6rem .8rem; }
.stat .label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 22px; font-weight: 600; line-height: 1.2; margin-top: .15rem; }
.stat .sub { font-size: 12px; color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.spec-summary { font-size: 13px; color: var(--ink-soft); }
.spec-summary strong { color: var(--ink); }
.indicator-row text { font-size: 10.5px; }
.data-table th { position: sticky; top: 0; background: #fff; }
.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--rule); border-radius: 4px; }
.table-wrap table { font-size: 12.5px; }
.pager { display: flex; gap: .6rem; align-items: center; font-size: 13px; margin: .6rem 0; font-family: var(--font-ui); }
.pager button { font: inherit; font-size: 12.5px; padding: .2rem .55rem; border: 1px solid var(--rule-strong); background: #fff; border-radius: 4px; cursor: pointer; }
.pager button:disabled { opacity: .4; cursor: default; }
.row-detail { background: var(--bg-panel); font-size: 12.5px; color: var(--ink-soft); }
.row-detail td { white-space: normal; }
.expand { font: inherit; font-size: 12px; color: var(--accent-ink); background: none; border: 0; padding: 0; cursor: pointer; }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 999px; background: var(--bg-inset); color: var(--ink-soft); }
.badge.t { background: #fde8dd; color: #9a3c12; }
.badge.l { background: #dff3ea; color: #146c43; }
.badge.z { background: var(--bg-inset); }
.note-box { border-left: 3px solid var(--annotation); background: #fff7ee; padding: .6rem .9rem; font-size: 13.5px; font-family: var(--font-ui); margin: 1rem 0; border-radius: 0 4px 4px 0; }
.faq h2 { font-family: var(--font-ui); font-size: 19px; margin-top: 2.2rem; }
.faq .q-link { font-size: 12px; color: var(--muted-light); margin-left: .4rem; }
pre, code { font-family: var(--font-mono); font-size: 12.5px; }
pre { background: var(--bg-panel); border: 1px solid var(--rule); border-radius: 4px; padding: .8rem 1rem; overflow-x: auto; line-height: 1.5; }
.read code { background: var(--bg-inset); padding: 0 .3em; border-radius: 3px; }
.read pre code { background: none; padding: 0; }
details { border: 1px solid var(--rule); border-radius: 4px; padding: .5rem .9rem; margin: .8rem 0; font-family: var(--font-ui); font-size: 14px; }
summary { cursor: pointer; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .paper-figure, .paper-table, .hero { margin-left: 0; margin-right: 0; }
}
@media (max-width: 900px) {
  .nav-toggle { display: inline-flex; align-items: center; gap: .4rem; }
  .site-title { display: none; }
  .sidebar { position: fixed; left: 0; top: var(--header-h); bottom: 0; transform: translateX(-100%); transition: transform .2s ease; z-index: 40; width: min(300px, 85vw); box-shadow: 0 4px 16px #0000001f; }
  .sidebar.open { transform: none; }
  .read { padding: 1.5rem 16px 2.5rem; font-size: 16px; }
  .site-foot { padding: 1rem 16px 3rem; }
  .fig-chart .chart-grid.cols-2, .fig-chart .chart-grid.cols-3 { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .titlepage h1.paper-title { font-size: 30px; }
  :root { --gutter: 16px; }
}
@media print {
  .topbar, .sidebar, .prevnext, .fig-links, .fig-controls { display: none; }
  .layout { padding-top: 0; }
  .read { max-width: none; }
}

/* ---------- additions for the FinancialAdvice_AI edition ---------- */
table.est td.al-left, table.est th.al-left { text-align: left; }
table.est td.al-center, table.est th.al-center { text-align: center; }
table.est td.al-right, table.est th.al-right { text-align: right; }
table.est thead th { text-align: center; }
table.est thead th:first-child { text-align: left; }
table.est tbody tr:first-child td { padding-top: .45rem; }
.tab-notes br { display: block; content: ""; margin-top: .35em; }
.prompt-box { background: var(--bg-panel); border: 1px solid var(--rule); border-radius: 4px; padding: .8rem 1rem; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; overflow-x: auto; }
.prompt-box .instr { color: var(--muted); }
.prompt-box .q { color: var(--ink); }
.prompt-meta { font-size: 12.5px; color: var(--muted); margin: .4rem 0 .6rem; }
.prompt-meta b { color: var(--ink-soft); }
.lang-tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #c4452a14; color: var(--accent-ink); margin-left: .4rem; }
.hero .legend { margin: .2rem 0 .4rem; }
.explorer .fig-chart { margin-top: .4rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; font-size: 13.5px; font-family: var(--font-ui); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.hl { background: #fff3cd; border-radius: 3px; padding: 0 .2em; }
/* ---------- run your own experiment ---------- */
.xp-row { margin: .5rem 0; }
.xp-arm { border-top: 1px solid var(--rule); padding: .8rem 0 .4rem; }
.xp-arm:first-child { border-top: 0; padding-top: 0; }
.xp-tag { font-weight: 700; color: var(--accent-ink); font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
.xp-arm textarea { display: block; width: 100%; box-sizing: border-box; margin-top: .5rem; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5; padding: .5rem .6rem; border: 1px solid var(--rule-strong); border-radius: 4px; resize: vertical; }
.xp-arm .xp-lib { max-width: 16rem; }
.xp-warn { color: var(--accent-ink); font-weight: 600; }
.xp button:disabled { opacity: .45; cursor: default; }
.xp ul { font-family: var(--font-ui); font-size: 13.5px; color: var(--ink-soft); padding-left: 1.2rem; }
.xp ul li { margin: .35rem 0; }
