:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef3f2;
  --line: #d8e0de;
  --line-strong: #bac8c4;
  --text: #1f2a28;
  --muted: #687774;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --primary-soft: #dcefeb;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --warning: #946200;
  --warning-soft: #fff7df;
  --shadow: 0 18px 50px rgba(31, 42, 40, 0.08);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: calc(100% - 32px);
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
  font-weight: 700;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
  font-weight: 700;
}

.meta {
  display: flex;
  gap: 14px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

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

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel-compact {
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 36px);
  overflow: auto;
}

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

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

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

.primary-action,
.secondary-action,
.config-toggle,
.icon-button,
.row-action,
.add-row-wide {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 40px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.primary-action {
  padding: 0 18px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.primary-action:hover {
  background: var(--primary-dark);
}

.secondary-action,
.config-toggle,
.row-action {
  padding: 0 12px;
  background: #fff;
  border-color: var(--line);
  color: var(--text);
}

.secondary-action:hover,
.config-toggle:hover,
.row-action:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.secondary-action:disabled,
.primary-action:disabled {
  cursor: wait;
  opacity: 0.68;
}

.visually-hidden-file {
  position: absolute;
  width: 1px;
  min-height: 1px;
  opacity: 0;
  pointer-events: none;
}

.config-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  font-weight: 700;
}

.config-toggle-icon {
  display: inline-block;
  font-size: 16px;
  line-height: 1;
  transition: transform 0.15s ease;
}

.config-panel.is-open .config-toggle-icon {
  transform: rotate(180deg);
}

.icon-button {
  width: 40px;
  padding: 0;
  background: var(--primary);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  font-weight: 700;
}

.icon-button:hover {
  background: var(--primary-dark);
}

.field-list,
.row-list {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.draft-panel {
  display: grid;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #f6fbfa;
}

.draft-current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.draft-current > div:first-child,
.draft-chip {
  min-width: 0;
}

.draft-label,
.draft-current small,
.draft-chip small,
.draft-empty,
.draft-unavailable {
  color: var(--muted);
  font-size: 12px;
}

.draft-label,
.draft-current strong,
.draft-current small,
.draft-chip span,
.draft-chip small {
  display: block;
}

.draft-current strong,
.draft-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.draft-actions,
.draft-list {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.draft-actions {
  flex: 0 0 auto;
}

.draft-chip {
  max-width: 240px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
}

.draft-chip:hover,
.draft-chip.is-active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.document-name-panel,
.shared-remark-panel {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
}

.shared-remark-panel {
  background: #fff;
}

.document-name-panel label,
.shared-remark-panel label {
  max-width: 520px;
}

.natural-fill-dock {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 40;
  display: grid;
  gap: 12px;
  justify-items: end;
  pointer-events: none;
}

.natural-fill-dock > * {
  pointer-events: auto;
}

.natural-fill-launcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 62px;
  height: 62px;
  padding: 0;
  overflow: visible;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(145deg, #6b8dff 0%, #155df5 78%);
  color: transparent;
  box-shadow: 0 12px 24px rgba(21, 93, 245, 0.3);
  font-size: 0;
  line-height: 0;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.natural-fill-launcher:hover {
  background: linear-gradient(145deg, #7596ff 0%, #0f50df 78%);
  box-shadow: 0 15px 30px rgba(21, 93, 245, 0.36);
  transform: translateY(-2px);
}

.natural-fill-launcher:focus-visible {
  outline: 3px solid rgba(21, 93, 245, 0.28);
  outline-offset: 4px;
}

.natural-fill-launcher:disabled {
  cursor: wait;
  opacity: 0.72;
  transform: none;
}

.natural-fill-launcher::before {
  width: 33px;
  height: 26px;
  border-radius: 7px 7px 7px 3px;
  background:
    radial-gradient(circle at 9px 11px, #2f6cf6 0 2.5px, transparent 3px),
    radial-gradient(circle at 16.5px 11px, #2f6cf6 0 2.5px, transparent 3px),
    radial-gradient(circle at 24px 11px, #2f6cf6 0 2.5px, transparent 3px),
    #fff;
  box-shadow: inset 0 -1px 0 rgba(21, 93, 245, 0.14);
  content: "";
}

.natural-fill-launcher::after {
  position: absolute;
  left: calc(50% - 12px);
  top: calc(50% + 8px);
  width: 9px;
  height: 9px;
  background: #fff;
  clip-path: polygon(0 0, 100% 0, 0 100%);
  content: "";
}

.natural-fill-launcher.is-loading::before {
  animation: natural-fill-pulse 0.9s ease-in-out infinite;
}

@keyframes natural-fill-pulse {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(0.9);
  }
}

.natural-fill-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  width: min(420px, calc(100vw - 36px));
  max-height: min(640px, calc(100vh - 104px));
  padding: 16px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 22px 64px rgba(31, 42, 40, 0.16);
}

.natural-fill-prompt {
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

.natural-fill-panel label {
  max-width: none;
}

.natural-fill-panel textarea {
  min-height: 118px;
}

.natural-fill-panel[hidden] {
  display: none;
}

.natural-fill-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.document-name-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(160px, 240px);
  gap: 12px;
}

.field-card,
.row-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.field-card {
  padding: 14px;
}

.row-card {
  overflow: hidden;
}

.custom-row-card {
  border-color: #9bcfc7;
}

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

.row-card .card-heading {
  margin: 0;
  padding: 12px 14px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
}

.custom-row-card .card-heading {
  background: #e6f5f2;
}

.card-title {
  font-weight: 700;
  min-width: 0;
}

.action-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.small-icon {
  width: 34px;
  min-height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.small-icon:hover {
  background: var(--surface-soft);
  border-color: var(--line-strong);
}

.small-icon.danger,
.row-action.danger {
  color: var(--danger);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 128px;
  align-items: start;
  gap: 12px;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.label-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.required-dot {
  color: var(--danger);
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 11px;
  text-align: left;
  outline: none;
}

textarea {
  min-height: 96px;
  padding: 10px 11px;
  line-height: 1.5;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

input[readonly] {
  background: #e7eaee;
  color: #38413f;
  cursor: default;
}

.calculated-label .label-row::after {
  content: "自动";
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 1px 6px;
  background: #f4f6f8;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.image-input {
  align-content: start;
  min-width: 0;
}

.image-input input[type="file"] {
  position: absolute;
  width: 1px;
  min-height: 1px;
  opacity: 0;
  pointer-events: none;
}

.image-select-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-weight: 700;
}

.image-select-button:hover {
  background: var(--surface-soft);
  border-color: var(--primary);
}

.image-preview,
.image-empty {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.image-preview {
  overflow: hidden;
}

.image-preview img {
  display: block;
  width: 100%;
  height: 110px;
  object-fit: contain;
  background: #fff;
}

.image-empty {
  display: grid;
  place-items: center;
  min-height: 64px;
  padding: 10px;
  color: var(--muted);
}

.image-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid var(--line);
}

.image-meta span {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-meta button {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid #ffccc7;
  border-radius: 8px;
  background: #fff;
  color: var(--danger);
}

.image-meta button:hover {
  background: var(--danger-soft);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  color: var(--text);
}

.checkbox-label input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--primary);
}

.row-input-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  padding: 14px;
}

.custom-row-options {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding: 0 14px 14px;
}

.custom-row-option {
  width: auto;
  min-height: 32px;
}

.custom-secondary-field {
  opacity: 0.68;
}

.custom-secondary-field:focus-within {
  opacity: 1;
}

.add-row-wide {
  background: var(--primary-soft);
  color: var(--primary-dark);
  border-color: #b7ddd7;
  font-weight: 700;
}

.add-row-wide:hover {
  background: #cfebe5;
}

.bottom-row-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 16px 16px;
}

.bottom-row-actions .add-row-wide {
  width: 100%;
  margin: 0;
}

.add-custom-wide {
  background: #fff;
}

.empty-state {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  padding: 22px;
  text-align: center;
  background: #fbfcfc;
}

.status {
  position: fixed;
  right: auto;
  bottom: 18px;
  left: 18px;
  z-index: 50;
  width: calc(100% - 36px);
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.status-static {
  position: static;
  max-width: none;
  margin-top: 16px;
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.status.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.status.is-error {
  border-color: #ffccc7;
  background: var(--danger-soft);
  color: var(--danger);
}

.status.is-warning {
  border-color: #ffe58f;
  background: var(--warning-soft);
  color: var(--warning);
}

.status.is-success {
  border-color: #a7dfd5;
  background: #edf9f6;
  color: var(--primary-dark);
}

.is-invalid {
  border-color: var(--danger) !important;
  background: var(--danger-soft);
}

.field-error {
  color: var(--danger);
  font-size: 12px;
  min-height: 16px;
}

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

  .panel-compact {
    position: static;
    max-height: none;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: 100%;
    padding: 12px 10px 24px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  h1 {
    font-size: 22px;
  }

  h2 {
    font-size: 16px;
  }

  .meta {
    flex-wrap: wrap;
    gap: 8px 12px;
  }

  .workspace,
  .field-list,
  .row-list {
    gap: 10px;
  }

  .draft-current {
    align-items: stretch;
    flex-direction: column;
  }

  .document-name-panel {
    grid-template-columns: 1fr;
  }

  .natural-fill-dock {
    right: max(16px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
    left: auto;
    justify-items: end;
  }

  .natural-fill-panel {
    width: min(330px, calc(100vw - 72px));
  }

  .natural-fill-launcher {
    width: 54px;
    height: 54px;
  }

  .natural-fill-panel {
    min-height: min(330px, calc(100dvh - 220px));
    max-height: min(680px, calc(100dvh - 86px));
    padding: 14px;
    gap: 10px;
  }

  .natural-fill-prompt {
    margin: 0 0 4px;
    line-height: 1.45;
  }

  .natural-fill-panel label {
    gap: 4px;
  }

  .natural-fill-panel textarea {
    min-height: 148px;
  }

  .natural-fill-actions {
    flex-direction: column-reverse;
    gap: 8px;
  }

  .natural-fill-actions > * {
    width: 100%;
  }

  .draft-actions,
  .draft-actions > *,
  .draft-chip {
    width: 100%;
    max-width: none;
  }

  .field-list,
  .row-list {
    padding: 10px;
  }

  .panel-heading,
  .field-card,
  .row-input-grid {
    padding: 12px;
  }

  .custom-row-options {
    padding: 0 12px 12px;
  }

  .primary-action {
    width: 100%;
  }

  .panel-heading,
  .card-heading,
  .row-card .card-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar,
  .heading-actions,
  .action-strip {
    flex-wrap: wrap;
    width: 100%;
  }

  .toolbar > *,
  .heading-actions > *,
  .action-strip > * {
    flex: 1 1 auto;
  }

  .config-toggle {
    display: inline-flex;
    justify-content: center;
  }

  .config-panel:not(.is-open) .field-list,
  .config-panel:not(.is-open) #addFieldBtn {
    display: none;
  }

  .config-panel:not(.is-open) .panel-heading {
    border-bottom: 0;
  }

  .icon-button,
  .small-icon {
    flex: 0 0 40px;
  }

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

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

  .image-meta {
    display: none;
  }

  .bottom-row-actions {
    grid-template-columns: 1fr;
    padding: 0 10px 10px;
  }

  .status {
    top: 10px;
    bottom: auto;
    left: 10px;
    max-width: calc(100% - 20px);
    transform: translateY(calc(-100% - 16px));
  }

  .status.is-visible {
    transform: translateY(0);
  }
}
