:root {
  --navy-950: #0a1f35;
  --navy-900: #102d4d;
  --navy-800: #173e67;
  --blue-600: #1f6aa5;
  --teal-600: #0d8178;
  --teal-100: #e2f4f1;
  --ink: #172534;
  --muted: #667588;
  --line: #d9e1e8;
  --soft: #f4f7f9;
  --paper: #ffffff;
  --danger: #a83d3d;
  --shadow: 0 18px 48px rgba(16, 45, 77, 0.1);
  font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
  background: #eef3f6;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: #eef3f6;
}

button,
input,
select {
  font: inherit;
}

button,
.upload-button {
  -webkit-tap-highlight-color: transparent;
}

.site-header {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(10, 31, 53, 0.97);
  color: white;
  backdrop-filter: blur(12px);
}

.header-inner {
  display: flex;
  width: min(1180px, calc(100% - 40px));
  min-height: 72px;
  margin: 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 0.98rem;
  letter-spacing: 0.04em;
}

.brand small {
  margin-top: 2px;
  color: #adbed0;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
}

.privacy-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.17);
  border-radius: 999px;
  padding: 8px 12px;
  color: #dbe8f3;
  font-size: 0.78rem;
}

.privacy-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #55d9ba;
  box-shadow: 0 0 0 4px rgba(85, 217, 186, 0.12);
}

.page-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 64px 0 56px;
}

.intro {
  max-width: 760px;
  margin-bottom: 34px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--teal-600);
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.intro h1 {
  margin: 0;
  color: var(--navy-950);
  font-size: clamp(2rem, 4vw, 3.5rem);
  line-height: 1.13;
  letter-spacing: -0.04em;
}

.intro > p:last-child {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.8;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  align-items: start;
  gap: 24px;
}

.form-card,
.export-card {
  border: 1px solid rgba(21, 54, 84, 0.08);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.form-card {
  border-radius: 18px;
  overflow: hidden;
}

.form-section {
  padding: 34px 38px 38px;
  border-bottom: 1px solid var(--line);
}

.form-section:last-child {
  border-bottom: 0;
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
}

.section-number {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 12px;
  background: var(--navy-900);
  color: white;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.section-heading h2,
.export-card h2 {
  margin: 0;
  color: var(--navy-950);
  font-size: 1.17rem;
  line-height: 1.25;
}

.section-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.subheading {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 26px 0 14px;
  color: var(--navy-800);
  font-size: 0.82rem;
  font-weight: 800;
}

.subheading:first-of-type {
  margin-top: 0;
}

.subheading::after {
  height: 1px;
  flex: 1;
  background: var(--line);
  content: "";
}

.field-grid {
  display: grid;
  gap: 16px;
}

.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.span-2 {
  grid-column: span 2;
}

.span-3 {
  grid-column: span 3;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field > span {
  color: #3e4d5e;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.45;
}

.field em {
  margin-left: 4px;
  color: var(--danger);
  font-size: 0.68rem;
  font-style: normal;
}

.field input,
.field select {
  width: 100%;
  min-height: 45px;
  border: 1px solid #cfd9e2;
  border-radius: 9px;
  outline: 0;
  background: #fbfcfd;
  color: var(--ink);
  padding: 10px 12px;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.field input::placeholder {
  color: #98a4b1;
}

.field input:hover,
.field select:hover {
  border-color: #a9bac9;
}

.field input:focus,
.field select:focus {
  border-color: var(--blue-600);
  background: white;
  box-shadow: 0 0 0 3px rgba(31, 106, 165, 0.12);
}

.field input:user-invalid,
.field select:user-invalid {
  border-color: #c85d5d;
}

.beneficiary-list {
  display: grid;
  gap: 14px;
}

.beneficiary-card {
  min-width: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--soft);
  padding: 18px;
}

.beneficiary-card legend {
  border: 1px solid #bed1df;
  border-radius: 999px;
  background: white;
  color: var(--navy-800);
  padding: 5px 11px;
  font-size: 0.74rem;
  font-weight: 800;
}

.beneficiary-grid {
  grid-template-columns: 1.3fr 0.8fr 1fr 1.2fr 1.35fr;
}

.beneficiary-grid .field > span {
  min-height: 34px;
}

.signature-panel {
  border: 1px solid #cbd8e2;
  border-radius: 13px;
  overflow: hidden;
}

.signature-toolbar {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--soft);
  padding: 9px 14px;
}

.signature-toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.text-button,
.reset-button {
  border: 0;
  background: transparent;
  color: var(--blue-600);
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 800;
  text-decoration: none;
}

.text-button {
  border-radius: 7px;
  padding: 7px 8px;
}

.text-button:hover,
.text-button:focus-visible {
  background: #e7eff5;
}

.upload-button {
  display: inline-flex;
  align-items: center;
}

.signature-canvas-wrap {
  position: relative;
  background: white;
  padding: 12px 18px 24px;
}

#signatureCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 5 / 1;
  border-bottom: 1px solid #738292;
  cursor: crosshair;
  touch-action: none;
}

.signature-canvas-wrap > span {
  position: absolute;
  right: 18px;
  bottom: 6px;
  color: #95a1ad;
  font-size: 0.66rem;
  letter-spacing: 0.05em;
}

.consent-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 16px;
  color: #425364;
  font-size: 0.83rem;
  line-height: 1.55;
}

