/*
 * 手机端布局安全层。
 * 所有规则都限制在 700px 以下；客户端电脑端的现有布局、尺寸和交互保持不变。
 */
@media (max-width: 700px) {
  html,
  body,
  body.order-detail-page,
  .login-screen {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
  }

  .login-screen {
    min-height: 100dvh;
    padding: 16px;
    overflow-y: auto;
  }

  .topbar-inner {
    height: auto;
    min-height: 58px;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }

  .brand {
    min-width: 0;
  }

  .brand span {
    display: none;
  }

  .account-menu,
  .account-menu-button {
    min-width: 0;
    max-width: 100%;
  }

  .page,
  .page-summary,
  .order-detail-page-shell,
  .order-detail-content {
    min-width: 0;
    max-width: 100%;
    padding-right: 12px;
    padding-left: 12px;
  }

  /* The standalone detail page uses these real shells (not detail-main or
     order-detail-layout). Keep its fixed-column business table on its own
     swipe rail instead of clipping the right-hand fields at the body edge. */
  .order-detail-page .detail-page {
    min-width: 0;
    max-width: 100%;
    padding: 12px;
  }

  .order-detail-page .detail-page-header {
    flex-wrap: wrap;
    gap: 12px;
    padding: 14px;
  }

  .order-detail-page .detail-page-header > div {
    min-width: 0;
    max-width: 100%;
  }

  .order-detail-page .detail-page-header h1 {
    font-size: 23px;
    overflow-wrap: anywhere;
  }

  .order-detail-page .detail-page-status {
    flex-wrap: wrap;
  }

  .order-detail-page .detail-page-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .order-detail-page .detail-page-main {
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .order-detail-page .detail-page-main::before {
    content: "詳細情報は左右にスワイプできます";
    display: block;
    margin-bottom: 10px;
    color: #647b90;
    font-size: 12px;
  }

  .menu-row,
  .page-toolbar,
  .page-summary-actions,
  .order-detail-actions {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    flex-wrap: nowrap;
  }

  .menu-btn,
  .page-toolbar > button,
  .page-summary-actions > button,
  .order-detail-actions > button {
    flex: 0 0 auto;
  }

  /* Preserve every business column and make the table rail swipeable on a
     phone.  The page itself never becomes wider than the viewport. */
  .legacy-table-wrap,
  .preorder-table-wrap,
  .order-detail-table-wrap,
  .order-document-table-wrap,
  .order-timeline-table-wrap,
  .ship-schedule-table-wrap {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .modal-layer {
    min-width: 0;
  }

  .preorder-modal {
    inset: 8px;
    min-width: 0;
    border-radius: 12px;
  }

  .track-modal,
  .client-export-modal,
  .preorder-crm-modal,
  .vessel-motion-modal,
  .company-notice-modal {
    top: 8px;
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    height: auto;
    border-radius: 12px;
  }

  .company-notice-modal {
    transform: translateX(-50%);
  }

  .modal-head,
  .company-notice-head {
    min-height: 0;
    gap: 10px;
    padding: 12px 14px;
  }

  .modal-head h1,
  .company-notice-head h1 {
    font-size: 18px;
  }

  .modal-head > p,
  .company-notice-head > p {
    display: none;
  }

  .company-notice-workbench {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(176px, 42%) minmax(0, 1fr);
  }

  .company-notice-sidebar {
    border-right: 0;
    border-bottom: 1px solid #b8c8d4;
  }

  .company-notice-filters {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .company-notice-filters button {
    flex: 0 0 auto;
  }

  /* Keep native Safari/Chrome/Edge fields from zooming a whole screen during
     data entry.  This scope deliberately excludes toggle controls and does
     not alter any client-side business data or request handling. */
  body.mobile-work-mode .modal-layer :is(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea),
  body.mobile-work-mode .page :is(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea) {
    max-width: 100%;
    font-size: 16px;
    scroll-margin-block: 18px;
    touch-action: manipulation;
  }

  body.mobile-work-mode .modal-layer :is(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select),
  body.mobile-work-mode .page :is(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select) {
    min-height: 44px;
  }

  body.mobile-work-mode .modal-layer textarea,
  body.mobile-work-mode .page textarea {
    min-height: 96px;
    line-height: 1.5;
  }

  /* Customer work flows frequently surface through dialog pages.  Keep the
     shell in the visual viewport and the action area available while the
     dialog content scrolls independently. */
  body.mobile-work-mode .preorder-modal,
  body.mobile-work-mode .track-modal,
  body.mobile-work-mode .client-export-modal,
  body.mobile-work-mode .preorder-crm-modal,
  body.mobile-work-mode .vessel-motion-modal,
  body.mobile-work-mode .company-notice-modal {
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }

  body.mobile-work-mode .preorder-modal :is(.form-grid, .preorder-grid, .track-grid),
  body.mobile-work-mode .track-modal :is(.form-grid, .track-grid),
  body.mobile-work-mode .vessel-motion-modal :is(.form-grid, .track-grid) {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 420px) {
  .login-box {
    padding: 28px 20px 22px;
  }

  .menu-btn {
    min-width: 136px;
  }
}
