:root {
  --bg: #f3f6f6;
  --panel: #ffffff;
  --text: #17212b;
  --muted: #667085;
  --line: #d9e2e5;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --danger: #b42318;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter,
    "Microsoft YaHei",
    system-ui,
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 36px;
  border: 0;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: var(--primary-dark);
}

button.ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

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

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

input,
select {
  min-height: 38px;
  min-width: 0;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  outline: none;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #102323;
  color: #fff;
}

.brand {
  display: grid;
  gap: 4px;
  padding: 6px 4px 18px;
}

.brand strong {
  font-size: 20px;
  letter-spacing: 0;
}

.brand span,
.topbar p,
.drawer-head p,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.brand span {
  color: #b6c2d2;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav button {
  display: flex;
  align-items: center;
  justify-content: start;
  width: 100%;
  padding: 0 12px;
  background: transparent;
  color: #d0d5dd;
  text-align: left;
}

.nav button.active,
.nav button:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.main {
  min-width: 0;
  padding: 24px;
}

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

.topbar h1 {
  margin: 2px 0 0;
  font-size: 24px;
}

.secret-form,
.toolbar,
.inline-form {
  display: flex;
  gap: 8px;
}

.secret-form input {
  width: min(280px, 42vw);
}

.notice {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-size: 14px;
}

.notice.error {
  border-color: #fecdca;
  background: #fff6f5;
  color: var(--danger);
}

.notice.success {
  border-color: #a7f3d0;
  background: #ecfdf3;
  color: var(--primary-dark);
}

.view {
  display: none;
}

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

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

.metric {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 12px 26px rgba(16, 35, 35, 0.05);
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  line-height: 1.15;
}

.toolbar {
  justify-content: space-between;
}

.filter-toolbar {
  flex-wrap: wrap;
  justify-content: start;
}

.key-create-form {
  justify-content: start;
}

.provider-validation-form {
  flex-wrap: wrap;
  justify-content: start;
}

.provider-edit-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.provider-edit-form label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
}

.provider-edit-form label input {
  min-height: 0;
}

.provider-edit-form .form-actions {
  display: flex;
  gap: 8px;
  grid-column: 1 / -1;
}

.retry-policy-meta {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafb;
}

.retry-policy-meta strong {
  font-size: 13px;
  color: var(--text);
  word-break: break-all;
}

.retry-policy-meta small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.config-editor {
  width: 100%;
  min-height: 320px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font: 13px/1.55 Consolas, monospace;
  resize: vertical;
}

.retry-policy-default,
.retry-policy-rules {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.retry-policy-default-head,
.retry-policy-rules-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.retry-policy-default-head div,
.retry-policy-rules-head div {
  display: grid;
  gap: 4px;
}

.retry-policy-default-head strong,
.retry-policy-rules-head strong {
  font-size: 13px;
  color: var(--text);
}

.retry-policy-default-head small,
.retry-policy-rules-head small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.retry-policy-rule-warning {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #f1d7a5;
  border-radius: 7px;
  background: #fff8e8;
  color: #7b5a1b;
  font-size: 12px;
  line-height: 1.5;
}

.retry-policy-default-form,
.retry-policy-rule-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.retry-policy-default-form label,
.retry-policy-rule-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.retry-policy-default-form .form-actions,
.retry-policy-rule-form .form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  grid-column: 1 / -1;
}

.retry-policy-default-sequence,
.retry-policy-rule-sequence {
  grid-column: 1 / -1;
}

.retry-policy-preview {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.retry-policy-preview-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
}

.retry-policy-preview-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.retry-policy-preview-grid input {
  width: 100%;
}

.retry-policy-preview small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.retry-policy-preview-output {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafb;
  color: var(--text);
  font: 12px/1.6 Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.key-create-form input {
  width: min(320px, 32vw);
}

.provider-validation-form input,
.provider-validation-form select {
  width: min(210px, 30vw);
}

.toolbar input {
  width: min(420px, 65vw);
}

.filter-toolbar input {
  flex: 1 1 260px;
}

.filter-toolbar select {
  width: min(190px, 46vw);
}

.check-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.check-control input {
  min-height: 0;
  width: auto;
}

.selection-count {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.table-wrap,
.drawer {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 12px 26px rgba(16, 35, 35, 0.05);
}

.table-wrap.compact {
  max-height: 280px;
}

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

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  background: #f8fafb;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
  white-space: nowrap;
}

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

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

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #ecfdf3;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 900;
}

.status.revoked,
.status.bad {
  background: #fff1f0;
  color: var(--danger);
}

.model-cooldowns {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.model-cooldown {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.model-cooldown small {
  color: var(--muted);
}

.model-cooldown button {
  min-height: 28px;
  padding: 0 8px;
  font-size: 12px;
}

.drawer {
  display: grid;
  gap: 12px;
  padding: 14px;
  max-height: calc(100dvh - 180px);
}

.drawer.hidden,
.hidden {
  display: none;
}

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

.drawer-head h2 {
  margin: 2px 0 0;
  font-size: 18px;
}

.section-title {
  margin: 2px 0 -4px;
  font-size: 15px;
}

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

.drawer-grid div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafb;
}

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

.drawer-grid strong {
  display: block;
  margin-top: 4px;
  word-break: break-all;
}

.inline-form input {
  flex: 1;
}

.created-key {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid #a7f3d0;
  border-radius: 7px;
  background: #ecfdf3;
}

.created-key code {
  min-width: 0;
  overflow: auto;
  font-family: Consolas, monospace;
  word-break: break-all;
}

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

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

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

  .main {
    padding: 16px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .topbar,
  .secret-form,
  .toolbar,
  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }

  .secret-form input,
  .toolbar input,
  .key-create-form input,
  .provider-validation-form input,
  .provider-validation-form select {
    width: 100%;
  }

  .provider-edit-form {
    grid-template-columns: 1fr;
  }

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

  .retry-policy-preview-grid {
    grid-template-columns: 1fr;
  }

  .retry-policy-default-form,
  .retry-policy-rule-form {
    grid-template-columns: 1fr;
  }

  .retry-policy-default-head,
  .retry-policy-rules-head {
    flex-direction: column;
    align-items: stretch;
  }

  .drawer {
    max-height: none;
  }

  .created-key {
    grid-template-columns: 1fr;
  }
}
