/* ============================================================================
   Factor Dashboard — grid-paper / statistician's-notebook design system.
   Mostly black/white/gray; ledger-indigo accent used ONLY for interaction
   state (active toggle, sorted column, hover, long-side weight bars).
   ============================================================================ */
:root {
  --paper:      #fcfcfa;   /* warm near-white graph paper            */
  --paper-2:    #f7f7f4;
  --ink:        #1a1a1a;   /* primary text (not pure black)          */
  --ink-2:      #555555;   /* secondary / labels                     */
  --ink-3:      #8c8c8c;   /* tertiary / units / captions            */
  --rule:       #d6d6d0;   /* hairline rules                         */
  --rule-soft:  #e7e7e2;

  --grid-minor: rgba(38, 71, 128, 0.033);   /* 8px fine ruling (subtle)  */
  --grid-major: rgba(38, 71, 128, 0.060);   /* 64px heavy ruling         */
  --chart-grid: rgba(38, 71, 128, 0.10);    /* chart gridlines (readable) */
  --card: #ffffff;                          /* opaque panel/chart surface */
  --card-shadow: 0 1px 2px rgba(26, 26, 26, 0.05), 0 0 0 0.5px rgba(26, 26, 26, 0.02);

  --accent:     #2b4a8b;   /* ledger indigo — interaction only       */
  --accent-dim: rgba(43, 74, 139, 0.10);
  --accent-2:   rgba(43, 74, 139, 0.18);
  --neg:        #9b3b34;   /* muted oxblood — negatives / short bars  */

  --mono: "IBM Plex Mono", "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --serif: "Iowan Old Style", "Charter", Georgia, "Times New Roman", serif;
  --grot: "Inter", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --ruler: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--grot);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body {
  /* the grid paper: minor 8px + major 64px, both axes. min-height:100vh +
     fixed attachment make it cover the whole page edge-to-edge, top-to-bottom,
     regardless of how little content a page has. */
  min-height: 100vh;
  background-image:
    linear-gradient(var(--grid-minor) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-minor) 1px, transparent 1px),
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px);
  background-size: 8px 8px, 8px 8px, 64px 64px, 64px 64px;
  background-position: -1px -1px;
  background-attachment: fixed;
}

.sheet { max-width: 1080px; margin: 0 auto; padding: 40px 28px 64px; }

/* ── typography ───────────────────────────────────────────────────────── */
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; color: var(--ink); margin: 0; }
h1 { font-size: 27px; line-height: 1.12; }
h2 { font-size: 17px; margin: 40px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--rule); }
h3 { font-size: 13px; }
p  { margin: 8px 0; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.label  { font-family: var(--grot); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); }
.citation { font-family: var(--serif); font-style: italic; color: var(--ink-2); font-size: 13.5px; }
.lede  { color: var(--ink-2); max-width: 70ch; font-size: 13.5px; }
.muted { color: var(--ink-3); }

