:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #eef4f1;
  --line: #d8ded9;
  --line-strong: #b9c3be;
  --text: #18211d;
  --muted: #66736d;
  --accent: #136f63;
  --accent-strong: #0c564d;
  --accent-soft: #d9eee9;
  --warn: #a05a1a;
  --danger: #b53a35;
  --shadow: 0 16px 48px rgba(25, 40, 34, 0.11);
  font-family: "Segoe UI", "Yu Gothic UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(10px);
}

.topbar h1,
.surface-title h2,
.panel h2,
.empty-state h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 28px;
}

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

.top-actions,
.wizard-actions,
.preview-actions,
.inline-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button,
.ghost-button,
.danger-button {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line-strong);
}

.ghost-button:hover {
  border-color: var(--accent);
}

.danger-button {
  background: #fff1ef;
  color: var(--danger);
  border: 1px solid #e5b7b1;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 20px;
  padding: 20px 28px 32px;
}

.sidebar,
.workspace {
  min-width: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel,
.editor-surface,
.preview-surface {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

.panel {
  overflow: hidden;
}

.panel-heading,
.surface-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel h2,
.surface-title h2 {
  font-size: 18px;
}

.surface-title.compact {
  align-items: center;
}

.count-pill,
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-badge.ready {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status-badge.completed {
  background: #e7f0ff;
  color: #28569a;
}

.status-badge.void {
  background: #fff1ef;
  color: var(--danger);
}

.template-list,
.contract-list {
  display: flex;
  flex-direction: column;
}

.template-button,
.contract-button {
  width: 100%;
  padding: 14px 16px;
  text-align: left;
  background: transparent;
  color: var(--text);
  border-top: 1px solid var(--line);
}

.template-button:first-child,
.contract-button:first-child {
  border-top: 0;
}

.template-button:hover,
.contract-button:hover,
.template-button.active,
.contract-button.active {
  background: var(--surface-soft);
}

.template-button strong,
.contract-button strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.template-button span,
.contract-button span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  line-height: 1.5;
}

.contract-panel {
  min-height: 220px;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.step-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.step-tab {
  min-height: 42px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 800;
}

.step-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 42%);
  gap: 16px;
  align-items: start;
}

.wizard-form {
  padding: 16px;
}

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

.step-heading h3 {
  margin: 0;
  font-size: 20px;
}

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

.form-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.form-field.full {
  grid-column: 1 / -1;
}

.form-field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.form-field input,
.form-field textarea,
.form-field select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  min-height: 42px;
  padding: 9px 11px;
  outline: none;
}

.form-field textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.55;
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.suffix-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
}

.suffix-field input {
  border: 0;
  border-radius: 0;
}

.suffix-field span {
  padding: 0 12px;
  color: var(--muted);
  font-weight: 800;
}

.party-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfa;
}

.party-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.party-title strong {
  font-size: 14px;
}

.required-mark {
  color: var(--warn);
  font-size: 12px;
  font-weight: 800;
}

.paste-zone {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 14px;
  align-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfa;
  outline: none;
}

.paste-zone:focus,
.paste-zone.dragging {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.paste-zone.busy {
  opacity: 0.72;
  pointer-events: none;
}

.paste-zone-main strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.paste-zone-main span,
.upload-status {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.upload-status {
  grid-column: 1 / -1;
  margin: 0;
}

.hidden-file {
  display: none;
}

.wizard-actions {
  justify-content: flex-end;
  padding-top: 18px;
  margin-top: 18px;
  border-top: 1px solid var(--line);
}

.preview-surface {
  position: sticky;
  top: 98px;
  overflow: hidden;
}

.contract-preview {
  margin: 0;
  min-height: 520px;
  max-height: calc(100vh - 220px);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  line-height: 1.75;
  padding: 18px;
  background: #fff;
  color: #111;
}

.document-disclaimer,
.site-disclaimer {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.document-disclaimer {
  padding: 10px 18px 12px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.site-disclaimer {
  padding: 0 28px 18px;
}

.image-preview-wrap {
  border-top: 1px solid var(--line);
  padding: 14px 18px 18px;
}

.image-preview-wrap img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.empty-state {
  padding: 18px 16px;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 32px));
  padding: 14px 16px;
  border-radius: 8px;
  background: #16221e;
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 700;
}

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

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

  .preview-surface {
    position: static;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button {
    flex: 1;
  }

  .app-shell {
    padding: 14px;
  }

  .site-disclaimer {
    padding: 0 14px 14px;
  }

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

  .step-tabs,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .wizard-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .paste-zone {
    grid-template-columns: 1fr;
  }

  .contract-preview {
    min-height: 360px;
    max-height: none;
  }
}

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

  .topbar,
  .sidebar,
  .step-tabs,
  .editor-surface,
  .preview-actions,
  .site-disclaimer {
    display: none !important;
  }

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

  .preview-surface {
    border: 0;
    box-shadow: none;
  }

  .contract-preview {
    max-height: none;
    padding: 0;
  }

  .document-disclaimer {
    color: #555;
    font-size: 8.5pt;
    padding: 8pt 0 0;
  }
}
