/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-overlay:not(.hidden) { opacity: 1; visibility: visible; }

.modal-content {
  background-color: var(--white);
  width: 100%; 
  max-width: 600px;
  max-height: 90vh;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
  transform: translateY(20px);
  transition: transform 0.2s ease;
  display: flex;
  flex-direction: column;
}

.modal-overlay:not(.hidden) .modal-content { transform: translateY(0); }

.modal-header {
  background-color: var(--primary-color);
  color: var(--white);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.modal-header h2 { 
  font-size: 1.125rem; 
  font-weight: 600; 
  letter-spacing: -0.02em;
}

.modal-header .btn-icon {
  color: #FFFFFF !important;
  cursor: pointer;
  background: none !important;
  border: none !important;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--primary-color);
  transition: opacity 0.2s;
}

.btn-icon:hover {
  opacity: 0.7;
}

.modal-body { 
  padding: 1.5rem; 
  overflow-y: auto;
  flex: 1;
}

.grid-form { 
  display: grid; 
  grid-template-columns: 1fr 1fr; 
  gap: 1.25rem; 
}

.form-group { 
  display: flex; 
  flex-direction: column; 
  gap: 0.375rem; 
}

.form-group.full-width { 
  grid-column: span 2; 
}

/* Section Title for Grouping */
.form-section-title {
  grid-column: span 2;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--primary-color);
  padding: 1.5rem 0 0.5rem 0; /* 패딩 조정 */
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
}

/* Modal Readonly/Edit Mode Interaction */
.grid-form.is-view-mode input,
.grid-form.is-view-mode select,
.grid-form.is-view-mode textarea {
  border: none !important;
  background-color: transparent !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
  pointer-events: none !important;
  color: var(--text-main) !important;
  font-weight: 500 !important;
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  box-shadow: none !important;
}

.grid-form.is-view-mode input[type="file"] {
  display: none !important;
}

.grid-form.is-view-mode .btn-helper {
  display: none !important;
}

.grid-form.is-view-mode button {
  pointer-events: none !important;
  background: none !important;
  border: none !important;
  opacity: 0.8;
}

.grid-form.is-view-mode select::-ms-expand {
  display: none !important;
}

.grid-form.is-edit-mode input,
.grid-form.is-edit-mode select,
.grid-form.is-edit-mode textarea {
  color: #FF3D00; /* 수정 시 글자색 변경 */
  border: 1px solid var(--border-color);
}

/* 수동 수정 불가 필드 (자산번호 등) 전용 스타일 */
.grid-form input[readonly] {
  border-color: transparent !important;
  background-color: transparent !important;
  pointer-events: none !important;
  color: var(--text-main) !important;
  font-weight: 500 !important;
  cursor: default;
}

.grid-form.is-edit-mode input:focus,
.grid-form.is-edit-mode select:focus,
.grid-form.is-edit-mode textarea:focus {
  border-color: #FF3D00;
  box-shadow: 0 0 0 2px rgba(255, 61, 0, 0.1);
}

.form-section-title:first-child {
  padding-top: 0.5rem;
}

.form-group label { 
  font-size: 0.8125rem; 
  font-weight: 600; 
  color: var(--text-muted);
}

.form-group input, 
.form-group select, 
.form-group textarea {
  padding: 0.625rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-family: inherit; 
  font-size: 0.875rem;
  outline: none; 
  transition: all 0.2s;
  background-color: var(--white);
}

.form-group textarea {
  resize: none;
}

.form-group input:focus, 
.form-group select:focus, 
.form-group textarea:focus { 
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(30, 81, 73, 0.1);
}

.modal-footer {
  padding: 1rem 1.5rem; 
  border-top: 1px solid var(--border-color);
  display: flex; 
  justify-content: space-between; 
  align-items: center;
  background-color: #FAFAFA;
  flex-shrink: 0;
}

.footer-actions { 
  display: flex; 
  gap: 0.5rem; 
}

/* Wide Modal for History/Detail */
.modal-content.wide {
  max-width: 950px;
}

