:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --line: #dde3ec;
  --text: #111827;
  --muted: #667085;
  --faint: #98a2b3;
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --primary-soft: #e7f7f5;
  --blue: #2563eb;
  --blue-soft: #e8efff;
  --amber: #b7791f;
  --amber-soft: #fff4d6;
  --rose: #be123c;
  --rose-soft: #ffe8ef;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --sidebar: 264px;
  --radius: 8px;
  --font: "Inter", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

a {
  color: inherit;
  text-decoration: none;
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
  flex: 0 0 auto;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #111827;
  color: #f8fafc;
  border-right: 1px solid rgba(255, 255, 255, 0.09);
  z-index: 20;
}

.brand {
  min-height: 72px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}

.brand img {
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  box-shadow: 0 8px 18px rgba(45, 212, 191, 0.18);
}

.brand-title {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.brand-title strong {
  font-size: 17px;
  line-height: 1.15;
}

.brand-title span {
  color: #94a3b8;
  font-size: 12px;
}

.nav {
  padding: 12px;
  display: grid;
  gap: 4px;
  overflow-y: auto;
}

.nav-button {
  width: 100%;
  height: 42px;
  border: 0;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 11px;
  color: #cbd5e1;
  background: transparent;
  padding: 0 12px;
  text-align: left;
}

.nav-button:hover,
.nav-button.active {
  background: rgba(45, 212, 191, 0.14);
  color: #5eead4;
}

.nav-button.active {
  font-weight: 700;
}

.nav-icon {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  color: #042f2e;
  background: #5eead4;
}

.nav-icon svg {
  width: 14px;
  height: 14px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.09);
  display: grid;
  gap: 10px;
}

.mini-balance {
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 6px;
  background: rgba(255, 255, 255, 0.05);
}

.mini-balance span {
  color: #94a3b8;
  font-size: 12px;
}

.mini-balance strong {
  font-size: 20px;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 22px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.search {
  flex: 1;
  max-width: 520px;
  position: relative;
}

.search svg {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 17px;
  height: 17px;
  transform: translateY(-50%);
  color: var(--faint);
}

.search input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0 12px 0 38px;
  outline: 0;
}

.user-chip {
  margin-left: auto;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  padding: 5px 11px;
  font-weight: 800;
  white-space: nowrap;
}

.user-chip span:first-child {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 12px;
}

