:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --line: #e5e7eb;
  --line-soft: #f1f2f4;
  --txt: #111827;
  --sub: #6b7280;
  --muted: #9ca3af;
  --brand: #2563eb;
  --brand-light: #eff6ff;
  --green: #16a34a;
  --orange: #d97706;
  --red: #dc2626;
  --radius: 8px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--txt); font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; }
.text-danger { color: #b91c1c; }
.text-warn { color: #b45309; }
.wrap { max-width: 1360px; margin: 0 auto; padding: 16px; }

/* ---------- 登录 ---------- */
#login-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-card {
  width: 340px; max-width: calc(100vw - 40px); background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 36px 32px;
  text-align: center;
}
.login-card h1 { font-size: 18px; font-weight: 600; margin-bottom: 24px; }
.btn-login {
  display: block; width: 100%; height: 38px; line-height: 38px; border-radius: 6px;
  background: var(--brand); color: #fff; text-decoration: none; font-size: 14px;
}
.btn-login:hover { background: #1d4ed8; }
.login-err { color: var(--red); font-size: 12px; margin-top: 12px; min-height: 16px; }

/* ---------- 顶栏 ---------- */
header.topbar {
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.topbar-in {
  max-width: 1360px; margin: 0 auto; padding: 0 16px; height: 56px;
  display: flex; align-items: center; gap: 20px;
}
.brand { font-size: 16px; font-weight: 600; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand img { width: 24px; height: 24px; display: block; }
.login-logo { width: 44px; height: 44px; display: block; margin: 0 auto 12px; }
.nav { display: flex; gap: 2px; }
.nav a {
  text-decoration: none; color: var(--sub); font-size: 13px; font-weight: 400;
  padding: 6px 12px; border-radius: 6px; white-space: nowrap;
}
.nav a:hover { color: var(--txt); background: #f5f6f8; }
.nav a.active { color: var(--brand); background: var(--brand-light); font-weight: 500; }
.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.who { font-size: 13px; color: var(--sub); }
.btn-ghost {
  border: 1px solid var(--line); background: #fff; color: var(--sub);
  border-radius: 6px; height: 28px; padding: 0 10px; font-size: 12px; cursor: pointer;
}
.btn-ghost:hover { color: var(--txt); }

/* ---------- 搜索 ---------- */
.search-container { position: relative; flex: 1 1 300px; min-width: 200px; max-width: 520px; }
.global-search-input {
  width: 100%; height: 32px; border-radius: 6px; border: 1px solid var(--line);
  padding: 0 12px 0 32px; font-size: 13px; outline: none; background: #fff;
}
.global-search-input:focus { border-color: var(--brand); }
.search-icon {
  position: absolute; left: 10px; top: 7px; font-size: 13px; color: var(--muted); pointer-events: none;
}
.search-dropdown {
  position: absolute; top: 38px; left: 0; right: 0; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius);
  max-height: 360px; overflow-y: auto; z-index: 40; display: none;
}
.search-dropdown.open { display: block; }
.search-group-title {
  font-size: 11px; color: var(--sub); padding: 8px 12px 4px; background: #f9fafb;
  border-bottom: 1px solid var(--line-soft);
}
.search-result-item {
  padding: 9px 12px; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; cursor: pointer; border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.search-result-item:hover { background: #f9fafb; }
.search-result-item .m-title { font-weight: 500; }
.search-result-item .m-sub { font-size: 12px; color: var(--sub); }

/* ---------- 页面结构 ---------- */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin: 4px 0 14px;
}
.page-head h1 { font-size: 18px; font-weight: 600; }
.page-head-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.inline-title { font-size: 18px; font-weight: 600; display: inline-block; margin-right: 8px; }
.back-link { color: var(--sub); text-decoration: none; font-size: 12px; margin-right: 8px; }
.back-link:hover { color: var(--brand); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 12px;
}
.card-head h3 { font-size: 15px; font-weight: 600; }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kpi .k-lab { font-size: 12px; color: var(--sub); }
.kpi .k-val {
  font-size: 24px; font-weight: 600; margin-top: 8px; letter-spacing: -.3px;
  font-variant-numeric: tabular-nums;
}
.kpi .k-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi-status .status { font-size: 16px; }

.overview-columns { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; align-items: start; }
.attention-list { display: flex; flex-direction: column; }
.attention-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 0; border-bottom: 1px solid var(--line-soft);
  color: var(--txt); text-decoration: none; font-size: 13px;
}
.attention-row:last-child { border-bottom: 0; }
.attention-row:hover { color: var(--brand); }
.attention-row b { font-weight: 600; }

/* ---------- 表格 ---------- */
.table-scroll { overflow: auto; max-height: calc(100vh - 250px); }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.data th, table.data td {
  text-align: center; padding: 0 12px; border-bottom: 1px solid var(--line-soft); white-space: nowrap;
}
table.data th {
  height: 38px; background: #f9fafb; color: var(--sub); font-size: 12px; font-weight: 500;
  position: sticky; top: 0; z-index: 2; border-bottom: 1px solid var(--line);
}
table.data td { height: 44px; color: #1f2937; }
table.data th.num, table.data td.num { text-align: center; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: #f9fafb; }
table.data tbody tr.clickable { cursor: pointer; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--txt); }
table.data th .arr { font-size: 10px; color: var(--brand); margin-left: 2px; }
.cell-title { display: block; font-weight: 500; color: var(--txt); }
.cell-sub {
  display: block; font-size: 11px; color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.link { color: var(--brand); text-decoration: none; }
.link:hover { text-decoration: underline; }

table.account-table th, table.account-table td { padding: 0 6px; font-size: 12.5px; }
table.account-table .cell-title { white-space: normal; line-height: 1.25; word-break: break-word; }

table.admin-table th, table.admin-table td { text-align: center; }
table.admin-table th.num, table.admin-table td.num { text-align: center; }
.checkbox-cell { width: 36px; text-align: center !important; }
.mismatch-row { background: #fff7ed; }
.mismatch-row:hover { background: #fff1e6 !important; }

/* ---------- 状态点 / 标签 ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.dot.green { background: var(--green); }
.dot.orange { background: var(--orange); }
.dot.gray { background: var(--muted); }
.tag {
  display: inline-block; padding: 1px 7px; margin-right: 4px; border-radius: 3px;
  font-size: 11px; line-height: 18px; white-space: nowrap;
}
.tag-red { background: #fef2f2; color: #b91c1c; }
.tag-amber { background: #fffbeb; color: #b45309; }
.tag-gray { background: #f3f4f6; color: #4b5563; }
.tag-blue { background: var(--brand-light); color: #1d4ed8; }
.tag-green { background: #ecfdf5; color: #047857; }

/* ---------- 按钮 / 选择框 ---------- */
.btn {
  height: 30px; padding: 0 12px; border: 1px solid var(--line); background: #fff;
  border-radius: 6px; font-size: 13px; color: #374151; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f9fafb; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { color: #b91c1c; border-color: #fecaca; background: #fff; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { height: 26px; padding: 0 10px; font-size: 12px; }
.btn:disabled { opacity: .45; pointer-events: none; }
.select, .input {
  height: 30px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
  font-size: 13px; padding: 0 8px; color: var(--txt); outline: none;
}
.select:focus, .input:focus { border-color: var(--brand); }
.input { width: 190px; }
.inline-input {
  height: 28px; border: 1px solid var(--line); border-radius: 5px; padding: 0 8px;
  font-size: 12px; width: 110px; outline: none;
}
.inline-input:focus { border-color: var(--brand); }
.inline-select {
  height: 28px; border: 1px solid var(--line); border-radius: 5px; font-size: 12px; background: #fff;
}

.filter-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filter-spacer { flex: 1 1 0; }
.check-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #374151; }

/* ---------- 图表 ---------- */
.legend { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--sub); margin-bottom: 8px; }
.legend-dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.line-chart { position: relative; height: 300px; }
.line-chart canvas { width: 100%; height: 100%; display: block; }
.line-tip {
  position: absolute; pointer-events: none; background: #111827; color: #fff;
  padding: 8px 10px; border-radius: 6px; font-size: 12px; line-height: 1.75;
  white-space: nowrap; opacity: 0; transform: translate(-50%, -100%); z-index: 5;
  transition: opacity .1s;
}
.line-tip.show { opacity: 1; }
.line-tip .tip-title { font-weight: 600; margin-bottom: 2px; }
.range-label { font-size: 12px; font-weight: 400; color: var(--sub); margin-left: 8px; }
.tip-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 6px; }
canvas.spark { width: 72px; height: 26px; display: block; margin: 0 auto; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button {
  border: 0; background: #fff; padding: 4px 10px; font-size: 12px; color: var(--sub); cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--brand-light); color: #1d4ed8; font-weight: 500; }

/* ---------- 日期区间日历 ---------- */
.calendar-pop {
  position: fixed; z-index: 200; width: 312px; max-width: calc(100vw - 24px);
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; box-shadow: 0 8px 24px rgba(17, 24, 39, .12);
}
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { font-size: 13px; font-weight: 600; }
.cal-nav {
  width: 26px; height: 26px; border: 1px solid var(--line); background: #fff;
  border-radius: 6px; color: var(--sub); cursor: pointer; font-size: 12px;
}
.cal-nav:hover { background: #f9fafb; }
.cal-week {
  display: grid; grid-template-columns: repeat(7, 1fr); text-align: center;
  font-size: 11px; color: var(--muted); margin-bottom: 4px;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-day {
  height: 32px; display: flex; align-items: center; justify-content: center;
  font-size: 12px; border-radius: 4px; cursor: pointer; user-select: none;
}
.cal-day:hover:not(.disabled):not(.empty):not(.start):not(.end) { background: #f3f4f6; }
.cal-day.disabled { color: #d1d5db; cursor: not-allowed; }
.cal-day.empty { cursor: default; }
.cal-day.in-range { background: var(--brand-light); border-radius: 0; color: #1d4ed8; }
.cal-day.start, .cal-day.end { background: var(--brand); color: #fff; border-radius: 4px; }
.cal-foot {
  margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line-soft);
  font-size: 11px; color: var(--sub); display: flex; justify-content: space-between;
}

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 12px; }

/* ---------- 详情 ---------- */
.meta-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px 20px; }
.meta-item .m-lab { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.meta-item .m-val { font-size: 13px; font-weight: 500; word-break: break-all; }

/* ---------- 导入 ---------- */
.ids-input {
  width: 100%; min-height: 150px; padding: 10px 12px; font-size: 13px; line-height: 1.7;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  border: 1px solid var(--line); border-radius: 6px; outline: none; resize: vertical;
}
.ids-input:focus { border-color: var(--brand); }
.form-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.form-row label { font-size: 13px; color: var(--sub); }
.import-error {
  margin-top: 12px; padding: 9px 12px; border: 1px solid #fecaca;
  background: #fef2f2; color: #b91c1c; border-radius: 6px; font-size: 13px;
}
.job-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 8px; }
.job-progress-text { font-weight: 500; font-variant-numeric: tabular-nums; }
.progress { height: 6px; background: #eef0f3; border-radius: 999px; overflow: hidden; margin-bottom: 8px; }
.progress i { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .3s; }
.result-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.result-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 6px; font-size: 13px; background: #fff;
}
.result-item.ok { border-color: #bbf7d0; }
.result-item.bad { border-color: #fecaca; }
.result-item .r-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.result-item .r-owner { font-size: 12px; color: var(--sub); }
.result-item { justify-content: center; text-align: center; }
.result-item .r-msg { color: var(--sub); font-size: 12px; text-align: center; }

/* ---------- 管理员 ---------- */
.tabs { display: flex; gap: 22px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab {
  padding: 9px 0; font-size: 13px; color: var(--sub); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--txt); border-bottom-color: var(--brand); font-weight: 500; }

/* ---------- 手机端卡片 ---------- */
.m-cards { display: none; }
.m-card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
}
.m-card .mc-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.m-card .mc-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-card .mc-main { display: flex; align-items: baseline; justify-content: space-between; margin: 8px 0 4px; }
.m-card .mc-main-val { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.m-card .mc-sub {
  display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; color: var(--sub); line-height: 1.8;
}

/* ---------- 通用 ---------- */
.toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%) translateY(-80px);
  background: #1f2937; color: #fff; padding: 9px 18px; border-radius: 6px;
  font-size: 13px; z-index: 999; opacity: 0; pointer-events: none;
  transition: transform .25s ease, opacity .25s ease; max-width: 80vw; text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.loading { padding: 40px; text-align: center; color: var(--sub); font-size: 13px; }
.empty { padding: 28px; text-align: center; color: var(--muted); font-size: 13px; }

@media (max-width: 1100px) {
  .meta-grid { grid-template-columns: repeat(3, 1fr); }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  html, body { overflow-x: hidden; max-width: 100vw; }
  .wrap { padding: 10px; }
  .topbar-in { height: auto; padding: 8px 12px; gap: 8px; flex-wrap: wrap; }
  .brand { font-size: 15px; }
  .topbar-right { margin-left: auto; }
  .who { display: none; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .nav a { padding: 5px 10px; font-size: 12.5px; }
  .search-container { order: 4; flex: 1 1 100%; max-width: none; }
  .global-search-input { height: 34px; }

  .page-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  .page-head-right { width: 100%; justify-content: space-between; }
  .kpi-grid { gap: 8px; }
  .kpi { padding: 12px; }
  .kpi .k-val { font-size: 20px; }
  .overview-columns { grid-template-columns: 1fr; }
  .line-chart { height: 220px; }
  .card { padding: 12px; }

  .table-desktop { display: none; }
  .m-cards { display: block; }

  .filter-row { gap: 6px; }
  .filter-row .select { flex: 1 1 calc(50% - 6px); min-width: 0; }
  .filter-row .btn { flex: 0 0 auto; }
  .filter-spacer { display: none; }

  .meta-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .pager { justify-content: space-between; }
  .result-item { flex-wrap: wrap; }
  .result-item .r-msg { margin-left: 0; text-align: left; width: 100%; }
  .input { width: 100%; }
  .table-scroll { max-height: none; }
  table.data th { position: static; }
}
