/**
 * MLBMA shared responsive contract — mobile / tablet / desktop.
 * Breakpoints: mobile 0–767, tablet 768–1099, desktop 1100+.
 * Optional compact: 0–479.
 */

:root {
  --bp-mobile-max: 767px;
  --bp-tablet-max: 1099px;
  --bp-compact-max: 479px;
  --shell-pad-mobile: 12px;
  --shell-pad-tablet: 18px;
  --section-gap-mobile: 10px;
  --touch-target-min: 44px;
}

/* Prevent horizontal page scroll on small viewports */
@media (max-width: 767px) {
  html {
    overflow-x: hidden;
  }

  body {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
  }

  .container,
  .ca-page-shell {
    padding-left: var(--shell-pad-mobile) !important;
    padding-right: var(--shell-pad-mobile) !important;
    max-width: 100% !important;
  }

  .ca-board {
    padding: 14px 12px 16px;
    border-radius: 14px;
  }

  .ca-board.tp-section {
    scroll-margin-top: 72px;
  }

  .ca-page-header {
    margin-bottom: 12px;
  }

  .ca-page-title {
    font-size: clamp(1.25rem, 5.5vw, 1.65rem) !important;
    line-height: 1.15;
  }

  .ca-page-header__sub,
  .ca-page-header .ca-helper {
    font-size: 12.5px;
    line-height: 1.45;
    max-width: 100%;
  }

  .ca-platform-cta {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .ca-platform-cta__item {
    padding: 12px 14px;
    min-height: var(--touch-target-min);
  }

  .ca-section-header {
    margin-bottom: 10px;
  }

  .ca-section-head {
    gap: 10px;
  }

  .ca-section-head .title {
    font-size: 0.95rem;
  }

  .ca-section-head .purpose {
    font-size: 12px;
    line-height: 1.4;
  }

  /* Hub controls — wrap, touch-friendly */
  .hub-control-bar,
  .hub-pill-row {
    flex-wrap: wrap;
    gap: 6px;
  }

  .hub-pill {
    min-height: 34px;
    padding: 6px 11px;
    font-size: 10.5px;
  }

  .hub-pill-sep {
    display: none;
  }

  /* Tables — horizontal scroll container */
  .ca-table-scroll,
  .bp-prop-table-wrap,
  .bp-pm-table-wrap,
  .table-scroll,
  .lv-table-wrap,
  .mc-lcc-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    margin-left: -2px;
    margin-right: -2px;
    padding-bottom: 4px;
  }

  .ca-table-scroll > table,
  .table-scroll > table {
    min-width: min(100%, 520px);
  }

  /* Metric chips — legible on small screens */
  .chip,
  .val-chip {
    font-size: 11px;
    padding: 3px 7px;
  }

  /* Profile shells */
  .profile-shell,
  .tp-identity-stack {
    gap: var(--section-gap-mobile);
  }

  .profile-decision-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .profile-decision-card {
    padding: 10px 11px;
  }

  .profile-decision-card__value {
    font-size: 15px;
  }

  /* Hero banners — stack photo + identity */
  .tp-pitcher-banner__inner {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .tp-pitcher-banner__photo {
    align-self: center;
  }

  .tp-pitcher-banner__identity {
    flex-direction: column;
    align-items: center;
    text-align: center;
    flex-wrap: wrap;
  }

  .tp-team-banner__copy {
    align-items: center;
    text-align: center;
    width: 100%;
  }

  .tp-team-banner--hero .tp-team-banner__title {
    font-size: clamp(1.5rem, 7vw, 2rem);
  }

  .pp-hero-stats.tp-hero-stat-row {
    flex-wrap: wrap;
    justify-content: stretch;
  }

  .pp-hero-stats.tp-team-banner__stats--hero .tp-hero-stat {
    flex: 1 1 calc(50% - 6px);
    min-width: 0;
    justify-content: center;
  }

  .pp-hero-stats .tp-hero-stat--solo {
    flex: 1 1 calc(50% - 6px);
    max-width: none;
  }

  /* Team profile density */
  .tp-section-filter-bar {
    padding: 10px 12px;
  }

  .tp-section-filter-bar .hub-pill-row {
    width: 100%;
  }

  /* Opening dashboard matchup cards */
  .mc-card,
  .ca-matchup-card {
    max-width: 100%;
  }

  /* Compare page header */
  .mc-header {
    flex-wrap: wrap;
    gap: 10px;
  }

  .mc-compare-nav-row {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    padding-bottom: 4px;
    max-width: 100%;
  }

  /* Sticky nav offset */
  #chaseHeader {
    position: sticky;
    top: 0;
    z-index: 200;
  }

  /* Team rankings */
  .lv-body,
  .hub-table-wrap,
  .table-wrap,
  .rl-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  .hub-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hub-expand-inner {
    grid-template-columns: 1fr;
    padding: 14px 12px;
  }

  .hub-expand-right {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Research lab dense panels */
  .rl-panel,
  .rl-scorecard-grid,
  .rl-compare-grid {
    min-width: 0;
  }

  .rl-table-wrap {
    margin-left: -2px;
    margin-right: -2px;
  }

  /* Bullpen / pitcher metric bands */
  .metric-band,
  .pp-metric-strip,
  .bp-metric-strip {
    flex-wrap: wrap;
    gap: 6px;
  }

  .metric-band .chip,
  .pp-metric-strip .chip {
    flex: 1 1 calc(50% - 6px);
    min-width: 0;
    justify-content: center;
  }

  /* Glossary / long-form */
  .glossary-grid,
  .education-card {
    min-width: 0;
  }
}

/* Tablet — selective two-column retention */
@media (min-width: 768px) and (max-width: 1099px) {
  .container,
  .ca-page-shell {
    padding-left: var(--shell-pad-tablet);
    padding-right: var(--shell-pad-tablet);
  }

  .ca-board {
    padding: 16px 16px 18px;
  }

  .profile-decision-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Mobile compact — single column, tighter type */
@media (max-width: 479px) {
  .container,
  .ca-page-shell {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  .ca-board {
    padding: 12px 10px 14px;
    border-radius: 12px;
  }

  .profile-decision-strip {
    grid-template-columns: 1fr;
  }

  .pp-hero-stats.tp-team-banner__stats--hero .tp-hero-stat,
  .pp-hero-stats .tp-hero-stat--solo {
    flex: 1 1 100%;
  }

  .hub-pill {
    flex: 1 1 auto;
    text-align: center;
    min-width: calc(50% - 6px);
  }

  .ca-platform-cta__label {
    font-size: 14px;
  }

  .hub-kpi-grid {
    grid-template-columns: 1fr;
  }

  .hub-expand-right {
    grid-template-columns: 1fr;
  }

  .metric-band .chip,
  .pp-metric-strip .chip {
    flex: 1 1 100%;
  }

  .mobile-card-metrics {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ──────────────────────────────────────────────────────────────────────────
   Card-ified data tables (mobile).
   Dense desktop tables (Team Rankings .lv-table, Trends Heat Map .thm-table, or
   any table opted-in with .ca-cardify) are tagged by mobile_cardify.js with
   .ca-cardified + per-cell data-label + a .ca-card-team header cell. Below 768px
   each <tr> becomes a stacked stat card so NO column hides behind a horizontal
   scroll. Desktop DOM is untouched — these rules only apply at mobile width.
   ────────────────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  body.team-rankings-page .container {
    padding: 18px 12px 56px;
  }

  body.team-rankings-page #teamRankingsPageHeader .ca-page-header {
    margin-bottom: 18px;
    padding-top: 4px;
  }

  body.team-rankings-page #teamRankingsPageHeader .ca-page-title {
    font-size: 30px;
    line-height: 1.05;
  }

  body.team-rankings-page .lv-bar {
    padding: 12px;
    border-radius: 10px;
  }

  body.team-rankings-page .lv-family-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px;
    margin-bottom: 16px;
  }

  body.team-rankings-page .lv-family {
    min-height: 76px;
    padding: 12px;
    border-radius: 10px;
  }

  body.team-rankings-page .lv-family-top {
    display: block;
    min-height: 0;
  }

  body.team-rankings-page .lv-family-name {
    display: block;
    font-size: 15px;
    line-height: 1.2;
  }

  body.team-rankings-page .lv-family-n,
  body.team-rankings-page .lv-family-desc,
  body.team-rankings-page .lv-family-chips {
    display: none;
  }

  body.team-rankings-page .lv-lens {
    display: grid;
    grid-template-columns: none !important;
    grid-auto-flow: column;
    grid-auto-columns: minmax(286px, 88%);
    gap: 8px;
    padding: 8px;
    border-radius: 10px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  body.team-rankings-page .lv-lens::-webkit-scrollbar {
    display: none;
  }

  body.team-rankings-page .lv-cat {
    padding: 12px;
    border-radius: 8px;
    scroll-snap-align: start;
  }

  body.team-rankings-page .lv-cat-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    margin-bottom: 12px;
  }

  body.team-rankings-page .lv-cat-k {
    min-width: 0;
  }

  body.team-rankings-page .lv-pills {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
    width: 100%;
    gap: 7px;
  }

  body.team-rankings-page .lv-pill {
    width: 100%;
    min-width: 0;
  }

  body.team-rankings-page .lv-query {
    margin-top: 14px;
    font-size: 12px;
  }

  body.team-rankings-page .lv-table-wrap {
    overflow: visible;
  }

  .lv-table.ca-cardified,
  .thm-table.ca-cardified,
  table.ca-cardify.ca-cardified {
    display: block;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
  }

  /* keep headers in the a11y tree but out of the visual flow */
  .lv-table.ca-cardified thead,
  .thm-table.ca-cardified thead,
  table.ca-cardify.ca-cardified thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .lv-table.ca-cardified tbody,
  .thm-table.ca-cardified tbody,
  table.ca-cardify.ca-cardified tbody {
    display: block;
  }

  .lv-table.ca-cardified tbody tr,
  .thm-table.ca-cardified tbody tr,
  table.ca-cardify.ca-cardified tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px 12px;
    padding: 12px 13px 13px;
    margin: 0 0 10px;
    border: 1px solid var(--border, #262A38);
    border-radius: 10px;
    background: var(--bg-2, #10131F);
  }

  /* strip desktop zebra / hover / sticky treatments inside a card */
  .lv-table.ca-cardified tbody tr:nth-child(even),
  .thm-table.ca-cardified tbody tr:nth-child(even) { background: var(--bg-2, #10131F); }
  .lv-table.ca-cardified tbody tr:hover,
  .thm-table.ca-cardified tbody tr:hover { box-shadow: none; }

  .lv-table.ca-cardified td,
  .thm-table.ca-cardified td,
  table.ca-cardify.ca-cardified td {
    position: static !important;
    left: auto !important;
    width: auto !important;
    min-width: 0 !important;
    height: auto !important;
    border: 0 !important;
    padding: 0 !important;
    text-align: left !important;
    white-space: normal !important;
    background: transparent !important;
  }

  /* team cell = full-width card header, with a rank badge when present */
  .lv-table.ca-cardified td.ca-card-team,
  .thm-table.ca-cardified td.ca-card-team,
  table.ca-cardify.ca-cardified td.ca-card-team {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 15px;
    font-weight: 800;
    padding-bottom: 9px !important;
    margin-bottom: 1px;
    border-bottom: 1px solid var(--border, #262A38) !important;
  }
  .lv-table.ca-cardified td.ca-card-team[data-cardrank]::before,
  .thm-table.ca-cardified td.ca-card-team[data-cardrank]::before {
    content: attr(data-cardrank);
    flex: 0 0 auto;
    min-width: 22px;
    padding: 2px 7px;
    border-radius: 7px;
    background: rgba(124, 77, 255, 0.16);
    color: #B79CFF;
    font-size: 12px;
    font-weight: 800;
    text-align: center;
  }

  /* the standalone rank cell is now redundant */
  .lv-table.ca-cardified td.ca-card-rank,
  .thm-table.ca-cardified td.ca-card-rank { display: none; }

  /* every other cell = label above value */
  .lv-table.ca-cardified td:not(.ca-card-team):not(.ca-card-rank),
  .thm-table.ca-cardified td:not(.ca-card-team):not(.ca-card-rank),
  table.ca-cardify.ca-cardified td:not(.ca-card-team):not(.ca-card-rank) {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
  }
  .lv-table.ca-cardified td:not(.ca-card-team):not(.ca-card-rank)::before,
  .thm-table.ca-cardified td:not(.ca-card-team):not(.ca-card-rank)::before,
  table.ca-cardify.ca-cardified td:not(.ca-card-team):not(.ca-card-rank)::before {
    content: attr(data-label);
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-3, #6E7383);
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .lv-table.ca-cardified td .chip,
  .thm-table.ca-cardified td .chip,
  .thm-table.ca-cardified td .thm-rel {
    align-self: flex-start;
    font-size: 14px;
  }
}

@media (max-width: 390px) {
  body.team-rankings-page .lv-family-grid {
    grid-template-columns: 1fr 1fr !important;
  }

  body.team-rankings-page .lv-family {
    min-height: 72px;
    padding: 10px;
  }
}

@media (max-width: 767px) {
  .hub-pill,
  .lv-pill,
  .ca-pill-btn,
  .bp-pt__line-input {
    min-height: var(--touch-target-min, 44px);
  }
}

/* Touch — larger radar / chart hit targets */
@media (hover: none) and (pointer: coarse) {
  .hub-pill,
  .lv-pill,
  .chase-nav-link,
  .chase-dropdown-item {
    min-height: var(--touch-target-min);
  }

  button,
  .hub-pill,
  input[type="number"],
  input[type="text"],
  select {
    font-size: 16px;
  }

  input.bp-search-input,
  input.bp-prop-card__line-input {
    font-size: 16px;
  }
}
