/* Factors + Portfolio pages — builds on styles.css, history.css, analysis.css */
.q-main { max-width: 1320px; }
.q-lede { max-width: 860px; line-height: 1.55; margin: 0; color: var(--muted); font-size: 13px; }
.q-lede b { color: var(--text); font-weight: 500; }

/* builder */
.q-builder { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px 24px; align-items: start; }
.q-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 38px; padding: 6px 8px;
  background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--radius); }
.q-chips:focus-within { border-color: var(--accent); }
.q-chip { display: inline-flex; align-items: center; gap: 4px; font-family: var(--mono); font-size: 12px; padding: 3px 4px 3px 9px;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 999px; }
.q-chip button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 4px; font-size: 13px; line-height: 1; }
.q-chip button:hover { color: var(--down); }
.q-chips input { flex: 1; min-width: 160px; background: none; border: 0; outline: none; font-family: var(--mono); text-transform: uppercase; padding: 3px 4px; }
.q-quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.q-quick .lbl { font-size: 12px; color: var(--muted); margin-right: 2px; }
.q-quick button { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 2px 10px; font-size: 12px; cursor: pointer; }
.q-quick button:hover { color: var(--text); border-color: var(--line-2); }
.q-controls { display: grid; grid-template-columns: auto auto; gap: 8px 12px; align-items: center; font-size: 12px; }
.q-controls > span { color: var(--muted); text-align: right; white-space: nowrap; }
.q-num { display: inline-flex; align-items: center; gap: 6px; }
.q-num input { width: 62px; background: var(--bg); border: 1px solid var(--line-2); border-radius: 6px; padding: 4px 6px; font-family: var(--mono); font-size: 12px; text-align: right; }
.q-num input:focus { outline: none; border-color: var(--accent); }
.q-run { margin-top: 4px; }

