/* Tables: panels, tables, rating chips, bars, avatars, team marks.
 *
 * Nothing sits in a card. A section is a block under a thin rule with a
 * heading; a table is rows on the page.
 */

/* ============================================================= sections === */

.panel { position: relative; border-top: 1px solid var(--line); }
.card { padding: var(--sp-4) 0; border-top: 1px solid var(--line); }
.ph2 { padding: var(--sp-5) 0 var(--sp-3); font: 600 var(--fs-xl)/1.2 var(--sans); letter-spacing: var(--snug); }
.sec { padding: 0 0 var(--sp-4); }
.sec > .ph2 { margin: 0; }
.sec > .section-title { margin: var(--sp-4) 0 var(--sp-3); }
/* it wraps: on a narrow screen a count or a link drops under the words whole */
.section-title {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--sp-2);
  font: 600 var(--fs-xl)/1.2 var(--sans); letter-spacing: var(--snug); color: var(--ink);
}
/* a bare heading over a table or a list keeps clear of it; zero specificity,
 * so every heading with its own spacing above keeps that */
:where(.page > .section-title, .page > section > .section-title, .pview > .section-title) { margin-bottom: var(--sp-2); }
.panel .pad { margin: 0; padding: var(--sp-2) 0 var(--sp-3); }

/* a board's table panel: toolbar, the scrolling table, the legend */
.tablewrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tbar { display: flex; align-items: center; gap: 10px; padding: var(--sp-3) 0; flex: none; flex-wrap: wrap; }
.tbar .cnt { color: var(--sub); }
.tbar .grow { margin-left: auto; }
.tbar .section-title { margin: 0; }
/* position: relative makes each scroller the containing block for absolutely
 * positioned descendants (.sr-only labels in cells), so its overflow clips
 * them instead of letting them widen the page. */
.scroll { flex: 1; min-height: 0; overflow: auto; position: relative; }
/* a row link that takes focus stops clear of the pinned header and the edge,
 * so its ring is whole */
.scroll { scroll-padding: var(--sp-16) 0 var(--sp-2); }
.table-wrap { position: relative; overflow: auto; }
/* a table that is its own panel: the rule under its header is the only rule */
.table-wrap.panel { border-top: 0; }
/* a board whose content is several panels scrolls as one column */
.stack { position: relative; flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: var(--sp-3); }
.stack > * { flex: none; }
.stack > .stats.figs, .stack > .note, .stack > .section-title { margin: 0; }

/* =============================================================== tables ===
 * `table.data` is listed beside the bare element so both spellings style the
 * same; cell colour sits at zero specificity so <td class="muted"> and the
 * sign classes still take effect. */

table, table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
table th, table.data th {
  padding: var(--sp-2); text-align: left; white-space: nowrap;
  font: 500 var(--fs-2xs)/1.3 var(--sans); color: var(--sub); background: var(--paper);
  border-bottom: 1px solid var(--line);
}
table td, table.data td {
  height: var(--row-h); padding: 6px var(--sp-2); white-space: nowrap;
  border-top: 0; border-bottom: 1px solid var(--line-2);
}
/* A row's own header cell takes the row rule, and the row's hover fill shows
 * through it. The last row ends on the space under the table, not on a rule
 * (the next section brings its own). */
table tbody th, table.data tbody th { border-bottom-color: var(--line-2); background: transparent; }
table tbody tr:last-child > td, table tbody tr:last-child > th { border-bottom: 0; }
/* a long text label that may wrap so the number beside it stays on screen */
table td.wrap, table.data td.wrap { white-space: normal; min-width: 9em; overflow-wrap: break-word; }
:where(table td) { color: var(--ink); }
table tbody tr, table.data tbody tr { background: transparent; transition: background-color 120ms var(--ease); }
table tbody tr:hover, table.data tbody tr:hover { background: var(--fill); }
/* a row that leads somewhere is one big target (the script in base.html) */
tbody tr:has(a[href]):not(:has(form, button, input)) { cursor: pointer; }
td a:hover, th a:hover, .player a:hover { text-decoration: underline; text-underline-offset: 3px; }
td .link, th .link { text-decoration: none; }
td a[href^="/players/"], td a[href^="/college/players/"], .player a { font-weight: 500; }

/* sticky grouped header: a group row over the column row */
.scroll thead th { position: sticky; top: 0; z-index: 1; }
.scroll thead tr.grp th { top: 0; height: 28px; padding: 6px var(--sp-2) 0; text-align: center; border-bottom: 0; }
.scroll thead tr.grp th.g { box-shadow: inset 0 -1px 0 var(--line); }
/* Only a column row under a group row drops below it. A single-row header
 * stays at top: 0, or it would hang low and cover the first body row. */
.scroll thead tr.grp + tr th { top: 28px; }
/* With border-collapse a sticky cell's border stays behind in the table, so
 * the rule under the column row vanishes once the body scrolls. An inset
 * shadow is painted by the cell itself and travels with it. */
.scroll thead tr:last-child th { border-bottom: 0; box-shadow: inset 0 -1px 0 var(--line); }

