/* analytics-page.css - Analytics
 *
 * One strip with the views, the point mode and the lens (which tournaments every view
 * counts), then the active view: Dashboard, Leaderboard, Players or Register. Panels,
 * buttons and the page title reuse the st-* styles in css/setup-page.css; the tables are
 * NewtonTable's, styled in css/components.css. Uses the shared tokens in
 * css/design-tokens.css. Light only.
 *
 * Analytics is the one page made for phones too: club members open the analytics-only
 * instance on their phones. The phone layout is the @media block at the end.
 */

#history.page.active { display: block; background: var(--nt-bg); padding: 0; font-family: var(--nt-sans); color: var(--nt-ink); }

.an-wrap { max-width: var(--nt-page-wide); margin: 0 auto; padding: 28px 24px 40px; display: grid; gap: 16px; }
.an-lbl { font-size: 12px; font-weight: 600; color: var(--nt-muted); }
.an-title-tools { display: flex; align-items: center; gap: 8px 20px; flex-wrap: wrap; }
.an-maint { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.an-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.an-note { font-size: 13px; color: var(--nt-muted); }
.an-foot { padding: 10px 20px 12px; border-top: 1px solid var(--nt-line); font-size: 13px; color: var(--nt-muted); }

/* ---- the strip: views and points, then the lens ---- */
.an-strip { background: var(--nt-surface); border: 1px solid var(--nt-line); border-radius: 12px; }
.an-strip.an-filtered { border-color: #f0a07f; }
.an-strip-row { display: flex; align-items: center; justify-content: space-between; gap: 10px 20px; flex-wrap: wrap; padding: 12px 16px; }
.an-strip-row + .an-strip-row { border-top: 1px solid var(--nt-line); }
.an-strip .st-seg button { padding: 7px 14px; }
.an-points { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; position: relative; }
/* the focus ring inside the button, so the group's edge doesn't clip it */
.an-strip .st-seg button:focus-visible { outline-offset: -3px; }
/* Custom points: a small panel under the buttons */
.an-points-panel { position: absolute; top: calc(100% + 8px); right: 0; z-index: 20; width: 300px; max-width: calc(100vw - 32px); background: var(--nt-surface); border: 1px solid var(--nt-line-2); border-radius: 10px; box-shadow: 0 12px 32px rgba(17,24,39,.18); padding: 12px 14px; display: grid; gap: 10px; }
.an-points-panel[hidden] { display: none; }
.an-points-panel fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; }
.an-points-panel legend { padding: 0; margin-bottom: 4px; font-size: 12px; font-weight: 700; color: var(--nt-muted); }
.an-points-panel label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--nt-ink); cursor: pointer; }
.an-points-panel input { accent-color: var(--nt-header); width: 16px; height: 16px; margin: 0; }
.an-points-panel p { margin: 0; font-size: 12px; color: var(--nt-muted); }