.content {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 20px;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 20px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.page-title {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.page-title h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.page-title p {
  margin: 0;
  color: var(--muted);
}

.toolbar,
.row-actions,
.copy-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn,
.icon-btn {
  min-height: 38px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.btn {
  padding: 8px 13px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
}

.btn.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.btn.soft,
.icon-btn.soft {
  color: var(--primary-strong);
  background: var(--primary-soft);
  border-color: transparent;
}

.btn.warn,
.icon-btn.warn {
  color: var(--rose);
  background: var(--rose-soft);
  border-color: transparent;
}

.btn.blue,
.icon-btn.blue {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: transparent;
}

.btn:hover,
.icon-btn:hover {
  border-color: color-mix(in srgb, var(--primary) 35%, var(--line));
}

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

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

.metric-card {
  min-height: 132px;
  padding: 16px;
  display: grid;
  gap: 12px;
  box-shadow: var(--shadow);
}

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

.metric-card strong {
  font-size: 25px;
  line-height: 1;
  overflow-wrap: anywhere;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  min-height: 58px;
  padding: 15px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

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

.panel-head span {
  color: var(--muted);
  font-size: 12px;
}

.panel-body {
  padding: 16px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 16px;
}

.chart-wrap {
  height: 330px;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 12px;
}

canvas {
  width: 100%;
  height: 100%;
}

.legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: currentColor;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-soft);
}

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

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

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

input:focus,
select:focus,
.search input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

.mono {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

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

.clip {
  max-width: 260px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  display: inline-block;
  vertical-align: bottom;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.ok {
  background: var(--primary-soft);
  color: var(--primary-strong);
}

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

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

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

.empty {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.key-hero {
  min-height: 170px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 26% 18%, rgba(45, 212, 191, 0.18), transparent 38%),
    linear-gradient(135deg, #eefbf8 0%, #edf8fb 46%, #f6fbff 100%);
  padding: 28px 28px 22px;
  display: grid;
  align-content: end;
  gap: 16px;
  position: relative;
}

.key-actions {
  position: absolute;
  top: 22px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.key-create {
  min-height: 52px;
  border-radius: 14px;
  padding: 0 20px;
  font-size: 16px;
  background: #12b8a6;
  border-color: #12b8a6;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.2);
}

.key-filters {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding-right: 320px;
}

.key-search {
  width: min(360px, 100%);
  position: relative;
}

.key-search svg {
  position: absolute;
  top: 50%;
  left: 14px;
  transform: translateY(-50%);
  color: var(--faint);
}

.key-search input,
.key-filters select {
  height: 56px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.04);
}

.key-search input {
  padding-left: 46px;
}

.key-filters select {
  width: 220px;
}

.endpoint-pills {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.endpoint-pill {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.04);
}

.endpoint-pill strong {
  color: var(--text);
}

.endpoint-pill code {
  color: var(--muted);
}

.endpoint-pill svg {
  width: 15px;
  height: 15px;
}

.key-table-panel {
  border-radius: 14px;
}

.key-table {
  min-width: 1380px;
}

.key-table th,
.key-table td {
  padding: 20px 20px;
}

.key-table th {
  font-size: 14px;
  background: #fbfcfd;
}

.key-name {
  font-size: 16px;
}

.key-token-badge,
.key-model-badge,
.key-concurrency {
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 6px 10px;
  font-weight: 800;
}

.key-token-badge {
  color: #0f9f92;
  background: #effaf8;
}

.key-model-badge {
  color: var(--primary-strong);
  background: var(--primary-soft);
}

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

.key-usage-lines {
  display: grid;
  gap: 4px;
}

.key-row-actions {
  gap: 14px;
}

.key-row-actions .icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
}

.key-row-actions .icon-btn:hover {
  background: var(--surface-soft);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(17, 24, 39, 0.58);
  backdrop-filter: blur(4px);
}

.modal-backdrop.open {
  display: flex;
}

.key-modal {
  width: min(760px, 100%);
  max-height: min(92vh, 900px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

.key-modal-head {
  min-height: 102px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 28px 36px;
  border-bottom: 1px solid var(--line);
}

.key-modal-head h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
}

.modal-close {
  border: 0;
  color: var(--faint);
  background: transparent;
}

.key-modal-body {
  display: grid;
  gap: 24px;
  overflow-y: auto;
  padding: 28px 36px;
}

.modal-field {
  display: grid;
  gap: 10px;
  color: var(--text);
  font-size: 18px;
}

.modal-field input,
.modal-field select,
.money-input {
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #ffffff;
  color: var(--text);
  font-size: 18px;
}

.modal-field input,
.modal-field select {
  padding: 0 22px;
}

.modal-field input::placeholder {
  color: #9aa4b2;
}

.modal-field small {
  color: var(--muted);
  font-size: 15px;
}

.relay-help {
  display: block;
  border: 1px solid #cceee9;
  border-radius: 12px;
  background: #effaf8;
  color: var(--primary-strong);
  padding: 10px 12px;
  line-height: 1.45;
}

.relay-help code {
  color: #0f766e;
  font-weight: 800;
}

.money-input {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
}

.money-input span {
  color: var(--muted);
  font-size: 24px;
}

.money-input input {
  min-height: 58px;
  border: 0;
  padding: 0;
}

.money-input input:focus {
  box-shadow: none;
}

.modal-toggle-row {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  color: var(--text);
  font-size: 18px;
}

.modal-switch {
  width: 54px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  background: #e3e7ed;
  position: relative;
  transition: 0.18s ease;
}

.modal-switch::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.2);
  transition: 0.18s ease;
}

.modal-switch[aria-pressed="true"] {
  background: #12b8a6;
}

.modal-switch[aria-pressed="true"]::before {
  transform: translateX(24px);
}

.key-modal-foot {
  min-height: 112px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  padding: 24px 30px;
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.key-modal-foot .btn {
  min-width: 92px;
  min-height: 62px;
  border-radius: 16px;
  padding: 0 24px;
  font-size: 18px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 36px));
}

.toast-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

@media (max-width: 1080px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

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

  .key-actions {
    position: static;
    justify-content: flex-end;
  }

  .key-filters {
    padding-right: 0;
  }
}

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

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

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

  .sidebar-footer {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .content {
    padding: 16px;
  }

  .topbar,
  .page-head {
    align-items: stretch;
    flex-direction: column;
  }

  .user-chip {
    width: fit-content;
  }

  .metric-grid,
  .form-grid,
  .nav {
    grid-template-columns: 1fr;
  }

  .key-hero {
    padding: 18px;
  }

  .key-actions,
  .key-filters,
  .endpoint-pills {
    align-items: stretch;
    flex-direction: column;
  }

  .key-refresh,
  .key-create,
  .key-search,
  .key-filters select,
  .endpoint-pill {
    width: 100%;
  }
}
