:root {
  --ink: #18211f;
  --muted: #66736f;
  --line: #dfe7e2;
  --panel: #ffffff;
  --bg: #f5f7f4;
  --green: #176f54;
  --green-soft: #e3f3ec;
  --gold: #9a6a16;
  --red: #b93a37;
  --blue: #245c97;
  --shadow: 0 16px 42px rgba(24, 33, 31, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

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

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

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: 100vh;
  overflow-y: auto;
  padding: 24px 18px;
  color: #eef8f3;
  background: #10231d;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: #10231d;
  background: #b7e1ca;
  font-size: 24px;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 4px;
  color: #adc2b9;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  border: 0;
  border-radius: 7px;
  color: #d9e7e1;
  background: transparent;
  text-align: left;
}

.nav button:hover,
.nav button.active {
  color: #10231d;
  background: #d9f0e4;
}

.nav .nav-icon {
  width: 22px;
  text-align: center;
  font-size: 17px;
}

.wecom-status {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(217, 240, 228, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.wecom-status div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wecom-status p {
  margin: 8px 0 0;
  color: #adc2b9;
  font-size: 12px;
  line-height: 1.6;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #76d39b;
}

.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
  overflow: hidden;
  padding: 26px 30px 38px;
}

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

.eyebrow {
  margin: 0 0 7px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

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

h1 {
  margin-bottom: 0;
  font-size: 30px;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 14px;
  font-size: 20px;
}

h3 {
  margin-bottom: 10px;
  font-size: 16px;
}

.top-actions,
.row-actions,
.filter-row,
.button-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  min-height: 38px;
  border-radius: 7px;
  border: 1px solid transparent;
}

.primary-button {
  padding: 0 15px;
  color: #fff;
  background: var(--green);
}

.secondary-button {
  padding: 0 14px;
  color: var(--green);
  background: var(--green-soft);
  border-color: #bfe1d1;
}

.ghost-button {
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.view {
  flex: 1 1 auto;
  display: grid;
  gap: 18px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-gutter: stable;
}

.view::-webkit-scrollbar,
.sidebar::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar,
.script-list::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

.view::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb,
.script-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #c6d3ce;
}

.grid {
  display: grid;
  gap: 16px;
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.two-col {
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
}

.three-col {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.panel {
  padding: 18px;
}

.card {
  padding: 15px;
}

.stat {
  padding: 16px;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.table-wrap {
  max-height: 44vh;
  overflow: auto;
}

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

th,
td {
  padding: 13px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

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

.tag,
.stage,
.level {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.tag {
  color: #35514b;
  background: #eef4f0;
}

.stage {
  color: var(--blue);
  background: #e5eff8;
}

.level-a {
  color: var(--red);
  background: #fae9e8;
}

.level-b {
  color: var(--gold);
  background: #f7efd9;
}

.level-c {
  color: var(--green);
  background: var(--green-soft);
}

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

.customer-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  min-width: 0;
}

.customer-name {
  font-size: 22px;
  font-weight: 800;
}

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

.meta-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfb;
}

.meta-item span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}

.script-list,
.timeline,
.config-list {
  display: grid;
  gap: 12px;
}

.panel > .script-list,
.panel > .timeline,
.panel > .config-list {
  max-height: 52vh;
  overflow-y: auto;
  padding-right: 4px;
}

.script-body {
  margin: 10px 0 12px;
  color: #33413e;
  line-height: 1.7;
  white-space: pre-line;
}

.timeline-item {
  padding-left: 14px;
  border-left: 3px solid #cce3d8;
}

.timeline-item p {
  margin-bottom: 5px;
  line-height: 1.6;
}

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

.field {
  display: grid;
  gap: 7px;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

.wide {
  grid-column: 1 / -1;
}

.chat-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(340px, 1.05fr);
  gap: 16px;
}

.compact-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
}

.compact-tabs button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  white-space: nowrap;
}

.compact-tabs button.active {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  transform: translateY(16px);
  opacity: 0;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: #10231d;
  box-shadow: var(--shadow);
  transition: 0.2s ease;
  pointer-events: none;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(16, 35, 29, 0.46);
  z-index: 10;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(640px, 100%);
  max-height: min(760px, 86vh);
  overflow-y: auto;
  padding: 18px;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal textarea {
  min-height: 180px;
  margin-top: 12px;
  line-height: 1.7;
}

.modal-form {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.modal-form .button-row {
  justify-content: flex-end;
}

.login-wrap {
  display: grid;
  place-items: center;
  min-height: 100%;
}

.login-panel {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.login-panel .brand-mark {
  margin-bottom: 4px;
}

.login-panel h2 {
  margin-bottom: 0;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: #edf1ef;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.api-list {
  columns: 2;
  padding-left: 18px;
  line-height: 1.9;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-columns: 1fr;
    height: 100vh;
    overflow: hidden;
  }

  .sidebar {
    position: static;
    flex: 0 0 auto;
    height: auto;
    max-height: 34vh;
    overflow-y: auto;
    padding: 16px;
  }

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

  .wecom-status {
    display: none;
  }

  .main {
    height: auto;
    min-height: 0;
    overflow: hidden;
    padding: 20px 16px 30px;
  }

  .view {
    overflow-y: auto;
  }

  .stats-grid,
  .two-col,
  .three-col,
  .chat-layout,
  .form-grid,
  .meta-grid {
    grid-template-columns: 1fr;
  }

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

  .panel,
  .card,
  .customer-head,
  .row-actions,
  .button-row,
  .filter-row {
    max-width: 100%;
    min-width: 0;
  }

  .primary-button,
  .secondary-button,
  .ghost-button {
    max-width: 100%;
    white-space: normal;
  }

  .customer-head > * {
    min-width: 0;
  }

  .api-list {
    columns: 1;
  }
}
