/* ──────────────────────────────────────────────────────────────
   Project Matrix — "By the Numbers"
   Pie charts + filterable project table + mobile card view.
   Lives on kinzer-track-record.html (#by-the-numbers).
   Moved out of kinzer-our-story.html's inline <style>, 7.16.26.
   Requires: main.css (uses --blue, --light-line)
   ────────────────────────────────────────────────────────────── */

    /* ── Project Matrix ── */
    /* scroll-margin-top only needs to clear the fixed nav: the "Jump to" bar has
       already retired by this section. html{scroll-padding-top:80px} plus this
       section's 3rem top padding position the heading just under the nav. (The
       old 140px double-counted with scroll-padding and dropped the anchor too
       low, so clicking "By the Numbers" showed the previous section instead.) */
    .matrix-section     { padding: 3rem 5% 7rem; background: var(--color-surface-paper); border-top: 1px solid var(--color-border); scroll-margin-top: 0; }
    .matrix-inner       { max-width: 1200px; margin: 0 auto; }
    .matrix-head        { margin-bottom: 2.5rem; }
    .matrix-head p      { font-size: 1.125rem; letter-spacing: normal; text-transform: none; color: var(--color-accent-2); font-weight: 500; margin-bottom: 0.65rem; display: flex; align-items: center; gap: 0.75rem; }
    .matrix-head p:not(.matrix-head-sub)::before { content: ""; display: block; width: 1.5rem; height: 1px; background: var(--color-accent-2); }
    .matrix-head h2     { font-family: 'Libre Baskerville', serif; font-size: clamp(1.9rem, 3vw, 2.8rem); font-weight: 400; color: var(--color-text-primary); margin: 0 0 0.85rem; }
    .matrix-head h2 em  { font-style: italic; color: var(--color-accent); }
    .matrix-head-sub    { font-size: 0.97rem; color: rgba(var(--color-text-primary-rgb), 0.80); line-height: 1.75; letter-spacing: 0.01em; }
    .matrix-head-sub strong { color: var(--color-accent); font-weight: 700; }

    /* Headline stats above the pies (moved from the Our Story hero). */
    .bn-stats           { display: flex; flex-wrap: wrap; border: 1px solid var(--color-border); background: var(--color-surface-raised); margin-bottom: 2.5rem; }
    .bn-stat            { flex: 1 1 0; min-width: 160px; padding: 1.5rem 1.75rem; text-align: center; border-right: 1px solid var(--color-border); }
    .bn-stat:last-child { border-right: none; }
    .bn-stat-num        { font-family: 'Libre Baskerville', serif; font-size: 2.2rem; font-weight: 700; color: var(--color-display); line-height: 1; margin-bottom: 0.35rem; }
    .bn-stat-label      { font-size: 1.125rem; color: rgba(var(--color-text-primary-rgb), 0.9); }
    @media (max-width: 620px) {
      .bn-stat          { flex: 1 1 50%; min-width: 0; border-bottom: 1px solid var(--color-border); }
      .bn-stat:nth-child(2n) { border-right: none; }
      .bn-stat:nth-last-child(-n+2) { border-bottom: none; }
      .bn-stat-num      { font-size: 1.8rem; }
    }

    .matrix-ratios      { display: flex; flex-wrap: wrap; gap: 2rem 3rem; margin-bottom: 1.5rem; align-items: flex-start; }
    .matrix-pie-block   { display: flex; flex-direction: column; align-items: flex-start; gap: 0.5rem; }
    .matrix-pie-chart-row { display: flex; align-items: center; gap: 1.25rem; }
    .matrix-pie-title   { font-size: 1.125rem; letter-spacing: normal; text-transform: none; color: var(--color-accent); font-weight: 600; }
    .matrix-pie-legend  { display: flex; flex-direction: column; gap: 0.6rem; }
    .matrix-pie-legend-item { display: flex; align-items: center; gap: 0.65rem; font-size: 1rem; color: var(--color-text-primary); font-weight: 600; }
    .matrix-pie-legend-swatch { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
    @media (max-width: 600px) {
      .matrix-ratios { gap: 1.5rem; }
      .matrix-pie-chart-row { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
      .matrix-pie-block svg { width: 140px; height: 140px; }
      .matrix-pie-legend-item { font-size: 0.88rem; }
    }

    /* Filter buttons */
    .matrix-filters       { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; align-items: center; }
    .matrix-filters-label { font-size: 1.125rem; letter-spacing: normal; text-transform: none; color: rgba(var(--color-text-primary-rgb), 0.40); font-weight: 600; margin-right: 0.25rem; }
    .mfilter-btn          { font-family: 'Barlow', sans-serif; font-size: 0.58rem; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 600; padding: 0.45rem 1rem; border: 1.5px solid rgba(var(--color-text-primary-rgb), 0.18); background: transparent; color: rgba(var(--color-text-primary-rgb), 0.50); border-radius: 2px; cursor: pointer; transition: all 0.15s; }
    .mfilter-btn:hover    { border-color: var(--color-accent); color: var(--color-accent); }
    .mfilter-btn.active   { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-on-dark); }

    /* Table */
    .matrix-wrap        { border-radius: 4px; box-shadow: 0 2px 24px rgba(var(--color-text-primary-rgb), 0.08); overflow-x: auto; }
    .mtable             { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.92rem; min-width: 750px; background: var(--color-surface-raised); }
    .mtable thead       { background: var(--color-dark-surface); }
    .mtable thead th    { font-size: 1rem; letter-spacing: 0.08em; text-transform: uppercase; color: rgba(var(--color-on-dark-rgb), 0.90); font-weight: 600; padding: 1.35rem 1.1rem; text-align: center; white-space: nowrap; border-bottom: 3px solid var(--color-accent); cursor: default; background: var(--color-dark-surface); }
    .mtable thead th:first-child { text-align: left; padding-left: 1.5rem; color: var(--color-on-dark); position: sticky; left: 0; background: var(--color-dark-surface); z-index: 2; }
    .mtable td          { padding: 0.9rem 1.1rem; border-bottom: 1px solid rgba(var(--color-text-primary-rgb), 0.06); text-align: center; color: var(--color-text-primary); vertical-align: middle; transition: background 0.15s; font-size: 1rem; }
    .mtable td:first-child { position: sticky; left: 0; z-index: 1; text-align: left; font-weight: 500; padding-left: 1.5rem; min-width: 220px; background: var(--color-surface-raised); font-size: 1.02rem; }
    /* Zebra striping */
    .mtable tbody tr:nth-child(even) td            { background: var(--color-surface-warm); }
    .mtable tbody tr:nth-child(even) td:first-child { background: var(--color-surface-warm); }
    .mtable tbody tr:nth-child(odd)  td:first-child { background: var(--color-surface-raised); }
    /* Row hover */
    .mtable tbody tr:not(.msection):not(.mtotals):hover td            { background: rgba(var(--color-accent-rgb), 0.07) !important; }
    .mtable tbody tr:not(.msection):not(.mtotals):hover td:first-child { background: rgba(var(--color-accent-rgb), 0.07) !important; }
    /* Section header rows */
    .mtable .msection td            { background: var(--color-dark-surface) !important; color: rgba(var(--color-on-dark-rgb), 0.68); font-size: 1.02rem; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 700; padding: 0.75rem 1.1rem; border: none; cursor: pointer; user-select: none; }
    .mtable .msection td:first-child { background: var(--color-dark-surface) !important; padding-left: 1.5rem; }
    .mtable .msection td .section-toggle { float: right; opacity: 0.45; font-style: normal; display: inline-block; transition: transform 0.2s; }
    .mtable .msection.collapsed td .section-toggle { transform: rotate(-90deg); }
    /* Totals row */
    .mtable .mtotals td            { font-weight: 700; font-size: 0.9rem; border-top: 2px solid rgba(var(--color-text-primary-rgb), 0.10); border-bottom: none; background: var(--color-surface-raised) !important; padding: 1.1rem; color: var(--color-text-primary); }
    .mtable .mtotals td:first-child { background: var(--color-surface-raised) !important; padding-left: 1.5rem; color: rgba(var(--color-text-primary-rgb), 0.6); font-weight: 500; font-size: 0.82rem; letter-spacing: 0.05em; text-transform: uppercase; }
    /* Project links */
    /* Clickable company names.
       Color alone must NOT signal clickability — it confused reviewers. Every
       company name uses the same text color whether or not it links; the
       affordance is the explicit "View project →" label instead. */
    .mtable tr.has-study td:first-child a        { color: var(--color-text-primary); text-decoration: none; font-weight: 600; display: inline-flex; align-items: baseline; gap: 0; }
    .mtable tr.has-study td:first-child a:hover  { text-decoration: underline; }
    .mtable tr.has-study td:first-child a:hover::after,
    .mtable tr.has-study td:first-child a:hover::before { text-decoration: none; }
    /* "View project" label + a larger angled arrow. The arrow lives in ::before
       (reordered after the label with flex `order`) purely so it can be sized
       independently while both still recolor with var(--color-accent). */
    .mtable tr.has-study td:first-child a::after {
      content: "View project";
      order: 2;
      margin-left: 0.6rem;
      font-size: 0.92rem;
      font-weight: 800;
      letter-spacing: 0.04em;
      color: var(--color-accent-2);
      white-space: nowrap;
      text-decoration: none;
    }
    .mtable tr.has-study td:first-child a::before {
      content: "↗";
      order: 3;
      margin-left: 0.28rem;
      font-size: 1.3rem;
      line-height: 1;
      font-weight: 700;
      color: var(--color-accent-2);
      text-decoration: none;
    }
    /* Check / dash */
    .mcheck { color: var(--color-text-primary); font-size: 1.2rem; line-height: 1; font-weight: 700; }
    .mdash  { color: rgba(var(--color-text-primary-rgb), 0.18); font-size: 1rem; }
    /* Column highlight on header hover */
    .mtable td.col-highlight      { background: rgba(var(--color-accent-rgb), 0.09) !important; }
    .mtable thead th.col-highlight { background: var(--color-dark-highlight) !important; }
    /* Filter: collapse non-matching rows */
    .mtable.filtered tbody tr:not(.msection):not(.mtotals):not(.match) { display: none; }

    /* Legend */
    .matrix-legend      { display: flex; gap: 2rem; margin-top: 1.25rem; flex-wrap: wrap; }
    .matrix-legend-item { display: flex; align-items: center; gap: 0.45rem; font-size: 0.82rem; color: rgba(var(--color-text-primary-rgb), 0.60); letter-spacing: 0.04em; }
    .ml-dot             { width: 7px; height: 7px; border-radius: 50%; background: var(--color-accent); flex-shrink: 0; }
    .ml-check           { color: var(--color-accent); font-size: 0.95rem; line-height: 1; }

    /* Sticky section label (scrolls with table) */
    .msection-indicator         { display: none; position: sticky; top: 68px; z-index: 10; background: var(--color-dark-surface); color: rgba(var(--color-on-dark-rgb), 0.60); font-size: 1.125rem; letter-spacing: normal; text-transform: none; font-weight: 700; padding: 0.55rem 1.5rem; pointer-events: none; }
    .msection-indicator.active  { display: block; }

    /* ── Mobile card view ── */
    .mobile-portfolio   { display: none; border: 1px solid var(--color-border); border-radius: 4px; overflow: hidden; box-shadow: 0 2px 24px rgba(var(--color-text-primary-rgb), 0.08); }
    .mp-group-empty     { display: none; }
    .mp-head            { background: var(--color-dark-surface); color: rgba(var(--color-on-dark-rgb), 0.55); font-size: 1.125rem; letter-spacing: normal; text-transform: none; font-weight: 700; padding: 0.65rem 1rem; }
    .mp-row             { display: flex; flex-direction: column; align-items: stretch; padding: 0.8rem 1rem; font-size: 0.92rem; color: var(--color-text-primary); border-bottom: 1px solid rgba(var(--color-text-primary-rgb), 0.06); background: var(--color-surface-raised); text-decoration: none; font-weight: 400; }
    .mp-row:last-child  { border-bottom: none; }
    .mp-row.mp-hidden   { display: none; }
    .mp-group:nth-child(even) .mp-row { background: var(--color-surface-warm); }
    /* Same rule as the desktop table: name color is constant, the labelled
       arrow carries the affordance. Here .mp-arr is a real span, so the arrow
       itself can be set large rather than riding on the label's font-size. */
    .mp-row--link       { color: var(--color-text-primary); font-weight: 600; }
    .mp-row--link:hover { background: rgba(var(--color-accent-rgb), 0.06); }
    .mp-row-top         { display: flex; justify-content: space-between; align-items: center; }
    .mp-arr             { color: var(--color-accent); font-size: 1.4rem; font-weight: 800; line-height: 1; flex-shrink: 0; margin-left: 0.5rem; display: inline-flex; align-items: center; }
    .mp-arr::before     { content: "View project"; font-size: 0.75rem; font-weight: 800; letter-spacing: 0.04em; margin-right: 0.4rem; }
    .mp-tags            { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.35rem; }
    .mp-tag             { font-size: 1.125rem; letter-spacing: normal; text-transform: none; padding: 0.18rem 0.45rem; border-radius: 2px; font-weight: 600; }
    .mp-tag--hq         { background: rgba(var(--color-accent-rgb), 0.12); color: var(--color-accent); }
    .mp-tag--pub        { background: rgba(var(--color-text-primary-rgb), 0.07); color: rgba(var(--color-text-primary-rgb), 0.55); }
    .mp-tag--size       { border: 1px solid rgba(var(--color-text-primary-rgb), 0.16); color: rgba(var(--color-text-primary-rgb), 0.50); }

/* ── Responsive ── */
    @media (max-width: 768px) {
      .matrix-wrap      { display: none; }
      .matrix-legend    { display: none; }
      .mobile-portfolio { display: block; }
      .matrix-filters   { margin-bottom: 1rem; }
      .mfilter-btn      { min-height: 44px; font-size: 0.72rem; padding: 0.5rem 1rem; }
    }
