:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --text: #172025;
  --muted: #68747d;
  --line: #dce3e8;
  --primary: #176a5b;
  --primary-dark: #104d42;
  --blue: #2d5f9a;
  --amber: #986d12;
  --red: #a33a35;
  --green-soft: #e9f6f2;
  --blue-soft: #eaf1fb;
  --amber-soft: #fff4d7;
  --red-soft: #fff0ef;
  --shadow: 0 10px 28px rgba(25, 40, 52, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

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

button {
  border: 0;
}

.hidden {
  display: none !important;
}

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

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 8px 0 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.9rem, 4vw, 3.2rem);
  line-height: 1.05;
}

h2 {
  margin-bottom: 0;
  font-size: 1.12rem;
}

h3 {
  font-size: 1rem;
}

.role-switch,
.filter-row,
.composer-actions,
.admin-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.role-switch {
  padding: 4px;
  background: #e9eef2;
  border-radius: var(--radius);
}

.role-btn,
.ghost-btn,
.primary-btn,
.mini-btn {
  min-height: 38px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 800;
  transition: background-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.role-btn {
  padding: 0 14px;
  color: #56636c;
  background: transparent;
}

.role-btn.active {
  color: #ffffff;
  background: var(--text);
}

.primary-btn {
  padding: 0 16px;
  color: #ffffff;
  background: var(--primary);
}

.primary-btn:hover {
  background: var(--primary-dark);
}

.ghost-btn,
.mini-btn {
  padding: 0 12px;
  color: #26343c;
  background: #edf2f4;
}

.ghost-btn:hover,
.mini-btn:hover {
  background: #dfe8ec;
}

.primary-btn:active,
.ghost-btn:active,
.mini-btn:active,
.role-btn:active {
  transform: translateY(1px);
}

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

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-panel,
.search-panel,
.match-panel,
.answer-panel,
.weekly-panel,
.gap-panel,
.admin-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-panel {
  min-height: 88px;
  padding: 16px;
  display: grid;
  align-content: space-between;
}

.metric-panel span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.metric-panel strong {
  font-size: 2rem;
  line-height: 1;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(340px, 1fr) minmax(420px, 1.2fr);
  gap: 16px;
  align-items: start;
}

.search-panel,
.match-panel,
.answer-panel,
.weekly-panel,
.gap-panel,
.admin-panel {
  padding: 18px;
}

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

.search-box,
.question-box {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.search-box span,
.question-box span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: #ffffff;
  outline: none;
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  min-height: 112px;
  padding: 12px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 106, 91, 0.14);
}

.product-list {
  display: grid;
  gap: 8px;
  max-height: 540px;
  overflow: auto;
  padding-right: 2px;
}

.product-row {
  width: 100%;
  min-height: 76px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface-soft);
  cursor: pointer;
}

.product-row strong,
.product-row small,
.product-row em {
  display: block;
}

.product-row strong {
  line-height: 1.35;
}

.product-row small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.78rem;
}

.product-row em {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--primary);
  background: var(--green-soft);
  font-size: 0.74rem;
  font-style: normal;
  font-weight: 800;
}

.product-row.active {
  border-color: var(--primary);
  background: #f0faf7;
}

.sku-pill {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--blue);
  background: var(--blue-soft);
  font-size: 0.78rem;
  font-weight: 900;
}

.product-detail {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

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

.detail-title h3 {
  margin: 0;
  line-height: 1.35;
}

.detail-title span {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--amber);
  background: var(--amber-soft);
  font-size: 0.74rem;
  font-weight: 900;
}

dl {
  margin: 0;
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 9px 12px;
  font-size: 0.9rem;
}

dt {
  color: var(--muted);
  font-weight: 800;
}

dd {
  margin: 0;
  line-height: 1.55;
}

.composer-actions {
  margin-bottom: 12px;
}

.match-grid {
  display: grid;
  gap: 10px;
}

.match-grid .question-box {
  margin-bottom: 0;
}

.match-grid textarea {
  min-height: 92px;
}

.match-results {
  display: grid;
  gap: 10px;
}

