:root {
  color-scheme: light;
  --bg: #f8f6f2;
  --surface: #ffffff;
  --surface-2: #fff7ed;
  --ink: #1f1b16;
  --muted: #746b60;
  --line: #e3d8cc;
  --accent: #c2410c;
  --accent-dark: #9a3412;
  --amber: #d97706;
  --green: #15803d;
  --red: #b91c1c;
  --blue: #2563eb;
  --shadow: 0 16px 44px rgba(49, 30, 15, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family:
    Inter, "Segoe UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 18px 28px;
  background: rgba(248, 246, 242, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.topbar h1,
.section-title h2,
.block h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 24px;
  line-height: 1.12;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(49, 30, 15, 0.08);
}

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

.text-button {
  min-height: 40px;
  padding: 9px 14px;
  color: var(--surface);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  font-weight: 900;
}

.text-button:hover {
  background: var(--accent-dark);
}

.shell {
  max-width: 1460px;
  margin: 0 auto;
  padding: 22px 28px 48px;
}

.tabs {
  position: sticky;
  top: 77px;
  z-index: 15;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px;
  margin-bottom: 16px;
  background: rgba(248, 246, 242, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(14px);
}

.tab {
  min-width: 84px;
  padding: 9px 14px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 900;
  white-space: nowrap;
}

.tab.is-active {
  color: var(--surface);
  background: var(--accent);
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.section-title h2 {
  font-size: 22px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  color: var(--accent);
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.status-pill.good {
  color: var(--green);
  background: #eef9f0;
  border-color: #bbebc9;
}

.status-pill.warn {
  color: var(--amber);
  background: #fffbeb;
  border-color: #fde68a;
}

.status-pill.bad {
  color: var(--red);
  background: #fef2f2;
  border-color: #fecaca;
}

.status-pill.neutral {
  color: var(--muted);
  background: #f4f0eb;
  border-color: var(--line);
}

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

.metric-grid.short {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 12px;
}

.metric,
.block,
.note-block,
.slot-row,
.audit-card,
.collapse-card,
.export-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(49, 30, 15, 0.06);
}

.metric {
  min-height: 116px;
  padding: 16px;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
}

.metric span {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 900;
}

.metric strong {
  display: block;
  margin-bottom: 4px;
  font-size: 28px;
  line-height: 1.08;
}

.metric small {
  font-size: 12px;
}

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

.block,
.note-block {
  padding: 16px;
}

.block h3 {
  margin-bottom: 12px;
  font-size: 16px;
}

.muted {
  margin: 0;
  color: var(--muted);
}

.signal-list,
.audit-card ul {
  margin: 0;
  padding-left: 18px;
}

.signal-list li,
.audit-card li {
  margin-bottom: 8px;
}

.formula-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.formula-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.formula-list div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.formula-list dt {
  color: var(--muted);
  font-weight: 900;
}

.formula-list dd {
  margin: 0;
  font-weight: 900;
  text-align: right;
}

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

.input-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 14px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 900;
}

input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fffdf9;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(194, 65, 12, 0.13);
}

.sales-editor {
  display: grid;
  gap: 10px;
}

.slot-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) 140px 150px 150px 42px;
  gap: 10px;
  align-items: end;
  padding: 12px;
}

.slot-row label {
  padding: 0;
  background: transparent;
  border: 0;
}

.slot-total {
  display: grid;
  gap: 4px;
}

.slot-total strong {
  font-size: 15px;
}

.slot-total small {
  color: var(--muted);
}

.remove-slot {
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: var(--red);
  background: #fff7f4;
  border: 1px solid #fed0c4;
  border-radius: 8px;
  font-weight: 900;
}

.note-block {
  margin-top: 12px;
  border-left: 4px solid var(--accent);
}

.note-block h3 {
  margin: 0 0 8px;
}

.note-block p {
  margin: 0;
  color: var(--muted);
}

.accordion-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.collapse-card {
  overflow: hidden;
}

.collapse-card summary {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  list-style: none;
  font-weight: 900;
}

.collapse-card summary::-webkit-details-marker {
  display: none;
}

.collapse-card summary::after {
  content: "+";
  display: inline-grid;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  place-items: center;
  color: var(--accent);
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 999px;
  font-weight: 900;
}

.collapse-card[open] summary {
  border-bottom: 1px solid var(--line);
}

.collapse-card[open] summary::after {
  content: "-";
}

.summary-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-name small {
  color: var(--muted);
  font-weight: 800;
}

.collapse-body {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.badge-row,
.link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.info-badge {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  padding: 4px 8px;
  color: var(--accent-dark);
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.source-link {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  padding: 6px 10px;
  color: var(--accent-dark);
  background: #fffdf9;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 900;
  text-decoration: none;
}

.source-link:hover {
  color: var(--surface);
  background: var(--accent);
  border-color: var(--accent);
}

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

.info-box {
  min-width: 0;
  padding: 12px;
  background: #fffdf9;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.info-box span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.info-box strong,
.info-box p {
  margin: 0;
}

.info-box p,
.step-list li,
.recipe-note {
  color: var(--muted);
}

.step-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
}

.recipe-note {
  margin: 0;
}

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

.ingredient-card {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
  padding: 10px;
  background: #fffdf9;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.material-thumb {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  color: var(--surface);
  background: linear-gradient(135deg, var(--accent), var(--amber));
  border-radius: 8px;
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.ingredient-card h4 {
  margin: 0 0 4px;
  font-size: 14px;
}

.ingredient-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.ingredient-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.ingredient-meta span,
.ingredient-meta a {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 3px 7px;
  color: var(--muted);
  background: #f4f0eb;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
  text-decoration: none;
}

.ingredient-meta a {
  color: var(--accent-dark);
  background: #fff7ed;
  border-color: #fed7aa;
}

.scenario-table {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(49, 30, 15, 0.06);
}

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

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: right;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--muted);
  background: #fff7ed;
  font-size: 12px;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

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

.audit-card {
  padding: 16px;
}

.audit-card h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.audit-card p {
  margin: 0 0 10px;
  color: var(--muted);
}

.export-dialog {
  width: min(940px, calc(100vw - 32px));
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
}

.export-dialog::backdrop {
  background: rgba(31, 27, 22, 0.42);
}

.export-box {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.export-box header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.export-box h2 {
  margin: 0;
}

#exportText {
  width: 100%;
  min-height: 430px;
  resize: vertical;
  padding: 12px;
  color: var(--ink);
  background: #fffdf9;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
}

.export-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 1100px) {
  .metric-grid,
  .metric-grid.short,
  .split,
  .input-grid,
  .input-grid.compact,
  .info-grid,
  .ingredient-grid,
  .audit-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

  .shell {
    padding: 16px;
  }

  .metric-grid,
  .metric-grid.short,
  .split,
  .input-grid,
  .input-grid.compact,
  .info-grid,
  .ingredient-grid,
  .audit-grid,
  .slot-row {
    grid-template-columns: 1fr;
  }

  .tabs {
    top: 72px;
  }

  .section-title {
    display: grid;
  }

  .remove-slot {
    width: 100%;
  }
}

@media print {
  .topbar,
  .tabs {
    position: static;
  }

  .top-actions,
  .tabs {
    display: none;
  }

  .tab-panel {
    display: block;
    margin-bottom: 18px;
  }

  .metric,
  .block,
  .note-block,
  .slot-row,
  .audit-card {
    box-shadow: none;
  }
}
