:root {
  color-scheme: light;
  --ink: #172a32;
  --muted: #5c6c72;
  --paper: #f7fbfa;
  --surface: #ffffff;
  --line: #cfddda;
  --teal: #0b756e;
  --teal-dark: #075b56;
  --teal-soft: #e5f2ef;
  --amber: #bd6808;
  --amber-soft: #fff3df;
  --danger: #a92f25;
  --danger-dark: #84231c;
  --danger-soft: #fff0ed;
  --shadow: 0 18px 48px rgba(23, 42, 50, 0.09);
  font-family:
    "Noto Sans TC",
    "PingFang TC",
    "Microsoft JhengHei",
    system-ui,
    sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
}
button, input {
  font: inherit;
}
button, input[type="file"], a {
  -webkit-tap-highlight-color: transparent;
}

.skip-link {
  position: fixed;
  left: 1rem;
  top: -4rem;
  z-index: 30;
  background: var(--ink);
  color: white;
  padding: 0.75rem 1rem;
}
.skip-link:focus {
  top: 1rem;
}
:focus-visible {
  outline: 3px solid #187fce;
  outline-offset: 3px;
}

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  padding: 2.25rem clamp(1.25rem, 4vw, 4.5rem) 1.5rem;
  border-bottom: 1px solid var(--line);
}
.product-mark, .eyebrow, .field-caption {
  margin: 0 0 0.4rem;
  color: var(--teal-dark);
  font: 700 0.74rem/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
h1, h2 {
  margin: 0;
  letter-spacing: -0.035em;
}
h1 {
  font-size: clamp(2rem, 4vw, 3.6rem);
  line-height: 0.96;
  max-width: 11ch;
}
h2 {
  font-size: clamp(1.45rem, 2.2vw, 2.15rem);
  line-height: 1.15;
}
.environment-stamp {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  border: 1px solid var(--ink);
  background: white;
  padding: 0.65rem 0.9rem;
  font-weight: 800;
}
.environment-dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 4px var(--amber-soft);
}
body[data-environment="prod"] .environment-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px var(--danger-soft);
}
.environment-warning {
  padding: 0.75rem clamp(1.25rem, 4vw, 4.5rem);
  color: #5b3509;
  background: var(--amber-soft);
  border-bottom: 1px solid #e8c58e;
  font-weight: 650;
}
body[data-environment="prod"] .environment-warning {
  color: #6f1c16;
  background: var(--danger-soft);
  border-bottom-color: #e9bab5;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(15rem, 20rem) minmax(0, 1fr);
  gap: clamp(1.25rem, 3vw, 3rem);
  max-width: 92rem;
  margin: 0 auto;
  padding: clamp(1.25rem, 3vw, 3rem) clamp(1.25rem, 4vw, 4.5rem) 5rem;
}
.manifest {
  align-self: start;
  position: sticky;
  top: 1.5rem;
  background: var(--ink);
  color: white;
  padding: 1.5rem;
  min-height: 32rem;
  box-shadow: var(--shadow);
}
.manifest-title {
  margin: 0 0 1.4rem;
  font: 700 0.75rem/1.2 ui-monospace, monospace;
  letter-spacing: 0.12em;
  color: #a9c8c4;
}
.manifest-steps {
  margin: 0;
  padding: 0;
  list-style: none;
}
.manifest-steps li {
  display: grid;
  grid-template-columns: 2.2rem 1fr;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.9rem 0;
  color: #a9b9bd;
  border-top: 1px solid #38505a;
}
.manifest-steps li span {
  font: 700 0.72rem/1 ui-monospace, monospace;
  color: #6e8b90;
}
.manifest-steps li.is-active {
  color: white;
}
.manifest-steps li.is-active span {
  color: #59d0c5;
}
.manifest-steps li.is-complete {
  color: #bce1dc;
}
.batch-reference {
  margin-top: 2.5rem;
  padding-top: 1.1rem;
  border-top: 1px solid #38505a;
}
.batch-reference span, .batch-reference strong {
  display: block;
}
.batch-reference span {
  color: #a9b9bd;
  font-size: 0.75rem;
  margin-bottom: 0.35rem;
}
.batch-reference strong {
  overflow-wrap: anywhere;
  font: 600 0.83rem/1.5 ui-monospace, monospace;
}

main {
  min-width: 0;
}
.intake-sheet, .preview-sheet, .result-sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: clamp(1.25rem, 3vw, 2.5rem);
}
.preview-sheet, .result-sheet {
  margin-top: 1.5rem;
}
.section-heading {
  margin-bottom: 1.5rem;
}
.section-heading.with-note {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}
.privacy-note {
  margin: 0;
  padding: 0.45rem 0.7rem;
  color: var(--teal-dark);
  background: var(--teal-soft);
  font-size: 0.8rem;
  font-weight: 700;
}
.instruction {
  border-left: 0.35rem solid var(--teal);
  background: var(--teal-soft);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.25rem;
}
.instruction strong {
  display: block;
  font-size: 1.05rem;
}
.instruction ul {
  margin: 0.7rem 0 0;
  padding-left: 1.2rem;
  color: #3f555b;
}
.instruction li + li {
  margin-top: 0.35rem;
}
.master-ledger {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.5rem;
}
.master-ledger strong, .master-ledger span {
  display: block;
}
.master-ledger > div > span:last-child {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.25rem;
}
.text-action {
  color: var(--teal-dark);
  font-weight: 750;
  text-underline-offset: 0.2em;
}
.text-action.is-disabled {
  color: #8a979b;
  pointer-events: none;
}

