:root {
  --bg: #eef2f5;
  --panel: #ffffff;
  --line: #d8dee6;
  --text: #20262d;
  --muted: #627083;
  --brand: #246b57;
  --brand-soft: #e4f1ec;
  --warn: #9a5b14;
  --danger: #b3261e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

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

button,
.import-btn {
  min-height: 38px;
  border: 1px solid var(--brand);
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  padding: 8px 12px;
  cursor: pointer;
}

.secondary-btn {
  background: #fff;
  color: var(--brand);
}

.sheet-app {
  max-width: 1500px;
  margin: 0 auto;
  padding: 16px;
}

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

.sheet-header h1 {
  margin: 0;
  font-size: 24px;
}

.save-status {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.section-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.section-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding-left: 4px;
}

.section-links a {
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 6px 11px;
  font-size: 13px;
}

.section-links a.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.import-btn {
  display: inline-flex;
  align-items: center;
}

.workbench {
  display: grid;
  grid-template-columns: 210px minmax(440px, 1fr) 360px;
  gap: 12px;
  align-items: start;
}

.step-nav,
.sheet-panel,
.library-panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.step-nav,
.library-panel {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: hidden;
}

.nav-title {
  padding: 14px 14px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.step-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 10px 12px;
}

.step-btn {
  width: 100%;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #f7f9fb;
  color: var(--text);
  text-align: left;
}

.step-btn.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: #12382e;
  font-weight: 700;
}

.sheet-panel {
  min-height: calc(100vh - 92px);
  padding: 16px;
}

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

.panel-heading h2,
.library-header h2 {
  margin: 0;
  font-size: 20px;
}

.panel-heading p,
.library-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.quick-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.summary-pill {
  border-radius: 999px;
  background: #f0f3f6;
  color: var(--muted);
  padding: 5px 9px;
  font-size: 12px;
}

.step-content {
  padding-top: 16px;
}

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

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea,
.library-search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 9px 10px;
}

.field textarea {
  min-height: 120px;
  resize: vertical;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f6f8fa;
  color: var(--muted);
  font-size: 12px;
}

td input {
  width: 88px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.compact-btn,
.remove-btn {
  min-height: 32px;
  padding: 5px 9px;
  font-size: 13px;
}

.remove-btn {
  border-color: #d0d7de;
  background: #fff;
  color: var(--danger);
}

.item-list {
  display: grid;
  gap: 8px;
}

.selected-item,
.validation-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 10px;
}

.selected-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.inline-edit-label,
.library-level-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.inline-level-input,
.library-level-input {
  width: 72px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px 8px;
}

.library-add-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.selected-title {
  font-weight: 700;
}

.selected-meta,
.validation-row p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.validation-row.warn {
  border-color: #d9a441;
  background: #fff8e9;
}

.validation-row.danger {
  border-color: #e09a96;
  background: #fff2f1;
}

.derived-note {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 10px;
}

.derived-note p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.derived-note code {
  font-family: Consolas, "Courier New", monospace;
  color: var(--text);
}

.export-box {
  width: 100%;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font-family: Consolas, "Courier New", monospace;
}

.library-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  padding: 12px;
}

.library-header {
  margin-bottom: 12px;
}

.library-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.library-tabs button {
  min-height: 34px;
  border-color: var(--line);
  background: #f7f9fb;
  color: var(--text);
  padding: 6px;
}

.library-tabs button.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.library-search {
  margin-bottom: 10px;
}

.library-results {
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding-right: 2px;
}

.library-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.library-card h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.library-card p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.library-card button {
  margin-top: 8px;
  min-height: 32px;
  padding: 5px 9px;
  font-size: 13px;
}

@media (max-width: 1180px) {
  .workbench {
    grid-template-columns: 180px minmax(0, 1fr);
  }

  .library-panel {
    grid-column: 1 / -1;
    position: static;
    max-height: none;
  }

  .library-results {
    max-height: 420px;
  }
}

@media (max-width: 760px) {
  .sheet-app {
    padding: 10px;
  }

  .sheet-header,
  .panel-heading {
    display: grid;
  }

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

  .step-nav {
    position: static;
    max-height: none;
  }

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

  .sheet-panel {
    min-height: 0;
  }
}