/* sort state: aria-sort is the contract; .sorted kept for static mockups */
th[aria-sort="descending"], th[aria-sort="ascending"], th.sorted { color: var(--ink); }
th[aria-sort="descending"]::after, th.sorted::after { content: " \25BC"; font-size: 8px; }
th[aria-sort="ascending"]::after { content: " \25B2"; font-size: 8px; }
th a { color: inherit; text-decoration: none; cursor: pointer; }
th a:hover { color: var(--ink); }

/* home-team row */
tbody tr.mine, table.data tbody tr.mine, table.data tbody tr.is-subject { background: var(--mine); }
tbody tr.mine:hover, table.data tbody tr.mine:hover, table.data tbody tr.is-subject:hover { background: var(--mine-hov); }
.mine-key { display: inline-block; width: 10px; height: 10px; margin-right: 4px; vertical-align: -1px; background: var(--mine); border: 1px solid var(--mine-rule); }

.r, table.data .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.c { text-align: center; }
.rk { color: var(--sub); width: 30px; }
table.data .empty, td.empty { padding: var(--sp-5); text-align: center; color: var(--sub); white-space: normal; }
table.data tr.div-row th {
  position: static; padding: var(--sp-5) var(--sp-2) var(--sp-2); text-align: left;
  color: var(--ink); font-size: var(--fs-sm); font-weight: 600; border-bottom: 1px solid var(--line);
}

/* player cell: avatar + name link + meta line */
.player { display: flex; align-items: center; gap: 10px; min-width: 0; }
.player > div { min-width: 0; }
.player small { display: block; color: var(--sub); font-size: var(--fs-xs); }
.pos-label { font-size: var(--fs-xs); font-weight: 500; color: var(--sub); }
.pctl { font-size: var(--fs-xs); color: var(--sub); }
.war-cell { display: inline-flex; align-items: center; gap: var(--sp-2); }

/* The image and its fallback share one box, so a failed headshot swaps to
 * initials with no layout shift. */
.avatar, .avatar-fb { width: 30px; height: 30px; flex: none; border-radius: 50%; background: var(--fill); }
.avatar { object-fit: cover; object-position: top; }
.avatar-fb { display: inline-flex; align-items: center; justify-content: center; color: var(--sub); font: 600 var(--fs-2xs)/1 var(--sans); user-select: none; }
.avatar[hidden], .avatar-fb[hidden] { display: none; }

/* middle, not baseline: an inline-flex box sits on its logo's bottom edge,
 * which lifts the abbreviation above the names beside it */
.tm { display: inline-flex; align-items: center; gap: 6px; vertical-align: middle; font-weight: 500; font-size: var(--fs-xs); color: var(--sub); white-space: nowrap; }
.tm img { width: 20px; height: 20px; flex: none; object-fit: contain; }
a.tm { border-radius: var(--r-sm); }
a.tm:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
/* club abbreviation chip: colours arrive via style="--club:..;--club2:.." */
.tm-fb {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 20px; height: 20px; border-radius: var(--r-sm);
  background: var(--club); color: var(--paper); box-shadow: inset 0 -3px 0 var(--club2);
  font: 700 8px/1 var(--sans);
  /* white on a light primary (NO gold, PIT yellow) is unreadable without it */
  text-shadow: 0 0 2px rgba(0, 0, 0, .6), 0 1px 1px rgba(0, 0, 0, .4);
}
.logos .tm-fb { width: 100%; height: 100%; }

/* ========================================================= rating chips ===
 * Colour plus the number, always: the chip text is the value. The top step
 * is solid; the rest are a tint with dark text. */

.tier {
  display: inline-block; min-width: 44px; padding: 2px var(--sp-2); text-align: center;
  border-radius: var(--r-sm); background: var(--fill); color: var(--sub);
  font-size: var(--fs-xs); font-weight: 600; font-variant-numeric: tabular-nums;
}
.tier.elite { background: var(--t-elite); color: var(--t-elite-ink); }
.tier.high { background: var(--t-high-bg); color: var(--t-high-ink); }
.tier.avg { background: var(--t-avg-bg); color: var(--t-avg-ink); }
.tier.below { background: var(--t-below-bg); color: var(--t-below-ink); }
.tier.poor { background: var(--t-poor-bg); color: var(--t-poor-ink); }
.tier-none, .tier.tier-none { background: var(--fill); color: var(--sub); }
.tier-none:empty::before { content: "\2014"; }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) 14px; padding: var(--sp-3) 0; color: var(--sub); font-size: var(--fs-2xs); flex: none; }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 4px; vertical-align: -1px; border-radius: 3px; background: var(--t-none); }
.legend i.elite { background: var(--t-elite); }
.legend i.high { background: var(--t-high); }
.legend i.avg { background: var(--t-avg); }
.legend i.below { background: var(--t-below); }
.legend i.poor { background: var(--t-poor); }
.legend .src { margin-left: auto; }

