:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #6b7785;
  --line: #e5e8ec;
  --brand: #1f6feb;
  --brand-ink: #ffffff;
  --ok: #1a7f4b;
  --warn: #9a6700;
  --bad: #b42318;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100vh; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { font-size: 18px; letter-spacing: .2px; }
.brand p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(135deg, #1f6feb, #39c0a0);
  box-shadow: 0 0 0 6px rgba(31, 111, 235, .12);
}

.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.badge {
  font-size: 12px; padding: 5px 9px; border-radius: 999px;
  background: #eef2ff; color: #3538cd; border: 1px solid #dfe3ff;
}
.badge.ok { background: #f1fbf5; color: var(--ok); border-color: #c7ead7; }
.badge.bad { background: #fff5f4; color: var(--bad); border-color: #f6d0cc; }
.token-field { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.token-field input {
  width: 150px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink);
}

.layout { padding: 22px 28px 40px; max-width: 1500px; margin: 0 auto; }
.summary {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.metric {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; box-shadow: var(--shadow);
}
.metric span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.metric strong { font-size: 24px; font-weight: 650; }

.workspace { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); min-height: 200px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 15px; }
.panel-head p { margin-top: 4px; color: var(--muted); font-size: 12px; }

.store-list { padding: 8px; display: flex; flex-direction: column; gap: 6px; max-height: calc(100vh - 250px); overflow: auto; }
.store-item {
  text-align: left; border: 1px solid transparent; background: transparent; border-radius: 10px;
  padding: 12px; cursor: pointer; width: 100%;
}
.store-item:hover { background: #f7f9fc; }
.store-item.active { background: #f0f6ff; border-color: #cfe0ff; }
.store-item .name { font-weight: 600; font-size: 14px; }
.store-meta { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; color: var(--muted); font-size: 11px; }
.pill {
  padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line); background: #fff;
}
.pill.ok { color: var(--ok); border-color: #c7ead7; background: #f1fbf5; }
.pill.warn { color: var(--warn); border-color: #f3e0b5; background: #fffaf0; }
.pill.bad { color: var(--bad); border-color: #f6d0cc; background: #fff5f4; }

.detail-panel { padding: 0; }
.detail-body { padding: 18px; }
.detail-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.detail-title h2 { font-size: 18px; }
.detail-title p { color: var(--muted); font-size: 12px; margin-top: 6px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.divider { height: 1px; background: var(--line); margin: 18px 0; }
.section h3 { font-size: 14px; margin-bottom: 10px; }
.section .hint { color: var(--muted); font-size: 12px; margin-bottom: 10px; line-height: 1.6; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px;
  background: #fff; color: var(--ink); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: #9dbcf5; box-shadow: 0 0 0 3px rgba(31,111,235,.08); }
.inline-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 8px 12px; cursor: pointer;
  background: #f2f4f7; color: var(--ink); font-size: 13px; white-space: nowrap;
}
.btn:hover { filter: brightness(.98); }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: #fff; border-color: var(--line); }
.btn.danger { background: #fff5f4; color: var(--bad); border-color: #f6d0cc; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.action-list { display: flex; flex-direction: column; gap: 10px; }
.action-card {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fcfcfd;
}
.action-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.action-head strong { font-size: 14px; }
.action-meta { color: var(--muted); font-size: 12px; margin-top: 6px; line-height: 1.6; }
.action-outcome { margin-top: 8px; font-size: 12px; color: var(--ok); }
.action-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.delivery-list { display: flex; flex-direction: column; gap: 10px; }
.delivery {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fcfcfd;
}
.delivery-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.delivery-head strong { font-size: 13px; }
.delivery-meta { color: var(--muted); font-size: 11px; margin-top: 4px; }
.status { font-size: 11px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); }
.status.sent { color: var(--ok); border-color: #c7ead7; background: #f1fbf5; }
.status.failed, .status.dead { color: var(--bad); border-color: #f6d0cc; background: #fff5f4; }
.status.pending { color: var(--warn); border-color: #f3e0b5; background: #fffaf0; }
.pre {
  margin: 10px 0 0; padding: 12px; background: #0f172a; color: #e6edf7; border-radius: 8px;
  font-size: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow: auto;
}
.error-text { color: var(--bad); font-size: 12px; margin-top: 8px; }

.empty { color: var(--muted); text-align: center; padding: 30px 16px; font-size: 13px; }
.empty.big { padding: 100px 20px; }
.empty.big h2 { color: var(--ink); margin-bottom: 8px; }

.modal {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .38);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(620px, 100%); background: #fff; border-radius: 14px; box-shadow: 0 20px 60px rgba(15,23,42,.2);
  padding: 20px;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.modal-head h2 { font-size: 17px; }
.modal-head p { color: var(--muted); font-size: 12px; margin-top: 5px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.form input, .form select, .form textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #fff; color: var(--ink);
}
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.toast {
  position: fixed; right: 22px; bottom: 22px; max-width: 420px;
  background: #17202a; color: #fff; padding: 12px 14px; border-radius: 10px;
  box-shadow: 0 12px 30px rgba(15,23,42,.25); font-size: 13px; z-index: 80;
}
.toast[hidden] { display: none; }
.toast.error { background: #7a271a; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .store-list { max-height: 280px; }
  .grid, .grid.three { grid-template-columns: 1fr; }
  .layout { padding: 16px; }
  .topbar { padding: 14px 16px; }
}
