/* v154：平板數字鍵盤、多格觸控選取與桌機／平板欄位換位 */
input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

.worklog-job-nav-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
}
.worklog-job-nav-row > [data-worklog-job] {
  min-width: 0;
}
.worklog-visibility-toggle {
  min-width: 46px;
  padding: 3px 5px !important;
  border: 1px solid #82b89c !important;
  border-radius: 999px !important;
  background: #ecfdf3 !important;
  color: #176b3a !important;
  font-size: 10px !important;
  line-height: 1.2;
}
.worklog-visibility-toggle.is-hidden {
  border-color: #cbd5e1 !important;
  background: #f1f5f9 !important;
  color: #64748b !important;
}
.worklog-closed-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 5px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #475569;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}
.worklog-closed-badge.detail {
  padding: 4px 9px;
  font-size: 12px;
}

/* 表格在可視範圍內自己捲動；底部只保留一組水平捲軸與分頁。 */
.mi-table-card {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 250px);
  min-height: 0;
}
.mi-table-card .mi-table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  scrollbar-gutter: stable;
}
.mi-table-card .mi-pagination {
  flex: 0 0 auto;
  position: sticky;
  bottom: 0;
  z-index: 8;
  border-top: 1px solid #cbd5e1;
}
.mi-table td.active-cell {
  position: relative;
  outline: 2px solid #1677c8 !important;
  outline-offset: -2px;
  background: #eaf5ff !important;
}
.mi-table td.active-cell::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 5px;
  height: 5px;
  background: #1677c8;
}
.mi-table td[data-cell] > input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  border: 0;
  outline: 0;
  background: #fff;
  text-align: inherit;
}

