* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Microsoft JhengHei", Arial, sans-serif;
  color: #202124;
  background: #f4f7f6;
}

.app {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.upload-area {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 230px;
  padding: 28px;
  text-align: center;
  background: #ffffff;
  border: 2px dashed #6aa58e;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.upload-area:hover,
.upload-area.dragging {
  background: #eef8f3;
  border-color: #247a5a;
  transform: translateY(-2px);
}

.file-input {
  display: none;
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  color: #ffffff;
  font-size: 20px;
  font-weight: 700;
  background: #247a5a;
  border-radius: 8px;
}

.excel-icon {
  background: #247a5a;
}

.word-icon {
  background: #2f63b8;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 5vw, 44px);
}

.upload-area p,
.viewer-head p,
.message {
  color: #66716d;
  line-height: 1.6;
}

.viewer {
  margin-top: 24px;
  padding: 22px;
  background: #ffffff;
  border: 1px solid #d9e2de;
  border-radius: 8px;
}

.viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.viewer-head h2 {
  margin-bottom: 4px;
  font-size: 22px;
}

.sheet-select {
  min-width: 180px;
  padding: 10px 12px;
  font-size: 16px;
  color: #202124;
  background: #ffffff;
  border: 1px solid #b9c8c2;
  border-radius: 6px;
}

.message {
  padding: 18px;
  background: #f7faf9;
  border: 1px solid #dfe8e4;
  border-radius: 6px;
}

.table-wrap {
  max-height: 560px;
  overflow: auto;
}

.word-content {
  display: none;
  min-height: 160px;
  max-height: 560px;
  overflow: auto;
  padding: 18px;
  line-height: 1.8;
  white-space: pre-wrap;
  background: #fbfdfc;
  border: 1px solid #dfe8e4;
  border-radius: 6px;
}

.word-content.show {
  display: block;
}

.field-box {
  display: none;
  margin-bottom: 14px;
  padding: 16px;
  background: #f7faf9;
  border: 1px solid #dfe8e4;
  border-radius: 6px;
}

.field-box.show {
  display: block;
}

.field-box h3 {
  margin-bottom: 12px;
  font-size: 18px;
}

.field-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.field-tag {
  padding: 7px 10px;
  color: #204438;
  background: #e8f2ee;
  border: 1px solid #c5d9d1;
  border-radius: 6px;
  font-size: 15px;
}

.contract-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.generate-button {
  min-height: 42px;
  padding: 0 16px;
  color: #ffffff;
  font-size: 16px;
  font-weight: 700;
  background: #247a5a;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.generate-button:disabled {
  color: #8a9691;
  background: #dce5e1;
  cursor: not-allowed;
}

.contract-actions p {
  color: #66716d;
  line-height: 1.5;
}

.contract-list-box {
  display: none;
  margin-bottom: 14px;
  border: 1px solid #dfe8e4;
  border-radius: 6px;
  overflow: hidden;
}

.contract-list-box.show {
  display: block;
}

.contract-list-box h3 {
  padding: 14px 16px;
  font-size: 18px;
  background: #f7faf9;
  border-bottom: 1px solid #dfe8e4;
}

.contract-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #ffffff;
  border-bottom: 1px solid #dfe8e4;
}

.contract-row:last-child {
  border-bottom: 0;
}

.tenant-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.download-button {
  min-height: 36px;
  padding: 0 12px;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  background: #2f63b8;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

th,
td {
  min-width: 120px;
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  border: 1px solid #dfe8e4;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #e8f2ee;
  font-weight: 700;
}

tr:nth-child(even) td {
  background: #fbfdfc;
}

@media (max-width: 680px) {
  .app {
    width: min(100% - 20px, 1100px);
    padding: 16px 0;
  }

  .upload-grid {
    grid-template-columns: 1fr;
  }

  .viewer {
    padding: 14px;
  }

  .viewer-head {
    align-items: stretch;
    flex-direction: column;
  }

  .sheet-select {
    width: 100%;
  }

  .contract-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .contract-row {
    grid-template-columns: 1fr;
  }
}
