:root {
  color-scheme: dark;
  --bg: #0d1014;
  --bg-elevated: #11161c;
  --surface: #151b22;
  --surface-soft: #19212a;
  --surface-strong: #202a34;
  --surface-input: #0b0f14;
  --line: #2b3642;
  --line-soft: rgba(255, 255, 255, 0.075);
  --text: #f3f7fb;
  --text-soft: #cbd5df;
  --muted: #8795a3;
  --accent: #32d296;
  --accent-strong: #8ee8bf;
  --accent-soft: rgba(50, 210, 150, 0.14);
  --blue: #6fa8ff;
  --blue-soft: rgba(111, 168, 255, 0.16);
  --warning: #f4bf50;
  --warning-soft: rgba(244, 191, 80, 0.14);
  --danger: #ff756f;
  --danger-soft: rgba(255, 117, 111, 0.13);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(17, 23, 31, 0.96), rgba(12, 15, 19, 0.98) 42%, #0b0e12),
    var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

::selection {
  background: rgba(50, 210, 150, 0.28);
}

.admin-shell {
  width: min(1540px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.admin-topbar,
.panel,
.metric-card,
.manage-card,
.modal-panel {
  border: 1px solid var(--line);
  background: rgba(21, 27, 34, 0.92);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.035) inset;
}

.admin-topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(520px, auto);
  gap: 24px;
  align-items: center;
  min-height: 86px;
  padding: 18px 20px;
  border-radius: 8px;
}

.brand-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.15;
}

h2 {
  font-size: 18px;
  line-height: 1.3;
}

h3 {
  font-size: 15px;
  line-height: 1.3;
}

.topbar-actions {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 118px 86px;
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-input);
  color: var(--text);
  outline: none;
  transition: border-color 0.14s ease, background 0.14s ease, box-shadow 0.14s ease;
}

input,
select {
  height: 40px;
  padding: 0 12px;
}

textarea {
  padding: 10px 12px;
  line-height: 1.55;
}

select {
  appearance: none;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 16px) 17px / 6px 6px no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 11px) 17px / 6px 6px no-repeat,
    var(--surface-input);
  padding-right: 30px;
}

input::placeholder,
textarea::placeholder {
  color: rgba(135, 149, 163, 0.78);
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(50, 210, 150, 0.72);
  background: #0d1319;
  box-shadow: 0 0 0 3px rgba(50, 210, 150, 0.11);
}

.server-status {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(11, 15, 20, 0.78);
  font-size: 13px;
  font-weight: 800;
}

.server-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.server-status.ok {
  color: var(--accent-strong);
  border-color: rgba(50, 210, 150, 0.32);
  background: rgba(50, 210, 150, 0.09);
}

.server-status.error {
  color: var(--danger);
  border-color: rgba(255, 117, 111, 0.35);
  background: var(--danger-soft);
}

.primary-button,
.secondary-button,
.small-button {
  min-height: 40px;
  border-radius: 7px;
  border: 1px solid var(--line);
  font-weight: 900;
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease, color 0.14s ease;
}

.primary-button {
  color: #061610;
  border-color: transparent;
  background: linear-gradient(180deg, #61e7af, var(--accent));
}

.secondary-button,
.small-button {
  color: var(--text-soft);
  background: var(--surface-strong);
}

.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled),
.small-button:hover:not(:disabled),
.manage-card:hover {
  transform: translateY(-1px);
}

.secondary-button:hover:not(:disabled),
.small-button:hover:not(:disabled) {
  color: var(--text);
  border-color: rgba(111, 168, 255, 0.45);
  background: #263340;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.metric-asset {
  grid-column: span 2;
}

.metric-finance {
  grid-column: span 1;
}

.metric-business {
  grid-column: span 1;
}

.metric-card {
  position: relative;
  min-height: 132px;
  overflow: hidden;
  border-radius: 8px;
  padding: 18px;
}

.metric-card::after {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, rgba(111, 168, 255, 0.7), rgba(50, 210, 150, 0.7), transparent);
  opacity: 0.72;
}

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

.metric-card strong {
  display: block;
  margin-top: 14px;
  font-size: 34px;
  line-height: 1;
  letter-spacing: 0;
}

.metric-card small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.primary-metric strong {
  color: var(--warning);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 16px;
  align-items: start;
  margin-top: 16px;
}

.panel {
  border-radius: 8px;
  padding: 18px;
}

.panel-head {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(420px, 52%);
  gap: 18px;
  align-items: start;
}

.panel-head p {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.license-panel {
  min-height: calc(100vh - 270px);
}

.quick-create-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 112px 88px;
  gap: 9px;
  align-items: end;
}

