:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --blue: #2f67ed;
  --blue-soft: #edf4ff;
  --green: #16a34a;
  --green-soft: #ecfdf3;
  --red: #dc2626;
  --red-soft: #fff1f2;
  --orange: #f59e0b;
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(47, 103, 237, 0.22);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.brand, .account-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand { padding: 0 8px 22px; border-bottom: 1px solid var(--line); }
.brand-mark {
  width: 46px;
  height: 46px;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: var(--blue);
  font-size: 22px;
  font-weight: 800;
}
.brand strong, .brand small, .account-card strong, .account-card small { display: block; }
.brand strong { font-size: 18px; }
.brand small, .account-card small { margin-top: 3px; color: var(--muted); font-size: 12px; }

.account-card { padding: 18px 8px; border-bottom: 1px solid var(--line); }
.account-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--blue);
  background: var(--blue-soft);
}
.account-card strong { max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-list { display: grid; gap: 8px; padding-top: 18px; }
.nav-item {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: #344054;
  background: transparent;
  text-align: left;
}
.nav-item span { width: 22px; color: #667085; text-align: center; }
.nav-item:hover { background: #f7f9fc; }
.nav-item.active { color: var(--blue); border-color: #cfe0ff; background: var(--blue-soft); }
.nav-item.active span { color: var(--blue); }

.main { min-width: 0; }
.app-header {
  min-height: 74px;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.app-header h1 { margin: 0; font-size: 24px; }
.app-header p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.header-actions { display: flex; align-items: center; gap: 14px; }
.freshness { color: var(--muted); font-size: 12px; }

.page-content { padding: 24px 28px 42px; }
.filter-row {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
input, select {
  min-width: 124px;
  height: 42px;
  padding: 0 12px;
  color: var(--text);
  background: #fff;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
}
.search-control { flex: 1; min-width: 230px; }
.search-control input { width: 100%; }

.ghost-button, .primary-button, .text-button {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  font-weight: 700;
}
.ghost-button {
  color: #344054;
  border: 1px solid #d0d5dd;
  background: #fff;
}
.ghost-button:hover { border-color: #98a2b3; }
.ghost-button:disabled { opacity: 0.45; cursor: not-allowed; }
.primary-button { color: #fff; border: 1px solid var(--blue); background: var(--blue); }
.text-button {
  min-height: 36px;
  padding: 0 8px;
  color: var(--blue);
  border: 0;
  background: transparent;
}

.tab-bar, .subtabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
}
.tab-bar {
  margin-bottom: 16px;
  padding: 0 16px;
  border-radius: 12px;
}
.subtabs {
  margin: 0 0 16px;
  padding: 8px;
  border-radius: 10px;
  background: #f8fafc;
}
.tab-bar button, .subtabs button {
  flex: 0 0 auto;
  min-height: 50px;
  padding: 0 18px;
  color: #667085;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
}
.subtabs button { min-height: 38px; border-radius: 7px; border-bottom: 0; }
.tab-bar button.active { color: var(--blue); border-bottom-color: var(--blue); }
.subtabs button.active { color: var(--blue); background: #fff; box-shadow: 0 1px 3px rgba(16,24,40,.08); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.metric-card {
  min-height: 96px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.metric-card.blue { background: var(--blue-soft); border-color: #d7e5ff; }
.metric-card.green { background: var(--green-soft); border-color: #bbf7d0; }
.metric-card.red { background: var(--red-soft); border-color: #fecdd3; }
.metric-card span { color: var(--muted); font-size: 13px; }
.metric-card strong { display: block; margin-top: 10px; font-size: clamp(20px, 2vw, 28px); font-variant-numeric: tabular-nums; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.panel {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel.wide { grid-column: span 2; }
.panel > header, .report-viewer > header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
.panel h2, .report-list h2, .report-viewer h2 { margin: 0; font-size: 18px; }
.panel header span, .report-viewer header span { color: var(--muted); font-size: 12px; }
.table-panel { padding: 0; overflow: hidden; }
.table-panel > header { padding: 18px 20px 0; }

.key-value, .cost-breakdown {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.key-value span, .cost-breakdown div {
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
}
.key-value strong, .cost-breakdown strong { display: block; margin-top: 6px; color: var(--text); font-size: 16px; }
.count-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.count-grid div { padding: 14px; text-align: center; border-radius: 9px; background: var(--surface-soft); }
.count-grid strong, .count-grid span { display: block; }
.count-grid strong { font-size: 26px; }
.count-grid span { margin-top: 4px; color: var(--muted); font-size: 12px; }

.trend-chart {
  min-height: 170px;
  display: flex;
  align-items: end;
  justify-content: space-around;
  gap: 8px;
  padding: 12px 8px 0;
  border-bottom: 1px solid var(--line);
}
.trend-column { flex: 1; display: grid; justify-items: center; gap: 8px; }
.trend-column span { color: var(--muted); font-size: 11px; }
.trend-bar { width: min(26px, 70%); min-height: 4px; border-radius: 5px 5px 0 0; background: var(--blue); }
.trend-bar.negative { background: var(--red); }

.match-summary { min-height: 190px; display: grid; place-content: center; text-align: center; }
.match-summary strong { color: var(--green); font-size: 30px; }
.match-summary span, .match-summary em { display: block; margin-top: 6px; color: var(--muted); font-style: normal; }
.match-summary em { color: var(--red); }
.compare-list { display: grid; gap: 18px; }
.compare-list header { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 7px; }
.compare-list small { color: var(--muted); }
.compare-list i { display: block; height: 10px; margin: 4px 0; border-radius: 999px; }
.compare-list .current { background: var(--blue); }
.compare-list .previous { background: #a7b0bf; }

.table-scroll { overflow: auto; }
table { width: 100%; min-width: 980px; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; font-size: 13px; }
th { color: var(--muted); background: #fafbfc; font-weight: 700; }
tbody tr:hover { background: #f8faff; }
.status { display: inline-flex; padding: 4px 9px; border-radius: 999px; color: #344054; background: #f2f4f7; font-size: 12px; }
.mobile-list { display: none; }

.pager {
  min-height: 58px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
}
.pager span { color: var(--muted); font-size: 12px; }
.empty-panel, .error-panel, .loading {
  min-height: 220px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 30px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed #d0d5dd;
  border-radius: 12px;
  background: var(--surface);
}
.empty-panel strong, .error-panel strong { color: var(--text); }
.loading span {
  width: 28px;
  height: 28px;
  border: 3px solid #d8e3ff;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.notice { margin-top: 16px; padding: 14px 16px; color: #92400e; background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; }
.muted { color: var(--muted); }

.report-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; }
.report-list, .report-viewer {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.report-list { display: grid; align-content: start; gap: 10px; }
.report-card {
  min-height: 92px;
  display: grid;
  gap: 5px;
  padding: 14px;
  color: var(--text);
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
}
.report-card:hover { border-color: #a9c4ff; background: var(--blue-soft); }
.report-card span, .report-card small { color: var(--muted); font-size: 12px; }
.report-viewer { min-height: 520px; }
.markdown-body { line-height: 1.75; overflow-wrap: anywhere; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 22px 0 12px; }
.markdown-body h1 { font-size: 24px; }
.markdown-body h2 { font-size: 20px; }
.markdown-body h3 { font-size: 17px; }

dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(16, 24, 40, .18);
}
dialog::backdrop { background: rgba(15, 23, 42, .42); }
.login-dialog { width: min(430px, calc(100vw - 28px)); padding: 0; }
.login-form { display: grid; gap: 16px; padding: 28px; }
.login-form h2, .login-form p { margin: 0; }
.login-form p { color: var(--muted); line-height: 1.55; font-size: 13px; }
.login-form input { width: 100%; }
.login-brand { display: flex; align-items: center; gap: 10px; }
.detail-dialog { width: min(920px, calc(100vw - 28px)); max-height: 88vh; padding: 0; }
.detail-shell { max-height: 88vh; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.detail-shell > header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.detail-shell h2 { margin: 0; font-size: 18px; }
.detail-body { overflow: auto; padding: 20px; }
.detail-list { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--line); }
.detail-list div { min-width: 0; padding: 12px; background: #fff; }
.detail-list dt { color: var(--muted); font-size: 12px; }
.detail-list dd { margin: 6px 0 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.detail-list pre { max-height: 280px; overflow: auto; margin: 0; white-space: pre-wrap; }
.primary-link { color: var(--blue); font-weight: 700; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: 380px; padding: 13px 16px; color: #fff; background: #111827; border-radius: 9px; box-shadow: var(--shadow); }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 220px minmax(0, 1fr); }
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-shell { display: block; padding-bottom: 72px; }
  .sidebar {
    position: static;
    height: auto;
    padding: 12px 14px 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0 0 10px; border: 0; }
  .brand-mark { width: 38px; height: 38px; border-radius: 9px; font-size: 18px; }
  .account-card { display: none; }
  .nav-list {
    position: fixed;
    inset: auto 0 0;
    z-index: 10;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    padding: 7px 8px max(7px, env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid var(--line);
  }
  .nav-item {
    min-height: 52px;
    display: grid;
    justify-items: center;
    gap: 2px;
    padding: 4px;
    font-size: 12px;
  }
  .nav-item span { width: auto; }
  .app-header { min-height: 62px; padding: 10px 16px; }
  .app-header h1 { font-size: 20px; }
  .app-header p, .freshness { display: none; }
  .page-content { padding: 14px 14px 28px; }
  .filter-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px; }
  .filter-row label, input, select { min-width: 0; width: 100%; }
  .search-control { grid-column: 1 / -1; min-width: 0; }
  .tab-bar { padding: 0 8px; }
  .tab-bar button { min-height: 44px; padding: 0 13px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-card { min-height: 86px; padding: 13px; }
  .metric-card strong { font-size: 20px; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .panel.wide { grid-column: auto; }
  .key-value { grid-template-columns: 1fr 1fr; }
  .table-scroll { display: none; }
  .mobile-list { display: grid; gap: 10px; padding: 0 12px 12px; }
  .mobile-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; }
  .mobile-row div { min-width: 0; }
  .mobile-row span, .mobile-row strong { display: block; overflow-wrap: anywhere; }
  .mobile-row span { color: var(--muted); font-size: 11px; }
  .mobile-row strong { margin-top: 3px; font-size: 13px; }
  .mobile-row button { grid-column: 1 / -1; width: 100%; min-height: 44px; }
  .pager { justify-content: center; flex-wrap: wrap; }
  .report-layout { grid-template-columns: 1fr; }
  .report-viewer { min-height: 340px; }
  .detail-list { grid-template-columns: 1fr; }
}

@media (max-width: 390px) {
  .header-actions { gap: 6px; }
  .ghost-button { padding: 0 10px; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric-card strong { font-size: 18px; }
}
