:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --border: #e5e5e8;
  --border-strong: #d6d6db;
  --text: #1a1a1c;
  --muted: #73737c;
  --faint: #9b9ba4;
  --ok: #2f7d52;
  --danger: #b42318;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.mono {
  font-family: var(--mono);
  font-size: 12px;
}

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

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  width: 224px;
  height: 100vh;
  padding: 20px 14px 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 22px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--text);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.brand-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.nav-item:hover {
  background: #f5f5f6;
  color: var(--text);
}

.nav-item.active {
  background: #f2f2f4;
  color: var(--text);
  font-weight: 600;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: 1px;
  background: var(--text);
}

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.gateway-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.gateway-copy:hover {
  border-color: var(--border-strong);
}

.gateway-label {
  font-size: 11px;
  color: var(--faint);
}

.gateway-value {
  color: var(--text);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 0 32px 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 68px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

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

.view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.view[hidden] {
  display: none;
}

.panel {
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-width: 0;
}

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

.panel-head h2 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
}

.panel-note {
  font-size: 12px;
  color: var(--faint);
}

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

.metric {
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.metric-label {
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
}

.metric-value {
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.metric-value small {
  margin-left: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.chart-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.segments {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.segments button {
  height: 22px;
  padding: 0 9px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.segments button.active {
  background: #f0f0f2;
  color: var(--text);
  font-weight: 600;
}

.chart-controls select {
  height: 28px;
  padding: 0 6px;
  font-size: 12px;
}

.chart-wrap {
  position: relative;
  width: 100%;
  min-height: 236px;
}

.chart-wrap svg {
  display: block;
  overflow: visible;
}

.chart-tip {
  position: absolute;
  z-index: 3;
  padding: 6px 9px;
  border-radius: 6px;
  background: var(--text);
  color: #fff;
  font-size: 11px;
  line-height: 1.5;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 0.1s ease;
}

.chart-tip.show {
  opacity: 1;
}

.chart-tip span {
  display: block;
  color: rgba(255, 255, 255, 0.65);
}

.chart-tip strong {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.two-col {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 16px;
}

.model-row {
  display: grid;
  grid-template-columns: minmax(80px, 1.2fr) minmax(60px, 2fr) 68px;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
}

.model-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-bar {
  height: 4px;
  border-radius: 2px;
  background: #f0f0f2;
  overflow: hidden;
}

.model-bar span {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--text);
  opacity: 0.75;
}

.model-value {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

.data-table th {
  padding: 0 10px 9px;
  border-bottom: 1px solid var(--border);
  color: var(--faint);
  font-size: 11.5px;
  font-weight: 500;
  text-align: left;
}

.data-table td {
  padding: 11px 10px;
  border-bottom: 1px solid #f1f1f3;
  font-size: 12.5px;
  vertical-align: middle;
}

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

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

.data-table th:first-child,
.data-table td:first-child {
  padding-left: 2px;
}

.data-table th:last-child,
.data-table td:last-child {
  padding-right: 2px;
}

.cell-name {
  font-weight: 500;
}

.cell-ellipsis {
  display: inline-block;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.url-cell {
  display: inline-block;
  max-width: 230px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  color: var(--muted);
}

.usage {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 130px;
}

.usage-bar {
  width: 130px;
  height: 3px;
  border-radius: 2px;
  background: #ededf0;
  overflow: hidden;
}

.usage-bar span {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: #3f3f46;
}

.usage > span {
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.status i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.status.ok {
  color: var(--ok);
}

.status.err {
  color: var(--danger);
}

.status.off {
  color: var(--faint);
}

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

.link-btn {
  padding: 3px 6px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.link-btn:hover {
  background: #f2f2f4;
  color: var(--text);
}

.link-btn.danger:hover {
  color: var(--danger);
}

.error-cell {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  color: var(--danger);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}

.btn:hover {
  background: #f7f7f8;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

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

.btn-primary:hover {
  background: #303034;
  border-color: #303034;
}

.btn-danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #962017;
  border-color: #962017;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  background: #f2f2f4;
  color: var(--text);
}

.btn-sm {
  height: 26px;
  padding: 0 9px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
  height: 36px;
}

input,
select,
textarea {
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input,
select {
  height: 32px;
  padding: 0 10px;
}

textarea {
  padding: 8px 10px;
  resize: vertical;
  line-height: 1.5;
}

input::placeholder,
textarea::placeholder {
  color: var(--faint);
}

input:focus,
select:focus,
textarea:focus {
  border-color: #a8a8b0;
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.05);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filters select {
  min-width: 118px;
}

.filters input {
  flex: 1;
  min-width: 180px;
}

.empty {
  padding: 34px 8px;
  text-align: center;
  color: var(--faint);
  font-size: 12.5px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 14px;
  margin-top: 4px;
  border-top: 1px solid #f1f1f3;
  font-size: 12px;
  color: var(--muted);
}

.pager-actions {
  display: flex;
  gap: 6px;
}

.data-table.compact td {
  padding: 9px 10px;
}

.data-table.compact th {
  padding-bottom: 8px;
}

.login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login[hidden] {
  display: none;
}

.login-card {
  width: 340px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  font-size: 14px;
  font-weight: 600;
}

.login-card .btn {
  margin-top: 18px;
}

.form-error {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--danger);
}

.field {
  display: block;
}

.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  width: 100%;
}

.field input[type="number"] {
  font-variant-numeric: tabular-nums;
}

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

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

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.hint {
  margin: -6px 0 0;
  font-size: 11.5px;
  color: var(--faint);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(18, 18, 22, 0.38);
  animation: backdrop-in 0.14s ease;
}

.modal {
  width: 460px;
  max-width: 100%;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 22px;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.18);
  animation: modal-in 0.16s ease;
}

.modal h3 {
  margin: 0 0 18px;
  font-size: 15px;
  font-weight: 600;
}

.modal-text {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.token-box {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafafb;
  word-break: break-all;
  user-select: all;
  font-size: 12px;
  line-height: 1.6;
}

.token-note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
}

@keyframes backdrop-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.toast-root {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-left: 2px solid var(--text);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.07);
  font-size: 12.5px;
  opacity: 0;
  transform: translateX(14px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: none;
}

.toast.ok {
  border-left-color: var(--ok);
}

.toast.err {
  border-left-color: var(--danger);
}

@media (max-width: 1080px) {
  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two-col {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .shell {
    flex-direction: column;
  }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    padding: 14px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .brand {
    padding-bottom: 14px;
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
  }

  .nav-item.active::before {
    display: none;
  }

  .sidebar-foot {
    margin-top: 12px;
  }

  .main {
    padding: 0 16px 32px;
  }

  .topbar {
    height: 60px;
  }

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

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