.created-key {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  border: 1px solid rgba(50, 210, 150, 0.35);
  background: rgba(50, 210, 150, 0.08);
  border-radius: 8px;
  padding: 13px;
  cursor: pointer;
}

.created-key span {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

code {
  color: var(--accent-strong);
  word-break: break-all;
  font-family: "Cascadia Mono", Consolas, monospace;
}

.search-field {
  margin-top: 16px;
}

.license-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 392px);
  margin-top: 14px;
  overflow: auto;
  padding-right: 4px;
}

.license-list::-webkit-scrollbar,
.modal-panel::-webkit-scrollbar {
  width: 8px;
}

.license-list::-webkit-scrollbar-thumb,
.modal-panel::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(135, 149, 163, 0.32);
}

.license-card {
  display: grid;
  gap: 12px;
  border: 1px solid rgba(43, 54, 66, 0.82);
  border-radius: 8px;
  background: rgba(12, 17, 22, 0.58);
  padding: 14px;
  transition: border-color 0.14s ease, background 0.14s ease;
}

.license-card:hover {
  border-color: rgba(111, 168, 255, 0.34);
  background: rgba(17, 24, 31, 0.78);
}

.license-card-head,
.license-card-foot {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.license-card h3 {
  margin-bottom: 7px;
  font-size: 16px;
}

.license-card code {
  display: block;
  max-width: 100%;
  color: #9fd6ff;
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.license-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 9px;
}

.license-stats div {
  border: 1px solid rgba(43, 54, 66, 0.82);
  border-radius: 7px;
  padding: 10px;
  background: rgba(25, 33, 42, 0.62);
}

.license-stats span,
.license-card-foot > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.license-stats strong {
  display: block;
  margin-top: 6px;
  font-size: 15px;
}

.license-stats small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  color: #061610;
  background: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.small-button {
  min-height: 32px;
  padding: 0 11px;
}

.danger-button {
  color: #ffd9d7;
  border-color: rgba(255, 117, 111, 0.34);
  background: rgba(255, 117, 111, 0.12);
}

.danger-button:hover:not(:disabled) {
  border-color: rgba(255, 117, 111, 0.55);
  background: rgba(255, 117, 111, 0.18);
}

.license-card.search-hit {
  background: rgba(50, 210, 150, 0.1);
  transition: background 0.2s ease;
}

.manage-column {
  display: grid;
  gap: 12px;
  position: sticky;
  top: 18px;
}

.manage-card {
  position: relative;
  display: grid;
  gap: 8px;
  min-height: 118px;
  overflow: hidden;
  padding: 17px;
  border-radius: 8px;
  text-align: left;
  color: var(--text);
  background: rgba(21, 27, 34, 0.92);
}

.manage-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 3px;
  height: 100%;
  background: linear-gradient(180deg, var(--blue), var(--accent));
  opacity: 0.86;
}

.manage-card:hover {
  border-color: rgba(111, 168, 255, 0.44);
  background: rgba(25, 33, 42, 0.96);
}

.manage-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.manage-card strong {
  font-size: 19px;
  line-height: 1.25;
}

.manage-card small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.usage-preview {
  display: grid;
  gap: 6px;
  margin-top: 4px;
}

.usage-preview .usage-item {
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 7px 0 0;
  font-size: 12px;
}

.usage-preview .usage-time,
.usage-preview .usage-model,
.usage-preview .usage-detail {
  display: none;
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(5, 8, 11, 0.72);
  backdrop-filter: blur(12px);
}

.modal-layer[hidden] {
  display: none;
}

.modal-panel {
  width: min(1040px, calc(100vw - 56px));
  max-height: calc(100vh - 56px);
  overflow: auto;
  border-radius: 8px;
  padding: 20px;
  box-shadow: var(--shadow);
}

#billingModal .modal-panel {
  width: min(1380px, calc(100vw - 56px));
}

.compact-modal {
  width: min(620px, calc(100vw - 56px));
}

.finance-modal {
  width: min(980px, calc(100vw - 56px));
}

.finance-summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.finance-summary-card {
  display: grid;
  gap: 8px;
  min-height: 112px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(12, 17, 22, 0.58);
}

.finance-summary-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.finance-summary-card strong {
  color: var(--text);
  font-size: 22px;
  line-height: 1.1;
}

.finance-summary-card small {
  color: var(--text-soft);
  font-size: 12px;
}

.finance-actions {
  display: grid;
  gap: 10px;
  justify-items: start;
}

.provider-asset-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.provider-asset-card {
  display: grid;
  gap: 14px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(12, 17, 22, 0.58);
}

