/**
 * MF Karting client — standard phone layout (~390px).
 * No page-level horizontal scroll; modals centered; tables become cards where needed.
 */
/* Desktop-only / mobile-only helpers */
.mobile-only {
  display: none;
}

@media (max-width: 899px) {
  html {
    overflow-x: hidden;
    max-width: 100%;
  }

  body {
    overflow-x: hidden !important;
    max-width: 100%;
    width: 100% !important;
  }

  body.w-screen,
  .w-screen {
    width: 100% !important;
    max-width: 100% !important;
  }

  .mf-page-main,
  main {
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
    box-sizing: border-box;
  }

  img,
  video,
  iframe,
  pre {
    max-width: 100%;
  }

  /* Lap History — drop fixed scrollbar track that steals width on phones */
  #archive-page-scrollbar {
    display: none !important;
  }

  .archive-shell {
    padding-right: 0 !important;
  }

  /* Pricing tables — fit panel; keep price headers/cells on one line */
  .hub-table-wrap {
    overflow-x: hidden !important;
  }

  .hub-pricing-panel {
    padding: 1rem !important;
  }

  .hub-pricing-table th:nth-child(1),
  .hub-pricing-table td:nth-child(1) {
    width: 42% !important;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .hub-pricing-table th:nth-child(2),
  .hub-pricing-table td:nth-child(2),
  .hub-pricing-table th:nth-child(3),
  .hub-pricing-table td:nth-child(3) {
    width: 29% !important;
    white-space: nowrap !important;
    word-break: normal !important;
    overflow-wrap: normal !important;
    font-size: 0.72rem;
    letter-spacing: 0.02em;
    padding-left: 0.35rem !important;
    padding-right: 0.35rem !important;
  }

  .hub-pricing-table thead th:nth-child(2),
  .hub-pricing-table thead th:nth-child(3) {
    font-size: 0.62rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }

  .hub-pricing-table tbody td:nth-child(2),
  .hub-pricing-table tbody td:nth-child(3) {
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
  }

  /* Bookings filters */
  .filter-bar {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .filter-bar label {
    min-width: 0 !important;
    width: 100%;
  }

  .filter-bar select {
    min-width: 0 !important;
    width: 100%;
  }

  /* Bookings list — card rows */
  .table-wrap {
    overflow-x: hidden !important;
  }

  #booking-list-table {
    min-width: 0 !important;
    width: 100%;
    border: 0;
  }

  #booking-list-table thead {
    display: none;
  }

  #booking-list-table tbody {
    display: flex;
    flex-direction: column;
  }

  #booking-list-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "date time"
      "meta meta"
      "actions actions";
    gap: 0.28rem 0.45rem;
    padding: 0.7rem 0.75rem;
    border-bottom: 1px solid #334155;
  }

  #booking-list-table tbody td {
    display: block;
    padding: 0;
    border: 0;
    background: transparent !important;
    font-size: 0.82rem;
  }

  #booking-list-table .col-date {
    grid-area: date;
    font-weight: 700;
    color: #e2e8f0;
  }

  #booking-list-table .col-time {
    grid-area: time;
    text-align: right;
    color: #fcd34d;
    font-weight: 600;
    white-space: nowrap;
  }

  #booking-list-table .col-meta {
    grid-area: meta;
    color: #94a3b8;
    font-size: 0.76rem;
    line-height: 1.35;
    word-break: break-word;
  }

  #booking-list-table .col-actions {
    grid-area: actions;
    padding-top: 0.35rem !important;
  }

  #booking-list-table .desk-only {
    display: none !important;
  }

  #booking-list-table .row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  /* Booking editor + standard centered modals */
  #booking-editor,
  #mf-auth-modal,
  #mf-profile-modal,
  #mf-waiver-notice-modal,
  #mf-profile-locale-notice-modal,
  #mf-perm-gate-dialog {
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    transform: translate(-50%, -50%) !important;
    width: calc(100% - 0.75rem) !important;
    max-width: 24rem !important;
    border-radius: 1rem !important;
    max-height: min(90dvh, calc(100dvh - 1rem)) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    box-sizing: border-box;
  }

  #mf-profile-modal #mf-profile-balance,
  #mf-profile-modal #mf-profile-balance .mf-balance-figure,
  #mf-profile-modal #mf-profile-balance .mf-yuan-mark,
  #mf-profile-modal #mf-profile-balance .mf-balance-amount {
    overflow: visible !important;
  }

  #mf-profile-modal #mf-profile-balance .mf-balance-figure {
    font-size: 1.45rem !important;
    line-height: 1.6 !important;
    min-height: 1.75em !important;
    padding: 0.2rem 0 0.35rem !important;
  }

  #booking-editor {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Vault voucher detail */
  #vault-detail-backdrop {
    padding: 0.5rem !important;
  }

  #vault-detail-modal {
    width: calc(100% - 0.75rem) !important;
    max-width: 24rem !important;
    max-height: min(90dvh, calc(100dvh - 1rem)) !important;
    overflow-x: hidden !important;
  }

  .vault-detail-row {
    grid-template-columns: minmax(4.25rem, 5.25rem) minmax(0, 1fr) !important;
    gap: 0.35rem !important;
  }

  .vault-detail-row dd {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  /* Session laps popup — compact 3-column grid, no min-width */
  #session-laps-modal .career-table {
    min-width: 0 !important;
    width: 100%;
    table-layout: fixed;
  }

  #session-laps-modal .career-table th,
  #session-laps-modal .career-table td {
    padding: 0.38rem 0.28rem;
    font-size: 0.72rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #session-laps-modal .career-table th:first-child,
  #session-laps-modal .career-table td:first-child {
    width: 2rem;
  }

  #session-laps-modal .career-table th:nth-child(2),
  #session-laps-modal .career-table td:nth-child(2) {
    width: auto;
  }

  #session-laps-modal .career-table th:last-child,
  #session-laps-modal .career-table td:last-child {
    width: 4.25rem;
  }

  /* Chat — stay in viewport width */
  #mf-chat-panel {
    width: calc(100% - 0.75rem) !important;
    max-width: 22.5rem !important;
    right: max(0.375rem, env(safe-area-inset-right, 0px)) !important;
    left: auto !important;
    overflow-x: hidden !important;
  }

  #mf-chat-emoji-pop {
    max-width: calc(100vw - 1rem) !important;
    right: 0 !important;
    left: auto !important;
  }

  /* Footer share sheet */
  #mf-footer-share {
    width: calc(100% - 0.75rem) !important;
    max-width: 18.5rem !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
  }

  /* Championship history drawer rows */
  .history-winner-row {
    grid-template-columns: minmax(0, 1fr) auto !important;
    grid-template-areas:
      "track cash"
      "name lap" !important;
    gap: 0.28rem 0.45rem !important;
  }

  .history-winner-track {
    grid-area: track;
  }

  .history-winner-name {
    grid-area: name;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }

  .history-winner-lap {
    grid-area: lap;
    text-align: right;
  }

  .history-winner-cash {
    grid-area: cash;
    min-width: 0 !important;
  }

  .board-header-inner {
    flex-wrap: wrap !important;
  }

  .board-header-inner .prize-pool-block {
    min-width: 0 !important;
    max-width: 100%;
  }

  #championship-period {
    white-space: normal !important;
    overflow-wrap: anywhere;
  }
}

/* Desktop-only table cells (bookings) */
@media (min-width: 900px) {
  #booking-list-table .mobile-only {
    display: none !important;
  }
}
