/* Mobile-only usability layer. Desktop layout remains untouched. */
@media screen and (max-width: 980px) {
  html.stage2-mobile-menu-open,
  html.stage2-mobile-menu-open body { overflow: hidden !important; }

  .stage2-mobile-drawer {
    display: flex !important;
    flex-direction: column;
    height: 100vh !important;
    height: 100dvh !important;
    overflow: hidden !important;
  }
  .stage2-mobile-drawer__head { flex: 0 0 auto; }
  .stage2-mobile-drawer__body {
    flex: 1 1 auto;
    height: auto !important;
    min-height: 0;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
    padding-bottom: calc(28px + env(safe-area-inset-bottom)) !important;
  }
  .stage2-mobile-group__items { padding-bottom: 4px; }
}

@media screen and (max-width: 720px) {
  html, body { width: 100%; max-width: 100%; overflow-x: hidden !important; }
  body.stage2-frame-body { min-width: 0 !important; }

  /* Header: centre information and shortcuts without vertical text wrapping. */
  .stage2-header__inner {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 10px !important;
    padding: 12px !important;
  }
  .stage2-brand {
    width: 100%;
    min-width: 0;
    gap: 10px !important;
  }
  .stage2-brand__link {
    font-size: 22px !important;
    line-height: 1.15;
    letter-spacing: .025em !important;
    white-space: nowrap;
  }
  .stage2-mobile-btn {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    padding: 0 !important;
  }
  .stage2-userbox {
    width: 100%;
    min-width: 0;
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) 44px;
    gap: 8px !important;
  }
  .stage2-cash-balance {
    grid-column: 1 / 4;
    width: 100%;
    min-width: 0;
    min-height: 44px;
    box-sizing: border-box;
    justify-content: center;
    padding: 7px 12px !important;
  }
  .stage2-cash-charge-btn { grid-column:4/5;grid-row:2;min-width:44px;padding:0 6px!important;font-size:12px; }
  .stage2-cash-balance__text { flex-direction: row; align-items: baseline; gap:8px; }
  .stage2-cash-balance__text small { font-size:12px; }
  .stage2-cash-balance__text strong { margin:0; font-size:14px; }
  .stage2-userbox__meta {
    grid-column: 1 / -1;
    display: flex !important;
    flex-direction: row !important;
    align-items: baseline;
    justify-content: center;
    gap: 7px;
    text-align: center !important;
    min-width: 0;
  }
  .stage2-userbox__meta strong,
  .stage2-userbox__meta span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .stage2-attendance-btn,
  .stage2-body-btn,
  .stage2-locker-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 44px;
    padding: 10px 8px !important;
    font-size: 13px;
    line-height: 1.2 !important;
    white-space: nowrap;
  }
  .stage2-attendance-btn { grid-column:1/2; }
  .stage2-body-btn { grid-column:2/3; }
  .stage2-locker-btn { grid-column:3/4; }
  .stage2-logout-form { grid-column:4/5; }
  .stage2-logout-form { width: 44px; min-width: 44px; margin: 0; }
  .stage2-logout-btn {
    width: 44px;
    height: 44px;
    padding: 0 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px !important;
    font-size: 0 !important;
    white-space: nowrap;
  }
  .stage2-logout-btn span { display: none; }
  .stage2-logout-btn::before {
    content: "↪";
    font-size: 24px;
    font-weight: 900;
    line-height: 1;
    transform: rotate(180deg);
  }
  .stage2-main-wrap { margin: 10px auto !important; padding: 0 5px !important; }
  .stage2-footer { padding: 15px 16px !important; font-size: 12px !important; }

  /* Common mobile spacing and controls. */
  .stage3-wrap,
  .stage3-wrap--members { width: 100%; max-width: 100%; padding: 8px !important; overflow-x: hidden; }
  .stage3-card { width: 100%; max-width: 100%; padding: 14px !important; border-radius: 14px !important; }
  .stage3-head { align-items: flex-start !important; }
  .stage3-head h1,
  .stage3-head h2 { font-size: 21px !important; line-height: 1.3; }
  .stage3-head p { font-size: 13px; line-height: 1.55; }
  .stage3-actions { width: 100%; display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage3-actions > *,
  .stage3-actions > form,
  .stage3-actions > form > button { width: 100%; min-width: 0; box-sizing: border-box; }
  .stage3-btn,
  .stage3-btn-secondary,
  .stage3-btn-danger,
  .stage3-btn-light { min-height: 44px; padding: 10px 12px !important; text-align: center; white-space: normal; }
  .stage3-inline { min-width: 0; }
  .stage3-inline > .stage3-field { min-width: 0 !important; flex: 1 1 100%; }
  .stage3-field input,
  .stage3-field select,
  .stage3-field textarea { min-width: 0 !important; max-width: 100%; font-size: 16px !important; }
  .stage3-summary .item { padding: 13px !important; }
  .stage3-summary .item strong { font-size: 22px !important; overflow-wrap: anywhere; }

  /* Member add/detail: photo and fields are stacked on mobile only. */
  .member-form-layout {
    display: flex !important;
    flex-direction: column;
    gap: 14px !important;
    width: 100%;
    min-width: 0;
  }
  .member-form-layout > * { width: 100%; min-width: 0; }
  .member-form-layout .stage3-card { margin: 0 !important; }
  .member-form-layout #member-photo-preview { width: 112px !important; height: 112px !important; }
  .member-form-layout input[type="file"] { width: 100%; min-width: 0; font-size: 13px !important; }
  #member-detail-form .stage3-grid { grid-template-columns: minmax(0, 1fr) !important; }
  #member-detail-form .stage3-grid > [style*="grid-column"] { grid-column: 1 / -1 !important; min-width: 0; }
  #member-detail-form .stage3-inline { max-width: 100%; }

  /* Every normal data table becomes a labelled vertical card list. */
  .stage3-table-wrap:has(> .mlms-mobile-card-table),
  .stage2-panel:has(> .mlms-mobile-card-table) { overflow: visible !important; }
  body table.mlms-mobile-card-table {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    table-layout: auto !important;
    border: 0 !important;
  }
  body table.mlms-mobile-card-table > thead {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }
  body table.mlms-mobile-card-table > tbody {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 12px !important;
    width: 100% !important;
  }
  body table.mlms-mobile-card-table > tbody > tr {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100% !important;
    min-width: 0 !important;
    padding: 7px 12px !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 13px !important;
    background: #fff !important;
    box-shadow: 0 4px 14px rgba(15, 23, 42, .045);
  }
  body table.mlms-mobile-card-table > tbody > tr > td {
    display: grid !important;
    grid-template-columns: minmax(82px, 34%) minmax(0, 1fr) !important;
    align-items: center !important;
    gap: 10px !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 42px;
    padding: 8px 0 !important;
    border: 0 !important;
    border-bottom: 1px solid #eef2f7 !important;
    background: transparent !important;
    text-align: left !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
    box-sizing: border-box;
  }
  body table.mlms-mobile-card-table > tbody > tr > td:last-child { border-bottom: 0 !important; }
  body table.mlms-mobile-card-table > tbody > tr > td::before {
    content: attr(data-mobile-label);
    color: #64748b;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.35;
  }
  body table.mlms-mobile-card-table > tbody > tr > td.mlms-mobile-full-cell {
    display: block !important;
    min-height: 0;
    padding: 18px 4px !important;
    text-align: center !important;
  }
  body table.mlms-mobile-card-table > tbody > tr > td.mlms-mobile-full-cell::before { display: none; }
  body table.mlms-mobile-card-table td input:not([type="checkbox"]):not([type="radio"]),
  body table.mlms-mobile-card-table td select,
  body table.mlms-mobile-card-table td textarea {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }
  body table.mlms-mobile-card-table td input[type="checkbox"],
  body table.mlms-mobile-card-table td input[type="radio"] { width: 20px !important; height: 20px !important; }
  body table.mlms-mobile-card-table .stage9-att-member,
  body table.mlms-mobile-card-table .stage8-tt-photo,
  body table.mlms-mobile-card-table .stage8-tt-asp-member-cell { min-width: 0 !important; }
  body table.mlms-mobile-card-table .stage8-tt-asp-photo,
  body table.mlms-mobile-card-table .stage8-tt-photo img,
  body table.mlms-mobile-card-table .stage8-tt-photo .placeholder { width: 72px !important; height: 72px !important; min-width: 72px !important; }
  .stage5-history-table,
  .stage5-monthly-table,
  .stage5-ranking-table,
  .stage8-daily-table,
  .stage8-tt-asp-table { min-width: 0 !important; }
  .stage5-alluser-top-scroll { display: none !important; }
  .stage5-alluser-table-wrap,
  .stage8-daily-table-wrap,
  .stage8-tt-asp-table-wrap,
  .stage9-att-overflow { max-height: none !important; overflow: visible !important; }
  .stage10-order-control { min-width: 0 !important; }
  .stage10-table .name-cell { min-width: 0 !important; }

  /* Schedule: compact monthly calendar; details remain in the labelled lists below. */
  .stage3-calendar { gap: 5px !important; }
  .stage3-calendar__head,
  .stage3-calendar__week { grid-template-columns: repeat(7, minmax(0, 1fr)) !important; gap: 3px !important; }
  .stage3-calendar__head > div { padding: 7px 1px !important; border-radius: 7px !important; font-size: 12px; }
  .stage3-calendar__cell { min-height: 58px !important; padding: 5px !important; border-radius: 8px !important; overflow: hidden; }
  .stage3-calendar__day { margin: 0 !important; font-size: 14px !important; }
  .stage3-calendar__plus { width: 18px !important; height: 18px !important; font-size: 13px !important; }
  .stage3-calendar__holiday { margin: 3px 0 0 !important; font-size: 9px !important; line-height: 1.15; }
  .stage3-calendar__item {
    display: inline-block !important;
    width: 7px !important;
    height: 7px !important;
    min-width: 7px !important;
    min-height: 7px !important;
    margin: 3px 2px 0 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 50% !important;
    background: #2563eb !important;
    overflow: hidden !important;
  }
  .stage3-calendar__item > * { visibility: hidden !important; }
  .stage3-selected-head { align-items: flex-start !important; }

  /* Personal monthly attendance: two-column agenda cards instead of a very long one-column calendar. */
  .stage9-att-calendar-head { display: none !important; }
  .stage9-att-calendar-grid { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px !important; }
  .stage9-att-calendar-cell { min-height: 118px !important; padding: 9px !important; border-radius: 11px !important; font-size: 12px; }
  .stage9-att-calendar-cell.-blank { display: none !important; }
  .stage9-att-calendar-actions { margin-top: auto; }

  /* Dashboard cards and tables remain readable without horizontal dragging. */
  .stage2-dashboard { padding: 8px !important; }
  .stage2-dashboard__hero { padding: 16px !important; }
  .stage2-dashboard__hero h1 { font-size: 22px !important; }
  .stage2-dashboard__cards { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px !important; }
  .stage2-panel { padding: 14px !important; }

  /* Modernised notice list. */
  .stage12-notice-search { grid-template-columns: minmax(0, 1fr) auto !important; }
  .stage12-notice-search .stage3-field { min-width: 0; }
}

