:root {
  --primary: #007AFF;
  --primary-deep: #0051D5;
  --accent: #5856D6;
  --success: #34C759;
  --warning: #FF9500;
  --danger: #FF3B30;
  --bg: #F2F2F7;
  --surface: #FFFFFF;
  --text: #1D1D1F;
  --text-secondary: rgba(60, 60, 67, 0.68);
  --text-muted: rgba(60, 60, 67, 0.45);
  --separator: rgba(60, 60, 67, 0.18);
  --input-fill: rgba(120, 120, 128, 0.12);
  --sidebar-w: 220px;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell {
  display: flex;
  min-height: 100vh;
  background-image: url("/static/backgrounds/bg-mesh.png");
  background-size: cover;
  background-attachment: fixed;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: rgba(255,255,255,0.86);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--separator);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 18px;
}
.brand img { width: 40px; height: 40px; }
.brand-text { font-weight: 650; font-size: 15px; line-height: 1.25; }
.brand-sub { font-size: 12px; color: var(--text-muted); font-weight: 400; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  transition: background .15s, transform .12s;
}
.nav-item:hover { background: var(--input-fill); text-decoration: none; }
.nav-item.active {
  background: rgba(0, 122, 255, 0.12);
  color: var(--primary-deep);
  font-weight: 600;
}
.nav-item img { width: 22px; height: 22px; }
.nav-item:active { transform: scale(0.97); }
.nav-badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px 16px;
}

.msg-hero-stat {
  min-width: 72px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(120, 120, 128, 0.1);
  text-align: center;
}
.msg-hero-stat.has-unread {
  background: rgba(255, 59, 48, 0.1);
}
.msg-hero-num {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
}
.msg-hero-stat.has-unread .msg-hero-num { color: var(--danger); }
.msg-hero-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.msg-page { padding-bottom: 8px; }
.msg-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--separator);
}
.msg-filter {
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 3px;
  border-radius: 999px;
  background: var(--input-fill);
}
.msg-chip {
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
}
.msg-chip:hover { text-decoration: none; color: var(--text); }
.msg-chip.active {
  background: #fff;
  color: var(--primary-deep);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.msg-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.msg-actions .btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}
.msg-table .col-check { width: 36px; text-align: center; }
.msg-reason {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 280px;
  padding: 36px 20px 28px;
}
.msg-empty img {
  width: 112px;
  height: 112px;
  opacity: 0.92;
  margin-bottom: 4px;
}
.msg-empty .t {
  font-size: 16px;
  font-weight: 650;
  color: var(--text);
  margin-top: 8px;
}
.msg-empty .d {
  max-width: 360px;
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.msg-filter-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.msg-filter-source { flex-wrap: wrap; }

.src-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.4;
  white-space: nowrap;
}
.src-sync { background: rgba(0, 122, 255, 0.12); color: #0051D5; }
.src-manual { background: rgba(52, 199, 89, 0.14); color: #1B7A36; }
.src-compare { background: rgba(255, 149, 0, 0.16); color: #9A5B00; }
.src-other { background: var(--input-fill); color: var(--text-secondary); }
.src-read { background: var(--input-fill); color: var(--text-secondary); }
.src-unread { background: rgba(255, 59, 48, 0.12); color: var(--danger); }

.msg-detail-hero { align-items: flex-start; }
.msg-detail-hero-main { min-width: 0; flex: 1; }
.msg-detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.msg-detail-hero h1 { word-break: break-word; }

.msg-reason-box {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  background: rgba(255, 59, 48, 0.08);
  border: 1px solid rgba(255, 59, 48, 0.18);
}
.msg-reason-box img {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: 2px;
}
.msg-reason-text {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 1.55;
  color: #8B1E18;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-kv {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--separator);
  border-radius: 12px;
  overflow: hidden;
  background: #fafafa;
}
.msg-kv-row {
  display: grid;
  grid-template-columns: 128px 1fr;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--separator);
  align-items: start;
}
.msg-kv-row:last-child { border-bottom: none; }
.msg-kv-row dt {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  line-height: 1.45;
}
.msg-kv-row dd {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  word-break: break-word;
  overflow-wrap: anywhere;
}
.msg-kv-row dd.break,
.msg-kv-row dd code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}
.msg-summary-block {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(0, 122, 255, 0.06);
  border: 1px solid rgba(0, 122, 255, 0.12);
}
.msg-summary-title {
  font-size: 12px;
  font-weight: 650;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.msg-summary-text {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  word-break: break-word;
}
.msg-payload {
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-detail-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 24px;
}
.msg-detail-footer form { margin: 0; }

@media (max-width: 720px) {
  .msg-kv-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .msg-toolbar { align-items: stretch; }
  .msg-filter { width: 100%; }
  .msg-actions { width: 100%; }
  .msg-actions .btn { flex: 1; }
}

.main {
  flex: 1;
  padding: 24px 28px 48px;
  max-width: 1280px;
}
.page-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding: 22px 24px;
  border-radius: 18px;
  background: rgba(255,255,255,0.78);
  backdrop-filter: blur(16px);
  border: 1px solid var(--separator);
  background-image: linear-gradient(180deg, rgba(255,255,255,0.55), rgba(255,255,255,0.85)),
    url("/static/backgrounds/bg-welcome.png");
  background-size: cover;
}
.page-hero h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.page-hero p { margin: 6px 0 0; color: var(--text-secondary); font-size: 14px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--separator);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 17px; }

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}
.stat {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--separator);
  padding: 16px;
}
.stat .label { color: var(--text-secondary); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 650; margin-top: 4px; letter-spacing: -0.03em; }
.stat.warn .value { color: var(--warning); }
.stat.danger .value { color: var(--danger); }
.stat.ok .value { color: var(--success); }

