:root {
  --navy: #0b1f33;
  --blue: #3d6fe0;
  --deep: #1e3a5f;
  --mid: #6f92e8;
  --light: #afc4f7;
  --pale: #dce6fb;
  --teal: #00a6a6;
  --ink: #0b1f33;
  --body: #44546a;
  --muted: #7c8a9e;
  --line: #e3e8ef;
  --line-strong: #b8c3d1;
  --bg: #f7f8fa;
  --card: #ffffff;
  --red: #d32f2f;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--body);
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 18px;
  background: #ffffff;
  color: var(--ink);
  border-bottom: 2px solid var(--blue);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: var(--navy); color: #ffffff;
  font-family: Georgia, "Songti SC", serif;
  font-weight: 700; font-size: 20px;
}
h1 {
  margin: 0; color: var(--ink);
  font-family: Georgia, "Songti SC", "Microsoft YaHei", serif;
  font-size: 21px; font-weight: 600; letter-spacing: .02em;
}
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 11px; letter-spacing: .02em; }
.actions { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.actions label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 10px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase;
}
input, select, button {
  font: inherit;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  padding: 7px 9px;
  background: white;
  color: var(--ink);
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid rgba(61, 111, 224, .2); outline-offset: 1px;
}
.actions input { width: 128px; }
button { cursor: pointer; background: var(--blue); color: white; border-color: var(--blue); font-weight: 600; }
button:hover { background: #2f5fd0; border-color: #2f5fd0; }
button.secondary { background: #ffffff; color: var(--navy); border-color: var(--line-strong); }
button.secondary:hover { border-color: var(--navy); background: #ffffff; }
button.ghost { background: white; color: var(--blue); border-color: var(--blue); }
button.ghost:hover { background: #eef2ff; }

main { width: 100%; max-width: none; margin: 0; padding: 14px 16px 28px; }
.hidden { display: none !important; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.error {
  padding: 12px 16px; margin-bottom: 14px;
  background: #fff5f5; color: var(--red);
  border: 1px solid #f3c4c4; border-left: 3px solid var(--red);
}

.cards {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}
.metric {
  background: var(--card); border: 1px solid var(--line);
  border-top: 2px solid var(--blue);
  padding: 12px 14px 10px;
}
.metric .label {
  color: var(--muted); font-size: 10px;
  letter-spacing: .1em; text-transform: uppercase;
}
.metric .value {
  margin-top: 6px; color: var(--ink);
  font-size: 24px; font-weight: 600; letter-spacing: -.02em;
}
.metric .note { margin-top: 4px; color: var(--muted); font-size: 11px; }

.card {
  background: var(--card); border: 1px solid var(--line);
}
.filters { padding: 12px 14px; margin-bottom: 10px; }
.filter-title { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 8px; }
.filter-breadcrumb { display: flex; align-items: center; gap: 10px; }
button.small { padding: 4px 9px; font-size: 11px; }
.filter-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px; align-items: end;
}
.filter-grid.multi {
  grid-template-columns: 1.3fr 1fr 1fr 1fr 1.1fr;
  align-items: start;
}
.filter-grid.multi > label,
.filter-grid.multi > div > label { min-width: 0; }
.filter-grid.multi > div { min-width: 0; }
.filter-grid > label,
.filter-grid > div > label {
  display: flex; flex-direction: column; gap: 4px;
  color: var(--muted); font-size: 11px;
}
.filter-grid > label > input,
.filter-grid > label > select { width: 100%; }

.grid {
  display: grid;
  grid-template-columns: 1.05fr 1.15fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
.chart-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}
.chart-card.wide { grid-column: 1 / -1; }
.chart-card { min-width: 0; }
.chart-wrap { position: relative; height: 320px; padding: 10px 10px 8px; }
.chart-wrap.tall { height: 410px; }
.tabs { display: flex; gap: 0; }
.tab {
  padding: 5px 11px; border-radius: 0;
  background: #ffffff; color: var(--body);
  border: 1px solid var(--line-strong); border-right: 0;
  font-weight: 500;
}
.tab:last-child { border-right: 1px solid var(--line-strong); }
.tab.active { background: var(--blue); color: white; border-color: var(--blue); }

.ms { position: relative; }
.ms-control {
  display: flex; flex-wrap: wrap; align-items: center; gap: 5px;
  min-height: 35px; padding: 4px 6px;
  background: #ffffff; border: 1px solid var(--line-strong);
  cursor: pointer;
}
.ms-control:hover { border-color: var(--mid); }
.ms-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.ms-chip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 5px 2px 7px; background: #eef2ff; color: var(--deep);
  font-size: 11px; white-space: nowrap;
}
.ms-chip button {
  padding: 0 2px; border: 0; background: none; color: var(--deep);
  font-size: 14px; font-weight: 400; line-height: 1;
}
.ms-chip button:hover { background: none; color: var(--navy); }
.ms-toggle {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 3px; border: 0; background: none;
  color: var(--muted); font-size: 11px; font-weight: 400;
}
.ms-toggle:hover { background: none; color: var(--blue); }
.ms-caret { font-size: 10px; line-height: 1; }
.ms-placeholder { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-panel {
  position: absolute; z-index: 40; left: 0; top: calc(100% + 5px);
  width: 400px; max-width: 82vw; background: #ffffff;
  border: 1px solid var(--line-strong);
  box-shadow: 0 14px 34px rgba(5, 28, 44, .16);
  display: none;
}
.ms.open .ms-panel { display: block; }
.ms-search-wrap { position: relative; padding: 8px 8px 0; }
.ms-search-icon {
  position: absolute; left: 17px; top: 16px;
  color: var(--muted); font-size: 15px; line-height: 1;
}
.ms-search {
  width: 100%; padding: 7px 8px 7px 28px;
  border: 1px solid var(--line); border-radius: 2px;
}
.ms-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 9px; border-bottom: 1px solid var(--line);
  color: var(--muted); font-size: 11px;
}
.ms-select-all { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.ms-select-all input { margin: 0; accent-color: var(--blue); }
.ms-options { max-height: 260px; overflow: auto; padding: 4px; }
.ms-option {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; cursor: pointer;
  font-size: 12px; white-space: normal;
}
.ms-option:hover { background: #f4f6ff; }
.ms-option input { margin: 0; accent-color: var(--blue); }
.ms-option-name { color: var(--ink); }
.ms-count { white-space: nowrap; }
.modal-filter .ms { min-width: 280px; }
.modal-filter .ms-control { min-width: 260px; }
.modal-filter {
  padding: 10px 18px; border-bottom: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
}
.modal-filter > label { color: var(--muted); font-size: 11px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px 9px; border-bottom: 1px solid var(--line);
}
.card-head h2 { margin: 0; color: var(--ink); font-size: 14px; font-weight: 600; letter-spacing: .01em; }
.card-head h2::before {
  content: ""; display: inline-block; width: 12px; height: 2px;
  margin-right: 8px; vertical-align: middle; background: var(--blue);
}
.muted { color: var(--muted); font-size: 11px; }
.card-head > div > .muted { display: block; margin-top: 3px; padding-left: 20px; }

.table-wrap { max-height: 360px; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid #eceff2; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th {
  position: sticky; top: 0; z-index: 2;
  background: #f2f4f7; color: var(--ink); font-weight: 600;
  font-size: 10px; letter-spacing: .05em;
}
tbody tr:hover { background: #f7f9ff; }
tbody tr.clickable { cursor: pointer; }
.name-cell { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 5px; background: #e8ecf2; overflow: hidden; min-width: 50px; }
.bar > span { display: block; height: 100%; background: var(--blue); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.footer {
  margin-top: 12px; padding-top: 8px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 10px; line-height: 1.8;
}
.tag { display: inline-block; padding: 2px 6px; background: #eef2ff; color: var(--blue); font-size: 10px; }
.tag.warn { background: #fff4e5; color: #a15c00; }
.negative { color: var(--red); }
.positive { color: var(--deep); }

.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5, 28, 44, .42);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal-card {
  width: min(1100px, 96vw); max-height: 88vh;
  background: white;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 70px rgba(5, 28, 44, .28);
}
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 18px; padding: 17px 20px; border-bottom: 2px solid var(--blue);
}
.modal-head h2 {
  margin: 0 0 4px; color: var(--ink);
  font-family: Georgia, "Songti SC", serif;
  font-size: 18px; font-weight: 600;
}
.modal-head p { margin: 0; }
.modal-actions { display: flex; gap: 8px; }
.modal-body { padding: 0 20px 20px; overflow: auto; }
.modal-body table { min-width: 760px; }
.modal-body th { top: 0; }

@media (max-width: 1180px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid { grid-template-columns: 1fr 1fr; }
  .filter-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .chart-grid { grid-template-columns: 1fr 1fr; }
  .chart-card.wide { grid-column: auto; }
}
@media (max-width: 760px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .cards, .grid, .filter-grid, .filter-grid.multi { grid-template-columns: 1fr; }
  .actions { justify-content: space-between; }
}
