:root {
  --bg: #f4f6f7;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #667085;
  --line: #d8dde3;
  --accent: #176b5f;
  --accent-strong: #0e4f46;
  --warn: #a14d2a;
  --soft: #e8f3f0;
  --soft-warn: #f4ede8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Arial, "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

.app-shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 4px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
  line-height: 1.35;
}

.app-header p,
.section-head span,
.summary-cell span,
.score-strip span {
  color: var(--muted);
  line-height: 1.55;
}

.header-actions,
.inline-actions,
.tabs,
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

button:hover,
.tab.is-active {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--soft);
}

.tabs {
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.tab {
  margin-bottom: -1px;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: grid;
  gap: 14px;
}

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

.summary-cell,
.content-band,
.stock-list,
.edge-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.summary-cell {
  display: grid;
  gap: 6px;
  padding: 14px;
}

.summary-cell strong {
  font-size: 22px;
}

.content-band {
  padding: 16px;
}

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

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 2060px;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--accent-strong);
  background: var(--soft);
  font-size: 13px;
}

.badge.warn {
  color: var(--warn);
  background: var(--soft-warn);
}

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

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

label,
.compact-form {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 14px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fff;
  font-weight: 400;
  line-height: 1.5;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--soft);
  border-color: var(--accent);
}

.edge-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 14px;
}

.stock-list,
.edge-editor {
  padding: 16px;
}

#stockList {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.stock-button {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 54px;
  text-align: left;
}

.stock-button.is-active {
  border-color: var(--accent);
  background: var(--soft);
}

.compact-form {
  margin-top: 14px;
}

.inline-form {
  align-items: center;
}

.inline-form input {
  width: 260px;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.score-strip div {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.score-strip strong {
  font-size: 18px;
}

.wide,
.form-subhead {
  grid-column: 1 / -1;
}

.form-subhead {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--accent-strong);
  font-weight: 700;
}

.large-input {
  min-height: 420px;
}

.compact-large-input {
  min-height: 180px;
}

.ai-draft-panel {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.ai-draft-panel pre {
  margin-top: 10px;
  min-height: 140px;
}

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

.ai-help-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.ai-help-strip div,
.ai-status {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.ai-help-strip span,
.ai-status {
  color: var(--muted);
  line-height: 1.45;
}

.ai-help-strip strong {
  display: block;
  margin-bottom: 4px;
}

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

.ai-status.warn {
  color: var(--warn);
  background: var(--soft-warn);
}

.ai-mode-control {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.ai-mode-control label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
  cursor: pointer;
}

.is-hidden {
  display: none !important;
}

.ai-import-card {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.ai-import-card .section-head {
  margin-bottom: 0;
}

.ai-import-card pre {
  min-height: 180px;
}

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

.prompt-input {
  min-height: 280px;
  background: #f8fafb;
}

pre {
  overflow: auto;
  min-height: 180px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
  white-space: pre-wrap;
}

.version-list {
  display: grid;
  gap: 10px;
}

.sector-list {
  display: grid;
  gap: 10px;
}

.sector-workbench {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 14px;
}

.sector-button {
  display: grid;
  gap: 5px;
  width: 100%;
  min-height: 78px;
  text-align: left;
}

.sector-button.is-active {
  border-color: var(--accent);
  background: var(--soft);
}

.sector-button small {
  color: var(--muted);
  line-height: 1.45;
}

.constraint-cell {
  min-width: 520px;
  max-width: 640px;
  white-space: normal;
  line-height: 1.45;
}

.decision-summary {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
}

.decision-summary span,
.dimension-row span,
.dimension-row small {
  display: block;
  color: var(--muted);
}

.dimension-stack {
  display: grid;
  gap: 6px;
}

.dimension-row {
  display: grid;
  gap: 3px;
  padding: 7px 8px;
  border-left: 3px solid var(--line);
  background: #f8fafb;
}

.dimension-row.support {
  border-left-color: var(--accent);
  background: var(--soft);
}

.dimension-row.caution {
  border-left-color: #b7791f;
  background: #fff8e8;
}

.dimension-row.block {
  border-left-color: var(--warn);
  background: var(--soft-warn);
}

.dimension-row strong,
.dimension-row small {
  font-size: 12px;
}

.dimension-row span {
  font-size: 13px;
}

.number-input {
  width: 110px;
}

.date-input {
  width: 148px;
}

.mini-input {
  margin-top: 6px;
  min-width: 150px;
}

.row-actions {
  min-width: 96px;
  white-space: normal;
}

.row-actions button {
  display: block;
  width: 100%;
  margin-bottom: 6px;
}

tr.is-closed {
  color: var(--muted);
  background: #fafbfc;
}

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

.version-panel {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.version-row {
  display: grid;
  grid-template-columns: 180px 180px minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.sector-row {
  grid-template-columns: 180px 220px minmax(0, 1fr);
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 420px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.16);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

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

@media (max-width: 980px) {
  .app-header,
  .section-head,
  .edge-layout,
  .summary-grid,
  .form-grid,
  .editor-grid,
  .ai-help-strip,
  .ai-import-grid,
  .prompt-builder-grid,
  .score-strip {
    grid-template-columns: 1fr;
    display: grid;
  }

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