.consent-row input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  margin: 1px 0 0;
  accent-color: var(--teal-600);
}

.export-card {
  position: sticky;
  top: 96px;
  border-radius: 16px;
  padding: 25px;
}

.export-icon {
  display: grid;
  width: 52px;
  height: 58px;
  place-items: center;
  margin-bottom: 18px;
  border: 1px solid #aac6d8;
  border-radius: 8px 8px 13px 8px;
  background: #edf6fa;
  color: var(--navy-800);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.export-card > p {
  margin: 10px 0 18px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.7;
}

.scope-block {
  margin: 18px 0;
  border-left: 3px solid var(--teal-600);
  background: var(--teal-100);
  padding: 13px 14px;
}

.scope-block strong {
  color: #165c58;
  font-size: 0.78rem;
}

.scope-block ul {
  margin: 9px 0 0;
  padding-left: 18px;
  color: #3f625f;
  font-size: 0.76rem;
  line-height: 1.75;
}

.excluded-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
}

.excluded-fields span {
  border-radius: 999px;
  background: #edf1f4;
  color: #677585;
  padding: 5px 8px;
  font-size: 0.66rem;
  font-weight: 700;
}

.button {
  display: inline-flex;
  width: 100%;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.button + .button {
  margin-top: 9px;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.65;
  transform: none;
}

.button-primary {
  border: 1px solid var(--navy-900);
  background: var(--navy-900);
  color: white;
  box-shadow: 0 8px 20px rgba(16, 45, 77, 0.18);
}

.button-primary:hover {
  background: var(--navy-800);
}

.button-secondary {
  border: 1px solid #b8c9d7;
  background: white;
  color: var(--navy-800);
}

.button-secondary:hover {
  background: #f4f8fa;
}

.reset-button {
  display: block;
  margin: 15px auto 0;
  color: #768392;
}

.reset-button:hover {
  color: var(--danger);
}

.status-message {
  min-height: 20px;
  margin: 12px 0 0 !important;
  color: var(--teal-600) !important;
  font-size: 0.74rem !important;
  text-align: center;
}

.status-message.is-error {
  color: var(--danger) !important;
}

.privacy-note {
  display: block;
  margin-top: 14px;
  color: #8794a1;
  font-size: 0.68rem;
  line-height: 1.6;
  text-align: center;
}

footer {
  border-top: 1px solid #d5dfe6;
  background: #e7edf1;
  color: #6f7b88;
  padding: 24px 20px;
  font-size: 0.74rem;
  text-align: center;
}

footer p {
  margin: 0;
}

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

  .export-card {
    position: static;
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 12px;
  }

  .export-card > * {
    grid-column: 1 / -1;
  }

  .export-card .button-secondary {
    grid-column: 1;
  }

  .export-card .button-primary {
    grid-column: 2;
    margin-top: 0;
  }

  .beneficiary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .header-inner,
  .page-shell {
    width: min(100% - 26px, 1180px);
  }

  .privacy-pill {
    display: none;
  }

  .page-shell {
    padding-top: 42px;
  }

  .intro h1 {
    font-size: 2.15rem;
  }

  .form-section {
    padding: 27px 20px 30px;
  }

  .cols-2,
  .cols-3,
  .beneficiary-grid {
    grid-template-columns: 1fr;
  }

  .span-2,
  .span-3 {
    grid-column: auto;
  }

  .beneficiary-grid .field > span {
    min-height: 0;
  }

  .signature-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .export-card {
    display: block;
  }

  .export-card .button-primary {
    margin-top: 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
