:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --border: #dfe4e8;
  --border-strong: #c8d0d6;
  --text: #172027;
  --muted: #66727c;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #e5f4f2;
  --blue: #2563eb;
  --green: #15803d;
  --green-soft: #e9f7ee;
  --amber: #a16207;
  --amber-soft: #fff7dc;
  --red: #b91c1c;
  --red-soft: #fdecec;
  --slate-soft: #edf1f4;
  --sidebar: #17212b;
  --sidebar-text: #d9e2e9;
  --sidebar-muted: #8fa0ae;
  --radius: 7px;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  --shadow: 0 18px 60px rgba(21, 32, 41, 0.2);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101519;
    --surface: #182027;
    --surface-soft: #1b252d;
    --border: #2b3740;
    --border-strong: #3a4852;
    --text: #e9eef2;
    --muted: #9aa8b3;
    --accent: #43b6aa;
    --accent-strong: #65cfc2;
    --accent-soft: #163b38;
    --blue: #7ba4ff;
    --green: #72d495;
    --green-soft: #173a26;
    --amber: #f2c45d;
    --amber-soft: #3b3016;
    --red: #ff8585;
    --red-soft: #402020;
    --slate-soft: #23303a;
    --sidebar: #0d1216;
    --sidebar-text: #d9e2e9;
    --sidebar-muted: #8494a1;
    --shadow: 0 18px 70px rgba(0, 0, 0, 0.45);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

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

svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.boot {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-panel {
  width: min(390px, 100%);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand-lockup,
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font: 700 10px/1 var(--mono);
  letter-spacing: 0.02em;
}

.brand-mark.small {
  width: 34px;
  height: 34px;
  font-size: 9px;
}

.brand-lockup h1,
.sidebar-brand strong {
  margin: 0;
  font-size: 17px;
  font-weight: 680;
}

.brand-lockup p,
.sidebar-brand span {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 15px 11px;
  background: var(--sidebar);
  color: var(--sidebar-text);
}

.sidebar .brand-mark {
  background: #0f766e;
}

.sidebar-brand {
  padding: 0 7px 18px;
}

.sidebar-brand strong {
  font-size: 13px;
  color: #fff;
}

.sidebar-brand span {
  color: var(--sidebar-muted);
  font-size: 11px;
}

.sidebar-brand > div {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

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

.nav-item {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--sidebar-muted);
  text-align: left;
  cursor: pointer;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-item.active {
  background: rgba(67, 182, 170, 0.16);
  color: #9ee4dc;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 26px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 680;
}

.topbar p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 11.5px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11.5px;
}

.connection i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
}

.page {
  display: none;
  padding: 22px 26px 36px;
}

.page.active {
  display: block;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.metric-strip > div {
  min-width: 0;
  padding: 16px 18px;
  border-right: 1px solid var(--border);
}

.metric-strip > div:last-child {
  border-right: 0;
}

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

.metric-strip strong {
  display: block;
  margin-top: 5px;
  font-size: 24px;
  line-height: 1.1;
  font-weight: 680;
  font-variant-numeric: tabular-nums;
}

.overview-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(260px, 0.7fr);
  gap: 16px;
}

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

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

.section-head h2,
.section-head h3 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 650;
}

.section-head h3 {
  font-size: 12.5px;
}

.section-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.status-panel {
  align-self: start;
}

.status-list {
  padding: 5px 16px 8px;
}