form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.file-field {
  min-width: 0;
  border: 1px dashed #9ab4b0;
  background: #fbfdfd;
  padding: 1rem;
}
.file-field-primary {
  border-color: var(--teal);
}
.file-field label {
  display: block;
  font-weight: 800;
}
.file-field label span {
  color: var(--danger);
  font-size: 0.75rem;
  margin-left: 0.35rem;
}
.file-field p {
  min-height: 2.6em;
  margin: 0.4rem 0 0.8rem;
  color: var(--muted);
  font-size: 0.84rem;
}
.file-field input {
  display: block;
  width: 100%;
  color: var(--muted);
}
.file-field input::file-selector-button {
  border: 0;
  background: var(--ink);
  color: white;
  padding: 0.65rem 0.8rem;
  margin-right: 0.7rem;
  cursor: pointer;
  font-weight: 700;
}
.validation-message {
  grid-column: 1 / -1;
  background: var(--danger-soft);
  color: var(--danger-dark);
  padding: 0.8rem 1rem;
}
.upload-progress {
  grid-column: 1 / -1;
}
.progress-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.4rem;
  font-size: 0.82rem;
}
progress {
  width: 100%;
  height: 0.65rem;
  border: 0;
  accent-color: var(--teal);
}
.primary-action, .danger-action {
  border: 0;
  padding: 0.85rem 1.15rem;
  color: white;
  cursor: pointer;
  font-weight: 800;
  min-height: 2.9rem;
}
.primary-action {
  grid-column: 1 / -1;
  justify-self: start;
  background: var(--teal);
}
.primary-action:hover {
  background: var(--teal-dark);
}
.danger-action {
  background: var(--danger);
}
.danger-action:hover {
  background: var(--danger-dark);
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  margin-bottom: 1.25rem;
}
.metric {
  padding: 1rem;
  border-right: 1px solid var(--line);
}
.metric:nth-child(4n) {
  border-right: 0;
}
.metric:nth-child(n+5) {
  border-top: 1px solid var(--line);
}
.metric span, .metric strong {
  display: block;
}
.metric span {
  color: var(--muted);
  font-size: 0.75rem;
}
.metric strong {
  margin-top: 0.25rem;
  font: 750 1.35rem/1 ui-monospace, monospace;
}
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
}
table {
  width: 100%;
  min-width: 58rem;
  border-collapse: collapse;
  font-size: 0.84rem;
}
th, td {
  padding: 0.78rem 0.7rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th {
  background: #edf3f2;
  color: #40545a;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}
td.numeric {
  font-family: ui-monospace, monospace;
  text-align: right;
}
.status-pill {
  display: inline-block;
  padding: 0.18rem 0.42rem;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-weight: 750;
  white-space: nowrap;
}
.status-pill.is-warning {
  background: var(--amber-soft);
  color: #754308;
}
.execute-panel {
  display: grid;
  grid-template-columns: 1fr minmax(13rem, 18rem) auto;
  gap: 1rem;
  align-items: end;
  margin-top: 1.25rem;
  padding: 1.1rem;
  background: #f0f5f4;
  border-left: 0.35rem solid var(--ink);
}
.execute-panel p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}
.confirmation-field {
  display: grid;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 700;
}
.confirmation-field input {
  width: 100%;
  border: 1px solid #8da5a1;
  padding: 0.65rem 0.7rem;
  background: white;
}
.status-message {
  margin-top: 1rem;
  min-height: 1.5rem;
  color: var(--muted);
}
.status-message.is-error {
  color: var(--danger-dark);
  font-weight: 700;
}
.result-sheet {
  border-top: 0.35rem solid var(--teal);
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 12.5rem minmax(0, 1fr);
  }
  form {
    grid-template-columns: 1fr;
  }
  .file-field p {
    min-height: 0;
  }
  .primary-action, .validation-message, .upload-progress {
    grid-column: 1;
  }
  .execute-panel {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .danger-action {
    justify-self: start;
  }
}

@media (max-width: 760px) {
  .masthead {
    align-items: flex-start;
    padding-top: 1.35rem;
  }
  h1 {
    font-size: 2rem;
  }
  .environment-stamp {
    font-size: 0.8rem;
  }
  .workspace {
    display: block;
    padding-left: 1rem;
    padding-right: 1rem;
  }
  .manifest {
    position: static;
    min-height: 0;
    padding: 1rem;
    margin-bottom: 1rem;
  }
  .manifest-title {
    margin-bottom: 0.7rem;
  }
  .manifest-steps {
    display: grid;
    grid-template-columns: repeat(5, minmax(4.5rem, 1fr));
    overflow-x: auto;
  }
  .manifest-steps li {
    display: block;
    min-width: 4.5rem;
    padding: 0.65rem 0.4rem;
    font-size: 0.7rem;
    border-top: 1px solid #38505a;
  }
  .manifest-steps li span {
    display: block;
    margin-bottom: 0.35rem;
  }
  .batch-reference {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
  }
  .master-ledger, .section-heading.with-note {
    align-items: flex-start;
    flex-direction: column;
  }
  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }
  .metric:nth-child(2n) {
    border-right: 0;
  }
  .metric:nth-child(n+3) {
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 420px) {
  .masthead {
    display: block;
  }
  .environment-stamp {
    margin-top: 1rem;
  }
  .intake-sheet, .preview-sheet, .result-sheet {
    padding: 1rem;
  }
  .metrics {
    grid-template-columns: 1fr;
  }
  .metric {
    border-right: 0;
    border-top: 1px solid var(--line);
  }
  .metric:first-child {
    border-top: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