/* Upload Preview Specific */
.upload-sidebar {
  width: 240px;
  border-right: 1px solid var(--border-color);
  background-color: var(--bg-light);
  padding: 1.5rem 1rem;
  overflow-y: auto;
  flex-shrink: 0;
}

.upload-tab-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.upload-tab-btn {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.2s;
  border: 1px solid transparent;
  color: var(--text-main);
}

.upload-tab-btn:hover {
  background-color: var(--white);
  border-color: var(--border-color);
}

.upload-tab-btn.active {
  background-color: var(--white);
  color: var(--primary-color);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  border-color: var(--border-color);
  font-weight: 700;
}

.preview-table-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--white);
  overflow: hidden;
}

.preview-stats-bar {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--white);
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  min-width: max-content;
}

.preview-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: var(--bg-light);
  box-shadow: 0 1px 0 var(--border-color);
}

.preview-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-muted);
}

.preview-table td {
  padding: 0.75rem 1rem;
  font-size: 13px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text-main);
}

.preview-table tr:hover {
  background-color: var(--bg-light);
}

.modal-body-split {
  display: flex;
  gap: 2rem;
  min-height: 480px;
}

.modal-form-area {
  flex: 1.2;
}

.modal-history-area {
  flex: 0.8;
  border-left: 1px solid var(--border-color);
  padding-left: 1.5rem;
  display: flex;
  flex-direction: column;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.history-header h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-main);
}

/* 읽기 전용 필드 (자산번호 등) 통일 스타일 */
.is-readonly-field {
  border-color: transparent !important;
  background-color: transparent !important;
  pointer-events: none !important;
  color: var(--text-main) !important;
  font-weight: 600 !important;
  cursor: default;
  padding-left: 0 !important;
}

/* 입력 필드 + 버튼 그룹 (자산번호 생성 등) */
.input-with-btn {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  width: 100%;
}

.input-with-btn input {
  flex: 1;
  min-width: 0; /* flex 컨테이너 안에서 너비 압축 방지 */
}

.input-with-btn .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.history-timeline {
  flex: 1;
  overflow-y: auto;
  max-height: 500px;
  padding-right: 0.5rem;
}

.history-item {
  position: relative;
  padding-left: 1.25rem;
  padding-bottom: 1.5rem;
  border-left: 2px solid var(--border-color);
}

.history-item::before {
  content: '';
  position: absolute;
  left: -7px;
  top: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: var(--white);
  border: 2px solid var(--primary-color);
}

.history-item:last-child {
  border-left: 2px solid transparent;
}

.history-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.history-user {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 0.25rem;
}

.history-details {
  font-size: 0.8125rem;
  color: var(--text-main);
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-all;
}

.empty-history {
  padding: 2rem 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

/* Dashboard Detail Modal Table Fixed Header */
#dashboard-detail-modal .modal-body {
  overflow-y: auto;
  max-height: calc(80vh - 120px);
  padding: 0;
}

/* 모달 내부의 table-container 기존 전역 스타일 무력화 */
#dashboard-detail-modal .table-container {
  border: none;
  border-radius: 0;
  box-shadow: none;
  max-height: none;
  overflow: visible;
}

#dashboard-detail-modal table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

#dashboard-detail-modal thead th {
  position: sticky;
  top: 0;
  background-color: var(--bg-light);
  z-index: 10;
  border-bottom: 2px solid var(--border-color);
  box-shadow: none;
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-main);
  text-align: left;
  white-space: nowrap;
}

#dashboard-detail-modal tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.8125rem;
  color: var(--text-main);
  white-space: nowrap;
}

#dashboard-detail-modal tbody tr:last-child td {
  border-bottom: none;
}

#dashboard-detail-modal tbody tr:hover {
  background-color: var(--bg-light);
}

/* 뱃지 스타일 (대시보드 상세 목록용) */
#dashboard-detail-modal .badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.5;
}

#dashboard-detail-modal .badge-outline {
  border: 1px solid var(--primary-color);
  color: var(--primary-color);
  background: var(--primary-light);
}

#dashboard-detail-modal .badge-sw {
  border: 1px solid #3b82f6;
  color: #3b82f6;
  background: #eff6ff;
}
