:root {
  --bg: #f4f6f8;
  --ink: #17202a;
  --muted: #6c7785;
  --line: #d9e0e7;
  --panel: #ffffff;
  --brand: #e5412f;
  --brand-dark: #b72e22;
  --green: #1f8f5f;
  --blue: #2764c7;
  --amber: #b66a00;
  --shadow: 0 12px 36px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(229, 65, 47, 0.08) 0 16px, transparent 16px 100%),
    var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

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

button:hover {
  border-color: #aeb8c4;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.workspace {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
  max-width: 1440px;
  margin: 0 auto;
}

.side-panel,
.main-panel,
.panel,
.metrics article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.side-panel {
  padding: 20px;
  align-self: start;
  position: sticky;
  top: 24px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 22px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 16px;
}

.brand p,
label span,
.metrics span {
  color: var(--muted);
  font-size: 13px;
}

.stack {
  display: grid;
  gap: 12px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

input {
  height: 40px;
  padding: 0 10px;
}

textarea {
  min-height: 220px;
  resize: vertical;
  padding: 12px;
  line-height: 1.65;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.actions button:first-child {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.save-status {
  min-height: 20px;
  margin-top: 10px;
  color: var(--green);
  font-size: 13px;
}

.main-panel {
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

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

.tab.is-active,
.top-actions button:last-child,
#addProductBtn {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.view {
  display: none;
  padding: 18px;
}

.view.is-visible {
  display: block;
}

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

.metrics article {
  padding: 16px;
  box-shadow: none;
}

.metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1;
}

.split,
.script-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.panel {
  padding: 16px;
  box-shadow: none;
}

.panel h2 {
  margin-bottom: 12px;
}

.insight-list,
.action-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.insight-list li,
.action-list li {
  border-left: 4px solid var(--blue);
  background: #f7f9fc;
  padding: 10px 12px;
  border-radius: 6px;
  line-height: 1.5;
}

.action-list li {
  border-left-color: var(--green);
}

#report {
  min-height: 260px;
}

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

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

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  background: #fff;
}

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

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

.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 13px;
  font-weight: 700;
}

.sort-btn::after {
  content: "";
  width: 1em;
  color: var(--brand);
}

.sort-btn.is-active[data-direction="asc"]::after {
  content: "↑";
}

.sort-btn.is-active[data-direction="desc"]::after {
  content: "↓";
}

td input {
  min-width: 86px;
}

td:first-child input {
  min-width: 180px;
}

.score-good {
  color: var(--green);
  font-weight: 700;
}

.score-mid {
  color: var(--amber);
  font-weight: 700;
}

.score-low {
  color: var(--brand-dark);
  font-weight: 700;
}

.remove-btn {
  width: 34px;
  min-height: 34px;
  padding: 0;
}

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

.history-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.history-item strong,
.history-item span {
  display: block;
}

.history-item span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

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

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

@media (max-width: 980px) {
  .app-shell {
    padding: 12px;
  }

  .workspace,
  .split,
  .script-grid,
  .metrics {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
  }

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

  .history-item {
    align-items: stretch;
    flex-direction: column;
  }

  .history-actions {
    justify-content: flex-start;
  }
}
