:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-soft: #f9faf7;
  --ink: #1f2523;
  --muted: #68716d;
  --line: #d9ded7;
  --green: #126f5a;
  --green-strong: #0c5a49;
  --amber: #b36b00;
  --rose: #b9415a;
  --blue: #2f6f9f;
  --shadow: 0 16px 36px rgba(45, 47, 43, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #24312c;
  color: #f8fbf8;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #d6f1df;
  color: #17352c;
  font-weight: 800;
}

.brand-title {
  font-size: 16px;
  font-weight: 800;
}

.brand-subtitle {
  color: #c6d0cb;
  font-size: 12px;
  margin-top: 3px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab,
.primary-button,
.secondary-button,
.icon-button,
.segment,
.quick-questions button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.nav-tab {
  justify-content: flex-start;
  color: #dfe7e2;
  background: transparent;
  padding: 10px 12px;
}

.nav-tab.active,
.nav-tab:hover {
  background: #34453e;
  color: #ffffff;
}

.nav-tab svg,
.primary-button svg,
.secondary-button svg,
.icon-button svg,
.compliance-list svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.sidebar-note {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.note-title {
  font-weight: 800;
  margin-bottom: 6px;
}

.sidebar-note p {
  margin: 0;
  color: #d7dfdb;
  font-size: 13px;
  line-height: 1.7;
}

.main-area {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 26px;
}

.topbar p,
.panel-header p {
  color: var(--muted);
  margin: 6px 0 0;
  line-height: 1.6;
}

.topbar-actions,
.form-actions,
.library-actions,
.dialog-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.primary-button {
  background: var(--green);
  color: white;
  padding: 0 16px;
  border-color: var(--green);
  font-weight: 700;
}

.primary-button:hover {
  background: var(--green-strong);
}

.secondary-button {
  background: #ffffff;
  color: var(--ink);
  padding: 0 14px;
  border-color: var(--line);
}

.secondary-button:hover,
.icon-button:hover,
.quick-questions button:hover {
  border-color: #9eb0a6;
  background: #f3f7f4;
}

.icon-button {
  width: 42px;
  height: 40px;
  background: #ffffff;
  border-color: var(--line);
  color: var(--ink);
}

.tab-panel {
  display: none;
}

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

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.92fr) minmax(330px, 1.12fr) minmax(280px, 0.86fr);
  gap: 14px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.form-panel,
.results-panel,
.advisor-panel,
.product-library,
.compliance-grid .panel {
  padding: 18px;
}

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

.panel h2,
.panel-header h2 {
  margin: 0;
  font-size: 17px;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  background: var(--surface-soft);
  margin-bottom: 16px;
}

.segment {
  background: transparent;
  min-height: 36px;
  font-weight: 700;
  color: var(--muted);
}

.segment.active {
  background: #ffffff;
  color: var(--green);
  border-color: var(--line);
  box-shadow: 0 4px 12px rgba(32, 52, 43, 0.08);
}

.customer-form,
.product-form {
  display: grid;
  gap: 12px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: #38413d;
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 11px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(18, 111, 90, 0.12);
}

.hidden {
  display: none !important;
}

.switch-grid {
  display: grid;
  gap: 8px;
}

.check-row {
  grid-template-columns: 18px 1fr;
  align-items: center;
  min-height: 36px;
  font-weight: 600;
  color: #38413d;
}

.check-row input {
  min-height: auto;
  width: 16px;
  height: 16px;
}

.form-actions {
  justify-content: flex-end;
  padding-top: 4px;
}

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

.metric-strip div {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
}

.metric-strip span {
  display: block;
  font-size: 22px;
  font-weight: 800;
}

.metric-strip small {
  color: var(--muted);
}

.decision-brief {
  border: 1px solid #bdd7ca;
  border-radius: 8px;
  background: #eef7f1;
  padding: 13px;
  margin-bottom: 14px;
}

.decision-brief strong {
  font-size: 14px;
}

.decision-brief p {
  margin: 5px 0 0;
  color: #38413d;
  line-height: 1.6;
  font-size: 13px;
}

.empty-brief {
  background: var(--surface-soft);
  border-color: var(--line);
}

.brief-danger {
  background: #fff1f3;
  border-color: #f0bbc6;
}

.brief-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.brief-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.5fr 1.35fr;
  gap: 9px;
  margin-top: 10px;
}

.brief-grid div {
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(18, 111, 90, 0.14);
  border-radius: 8px;
  padding: 9px;
}

.brief-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.brief-grid b {
  display: block;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
  font-weight: 700;
}

.compliance-line {
  border-top: 1px solid rgba(18, 111, 90, 0.16);
  padding-top: 9px;
}