/* 所有資料欄都可縮至很窄；內容依欄寬換行，之後仍可拉寬查看。 */
.mi-table:not(.mi-history-compare) {
  table-layout: fixed;
  width: var(--mi-table-width) !important;
  min-width: var(--mi-table-width) !important;
  max-width: none;
}
.mi-table col {
  min-width: 0;
}
.mi-table th:not(.mi-check-col),
.mi-table td:not(.mi-check-col) {
  min-width: 24px !important;
  max-width: none;
  white-space: normal !important;
  overflow-wrap: anywhere;
  word-break: break-word;
  overflow: hidden;
  text-overflow: clip;
}
.mi-table th:not(.mi-check-col) > span {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.mi-table .mi-merged-cell,
.mi-history-compare th:first-child,
.mi-history-compare td:first-child,
.mi-history-compare th:nth-child(2),
.mi-history-compare td:nth-child(2) {
  min-width: 24px !important;
  max-width: none !important;
}
.mi-table .mi-input-cell > input,
.mi-table .mi-drawing-input-row input {
  min-width: 0 !important;
}
.mi-table .mi-drawing-cell {
  min-width: 0 !important;
  max-width: 100%;
  overflow: hidden;
}
.mi-table .mi-drawing-input-row {
  min-width: 0;
  flex-wrap: wrap;
}

/* 核取方框欄維持可操作的固定寬度，不跟著資料欄縮小。 */
.mi-table th.mi-check-col,
.mi-table td.mi-check-col {
  width: 36px !important;
  min-width: 36px !important;
  max-width: 36px !important;
  white-space: nowrap !important;
  overflow: visible;
}

/* 平板保留細線外觀，但把可按住拖曳的觸控範圍加寬。 */
.mi-table .mi-col-resizer {
  right: -12px;
  width: 24px;
  z-index: 7;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.mi-table .mi-col-resizer::after {
  content: "";
  position: absolute;
  top: 18%;
  bottom: 18%;
  left: 11px;
  width: 2px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.55);
}
@media (pointer: coarse) {
  .mi-table .mi-col-resizer {
    right: -16px;
    width: 32px;
  }
  .mi-table .mi-col-resizer::after {
    left: 15px;
  }
}

/* 平板專用右下角數字鍵盤：實體尺寸約 6 × 8 公分。 */
.mi-tablet-number-keypad {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 13000;
  width: 6cm;
  height: 8cm;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 5px;
  padding: 8px;
  border-radius: 18px;
  background: #050505;
  box-shadow: 0 16px 42px rgba(0,0,0,.42);
  transform: translate(115%, 115%);
  opacity: 0;
  transition: transform .18s ease-out, opacity .18s ease-out;
  touch-action: none;
  user-select: none;
}
.mi-tablet-number-keypad.open { transform: translate(0, 0); opacity: 1; }
.mi-tablet-number-keypad button {
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  align-self: center;
  justify-self: center;
  width: min(1.55cm, 90%);
  border: 0;
  border-radius: 50%;
  background: #343434;
  color: #fff;
  font-size: .62cm;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.mi-tablet-number-keypad button:active { background: #5a5a5a; transform: scale(.94); }

.worklog-list-card,
.response-table-module {
  min-height: 0;
}
.worklog-list-card > .worklog-table-wrap,
.response-table-module > .response-table-scroll {
  max-height: min(62vh, 680px);
  overflow: auto;
  scrollbar-gutter: stable;
}
.worklog-table thead th {
  position: sticky;
  top: 0;
  z-index: 4;
}
.response-table-module {
  display: flex;
  flex-direction: column;
  max-height: min(70vh, 760px);
}
.response-table-module > .response-table-tools,
.response-table-module > .response-job-page-controls {
  flex: 0 0 auto;
}
.response-table-module > .response-table-scroll {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
}
.response-job-page-controls {
  position: sticky;
  bottom: 0;
  z-index: 7;
  justify-content: center;
  background: #fff;
  border-top: 1px solid #d8e1eb;
  padding: 8px;
}
.response-bottom-scrollbar {
  display: none !important;
}
body.has-response-bottom-scrollbar {
  padding-bottom: 0 !important;
}

@media (max-width: 900px) {
  .mi-table-card {
    height: calc(100dvh - 290px);
  }
  .worklog-list-card > .worklog-table-wrap,
  .response-table-module {
    max-height: 64vh;
  }
}

/* 所有表格與儲存格統一置中；窄欄位允許文字自動換行。 */
table { margin-inline: auto; }
table th,
table td {
  text-align: center !important;
  vertical-align: middle !important;
  white-space: normal;
  overflow-wrap: anywhere;
}
table th input,
table td input,
table th textarea,
table td textarea,
table th select,
table td select { text-align: center !important; }

.mi-table th[draggable] { cursor: grab; touch-action: pan-y; }
.mi-table th[draggable]:active,
.mi-table th.mi-column-dragging { cursor: grabbing; opacity: 0.78; }
.mi-table th.mi-column-drop-target { box-shadow: inset 4px 0 #38bdf8; background: #0b4773 !important; }

/* 平板可直接用手指水平／垂直捲動，不會被長按監聽阻擋。 */
.mi-table-wrap,
.worklog-table-wrap,
.response-table-scroll,
.summary-table-wrap,
.table-responsive,
[data-table-scroll] {
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.global-action-button {
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid #64748b;
  border-radius: 7px;
  background: #24334d;
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.global-action-button:hover,
.global-action-button:focus-visible {
  background: #334766;
  outline: 2px solid #38bdf8;
  outline-offset: 1px;
}
.v152-context-menu {
  position: fixed;
  z-index: 12000;
  display: grid;
  min-width: 176px;
  padding: 5px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.24);
}
.v152-context-menu[hidden] { display: none !important; }
.v152-context-menu button {
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #1e293b;
  text-align: left;
  cursor: pointer;
}
.v152-context-menu button:hover,
.v152-context-menu button:focus-visible { background: #eaf4ff; outline: none; }
.v152-context-menu button.danger { color: #c62828; }
@media (pointer: coarse) {
  .global-action-button { min-width: 74px; min-height: 38px; }
  .v152-context-menu button { min-height: 46px; font-size: 15px; }
}
