:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #f1f5f9;
  --ink: #172033;
  --muted: #637083;
  --line: #dce2ea;
  --blue: #2563eb;
  --blue-soft: #e8f0ff;
  --green: #15803d;
  --green-soft: #e7f7ed;
  --red: #b42318;
  --red-soft: #fee4e2;
  --amber: #b45309;
  --amber-soft: #fff4d8;
  --teal: #0f766e;
  --teal-soft: #e2f6f3;
  --shadow: 0 18px 50px rgba(23, 32, 51, 0.12);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 32px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.25;
}

h2 {
  font-size: 17px;
  line-height: 1.35;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.mode-banner {
  display: grid;
  gap: 4px;
  max-width: 520px;
  padding: 12px 14px;
  border: 1px solid #b7c6df;
  border-radius: 8px;
  background: var(--blue-soft);
  color: #173b80;
  font-size: 13px;
}

main {
  padding: 22px 32px 32px;
}

.rule-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.rule-strip span {
  min-height: 56px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  background: var(--surface);
  color: #25344d;
  font-size: 13px;
  line-height: 1.45;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  min-height: 96px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: left;
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  font-size: 25px;
  line-height: 1;
}

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

.stat-card.is-danger {
  border-color: #f2a7a2;
  background: var(--red-soft);
  color: var(--red);
}

.stat-card.is-warning {
  border-color: #f5ce86;
  background: var(--amber-soft);
  color: var(--amber);
}

.filter-band {
  display: grid;
  grid-template-columns: 180px 180px 140px minmax(240px, 1fr);
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.toolbar-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.toolbar-band p,
.compact-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
input,
textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #c8d1dd;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 16px;
  align-items: start;
}

.delivery-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}

.table-panel,
.detail-panel,
.delivery-panel {
  border: 1px solid var(--line);
  background: var(--surface);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.section-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

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

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

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

th {
  background: var(--surface-strong);
  color: #334155;
  font-size: 12px;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody tr.is-overdue {
  background: #fff8f7;
}

tbody tr.is-overdue:hover {
  background: #fff0ee;
}

.item-title {
  display: grid;
  gap: 3px;
}

.item-title small {
  color: var(--muted);
}

.status-pill,
.trigger-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.blue,
.trigger-pill.blue {
  background: var(--blue-soft);
  color: var(--blue);
}

.status-pill.green,
.trigger-pill.green {
  background: var(--green-soft);
  color: var(--green);
}

.status-pill.red,
.trigger-pill.red {
  background: var(--red-soft);
  color: var(--red);
}

.status-pill.amber,
.trigger-pill.amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-pill.teal,
.trigger-pill.teal {
  background: var(--teal-soft);
  color: var(--teal);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.primary-button,
.ghost-button,
.warning-button,
.icon-button {
  min-height: 34px;
  border-radius: 7px;
  border: 1px solid transparent;
  padding: 7px 11px;
  font-weight: 700;
}

.primary-button {
  background: var(--blue);
  color: white;
}

.ghost-button {
  border-color: #c8d1dd;
  background: #fff;
  color: #334155;
}

.warning-button {
  background: var(--amber);
  color: white;
}

.icon-button {
  width: 34px;
  padding: 0;
  border-color: #c8d1dd;
  background: #fff;
  color: #334155;
  font-size: 22px;
  line-height: 1;
}

.detail-panel {
  position: sticky;
  top: 16px;
  min-height: 520px;
}

.empty-state {
  display: grid;
  place-content: center;
  min-height: 520px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.detail-content {
  padding: 16px;
}

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

.detail-block {
  padding: 13px 0;
  border-top: 1px solid var(--line);
}

.detail-block:first-of-type {
  border-top: 0;
}

.detail-block h3 {
  margin: 0 0 9px;
  font-size: 13px;
}

.compact-heading {
  padding: 14px;
}

.kv-grid {
  display: grid;
  grid-template-columns: 116px 1fr;
  gap: 8px 12px;
  font-size: 13px;
}

.kv-grid span:nth-child(odd) {
  color: var(--muted);
}

.timeline {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
  font-size: 13px;
}

.timeline li {
  padding-left: 12px;
  border-left: 3px solid var(--line);
}

.reply-actions {
  margin-top: 10px;
}

.reply-result {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
}

.checklist,
.api-list {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.api-config {
  display: grid;
  gap: 10px;
  padding: 14px 14px 0;
}

.api-config-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.api-config-status {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.check-row,
.api-row {
  display: grid;
  gap: 5px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  font-size: 13px;
}

.check-row strong,
.api-row strong {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.check-row small,
.api-row small {
  color: var(--muted);
  line-height: 1.45;
}

.check-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  min-height: 24px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-weight: 800;
}

.operation-log {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  padding: 14px 14px 14px 34px;
  margin: 0;
  font-size: 13px;
}

.operation-log li {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.operation-log time {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.danger-note {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #f2a7a2;
  border-radius: 8px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 13px;
  line-height: 1.5;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.42);
}

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

.modal {
  width: min(880px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  line-height: 1.55;
}

#messagePreview {
  margin: 16px 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  color: #162033;
  font-size: 13px;
}

.draft-box {
  margin: 0 18px 18px;
  padding: 14px;
  border: 1px dashed #9aa8ba;
  border-radius: 8px;
  background: #f8fafc;
}

.draft-box p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

#draftPreview {
  min-height: 56px;
  margin-top: 12px;
  color: #334155;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 44px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #101828;
  color: white;
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.45;
}

@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

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

  .detail-panel {
    position: static;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 18px;
  }

  main {
    padding: 16px;
  }

  .rule-strip,
  .stats-grid,
  .filter-band,
  .toolbar-band {
    grid-template-columns: 1fr;
  }

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

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .modal-actions {
    flex-direction: column;
  }

  .modal-actions button {
    width: 100%;
  }
}
