:root {
  color-scheme: light;
  --ink: #1d252c;
  --muted: #66717d;
  --line: #d9dee5;
  --soft: #f4f6f8;
  --paper: #ffffff;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --warn: #9f5b00;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #eef2f5;
  color: var(--ink);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", Arial, sans-serif;
  letter-spacing: 0;
}

.law-site-nav {
  min-height: 74px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 12px 28px;
  background: #162721;
  color: #fff;
}

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

.law-site-brand img {
  width: 46px;
  height: 46px;
  object-fit: contain;
  background: #fff;
  border-radius: 4px;
}

.law-site-brand span {
  display: grid;
  gap: 2px;
}

.law-site-brand strong {
  font-size: 18px;
}

.law-site-brand small {
  color: #cbd6d1;
  font-size: 11px;
}

.law-site-links {
  display: flex;
  align-items: center;
  gap: 18px;
}

.law-site-links a {
  color: #edf3f0;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.law-site-links a:hover,
.law-site-links a:focus-visible {
  color: #fff;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.law-site-links .consult-link {
  padding: 9px 12px;
  border: 1px solid #d7b46a;
  border-radius: 4px;
  color: #fff;
}

.topbar {
  min-height: 92px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 18px 28px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
}

.privacy-note {
  max-width: 300px;
  padding: 10px 12px;
  border: 1px solid #b9d8d3;
  border-radius: 6px;
  color: var(--accent-dark);
  background: #edf9f6;
  font-size: 14px;
}

.app-shell {
  display: grid;
  grid-template-columns: 180px minmax(420px, 620px) minmax(360px, 1fr);
  gap: 18px;
  padding: 18px;
}

.steps,
.workspace,
.document-side {
  min-width: 0;
}

.steps {
  position: sticky;
  top: 18px;
  align-self: start;
  display: grid;
  gap: 8px;
}

.step,
button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
}

.step {
  min-height: 42px;
  padding: 9px 12px;
  text-align: left;
}

.step.is-active {
  border-color: var(--accent);
  background: #eaf8f5;
  color: var(--accent-dark);
  font-weight: 700;
}

.workspace {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.book-mode .steps,
.book-mode #agreementForm,
.book-mode .document-side {
  display: none !important;
}

.book-mode .app-shell {
  grid-template-columns: minmax(0, 920px);
  justify-content: center;
}

.book-mode .workspace {
  padding: 0;
  overflow: hidden;
  border: 0;
  background: transparent;
}

.book-complete .steps {
  display: grid !important;
}

.book-complete #agreementForm,
.book-complete .document-side {
  display: block !important;
}

.book-complete .app-shell {
  grid-template-columns: 180px minmax(420px, 620px) minmax(360px, 1fr);
  justify-content: initial;
}

.book-complete .conversation {
  border-bottom: 1px solid var(--line);
}

.conversation {
  padding: 24px;
}

.book {
  position: relative;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  min-height: min(720px, calc(100vh - 180px));
  border-radius: 8px;
  box-shadow: 0 24px 54px rgba(42, 52, 62, 0.18);
}

.book-spine {
  border-radius: 8px 0 0 8px;
  background: linear-gradient(90deg, #27443f, #0f766e);
  box-shadow: inset -7px 0 14px rgba(0, 0, 0, 0.18);
}

.book-page {
  position: relative;
  display: grid;
  align-content: start;
  min-height: min(720px, calc(100vh - 180px));
  padding: clamp(28px, 5vw, 56px);
  border: 1px solid #d9dee5;
  border-left: 0;
  border-radius: 0 8px 8px 0;
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.08), transparent 42px),
    #fffdf8;
}

.book-page::after {
  content: "";
  position: absolute;
  inset: 18px 18px auto auto;
  width: 70px;
  height: 70px;
  border-top: 1px solid rgba(15, 118, 110, 0.18);
  border-right: 1px solid rgba(15, 118, 110, 0.18);
  pointer-events: none;
}

.page-kicker {
  margin-bottom: 10px;
  color: var(--accent-dark);
  font-size: clamp(18px, 2.5vw, 24px);
  font-weight: 700;
}

.page-number {
  justify-self: end;
  margin-top: -28px;
  color: var(--muted);
  font-size: 14px;
}

.book-page h2 {
  margin-bottom: 18px;
  font-size: clamp(26px, 4vw, 40px);
}