.match-card {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.match-score {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  align-content: center;
  border-radius: var(--radius);
  color: #ffffff;
  background: var(--primary);
}

.match-score strong {
  line-height: 1;
  font-size: 1.15rem;
}

.match-score span {
  font-size: 0.68rem;
  font-weight: 800;
}

.match-main h3 {
  margin: 0;
  line-height: 1.35;
  font-size: 0.95rem;
}

.match-main p {
  margin: 4px 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.match-reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.match-reasons span {
  padding: 3px 7px;
  border-radius: 999px;
  color: var(--blue);
  background: var(--blue-soft);
  font-size: 0.72rem;
  font-weight: 800;
}

.answer-card {
  min-height: 148px;
  padding: 16px;
  border: 1px solid #c7ddd6;
  border-radius: var(--radius);
  background: #f2fbf8;
  line-height: 1.7;
  white-space: pre-wrap;
}

.answer-card.muted-state {
  display: grid;
  place-items: center;
  color: var(--muted);
  border-color: var(--line);
  background: var(--surface-soft);
  text-align: center;
}

.answer-card.warning-state {
  border-color: #efc06a;
  background: #fffaf0;
}

.answer-text {
  font-weight: 650;
}

.evidence-box {
  margin-top: 12px;
  padding: 10px 12px;
  display: grid;
  gap: 5px;
  border-left: 3px solid var(--primary);
  background: rgba(255, 255, 255, 0.62);
  font-size: 0.86rem;
  white-space: normal;
}

.evidence-box span {
  color: var(--muted);
}

.risk-note {
  margin-top: 10px;
  color: var(--amber);
  font-size: 0.86rem;
  font-weight: 800;
}

.insights-grid {
  display: grid;
  grid-template-columns: minmax(440px, 1.25fr) minmax(320px, 0.75fr);
  gap: 16px;
  margin-top: 16px;
}

.weekly-report,
.gap-list {
  display: grid;
  gap: 10px;
}

.report-row {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.report-rank {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: #ffffff;
  background: var(--blue);
  font-weight: 900;
}

.report-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.report-title span,
.report-main p,
.gap-item small {
  color: var(--muted);
  font-size: 0.82rem;
}

.report-main p {
  margin: 8px 0 0;
}

.bar-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e3e9ed;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--blue));
}

.gap-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.gap-item p {
  margin: 4px 0 5px;
  line-height: 1.45;
}

.gap-item.resolved {
  opacity: 0.62;
}

.gap-item .mini-btn {
  flex: 0 0 auto;
}

.admin-panel {
  margin-top: 16px;
}

.product-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 10px;
}

.product-form textarea {
  grid-column: span 2;
}

.product-form button {
  min-height: 42px;
}

.empty-state {
  min-height: 88px;
  display: grid;
  place-items: center;
  border: 1px dashed #c9d3d9;
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface-soft);
  text-align: center;
  padding: 12px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: var(--radius);
  color: #ffffff;
  background: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

body[data-role="external"] .answer-panel dl dt:nth-of-type(n + 7),
body[data-role="external"] .answer-panel dl dd:nth-of-type(n + 7) {
  display: none;
}

@media (max-width: 1040px) {
  .workbench,
  .insights-grid {
    grid-template-columns: 1fr;
  }

  .product-list {
    max-height: 360px;
  }

  .product-form {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100vw - 20px, 680px);
    padding-top: 14px;
  }

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

  .role-switch {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .role-btn {
    padding: 0 8px;
  }

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

  .search-panel,
  .answer-panel,
  .weekly-panel,
  .gap-panel,
  .admin-panel {
    padding: 14px;
  }

  .section-head,
  .report-title,
  .gap-item,
  .match-card {
    align-items: stretch;
    flex-direction: column;
  }

  .match-card {
    display: flex;
  }

  dl {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  dd {
    margin-bottom: 8px;
  }

  .product-form textarea {
    grid-column: 1 / -1;
  }
}

@media (max-width: 460px) {
  .summary-grid,
  .product-form {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 2rem;
  }
}