/* method comparison */
.q-cmp { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.q-cmp th, .q-cmp td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.q-cmp th:first-child, .q-cmp td:first-child { text-align: left; color: var(--muted); font-weight: 400; }
.q-cmp thead th { font-weight: 500; color: var(--muted); font-size: 12px; cursor: pointer; border-bottom-color: var(--line-2); }
.q-cmp thead th .sw { width: 9px; height: 9px; border-radius: 2px; }
.q-cmp td { font-family: var(--mono); }
.q-cmp td:first-child { font-family: var(--sans); }
.q-cmp .sel { background: var(--panel-2); }
.q-cmp thead th.sel { color: var(--text); box-shadow: inset 0 2px 0 var(--accent); }
.q-cmp tr.best td.b { color: var(--accent); }
.q-cmp tbody tr:hover td { background: rgba(255,255,255,.02); }

/* weights */
.q-wrows { display: flex; flex-direction: column; gap: 2px; }
.q-wrow { display: grid; grid-template-columns: 110px minmax(0,1fr) 62px 62px; gap: 10px; align-items: center; padding: 4px 0; font-size: 12.5px; }
.q-wrow .s { font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-wrow .v { font-family: var(--mono); text-align: right; }
.q-bars { position: relative; display: flex; flex-direction: column; gap: 3px; }
.q-bar { height: 7px; border-radius: 2px; background: var(--line); overflow: hidden; }
.q-bar i { display: block; height: 100%; }
.q-bar.cap i { background: var(--text); opacity: .85; }
.q-bar.risk i { background: var(--accent); }
.q-wrow.head { color: var(--muted); font-size: 11px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.q-wrow.head .v { font-family: var(--sans); }
.q-key { display: flex; gap: 14px; font-size: 11.5px; color: var(--muted); }
.q-key i { display: inline-block; width: 12px; height: 6px; border-radius: 1px; margin-right: 5px; vertical-align: middle; }

/* frontier */
.q-front { fill: none; stroke: var(--text); stroke-width: 2; stroke-linejoin: round; }
.q-cml { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 5 4; opacity: .8; }
.q-asset { fill: var(--panel); stroke: var(--muted); stroke-width: 1.4; }
.q-alab { fill: var(--muted); font-family: var(--mono); font-size: 10px; }
.q-mark { stroke: var(--bg); stroke-width: 1.5; cursor: pointer; }
.q-mark.on { stroke: var(--text); stroke-width: 1.5; }
.q-hover { fill: none; stroke: var(--text); stroke-width: 1.5; pointer-events: none; }
.q-hit { cursor: crosshair; }
.q-fwrap { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 16px; }
.q-fside { font-size: 12.5px; border-left: 1px solid var(--line); padding-left: 16px; min-width: 0; }
.q-fside h3 { margin: 0 0 4px; font-size: 13px; font-weight: 600; }
.q-fside .row { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; font-family: var(--mono); font-size: 12px; }
.q-fside .row span:first-child { color: var(--muted); font-family: var(--sans); }
.q-mini { height: 5px; background: var(--line); border-radius: 2px; margin: 1px 0 4px; overflow: hidden; }
.q-mini i { display: block; height: 100%; background: var(--text); opacity: .8; }

/* heatmap */
.q-heat { display: grid; gap: 2px; font-family: var(--mono); font-size: 10.5px; overflow-x: auto; }
.q-hh { color: var(--muted); text-align: center; padding: 2px 0 4px; writing-mode: vertical-rl; transform: rotate(180deg); justify-self: center; max-height: 80px; white-space: nowrap; }
.q-hr { color: var(--muted); text-align: right; padding: 6px 8px 6px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-hc { text-align: center; padding: 6px 0; border-radius: 3px; color: var(--text); }
.q-scale { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); margin-top: 10px; }
.q-scale i { width: 120px; height: 7px; border-radius: 2px; background: linear-gradient(90deg, rgba(90,169,255,.85), rgba(90,169,255,0) 50%, rgba(233,162,59,0) 50%, rgba(233,162,59,.85)); }
.q-kv { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-top: 12px; }

/* tables */
.q-tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.q-tbl th, .q-tbl td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.q-tbl th { color: var(--muted); font-weight: 500; font-size: 11.5px; border-bottom-color: var(--line-2); }
.q-tbl th:first-child, .q-tbl td:first-child { text-align: left; }
.q-tbl td { font-family: var(--mono); }
.q-tbl td.nm { font-family: var(--sans); color: var(--muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.q-tbl td a { color: var(--text); text-decoration: none; }
.q-tbl td a:hover { color: var(--accent); }
.q-tbl th.grp { text-align: center; border-bottom: 1px solid var(--line); font-size: 11px; letter-spacing: .04em; }
.q-tbl td small { color: var(--muted); font-size: 10.5px; margin-left: 3px; }
.q-tbl td small.up { color: var(--up); }
.q-tbl td small.down { color: var(--down); }
.q-tbl td.nm { max-width: 150px; }
.q-tbl tbody tr:hover td { background: var(--panel-2); }
.q-sig { color: var(--accent); }

/* exposures */
.q-expo { display: flex; flex-direction: column; gap: 8px; }
.q-erow { display: grid; grid-template-columns: 120px minmax(0, 1fr) 54px; gap: 10px; align-items: center; font-size: 12.5px; }
.q-erow .v { font-family: var(--mono); text-align: right; }
.q-ebar { position: relative; height: 10px; background: var(--panel-2); border-radius: 2px; }
.q-ebar::before { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--line-2); }
.q-ebar i { position: absolute; top: 0; bottom: 0; border-radius: 2px; }

.q-notes { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.q-empty { padding: 26px 4px; color: var(--muted); }
.q-loading { opacity: .55; pointer-events: none; transition: opacity .15s; }
.q-hint { font-size: 12px; color: var(--muted); }
.q-method { font-size: 12px; color: var(--muted); line-height: 1.55; columns: 2 360px; column-gap: 32px; }
.q-method p { margin: 0 0 10px; break-inside: avoid; }
.q-method b { color: var(--text); font-weight: 500; }
.q-lists { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.q-list-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.q-list-head h3 { margin: 0; font-size: 13px; font-weight: 600; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; }
.link-btn:hover { text-decoration: underline; }

@media (max-width: 1000px) {
  .q-builder { grid-template-columns: 1fr; }
  .q-controls { grid-template-columns: auto 1fr; }
  .q-controls > span { text-align: left; }
  .q-fwrap { grid-template-columns: 1fr; }
  .q-fside { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 12px; }
  .q-lists { grid-template-columns: 1fr; }
  .q-kv { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .q-wrow { grid-template-columns: 84px minmax(0,1fr) 52px 52px; gap: 6px; }
  .q-erow { grid-template-columns: 96px minmax(0, 1fr) 48px; }
}