/* MOBILE-ONLY SURFACE: this file is intentionally viewport-scoped. */
/*
 * Mobile-only presentation layer.
 * Keep mobile layout decisions here so desktop CSS and application behavior
 * remain independent of the phone layout.
 */
@media screen and (max-width: 760px) {
  :root {
    --mobile-gutter: 12px;
    --mobile-radius: 12px;
    --mobile-control-height: 44px;
  }

  html,
  body {
    width: 100%;
    min-width: 0 !important;
    min-height: 100%;
    overflow-x: hidden;
    background: #f2f5f9;
  }

  body {
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
  }

  button,
  input,
  select {
    touch-action: manipulation;
  }

  button:focus-visible,
  input:focus-visible,
  select:focus-visible {
    outline: 3px solid #9fc1f4;
    outline-offset: 1px;
  }

  .app-shell {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 100dvh;
    height: auto !important;
    padding: 0 0 20px;
    background: #f2f5f9;
  }

  .app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    margin: 0;
    padding: 12px var(--mobile-gutter) 10px;
    border-bottom: 1px solid #dce3ec;
    background: #f8fafc;
    box-shadow: 0 2px 10px #17223514;
  }

  .title-block h1 {
    margin: 0;
    font-size: 17px;
    line-height: 1.35;
    letter-spacing: 0;
  }

  .title-block p,
  .brand-chip {
    display: none;
  }

  .dashboard {
    display: flex !important;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    min-height: 0;
    padding: 10px var(--mobile-gutter) 0;
  }

  /* Keep the existing DOM and event wiring intact while changing visual order. */
  .left-column {
    display: contents;
  }

  .workspace-tabs {
    position: sticky;
    top: 61px;
    z-index: 25;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    width: 100%;
    margin: 0;
    padding: 4px;
    border: 1px solid #cbd5e2;
    border-radius: 11px;
    background: #f8fafc;
    box-shadow: 0 4px 12px #17223514;
  }

  .workspace-tab {
    min-height: var(--mobile-control-height);
    padding: 9px 10px;
    border: 0;
    border-radius: 8px;
    font-size: 13px;
  }

  .workspace-tab:not(.active) {
    color: #667386;
    background: transparent;
  }

  .workspace-tab.active {
    background: #14171f;
    color: #fff;
  }

  .workspace-tab-indicator {
    display: none;
  }

  /* Search and the table are the first task on a phone. */
  .right-column {
    order: 1;
    width: 100%;
    min-height: 0;
  }

  #progressWorkspace,
  #settingsWorkspace {
    order: 2;
    width: 100%;
  }

  .workspace {
    gap: 10px;
  }

  .table-wrap {
    width: 100%;
    height: auto;
    min-height: 0;
    border: 1px solid #d7e0eb;
    border-radius: var(--mobile-radius);
    box-shadow: 0 3px 14px #17223512;
  }

  .table-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 9px;
    padding: 12px;
  }

  .table-header h2 {
    font-size: 15px;
    line-height: 1.3;
  }

  .storage-status {
    display: block;
    max-width: 100%;
    margin-top: 3px;
    overflow-wrap: anywhere;
    font-size: 10.5px;
    line-height: 1.4;
  }

  .table-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    width: 100%;
  }

  .table-actions > * {
    min-width: 0;
    min-height: var(--mobile-control-height);
    padding: 9px 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .table-actions .logout-button {
    grid-column: 1 / -1;
    order: 4;
  }

  .list-controlbar {
    display: grid;
    grid-template-columns: 106px minmax(0, 1fr);
    gap: 7px;
    padding: 10px;
    align-items: stretch;
  }

  .list-controlbar > #tableTitle {
    grid-column: 1 / -1;
    min-height: 20px;
    align-self: center;
    color: #27364a;
    font-size: 12px;
    font-weight: 800;
  }

  .list-controlbar > #searchMode {
    grid-column: 1;
  }

  .list-controlbar > #tableSearch {
    grid-column: 2;
  }

  .list-controlbar > #workPresetSelect {
    grid-column: 1 / -1;
  }

  .list-controlbar > #saveWorkPreset,
  .list-controlbar > #resetWorkPreset,
  .list-controlbar > #deleteWorkPreset {
    min-width: 0;
    min-height: 40px;
    padding: 8px 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .list-controlbar > #hideCompleted,
  .list-controlbar > #stateFilter,
  .list-controlbar > #clearSort {
    grid-column: 1 / -1;
  }

  .list-controlbar select,
  .list-controlbar button,
  .table-search {
    width: 100%;
    min-width: 0;
    min-height: var(--mobile-control-height);
    padding: 9px 8px;
    font-size: 12px;
  }

  .sort-info {
    grid-column: 1 / -1;
    min-height: 18px;
    margin: 0;
    overflow: hidden;
    color: #78869a;
    font-size: 10.5px;
    line-height: 1.4;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sort-guide,
  .sort-info:empty {
    display: none;
  }

  .table-scroll {
    min-height: 320px;
    max-height: min(58dvh, 560px);
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 980px;
  }

  th,
  td {
    padding: 11px 9px;
    font-size: 11.5px;
  }

  #tableHead th:first-child,
  #tableBody td:first-child {
    position: sticky;
    left: 0;
    z-index: 3;
    background: #f0f4f8;
    box-shadow: 2px 0 5px #1722351a;
  }

  #tableHead th:first-child {
    z-index: 5;
    background: #e7edf5;
  }

  #tableBody tr:hover td:first-child,
  #tableBody tr.active td:first-child {
    background: #e4efff;
  }

  .table-summary {
    grid-template-columns: repeat(5, minmax(112px, 1fr));
    max-width: 100%;
    overflow-x: auto;
  }

  .summary-item {
    min-width: 112px;
    padding: 10px 9px;
  }

  .empty-table-state {
    min-height: 260px;
    padding: 24px 14px;
  }

  .empty-table-state h3 {
    line-height: 1.45;
  }

  .alert-tabs {
    gap: 4px;
    padding-left: 8px;
    margin-bottom: -10px;
  }

  .alert-tab {
    min-height: 38px;
    padding: 9px 9px 8px;
    font-size: 10.5px;
  }

  .alert-tab span {
    padding: 1px 6px;
    font-size: 12px;
  }

  .alert-panel {
    max-height: 230px;
    padding: 12px;
  }

  .alert-heading {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr);
    gap: 7px;
    align-items: start;
  }

  .alert-heading h2,
  .alert-heading p {
    overflow-wrap: anywhere;
  }

  .alert-heading h2 {
    font-size: 12px;
    line-height: 1.35;
  }

  .alert-heading p {
    font-size: 10.5px;
    line-height: 1.4;
  }

  .alert-item {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
    padding: 10px 2px;
    font-size: 11.5px;
  }

  .alert-item > span:last-child {
    align-self: flex-end;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .stat {
    min-width: 0;
    padding: 10px;
    border-radius: 9px;
  }

  .stat b {
    font-size: 19px;
  }

  .form-panel {
    min-height: 260px;
    max-height: none;
  }

  .form-grid,
  .typography-settings,
  .column-options,
  .proximity-settings {
    grid-template-columns: 1fr;
  }

  .form-heading {
    align-items: flex-start;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .info-card {
    border-right: 0;
    border-bottom: 1px solid #e3e8ef;
  }

  .info-card:last-child {
    border-bottom: 0;
  }

  .field {
    padding: 10px;
  }

  .field input,
  .field select,
  .save-button {
    min-height: 44px;
  }

  .file-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .file-actions > * {
    min-width: 0;
    min-height: var(--mobile-control-height);
    padding: 9px 7px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .file-actions .logout-button {
    grid-column: 1 / -1;
  }

  .column-options {
    gap: 7px;
  }

  .column-options label {
    min-height: 42px;
  }

  .column-filter-menu {
    width: calc(100vw - 20px) !important;
    max-height: min(76dvh, 600px);
    overflow: auto;
  }

  .column-filter-values {
    max-height: 38dvh;
  }

  .column-filter-actions {
    position: sticky;
    bottom: -1px;
    padding-top: 8px;
    background: #fff;
  }

  .map-dialog {
    width: calc(100vw - 16px);
    height: calc(100dvh - 20px);
    max-width: none;
    max-height: none;
    border-radius: 10px;
  }

  .map-heading {
    align-items: flex-start;
    gap: 8px;
    padding: 11px 44px 9px 11px;
  }

  .map-heading h2 {
    font-size: 14px;
  }

  .map-heading p {
    font-size: 10px;
    line-height: 1.35;
  }

  .map-actions {
    flex-wrap: wrap;
    gap: 6px;
  }

  .map-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .map-details {
    display: block;
    order: 2;
    flex: 0 1 34dvh;
    max-height: 34dvh;
    min-height: 128px;
    overflow: auto;
    border-top: 1px solid #cbd5e2;
    border-right: 0;
    padding: 12px;
    background: #f8fafc;
    -webkit-overflow-scrolling: touch;
  }

  .map-canvas {
    order: 1;
    flex: 1 1 auto;
    min-height: 42dvh;
  }

  .map-close {
    top: 8px;
    right: 8px;
  }

  /* Use scan-friendly cards for rows while keeping the sortable header usable. */
  .table-scroll {
    max-height: min(64dvh, 620px);
    padding: 0;
    background: #f2f5f9;
  }

  .table-scroll > table {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .table-scroll > table > thead {
    display: block;
    position: sticky;
    top: 0;
    z-index: 8;
    overflow-x: auto;
    background: #e7edf5;
    border-bottom: 1px solid #b8c5d4;
    scrollbar-width: thin;
  }

  .table-scroll > table > thead > tr {
    display: table;
    width: max-content;
    min-width: 980px;
    table-layout: fixed;
  }

  .table-scroll > table > thead th {
    position: static;
    min-width: 112px;
    padding: 9px 8px;
    background: #e7edf5;
    font-size: 10.5px;
  }

  .table-scroll > table > thead th:first-child {
    position: sticky;
    left: 0;
    z-index: 9;
    min-width: 82px;
    background: #dfe7f1;
  }

  .table-scroll > table > tbody {
    display: grid;
    gap: 7px;
    padding: 8px;
  }

  .table-scroll > table > tbody > tr {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "status office nearest"
      "status management machine"
      "status search search"
      "status address address"
      "status order completed";
    min-height: 116px;
    padding: 10px 10px 9px;
    border: 1px solid #d6e0eb;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 2px 7px #17223510;
    cursor: pointer;
  }

  .table-scroll > table > tbody > tr:hover,
  .table-scroll > table > tbody > tr.active {
    box-shadow: 0 0 0 2px #315fd4, 0 4px 12px #315fd426;
  }

  .table-scroll > table > tbody > tr.warn-row,
  .table-scroll > table > tbody > tr.danger-row,
  .table-scroll > table > tbody > tr.offline-row {
    border-left-width: 4px;
  }

  .table-scroll > table > tbody > tr.warn-row {
    border-left-color: #e8912a;
    background: #fffaf2;
  }

  .table-scroll > table > tbody > tr.danger-row {
    border-left-color: #e2483d;
    background: #fff6f5;
  }

  .table-scroll > table > tbody > tr.offline-row {
    border-left-color: #8995a5;
    background: #f0f3f7;
  }

  .table-scroll > table > tbody td {
    display: none;
    min-width: 0;
    padding: 3px 6px;
    border: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    font-size: 11.5px;
    line-height: 1.35;
  }

  .table-scroll > table > tbody td::before {
    display: block;
    margin-bottom: 2px;
    color: #7a8798;
    font-size: 9px;
    font-weight: 700;
    line-height: 1.2;
  }

  .table-scroll > table > tbody td[data-column="ステータス"],
  .table-scroll > table > tbody td[data-column="一致判定"],
  .table-scroll > table > tbody td[data-column="通信状態"] {
    display: flex;
    grid-area: status;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 5px 4px 5px 0;
    border-right: 1px solid #e1e7ef;
    white-space: nowrap;
    text-align: center;
  }

  .table-scroll > table > tbody td[data-column="通信状態"] .status-dot {
    flex: 0 0 auto;
  }

  .table-scroll > table > tbody td[data-column="最寄営業所"] {
    display: block;
    grid-area: office;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 800;
  }

  .table-scroll > table > tbody td[data-column="最寄営業所"]::before {
    content: "最寄営業所";
  }

  .table-scroll > table > tbody td[data-column="最寄距離km"] {
    display: block;
    grid-area: nearest;
    color: #315a9a;
    font-weight: 800;
    text-align: right;
  }

  .table-scroll > table > tbody td[data-column="最寄距離km"]::before {
    content: "営業所まで";
  }

  .table-scroll > table > tbody td.search-distance-cell {
    display: block;
    grid-area: search;
    color: #315a9a;
    font-weight: 800;
    text-align: right;
  }

  .table-scroll > table > tbody td.search-distance-cell::before {
    content: "検索場所から";
  }

  .table-scroll > table > tbody td[data-column="管理番号"],
  .table-scroll > table > tbody td[data-column="管理NO"],
  .table-scroll > table > tbody td[data-column="管理No"] {
    display: block;
    grid-area: management;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 800;
  }

  .table-scroll > table > tbody td[data-column="管理番号"]::before,
  .table-scroll > table > tbody td[data-column="管理NO"]::before,
  .table-scroll > table > tbody td[data-column="管理No"]::before {
    content: "管理番号";
  }

  .table-scroll > table > tbody td[data-column="製造番号"],
  .table-scroll > table > tbody td[data-column="号機"] {
    display: block;
    grid-area: machine;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
  }

  .table-scroll > table > tbody td[data-column="製造番号"]::before,
  .table-scroll > table > tbody td[data-column="号機"]::before {
    content: "号機";
  }

  .table-scroll > table > tbody td[data-column="位置住所"] {
    display: block;
    grid-area: address;
    overflow: hidden;
    color: #46556c;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .table-scroll > table > tbody td[data-column="位置住所"]::before {
    content: "現在位置";
    display: inline;
    margin-right: 6px;
  }

  .table-scroll > table > tbody td[data-column="受注日"],
  .table-scroll > table > tbody td[data-column="受注完了日"] {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #536174;
  }

  .table-scroll > table > tbody td[data-column="受注日"] {
    grid-area: order;
  }

  .table-scroll > table > tbody td[data-column="受注完了日"] {
    grid-area: completed;
    text-align: right;
  }

  .table-scroll > table > tbody td[data-column="受注日"]::before {
    content: "受注日";
  }

  .table-scroll > table > tbody td[data-column="受注完了日"]::before {
    content: "受注完了日";
  }

  .table-scroll > table > tbody td[data-column="受注日"]::before,
  .table-scroll > table > tbody td[data-column="受注完了日"]::before {
    display: inline;
    margin-right: 5px;
  }

  .table-scroll > table > tbody td.status-cell span:last-child {
    display: none;
  }

  .table-scroll > table > tbody td.mark-cell {
    display: flex;
    grid-area: status;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 5px 4px 5px 0;
    border-right: 1px solid #e1e7ef;
    white-space: nowrap;
    text-align: center;
  }

  .table-scroll > table > tbody td.mark-cell .nearest-distance-inline {
    margin: 0;
    padding: 1px 3px;
    font-size: 9px;
    line-height: 1.25;
  }

  /* Mobile map surface: map first, compact controls above, details as a sheet. */
  .map-dialog {
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    border-radius: 0;
  }

  .map-window {
    height: 100dvh;
    min-height: 0;
    background: #eef3f7;
  }

  .map-close {
    top: max(10px, env(safe-area-inset-top));
    right: 10px;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    z-index: 20;
    font-size: 25px;
  }

  .map-heading {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    min-height: 0;
    padding: max(10px, env(safe-area-inset-top)) 58px 9px 12px;
    background: #fff;
    box-shadow: 0 2px 9px #1722351f;
  }

  .map-heading > div:first-child {
    min-width: 0;
  }

  .map-heading h2 {
    margin: 0;
    font-size: 15px;
    line-height: 1.3;
  }

  .map-heading p {
    max-width: 100%;
    margin: 3px 0 0;
    overflow: hidden;
    color: #667488;
    font-size: 10.5px;
    line-height: 1.4;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .map-actions {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    justify-content: stretch;
    gap: 7px;
    width: 100%;
  }

  .map-layer-toggle {
    flex: none;
  }

  .map-layer-toggle button {
    min-width: 61px;
    height: 40px;
    padding: 0 8px;
  }

  .google-map-button {
    width: 100%;
    min-height: 40px;
    overflow: hidden;
    padding: 8px 7px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .map-body {
    position: relative;
    display: block;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .map-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
  }

  .map-canvas .leaflet-control-zoom {
    margin-top: 10px;
    margin-left: 10px;
  }

  .map-canvas .leaflet-control-zoom a {
    width: 38px;
    height: 38px;
    font-size: 22px;
    line-height: 36px;
  }

  .map-details {
    position: absolute;
    z-index: 700;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 10px;
    display: block;
    max-height: min(38dvh, 360px);
    margin: 0;
    padding: 0;
    overflow: auto;
    border: 1px solid #cad5e2;
    border-radius: 15px;
    background: #f8fafc;
    box-shadow: 0 10px 28px #17223538;
    -webkit-overflow-scrolling: touch;
  }

  .map-details::before {
    content: "";
    display: block;
    width: 38px;
    height: 4px;
    margin: 8px auto 0;
    border-radius: 99px;
    background: #b6c2d0;
  }

  .map-detail-heading {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 9px 12px 10px;
    background: #f8fafc;
  }

  .map-detail-machine {
    font-size: 14px;
  }

  .map-detail-status {
    margin-top: 7px;
    padding: 6px 8px;
  }

  .map-detail-section {
    padding: 10px 12px;
  }

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

  .map-detail-item,
  .map-detail-wide {
    min-height: 48px;
    padding: 8px;
  }

  .map-detail-item .value,
  .map-detail-wide .value {
    font-size: 11px;
  }
}

/* Reference-inspired mobile surface. All rules below remain viewport-scoped. */
@media screen and (max-width: 760px) {
  :root {
    --mobile-gutter: 6px;
    --mobile-radius: 14px;
    --mobile-control-height: 42px;
  }

  html,
  body {
    background: #f5f7fa;
  }

  body {
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
    color: #1f2937;
  }

  .app-shell {
    padding-bottom: 0;
  }

  .app-header {
    position: relative;
    z-index: 40;
    padding: 16px 18px 13px;
    border-bottom: 1px solid #dfe4eb;
    background: #fff;
    box-shadow: none;
  }

  .title-block h1 {
    font-size: 21px;
    font-weight: 800;
    line-height: 1.25;
  }

  .dashboard {
    display: flex !important;
    flex-direction: column;
    gap: 8px;
    padding: 8px 6px calc(84px + env(safe-area-inset-bottom));
  }

  .left-column,
  .right-column,
  #progressWorkspace,
  #settingsWorkspace {
    display: contents;
  }

  #progressWorkspace[hidden],
  #settingsWorkspace[hidden] {
    display: none !important;
  }

  .workspace-tabs {
    position: relative;
    top: auto;
    z-index: 20;
    order: 0;
    width: calc(100% - 22px);
    margin: 0 auto 2px;
    padding: 5px;
    border: 1px solid #c9d1dc;
    border-radius: 15px;
    background: #fff;
    box-shadow: 0 3px 8px #1f29371c;
  }

  .workspace-tab {
    min-height: 48px;
    border-radius: 11px;
    font-size: 16px;
    font-weight: 800;
  }

  .workspace-tab:not(.active) {
    color: #738094;
    background: #f4f6f9;
  }

  .workspace-tab.active {
    background: #171a23;
    color: #fff;
  }

  .table-wrap {
    order: 1;
    width: 100%;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .table-header {
    display: none;
  }

  .list-controlbar {
    grid-template-columns: 102px minmax(0, 1fr);
    gap: 6px;
    padding: 4px 12px 7px;
    background: transparent;
  }

  .list-controlbar > #tableTitle {
    display: none;
  }

  .list-controlbar > #searchMode {
    grid-column: 1;
    min-height: 38px;
    padding: 6px 7px;
    border-color: #c8d1dd;
    border-radius: 9px;
    background: #fff;
    font-size: 12px;
    font-weight: 700;
  }

  .list-controlbar > #tableSearch {
    grid-column: 2;
    min-height: 38px;
    border-color: #c8d1dd;
    border-radius: 9px;
    background: #fff;
  }

  .list-controlbar > #workPresetSelect,
  .list-controlbar > #saveWorkPreset,
  .list-controlbar > #resetWorkPreset,
  .list-controlbar > #deleteWorkPreset,
  .list-controlbar > #hideCompleted,
  .list-controlbar > #stateFilter,
  .list-controlbar > #clearFilters,
  .list-controlbar > #clearSort {
    display: none;
  }

  .list-controlbar > #sortButton {
    display: block;
    grid-column: 1 / -1;
    min-height: 34px;
    padding: 4px 8px;
    border: 0;
    background: transparent;
    color: #667386;
    font-size: 12px;
    font-weight: 700;
    text-align: left;
  }

  .sort-info {
    display: block;
    grid-column: 1 / -1;
    min-height: 20px;
    color: #768397;
    font-size: 12px;
    font-weight: 700;
  }

  .table-scroll {
    max-height: none;
    min-height: 0;
    overflow: visible;
    background: transparent;
  }

  .table-scroll > table > thead {
    position: relative;
    top: auto;
    margin: 0 -6px;
    border-top: 1px solid #c9d2de;
    border-bottom: 1px solid #c9d2de;
    background: #edf2f7;
  }

  .table-scroll > table > thead > tr {
    min-width: 760px;
  }

  .table-scroll > table > thead th {
    min-width: 138px;
    padding: 10px 11px;
    border-right: 1px solid #d5dce5;
    color: #344154;
    font-size: 12px;
    font-weight: 800;
  }

  .table-scroll > table > thead th:first-child {
    min-width: 145px;
    background: #e4ebf3;
  }

  .table-scroll > table > tbody {
    gap: 9px;
    padding: 10px 22px 8px;
  }

  .table-scroll > table > tbody > tr {
    position: relative;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "management machine"
      "order machine"
      "office nearest"
      "address address"
      "completed completed";
    min-height: 154px;
    padding: 14px 14px 12px;
    border: 1px solid #d6dde7;
    border-radius: 15px;
    background: #fff;
    box-shadow: 0 2px 6px #26384b14;
    transition: border-color .16s ease, box-shadow .16s ease;
  }

  .table-scroll > table > tbody > tr:hover,
  .table-scroll > table > tbody > tr.active {
    box-shadow: 0 0 0 3px #2f62cc, 0 5px 13px #2f62cc26;
  }

  .table-scroll > table > tbody td {
    font-size: 13px;
    line-height: 1.3;
  }

  .table-scroll > table > tbody td::before {
    color: #8a96a6;
    font-size: 10px;
    font-weight: 700;
  }

  .table-scroll > table > tbody td[data-column="管理番号"],
  .table-scroll > table > tbody td[data-column="管理NO"],
  .table-scroll > table > tbody td[data-column="管理No"] {
    align-self: start;
    max-width: 150px;
    padding: 5px 9px;
    border-radius: 4px;
    background: #eef4fb;
    color: #27384f;
    font-size: 17px;
  }

  .table-scroll > table > tbody td[data-column="製造番号"],
  .table-scroll > table > tbody td[data-column="号機"] {
    align-self: end;
    padding: 4px 2px 5px 7px;
    color: #364154;
    font-size: 16px;
    font-weight: 700;
  }

  .table-scroll > table > tbody td[data-column="最寄営業所"] {
    padding-top: 8px;
    color: #46556a;
    font-size: 12px;
  }

  .table-scroll > table > tbody td[data-column="最寄距離km"] {
    padding-top: 8px;
    color: #536a89;
    font-size: 12px;
  }

  .table-scroll > table > tbody td[data-column="位置住所"] {
    padding-top: 7px;
    border-top: 1px solid #edf0f4;
    color: #687589;
    font-size: 11px;
  }

  .table-scroll > table > tbody td[data-column="受注日"],
  .table-scroll > table > tbody td[data-column="受注完了日"] {
    padding-top: 0;
    color: #536174;
    font-size: 12px;
  }

  .table-scroll > table > tbody td[data-column="受注完了日"] {
    text-align: right;
  }

  .table-scroll > table > tbody td[data-column="一致判定"],
  .table-scroll > table > tbody td[data-column="ステータス"],
  .table-scroll > table > tbody td[data-column="通信状態"] {
    position: absolute;
    top: 14px;
    left: -9px;
    display: flex;
    width: 17px;
    height: 17px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px #26384b33;
  }

  .table-scroll > table > tbody td.mark-cell {
    position: absolute;
    top: 14px;
    left: -9px;
    display: flex;
    width: 17px;
    height: 17px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #fff;
  }

  .table-summary {
    position: sticky;
    bottom: 0;
    z-index: 15;
    display: flex;
    grid-template-columns: none;
    min-height: 74px;
    margin: 0 -6px;
    overflow-x: auto;
    border-top: 1px solid #d5dce5;
    background: #fff;
    box-shadow: 0 -3px 10px #1f29371a;
  }

  .summary-item {
    flex: 0 0 25%;
    min-width: 112px;
    padding: 10px 9px 8px;
    border-right: 1px solid #d5dce5;
  }

  .summary-item b {
    font-size: 20px;
  }

  .alert-tabs,
  .alert-panel,
  .settings-search-panel,
  .form-panel,
  .settings-workspace {
    order: 4;
  }

  /* MERiT mobile controls: keep the connection state readable at a glance. */
  .settings-workspace .merit-settings-panel {
    display: block;
    margin: 0 8px 10px;
    padding: 16px 14px 14px;
    border: 1px solid #d7dee8;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 2px 8px #1f293714;
  }

  .settings-workspace .merit-settings-heading {
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
  }

  .settings-workspace .merit-settings-heading h2 {
    margin: 0;
    color: #172033;
    font-size: 18px;
    line-height: 1.3;
  }

  .settings-workspace .merit-settings-heading p {
    margin-top: 4px;
    color: #667386;
    font-size: 11px;
    line-height: 1.45;
  }

  .settings-workspace .merit-status-badge {
    flex: 0 0 auto;
    min-height: 30px;
    padding: 0 9px;
    border: 1px solid #d7dee8;
    background: #f3f5f8;
    color: #667386;
    font-size: 11px;
  }

  .settings-workspace .merit-status-badge.active {
    border-color: #b8e1ca;
    background: #edf9f1;
    color: #147a48;
  }

  .settings-workspace .merit-connection-card {
    display: block;
    margin-top: 0;
    padding: 12px;
    border: 1px solid #dce3ec;
    border-radius: 11px;
    background: #f7f9fb;
  }

  .settings-workspace .merit-connection-card strong {
    color: #172033;
    font-size: 15px;
    line-height: 1.35;
  }

  .settings-workspace .merit-connection-card small {
    margin-top: 5px;
    color: #718096;
    font-size: 11px;
    line-height: 1.45;
  }

  .settings-workspace .merit-connection-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 12px;
  }

  .settings-workspace .merit-connection-actions button {
    width: 100%;
    min-height: 46px;
    margin: 0;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 800;
  }

  .settings-workspace .merit-connection-actions #meritLocationRefreshButton {
    border-color: #aec6e9;
    background: #eef5ff;
    color: #245caa;
  }

  .settings-workspace .merit-connection-actions #meritLocationRefreshButton:disabled {
    opacity: .65;
  }

  .settings-workspace .merit-connection-actions #meritLoginButton.merit-logout-button {
    border-color: #b42318 !important;
    background: #b42318 !important;
    color: #fff !important;
  }

  .settings-workspace .merit-monitor-settings {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 12px;
  }

  .settings-workspace .merit-monitor-settings label {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px 12px;
    min-height: 48px;
    padding: 9px 10px;
    border: 1px solid #e0e6ee;
    border-radius: 9px;
    background: #fff;
    color: #667386;
    font-size: 11px;
    line-height: 1.35;
  }

  .settings-workspace .merit-monitor-settings label strong,
  .settings-workspace .merit-monitor-settings label select {
    grid-column: 2;
    grid-row: 1 / span 2;
    min-width: 118px;
    min-height: 36px;
    margin: 0;
    padding: 0 9px;
    border: 1px solid #d6deea;
    border-radius: 8px;
    background: #f7f9fb;
    color: #172033;
    font-size: 12px;
    font-weight: 800;
  }

  .settings-workspace .merit-monitor-settings label select {
    font-weight: 700;
  }

  .settings-workspace .merit-monitor-settings label small {
    grid-column: 1;
    grid-row: 2;
    color: #8591a2;
    font-size: 10px;
  }

  .settings-workspace .merit-monitor-settings label:first-child strong {
    color: #147a48;
  }

  .settings-workspace .merit-settings-panel > .setting-note {
    margin: 10px 2px 0;
    color: #7a8798;
    font-size: 10px;
    line-height: 1.55;
  }

  .settings-workspace .merit-settings-panel > .setting-note + .setting-note {
    margin-top: 3px;
  }

  .alert-tabs {
    margin: 8px 8px 0;
    padding: 0;
  }

  .alert-tab {
    min-height: 42px;
    padding: 9px 12px;
    border-radius: 10px 10px 0 0;
    font-size: 12px;
  }

  .alert-panel,
  .settings-search-panel,
  .form-panel {
    margin: 0 8px;
  }

  .mobile-bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1000;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    min-height: 68px;
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid #d5dce5;
    background: #fff;
    box-shadow: 0 -3px 14px #1f29371c;
  }

  .mobile-bottom-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    border: 0;
    background: transparent;
    color: #6d7787;
    font: inherit;
  }

  .mobile-bottom-nav button span {
    font-size: 22px;
    line-height: 1;
  }

  .mobile-bottom-nav button small {
    font-size: 11px;
    font-weight: 700;
  }

  .mobile-bottom-nav button.active {
    color: #12a9b1;
  }

  .column-filter-menu,
  .sort-dialog {
    position: fixed !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    top: auto !important;
    width: 100vw !important;
    max-width: none !important;
    max-height: min(82dvh, 680px);
    margin: 0 !important;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 28px #1f29373d;
  }

  .column-filter-menu::before,
  .sort-dialog::before {
    content: "";
    display: block;
    width: 38px;
    height: 4px;
    margin: 9px auto 4px;
    border-radius: 99px;
    background: #c1cad5;
  }
}