.status-list > div {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.status-list > div:last-child {
  border-bottom: 0;
}

.status-list strong {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.status-list .status-extra {
  grid-template-columns: minmax(0, 1fr) auto;
  padding-left: 19px;
  color: var(--muted);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.dot.active { background: var(--green); }
.dot.locked { background: var(--amber); }
.dot.expired { background: var(--red); }
.dot.revoked { background: #7c8790; }

.table-wrap {
  overflow-x: auto;
}

.table-wrap.compact {
  max-height: 340px;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

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

.license-table tbody tr {
  cursor: pointer;
}

.license-table tbody tr:hover,
.table-wrap.compact tbody tr:hover {
  background: var(--surface-soft);
}

.cell-title {
  display: block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}

.cell-note {
  display: block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
  font-size: 10.5px;
}

.mono,
.cell-code {
  font-family: var(--mono);
  font-size: 11px;
}

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

.toolbar {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 13px;
}

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

.search-box svg {
  position: absolute;
  top: 50%;
  left: 10px;
  transform: translateY(-50%);
  color: var(--muted);
}

.search-box input {
  width: 100%;
  height: 34px;
  padding: 6px 10px 6px 34px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
}

.filter-select,
.field input,
.field textarea,
.filter-select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
}

.filter-select {
  width: 132px;
  height: 34px;
  padding: 5px 9px;
}

input:focus,
textarea:focus,
select:focus,
button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 42%, transparent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.btn {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

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

.btn.primary:hover:not(:disabled) {
  background: var(--accent-strong);
  color: #fff;
}

.btn.danger {
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 45%, var(--border));
}

.btn.danger:hover:not(:disabled) {
  background: var(--red-soft);
  border-color: var(--red);
  color: var(--red);
}

.btn.small {
  min-height: 27px;
  padding: 3px 8px;
  font-size: 11px;
}

.btn.wide {
  width: 100%;
}

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

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 21px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--slate-soft);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 650;
}

.badge.active { background: var(--green-soft); color: var(--green); }
.badge.locked { background: var(--amber-soft); color: var(--amber); }
.badge.expired,
.badge.revoked { background: var(--red-soft); color: var(--red); }

.empty-state,
.empty-inline {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 38px 20px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--text);
  font-size: 13px;
}

.empty-state span {
  font-size: 11.5px;
}

.empty-inline {
  padding: 20px;
  font-size: 11.5px;
}

.error-text {
  margin: 0;
  padding: 7px 9px;
  border: 1px solid color-mix(in srgb, var(--red) 35%, var(--border));
  border-radius: 5px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 11.5px;
}

.dialog {
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100vh - 36px);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.detail-dialog {
  width: min(980px, calc(100vw - 28px));
}

.dialog::backdrop {
  background: rgba(11, 18, 24, 0.58);
  backdrop-filter: blur(3px);
}

.dialog-body {
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 18px;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.dialog-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 680;
}

.dialog-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.dialog-close {
  font-size: 21px;
  line-height: 1;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px;
  padding-top: 16px;
}

.span-2 {
  grid-column: 1 / -1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

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

.field input,
.field textarea {
  padding: 7px 9px;
}

.field textarea {
  resize: vertical;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 16px;
}

.detail-head {
  padding-bottom: 13px;
}

.title-line {
  display: flex;
  align-items: center;
  gap: 9px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.detail-section {
  padding-top: 16px;
}

.detail-section .section-head {
  min-height: 40px;
  padding: 0 0 9px;
  border-bottom: 1px solid var(--border);
}

.edit-grid {
  padding-top: 12px;
}

.form-action {
  display: flex;
  justify-content: flex-end;
}

.audit-list {
  max-height: 240px;
  overflow-y: auto;
}

.audit-item {
  display: grid;
  grid-template-columns: 142px 150px minmax(0, 1fr);
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}

.audit-item:last-child {
  border-bottom: 0;
}

.audit-item time,
.audit-item .action {
  color: var(--muted);
}

.code-dialog {
  width: min(520px, calc(100vw - 28px));
}

.code-value {
  margin-top: 18px;
  padding: 18px 14px;
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--accent);
  font: 650 20px/1.4 var(--mono);
  letter-spacing: 0.06em;
  text-align: center;
  overflow-wrap: anywhere;
}

.api-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.guide-panel {
  padding-bottom: 16px;
}

.guide-panel > p,
.endpoint,
.code-block,
.notice {
  margin-left: 16px;
  margin-right: 16px;
}

.endpoint {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 13px;
}

.endpoint span {
  display: inline-flex;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font: 650 10px/1.6 var(--mono);
}

.endpoint code {
  font: 12px/1.5 var(--mono);
}

.code-block {
  margin-top: 13px;
  margin-bottom: 13px;
  padding: 13px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--text);
  font: 11px/1.65 var(--mono);
}

.notice {
  padding: 10px 11px;
  border-left: 3px solid var(--amber);
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 11px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 100;
  max-width: min(420px, calc(100vw - 32px));
  padding: 9px 13px;
  border-radius: 6px;
  background: #17212b;
  color: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.24);
  font-size: 12px;
}

.toast.error {
  background: #8f1d1d;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    align-content: start;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
  }

  .sidebar-brand {
    padding: 0;
  }

  .sidebar-brand span {
    display: none;
  }

  .nav {
    flex-direction: row;
    flex: 1;
  }

  .nav-item {
    width: auto;
    min-height: 32px;
  }

  .sidebar-foot {
    margin: 0;
    padding: 0;
    border: 0;
  }

  .overview-grid,
  .api-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .topbar,
  .page {
    padding-left: 14px;
    padding-right: 14px;
  }

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

  .metric-strip > div {
    border-bottom: 1px solid var(--border);
  }

  .metric-strip > div:nth-child(2n) {
    border-right: 0;
  }

  .metric-strip > div:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    border-right: 0;
  }

  .toolbar {
    flex-wrap: wrap;
  }

  .search-box {
    max-width: none;
    flex-basis: 100%;
  }

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

  .span-2 {
    grid-column: auto;
  }

  .audit-item {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .sidebar-brand strong {
    display: none;
  }

  .nav-item {
    font-size: 0;
  }

  .nav-item svg {
    width: 18px;
    height: 18px;
  }

  .sidebar-foot .nav-item {
    font-size: 0;
  }
}
