:root {
  --bg: #f7f8fc;
  --card: #ffffff;
  --muted: #6b7280;
  --text: #111827;
  --accent: #6ea8fe; /* 柔和藍 */
  --accent2: #67e8f9; /* 清新藍綠 */
  --border: #e5e7eb;
  --thead: #f3f6ff;
  --zebra: #fafbff;
  --pill: #eef2ff;
  --sticky: #ffffff;

  /* 多欄 KV 表寬度（可自行微調） */
  --kv-label-w: 120px;
  --kv-value-w: 220px;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 20% -10%, #e9f0ff, #f7f8fc);
  color: var(--text);
  font-family:
    ui-sans-serif,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    "Noto Sans TC",
    "Helvetica Neue",
    Arial,
    sans-serif;
}
header {
  padding: 22px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #ffffffcc, #ffffffa0);
  backdrop-filter: saturate(140%) blur(6px);
}
.container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 16px;
}
h2 {
  margin: 0 0 4px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.muted {
  color: var(--muted);
}

.header-text {
  float: right;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mobile-only {
  display: none;
}

@media (max-width: 767.98px) {
  .header-text {
    display: none;
  }
  
  .mobile-only {
    display: inline-block;
    position: absolute;
    right: 22px;
    top: 22px;
  }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin: 14px 0;
  box-shadow: 0 6px 18px rgba(44, 63, 88, 0.06);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
label {
  font-size: 13px;
  color: var(--muted);
  margin-right: 6px;
}

select,
input[type="text"] {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  outline: none;
  transition:
    box-shadow 0.15s,
    border-color 0.15s;
}
select:focus,
input[type="text"]:focus {
  border-color: #bfd3ff;
  box-shadow: 0 0 0 4px rgba(110, 168, 254, 0.25);
}

button {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #ffffff, #f1f5ff);
  color: var(--text);
  cursor: pointer;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
}
button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}
.btn-accent {
  border-color: #b9d1ff;
  background: linear-gradient(180deg, #e7f0ff, #dce9ff);
}

#dropzone {
  border: 2px dashed #c9d8ff;
  border-radius: 16px;
  padding: 22px;
  text-align: center;
  color: var(--muted);
  background: #fff;
}
#dropzone.drag {
  background: linear-gradient(180deg, #f4f8ff, #ffffff);
  border-color: var(--accent);
  color: var(--text);
}

progress {
  width: 240px;
  height: 12px;
  vertical-align: middle;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 8px;
}

.checkbox-group {
  display: flex;
  gap: 12px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  margin-right: 0;
}

.checkbox-label input[type="checkbox"] {
  margin: 0;
  padding: 0;
  width: auto;
  height: auto;
}

/* 隱藏篩選器 */
.filter-group.hidden {
  display: none;
}

/* 工具列 */
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 16px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

/* 欄位管理面板 */
.column-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(500px, calc(100vw - 32px));
  max-height: 80vh;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
  z-index: 70;
  overflow: hidden;
}

.column-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #ffffff, #f7faff);
}

.column-panel-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.column-panel-body {
  padding: 16px;
  max-height: calc(80vh - 80px);
  overflow-y: auto;
}

.column-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 4px;
  background: #fff;
  cursor: move;
}

.column-item:hover {
  background: var(--zebra);
}

.column-item.locked {
  cursor: default;
  opacity: 0.7;
}

.column-checkbox {
  margin: 0;
}

.column-label {
  flex: 1;
  font-size: 14px;
}