.results-list {
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 250px);
  overflow: auto;
  padding-right: 4px;
}

.empty-state {
  min-height: 260px;
  place-items: center;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 24px;
}

.empty-state svg {
  width: 40px;
  height: 40px;
  color: var(--green);
}

.match-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
}

.match-card.good {
  border-left-color: var(--green);
}

.match-card.conditional,
.match-card.weak {
  border-left-color: var(--amber);
}

.match-card.blocked {
  border-left-color: var(--rose);
  background: #fffafa;
}

.match-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.match-head h3 {
  margin: 0;
  font-size: 16px;
}

.match-head p {
  color: var(--muted);
  margin: 4px 0 0;
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  border: 1px solid transparent;
}

.badge.good {
  background: #e3f5ec;
  color: var(--green-strong);
  border-color: #bde2cf;
}

.badge.warn {
  background: #fff3dc;
  color: var(--amber);
  border-color: #f3d8a6;
}

.badge.bad {
  background: #fde8ed;
  color: var(--rose);
  border-color: #f4bbc7;
}

.score-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  margin: 12px 0;
}

.scorebar {
  height: 9px;
  background: #edf0ec;
  border-radius: 999px;
  overflow: hidden;
}

.scorebar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.score-number {
  font-weight: 800;
}

.match-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.pill {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 8px;
  font-size: 12px;
  color: #3d4641;
}

.action-block {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: start;
  background: #f8faf7;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  margin-bottom: 11px;
  font-size: 13px;
  line-height: 1.6;
}

.action-block strong {
  color: var(--green-strong);
  white-space: nowrap;
}

.action-block span {
  color: #3d4641;
}

.match-details {
  display: grid;
  gap: 8px;
}

.detail-block strong {
  display: block;
  font-size: 13px;
  margin-bottom: 4px;
}

.detail-block ul {
  margin: 0;
  padding-left: 18px;
  color: #4a534f;
  line-height: 1.6;
  font-size: 13px;
}

.quick-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.quick-questions button {
  background: var(--surface-soft);
  border-color: var(--line);
  min-height: 34px;
  padding: 0 10px;
  color: #33413b;
  font-size: 12px;
}

.chat-log {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 294px);
  min-height: 330px;
  overflow: auto;
  padding-right: 4px;
}

.assistant-msg,
.user-msg {
  border-radius: 8px;
  padding: 11px 12px;
  line-height: 1.7;
  font-size: 13px;
}

.assistant-msg {
  background: #f2f7f4;
  border: 1px solid #d7e5dd;
}

.user-msg {
  background: #eef4f8;
  border: 1px solid #cfdeea;
}

.advisor-form {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
  margin-top: 12px;
}

.send-button {
  background: var(--green);
  color: #ffffff;
  border-color: var(--green);
}

.product-table-wrap {
  overflow: auto;
}

.product-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.product-table th,
.product-table td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  vertical-align: top;
  line-height: 1.5;
}

.product-table th {
  color: var(--muted);
  font-size: 12px;
  background: var(--surface-soft);
}

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

.text-button {
  border: 0;
  background: transparent;
  color: var(--green);
  padding: 0;
  font-weight: 800;
}

.text-danger {
  color: var(--rose);
}

.compliance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.compliance-list {
  display: grid;
  gap: 12px;
  padding: 0;
  margin: 16px 0 0;
  list-style: none;
}

.compliance-list li {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  align-items: start;
  line-height: 1.7;
  color: #3c4742;
}

.compliance-list svg {
  color: var(--green);
  margin-top: 3px;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  width: min(680px, calc(100vw - 28px));
  box-shadow: 0 24px 70px rgba(31, 37, 35, 0.24);
}

dialog::backdrop {
  background: rgba(31, 37, 35, 0.38);
}

.product-form {
  padding: 18px;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 18px;
}

.dialog-actions {
  justify-content: flex-end;
  margin: 4px 0 0;
  padding: 0;
}

@media (max-width: 1120px) {
  .workspace-grid {
    grid-template-columns: 1fr 1fr;
  }

  .advisor-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    padding: 16px;
  }

  .nav-tabs {
    grid-template-columns: repeat(3, 1fr);
  }

  .sidebar-note {
    display: none;
  }

  .main-area {
    padding: 16px;
  }

  .topbar,
  .panel-header,
  .match-head {
    align-items: stretch;
    flex-direction: column;
  }

  .brief-grid {
    grid-template-columns: 1fr;
  }

  .workspace-grid,
  .compliance-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .field-row,
  .metric-strip {
    grid-template-columns: 1fr;
  }

  .nav-tabs {
    grid-template-columns: 1fr;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .form-actions,
  .library-actions,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }
}
