:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #f0f3f7;
  --line: #dde2ea;
  --text: #19202b;
  --muted: #66707f;
  --accent: #1f7ae0;
  --on-accent: #ffffff;
  --ok: #1e9a5c;
  --late: #7c4dde;
  --over: #e03b3b;
  --urgent: #e07400;
  --pending: #b38a00;
  --none: #8a93a1;
  --grid: #e7ebf0;
  --shadow: 0 1px 2px rgba(20, 30, 50, .08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Noto Sans SC", system-ui, -apple-system, "PingFang SC", sans-serif;
}
h1, h2, h3, .num, .font-num { font-family: "Space Grotesk", "Noto Sans SC", sans-serif; }
button, input, select { font: inherit; color: inherit; }
.wrap { max-width: 1760px; margin: 0 auto; padding: 0 24px; }
@media (max-width: 640px) { .wrap { padding: 0 16px; } }

/* 顶栏 */
.topbar { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 14px; padding-bottom: 10px; flex-wrap: wrap; }
.brand h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .2px; }
.meta-line { color: var(--muted); font-size: 12px; margin-top: 2px; }
.meta-line b { color: var(--text); font-weight: 500; }
.actions { display: flex; gap: 8px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tab { background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }

/* 按钮与 chip */
.btn { border: 1px solid var(--line); background: var(--panel-2); padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 500; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); padding: 4px 12px; border-radius: 999px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.chip:hover { color: var(--text); border-color: var(--muted); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 500; }
.chip .cnt { font-family: "Space Grotesk", sans-serif; margin-left: 4px; opacity: .8; }

main { padding-top: 20px; padding-bottom: 48px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.card-head .sub { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 8px; font-family: "Noto Sans SC", sans-serif; }
.hint { color: var(--muted); font-size: 12px; }

/* 到期概览 */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .num { font-size: 32px; font-weight: 600; line-height: 1.2; margin-top: 4px; }
.kpi .foot { color: var(--muted); font-size: 12px; margin-top: 6px; }
.kpi.ok .num { color: var(--ok); }
.kpi.bad .num { color: var(--over); }
.bar { height: 6px; border-radius: 3px; background: var(--grid); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--ok); }
.prio-rates { display: flex; gap: 14px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.prio-rates b { color: var(--text); font-family: "Space Grotesk", sans-serif; font-weight: 600; }

/* 筛选栏 */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar select, .toolbar input[type="search"] { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; min-width: 120px; }
.toolbar input[type="search"] { min-width: 200px; }
.toolbar .count { margin-left: auto; color: var(--muted); font-size: 12px; }

/* 表格 */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: var(--panel-2); color: var(--muted); font-weight: 500; white-space: nowrap; position: sticky; top: 0; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th .arrow { font-size: 11px; margin-left: 2px; opacity: .5; }
th.sorted { color: var(--text); }
th.sorted .arrow { opacity: 1; color: var(--accent); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--panel-2); }
td.nowrap, td.mono { white-space: nowrap; }
td.mono { font-family: "Space Grotesk", ui-monospace, monospace; font-size: 12px; }
td.title { min-width: 220px; max-width: 420px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.prov { color: var(--pending); font-size: 11px; margin-left: 4px; }
.prio { font-family: "Space Grotesk", sans-serif; font-weight: 600; }
.prio.P0 { color: var(--over); }
.prio.P1 { color: var(--accent); }
.prio.P2 { color: var(--none); }
.status { display: flex; flex-direction: column; gap: 3px; min-width: 150px; }
.stage { font-size: 12px; color: var(--muted); }
.badge { display: inline-block; width: fit-content; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 500; white-space: nowrap; border: 1px solid currentColor; background: color-mix(in srgb, currentColor 14%, transparent); }
.s-ok { color: var(--ok); }
.s-late { color: var(--late); }
.s-over { color: var(--over); }
.s-urgent { color: var(--urgent); }
.s-pending { color: var(--pending); }
.s-none { color: var(--none); }
.reason { display: flex; gap: 6px; min-width: 280px; }
.reason input { flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; }
.reason input.dirty { border-color: var(--urgent); }
.reason .saved { color: var(--muted); font-size: 11px; white-space: nowrap; align-self: center; }

/* 趋势 */
.ctrl-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin-bottom: 12px; }
.ctrl-row .lbl { color: var(--muted); font-size: 13px; }
.ctrl-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ctrl-row select { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; }
.datepick { position: relative; display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 12px; cursor: pointer; min-width: 132px; }
.datepick:hover { border-color: var(--muted); }
.datepick .txt { color: var(--muted); }
.datepick.has .txt { color: var(--text); font-family: "Space Grotesk", sans-serif; }
.datepick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }
.datepick.disabled { opacity: .45; pointer-events: none; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 4px 0 8px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
#chart { width: 100%; min-height: 340px; }
#chart svg { display: block; }
#chart text { fill: var(--muted); font-family: "Space Grotesk", sans-serif; font-size: 11px; }
.chart-tip { position: fixed; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0, 0, 0, .3); z-index: 30; display: none; }
.chart-tip div { display: flex; gap: 8px; align-items: center; }
.chart-tip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* 弹窗与提示 */
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); padding: 0; width: min(380px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.dlg { padding: 20px; }
.dlg h3 { margin: 0 0 6px; font-size: 16px; }
.dlg input { width: 100%; margin-top: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.dlg-err { color: var(--over); font-size: 12px; min-height: 18px; margin-top: 6px; }
.dlg-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--over); color: #fff; }
.placeholder { text-align: center; padding: 80px 20px; color: var(--muted); }
.placeholder h2 { color: var(--text); font-size: 18px; margin: 0 0 8px; }