.provider-asset-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.provider-asset-card strong {
  display: block;
  margin-top: 7px;
  font-size: 28px;
}

.provider-asset-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.provider-asset-metrics p {
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(25, 33, 42, 0.62);
}

.provider-asset-metrics b,
.provider-asset-metrics small {
  display: block;
}

.provider-recharge-log {
  display: grid;
  gap: 6px;
  max-height: 110px;
  overflow: auto;
}

.asset-warning {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 181, 72, 0.38);
  border-radius: 8px;
  color: #ffd99a;
  background: rgba(255, 181, 72, 0.11);
  font-weight: 800;
}

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

.system-status-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(12, 17, 22, 0.58);
}

.modal-section-title {
  margin: 4px 0 0;
  color: var(--text);
  font-size: 15px;
}

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

.close-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text-soft);
  background: var(--surface-strong);
  font-size: 20px;
  line-height: 1;
}

.close-button:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.18);
}

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

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

.provider-pool-row {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(12, 17, 22, 0.45);
}

.asset-form-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.form-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.settings-grid {
  display: grid;
  gap: 14px;
}

.settings-section {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 13px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(12, 17, 22, 0.45);
}

.settings-section h3 {
  grid-column: 1 / -1;
}

.advanced-api-panel {
  width: min(1180px, calc(100vw - 48px));
}

.advanced-api-grid .settings-section {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.advanced-api-grid .settings-section label.wide-field {
  grid-column: 1 / -1;
}

.advanced-api-grid textarea {
  min-height: 82px;
  resize: vertical;
}

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

.advanced-api-hint {
  padding: 0 2px;
}

.secret-field {
  grid-column: 1 / -1;
}

.secret-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px;
  gap: 8px;
}

.settings-save-button {
  justify-self: end;
  width: min(280px, 100%);
}

.billing-form {
  display: grid;
  gap: 12px;
}

.billing-table-head,
.billing-row {
  display: grid;
  grid-template-columns: minmax(170px, 1.2fr) minmax(160px, 1fr) repeat(8, minmax(94px, 0.72fr));
  gap: 10px;
  align-items: center;
  min-width: 1120px;
}

.billing-table-head {
  position: sticky;
  top: -20px;
  z-index: 2;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(21, 27, 34, 0.98);
}

.billing-model-list {
  display: grid;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.billing-provider-group {
  display: grid;
  gap: 8px;
  min-width: 1120px;
  padding: 10px;
  border: 1px solid rgba(43, 54, 66, 0.7);
  border-radius: 8px;
  background: rgba(8, 12, 17, 0.36);
}

.billing-provider-group h3 {
  color: var(--text);
  font-size: 14px;
}

.billing-row {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(12, 17, 22, 0.45);
}

.billing-row.billing-loss,
.billing-row.billing-missing-api {
  border-color: rgba(255, 117, 111, 0.55);
  background: rgba(255, 117, 111, 0.1);
}

.billing-row strong {
  font-size: 13px;
}

.billing-row input,
.billing-row select {
  height: 38px;
  font-size: 13px;
}

.billing-row small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 11px;
}

.usage-list {
  display: grid;
  gap: 8px;
}

.usage-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.filter-chip {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-soft);
  background: rgba(12, 17, 22, 0.7);
  font-size: 12px;
  font-weight: 900;
}

.filter-chip.active,
.filter-chip:hover {
  color: var(--text);
  border-color: rgba(111, 168, 255, 0.48);
  background: rgba(111, 168, 255, 0.15);
}

.usage-item {
  display: grid;
  grid-template-columns: minmax(130px, 1.1fr) minmax(110px, 0.9fr) minmax(160px, auto) auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

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

.usage-time {
  white-space: nowrap;
}

.empty {
  color: var(--muted);
  padding: 10px 0;
}

@media (max-width: 1120px) {
  .admin-topbar,
  .content-grid,
  .panel-head,
  .topbar-actions {
    grid-template-columns: 1fr;
  }

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

  .provider-asset-list,
  .license-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .manage-column {
    position: static;
  }
}

@media (max-width: 820px) {
  .admin-shell {
    width: min(100vw - 20px, 1540px);
    padding-top: 12px;
  }

  .overview-grid,
  .quick-create-form,
  .settings-section,
  .finance-summary-grid,
  .provider-asset-list,
  .provider-pool-fields {
    grid-template-columns: 1fr;
  }

  .license-stats {
    grid-template-columns: 1fr;
  }

  .license-list {
    max-height: none;
  }

  .usage-item {
    grid-template-columns: 1fr;
  }
}
