:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --ok: #059669;
  --warn: #d97706;
  --bad: #dc2626;
  --process: #0891b2;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: #f1f5f9;
  padding: 1px 5px;
  border-radius: 5px;
  word-break: break-all;
}

/* ------------------------------ topbar ------------------------------ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  background: linear-gradient(120deg, #1e3a8a, #2563eb);
  color: #fff;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 42px; height: 42px; border-radius: 12px;
  background: rgba(255,255,255,.18);
  display: grid; place-items: center;
  font-weight: 700; letter-spacing: .5px;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 650; }
.topbar .sub { margin: 2px 0 0; font-size: 12.5px; opacity: .85; }
.topbar .sub code { background: rgba(255,255,255,.16); color: #fff; }

.badge {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-muted { background: rgba(255,255,255,.18); color: #fff; }
.badge-ok { background: rgba(255,255,255,.18); color: #fff; }
.badge-bad { background: #fecaca; color: #7f1d1d; }

/* -------------------------------- tabs -------------------------------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 0 28px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 14px 18px;
  font-size: 14.5px;
  font-weight: 550;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--brand); border-bottom-color: var(--brand); }

/* ------------------------------- layout ------------------------------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 22px 28px 40px; }
.panel { display: none; }
.panel.is-active { display: block; }

.grid { display: grid; grid-template-columns: 1fr 320px; gap: 18px; align-items: start; }
.span2 { grid-column: span 1; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: 0 1px 2px rgba(16,24,40,.04);
}
.card h2 { margin: 0 0 6px; font-size: 15.5px; font-weight: 650; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; padding: 18px 0; }

/* ------------------------------- form ------------------------------- */
textarea#urls {
  width: 100%;
  min-height: 210px;
  resize: vertical;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink);
  background: #fbfcfe;
}
textarea#urls:focus, input:focus, select:focus {
  outline: 2px solid rgba(37,99,235,.35);
  outline-offset: 1px;
  border-color: var(--brand);
}

.row { display: flex; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
.wrap-row { flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.field.grow { flex: 1 1 auto; min-width: 200px; }
.field > span { font-size: 12.5px; color: var(--muted); font-weight: 550; }
.field input, .field select {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--ink);
  min-width: 160px;
}
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { background: #93b4f5; cursor: not-allowed; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: #f3f4f6; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-xs { padding: 3px 9px; font-size: 12px; margin-left: 6px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ------------------------------ results ------------------------------ */
.result {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  background: #fbfcfe;
}
.result-head { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.pill { padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.pill-ok { background: #d1fae5; color: #065f46; }
.pill-warn { background: #fef3c7; color: #92400e; }
.pill-bad { background: #fee2e2; color: #991b1b; }
.reject-list { margin: 0; padding-left: 18px; font-size: 13px; }
.reject-list li { margin-bottom: 4px; }

.kv-mini { display: grid; grid-template-columns: 90px 1fr; gap: 6px 12px; margin: 0; font-size: 13px; }
.kv-mini dt { color: var(--muted); }
.kv-mini dd { margin: 0; display: flex; align-items: center; flex-wrap: wrap; }

/* ------------------------------- rules ------------------------------- */
.rules { margin: 0; padding-left: 18px; font-size: 13px; color: #374151; }
.rules li { margin-bottom: 6px; }
.quota-mini { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 12px; }
.budget-row { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 0; }

/* ------------------------------- table ------------------------------- */
.table-scroll { overflow-x: auto; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
thead th { background: #f9fafb; font-size: 12.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: #fafbff; }
.cell-url { max-width: 420px; }
.cell-url code { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

table.kv th { width: 210px; background: #f9fafb; color: var(--muted); font-weight: 600; white-space: nowrap; }
table.kv td { font-size: 13.5px; }

/* ------------------------------ status ------------------------------ */
.status { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status-done { background: #d1fae5; color: #065f46; }
.status-process { background: #cffafe; color: #155e75; }
.status-fail { background: #fee2e2; color: #991b1b; }
.status-invalid { background: #fef3c7; color: #92400e; }
.status-unknown { background: #f3f4f6; color: #374151; }

.bar { height: 6px; width: 110px; background: #eef2f7; border-radius: 999px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 8px; }
.bar-fill { height: 100%; border-radius: 999px; }
.bar-done { background: var(--ok); }
.bar-process { background: var(--process); }
.bar-fail { background: var(--bad); }
.bar-invalid { background: var(--warn); }
.bar-unknown { background: #9ca3af; }
.bar-used { background: var(--brand); }

/* ------------------------------- quota ------------------------------- */
.quota-box { margin-bottom: 12px; }
.quota-row { display: flex; align-items: center; gap: 12px; margin: 6px 0 2px; }
.quota-area { min-width: 76px; font-weight: 600; font-size: 13.5px; }
.quota-num { margin-left: auto; font-size: 13.5px; }

.pager { display: flex; align-items: center; gap: 10px; }
.pager .muted { font-size: 12.5px; }

/* -------------------------------- misc -------------------------------- */
.foot { max-width: 1180px; margin: 0 auto; padding: 0 28px 30px; color: var(--muted); font-size: 12.5px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  padding: 11px 20px;
  border-radius: 10px;
  color: #fff;
  font-size: 14px;
  font-weight: 550;
  box-shadow: 0 8px 24px rgba(16,24,40,.18);
  z-index: 60;
  max-width: 90vw;
}
.toast.is-ok { background: #065f46; }
.toast.is-error { background: #991b1b; }
