:root {
  --bg: #f3f5f8;
  --bg-deep: #eef2f7;
  --card: #ffffff;
  --text: #172033;
  --text-soft: #344054;
  --muted: #667085;
  --muted-2: #98a2b3;
  --border: #e4e9f0;
  --border-strong: #d0d5dd;
  --accent: #2f6bff;
  --accent-dark: #1d4ed8;
  --accent-soft: #eef4ff;
  --danger: #d92d20;
  --danger-soft: #fef3f2;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --success: #027a48;
  --success-soft: #ecfdf3;
  --purple: #7c3aed;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 10px 28px rgba(16, 24, 40, .045);
  --radius: 14px;
  --font: "Inter", "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: var(--accent-dark); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 26px 32px 42px;
}

/* ---------- 顶部栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 11px;
  background-color: var(--accent);
  background-image:
    linear-gradient(#fff, #fff),
    linear-gradient(#fff, #fff),
    linear-gradient(#fff, #fff);
  background-size: 4px 11px, 4px 17px, 4px 7px;
  background-position: 9px 18px, 17px 12px, 25px 22px;
  background-repeat: no-repeat;
  box-shadow: 0 6px 14px rgba(47, 107, 255, .28);
}

.brand-kicker {
  margin: 0 0 1px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .16em;
  color: var(--muted-2);
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: -.01em;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted-2);
}

.status-pill.is-ok .status-dot { background: #12b76a; box-shadow: 0 0 0 3px var(--success-soft); }
.status-pill.is-warn .status-dot { background: #f79009; box-shadow: 0 0 0 3px var(--warning-soft); }
.status-pill.is-error .status-dot { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.status-pill.is-loading .status-dot { animation: pulse 1.2s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: .35; transform: scale(.85); }
  50% { opacity: 1; transform: scale(1); }
}

.updated-at {
  color: var(--muted-2);
  font-size: 12px;
  white-space: nowrap;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.inline-form { display: inline; margin: 0; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}

.btn:active { transform: translateY(1px); }

.btn-ghost {
  border-color: var(--border-strong);
  background: var(--card);
}
.btn-ghost:hover { border-color: #b8c2d1; background: #fbfcfe; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 14px rgba(47, 107, 255, .22);
}
.btn-primary:hover { background: var(--accent-dark); }

.btn-sm { height: 32px; padding: 0 11px; font-size: 12px; }
.btn-block { width: 100%; height: 44px; font-size: 14px; }

.btn:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(47, 107, 255, .22);
  outline-offset: 1px;
}

/* ---------- 提示 ---------- */
.alert {
  margin: 0 0 16px;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.6;
}
.alert-warning { border-color: #fedf89; background: var(--warning-soft); color: #93370d; }
.alert-error { border-color: #fecdca; background: var(--danger-soft); color: #912018; }

/* ---------- 页头 ---------- */
.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin: 26px 0 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.hero h2 {
  margin: 0;
  font-size: 30px;
  line-height: 1.2;
  letter-spacing: -.03em;
}

.hero-sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  word-break: break-all;
}

.hero-note {
  max-width: 440px;
  padding: 10px 14px;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: var(--accent-soft);
  color: #344054;
  font-size: 12px;
  line-height: 1.65;
}

/* ---------- KPI ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
}

.kpi-card {
  position: relative;
  overflow: hidden;
  padding: 17px 18px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  animation: rise .35s ease both;
}

.kpi-card::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 3px;
  background: var(--accent);
  opacity: .85;
}
.kpi-card:nth-child(2)::before { background: #0e9384; }
.kpi-card:nth-child(3)::before { background: #7c3aed; }
.kpi-card:nth-child(4)::before { background: #2f6bff; }
.kpi-card:nth-child(5)::before { background: #f79009; }
.kpi-card:nth-child(6)::before { background: #d92d20; }

.kpi-label {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 5px;
  min-width: 0;
}

.kpi-value {
  font-size: 27px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.kpi-unit { color: var(--muted); font-size: 12px; white-space: nowrap; }

.kpi-sub {
  margin: 6px 0 0;
  color: var(--muted-2);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 图表 ---------- */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.span-7 { grid-column: span 7; }
.span-5 { grid-column: span 5; }

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

.chart-card { padding: 18px 18px 12px; min-width: 0; }

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.card-head h3,
.section-head h3 {
  margin: 0;
  font-size: 15px;
  letter-spacing: -.01em;
}

.card-head p,
.section-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.card-tag {
  flex: 0 0 auto;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f2f4f7;
  color: var(--muted);
  font-size: 11px;
}

.chart { width: 100%; height: 292px; }

.hv-chart {
  display: flex;
  height: 100%;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
}

.hv-row {
  display: grid;
  grid-template-columns: minmax(72px, 34%) 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 20px;
}

.hv-label {
  color: #475467;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hv-track {
  height: 14px;
  overflow: hidden;
  border-radius: 4px;
  background: #f2f4f7;
}

.hv-bar {
  height: 100%;
  min-width: 2px;
  border-radius: 0 4px 4px 0;
  transition: width .3s ease;
}

.hv-value {
  min-width: 44px;
  color: #475467;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.hv-row:hover .hv-track { box-shadow: inset 0 0 0 1px var(--border-strong); }

.chart-empty {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: center;
  color: var(--muted-2);
  font-size: 12px;
}

.donut-wrap {
  display: flex;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.donut {
  position: relative;
  width: 150px;
  height: 150px;
  border-radius: 50%;
}

.donut-hole {
  position: absolute;
  inset: 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--card);
}

.donut-hole strong {
  font-size: 26px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.donut-hole span { color: var(--muted); font-size: 11px; }

.donut-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px 14px;
  color: var(--muted);
  font-size: 11px;
}

.donut-legend-item { display: inline-flex; align-items: center; gap: 5px; }

.donut-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.data-note {
  margin: 14px 2px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

/* ---------- 明细表 ---------- */
.table-card { margin-top: 14px; padding: 18px 0 6px; }

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px 14px;
}

.muted { color: var(--muted); }

.table-actions { display: flex; gap: 8px; }

.toolbar {
  display: flex;
  gap: 9px;
  padding: 0 18px 14px;
}

.search-box { flex: 1 1 260px; min-width: 180px; }

.toolbar input,
.toolbar select {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--card);
  color: var(--text);
  font-size: 13px;
}
.toolbar input::placeholder { color: var(--muted-2); }
.toolbar select { flex: 0 0 auto; width: auto; min-width: 128px; padding-right: 28px; }

.table-wrap {
  max-height: 760px;
  overflow: auto;
  border-top: 1px solid var(--border);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
  letter-spacing: .02em;
}

.data-table thead th:first-child { padding-left: 18px; }
.data-table thead th:last-child { padding-right: 18px; }

.data-table tbody td {
  padding: 13px 12px;
  border-bottom: 1px solid #eef2f7;
  vertical-align: top;
}

.data-table tbody td:first-child { padding-left: 18px; }
.data-table tbody td:last-child { padding-right: 18px; }

.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table tbody tr.customer-row { cursor: pointer; }
.data-table tbody tr.customer-row:hover { background: #fbfcff; }
.data-table tbody tr.customer-row.is-open { background: #f8faff; }

.customer-cell {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  max-width: 360px;
}

.customer-cell > div {
  flex: 1 1 auto;
  min-width: 0;
}

.customer-name {
  font-weight: 650;
  color: var(--text);
  word-break: break-word;
  overflow-wrap: anywhere;
}

.customer-sub {
  margin-top: 2px;
  color: var(--muted-2);
  font-size: 11px;
  line-height: 1.5;
  word-break: break-word;
}

.expand-btn {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--muted);
  font-size: 12px;
  line-height: 20px;
  transition: transform .15s ease, background .15s ease;
}
.customer-row.is-open .expand-btn { transform: rotate(90deg); background: var(--accent-soft); color: var(--accent-dark); }

.money { font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.money-zero { color: var(--muted-2); font-weight: 500; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}
.badge-danger { background: var(--danger-soft); color: #b42318; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-muted { background: #f2f4f7; color: var(--muted); }
.badge-info { background: var(--accent-soft); color: var(--accent-dark); }

.chips { display: flex; flex-wrap: wrap; gap: 4px; max-width: 220px; }
.chip {
  display: inline-flex;
  padding: 1px 7px;
  border-radius: 6px;
  background: #f2f4f7;
  color: #475467;
  font-size: 11px;
  white-space: nowrap;
}

.row-arrow { color: var(--muted-2); font-size: 16px; line-height: 1; }

.detail-row > td {
  padding: 0 18px 16px !important;
  background: #fbfcff;
}

.service-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 2px 0 2px 31px;
}

.service-list > .service-card:only-child { grid-column: 1 / -1; }

.service-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  padding: 12px 13px;
  min-width: 0;
}

.service-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 9px;
}

.service-type {
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 700;
}

.service-id {
  color: var(--muted);
  font-size: 11px;
  word-break: break-all;
}

.service-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  margin: 0;
}

