/**
 * 任務歷史紀錄彈窗 - 統一樣式
 * 操作員、客戶、廠商檢視共用，與 utils/ui/task-history-modal.js 搭配使用
 */

#task-history-modal {
  display: none !important;
  position: fixed;
  inset: 0;
  z-index: 10001;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  padding: 1rem;
  box-sizing: border-box;
}
#task-history-modal.show {
  display: flex !important;
}
#task-history-modal .modal-dialog {
  margin: 0;
  max-width: min(90vw, 800px);
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
#task-history-modal .modal-content {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
#task-history-modal .modal-header {
  flex-shrink: 0;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #e9ecef;
  background: #f8f9fa;
  border-radius: 12px 12px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#task-history-modal .modal-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}
#task-history-modal .modal-body {
  overflow-y: auto;
  padding: 1.25rem;
  flex: 1;
  min-height: 0;
}
#task-history-modal .task-history-forum-list {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
#task-history-modal .btn-close {
  background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23000'%3e%3cpath d='M.293.293a1 1 0 011.414 0L8 6.586 14.293.293a1 1 0 111.414 1.414L9.414 8l6.293 6.293a1 1 0 01-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 01-1.414-1.414L6.586 8 .293 1.707a1 1 0 010-1.414z'/%3e%3c/svg%3e") center/1em auto no-repeat;
  border: 0;
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  opacity: 0.6;
  cursor: pointer;
}
#task-history-modal .btn-close:hover {
  opacity: 1;
}

/* 版本區塊 */
#task-history-modal .task-history-forum-item {
  background: #fff;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
#task-history-modal .task-history-forum-item .d-flex {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: space-between;
  align-items: flex-start;
}
#task-history-modal .task-history-forum-item .fw-bold {
  font-weight: 600;
  color: #333;
}
#task-history-modal .task-history-forum-item .text-muted {
  color: #6c757d;
  font-size: 0.9rem;
}
#task-history-modal .task-history-forum-item .ms-2 { margin-left: 0.5rem; }
#task-history-modal .task-history-forum-item .mt-2 { margin-top: 0.5rem; }
#task-history-modal .task-history-forum-item .badge {
  display: inline-block;
  padding: 0.25em 0.5em;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1;
  border-radius: 4px;
}
#task-history-modal .task-history-forum-item .badge.bg-secondary {
  background-color: #6c757d;
  color: #fff;
}
#task-history-modal .task-history-forum-item .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.65rem;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.2;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}
#task-history-modal .task-history-forum-item .btn.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
}
#task-history-modal .task-history-forum-item .btn.btn-outline-primary {
  color: var(--primary-color, #4A6482);
  background-color: transparent;
  border-color: var(--primary-color, #4A6482);
}
#task-history-modal .task-history-forum-item .btn.btn-outline-primary:hover {
  color: #fff;
  background-color: var(--primary-color, #4A6482);
}
#task-history-modal .task-history-row-diff {
  margin-top: 0.5rem;
}

/* 還原時三個按鈕放在版本卡片內，與「版本 XX」同一塊 */
#task-history-modal .task-history-confirm-inline-actions {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e9ecef;
}
#task-history-modal .task-history-confirm-inline-actions .d-flex {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  justify-content: flex-start;
}
#task-history-modal .task-history-confirm-inline-actions .btn {
  font-size: 0.8125rem;
  padding: 0.4rem 0.85rem;
  border: none;
  color: #fff;
  font-weight: 500;
  border-radius: 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.1s ease;
}
#task-history-modal .task-history-confirm-inline-actions .btn:hover {
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
}
#task-history-modal .task-history-confirm-inline-actions .btn:active {
  transform: scale(0.98);
}
/* 直接儲存：主色藍 */
#task-history-modal .task-history-confirm-inline-actions .task-history-save-direct {
  background: #0d6efd;
  color: #fff;
}
#task-history-modal .task-history-confirm-inline-actions .task-history-save-direct:hover {
  background: #0b5ed7;
  color: #fff;
}
/* 更改但不儲存：綠色 */
#task-history-modal .task-history-confirm-inline-actions .task-history-apply-only {
  background: #198754;
  color: #fff;
  font-weight: 600;
}
#task-history-modal .task-history-confirm-inline-actions .task-history-apply-only:hover {
  background: #157347;
  color: #fff;
}
/* 取消：灰底 */
#task-history-modal .task-history-confirm-inline-actions .task-history-confirm-cancel {
  background: #6c757d;
  color: #fff;
}
#task-history-modal .task-history-confirm-inline-actions .task-history-confirm-cancel:hover {
  background: #5c636a;
  color: #fff;
}

/* 差異表格 */
#task-history-modal .table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  background: #fff;
}
#task-history-modal .table.table-sm th,
#task-history-modal .table.table-sm td {
  padding: 8px 12px;
}
#task-history-modal .table.table-bordered,
#task-history-modal .table.table-bordered th,
#task-history-modal .table.table-bordered td {
  border: 1px solid #dee2e6;
}
#task-history-modal .table th {
  background: #f8f9fa;
  font-weight: 600;
  color: #333;
  text-align: left;
  white-space: nowrap;
}
#task-history-modal .table td {
  color: #333;
}
#task-history-modal .table .text-nowrap { white-space: nowrap; }
#task-history-modal .table .text-break { word-break: break-word; max-width: 200px; }
#task-history-modal .table thead th:nth-child(2),
#task-history-modal .table thead th:nth-child(3) { text-align: center; }
#task-history-modal .table thead th:nth-child(4) { text-align: center; min-width: 3em; }
#task-history-modal .table tbody td:nth-child(2),
#task-history-modal .table tbody td:nth-child(3),
#task-history-modal .table tbody td:nth-child(4) { text-align: center; }

/* 還原確認區塊 */
#task-history-modal .task-history-confirm-panel .table { margin-bottom: 0; }
#task-history-modal .task-history-confirm-panel .d-flex {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
#task-history-modal .task-history-confirm-panel .btn-secondary {
  background-color: #6c757d;
  color: #fff;
  border-color: #6c757d;
}
#task-history-modal .task-history-confirm-panel .btn-success {
  background-color: #28a745;
  color: #fff;
  border-color: #28a745;
}
#task-history-modal .task-history-confirm-panel .btn-outline-secondary {
  background-color: transparent;
  color: #6c757d;
  border-color: #6c757d;
}
#task-history-modal .task-history-confirm-panel.border.rounded.p-3.mb-3 {
  border: 1px solid #dee2e6 !important;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}
#task-history-modal .task-history-confirm-panel h6 { margin: 0 0 0.5rem 0; font-size: 1rem; }
#task-history-modal .task-history-confirm-panel .small { font-size: 0.875rem; }
#task-history-modal .task-history-confirm-panel .mb-2 { margin-bottom: 0.5rem; }
#task-history-modal .task-history-confirm-panel .mb-3 { margin-bottom: 1rem; }
#task-history-modal .task-history-confirm-panel .mt-2 { margin-top: 0.5rem; }
