/* Related Markets (economics/related-markets.php). Builds on market-graph.css (the curves' colours, the
   controls). On a laptop or desktop: market A and market B side by side, filling the height, with the
   results under them and the controls and the step-by-step story on the right. On tablets and phones
   it stacks and the page scrolls. Theme tokens only (the curve colours are market-graph.css's). */

.rm-stage{flex:1;min-height:0;display:grid;grid-template-columns:minmax(0,1fr) minmax(290px,340px);gap:12px}
.rm-graphs{display:flex;flex-direction:column;gap:6px;padding:10px 12px;min-height:0;min-width:0}
.rm-graph-head{display:flex;align-items:center;justify-content:space-between;gap:6px 14px;flex-wrap:wrap;flex:none}
.rm-graph-head > *{min-width:0;max-width:100%}
.rm-pair{flex:1;min-height:0;display:grid;grid-template-columns:minmax(0,1fr) 34px minmax(0,1fr);gap:4px;align-items:stretch}
.rm-box{position:relative;min-height:0;min-width:0}
.rm-box svg{position:absolute;inset:0;width:100%;height:100%;display:block;background:var(--panel);border-radius:6px}

/* the link between the two markets */
.rm-link{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;color:var(--muted);font:700 13px/1 var(--font-mono)}
.rm-link-arrow{display:block;width:30px;height:30px;border-radius:50%;background:var(--panel-2);border:1px solid var(--line-strong);position:relative;transition:background .3s,border-color .3s}
.rm-link-arrow::after{content:"";position:absolute;left:9px;top:9px;width:9px;height:9px;border-top:3px solid currentColor;border-right:3px solid currentColor;transform:rotate(45deg)}
.rm-link.on{color:var(--hint)}
.rm-link.on .rm-link-arrow{background:var(--hint-tint);border-color:var(--hint)}
@media (prefers-reduced-motion:reduce){.rm-link-arrow{transition:none}}

/* the results */
.rm-results{flex:none;overflow-x:auto}
table.rm-table{width:100%;border-collapse:collapse;font-size:13px}
table.rm-table th,table.rm-table td{padding:4px 7px;border-bottom:1px solid var(--line);text-align:left;white-space:nowrap}
table.rm-table thead th{font:600 10.5px/1.2 var(--font-display);letter-spacing:.06em;text-transform:uppercase;color:var(--muted)}
table.rm-table tbody th{font:600 13px/1.3 var(--font-display);color:var(--ink);text-transform:none;letter-spacing:normal}
table.rm-table td{font:500 13px/1.3 var(--font-mono);font-variant-numeric:tabular-nums;color:var(--ink)}
table.rm-table td:nth-child(2){font-family:var(--font-body);color:var(--ink-soft)}
table.rm-table tr:last-child th,table.rm-table tr:last-child td{border-bottom:0}
.rm-d{font-weight:700}
.rm-up{color:var(--ok)}
.rm-down{color:var(--bad)}

.rm-side{gap:10px}
.rm-side > section{display:flex;flex-direction:column;gap:7px}
.rm-side > section + section{border-top:1px solid var(--line);padding-top:10px}
.rm-side p{margin:0;font-size:13px;line-height:1.45;color:var(--ink-soft)}
.rm-side p[hidden]{display:none}
.rm-chain{margin:0;padding:0 0 0 18px;font-size:13px;line-height:1.45;color:var(--ink);display:flex;flex-direction:column;gap:4px}
.rm-chain li::marker{color:var(--accent-deep);font-weight:700}

/* the legend */
.mg-legend i.rm-sw-d{background:var(--curve-d);height:4px;border-radius:2px}
.mg-legend i.rm-sw-s{background:var(--curve-s);height:4px;border-radius:2px}
.mg-legend i.rm-sw-old{height:0;border-top:2px dashed var(--muted);border-radius:0}

/* the diagrams */
.rm-grid{stroke-width:1;stroke-dasharray:3 5;opacity:.7}
.rm-title{font:700 15px/1 var(--font-display);fill:var(--ink)}
.rm-bold{font-weight:700}
.rm-drop{stroke-width:1.3}
.rm-drop-0{opacity:.55}
.rm-shift{stroke:var(--hint);stroke-width:3}
.rm-arrowhead{fill:var(--hint)}

@media (max-width:1300px){
  .rm-stage{grid-template-columns:minmax(0,1fr) minmax(280px,310px)}
}
@media (min-width:901px) and (max-width:1150px){
  table.rm-table th,table.rm-table td{padding:3px 4px;font-size:12px}
  table.rm-table td:nth-child(2){white-space:normal}
}
@media (max-width:900px){
  .rm-stage{display:flex;flex-direction:column}
  .rm-pair{display:flex;flex-direction:column;gap:6px}
  .rm-box svg{position:static;height:auto}
  .rm-link{flex-direction:row}
  .rm-link-arrow{transform:rotate(90deg)}
}
@media (max-width:640px){
  .rm-graphs{padding:8px 6px}
  .rm-graph-head{padding:0 4px}
  .rm-title{font-size:20px}
  table.rm-table td:nth-child(2){white-space:normal}
}

/* short windows: the legend gives its height to the diagrams */
@media (min-width:901px) and (max-height:700px){
  .rm-graph-head .mg-legend{display:none}
}
/* phones: the title bar's four links scroll sideways rather than overflow; the results become cards */
@media (max-width:640px){
  .rp-controls .seg-toggle[data-name="case"]{max-width:100%;overflow-x:auto;scrollbar-width:none}
  .rp-controls .seg-toggle[data-name="case"]::-webkit-scrollbar{display:none}
  .rm-results{overflow:visible}
  table.rm-table thead{display:none}
  table.rm-table,table.rm-table tbody{display:block}
  table.rm-table tr{display:grid;grid-template-columns:1fr 1fr;gap:3px 12px;padding:6px 2px;border-bottom:1px solid var(--line)}
  table.rm-table tr:last-child{border-bottom:0}
  table.rm-table tbody th,table.rm-table td{display:flex;justify-content:space-between;align-items:baseline;gap:6px;padding:0;border:0;white-space:normal}
  table.rm-table tbody th{grid-column:1 / -1;font-size:14px}
  table.rm-table td:nth-child(2){grid-column:1 / -1;justify-content:flex-start}
  table.rm-table td::before{content:attr(data-label);font:600 11.5px/1.3 var(--font-display);color:var(--muted)}
}