.service-fields > div { min-width: 0; }
.service-fields dt { margin: 0 0 2px; color: var(--muted-2); font-size: 10px; font-weight: 600; }
.service-fields dd { margin: 0; color: var(--text-soft); font-size: 12px; line-height: 1.55; word-break: break-word; white-space: pre-wrap; }

.service-fields .full { grid-column: 1 / -1; }

.service-more {
  margin-top: 9px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}
.service-more summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 600;
  list-style: none;
}
.service-more summary::-webkit-details-marker { display: none; }
.service-more summary::before { content: "＋ "; }
.service-more[open] summary::before { content: "－ "; }
.service-more p { margin: 6px 0 0; color: var(--text-soft); font-size: 12px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.service-more p strong { color: var(--muted); font-weight: 600; }

.empty-state {
  padding: 34px 18px 40px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--muted-2);
  font-size: 11px;
}

/* ---------- 登录页 ---------- */
.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 12% 8%, rgba(47, 107, 255, .10), transparent 60%),
    radial-gradient(700px 430px at 92% 92%, rgba(124, 58, 237, .09), transparent 62%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 410px;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--card);
  box-shadow: 0 24px 60px rgba(16, 24, 40, .10);
}

.login-card .brand { margin-bottom: 18px; }
.login-card .brand h1 { font-size: 20px; }