@media screen and (max-width: 720px) {
  .stage2-cash-modal { padding:0;align-items:end; }
  .stage2-cash-modal__dialog { width:100%;max-height:94dvh;border-radius:24px 24px 0 0; }
  .stage2-cash-modal__head { grid-template-columns:44px 1fr 38px;padding:18px 17px;gap:11px; }
  .stage2-cash-modal__head-icon { width:44px;height:44px;border-radius:14px;font-size:20px; }
  .stage2-cash-modal__head-copy strong { font-size:20px; }
  .stage2-cash-modal__head-copy p { margin-top:3px;font-size:11px; }
  .stage2-cash-modal__close { width:38px;height:38px;border-radius:12px; }
  .stage2-cash-modal__body { padding:18px 16px 12px; }
  .stage2-cash-modal fieldset { margin-bottom:20px; }
  .stage2-cash-products { grid-template-columns:repeat(2,minmax(0,1fr));gap:9px; }
  .stage2-cash-product-card { min-height:96px;padding:15px 12px 13px; }
  .stage2-cash-product-card>strong { font-size:20px; }
  .stage2-cash-product-card>i { top:10px;right:10px;width:21px;height:21px; }
  .stage2-cash-methods { grid-template-columns:repeat(3,minmax(0,1fr));gap:7px; }
  .stage2-cash-methods label>span { min-height:78px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;padding:9px 4px;text-align:center; }
  .stage2-cash-methods label i { width:30px;height:30px;border-radius:9px;font-size:14px; }
  .stage2-cash-methods label b { font-size:11px; }
  .stage2-cash-methods label small { font-size:9px; }
  .stage2-cash-customer,.stage2-cash-bank { grid-template-columns:1fr;gap:11px; }
  .stage2-cash-customer input,.stage2-cash-bank input,.stage2-cash-bank select { min-height:50px;font-size:16px; }
  .stage2-cash-help { margin-top:15px; }
  .stage2-cash-modal__actions { padding:12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .stage2-cash-modal__actions button { min-width:0;flex:1;min-height:50px; }
}

@media screen and (max-width: 430px) {
  .stage2-cash-modal__head-copy p { max-width:250px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis; }
  .stage2-cash-product-card>em { font-size:9px; }
  .stage2-cash-product-card>b { font-size:10px; }
}

@media screen and (max-width: 380px) {
  .stage2-brand__link { font-size: 20px !important; }
  .stage2-userbox { grid-template-columns: repeat(3, minmax(0, 1fr)) 42px; }
  .stage2-attendance-btn,
  .stage2-body-btn,
  .stage2-locker-btn { font-size: 12px; padding-inline: 5px !important; }
  .stage2-logout-form,
  .stage2-logout-btn { width: 42px; min-width: 42px; }
  body table.mlms-mobile-card-table > tbody > tr > td { grid-template-columns: minmax(74px, 32%) minmax(0, 1fr) !important; gap: 8px !important; }
}