.entry-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.entry {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 16px;
  background: var(--surface);
  border-radius: 18px;
  border: 1px solid var(--separator);
  text-decoration: none;
  color: var(--text);
  transition: transform .12s, box-shadow .15s;
}
.entry:hover { text-decoration: none; box-shadow: 0 8px 24px rgba(0,0,0,0.06); }
.entry:active { transform: scale(0.97); }
.entry img { width: 56px; height: 56px; }
.entry .t { font-weight: 600; font-size: 15px; }
.entry .d { font-size: 12px; color: var(--text-secondary); line-height: 1.4; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px 14px;
  align-items: end;
}
.form-grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
input[type="text"], input[type="number"], input[type="date"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: var(--input-fill);
  font-size: 15px;
  color: var(--text);
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(0,122,255,0.35);
  background: #fff;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  background-image: url("/static/buttons/btn-primary.png");
  background-size: cover;
  background-position: center;
  background-color: var(--primary);
  transition: transform .12s, opacity .15s;
}
.btn:active { transform: scale(0.97); }
.btn:hover { opacity: 0.92; text-decoration: none; color: #fff; }
.btn-secondary {
  background-image: url("/static/buttons/btn-secondary.png");
  background-color: var(--accent);
}
.btn-success {
  background-image: url("/static/buttons/btn-success.png");
  background-color: var(--success);
}
.btn-warn {
  background-image: url("/static/buttons/btn-warning.png");
  background-color: var(--warning);
}
.btn img.icon { width: 16px; height: 16px; filter: brightness(10); }

.meta { color: var(--text-secondary); font-size: 13px; margin-bottom: 10px; }
.error {
  background: rgba(255, 59, 48, 0.1);
  color: #a00;
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.error img { width: 20px; height: 20px; margin-top: 1px; }

.table-wrap { overflow: auto; max-height: 62vh; border-radius: 12px; border: 1px solid var(--separator); }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: #fff;
}
table.data th, table.data td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--separator);
  text-align: left;
  white-space: nowrap;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.data th {
  position: sticky; top: 0;
  background: #fafafa;
  z-index: 1;
  font-weight: 600;
}
table.data tr:hover td { background: rgba(0,122,255,0.04); }

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.pager a, .pager span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--input-fill);
  color: var(--text);
  text-decoration: none;
}
.pager a:hover { background: rgba(0,122,255,0.12); }
.pager img { width: 14px; height: 14px; }

.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-secondary);
}
.empty img { width: 120px; height: 120px; opacity: 0.95; }
.empty .t { font-weight: 600; color: var(--text); margin-top: 8px; }