@media screen and (min-width: 761px) {
  .mobile-bottom-nav {
    display: none;
  }
}

/* Mobile machine detail is an independent surface. Desktop map styles remain unchanged. */
@media screen and (max-width: 760px) {
  .map-dialog {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: #f6f7f8;
  }

  .map-window {
    position: relative;
    display: flex;
    width: 100%;
    height: 100%;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
    background: #f6f7f8;
  }

  .map-heading {
    display: none !important;
  }

  .map-dialog.mobile-map-view .map-heading {
    display: flex !important;
  }

  .map-close {
    position: absolute;
    top: max(9px, env(safe-area-inset-top));
    right: auto;
    left: 13px;
    z-index: 80;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 0;
    background: transparent;
    color: #17191e;
    font-size: 0;
    line-height: 1;
  }

  .map-close::after {
    content: "‹";
    display: block;
    font-size: 42px;
    font-weight: 300;
    line-height: 35px;
  }

  .map-dialog.mobile-map-view .map-close {
    top: 8px;
    right: 10px;
    left: auto;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 5px #1118271c;
  }

  .map-dialog.mobile-map-view .map-close::after {
    content: "×";
    font-size: 30px;
    line-height: 36px;
  }

  .mobile-machine-detail {
    display: flex;
    min-height: 0;
    flex: 1;
    flex-direction: column;
    color: #15171b;
  }

  .mobile-detail-title {
    flex: 0 0 auto;
    padding: max(48px, calc(env(safe-area-inset-top) + 38px)) 20px 14px 62px;
    border-bottom: 1px solid #e1e3e6;
    background: #fff;
  }

  .mobile-detail-title small {
    display: block;
    margin-bottom: 4px;
    color: #72777e;
    font-size: 12px;
    font-weight: 700;
  }

  .mobile-detail-title h2 {
    margin: 0;
    color: #17191e;
    font-size: 21px;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: 0;
    word-break: break-word;
  }

  .mobile-detail-tabs {
    display: flex;
    flex: 0 0 auto;
    min-height: 73px;
    overflow-x: auto;
    border-bottom: 1px solid #e2e4e7;
    background: #fff;
    scrollbar-width: none;
  }

  .mobile-detail-tabs::-webkit-scrollbar { display: none; }

  .mobile-detail-tabs button {
    position: relative;
    flex: 1 0 82px;
    min-width: 82px;
    padding: 34px 4px 10px;
    border: 0;
    background: transparent;
    color: #747980;
    font: 700 11px/1.1 "Yu Gothic UI", Meiryo, sans-serif;
    white-space: nowrap;
  }

  .mobile-detail-tabs button::before {
    position: absolute;
    top: 9px;
    left: 50%;
    color: #747980;
    content: "○";
    font-size: 22px;
    font-weight: 300;
    line-height: 1;
    transform: translateX(-50%);
  }

  .mobile-detail-tabs button:nth-child(2)::before { content: "♢"; }
  .mobile-detail-tabs button:nth-child(3)::before { content: "△"; }
  .mobile-detail-tabs button:nth-child(4)::before { content: "⌖"; }
  .mobile-detail-tabs button:nth-child(5)::before { content: "◔"; }

  .mobile-detail-tabs button.active {
    color: #10a6ae;
  }

  .mobile-detail-tabs button.active::after {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: 4px;
    background: #10a6ae;
    content: "";
  }

  .mobile-detail-tabs button.active::before { color: #10a6ae; }

  .mobile-detail-content {
    min-height: 0;
    flex: 1;
    overflow-y: auto;
    padding: 9px 6px calc(82px + env(safe-area-inset-bottom));
    background: #f1f2f3;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-detail-warning {
    display: grid;
    gap: 5px;
    margin-bottom: 8px;
    padding: 14px 12px;
    border: 2px solid #f02d2d;
    border-radius: 5px;
    background: #fff;
    color: #df2424;
  }

  .mobile-detail-warning strong { font-size: 16px; line-height: 1.35; }
  .mobile-detail-warning span { color: #353a42; font-size: 13px; }

  .mobile-detail-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1px;
    margin-bottom: 8px;
    padding: 18px 10px 14px;
    border-radius: 5px;
    background: #fff;
  }

  .mobile-detail-metrics .mobile-detail-card { min-height: 87px; border: 0; text-align: center; }
  .mobile-detail-metrics .mobile-detail-card span::before { display: block; content: ""; }
  .mobile-detail-metrics .mobile-detail-card strong { margin-top: 7px; font-size: 24px; }

  .mobile-detail-card {
    display: flex;
    min-width: 0;
    min-height: 57px;
    flex-direction: column;
    justify-content: center;
    padding: 8px 10px;
    border-bottom: 1px solid #eceeef;
    background: #fff;
  }

  .mobile-detail-card span,
  .mobile-detail-label {
    color: #767b82;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.3;
  }

  .mobile-detail-card strong {
    margin-top: 3px;
    color: #15171b;
    font-size: 16px;
    font-weight: 800;
    line-height: 1.35;
    word-break: break-word;
  }

  .mobile-detail-card.attention strong { color: #dc2828; }
  .mobile-detail-card.online strong { color: #0a9b65; }

  .mobile-detail-location,
  .mobile-detail-info,
  .mobile-detail-office {
    margin-bottom: 8px;
    padding: 14px 12px;
    border-radius: 5px;
    background: #fff;
  }

  .mobile-detail-location {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .mobile-detail-location-copy { min-width: 0; flex: 1; }
  .mobile-detail-location-copy::before { content: "⌖"; float: left; margin: 1px 8px 0 0; color: #22262c; font-size: 22px; }
  .mobile-detail-location-copy strong { display: block; margin-top: 4px; color: #262a30; font-size: 16px; line-height: 1.35; word-break: break-word; }
  .mobile-detail-location-copy small { display: block; margin-top: 5px; color: #646a72; font-size: 13px; }

  .mobile-detail-location-button,
  .mobile-detail-edit {
    flex: 0 0 auto;
    min-height: 42px;
    padding: 7px 12px;
    border: 1px solid #0da9b0;
    border-radius: 5px;
    background: #fff;
    color: #0b9fa8;
    font: 700 14px/1 "Yu Gothic UI", Meiryo, sans-serif;
  }

  .mobile-detail-location-button:disabled,
  .mobile-detail-edit:disabled { opacity: .45; }

  .mobile-detail-info header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
  .mobile-detail-info h3 { margin: 0; color: #181b20; font-size: 20px; line-height: 1.3; }
  .mobile-detail-info .mobile-detail-card:last-child { border-bottom: 0; }

  .mobile-detail-office { display: grid; gap: 4px; }
  .mobile-detail-office strong { color: #15171b; font-size: 16px; }
  .mobile-detail-office small { color: #5f666e; font-size: 12px; line-height: 1.4; }
  .mobile-detail-empty { padding: 25px 8px; color: #69717a; font-size: 14px; line-height: 1.6; text-align: center; }

  .mobile-detail-bottom-nav {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    min-height: 66px;
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid #dfe2e5;
    background: #fff;
  }

  .mobile-detail-bottom-nav button { display: grid; place-items: center; gap: 2px; border: 0; background: transparent; color: #777d84; font: inherit; }
  .mobile-detail-bottom-nav button span { font-size: 24px; line-height: 1; }
  .mobile-detail-bottom-nav button small { font-size: 11px; font-weight: 700; }
  .mobile-detail-bottom-nav button.active { color: #10a6ae; }

  .map-dialog.mobile-detail-view .map-body { display: none !important; }
  .map-dialog.mobile-map-view .mobile-machine-detail { display: none !important; }
  .map-dialog.mobile-map-view .map-body { display: block !important; position: relative; flex: 1; min-height: 0; }
}

.mobile-loading-state[hidden] {
  display: none !important;
}

@media screen and (max-width: 760px) {
  .mobile-loading-state {
    position: fixed;
    inset: 0;
    z-index: 1400;
    display: grid;
    place-items: center;
    background: rgb(255 255 255 / 91%);
    backdrop-filter: blur(1px);
  }

  .mobile-loading-content {
    display: flex;
    align-items: baseline;
    gap: 26px;
    margin-top: -4dvh;
    color: #12151b;
    font-size: 25px;
    letter-spacing: 7px;
  }

  .mobile-loading-dots {
    display: inline-flex;
    gap: 4px;
    letter-spacing: 0;
  }

  .mobile-loading-dots i {
    display: block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #13a9b1;
    animation: mobile-loading-dot 1.15s ease-in-out infinite;
  }

  .mobile-loading-dots i:nth-child(2) {
    animation-delay: .14s;
  }

  .mobile-loading-dots i:nth-child(3) {
    animation-delay: .28s;
  }

  @keyframes mobile-loading-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: .45; }
    30% { transform: translateY(-4px); opacity: 1; }
  }
}