.page-question {
  max-width: 760px;
  margin-bottom: 24px;
  color: #26313a;
  font-size: clamp(22px, 3.2vw, 32px);
  font-weight: 700;
  line-height: 1.45;
}

.page-answer {
  max-width: 760px;
}

.page-field {
  margin: 0;
}

.page-field input,
.page-field textarea,
.date-field select,
.group-field input,
.group-field textarea,
.group-field select {
  min-height: 52px;
  border-color: #b8c4cf;
  font-size: 18px;
}

.group-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  max-width: 760px;
}

.group-field {
  display: grid;
  gap: 8px;
  margin: 0;
  color: #26313a;
  font-size: 17px;
  font-weight: 700;
}

.group-heading {
  grid-column: 1 / -1;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid #d5dee6;
  color: #0f6b61;
  font-size: 22px;
  font-weight: 800;
}

.group-heading:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.topic-group-heading {
  margin-top: 14px;
  padding: 12px 0 2px;
  border-top-color: #c6d7dc;
}

.group-field:has(.group-switch) {
  grid-column: 1 / -1;
}

.group-subheading {
  grid-column: 1 / -1;
  margin-top: 4px;
  color: #26313a;
  font-size: 20px;
  font-weight: 800;
}

.group-subheading.real-estate-part {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 12px 16px;
  border: 1px solid #c8d7df;
  border-radius: 8px 8px 0 0;
  background: #eef7f4;
  color: #075e54;
}

.group-subheading.real-estate-part::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #0b7d71;
}

.group-subheading.building-part {
  background: #f3f6fb;
  color: #243f63;
}

.group-subheading.building-part::before {
  background: #426b9a;
}

.group-field.real-estate-field {
  padding: 12px 14px;
  border: 1px solid #d7e1e6;
  border-radius: 8px;
  background: #fbfefd;
}

.group-field.building-field {
  border-color: #d8e0ec;
  background: #fbfcff;
}

.group-field input,
.group-field textarea,
.group-field select {
  width: 100%;
  font-weight: 400;
}

.group-field textarea {
  min-height: 86px;
  resize: vertical;
  line-height: 1.55;
}

.group-field .date-selects {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.group-field .date-selects-with-icon {
  grid-template-columns: 44px repeat(3, minmax(0, 1fr));
}

.range-control {
  display: grid;
  gap: 16px;
  max-width: 760px;
  padding: 18px 20px;
  border: 1px solid #c8d0d8;
  border-radius: 8px;
  background: #fff;
}

.range-control strong {
  color: var(--accent-dark);
  font-size: clamp(24px, 4vw, 36px);
  line-height: 1.25;
}

.range-control input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.range-control span {
  color: var(--muted);
  font-size: 15px;
}

.due-choice {
  display: grid;
  gap: 18px;
}

.period-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.period-option {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 16px;
  border: 1px solid #c8d0d8;
  border-radius: 8px;
  background: #fff;
}

.period-option:has(input:checked) {
  border-color: var(--accent);
  background: #eaf8f5;
}

.period-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #26313a;
  font-size: 17px;
  font-weight: 800;
}

.period-title input {
  width: 20px;
  height: 20px;
}

.period-body,
.period-date {
  display: grid;
  gap: 10px;
}

.time-choice {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  max-width: 520px;
}