/* how many tournaments are counted, and why */
.an-scope { display: flex; align-items: baseline; gap: 4px 10px; flex-wrap: wrap; }
.an-scope b { font-size: 15px; font-weight: 700; }
.an-scope b span { font-variant-numeric: tabular-nums; }
.an-filtered .an-scope b { color: #b2410f; }
.an-why { font-size: 13px; color: var(--nt-muted); }
.an-lens { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; }
.an-text { height: 34px; border: 1px solid var(--nt-line-2); border-radius: 8px; padding: 0 10px; background: var(--nt-surface); font: inherit; font-size: 14px; color: var(--nt-ink); min-width: 0; }
.an-text:focus { outline: none; border-color: var(--nt-ink-2); box-shadow: 0 0 0 3px var(--nt-inset); }
.an-text.an-name { width: 220px; }
.an-dates { display: inline-flex; align-items: center; gap: 6px; }
.an-dates .an-text { width: 150px; font-variant-numeric: tabular-nums; }

/* ---- the views ---- */
.analytics-view { display: none; }
.analytics-view.active { display: grid; gap: 12px; }
.analytics-placeholder { padding: 48px 24px; text-align: center; color: var(--nt-muted); }
.analytics-placeholder h3 { margin: 0 0 4px; font-size: 16px; color: var(--nt-ink); }
.analytics-placeholder p { margin: 0; }
.st-panel-head h3 small { font-variant-numeric: tabular-nums; }

/* Dashboard: one tile per number */
.an-tiles { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 12px; }
.an-tile { display: grid; gap: 2px; align-content: start; text-align: left; min-width: 0; padding: 14px 16px 16px; border-radius: 12px; border: 1px solid var(--nt-line); background: var(--nt-surface); font: inherit; color: var(--nt-ink); }
button.an-tile { cursor: pointer; }
button.an-tile:hover { border-color: var(--nt-ink-2); }
button.an-tile:focus-visible { outline: 2px solid var(--nt-accent); outline-offset: 2px; }
.an-tile-label { font-size: 12px; font-weight: 600; color: var(--nt-muted); }
.an-tile-value { font-size: 34px; font-weight: 800; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.an-tile-value small { font-size: 14px; font-weight: 600; letter-spacing: 0; color: var(--nt-muted); margin-left: 4px; }
.an-tile-sub { font-size: 13px; color: var(--nt-ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Dashboard: the top 10 and the latest tournaments under the tiles */
.an-dash-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }

/* Leaderboard: the top 16 end at a line */
.an-legend { display: inline-flex; align-items: center; font-size: 12px; color: var(--nt-muted); }
.an-legend i { display: inline-block; width: 18px; border-top: 2px solid var(--nt-ink-2); margin-right: 6px; }
.newton-table tr.an-cut td { border-bottom: 2px solid var(--nt-ink-2); }

/* Players: the list, and the profile or comparison */
.an-players { display: grid; grid-template-columns: 420px minmax(0, 1fr); gap: 16px; align-items: start; }
.an-prof-head { padding: 20px 20px 4px; }
.an-prof-head h3 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.an-prof-head p { margin: 2px 0 0; color: var(--nt-muted); }
.an-facts { display: flex; gap: 12px 28px; flex-wrap: wrap; margin: 0; padding: 8px 20px 18px; }
.an-facts > div { display: grid; }
.an-facts dt { font-size: 12px; color: var(--nt-muted); }
.an-facts dd { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.an-facts dd small { font-size: 12px; font-weight: 600; color: var(--nt-muted); margin-left: 3px; }
/* the profile's facts: a ruled grid */
.an-facts.an-facts--grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 0; margin: 12px 20px 16px; padding: 0; border: 1px solid var(--nt-line); border-radius: 10px; overflow: hidden; }
.an-facts--grid > div { padding: 10px 14px; box-shadow: 1px 0 0 var(--nt-line), 0 1px 0 var(--nt-line); }
/* placements, one box each */
.an-place { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin: 0 20px 18px; }
.an-place > div { border-radius: 8px; border: 1px solid var(--nt-line); background: var(--nt-surface-2); padding: 8px 10px; text-align: center; }
.an-place dt { font-size: 12px; font-weight: 600; color: var(--nt-muted); }
.an-place dd { margin: 0; font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.an-place .an-zero dd { color: var(--nt-faint); font-weight: 600; }
.an-sub { margin: 0; padding: 4px 20px 10px; font-size: 13px; font-weight: 700; color: var(--nt-ink-2); }
.st-pill.an-first { background: var(--nt-ok-soft); color: var(--nt-ok); }

/* unticked tournaments and players are dimmed */
.newton-table tr.an-off td:not(:first-child) { color: var(--nt-faint); }
.newton-table tr.an-off .nt-name { color: var(--nt-muted); font-weight: 500; }

/* Register: tabs, the path back, and the tables */
.an-reg-nav { display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap; }
.an-crumbs { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.an-crumbs .st-link { font-size: 14px; font-weight: 600; }
.an-crumbs b { font-weight: 700; }
.an-crumbs small { margin-left: 6px; font-weight: 500; color: var(--nt-muted); }
.an-sep { color: var(--nt-faint); }
.newton-table td.an-acts { width: 1%; }
.newton-table td.an-acts .st-btn + .st-btn { margin-left: 6px; }
.st-btn.an-danger:hover { border-color: var(--nt-danger); color: var(--nt-danger); }
.newton-table td .st-link { font-size: 14px; text-align: left; }
#historyMatchList .an-facts { padding-top: 0; }
#historyMatchList .an-facts dd { font-size: 18px; }

/* ---- player charts (js/newton-charts.js): Last 10, cards, the chart, compare, full screen ---- */
.pc-form { display: grid; gap: 12px; padding: 4px 20px 20px; border-top: 1px solid var(--nt-line); margin-top: 2px; padding-top: 16px; }
.pc-last { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; }
.pc-lbl { font-size: 12px; font-weight: 600; color: var(--nt-muted); }
.pc-note { font-size: 12px; color: var(--nt-muted); margin: 0; }
.pc-results { display: flex; gap: 4px; flex-wrap: wrap; }
.pc-res { min-width: 34px; height: 26px; padding: 0 6px; border-radius: 6px; display: inline-grid; place-items: center; font-family: var(--nt-mono); font-size: 11px; font-weight: 700; border: 1px solid var(--nt-line-2); color: var(--nt-ink-2); background: var(--nt-surface); }
.pc-res.pc-t1 { background: var(--nt-header); border-color: var(--nt-header); color: var(--nt-header-ink); }
.pc-res.pc-t2 { background: var(--nt-ink-2); border-color: var(--nt-ink-2); color: #fff; }
.pc-res.pc-t4 { background: var(--nt-line); }
.pc-res.pc-dnp { border-style: dashed; color: var(--nt-faint); background: transparent; }

.pc-cards { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.pc-card { display: grid; gap: 2px; text-align: left; min-width: 0; border: 1px solid var(--nt-line); border-radius: 10px; padding: 10px 12px 8px; background: var(--nt-surface); font: inherit; color: var(--nt-ink); cursor: pointer; }
.pc-card:hover { border-color: var(--nt-ink-2); }
.pc-card[aria-pressed="true"] { border-color: var(--nt-ink); box-shadow: inset 0 0 0 1px var(--nt-ink); }
.pc-card:focus-visible { outline: 2px solid var(--nt-accent); outline-offset: 2px; }
.pc-k { font-size: 12px; font-weight: 600; color: var(--nt-muted); }
.pc-v { font-size: 22px; font-weight: 800; letter-spacing: -.01em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.pc-v small { font-size: 12px; font-weight: 600; color: var(--nt-muted); margin-left: 3px; letter-spacing: 0; }
.pc-t { font-size: 12px; color: var(--nt-ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-t.up { color: var(--nt-ok); }
.pc-t.down { color: #b2410f; }
.pc-card svg { width: 100%; height: 34px; display: block; margin-top: 4px; }

.pc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; margin-top: 4px; }
.pc-title { margin: 0; font-size: 16px; font-weight: 700; }
.pc-desc { margin: 2px 0 0; color: var(--nt-muted); font-size: 13px; max-width: 80ch; }
.pc-tools { display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap; }
.pc-legend { display: flex; gap: 6px 14px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--nt-ink-2); }
.pc-legend i { display: inline-block; width: 16px; border-top: 2.5px solid; vertical-align: middle; margin-right: 6px; }
.pc-legend i.pc-dash { border-top: 2px dashed var(--nt-muted); }
.pc-legend i.pc-box { width: 12px; height: 10px; border: 0; }
.pc-fullbtn { height: 30px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--nt-line-2); background: var(--nt-surface); font: inherit; font-weight: 600; font-size: 13px; color: var(--nt-ink-2); cursor: pointer; white-space: nowrap; }
.pc-fullbtn::before { content: "\2922"; margin-right: 6px; }
.pc-fullbtn:hover { border-color: var(--nt-ink-2); }

/* the players: chips, + Compare with, The field */
.pc-pick { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pc-chip { display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 4px 0 10px; border: 1px solid var(--nt-line-2); border-radius: 99px; font-weight: 600; font-size: 13px; background: var(--nt-surface); }
.pc-chip.pc-fixed { padding-right: 12px; }
.pc-chip i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.pc-chip button { border: 0; background: none; width: 24px; height: 24px; border-radius: 50%; cursor: pointer; color: var(--nt-muted); font: inherit; font-size: 15px; line-height: 1; }
.pc-chip button:hover { background: var(--nt-inset); color: var(--nt-ink); }
.pc-add { height: 32px; border: 1px dashed var(--nt-line-2); border-radius: 99px; padding: 0 10px; background: var(--nt-surface); font: inherit; font-weight: 600; font-size: 13px; color: var(--nt-ink-2); max-width: 100%; }
.pc-field { display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px 0 10px; border-radius: 99px; border: 1px solid var(--nt-line-2); background: var(--nt-surface); font: inherit; font-weight: 600; font-size: 13px; color: var(--nt-ink-2); cursor: pointer; }
.pc-field::before { content: ""; width: 14px; border-top: 2px dashed var(--nt-muted); }
.pc-field[aria-pressed="true"] { border-color: var(--nt-ink); box-shadow: inset 0 0 0 1px var(--nt-ink); }
.pc-field:disabled { opacity: .4; cursor: default; box-shadow: none; border-color: var(--nt-line-2); }

/* the chart: an SVG drawn to the box's width, and its tooltip */
.pc-chart { position: relative; min-width: 0; }
.pc-chart svg { display: block; max-width: 100%; height: auto; overflow: visible; }
.pc-chart svg text { font-family: var(--nt-sans); fill: var(--nt-muted); font-size: 11px; }
.pc-chart svg .pc-ylab { font-variant-numeric: tabular-nums; }
.pc-chart svg .pc-strip { fill: var(--nt-ink-2); font-weight: 600; }
.pc-chart svg .pc-empty { font-size: 13px; }
.pc-chart svg .pc-hit { cursor: pointer; }
.pc-tip { position: absolute; z-index: 5; pointer-events: none; transform: translate(-50%, calc(-100% - 10px)); background: var(--nt-header); color: var(--nt-header-ink); border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.45; white-space: nowrap; box-shadow: 0 6px 20px rgba(17,24,39,.25); }
.pc-tip b { display: block; font-size: 13px; }
.pc-tip[hidden] { display: none; }
.pc-foot { margin: 0; font-size: 12px; color: var(--nt-muted); }

/* several players: measure buttons over the chart */
.pc-compare { display: grid; gap: 12px; padding: 0 20px 20px; }
.pc-seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--nt-line-2); border-radius: 8px; overflow: hidden; justify-self: start; }
.pc-seg button { border: 0; background: var(--nt-surface); padding: 7px 14px; font: inherit; font-weight: 600; font-size: 13px; color: var(--nt-ink-2); cursor: pointer; }
.pc-seg button + button { border-left: 1px solid var(--nt-line-2); }
.pc-seg button[aria-pressed="true"] { background: var(--nt-header); color: var(--nt-header-ink); }
.pc-seg button:hover:not([aria-pressed="true"]) { background: var(--nt-surface-2); }
.pc-desc-c { margin: 0; }
.pc-head-c { align-items: center; margin: 0; }
.pc-capnote { color: #b2410f; }

/* full screen */
.pc-full { position: fixed; inset: 0; z-index: 2000; background: var(--nt-surface); display: grid; grid-template-rows: auto auto auto minmax(0, 1fr) auto; gap: 10px; padding: 16px 24px 14px; font-family: var(--nt-sans); color: var(--nt-ink); }
.pc-full-head { display: flex; align-items: center; gap: 10px 20px; flex-wrap: wrap; }
.pc-full-head h3 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.pc-close { margin-left: auto; width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--nt-line-2); background: var(--nt-surface); font-size: 22px; line-height: 1; color: var(--nt-ink-2); cursor: pointer; }
.pc-close:hover { border-color: var(--nt-ink-2); }
.pc-full .pc-desc { margin: 0; }
.pc-full-chart { min-height: 0; }
.pc-full-chart svg { height: 100%; }
.pc-close:focus-visible, .pc-fullbtn:focus-visible, .pc-field:focus-visible, .pc-seg button:focus-visible { outline: 2px solid var(--nt-accent); outline-offset: 2px; }

/* ---- below desktop width ---- */
@media (max-width: 1400px) {
  .an-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .pc-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1000px) {
  .an-players, .an-dash-cols { grid-template-columns: minmax(0, 1fr); }
}

/* ---- phones ---- */
@media (max-width: 700px) {
  .an-wrap { padding: 16px 12px 28px; gap: 12px; }
  .an-wrap .st-title h2 { font-size: 24px; }
  .an-wrap .st-title p { display: none; }
  .an-strip-row { padding: 10px 12px; }
  /* the views fill the width; the lens stacks */
  .an-views { width: 100%; }
  .an-views .st-seg { display: flex; }
  .an-views .st-seg button { flex: 1; padding-inline: 6px; }
  .an-points { width: 100%; }
  .an-points .st-seg { flex: 1 1 calc(100% - 60px); display: flex; }
  .an-points .st-seg button { flex: 1; }
  .an-points-panel { left: 0; right: auto; width: 100%; }
    .an-lens { width: 100%; }
  .an-text.an-name { width: 100%; }
  .an-dates { width: 100%; }
  .an-dates .an-text { flex: 1; width: auto; }
  .an-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .an-tile { padding: 10px 12px 12px; }
  .an-tile:last-child:nth-child(odd) { grid-column: 1 / -1; } /* no tile alone in a half row */
  .an-tile-value { font-size: 26px; }
  .an-wrap .st-panel-head { padding: 14px 14px 10px; }
  .an-foot { padding-inline: 14px; }
  .an-prof-head, .an-facts, .an-sub { padding-inline: 14px; }
  .an-facts.an-facts--grid { margin-inline: 14px; padding: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .an-place { margin-inline: 14px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .newton-table .an-wide-only { display: none; }
  #analyticsViewRegister .newton-table td.nt-name, #analyticsViewPlayers .newton-table td.nt-name { white-space: normal; }
  /* the player list scrolls in its own box, so the profile under it stays close */
  #playersTableContainer .newton-table-scroll { max-height: 320px; overflow-y: auto; }
  .pc-form, .pc-compare { padding-inline: 14px; }
  .pc-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .pc-v { font-size: 19px; }
  .pc-full { padding: 12px 12px 10px; }
  .pc-full-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .pc-full-head .pc-seg { grid-column: 1 / -1; grid-row: 2; }
  .pc-seg button { padding: 6px 9px; font-size: 12px; }
  /* the Leaderboard scrolls sideways with rank and name kept in view */
  #leaderboardTableContainer :is(td, tr:not(.newton-table-groups) th):nth-child(-n+2),
  #leaderboardTableContainer .newton-table-groups th:first-child { position: sticky; z-index: 1; background: var(--nt-surface); }
  #leaderboardTableContainer :is(td, th):nth-child(1) { left: 0; min-width: 40px; }
  #leaderboardTableContainer :is(td, tr:not(.newton-table-groups) th):nth-child(2) { left: 40px; max-width: 130px; overflow: hidden; text-overflow: ellipsis; box-shadow: 1px 0 0 var(--nt-line); }
}
