:root {
  --ink: #17211f;
  --muted: #687672;
  --line: #dfe5e2;
  --surface: #ffffff;
  --canvas: #f4f8fc;
  --brand: #1979c9;
  --brand-dark: #0b5da2;
  --brand-ink: #082941;
  --brand-soft: #e9f4ff;
  --gold: #b7791f;
  --danger: #c23b3b;
  --shadow: 0 10px 30px rgba(23, 33, 31, .08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}
.hidden { display: none !important; }
button { font: inherit; }
svg { flex: none; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(390px, 41%) 1fr;
  background: var(--surface);
}
.auth-aside {
  position: relative;
  overflow: hidden;
  background: linear-gradient(155deg, #eff8ff 0%, #d9ecff 58%, #c5e1fb 100%);
  color: #0e3959;
  padding: 38px 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.auth-aside::after {
  content: '';
  position: absolute;
  left: -12%;
  right: -12%;
  bottom: -60px;
  height: 120px;
  border-top: 3px solid rgba(31, 133, 210, .2);
  border-radius: 50%;
  box-shadow: 0 -18px 0 rgba(31, 133, 210, .09), 0 -36px 0 rgba(31, 133, 210, .06);
  pointer-events: none;
}
.auth-main { display: grid; place-items: center; padding: 32px; background: #f8fafc; }
.auth-card {
  width: min(438px, 100%);
  background: var(--surface);
  border: 1px solid #e1e9f0;
  border-radius: 12px;
  box-shadow: 0 14px 36px rgba(30, 70, 102, .13);
  padding: 22px;
}
.auth-intro { position: relative; z-index: 1; margin: 56px 0 24px; max-width: 330px; }
.auth-kicker { display: inline-flex; padding: 4px 10px; border: 1px solid rgba(25,121,201,.25); border-radius: 999px; color: var(--brand); background: rgba(255,255,255,.65); font-size: 12px; }
.auth-intro h1 { margin: 16px 0 12px; font-size: clamp(25px, 3vw, 34px); line-height: 1.35; letter-spacing: 0; color: #0b3453; }
.auth-intro p { margin: 0; color: #4d6e86; line-height: 1.8; }
.auth-points { position: relative; z-index: 1; display: grid; gap: 15px; margin-top: 26px; }
.auth-points div { display: flex; align-items: flex-start; gap: 11px; color: #0d73bd; }
.auth-points div > span { display: grid; gap: 3px; }
.auth-points strong { color: #164767; font-size: 13px; }
.auth-points small { color: #63829a; font-size: 11px; font-weight: 400; }
.auth-points svg { width: 20px; color: #1678c3; margin-top: 1px; }
.auth-form { display: grid; gap: 16px; margin-top: 22px; }
.auth-heading { display: grid; gap: 5px; margin: 4px 0 3px; }
.auth-heading h2 { margin: 0; color: #142b3e; font-size: 21px; }
.auth-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  background: #edf2f7;
  border-radius: 7px;
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 5px;
  min-height: 36px;
  cursor: pointer;
}
.segmented button.active { background: #fff; color: var(--brand-dark); box-shadow: 0 1px 3px rgba(36, 83, 119, .14); }

.brand { display: flex; align-items: center; gap: 12px; }
.brand strong { display: block; font-size: 24px; line-height: 1.15; font-weight: 750; }
.brand small { display: block; color: #6c889d; font-size: 12px; margin-top: 2px; }
.brand.large strong { font-size: 28px; }
.brand > div:last-child { min-width: 0; }

.app-shell {
  --canvas: #e6f3fb;
  --ink: #173f5f;
  --muted: #55778d;
  --line: #c9e0ee;
  display: grid;
  grid-template-columns: 252px 1fr;
  min-height: 100vh;
  background: var(--canvas);
}
.sidebar {
  background: var(--canvas);
  color: #173f5f;
  padding: 24px 14px 18px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.side-nav { display: grid; align-content: start; gap: 8px; margin-top: 34px; flex: 0 0 auto; }
.side-nav button {
  display: flex;
  align-items: center;
  gap: 13px;
  min-height: 48px;
  padding: 0 15px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #35657f;
  cursor: pointer;
  text-align: left;
  font-size: 15px;
}
.side-nav button:hover { background: rgba(255,255,255,.72); color: #0f5c92; }
.side-nav button.active { background: #fff; color: #0f6eae; font-weight: 650; box-shadow: inset 3px 0 0 #168bd0, 0 2px 8px rgba(30, 92, 132, .08); }
.side-nav svg { width: 19px; height: 19px; }
.side-user {
  display: grid;
  grid-template-columns: 34px 1fr 34px;
  align-items: center;
  gap: 9px;
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(37, 95, 129, .18);
}
.side-user strong { display: block; max-width: 155px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.side-user small { color: #52758c; }
.avatar { width: 34px; height: 34px; border-radius: 6px; background: rgba(255,255,255,.72); display: grid; place-items: center; color: #4b7591; }
.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #315f7d;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,.72); color: #0f6eae; }

.workspace { min-width: 0; padding: 24px 30px 44px; background: #fff; }
.workspace .data-table th { background: #eff8fe; color: #315f7d; }
.workspace label span { color: #315f7d; }
.workspace input, .workspace select, .workspace textarea { border-color: var(--line); }
.workspace input:focus, .workspace select:focus, .workspace textarea:focus { border-color: var(--brand); outline-color: rgba(25,121,201,.18); }
.workspace .btn-light { color: #315f7d; border-color: var(--line); }
.workspace .btn-light:hover { background: #eff8fe; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}
.topbar h1 { margin: 0; font-size: 25px; font-weight: 680; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.topbar-actions { display: flex; gap: 8px; }

.view { display: none; min-width: 0; }
.view.active { display: grid; gap: 18px; }
.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(23,33,31,.04);
  padding: 20px;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.panel-header h2 { margin: 0; font-size: 17px; font-weight: 650; }
.panel-caption { margin: 4px 0 0; color: var(--muted); font-size: 12px; font-weight: 400; }
.tool-row { display: flex; align-items: center; gap: 8px; }

.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }
.metric-grid.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px 20px;
  min-height: 125px;
  display: grid;
  gap: 5px;
}
.metric-card > span { color: var(--muted); font-size: 12px; }
.metric-card > strong { font-size: 28px; line-height: 1.1; font-weight: 700; color: var(--brand-dark); }
.metric-card > strong:has(+ small) { overflow-wrap: anywhere; }
.metric-card > strong { font-variant-numeric: tabular-nums; }
.metric-card > small { color: var(--muted); }

.table-responsive { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table td {
  padding: 12px;
  border-bottom: 1px solid #eef1ef;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: 0; }
.data-table .wrap { min-width: 260px; max-width: 520px; overflow-wrap: anywhere; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
}
.badge-success { background: #e5f4ee; color: #166534; }
.badge-warning { background: #fdf0d8; color: #92400e; }
.badge-danger { background: #fde7e7; color: #991b1b; }
.badge-muted { background: #edf1ef; color: #566462; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .span-2 { grid-column: span 2; }
label { display: grid; gap: 6px; font-weight: 600; }
label span { font-size: 12px; color: #4d5b58; }
input, select, textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid #ccd5d1;
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
  font: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); outline: 2px solid rgba(15,118,110,.14); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.form-select.slim { width: 148px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-light { background: #fff; color: #394946; border-color: #ccd5d1; }
.btn-light:hover { background: #f5f7f6; }
.btn-danger { background: #fff; color: var(--danger); border-color: #efc9c9; }
.btn-danger:hover { background: #fdf2f2; }
.btn-sm { min-height: 32px; padding: 5px 9px; font-size: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.empty-state { min-height: 180px; display: grid; place-content: center; justify-items: center; gap: 10px; color: var(--muted); }
.empty-state svg { width: 28px; height: 28px; }
.mapping-hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  grid-column: 1 / -1;
  padding: 10px 12px;
  border: 1px solid #bfe3d2;
  border-radius: 6px;
  background: #f0fbf5;
  color: #176b48;
  font-size: 13px;
  line-height: 1.5;
}
.mapping-hint-warning { border-color: #f0d29e; background: #fff9eb; color: #8a5a09; }
.mapping-hint svg { width: 16px; height: 16px; flex: 0 0 auto; margin-top: 2px; }
.alert { display: flex; align-items: center; gap: 10px; border-radius: 7px; padding: 12px 14px; }
.alert-warning { background: #fdf4e3; color: #8a5a10; border: 1px solid #f0d9a9; }
.alert svg { width: 18px; height: 18px; }
.generated-key {
  margin-top: 14px;
  padding: 14px;
  border: 1px dashed var(--brand);
  border-radius: 7px;
  color: var(--brand-dark);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.webhook-url {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f5f7f6;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  overflow-wrap: anywhere;
}
.webhook-url code { flex: 1; }
.preview-list { display: grid; gap: 10px; }
.preview-stages { margin-bottom: 12px; }
.admin-proof-dialog { width: min(420px, calc(100% - 32px)); padding: 24px; border: 1px solid var(--line); border-radius: 8px; }
.admin-proof-dialog::backdrop { background: rgb(0 0 0 / 35%); }
.admin-proof-dialog form { display: grid; gap: 16px; }
.admin-proof-dialog h2 { font-size: 18px; margin: 0; }
.preview-row { display: grid; grid-template-columns: 70px 1fr; gap: 12px; align-items: start; padding: 10px; border: 1px solid var(--line); border-radius: 6px; }
#toast {
  display: block;
  position: fixed;
  right: 26px;
  bottom: 26px;
  max-width: min(420px, calc(100vw - 42px));
  padding: 13px 16px;
  border-radius: 7px;
  background: #17211f;
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 1000;
}
.toast.success { background: #14532d; }
.toast.error { background: #7f1d1d; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace { padding: 22px 20px 38px; }
}

@media (max-width: 860px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-aside { min-height: 210px; padding: 26px; }
  .auth-points { grid-template-columns: 1fr; margin-top: 24px; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .side-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 18px; }
  .form-grid, .form-grid .span-2 { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .panel-header { align-items: flex-start; flex-direction: column; }
  .metric-grid, .metric-grid.compact { grid-template-columns: 1fr; }
  .toast { right: 16px; bottom: 16px; }
}
.sidebar .brand strong { color: #123d5d; }
.sidebar .brand small { color: #52758c; }

@media (max-width: 640px) {
  .auth-aside { padding: 28px 24px; }
  .auth-intro { margin-top: 34px; }
  .auth-main { padding: 18px; }
  .workspace { padding: 18px 14px 30px; }
}
