/* 資料匯入工作台 — 全頁 modal */

.di-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2147483640;
  background: rgba(38, 24, 16, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4vh 4vw;
  animation: diFadeIn 200ms ease-out;
  font-family: "Noto Sans TC", -apple-system, sans-serif;
}
@keyframes diFadeIn { from { opacity: 0; } to { opacity: 1; } }

.di-modal {
  background: #FAF6EE;
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.35);
  width: min(1100px, 100%);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: diSlideUp 240ms ease-out;
  color: #261810;
}
@keyframes diSlideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.di-head {
  padding: 22px 30px;
  border-bottom: 1px solid #E4D8C2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
}
.di-title { font-family: "Noto Serif TC", serif; font-size: 26px; font-weight: 800; }
.di-sub { font-size: 14px; color: #6E5A48; margin-top: 4px; }
.di-close {
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: #F5E8D0; color: #261810; font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.di-close:hover { background: #EAD9B5; }

.di-steps {
  display: flex;
  padding: 14px 30px;
  background: #fff;
  gap: 8px;
  border-bottom: 1px solid #E4D8C2;
  font-size: 14px;
}
.di-step {
  flex: 1;
  padding: 8px 14px;
  border-radius: 8px;
  background: #F5E8D0;
  color: #A89580;
  font-weight: 600;
  text-align: center;
  position: relative;
}
.di-step.active { background: #D97A3B; color: #fff; }
.di-step.done { background: #C9A961; color: #261810; }

.di-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 30px;
}

/* === Upload === */
.di-upload { display: flex; flex-direction: column; gap: 20px; }
.di-dropzone {
  border: 2px dashed #D4B57C;
  border-radius: 14px;
  padding: 56px 24px;
  text-align: center;
  cursor: pointer;
  background: #fff;
  transition: all 180ms;
}
.di-dropzone:hover { background: #FFF8E8; border-color: #D97A3B; }
.di-dropzone.dragging { background: #FBE9D6; border-color: #D97A3B; border-style: solid; }
.di-dropzone-icon { font-size: 56px; margin-bottom: 8px; }
.di-dropzone-title { font-size: 22px; font-weight: 700; }
.di-dropzone-sub { font-size: 14px; color: #6E5A48; margin-top: 4px; }

.di-tips {
  background: #FFF8E8;
  border-left: 4px solid #C9A961;
  padding: 14px 18px;
  border-radius: 8px;
  font-size: 14px;
}
.di-tips-title { font-weight: 700; margin-bottom: 6px; }
.di-tips ul { margin: 0; padding-left: 20px; line-height: 1.7; color: #6E5A48; }

.di-history {
  background: #fff;
  border: 1px solid #E4D8C2;
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 13px;
}
.di-history-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 700; }
.di-history-head button {
  background: none; border: none; color: #C44A36; font-size: 12px; cursor: pointer;
}
.di-history ul { list-style: none; padding: 0; margin: 0; }
.di-history li { display: grid; grid-template-columns: 1.3fr 1.5fr auto; gap: 10px; padding: 6px 0; border-bottom: 1px dashed #E4D8C2; }
.di-history li:last-child { border-bottom: none; }
.di-h-target { font-weight: 600; }
.di-h-file { color: #6E5A48; font-size: 12px; }
.di-h-time { color: #A89580; font-size: 12px; }

/* === Stored keys (DB status) === */
.di-stored {
  background: #F3F8EC;
  border: 1px solid #6B8E4E40;
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 13px;
}
.di-stored-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-weight: 700;
  color: #3F5D2A;
}
.di-stored-head button {
  background: none;
  border: 1px solid #C44A36;
  color: #C44A36;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
}
.di-stored ul { list-style: none; padding: 0; margin: 0; }
.di-stored li {
  display: grid;
  grid-template-columns: 1.3fr 1.5fr auto;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px dashed #C5D8AA;
  align-items: center;
}
.di-stored li:last-child { border-bottom: none; }
.di-s-target { font-weight: 600; color: #3F5D2A; }
.di-s-file { color: #6E5A48; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.di-s-stats { color: #4D6B33; font-size: 12px; font-variant-numeric: tabular-nums; display: flex; gap: 6px; align-items: center; }
.di-s-tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 4px;
  background: #C9A961;
  color: #261810;
  font-size: 11px;
  font-weight: 600;
}
.di-s-tag.warn { background: #D89A2C; color: #fff; }

/* === Preview === */
.di-preview { display: flex; flex-direction: column; gap: 14px; }
.di-file-info {
  padding: 12px 16px;
  background: #fff;
  border-radius: 8px;
  font-size: 14px;
  border: 1px solid #E4D8C2;
}
.di-file-info > div + div { margin-top: 4px; color: #6E5A48; font-size: 13px; }

.di-sheets { display: flex; gap: 8px; flex-wrap: wrap; }
.di-sheet {
  padding: 6px 14px;
  background: #fff;
  border: 1px solid #E4D8C2;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.di-sheet.active { background: #D97A3B; color: #fff; border-color: #D97A3B; }
.di-sheet-rows {
  background: rgba(0,0,0,0.1);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
  font-size: 11px;
}
.di-sheet.active .di-sheet-rows { background: rgba(255,255,255,0.25); }

.di-table-wrap {
  background: #fff;
  border: 1px solid #E4D8C2;
  border-radius: 10px;
  overflow: auto;
  max-height: 360px;
  font-size: 13px;
}
.di-table { width: 100%; border-collapse: collapse; }
.di-table th, .di-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid #F0E5D0; white-space: nowrap; }
.di-table th { background: #F5E8D0; font-weight: 700; position: sticky; top: 0; }
.di-table td.di-rownum, .di-table th.di-rownum { background: #F5E8D0; color: #A89580; width: 40px; text-align: right; }
.di-more { padding: 10px; text-align: center; font-size: 12px; color: #A89580; }

/* === AI === */
.di-loading {
  text-align: center;
  padding: 80px 20px;
}
.di-spinner {
  width: 48px; height: 48px;
  border: 4px solid #F5E8D0;
  border-top-color: #D97A3B;
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: diSpin 0.8s linear infinite;
}
@keyframes diSpin { to { transform: rotate(360deg); } }
.di-loading > div:nth-child(2) { font-size: 18px; font-weight: 700; }
.di-loading-sub { font-size: 14px; color: #6E5A48; margin-top: 4px; }

.di-error { text-align: center; padding: 40px 20px; }
.di-error-title { font-size: 20px; font-weight: 700; color: #C44A36; margin-bottom: 8px; }
.di-error-msg { font-size: 14px; color: #6E5A48; margin-bottom: 20px; }

.di-result { display: flex; flex-direction: column; gap: 16px; }
.di-result-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  background: linear-gradient(135deg, #261810 0%, #3A2818 100%);
  color: #F5E8D0;
  padding: 22px 26px;
  border-radius: 12px;
}
.di-result-label { font-size: 13px; opacity: 0.75; }
.di-result-target { font-family: "Noto Serif TC", serif; font-size: 32px; font-weight: 800; color: #C9A961; line-height: 1.2; margin: 4px 0; }
.di-result-reason { font-size: 14px; opacity: 0.85; }
.di-conf { text-align: center; align-self: center; }
.di-conf-num { font-family: "Noto Serif TC", serif; font-size: 48px; font-weight: 800; color: #C9A961; line-height: 1; }
.di-conf-num span { font-size: 22px; opacity: 0.7; }
.di-conf-label { font-size: 12px; opacity: 0.65; }

.di-summary {
  background: #fff;
  border: 1px solid #E4D8C2;
  border-radius: 10px;
  padding: 16px 20px;
}
.di-summary-label { font-size: 12px; font-weight: 700; color: #6E5A48; letter-spacing: 0.06em; }
.di-summary-text { font-size: 16px; margin-top: 6px; line-height: 1.6; }

.di-mapping { }
.di-mapping-label { font-size: 12px; font-weight: 700; color: #6E5A48; letter-spacing: 0.06em; margin-bottom: 6px; }
.di-mapping .di-table { border: 1px solid #E4D8C2; border-radius: 10px; overflow: hidden; }
.di-mapped { color: #6B8E4E; font-weight: 700; }
.di-skip { color: #A89580; font-style: italic; }
.di-sample { color: #6E5A48; font-size: 12px; }

.di-warnings {
  background: #F7E9C8;
  border-left: 4px solid #D89A2C;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
}
.di-warnings-label { font-weight: 700; margin-bottom: 4px; color: #8C6610; }
.di-warnings ul { margin: 0; padding-left: 18px; color: #8C6610; }

/* === Applied === */
.di-applied {
  text-align: center;
  padding: 50px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.di-applied-icon { font-size: 64px; }
.di-applied-title { font-family: "Noto Serif TC", serif; font-size: 28px; font-weight: 800; }
.di-applied-sub { font-size: 16px; color: #6E5A48; line-height: 1.7; }
.di-applied-note {
  background: #FFF8E8;
  border-left: 3px solid #C9A961;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  color: #6E5A48;
  text-align: left;
  max-width: 480px;
  margin: 12px 0 8px;
}

/* === Actions === */
.di-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}
.di-btn {
  padding: 10px 22px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: all 150ms;
}
.di-btn-ghost { background: #F5E8D0; color: #261810; }
.di-btn-ghost:hover { background: #EAD9B5; }
.di-btn-primary { background: #D97A3B; color: #fff; }
.di-btn-primary:hover { background: #B85F26; }