.log-list { list-style: none; padding: 0; margin: 0; }
.log-list li {
  background: #f9f9fb;
  margin: 10px 0;
  padding: 14px;
  border-radius: 12px;
  border-left: 4px solid var(--primary);
}
.json-text {
  color: var(--primary-deep);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  background: #f0f6ff;
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  max-height: 320px;
  font-size: 12px;
}

.chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--input-fill);
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
}
.chip.active {
  background: rgba(0,122,255,0.14);
  color: var(--primary-deep);
  font-weight: 600;
}

.console {
  background: #1e1e1e;
  color: #f5f5f7;
  border-radius: 12px;
  padding: 12px 14px;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.thread-table td.on { color: var(--success); font-weight: 600; }
.thread-table td.off { color: var(--text-muted); }

.spinner {
  width: 36px; height: 36px;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}

/* ---- 质控：多 SELECT 布局 ---- */
.qc-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  align-items: start;
}
.qc-query-nav {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  padding: 12px !important;
  overflow: hidden;
}
.qc-query-nav-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 8px 10px;
  border-bottom: 1px solid var(--separator);
  margin-bottom: 8px;
}
.qc-query-list {
  overflow: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 2px;
}
.qc-query-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 10px;
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  transition: background .12s, transform .1s;
}
.qc-query-item:hover { background: var(--input-fill); text-decoration: none; }
.qc-query-item.active {
  background: rgba(0, 122, 255, 0.12);
  color: var(--primary-deep);
}
.qc-query-item:active { transform: scale(0.98); }
.qc-qi-num {
  flex-shrink: 0;
  width: 22px; height: 22px;
  border-radius: 7px;
  background: var(--input-fill);
  font-size: 12px;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
.qc-query-item.active .qc-qi-num {
  background: rgba(0, 122, 255, 0.2);
  color: var(--primary-deep);
}
.qc-qi-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.qc-qi-label {
  font-size: 13px;
  font-weight: 560;
  line-height: 1.3;
  word-break: break-word;
}
.qc-qi-table {
  font-size: 11px;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.qc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.qc-compare-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 12px;
}
.qc-compare-cols h3 {
  font-size: 14px;
  margin: 0 0 8px;
  font-weight: 600;
}
@media (max-width: 900px) {
  .qc-compare-cols { grid-template-columns: 1fr; }
}
.send-result-box {
  margin: 12px 0 16px;
  padding: 12px;
  border: 1px solid var(--separator);
  border-radius: 12px;
  background: rgba(52, 199, 89, 0.04);
}
.send-result-box h3 {
  margin: 0 0 6px;
  font-size: 15px;
}
.ok-text { color: var(--success); font-weight: 600; }
.bad-text { color: var(--danger); font-weight: 600; }
.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}
.inline-form { display: inline; margin: 0; }
.resend-form .table-wrap { max-height: 360px; overflow: auto; }
.send-meta { min-width: 140px; max-width: 280px; word-break: break-all; }
.send-meta strong { font-size: 14px; }
.qc-select-wrap { display: none; }
.qc-hit td { background: rgba(255, 149, 0, 0.06); }
.qc-err { color: var(--danger); font-weight: 600; }

.qc-log-card { margin-top: 0; }
.qc-log-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 420px;
  overflow: auto;
}
.qc-log-item {
  border: 1px solid var(--separator);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fafafa;
}
.qc-log-item.ok { border-left: 4px solid var(--success); }
.qc-log-item.bad { border-left: 4px solid var(--danger); background: rgba(255,59,48,0.04); }
.qc-log-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.qc-log-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.qc-log-msg { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; word-break: break-word; }
.qc-log-sql {
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: #1e1e1e;
  color: #f5f5f7;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 160px;
  overflow: auto;
}

@media (max-width: 960px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--separator);
  }
  .brand { width: 100%; }
  .grid-4, .entry-grid, .form-grid { grid-template-columns: 1fr 1fr; }
  .qc-layout { grid-template-columns: 1fr; }
  .qc-query-nav {
    position: static;
    max-height: 220px;
  }
  .qc-select-wrap { display: block; }
}
@media (max-width: 560px) {
  .grid-4, .entry-grid, .form-grid { grid-template-columns: 1fr; }
  .main { padding: 16px; }
}