.login-subtitle {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.login-form { display: grid; gap: 14px; }

.login-form label { display: grid; gap: 6px; }
.login-form label > span { color: var(--text-soft); font-size: 12px; font-weight: 650; }
.login-form input {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: #fcfdff;
  font-size: 14px;
}
.login-form input:focus { border-color: var(--accent); background: #fff; }

.login-foot {
  margin: 18px 0 0;
  color: var(--muted-2);
  font-size: 11px;
  text-align: center;
}

/* ---------- 响应式 ---------- */
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .span-7, .span-5 { grid-column: span 12; }
  .chart { height: 300px; }
}

@media (max-width: 900px) {
  .shell { padding: 20px 18px 32px; }
  .topbar { flex-wrap: wrap; }
  .topbar-meta { order: 3; width: 100%; margin-left: 0; }
  .topbar-actions { margin-left: auto; }
  .hero { align-items: flex-start; flex-direction: column; gap: 12px; }
  .hero-note { max-width: none; width: 100%; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .service-list { grid-template-columns: 1fr; padding-left: 0; }
  .table-wrap { max-height: none; }
  .data-table th:nth-child(3), .data-table td:nth-child(3),
  .data-table th:nth-child(5), .data-table td:nth-child(5),
  .data-table th:nth-child(7), .data-table td:nth-child(7) { display: none; }
  .toolbar { flex-wrap: wrap; }
  .search-box { flex: 1 1 100%; }
  .toolbar select { flex: 1 1 auto; }
  .footer { flex-direction: column; gap: 4px; }
}

@media (max-width: 560px) {
  .hero h2 { font-size: 25px; }
  .kpi-card { padding: 14px 15px; }
  .kpi-value { font-size: 24px; }
  .topbar-actions .btn { padding: 0 10px; }
  .updated-at { display: none; }
  .data-table th:nth-child(2), .data-table td:nth-child(2),
  .data-table th:nth-child(8), .data-table td:nth-child(8) { display: none; }
  #customer-table { table-layout: fixed; }
  #customer-table th:nth-child(1), #customer-table td:nth-child(1) { width: 54%; }
  #customer-table th:nth-child(4), #customer-table td:nth-child(4) { width: 27%; }
  #customer-table th:nth-child(6), #customer-table td:nth-child(6) { width: 19%; }
  .data-table thead th, .data-table tbody td { padding-left: 7px; padding-right: 7px; }
  .data-table thead th:first-child, .data-table tbody td:first-child { padding-left: 12px; }
  .data-table .money { font-size: 12px; }
  .customer-cell { max-width: 100%; }
  .customer-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .section-head { flex-direction: column; }
  .table-actions { align-self: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media print {
  .topbar-actions, .toolbar, .table-actions, .footer { display: none !important; }
  body { background: #fff; }
  .card, .kpi-card { box-shadow: none; }
  .table-wrap { max-height: none; overflow: visible; }
}