/* interval bar: a picture of the range beside the numbers, never instead */
.ci { position: relative; display: inline-block; vertical-align: middle; width: 130px; height: 6px; background: var(--line-2); border-radius: var(--r-pill); }
.ci i { position: absolute; top: 0; bottom: 0; background: var(--t-none); border-radius: var(--r-pill); }
.ci b { position: absolute; top: -3px; width: 2px; height: 12px; margin-left: -1px; background: var(--ink); }
.ci-cell { display: inline-flex; align-items: center; gap: var(--sp-2); }

/* ============================================================== figures ===
 * A row of labelled figures, each behind a thin rule. */
.stats { display: grid; gap: var(--sp-4) 0; }
.stat { padding: 0 var(--sp-5); border-left: 1px solid var(--line); }
.stat dt { font: 400 var(--fs-2xs)/1.3 var(--sans); color: var(--sub); }
.stat dd { margin-top: 2px; font-size: var(--fs-lg); font-weight: 600; letter-spacing: var(--snug); font-variant-numeric: tabular-nums; }
:where(.stat dd) { color: var(--ink); }    /* zero specificity: .pos/.neg on the dd win */
.stat dd.small { font-size: var(--fs-md); font-weight: 400; color: var(--sub); }
/* summary figures above a table: one row of four, two on a narrow screen */
.stats.figs { grid-template-columns: repeat(4, minmax(0, 1fr)); flex: none; margin: 0 0 var(--sp-4); }
.refresh-stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-top: var(--sp-2); }
.kv.kv-tight { padding: var(--sp-1) 0; font-size: var(--fs-sm); }

/* depth chart: one compact block per position group */
.depth-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: var(--sp-4) var(--sp-8); align-items: start; }
.depth-grp .ph2 { margin: 0; font-size: var(--fs-lg); }
/* stacked tables of one group are parted by space; each header keeps one rule */
.depth-grp table.depth-table + table.depth-table { margin-top: var(--sp-3); }
.depth-grp table.depth-table td, .depth-grp table.depth-table th { height: auto; padding: 6px var(--sp-2); }

/* ============================================== columns and card views ===
 * A Columns menu's checkboxes hide column groups; Table | Cards redraws the
 * rows as cards. Both are CSS only. */
.tablewrap:has(.colt-usage:not(:checked)) .c-usage,
.tablewrap:has(.colt-contract:not(:checked)) .c-contract,
.tablewrap:has(.colt-value:not(:checked)) .c-value,
.tablewrap:has(.colt-volume:not(:checked)) .c-volume,
.tablewrap:has(.colt-efficiency:not(:checked)) .c-efficiency,
.tablewrap:has(.colt-yac:not(:checked)) .c-yac,
.tablewrap:has(.colt-charted:not(:checked)) .c-charted,
.tablewrap:has(.colt-tracking:not(:checked)) .c-tracking,
.tablewrap:has(.colt-advanced:not(:checked)) .c-advanced { display: none; }

.tablewrap:has(.view-cards:checked) table.data { display: block; }
.tablewrap:has(.view-cards:checked) table.data thead { display: none; }
.tablewrap:has(.view-cards:checked) table.data tbody {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--sp-3); padding: var(--sp-3) 0;
}
.tablewrap:has(.view-cards:checked) table.data tbody tr {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 10px 12px;
  border: 1px solid var(--line-2); border-radius: var(--r);
}
.tablewrap:has(.view-cards:checked) table.data tbody td { height: auto; padding: 0; border: 0; }
.tablewrap:has(.view-cards:checked) table.data tbody td:has(.player) { flex-basis: 100%; order: -1; }
.tablewrap:has(.view-cards:checked) table.data tbody td.rk { order: -2; }
.tablewrap:has(.view-cards:checked) table.data tbody td.empty { flex-basis: 100%; }

/* ======================================================= feedback inbox ===
 * A note is free text: pasted URLs and paragraphs. It wraps anywhere inside a
 * bounded column so an unbroken string cannot push the Status column off
 * screen, and rows top-align so a long note never leaves the first screen
 * blank. Selectors carry `table.data` to outrank the base nowrap rule. */
table.data tr.fb-row td { vertical-align: top; }
table.data td.fb-note { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 18rem; max-width: 48rem; }
table.data td.fb-status { width: 1%; white-space: nowrap; }
table.data td.fb-status .btn { white-space: nowrap; }
/* The page is a user-supplied path of up to 500 characters. It wraps anywhere
 * inside a bounded block, with the full value in its title. The Status column
 * is pinned to the right edge of the scrolling table: pinned cells need an
 * opaque fill, and the header cell sits above the body cells. */
table.data .fb-clip { white-space: normal; overflow-wrap: anywhere; min-width: 8rem; max-width: 16rem; }
table.data .fb-status { position: sticky; right: 0; background: var(--paper); box-shadow: inset 1px 0 0 var(--line-2); }
table.data tbody tr:hover .fb-status { background: var(--fill); }
table.data th.fb-status { background: var(--paper); z-index: 2; }

@media (max-width: 860px) {
  .stats.figs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .depth-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  table th, table.data th, table td, table.data td { padding-left: 6px; padding-right: 6px; }
  table.data td.fb-note { min-width: 12rem; }
}