.week-choice {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.week-card {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin: 0;
  padding: 14px 10px;
  border: 1px solid #c8d0d8;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  text-align: center;
}

.week-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.week-card:has(input:checked) {
  border-color: var(--accent);
  background: #eaf8f5;
  color: var(--accent-dark);
}

.week-icon {
  display: block;
  width: 38px;
  height: 38px;
  border: 3px solid currentColor;
  border-radius: 8px;
  background:
    linear-gradient(currentColor 0 9px, transparent 9px),
    linear-gradient(90deg, transparent 11px, #d5dee6 11px 13px, transparent 13px 24px, #d5dee6 24px 26px, transparent 26px),
    linear-gradient(transparent 20px, #d5dee6 20px 22px, transparent 22px 30px, #d5dee6 30px 32px, transparent 32px);
}

.currency-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  max-width: 760px;
}

.currency-field span {
  color: #26313a;
  font-size: 22px;
  font-weight: 700;
}

.currency-field input {
  width: 100%;
}

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

.two-choice {
  max-width: 520px;
}

.choice-option {
  display: flex;
  align-items: center;
  min-height: 58px;
  margin: 0;
  padding: 14px 16px;
  border: 1px solid #c8d0d8;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 17px;
}

.choice-option input {
  width: 20px;
  height: 20px;
  margin-right: 10px;
}

.choice-option:has(input:checked) {
  border-color: var(--accent);
  background: #eaf8f5;
  color: var(--accent-dark);
}

.date-selects {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  max-width: 620px;
}

.date-selects-with-icon {
  grid-template-columns: 54px repeat(3, minmax(0, 1fr));
  max-width: 720px;
  align-items: end;
}

.date-icon {
  position: relative;
  display: block;
  width: 44px;
  height: 44px;
  align-self: center;
  border: 3px solid var(--accent);
  border-radius: 8px;
  background:
    linear-gradient(var(--accent) 0 10px, transparent 10px),
    linear-gradient(90deg, transparent 12px, #d5dee6 12px 15px, transparent 15px 29px, #d5dee6 29px 32px, transparent 32px),
    linear-gradient(transparent 22px, #d5dee6 22px 25px, transparent 25px 34px, #d5dee6 34px 37px, transparent 37px);
}

.date-icon::before,
.date-icon::after {
  content: "";
  position: absolute;
  top: -8px;
  width: 6px;
  height: 12px;
  border-radius: 4px;
  background: var(--accent-dark);
}

.date-icon::before {
  left: 10px;
}

.date-icon::after {
  right: 10px;
}

.date-field {
  margin: 0;
  color: var(--muted);
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 34px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.page-actions button,
.completion-card {
  min-height: 44px;
}

.completion-card {
  padding: 18px;
  border: 1px solid #b9d8d3;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(42, 52, 62, 0.08);
}

#pageNext,
#generateDraft {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.page-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.panel {
  display: none;
}

.panel.is-active {
  display: block;
}

.interview-panel .interview-item {
  display: none;
}

.interview-panel .interview-item.is-current {
  display: block;
}

.interview-panel .interview-item.grid.is-current {
  display: grid;
}

.interview-panel .interview-item.is-current {
  padding: 18px;
  border: 1px solid #b9d8d3;
  border-radius: 8px;
  background: #fbfefd;
  box-shadow: 0 10px 24px rgba(42, 52, 62, 0.08);
}

.interview-panel label.interview-item.is-current {
  font-size: 16px;
}

.interview-panel fieldset.interview-item.is-current {
  padding: 18px;
}

.interview-panel .grid .interview-item.is-current {
  margin-bottom: 0;
}

.interview-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.interview-progress {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.interview-actions {
  display: flex;
  gap: 10px;
}

.interview-actions button {
  min-height: 40px;
  padding: 8px 14px;
}

.interview-next {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.interview-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.section-title {
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.section-title h2 {
  margin-bottom: 6px;
  font-size: 20px;
}

.section-title p {
  color: var(--muted);
  font-size: 14px;
}

.grid {
  display: grid;
  gap: 14px;
}

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

fieldset {
  min-width: 0;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

legend {
  padding: 0 6px;
  font-weight: 700;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c8d0d8;
  border-radius: 6px;
  padding: 9px 10px;
  font: inherit;
  font-weight: 400;
  background: #fff;
}

textarea {
  resize: vertical;
  line-height: 1.55;
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
}

.switch input {
  width: 18px;
  height: 18px;
}

.conditional {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.conditional.is-hidden {
  display: none;
}

.document-side {
  position: sticky;
  top: 18px;
  align-self: start;
  max-height: calc(100vh - 36px);
  overflow: auto;
}

.pdf-export-host {
  position: static;
  width: 794px;
  overflow: visible;
  pointer-events: none;
  background: #fff;
}

.doc-paper {
  width: min(100%, 794px);
  min-height: 1123px;
  margin: 0 auto;
  padding: 64px clamp(36px, 10%, 80px) 112px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 18px 40px rgba(42, 52, 62, 0.12);
  color: #000;
  font-family: "DFKai-SB", "標楷體", "BiauKai", "KaiTi", serif;
  font-size: 18px;
  line-height: 1.8;
  white-space: normal;
}

.doc-line {
  white-space: pre-wrap;
  break-inside: avoid;
  margin: 0 0 4px;
  text-align: justify;
  text-justify: inter-ideograph;
}

.doc-paper h1 {
  font-family: "DFKai-SB", "標楷體", "BiauKai", "KaiTi", serif;
  text-align: center;
  font-size: 29px;
  line-height: 1.4;
  margin: 4px 0 28px;
  color: #000;
  white-space: nowrap;
}

.doc-blank {
  min-height: 0.55em;
  margin: 0;
}

.doc-section,
.doc-party-heading,
.doc-signature-heading,
.doc-note-heading {
  text-align: left;
}

.doc-section-heading,
.doc-subheading,
.doc-party-heading,
.doc-signature-heading,
.doc-note-heading {
  font-weight: 700;
}

.doc-section {
  margin-top: 14px;
  margin-bottom: 4px;
}

.doc-level-1,
.doc-level-2,
.doc-level-3,
.doc-level-4,
.doc-numbered-note {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  column-gap: 0.5em;
  text-indent: 0;
}

.doc-marker {
  grid-column: 1;
}

.doc-item-text {
  grid-column: 2;
  min-width: 0;
}

.doc-level-1 {
  padding-left: 0;
}

.doc-level-2 {
  padding-left: 2em;
  margin-top: 8px;
  font-weight: 700;
  text-align: left;
}

.doc-level-3 {
  padding-left: 4em;
}

.doc-level-4 {
  padding-left: 6em;
}

.doc-party-heading {
  margin-bottom: 6px;
}

.doc-party-detail,
.doc-signature-line {
  padding-left: 2em;
  text-align: left;
}

.doc-body-line {
  text-indent: 2em;
}

.doc-subclause {
  font-weight: 400;
}

.doc-signature-heading,
.doc-note-heading {
  break-before: page;
  page-break-before: always;
  margin-top: 0;
  margin-bottom: 12px;
}

.doc-signing-date {
  margin-top: 16px;
  text-align: right;
}

.doc-empty-marker {
  margin: 18px 0;
  text-align: center;
}

.doc-note-body,
.doc-meta {
  font-size: 16px;
  line-height: 1.65;
  text-align: left;
}

.doc-numbered-note {
  padding-left: 1em;
}

.doc-meta {
  margin-top: 10px;
}

.preview-editor {
  min-height: 520px;
  font-family: "DFKai-SB", "標楷體", "BiauKai", "KaiTi", serif;
  line-height: 1.7;
}

.messages {
  margin-bottom: 12px;
}

.message {
  margin-bottom: 8px;
  padding: 9px 12px;
  border-radius: 6px;
  background: #fff7e6;
  border: 1px solid #f0c36a;
  color: var(--warn);
  font-size: 14px;
}

.message-link {
  width: 100%;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.message-link:hover,
.message-link:focus-visible {
  border-color: #b8860b;
  background: #fff1c4;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.actions button {
  min-height: 40px;
  padding: 8px 14px;
}

#downloadPdf {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.tool-footer {
  padding: 24px 28px 30px;
  border-top: 1px solid var(--line);
  background: #162721;
  color: #dce5e1;
  font-size: 13px;
  line-height: 1.7;
}

.tool-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  margin-bottom: 14px;
}

.tool-footer a {
  color: #fff;
  font-weight: 700;
  text-decoration: none;
}

.tool-footer a:hover,
.tool-footer a:focus-visible {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.tool-footer p {
  max-width: 980px;
  margin-bottom: 6px;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 150px minmax(0, 1fr);
  }

  .document-side {
    grid-column: 1 / -1;
    position: static;
    max-height: none;
  }
}

@media (max-width: 760px) {
  .law-site-nav {
    align-items: flex-start;
    padding: 12px 16px;
  }

  .law-site-brand strong {
    font-size: 16px;
  }

  .law-site-links {
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px 14px;
  }

  .law-site-links a:not(.consult-link) {
    display: none;
  }

  .topbar,
  .app-shell {
    display: block;
  }

  .topbar {
    padding: 16px;
  }

  .privacy-note,
  .steps,
  .workspace,
  .document-side {
    margin-top: 14px;
  }

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

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

  .group-fields,
  .group-field .date-selects {
    grid-template-columns: 1fr;
  }

  .doc-paper {
    padding: 28px 22px;
  }

  .tool-footer {
    padding: 22px 16px 26px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .law-site-nav,
  .tool-footer,
  .steps,
  .workspace {
    display: none;
  }

  .app-shell {
    display: block;
    padding: 0;
  }

  .document-side {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .doc-paper {
    width: auto;
    min-height: auto;
    box-shadow: none;
    border: 0;
    padding: 25.4mm;
  }
}
