:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #d8dee8;
  --line-soft: #e7ebf2;
  --text: #18212f;
  --muted: #6b7688;
  --accent: #2563eb;
  --accent-soft: #e8f0ff;
  --green: #13845b;
  --green-soft: #e8f7ef;
  --amber: #a65f00;
  --amber-soft: #fff4dc;
  --red: #c33445;
  --red-soft: #fff0f2;
  --violet: #6d4aff;
  --violet-soft: #f0edff;
  --shadow: 0 14px 34px rgba(22, 34, 51, 0.08);
  --radius: 8px;
  --sans: "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.admin-shell {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  background: #111827;
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f8fafc;
  color: #111827;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 4px;
  color: #aeb7c6;
  font-size: 12px;
}

.side-nav {
  display: grid;
  gap: 6px;
  padding-top: 18px;
}

.nav-item {
  height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: #253247;
  color: #fff;
}

.main {
  min-width: 0;
  padding: 18px 22px 40px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: -18px -22px 20px;
  padding: 14px 22px;
  background: rgba(244, 246, 249, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.global-search {
  display: grid;
  grid-template-columns: auto minmax(260px, 520px) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.global-search span {
  color: var(--muted);
  font-size: 13px;
}

.top-actions,
.head-actions,
.inline-controls,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

input,
select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  color: var(--text);
  background: #fff;
  outline: none;
}

input:focus,
select:focus {
  border-color: #7aa4ff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button {
  height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0 13px;
  white-space: nowrap;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.secondary-button {
  background: #eef2f7;
  color: var(--text);
}

.danger-button {
  background: var(--red-soft);
  color: var(--red);
}

.ghost-button {
  background: transparent;
  color: var(--accent);
}

.icon-button {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: #eef2f7;
  color: var(--text);
  font-size: 18px;
  line-height: 1;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.view-head h1 {
  font-size: 25px;
  letter-spacing: 0;
}

.view-head p,
.panel-head span,
.form-message {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric-card,
.panel,
.empty-card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 15px;
  min-height: 94px;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  display: block;
  margin-top: 9px;
  font-size: 25px;
  letter-spacing: 0;
}

.metric-card small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
}

.dashboard-grid,
.content-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.content-grid {
  grid-template-columns: 300px minmax(0, 1fr);
}

.panel {
  padding: 16px;
  margin-bottom: 14px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2 {
  font-size: 16px;
}

.wide-panel {
  min-width: 0;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(180px, 1.8fr) repeat(2, minmax(120px, 0.7fr)) repeat(2, minmax(130px, 0.7fr)) repeat(2, minmax(110px, 0.6fr)) auto;
  gap: 10px;
  margin-bottom: 14px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}

.data-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  background: #fff;
}

.data-table th,
.data-table td {
  padding: 12px 11px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.data-table th {
  background: #f8fafc;
  color: #526174;
  font-size: 12px;
  font-weight: 700;
}

.data-table tbody tr:hover {
  background: #fbfdff;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.member-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}

.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
}

.member-cell strong,
.member-cell span {
  display: block;
}

.member-cell span,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.tag-row,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge,
.status-pill,
.tag {
  display: inline-flex;
  align-items: center;
  height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.badge {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge.green,
.status-pill.success {
  background: var(--green-soft);
  color: var(--green);
}

.badge.amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.red,
.status-pill.danger {
  background: var(--red-soft);
  color: var(--red);
}

.badge.violet {
  background: var(--violet-soft);
  color: var(--violet);
}

.tag {
  background: #edf1f6;
  color: #526174;
}

.amount-positive {
  color: var(--green);
  font-weight: 700;
}

.amount-negative {
  color: var(--red);
  font-weight: 700;
}

.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding-top: 12px;
  color: var(--muted);
}

.chart {
  height: 250px;
  min-height: 250px;
}

.chart svg {
  width: 100%;
  height: 100%;
  display: block;
}

.chart .axis-label,
.chart .empty-label {
  fill: var(--muted);
  font-size: 12px;
}

.donut-wrap {
  display: grid;
  grid-template-columns: 180px 1fr;
  align-items: center;
  gap: 14px;
  min-height: 250px;
}

.donut-wrap svg {
  width: 180px;
  height: 180px;
}

.legend {
  display: grid;
  gap: 10px;
}

.legend-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.legend-item strong {
  color: var(--text);
}

.legend-color {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
}

.compact-list {
  display: grid;
  gap: 10px;
}

.compact-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-soft);
}

.package-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.package-card {
  min-height: 154px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.package-card strong {
  display: block;
  margin: 6px 0;
  font-size: 24px;
}

.package-card span,
.package-card small {
  display: block;
  color: var(--muted);
}

.rule-list {
  display: grid;
  gap: 12px;
}

.rule-list div {
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-soft);
}

.rule-list strong,
.rule-list span {
  display: block;
}

.rule-list span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.empty-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.empty-card {
  min-height: 120px;
  padding: 18px;
}

.empty-card strong,
.empty-card span {
  display: block;
}

.empty-card span {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.6;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.38);
}

.modal-backdrop.active {
  display: grid;
}

.modal {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 22px 70px rgba(15, 23, 42, 0.22);
  padding: 18px;
}

.modal-head,
.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 35;
  width: min(620px, 100%);
  height: 100vh;
  transform: translateX(100%);
  transition: transform 0.18s ease;
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 48px rgba(15, 23, 42, 0.16);
  padding: 18px;
  overflow-y: auto;
}

.drawer.active {
  transform: translateX(0);
}

.drawer-head p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.drawer-body {
  display: grid;
  gap: 14px;
}

.detail-section {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-soft);
}

.detail-section h3 {
  margin-bottom: 10px;
  font-size: 15px;
}

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

.detail-grid div {
  min-width: 0;
}

.detail-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.detail-grid strong {
  display: block;
  margin-top: 5px;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  display: none;
  max-width: min(420px, calc(100% - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
}

.toast.active {
  display: block;
}

@media (max-width: 1180px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .side-nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .metric-grid,
  .package-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid,
  .content-grid,
  .empty-grid {
    grid-template-columns: 1fr;
  }

  .filter-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .main {
    padding: 14px 12px 32px;
  }

  .topbar {
    position: static;
    flex-direction: column;
    align-items: stretch;
    margin: -14px -12px 16px;
    padding: 12px;
  }

  .global-search,
  .filter-bar,
  .side-nav,
  .metric-grid,
  .package-grid,
  .donut-wrap {
    grid-template-columns: 1fr;
  }

  .top-actions,
  .inline-controls,
  .view-head,
  .panel-head {
    flex-direction: column;
    align-items: stretch;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }
}