/* masthead */
.masthead { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.masthead .asof { font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.crumbs { font-family: var(--mono); font-size: 12px; color: var(--ink-3); margin-bottom: 18px; }
.crumbs a { color: var(--ink-2); }

/* numerals: mono + tabular so columns align to the pixel */
.num, td.num, th.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "zero" 1;
  text-align: right;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

/* ── tables ───────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
thead th {
  font-family: var(--grot); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-2);
  text-align: left; padding: 8px 10px; border-bottom: 1.5px solid var(--ink); white-space: nowrap;
}
thead th.num { text-align: right; }
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--accent); }
tbody td { padding: 6px 10px; border-bottom: 1px solid var(--rule-soft); font-size: 13px; }
tbody tr:hover { background: var(--accent-dim); }
tr.clickrow { cursor: pointer; }

.pos { color: var(--ink); }
.neg { color: var(--neg); }

/* sorted column emphasis */
th.sorted, td.sorted { background: var(--accent-dim); }
thead th.sorted { color: var(--accent); }
thead th .caret { font-size: 9px; color: var(--accent); margin-left: 3px; }

/* benchmark reference rows: demoted, pinned below a rule */
tr.bench td { color: var(--ink-2); }
tr.bench .name { font-style: italic; }
tr.bench:hover { background: transparent; }
tr.bench-first td { border-top: 1.5px solid var(--rule); }

.rowname { font-weight: 600; color: var(--ink); }
.rowname a { color: var(--ink); }
.rowsub { color: var(--ink-3); font-size: 12px; }

/* ── toggle / segmented controls ──────────────────────────────────────── */
.controls { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; margin: 16px 0 14px; }
.ctl { display: flex; align-items: center; gap: 8px; }
.ctl > .label { margin-right: 2px; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 2px; overflow: hidden; background: var(--paper); }
.seg button {
  font-family: var(--mono); font-size: 12px; padding: 5px 12px;
  background: transparent; color: var(--ink-2); border: 0; border-right: 1px solid var(--rule);
  cursor: pointer; line-height: 1.4;
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.seg button:not([aria-pressed="true"]):hover { background: var(--accent-dim); color: var(--ink); }

/* ── panels / chart ───────────────────────────────────────────────────── */
.panel { border: 1px solid var(--rule); background: var(--card); box-shadow: var(--card-shadow); padding: 14px 16px; border-radius: 2px; }
.chart-wrap { border: 1px solid var(--rule); background: var(--card); box-shadow: var(--card-shadow); padding: 8px 10px 4px; border-radius: 2px; }
svg.chart { display: block; width: 100%; height: auto; }
.chart-axis { stroke: var(--rule); stroke-width: 1; shape-rendering: crispEdges; }
.chart-grid { stroke: var(--chart-grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart-tick { font-family: var(--mono); font-size: 10px; fill: var(--ink-3); }
.series-strategy { fill: none; stroke: var(--accent); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.series-spy { fill: none; stroke: var(--ink-2); stroke-width: 1.2; stroke-dasharray: 5 3; vector-effect: non-scaling-stroke; }
.series-qqq { fill: none; stroke: var(--ink-3); stroke-width: 1.2; stroke-dasharray: 2 3; vector-effect: non-scaling-stroke; }
.legend { font-family: var(--mono); font-size: 11px; color: var(--ink-2); display: flex; gap: 20px; margin: 8px 2px 2px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 18px; height: 0; border-top-width: 2px; border-top-style: solid; vertical-align: middle; margin-right: 6px; }
.legend .l-strategy i { border-color: var(--accent); }
.legend .l-spy i { border-color: var(--ink-2); border-top-style: dashed; }
.legend .l-qqq i { border-color: var(--ink-3); border-top-style: dotted; }

/* sparkline */
svg.spark { display: inline-block; vertical-align: middle; }
.spark path { fill: none; stroke: var(--ink-2); stroke-width: 1; vector-effect: non-scaling-stroke; }

/* ── holdings ─────────────────────────────────────────────────────────── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.two-col.single { grid-template-columns: 1fr; }
.legtitle { font-family: var(--grot); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-2); margin-bottom: 6px; }
.legtitle .gross { color: var(--ink-3); font-weight: 400; }
.wbar { display: inline-block; height: 6px; background: var(--accent); border-radius: 1px; vertical-align: middle; min-width: 1px; }
.wbar.short { background: var(--neg); }
.holdtab td { padding: 4px 8px; }
.sym { font-family: var(--mono); font-weight: 600; }

footer { margin-top: 48px; padding-top: 14px; border-top: 1px solid var(--rule); font-family: var(--mono); font-size: 11px; color: var(--ink-3); }

@media (max-width: 720px) {
  .two-col { grid-template-columns: 1fr; }
  .sheet { padding: 28px 16px 48px; }
  .hide-sm { display: none; }
}


/* ---- factor tiles (leaderboard header) ----------------------------------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 10px;
  margin: 0 0 22px;
}
.tile {
  background: var(--card);
  border: 1px solid var(--rule-soft);
  box-shadow: var(--card-shadow);
  border-radius: 3px;
  padding: 9px 10px 10px;
}
.tile-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 7px;
}
.tile-name {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.tile-n {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-3);
}
.tile-cells {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.tcell {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 6px;
  border-radius: 2px;
}
.tcell-k {
  font-size: 9.5px;
  color: var(--ink-2);
  letter-spacing: 0.04em;
}
.tcell-v {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 500;
}
.tcell-dark .tcell-k, .tcell-dark .tcell-v { color: #fff; }