.column-badge {
  background: var(--pill);
  color: #3446a1;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}

.drag-handle {
  color: var(--muted);
  cursor: move;
  font-size: 12px;
}

.btn-secondary {
  background: linear-gradient(180deg, #f8f9fa, #e9ecef);
  border-color: #ced4da;
  color: #495057;
}

/* CSV 強調文字 - 僅 "CSV壓縮檔" 五個字 */
.csv-highlight {
  background: linear-gradient(90deg, #ff8c42, #ffa726);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 2px 4px rgba(255, 140, 66, 0.3);
}

.info-btn {
  background: linear-gradient(135deg, #ffa726, #ff8c42);
  border-color: #ff8c42;
  color: white;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(255, 140, 66, 0.3);
}

.info-btn:hover {
  background: linear-gradient(135deg, #ff8c42, #f57c00);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(255, 140, 66, 0.4);
}

/* 期間顯示 */
.period-display {
  background: linear-gradient(135deg, #e3f2fd, #f3e5f5);
  border: 1px solid #90caf9;
  border-radius: 12px;
  padding: 12px 16px;
  margin: 12px 0;
  box-shadow: 0 4px 12px rgba(144, 202, 249, 0.2);
}

.period-content {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

.period-icon {
  font-size: 16px;
}

.period-text {
  font-weight: 600;
  color: #1565c0;
  font-size: 14px;
  letter-spacing: 0.5px;
}

/* ZIP規格說明彈窗 */
.zip-info-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 20px;
}

.zip-info-content {
  background: white;
  border-radius: 16px;
  width: min(700px, 100%);
  max-height: 80vh;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: fadeInScale 0.2s ease-out;
}

.zip-info-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, #fff3e0, #ffffff);
}

.zip-info-header h3 {
  margin: 0;
  color: #e65100;
  font-size: 18px;
  font-weight: 700;
}

.zip-info-body {
  padding: 20px;
  max-height: calc(80vh - 80px);
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.6;
}

.info-section {
  margin-bottom: 20px;
}

.info-section:last-child {
  margin-bottom: 0;
}

.info-section h4 {
  color: #1565c0;
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 8px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.info-section ul {
  margin: 8px 0;
  padding-left: 20px;
}

.info-section li {
  margin-bottom: 6px;
}

.info-section code {
  background: #f5f5f5;
  color: #d63384;
  padding: 2px 4px;
  border-radius: 3px;
  font-family: 'Monaco', 'Consolas', monospace;
  font-size: 13px;
}

.info-section strong {
  color: #1976d2;
  font-weight: 600;
}

.mobile-intro {
  display: none;
  background: linear-gradient(135deg, #fff3e0, #ffecb3);
  padding: 16px;
  border-radius: 8px;
  border: 1px solid #ffcc02;
  margin-bottom: 20px;
}

.mobile-intro p {
  margin: 0;
  color: #e65100;
  font-size: 15px;
  line-height: 1.5;
  text-align: center;
}

.mobile-intro .csv-highlight {
  font-size: 14px;
}

@media (max-width: 767.98px) {
  .mobile-intro {
    display: block;
  }
}

@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* 資訊卡（隱藏原版，整合到彈窗中） */
.info-card {
  display: none;
}

/* 彈窗內的資訊卡 */
.modal-info-card {
  background: linear-gradient(135deg, #f8f9fa, #ffffff);
  border: 1px solid #e3f2fd;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.info-item {
  background: white;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #f0f0f0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.info-label {
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.info-value {
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

.price-highlight {
  color: #d63384;
  font-weight: 700;
  font-size: 16px;
}

@media (max-width: 767.98px) {
  .info-grid {
    grid-template-columns: 1fr;
  }
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 14px;
  table-layout: fixed;
}
th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
thead th {
  position: sticky;
  top: 0;
  background: var(--thead);
  z-index: 5;
}
tbody tr:nth-child(even) {
  background: var(--zebra);
}

.pagination {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 10px;
}

.detail {
  background: #f9fbff;
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 12px;
  margin-top: 8px;
}
.pill {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--pill);
  border: 1px solid #dbe4ff;
  color: #3446a1;
}
.nowrap {
  white-space: nowrap;
}
.hidden {
  display: none;
}

.tableWrap {
  overflow: auto;
  max-width: 100%;
}
th .thwrap {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.2;
}
td .cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
thead th {
  z-index: 4;
}
th.sticky-left,
td.sticky-left {
  position: sticky;
  left: 0;
  background: var(--sticky);
  z-index: 5;
}
th.sticky-right,
td.sticky-right {
  position: sticky;
  right: 0;
  background: var(--sticky);
  z-index: 5;
}

#toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: #ffffff;
  border: 1px solid var(--border);
  color: #1f2a44;
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  max-width: 60ch;
  opacity: 0.98;
  display: none;
}

/* ===== Modal (查看→彈窗) ===== */
#modalBackdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: none;
  z-index: 50;
}
#modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 60;
  align-items: flex-start;
  justify-content: center;
  padding: 32px 16px;
  overflow: auto;
}
.modal-box {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: min(1100px, calc(100% - 16px));
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
  animation: pop 0.15s ease-out;
  margin-top: 4vh;
  overflow: hidden;
}
.modal-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #ffffff, #f7faff);
  position: sticky;
  top: 0;
}
.modal-tt {
  font-weight: 700;
}
.modal-bd {
  padding: 12px 16px;
}
.icon-btn {
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 10px;
  padding: 6px 9px;
}
.icon-btn:hover {
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
}

@keyframes pop {
  from {
    transform: translateY(10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ===== 多欄 KV 表（長字會換行、不溢出） ===== */
.kv-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-bottom: 10px;
  border-radius: 0;
}
.kv-table th.kv-label {
  width: var(--kv-label-w);
  text-align: right;
  padding: 6px 8px;
  background: #f3f6ff;
  border: 1px solid var(--border);
  font-weight: 600;
  vertical-align: top;
  white-space: normal;
  word-break: break-all;
  overflow-wrap: anywhere;
}
.kv-table td.kv-value {
  width: var(--kv-value-w);
  padding: 6px 8px;
  border: 1px solid var(--border);
  white-space: normal;
  word-break: break-all;
  overflow-wrap: anywhere;
}

@media (max-width: 767.98px) {
  :root {
    --kv-label-w: 110px;
    --kv-value-w: 1fr;
  }
}