:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --line: #e4e7ec;
  --surface: #ffffff;
  --canvas: #f4f6f9;
  --nav: #15243a;
  --nav-soft: #223550;
  --orange: #f26522;
  --orange-dark: #d94d0c;
  --blue: #275f9b;
  --green: #138a62;
  --red: #c2413b;
  --shadow: 0 18px 46px rgba(24, 39, 75, .10);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-size: 16px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 26px 18px; background: var(--nav); color: #fff; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: linear-gradient(135deg, #ff7b32, var(--orange)); color: #fff; font-weight: 800; box-shadow: 0 8px 20px rgba(242,101,34,.25); }
.brand-mark.large { width: 52px; height: 52px; margin-bottom: 22px; font-size: 22px; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 19px; }
.brand span { margin-top: 3px; color: #a9b6c8; font-size: 13px; }
nav { display: grid; gap: 7px; }
nav button { border: 0; border-radius: 10px; background: transparent; color: #b9c5d5; padding: 12px 14px; text-align: left; display: flex; align-items: center; gap: 12px; font-size: 15px; }
nav button span { width: 24px; text-align: center; color: #8da2bd; font-size: 19px; }
nav button:hover { background: rgba(255,255,255,.06); color: #fff; }
nav button.active { background: var(--nav-soft); color: #fff; box-shadow: inset 3px 0 var(--orange); }
nav button.active span { color: #ff9b62; }
.sidebar-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.10); padding: 18px 8px 0; color: #a9b6c8; }
.sidebar-foot small { display: block; margin-top: 8px; font-size: 12px; line-height: 1.5; }
.system-state { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.system-state i { width: 8px; height: 8px; border-radius: 50%; background: #48c78e; box-shadow: 0 0 0 4px rgba(72,199,142,.13); }
.workspace { min-width: 0; }
.topbar { padding: 28px 34px 22px; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 20px; position: sticky; top: 0; z-index: 5; backdrop-filter: blur(10px); }
.eyebrow { margin: 0 0 5px; color: var(--orange); letter-spacing: .12em; font-size: 12px; font-weight: 800; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 27px; letter-spacing: -.02em; }
h2 { font-size: 21px; }
h3 { font-size: 16px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.btn { border: 0; border-radius: 9px; padding: 10px 15px; font-weight: 700; font-size: 14px; transition: .18s ease; }
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--orange); color: #fff; box-shadow: 0 8px 18px rgba(242,101,34,.20); }
.btn.primary:hover { background: var(--orange-dark); }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost { background: #f8fafc; color: var(--blue); }
.btn.danger { background: #fff2f1; color: var(--red); }
.btn.small { padding: 7px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
main { padding: 28px 34px 50px; }
.loading, .empty { min-height: 260px; display: grid; place-items: center; color: var(--muted); }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 4px 14px rgba(24,39,75,.035); }
.stat-card { padding: 21px; position: relative; overflow: hidden; }
.stat-card::after { content: ""; position: absolute; width: 64px; height: 64px; border-radius: 50%; right: -20px; top: -20px; background: #fff1e8; }
.stat-label { color: var(--muted); font-size: 14px; }
.stat-value { margin: 9px 0 5px; font-size: 30px; font-weight: 800; letter-spacing: -.03em; }
.stat-foot { color: #7a8699; font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(300px, .8fr); gap: 18px; }
.panel { padding: 21px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.panel-head h2, .panel-head h3 { margin: 0; }
.panel-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.bar-list { display: grid; gap: 13px; }
.bar-row { display: grid; grid-template-columns: 72px minmax(0,1fr) 54px; align-items: center; gap: 10px; font-size: 14px; }
.bar-track { height: 9px; background: #edf0f5; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--orange), #ff9860); }
.bar-count { color: var(--muted); text-align: right; }
.status-list { display: grid; gap: 10px; }
.status-row { padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; display: flex; justify-content: space-between; align-items: center; }
.status-row strong { font-size: 18px; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge.neutral { background: #eef2f7; color: #546174; }
.badge.success { background: #e8f7f1; color: #087653; }
.badge.warning { background: #fff4e8; color: #a64c0a; }
.badge.danger { background: #fdeceb; color: #ad322d; }
.badge.info { background: #eaf2fb; color: #245e9b; }
.filters { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.filters input, .filters select { height: 42px; border: 1px solid #d8dde6; border-radius: 9px; background: #fff; padding: 0 12px; min-width: 170px; color: var(--ink); }
.filters input { min-width: 270px; }
.table-wrap { width: 100%; overflow: auto; border: 1px solid var(--line); border-radius: 11px; }
table { width: 100%; border-collapse: collapse; min-width: 980px; background: #fff; }
th { position: sticky; top: 0; z-index: 1; background: #f6f8fb; color: #596579; text-align: left; font-size: 13px; padding: 12px 13px; border-bottom: 1px solid var(--line); }
td { padding: 13px; border-bottom: 1px solid #edf0f4; font-size: 14px; vertical-align: top; }
tbody tr:hover { background: #fbfcfe; }
.primary-text { font-weight: 750; color: #202a3b; }
.secondary-text { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.link { color: var(--blue); text-decoration: none; }
.link:hover { text-decoration: underline; }
.pagination { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; color: var(--muted); font-size: 14px; }
.campaign-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; }
.campaign-card { border: 1px solid var(--line); border-radius: 13px; padding: 18px; background: #fff; }
.campaign-card h3 { margin-bottom: 7px; }
.campaign-card p { color: var(--muted); min-height: 40px; font-size: 13px; line-height: 1.5; }
.campaign-meta { display: flex; justify-content: space-between; gap: 8px; margin: 18px 0; color: var(--muted); font-size: 13px; }
.campaign-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.modal-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(12,22,37,.48); display: grid; place-items: center; padding: 24px; }
.modal { width: min(540px, 100%); max-height: 88vh; overflow: auto; background: #fff; border-radius: 16px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-head button { border: 0; background: transparent; font-size: 28px; color: var(--muted); }
#modalBody { padding: 22px; }
.form-grid { display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: #344054; font-size: 14px; font-weight: 700; }
label input, label select, label textarea { width: 100%; border: 1px solid #d8dde6; border-radius: 9px; padding: 11px 12px; color: var(--ink); background: #fff; }
label textarea { min-height: 90px; resize: vertical; }
.form-hint { color: var(--muted); font-size: 13px; line-height: 1.6; }
.form-error { color: var(--red); min-height: 20px; font-size: 13px; }
.login-overlay { position: fixed; inset: 0; z-index: 50; background: linear-gradient(145deg, #102038, #213a5b); display: grid; place-items: center; padding: 22px; }
.login-card { width: min(430px,100%); background: #fff; border-radius: 18px; padding: 34px; box-shadow: var(--shadow); }
.login-card h2 { font-size: 25px; margin-bottom: 10px; }
.login-card > p:not(.eyebrow):not(.form-error) { color: var(--muted); line-height: 1.65; margin-bottom: 22px; }
.toast { position: fixed; z-index: 60; right: 24px; bottom: 24px; max-width: 390px; background: #15243a; color: #fff; padding: 13px 17px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; }
.api-docs { margin-top: 18px; }
.endpoint { padding: 13px 15px; border: 1px solid #cfd8e5; border-radius: 10px; background: #f7f9fc; overflow-wrap: anywhere; margin-bottom: 14px; }
.api-docs pre { margin: 0; padding: 16px; overflow: auto; border-radius: 10px; background: #101b2b; color: #dce7f7; font: 14px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; }
.api-key-secret { padding: 16px; border: 1px solid #f3c7a9; border-radius: 10px; background: #fff7f1; overflow-wrap: anywhere; user-select: all; }
.api-key-secret code { font-size: 14px; line-height: 1.6; }
.report-filter { margin-bottom: 20px; }
.report-filter .filters { margin-bottom: 0; }
.report-panel { margin-bottom: 20px; }
.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.report-grid .panel { margin-bottom: 0; }
.report-panel table, .report-grid table { min-width: 720px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.hidden { display: none !important; }
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2,1fr); }
  .campaign-grid { grid-template-columns: repeat(2,1fr); }
}
@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 16px; }
  .brand { padding-bottom: 14px; }
  nav { display: flex; overflow-x: auto; }
  nav button { flex: 0 0 auto; }
  .sidebar-foot { display: none; }
  .topbar { position: static; padding: 20px; align-items: flex-start; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  #dbBadge { display: none; }
  main { padding: 20px; }
  .stats-grid, .grid-2, .campaign-grid, .report-grid { grid-template-columns: 1fr; }
  .filters input, .filters select { min-width: 100%; }
}
