/* Phone layout for tables and the performance profile.
   Desktop is unchanged: every rule sits under a max-width query. */

@media (max-width: 639px) {
  body:has(nav[aria-label="Athlete"]) main {
    padding-bottom: calc(5.25rem + env(safe-area-inset-bottom));
  }

  main .panel.p-5 {
    padding: 16px;
  }
}

@media (max-width: 767px) {
  .itb-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }

  .itb-actions > * {
    width: 100%;
    justify-content: center;
  }

  div.itb-standards,
  div.itb-access,
  div.itb-stack {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .itb-standards table,
  .itb-access table,
  .itb-stack table,
  .itb-tests {
    min-width: 0 !important;
  }

  .itb-standards table,
  .itb-standards tbody,
  .itb-access table,
  .itb-access tbody,
  .itb-stack table,
  .itb-stack tbody,
  .itb-tests,
  .itb-tests tbody {
    display: block;
    width: 100%;
  }

  .itb-standards thead,
  .itb-access thead,
  .itb-stack thead,
  .itb-tests thead {
    display: none;
  }

  .itb-standards tbody tr,
  .itb-stack tbody tr {
    display: grid;
    gap: 8px;
    margin: 0 0 10px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: color-mix(in srgb, var(--panel-2) 72%, transparent);
  }

  .itb-standards tbody tr {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .itb-stack tbody tr {
    grid-template-columns: 1fr;
  }

  .itb-standards td,
  .itb-stack td,
  .itb-tests td {
    display: block;
    min-width: 0;
    padding: 0 !important;
    text-align: left !important;
  }

  .itb-standards td:nth-child(1),
  .itb-standards td:nth-child(3) {
    grid-column: 1 / -1;
  }

  .itb-standards td:nth-child(2) {
    grid-column: 1 / 2;
  }

  .itb-standards td:nth-child(3) {
    grid-column: 2 / -1;
  }

  .itb-standards td[data-label]::before,
  .itb-stack td[data-label]::before,
  .itb-access td[data-label]::before,
  .itb-tests td:nth-child(2)::before,
  .itb-tests td:nth-child(3)::before {
    display: block;
    margin-bottom: 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1.2;
    text-transform: uppercase;
    color: var(--text-muted);
  }

  .itb-tests td:nth-child(2)::before {
    content: "Actual";
  }

  .itb-tests td:nth-child(3)::before {
    content: "Target";
  }

  .itb-standards input,
  .itb-access select {
    width: 100% !important;
    max-width: none;
  }

  .itb-access tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 0 0 10px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 14px;
  }

  .itb-access td:first-child,
  .itb-access td:last-child {
    grid-column: 1 / -1;
  }

  .itb-access td[data-label] {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px !important;
    border: 1px solid var(--border);
    border-radius: 10px;
  }

  .itb-access td[data-label]::before {
    margin: 0;
  }

  .itb-tests tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
    padding: 10px 0;
    border-top: 1px solid var(--border);
  }

  .itb-tests td:first-child {
    grid-column: 1 / -1;
  }
}
