:root {
  --bg: #eef3f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #66758a;
  --line: #e3e9f1;
  --input: #d5dde8;
  --accent: #2f6de0;
  --accent-soft: #f3f7fd;
  --accent-line: #c9daf6;
  --danger: #8d2f2f;
  --danger-bg: #fdf3f3;
  --warn: #8a5a12;
  --warn-bg: #fbf6ea;
  --radius: 12px;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

.page {
  width: min(1440px, calc(100% - 16px));
  margin: 0 auto;
  padding: 10px 0 20px;
}

h1, h2, h3, p { margin: 0; }

h1 {
  font-size: 20px;
  font-weight: 600;
}

h2 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

.top {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.note, .fine, .system-desc, .qty, .summary-note, .summary-foot, .consult-line, .local-note, .qty-hint {
  color: var(--muted);
}
.note { font-size: 12px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 10px;
  align-items: start;
  margin-top: 8px;
}

.block {
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.block + .block { margin-top: 14px; }

.basics-grid {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(180px, 1.1fr) minmax(120px, 0.8fr) minmax(140px, 0.9fr);
  gap: 8px 10px;
  align-items: end;
}

.field { display: grid; gap: 4px; min-width: 0; }
.field > span, legend {
  font-size: 13px;
  color: var(--muted);
}

fieldset { border: 0; margin: 0; padding: 0; }

input, select {
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--input);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.unit-field { display: flex; align-items: center; gap: 6px; min-width: 0; }
.unit-field input { width: auto; flex: 1; min-width: 0; }
.unit { flex: none; color: var(--muted); font-size: 13px; }

.choices { display: flex; flex-wrap: wrap; gap: 6px 10px; min-height: 30px; align-items: center; }
.choice { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.choice input { width: auto; height: auto; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#system-list { display: grid; }

.system-columns,
.system {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 200px max-content;
  gap: 4px 10px;
  align-items: center;
}

.system-columns {
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.system {
  padding: 6px 8px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.system.is-on { background: var(--accent-soft); }

.system-main {
  --check: 24px;
  --check-gap: 8px;
}

.system-head {
  display: grid;
  grid-template-columns: var(--check) minmax(0, 1fr);
  column-gap: var(--check-gap);
  align-items: center;
  min-width: 0;
  cursor: pointer;
  font-weight: 600;
}

.system-copy {
  min-width: 0;
  display: grid;
  align-content: center;
}

.system-head input.system-toggle {
  appearance: none;
  width: var(--check);
  height: var(--check);
  margin: 0;
  flex: none;
  border: 1.5px solid #16325f;
  border-radius: 5px;
  background: #fff;
  display: grid;
  place-content: center;
}

.system-head input.system-toggle:checked {
  border-color: #16325f;
  background: #16325f;
}

.system-head input.system-toggle:checked::after {
  content: "";
  width: 6px;
  height: 11px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -2px);
}

.system-head input.system-toggle:focus-visible {
  outline: 2px solid var(--accent-line);
  outline-offset: 2px;
}

.system-desc {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.35;
}

.system.is-custom .system-main {
  display: grid;
  grid-template-columns: var(--check) minmax(0, 1fr);
  column-gap: var(--check-gap);
  align-items: center;
}

.system.is-custom .system-head {
  display: flex;
  grid-column: 1;
  grid-row: 1 / span 2;
  align-self: center;
  width: var(--check);
}

.system.is-custom .custom-title {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}

.system.is-custom .system-desc {
  grid-column: 2;
  grid-row: 2;
}
.qty-hint { margin: 0; font-size: 12px; line-height: 1.35; }

.system-qty {
  min-width: 0;
  justify-self: stretch;
}

.qty-inline {
  display: grid;
  grid-template-columns: 5.5em 72px 1.5em;
  align-items: center;
  column-gap: 6px;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
}

.qty-inline > span:first-child {
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.qty-inline input[type="number"] {
  width: 72px;
  text-align: right;
}

.qty-inline .unit,
.qty-inline .custom-unit {
  white-space: nowrap;
}

.qty-inline .custom-unit {
  width: 1.5em;
  min-width: 0;
  padding: 0 2px;
  text-align: center;
}

.tier { min-width: 0; }
.tier .choices {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 0;
  min-height: 0;
  border: 1px solid #16325f;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}
.tier .choice {
  position: relative;
  gap: 0;
  padding: 4px 8px;
  border-right: 1px solid #16325f;
  font-size: 14px;
  line-height: 1.2;
  white-space: nowrap;
  color: #16325f;
  background: #fff;
}
.tier .choice:last-child { border-right: 0; }
.tier .choice input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.tier .choice:has(input:checked) {
  background: #4d78ad;
  color: #fff;
}

.actions, .result-actions {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.result-actions { grid-template-columns: 1fr 1fr; }
.result-actions .primary,
.result-actions .save-note { grid-column: 1 / -1; }
.save-note { margin: 0; color: var(--accent); font-size: 12px; text-align: left; }
.save-note:empty { display: none; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  border: 0;
  background: linear-gradient(180deg, #16325f, #0b1c36);
  color: #fff;
  font: inherit;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}

.button:hover { filter: brightness(1.08); }
.button.primary,
a.button.primary:visited,
.button.secondary {
  background: linear-gradient(180deg, #16325f, #0b1c36);
  color: #fff;
  border: 0;
}
.button:disabled {
  color: rgba(255, 255, 255, 0.7);
  cursor: not-allowed;
  filter: none;
  opacity: 0.55;
}

.button[data-action="export-word"] {
  background: #ffcc00;
  color: #000;
  border: 1px solid #16325f;
}
.button[data-action="export-word"]:hover { filter: brightness(1.08); color: #000; }
.button[data-action="export-word"]:disabled {
  color: rgba(0, 0, 0, 0.55);
  opacity: 0.55;
}

.errors {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #f0d0d0;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger);
}

.errors p + p { margin-top: 4px; }

.summary {
  position: sticky;
  top: 8px;
  display: flex;
  flex-direction: column;
  height: 0;
  min-height: 100%;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.summary-head {
  padding: 8px 12px;
  background: linear-gradient(180deg, #16325f, #0b1c36);
  color: #fff;
  font-weight: 600;
}
#compute > h2 {
  flex: none;
  margin: -10px -12px 8px;
  padding: 8px 12px;
  background: linear-gradient(180deg, #16325f, #0b1c36);
  color: #fff;
  font-size: inherit;
  font-weight: 600;
  border-radius: var(--radius) var(--radius) 0 0;
}
#compute {
  border-top-right-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#compute .basics-grid {
  margin-bottom: 8px;
  flex: none;
}



.summary-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 10px 12px 12px;
}

.picked-scroll {
  flex: 1;
  min-height: 72px;
  max-height: 160px;
  margin-top: 4px;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 4px 10px;
}
.summary-block + .summary-block {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.summary-kicker { color: var(--muted); font-size: 13px; }

.summary-amount, .summary-message {
  margin-top: 2px;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0;
}

.summary-note { margin-top: 8px; font-size: 12px; }

.banner {
  margin-bottom: 12px;
  padding: 8px 10px;
  border: 1px solid #eadcbf;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 13px;
}

.picked-title {
  margin: 10px 0 4px;
  font-size: 13px;
  font-weight: 600;
}

.picked { margin: 0; padding: 0; list-style: none; }
.picked li {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  padding: 6px 0;
  font-size: 13px;
  line-height: 1.35;
}
.picked li + li {
  border-top: 1px solid var(--line);
}
.picked li::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.picked-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-foot {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.4;
}

.info {
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  border: 1px solid var(--muted);
  border-radius: 50%;
  text-align: center;
  font-size: 11px;
  line-height: 14px;
}

.more { margin-top: 8px; border-top: 1px solid var(--line); }
.more > summary, .cost summary, .missing summary {
  padding: 10px 0;
  cursor: pointer;
  font-size: 13px;
}

.cost { border-top: 1px solid var(--line); }
.cost-body { padding-bottom: 6px; }
.cost-row { padding: 8px 0; }
.cost-row + .cost-row { border-top: 1px solid var(--line); }
.cost-label { font-weight: 600; font-size: 13px; }
.cost-value, .qty { font-size: 13px; }
.qty { margin-top: 2px; }

.missing-list { margin: 0 0 8px; padding: 0; list-style: none; }
.missing-list li { padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.missing-list span { display: block; }
.missing-list span:first-child { font-weight: 600; }

.notes { margin: 0 0 8px; padding-left: 1.2em; font-size: 13px; }
.notes li + li { margin-top: 6px; }

/* 大卡片（#compute）左下角，在子系统列表卡片之外 */
.compute-foot {
  flex: none;
  margin-top: auto;
  padding-top: 8px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.add-system {
  margin: 0;
  /* 与右侧「历史记录」同宽：summary 280px，内边距 12×2，两列间隙 6 */
  width: 124px;
}

.custom-title {
  display: flex;
  align-items: center;
  gap: var(--check-gap, 8px);
}
.custom-name { flex: 1; min-width: 0; }
.custom-remove {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  padding: 0 2px;
}
.qty-inline .custom-unit { width: 48px; text-align: center; }

body.is-settings {
  height: 100vh;
  overflow: hidden;
}
body.is-settings .page {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 10px 0;
  overflow: hidden;
}
body.is-settings .workspace,
body.is-settings .top,
body.is-settings .consult-line,
body.is-settings #consult-note,
body.is-settings .local-note { display: none; }

.settings-page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-top: 0;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.settings-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
  margin-bottom: 8px;
}
.settings-bar h2 { margin: 0; }
.settings-guide {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-size: 12px;
  line-height: 1.3;
  align-self: center;
}
.settings-guide[hidden] { display: none !important; }
.settings-status { margin: 0 0 0 auto; color: var(--accent); font-size: 13px; flex: none; }
.settings-status.is-error { color: var(--danger); }
.settings-bar .button,
.settings-page .button { width: auto; }
#settings-body,
.settings-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.settings-head { flex: none; }
.settings-head > p + p { margin-top: 4px; }
.tier-percents {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px 14px;
  margin-top: 0;
  padding: 5px 10px;
  border-radius: 8px;
  background: #16325f;
  color: #fff;
}
.tier-percents .field {
  width: auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
}
.tier-percents .field > span {
  color: #fff;
  white-space: nowrap;
}
.tier-percents .unit-field { gap: 4px; }
.tier-percents .unit-field input {
  width: 64px;
  flex: none;
  height: 28px;
}
.tier-percents .unit { color: #fff; }
.percent-note {
  margin: 0;
  flex: 1;
  min-width: 0;
  align-self: center;
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.price-board {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 10px;
  margin-top: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 6px;
}
.price-board::-webkit-scrollbar { height: 10px; }
.price-board::-webkit-scrollbar-thumb {
  background: #c5d0de;
  border-radius: 999px;
}
.price-column {
  flex: 0 0 156px;
  width: 156px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid #16325f;
  border-radius: 10px;
  background: #f7f9fc;
  font-size: 12px;
}
.price-column h3 {
  margin: 0;
  padding: 6px 8px;
  font-size: 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  border-radius: 10px 10px 0 0;
}
.price-column .price-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 6px 8px 8px;
}
.price-column .price-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1px;
  font-size: 12px;
}
.price-meta {
  display: flex;
  align-items: center;
  gap: 4px;
}
.price-meta input {
  flex: 0 0 72px;
  width: 72px;
  min-width: 72px;
  max-width: 72px;
  height: 26px;
  font-size: 12px;
  padding: 0 6px;
  border: 1px solid #16325f;
}
.price-meta .unit {
  flex: none;
  white-space: nowrap;
  font-size: 11px;
}
.price-empty { margin: 8px 10px; text-align: left; }
.history-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}
.history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7f9fc;
}
.history-row strong { font-size: 14px; }
.history-row .fine { margin: 4px 0 0; }
.history-row .actions { flex: none; display: flex; margin-top: 0; }
.history-empty { margin-top: 12px; text-align: left; }
.settings-foot { flex: none; margin-top: 8px; }
.settings-foot .actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  margin-top: 0;
}
.settings-save-note {
  margin: 0;
  align-self: center;
  white-space: nowrap;
  line-height: 32px;
  color: var(--accent);
  font-size: 13px;
}
.settings-save-note.is-error { color: var(--danger); }
.settings-save-note:empty { display: none; }
.settings-foot .fine { margin-top: 6px; text-align: left; }
.settings-foot .errors { margin-top: 8px; }

.consult-line { margin-top: 10px; text-align: center; font-size: 12px; }
.consult-line a { color: var(--accent); }
.fine, .local-note { margin-top: 8px; text-align: center; font-size: 12px; }
.settings-foot .fine,
.price-column .price-empty { text-align: left; }

/* 与官网「项目咨询」同结构的本地弹窗（独立打开概算页时使用） */
.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal .backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 18, 36, 0.45);
}
.modal-card {
  position: relative;
  z-index: 1;
  width: min(480px, 100%);
  padding: 22px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}
.modal-card h3 { margin: 0 0 6px; font-size: 20px; }
.modal-card .lead { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.modal-card .field { display: grid; gap: 4px; margin-bottom: 10px; }
.modal-card .field > .text,
.modal-card textarea.text {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--input);
  border-radius: 6px;
  font: inherit;
  resize: vertical;
}
.modal-card .form-error { min-height: 1.2em; margin: 0 0 8px; color: var(--danger); font-size: 12px; }
.modal-card .btn-block { width: 100%; }
.modal-card .success p { margin: 8px 0 14px; color: var(--muted); font-size: 13px; }
.modal-card .success a { color: var(--accent); }
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: #f3f6fb;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
body.modal-open { overflow: hidden; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Homepage / library embed: hug content, no tall empty flex regions */
body.pane {
  height: auto;
  overflow: hidden;
  background: var(--bg);
}
body.pane .page {
  width: 100%;
  max-width: none;
  height: auto;
  margin: 0;
  padding: 8px;
  display: block;
  overflow: visible;
}
body.pane .workspace {
  margin-top: 6px;
  align-items: stretch;
}
body.pane #estimate-form {
  height: auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}
body.pane #compute {
  flex: 1;
  min-height: 0;
  height: auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body.pane #system-scroll {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
}
body.pane .compute-foot {
  margin-top: auto;
  flex: none;
}
body.pane .summary {
  position: static;
  height: auto;
  min-height: 100%;
  align-self: stretch;
}
body.pane .summary-body {
  flex: 1;
  min-height: 0;
}
body.pane .picked-scroll { flex: 1 1 auto; }
body.pane .consult-line,
body.pane .local-note { display: none; }

@media (min-width: 1101px) {
  html, body { height: 100%; overflow: auto; }
  .page {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: auto;
    padding-bottom: 8px;
  }
  .workspace {
    flex: 1;
    min-height: 0;
    grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
  }
  #estimate-form {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  #compute {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  #compute .basics-grid { flex: none; }
  #system-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }
  #form-errors { flex: none; }
  .summary { position: static; height: 100%; min-height: 0; }
  .compute-foot { flex: none; }

  body.pane,
  body.pane .page {
    height: auto;
    overflow: visible;
  }
  body.pane .page { display: block; padding-bottom: 8px; }
  body.pane .workspace {
    flex: none;
    min-height: 0;
    grid-template-rows: auto;
    align-items: stretch;
  }
  body.pane #estimate-form {
    height: auto;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    overflow: visible;
  }
  body.pane #compute {
    flex: 1;
    height: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  body.pane #system-scroll {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
  }
  body.pane .compute-foot { margin-top: auto; }
  body.pane .summary {
    height: auto;
    min-height: 100%;
  }
}

@media (max-width: 1100px) {
  .top { display: block; }
  .workspace { grid-template-columns: 1fr; }
  .summary { position: static; height: auto; min-height: 0; overflow: visible; }
  .summary-body { display: block; }
  .picked-scroll { max-height: 220px; }
  .basics-grid { grid-template-columns: 1fr 1fr; }
  .system-columns { display: none; }
  .system { grid-template-columns: 1fr; }
  #system-scroll { max-height: 420px; overflow-y: auto; }
  .tier .choices { width: 100%; }
  .tier .choice { flex: 1; justify-content: center; }
}

@media (max-width: 720px) {
  .page { width: min(100% - 12px, 1440px); }
  .basics-grid { grid-template-columns: 1fr; }
  .summary-amount, .summary-message { font-size: 20px; }
  .button, a.button { width: 100%; }
  .add-system { width: 124px; }
  .result-actions { grid-template-columns: 1fr; }
  .result-actions .primary,
  .result-actions .save-note { grid-column: auto; }
  .settings-page .button { width: auto; }
  .settings-foot .actions { display: flex; }
  .history-row { align-items: stretch; flex-direction: column; }
}
